blob: c25814ae6a385965e313a964ed3c328ae5fb83c1 [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=ecdbaff44a02c310ef672b7d393c6dea
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Image_makeNonTextureImage, 256, 256, false, 5) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
Robert Phillips3b356c52020-08-13 14:56:33 -04007 auto dContext = GrAsDirectContext(canvas->recordingContext());
8 if (!dContext) {
9 return;
10 }
11
Hal Canary87515122019-03-15 14:22:51 -040012 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 Phillips3b356c52020-08-13 14:56:33 -040018 SkFont font;
Hal Canary87515122019-03-15 14:22:51 -040019 sk_sp<SkImage> nonTexture(image->makeNonTextureImage());
20 canvas->drawImage(nonTexture, 0, 0);
Robert Phillips3b356c52020-08-13 14:56:33 -040021 canvas->drawString(label, 20, nonTexture->height() / 4, font, paint);
Hal Canary87515122019-03-15 14:22:51 -040022 };
Mike Reeddc607e32020-12-23 11:50:36 -050023 sk_sp<SkImage> bitmapImage(source.asImage());
Robert Phillips3b356c52020-08-13 14:56:33 -040024 sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
25 kTopLeft_GrSurfaceOrigin,
26 kRGBA_8888_SkColorType,
27 kOpaque_SkAlphaType, nullptr));
Hal Canary87515122019-03-15 14:22:51 -040028 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