Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=80856fe921ce36f8d5a32d8672bccbfc |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Image_refEncodedData, 256, 256, false, 3) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 7 | auto dContext = GrAsDirectContext(canvas->recordingContext()); |
| 8 | if (!dContext) { |
| 9 | return; |
| 10 | } |
| 11 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 12 | struct { |
| 13 | const char* name; |
| 14 | sk_sp<SkImage> image; |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 15 | } tests[] = { |
| 16 | { "image", image }, |
Mike Reed | dc607e3 | 2020-12-23 11:50:36 -0500 | [diff] [blame^] | 17 | { "bitmap", source.asImage() }, |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 18 | { "texture", SkImage::MakeFromTexture(dContext, backEndTexture, kTopLeft_GrSurfaceOrigin, |
| 19 | kRGBA_8888_SkColorType, kOpaque_SkAlphaType, |
| 20 | nullptr) } |
| 21 | }; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 22 | SkString string; |
| 23 | SkPaint paint; |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 24 | SkFont font; |
| 25 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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 | } |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 32 | canvas->drawString(string, 10, 20, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 33 | canvas->translate(0, 20); |
| 34 | } |
| 35 | } |
| 36 | } // END FIDDLE |