Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Image_TextureFromImage.cpp
Go to the documentation of this file.
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.
4// HASH=eeec9e07e604b44d0208899a2fe5bef5
5REG_FIDDLE(Image_TextureFromImage, 256, 256, false, 5) {
6void 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(fontMgr->matchFamilyStyle(nullptr, {}), 12);
20
22 paint.setAntiAlias(true);
23
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 sk_sp<SkImage> textureImage(SkImages::BorrowTextureFrom(dContext,
35 nullptr));
36 drawImage(image, dContext, "image");
37 canvas->translate(image->width(), 0);
38 drawImage(bitmapImage, dContext, "source");
39 canvas->translate(-image->width(), image->height());
40 drawImage(textureImage, dContext, "backEndTexture");
41}
42} // END FIDDLE
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
sk_sp< SkImage > asImage() const
Definition SkBitmap.cpp:645
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
int width() const
Definition SkImage.h:285
int height() const
Definition SkImage.h:291
const Paint & paint
sk_sp< SkFontMgr > fontMgr
Definition examples.cpp:32
sk_sp< SkImage > image
Definition examples.cpp:29
SkBitmap source
Definition examples.cpp:28
GrBackendTexture backEndTexture
Definition examples.cpp:25
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
FlTexture * texture
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)