xref: /aosp_15_r20/external/skia/docs/examples/Image_AdoptTextureFrom.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 REG_FIDDLE(Image_AdoptTextureFrom, 256, 256, false, 5) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     GrDirectContext* dContext = GrAsDirectContext(canvas->recordingContext());
7     // Example does not support DDL.
8     if (!dContext) {
9         return;
10     }
11     canvas->scale(.5f, .5f);
12     canvas->clear(0x7f3f5f7f);
13     int x = 0, y = 0;
14     for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
15         for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) {
16             sk_sp<SkImage> image = SkImages::AdoptTextureFrom(
17                     dContext, backEndTexture, origin, kRGBA_8888_SkColorType, alpha);
18             canvas->drawImage(image, x, y);
19             x += 160;
20         }
21         x -= 160 * 3;
22         y += 256;
23     }
24 }
25 }  // END FIDDLE
26