Flutter Engine
The Flutter Engine
Functions
Image_isValid.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Image_isValid, 256, 256, false, 5)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Image_isValid  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file Image_isValid.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 auto dContext = GrAsDirectContext(canvas->recordingContext());
7 if (!dContext) {
8 return;
9 }
10
11 auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
12 if (nullptr == image) {
13 return;
14 }
15 SkFont font = SkFont(fontMgr->matchFamilyStyle(nullptr, {}));
17 paint.setAntiAlias(true);
18 canvas->drawImage(image, 0, 0);
19 canvas->drawString(label, image->width() / 2, image->height() / 4, font, paint);
20 if (dContext) {
21 const char* msg = image->isValid(dContext) ? "is valid on GPU"
22 : "not valid on GPU";
23 canvas->drawString(msg, 20, image->height() * 5 / 8, font, paint);
24 }
25
26 const char* msg = image->isValid(nullptr) ? "is valid on CPU" : "not valid on CPU";
27
28 canvas->drawString(msg, 20, image->height() * 7 / 8, font, paint);
29 };
30 sk_sp<SkImage> bitmapImage(source.asImage());
31 sk_sp<SkImage> textureImage(SkImages::BorrowTextureFrom(dContext,
36 nullptr));
37 drawImage(image, "image");
38 canvas->translate(image->width(), 0);
39 drawImage(bitmapImage, "source");
40 canvas->translate(-image->width(), image->height());
41 drawImage(textureImage, "backEndTexture");
42}
43} // END FIDDLE
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ 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
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
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
int width() const
Definition: SkImage.h:285
virtual bool isValid(GrRecordingContext *context) const =0
int height() const
Definition: SkImage.h:291
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
SkBitmap source
Definition: examples.cpp:28
GrBackendTexture backEndTexture
Definition: examples.cpp:25
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
font
Font Metadata and Metrics.