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=ecdbaff44a02c310ef672b7d393c6dea |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Image_makeNonTextureImage, 256, 256, false, 5) { |
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 | auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void { |
| 13 | if (nullptr == image) { |
| 14 | return; |
| 15 | } |
| 16 | SkPaint paint; |
| 17 | paint.setAntiAlias(true); |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 18 | SkFont font; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 19 | sk_sp<SkImage> nonTexture(image->makeNonTextureImage()); |
| 20 | canvas->drawImage(nonTexture, 0, 0); |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 21 | canvas->drawString(label, 20, nonTexture->height() / 4, font, paint); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 22 | }; |
Mike Reed | dc607e3 | 2020-12-23 11:50:36 -0500 | [diff] [blame] | 23 | sk_sp<SkImage> bitmapImage(source.asImage()); |
Robert Phillips | 3b356c5 | 2020-08-13 14:56:33 -0400 | [diff] [blame] | 24 | sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture, |
| 25 | kTopLeft_GrSurfaceOrigin, |
| 26 | kRGBA_8888_SkColorType, |
| 27 | kOpaque_SkAlphaType, nullptr)); |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 28 | drawImage(image, "image"); |
| 29 | canvas->translate(image->width(), 0); |
| 30 | drawImage(bitmapImage, "source"); |
| 31 | canvas->translate(-image->width(), image->height()); |
| 32 | drawImage(textureImage, "backEndTexture"); |
| 33 | } |
| 34 | } // END FIDDLE |