Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / docs / examples / Surface_MakeFromBackendTexture.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=d3aec071998f871809f515e58abb1b0e
5 REG_FIDDLE(Surface_MakeFromBackendTexture, 256, 256, false, 3) {
6 void draw(SkCanvas* canvas) {
7     SkFont font(nullptr, 32);
8     SkPaint paint;
9
10     GrRecordingContext* context = canvas->recordingContext();
11     if (!context) {
12          canvas->drawString("GPU only!", 20, 40, font, paint);
13          return;
14     }
15     GrDirectContext* direct = context->asDirectContext();
16     if (!direct) {
17          canvas->drawString("Direct Context only!", 20, 40, font, paint);
18          return;
19     }
20
21     sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(direct,
22                                                                     backEndTexture,
23                                                                     kTopLeft_GrSurfaceOrigin,
24                                                                     0,
25                                                                     kRGBA_8888_SkColorType,
26                                                                     nullptr,
27                                                                     nullptr,
28                                                                     nullptr);
29     auto surfaceCanvas = gpuSurface->getCanvas();
30     surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
31     sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
32     canvas->drawImage(image, 0, 0);
33 }
34 }  // END FIDDLE