Flutter Engine
The Flutter Engine
Functions
Surface_MakeRenderTarget.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Surface_MakeRenderTarget, 256, 64, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Surface_MakeRenderTarget  ,
256  ,
64  ,
false  ,
 
)

Definition at line 4 of file Surface_MakeRenderTarget.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 32);
8
9 auto dContext = GrAsDirectContext(canvas->recordingContext());
10 if (!dContext) {
11 return;
12 }
13
15 for (auto surfaceOrigin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
16 auto gpuSurface(SkSurfaces::RenderTarget(
17 dContext, skgpu::Budgeted::kNo, info, 0, surfaceOrigin, nullptr));
18 auto surfaceCanvas = gpuSurface->getCanvas();
19 surfaceCanvas->clear(SK_ColorWHITE);
20 surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
21 sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
22 canvas->drawImage(image, 0, 0);
23 canvas->translate(0, 128);
24 }
25}
26} // END FIDDLE
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
font
Font Metadata and Metrics.
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)