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=80856fe921ce36f8d5a32d8672bccbfc
5 REG_FIDDLE(Image_refEncodedData, 256, 256, false, 3) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 auto dContext = GrAsDirectContext(canvas->recordingContext());
8 if (!dContext) {
9 return;
10 }
11
12 struct {
13 const char* name;
14 sk_sp<SkImage> image;
15 } tests[] = {
16 { "image", image },
17 { "bitmap", source.asImage() },
18 { "texture", SkImage::MakeFromTexture(dContext, backEndTexture, kTopLeft_GrSurfaceOrigin,
19 kRGBA_8888_SkColorType, kOpaque_SkAlphaType,
20 nullptr) }
21 };
22 SkString string;
23 SkPaint paint;
24 SkFont font;
25
26 for (const auto& test : tests ) {
27 if (!test.image) {
28 string.printf("no %s", test.name);
29 } else {
30 string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name);
31 }
32 canvas->drawString(string, 10, 20, font, paint);
33 canvas->translate(0, 20);
34 }
35 }
36 } // END FIDDLE
37