Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
SkRasterHandleAllocator Class Referenceabstract

#include <SkRasterHandleAllocator.h>

Inheritance diagram for SkRasterHandleAllocator:
SkiaAllocator

Classes

struct  Rec
 

Public Types

typedef void * Handle
 

Public Member Functions

virtual ~SkRasterHandleAllocator ()=default
 
virtual bool allocHandle (const SkImageInfo &, Rec *)=0
 
virtual void updateHandle (Handle, const SkMatrix &, const SkIRect &)=0
 

Static Public Member Functions

static std::unique_ptr< SkCanvasMakeCanvas (std::unique_ptr< SkRasterHandleAllocator >, const SkImageInfo &, const Rec *rec=nullptr, const SkSurfaceProps *props=nullptr)
 

Protected Member Functions

 SkRasterHandleAllocator ()=default
 
 SkRasterHandleAllocator (const SkRasterHandleAllocator &)=delete
 
SkRasterHandleAllocatoroperator= (const SkRasterHandleAllocator &)=delete
 

Friends

class SkBitmapDevice
 

Detailed Description

If a client wants to control the allocation of raster layers in a canvas, it should subclass SkRasterHandleAllocator. This allocator performs two tasks:

  1. controls how the memory for the pixels is allocated
  2. associates a "handle" to a private object that can track the matrix/clip of the SkCanvas

This example allocates a canvas, and defers to the allocator to create the base layer.

std::unique_ptr<SkCanvas> canvas = SkRasterHandleAllocator::MakeCanvas(
        SkImageInfo::Make(...),
        std::make_unique<MySubclassRasterHandleAllocator>(...),
        nullptr);

If you have already allocated the base layer (and its handle, release-proc etc.) then you can pass those in using the last parameter to MakeCanvas().

Regardless of how the base layer is allocated, each time canvas->saveLayer() is called, your allocator's allocHandle() will be called.

Definition at line 37 of file SkRasterHandleAllocator.h.

Member Typedef Documentation

◆ Handle

Definition at line 42 of file SkRasterHandleAllocator.h.

Constructor & Destructor Documentation

◆ ~SkRasterHandleAllocator()

virtual SkRasterHandleAllocator::~SkRasterHandleAllocator ( )
virtualdefault

◆ SkRasterHandleAllocator() [1/2]

SkRasterHandleAllocator::SkRasterHandleAllocator ( )
protecteddefault

◆ SkRasterHandleAllocator() [2/2]

SkRasterHandleAllocator::SkRasterHandleAllocator ( const SkRasterHandleAllocator )
protecteddelete

Member Function Documentation

◆ allocHandle()

virtual bool SkRasterHandleAllocator::allocHandle ( const SkImageInfo ,
Rec  
)
pure virtual

Given a requested info, allocate the corresponding pixels/rowbytes, and whatever handle is desired to give clients access to those pixels. The rec also contains a proc and context which will be called when this allocation goes out of scope.

e.g. when canvas->saveLayer() is called, the allocator will be called to allocate the pixels for the layer. When canvas->restore() is called, the fReleaseProc will be called.

Implemented in SkiaAllocator.

◆ MakeCanvas()

std::unique_ptr< SkCanvas > SkRasterHandleAllocator::MakeCanvas ( std::unique_ptr< SkRasterHandleAllocator alloc,
const SkImageInfo info,
const Rec rec = nullptr,
const SkSurfaceProps props = nullptr 
)
static

This creates a canvas which will use the allocator to manage pixel allocations, including all calls to saveLayer().

If rec is non-null, then it will be used as the base-layer of pixels/handle. If rec is null, then the allocator will be called for the base-layer as well.

Definition at line 3298 of file SkCanvas.cpp.

3300 {
3301 if (!alloc || !SkSurfaceValidateRasterInfo(info, rec ? rec->fRowBytes : kIgnoreRowBytesValue)) {
3302 return nullptr;
3303 }
3304
3305 SkBitmap bm;
3306 Handle hndl;
3307
3308 if (rec) {
3309 hndl = install(&bm, info, *rec) ? rec->fHandle : nullptr;
3310 } else {
3311 hndl = alloc->allocBitmap(info, &bm);
3312 }
3313 return hndl ? std::unique_ptr<SkCanvas>(new SkCanvas(bm, std::move(alloc), hndl, props))
3314 : nullptr;
3315}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static bool install(SkBitmap *bm, const SkImageInfo &info, const SkRasterHandleAllocator::Rec &rec)
bool SkSurfaceValidateRasterInfo(const SkImageInfo &, size_t rb=kIgnoreRowBytesValue)
constexpr size_t kIgnoreRowBytesValue

◆ operator=()

SkRasterHandleAllocator & SkRasterHandleAllocator::operator= ( const SkRasterHandleAllocator )
protecteddelete

◆ updateHandle()

virtual void SkRasterHandleAllocator::updateHandle ( Handle  ,
const SkMatrix ,
const SkIRect  
)
pure virtual

Clients access the handle for a given layer by calling SkCanvas::accessTopRasterHandle(). To allow the handle to reflect the current matrix/clip in the canvs, updateHandle() is is called. The subclass is responsible to update the handle as it sees fit.

Implemented in SkiaAllocator.

Friends And Related Symbol Documentation

◆ SkBitmapDevice

friend class SkBitmapDevice
friend

Definition at line 89 of file SkRasterHandleAllocator.h.


The documentation for this class was generated from the following files: