blob: 21c013529cb7770962696dea5269e85721a7c96a [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=80856fe921ce36f8d5a32d8672bccbfc
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Image_refEncodedData, 256, 256, false, 3) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
Robert Phillips3b356c52020-08-13 14:56:33 -04007 auto dContext = GrAsDirectContext(canvas->recordingContext());
8 if (!dContext) {
9 return;
10 }
11
Hal Canary87515122019-03-15 14:22:51 -040012 struct {
13 const char* name;
14 sk_sp<SkImage> image;
Robert Phillips3b356c52020-08-13 14:56:33 -040015 } tests[] = {
16 { "image", image },
Mike Reeddc607e32020-12-23 11:50:36 -050017 { "bitmap", source.asImage() },
Robert Phillips3b356c52020-08-13 14:56:33 -040018 { "texture", SkImage::MakeFromTexture(dContext, backEndTexture, kTopLeft_GrSurfaceOrigin,
19 kRGBA_8888_SkColorType, kOpaque_SkAlphaType,
20 nullptr) }
21 };
Hal Canary87515122019-03-15 14:22:51 -040022 SkString string;
23 SkPaint paint;
Robert Phillips3b356c52020-08-13 14:56:33 -040024 SkFont font;
25
Hal Canary87515122019-03-15 14:22:51 -040026 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 }
Robert Phillips3b356c52020-08-13 14:56:33 -040032 canvas->drawString(string, 10, 20, font, paint);
Hal Canary87515122019-03-15 14:22:51 -040033 canvas->translate(0, 20);
34 }
35}
36} // END FIDDLE