blob: 55fb5088ca1d38a58c7cfe18491849bb2014a0a9 [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=b034517e39394b7543f06ec885e36d7d
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Image_MakeFromAdoptedTexture, 256, 256, false, 5) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
Adlai Hollere34b2822020-07-29 12:50:56 -04007 GrDirectContext* dContext = GrAsDirectContext(canvas->recordingContext());
8 // Example does not support DDL.
9 if (!dContext) {
Hal Canary87515122019-03-15 14:22:51 -040010 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 Hollere34b2822020-07-29 12:50:56 -040017 sk_sp<SkImage> image = SkImage::MakeFromAdoptedTexture(dContext,
Hal Canary87515122019-03-15 14:22:51 -040018 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