Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Canvas_accessTopRasterHandle.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.
3#include <memory>
4
6// HASH=4486d0c0b22ad2931db130f42da4c80c
7REG_FIDDLE(Canvas_accessTopRasterHandle, 256, 256, true, 0) {
8static void DeleteCallback(void*, void* context) {
9 delete (char*) context;
10}
11class CustomAllocator : public SkRasterHandleAllocator {
12public:
13 bool allocHandle(const SkImageInfo& info, Rec* rec) override {
14 char* context = new char[4]{'s', 'k', 'i', 'a'};
15 rec->fReleaseProc = DeleteCallback;
16 rec->fReleaseCtx = context;
17 rec->fHandle = context;
18 rec->fPixels = context;
19 rec->fRowBytes = 4;
20 return true;
21 }
22 void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override {
23 // apply canvas matrix and clip to custom environment
24 }
25};
26
27void draw(SkCanvas* canvas) {
29 std::unique_ptr<SkCanvas> c2 =
30 SkRasterHandleAllocator::MakeCanvas(std::make_unique<CustomAllocator>(), info);
31 char* context = (char*) c2->accessTopRasterHandle();
32 SkDebugf("context = %.4s\n", context);
33}
34} // END FIDDLE
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
static std::unique_ptr< SkCanvas > MakeCanvas(std::unique_ptr< SkRasterHandleAllocator >, const SkImageInfo &, const Rec *rec=nullptr, const SkSurfaceProps *props=nullptr)
virtual void updateHandle(Handle, const SkMatrix &, const SkIRect &)=0
virtual bool allocHandle(const SkImageInfo &, Rec *)=0
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
static SkImageInfo MakeN32Premul(int width, int height)