Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Surface_MakeFromBackendTexture.cpp
Go to the documentation of this file.
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.
4// HASH=d3aec071998f871809f515e58abb1b0e
5REG_FIDDLE(Surface_WrapBackendTexture, 256, 256, false, 3) {
6 void draw(SkCanvas * canvas) {
7 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 32);
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
24 0,
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
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
virtual GrDirectContext * asDirectContext()
virtual GrRecordingContext * recordingContext() const
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
const Paint & paint
sk_sp< SkFontMgr > fontMgr
Definition examples.cpp:32
sk_sp< SkImage > image
Definition examples.cpp:29
GrBackendTexture backEndTexture
Definition examples.cpp:25
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)