1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h" 4cb93a386Sopenharmony_ci// HASH=6de6f3ef699a72ff26da1b26b23a3316 5cb93a386Sopenharmony_ciREG_FIDDLE(Surface_characterize, 256, 64, false, 0) { 6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) { 7cb93a386Sopenharmony_ci SkFont font(nullptr, 32); 8cb93a386Sopenharmony_ci SkPaint paint; 9cb93a386Sopenharmony_ci auto context = canvas->recordingContext(); 10cb93a386Sopenharmony_ci if (!context) { 11cb93a386Sopenharmony_ci canvas->drawString("GPU only!", 20, 40, font, paint); 12cb93a386Sopenharmony_ci return; 13cb93a386Sopenharmony_ci } 14cb93a386Sopenharmony_ci sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget( 15cb93a386Sopenharmony_ci context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(64, 64)); 16cb93a386Sopenharmony_ci SkSurfaceCharacterization characterization; 17cb93a386Sopenharmony_ci if (!gpuSurface->characterize(&characterization)) { 18cb93a386Sopenharmony_ci canvas->drawString("characterization unsupported", 20, 40, font, paint); 19cb93a386Sopenharmony_ci return; 20cb93a386Sopenharmony_ci } 21cb93a386Sopenharmony_ci // start of threadable work 22cb93a386Sopenharmony_ci SkDeferredDisplayListRecorder recorder(characterization); 23cb93a386Sopenharmony_ci SkCanvas* subCanvas = recorder.getCanvas(); 24cb93a386Sopenharmony_ci subCanvas->clear(SK_ColorGREEN); 25cb93a386Sopenharmony_ci sk_sp<SkDeferredDisplayList> displayList = recorder.detach(); 26cb93a386Sopenharmony_ci // end of threadable work 27cb93a386Sopenharmony_ci gpuSurface->draw(displayList); 28cb93a386Sopenharmony_ci sk_sp<SkImage> img = gpuSurface->makeImageSnapshot(); 29cb93a386Sopenharmony_ci canvas->drawImage(std::move(img), 0, 0); 30cb93a386Sopenharmony_ci} 31cb93a386Sopenharmony_ci} // END FIDDLE 32