Flutter Engine
The Flutter Engine
Image_GetBackendTextureFromImage.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.
4REG_FIDDLE(Image_GetBackendTextureFromImage, 256, 256, false, 3) {
5void draw(SkCanvas* canvas) {
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<SkImage> imageFromBackend = SkImages::AdoptTextureFrom(direct,
25 GrBackendTexture textureFromImage;
26 if (!SkImages::GetBackendTextureFromImage(imageFromBackend, &textureFromImage, false)) {
27 return;
28 }
29
30 sk_sp<SkImage> imageFromTexture = SkImages::AdoptTextureFrom(direct,
31 textureFromImage,
35 canvas->drawImage(imageFromTexture, 0, 0);
36 canvas->drawImage(imageFromBackend, 128, 128);
37}
38} // END FIDDLE
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
REG_FIDDLE(Image_GetBackendTextureFromImage, 256, 256, false, 3)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ 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
Definition: SkCanvas.cpp:1637
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
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
GrBackendTexture backEndTexture
Definition: examples.cpp:25
SK_API sk_sp< SkImage > AdoptTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin textureOrigin, SkColorType colorType)
SK_API bool GetBackendTextureFromImage(const SkImage *img, GrBackendTexture *outTexture, bool flushPendingGrContextIO, GrSurfaceOrigin *origin=nullptr)
font
Font Metadata and Metrics.