Debian Codegraph @

docs/examples/Surface_MakeFromBackendTexture.cpp

raw
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 REG_FIDDLE(Surface_WrapBackendTexture, 256, 256, false, 3) {
5 void draw(SkCanvas * canvas) {
6 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 32);
7 SkPaint paint;
8
9 GrRecordingContext* context = canvas->recordingContext();
10 if (!context) {
11 canvas->drawString("GPU only!", 20, 40, font, paint);
12 return;
13 }
14 GrDirectContext* direct = context->asDirectContext();
15 if (!direct) {
16 canvas->drawString("Direct Context only!", 20, 40, font, paint);
17 return;
18 }
19
20 sk_sp<SkSurface> gpuSurface = SkSurfaces::WrapBackendTexture(direct,
21 backEndTexture,
22 kTopLeft_GrSurfaceOrigin,
23 0,
24 kRGBA_8888_SkColorType,
25 nullptr,
26 nullptr,
27 nullptr);
28 auto surfaceCanvas = gpuSurface->getCanvas();
29 surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
30 sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
31 canvas->drawImage(image, 0, 0);
32 }
33 } // END FIDDLE