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