• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=ecdbaff44a02c310ef672b7d393c6dea
5 REG_FIDDLE(Image_makeNonTextureImage, 256, 256, false, 5) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7     auto dContext = GrAsDirectContext(canvas->recordingContext());
8     if (!dContext) {
9         return;
10     }
11 
12     auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
13         if (nullptr == image) {
14             return;
15         }
16         SkPaint paint;
17         paint.setAntiAlias(true);
18         SkFont font;
19         sk_sp<SkImage> nonTexture(image->makeNonTextureImage());
20         canvas->drawImage(nonTexture, 0, 0);
21         canvas->drawString(label, 20, nonTexture->height() / 4, font, paint);
22     };
23     sk_sp<SkImage> bitmapImage(source.asImage());
24     sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
25                                                          kTopLeft_GrSurfaceOrigin,
26                                                          kRGBA_8888_SkColorType,
27                                                          kOpaque_SkAlphaType, nullptr));
28     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
35