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=9cf5c62a3d2243e6577ae563f360ea9d
5 REG_FIDDLE(Image_isTextureBacked, 256, 256, false, 5) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 auto dContext = GrAsDirectContext(canvas->recordingContext());
8 if (!dContext) {
9 return;
10 }
11
12 auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
13 if (nullptr == image) {
14 return;
15 }
16 SkPaint paint;
17 paint.setAntiAlias(true);
18 SkFont font;
19 canvas->drawImage(image, 0, 0);
20 canvas->drawString(label, 30, image->height() / 4, font, paint);
21 canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture",
22 20, image->height() * 3 / 4, font, paint);
23 };
24 sk_sp<SkImage> bitmapImage(source.asImage());
25 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
26 kTopLeft_GrSurfaceOrigin,
27 kRGBA_8888_SkColorType,
28 kOpaque_SkAlphaType, nullptr));
29 drawImage(image, "image");
30 canvas->translate(image->width(), 0);
31 drawImage(bitmapImage, "source");
32 canvas->translate(-image->width(), image->height());
33 drawImage(textureImage, "backEndTexture");
34 }
35 } // END FIDDLE
36