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=b034517e39394b7543f06ec885e36d7d
5 REG_FIDDLE(Image_MakeFromAdoptedTexture, 256, 256, false, 5) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7     GrDirectContext* dContext = GrAsDirectContext(canvas->recordingContext());
8     // Example does not support DDL.
9     if (!dContext) {
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 } ) {
17             sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(dContext,
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
28