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=b034517e39394b7543f06ec885e36d7d |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Image_MakeFromAdoptedTexture, 256, 256, false, 5) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void draw(SkCanvas* canvas) { |
Adlai Holler | e34b282 | 2020-07-29 12:50:56 -0400 | [diff] [blame] | 7 | GrDirectContext* dContext = GrAsDirectContext(canvas->recordingContext()); |
| 8 | // Example does not support DDL. |
| 9 | if (!dContext) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 10 | return; |
| 11 | } |
| 12 | canvas->scale(.5f, .5f); |
| 13 | canvas->clear(0x7f3f5f7f); |
| 14 | int x = 0, y = 0; |
| 15 | for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { |
| 16 | for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { |
Adlai Holler | e34b282 | 2020-07-29 12:50:56 -0400 | [diff] [blame] | 17 | sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(dContext, |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 18 | backEndTexture, origin, |
| 19 | kRGBA_8888_SkColorType, alpha); |
| 20 | canvas->drawImage(image, x, y); |
| 21 | x += 160; |
| 22 | } |
| 23 | x -= 160 * 3; |
| 24 | y += 256; |
| 25 | } |
| 26 | } |
| 27 | } // END FIDDLE |