• 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=eeec9e07e604b44d0208899a2fe5bef5
5 REG_FIDDLE(Image_makeTextureImage, 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,
13                          GrDirectContext* dContext,
14                          const char* label) -> void {
15         if (nullptr == image || nullptr == dContext) {
16             return;
17         }
18 
19         SkFont font(nullptr, 12);
20 
21         SkPaint paint;
22         paint.setAntiAlias(true);
23 
24         sk_sp<SkImage> texture(image->makeTextureImage(dContext));
25         canvas->drawImage(texture, 0, 0);
26         canvas->drawString(label, 20, texture->height() / 4, font, paint);
27     };
28     sk_sp<SkImage> bitmapImage(source.asImage());
29 
30 
31     sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
32                                                          kTopLeft_GrSurfaceOrigin,
33                                                          kRGBA_8888_SkColorType,
34                                                          kOpaque_SkAlphaType, nullptr));
35     drawImage(image, dContext, "image");
36     canvas->translate(image->width(), 0);
37     drawImage(bitmapImage, dContext, "source");
38     canvas->translate(-image->width(), image->height());
39     drawImage(textureImage, dContext, "backEndTexture");
40 }
41 }  // END FIDDLE
42