Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkRasterHandleAllocator Class Referenceabstract

If a client wants to control the allocation of raster layers in a canvas, it should subclass SkRasterHandleAllocator. More...

#include <SkRasterHandleAllocator.h>

Classes

struct  Rec
 

Public Types

typedef void * Handle
 

Public Member Functions

virtual bool allocHandle (const SkImageInfo &, Rec *)=0
 Given a requested info, allocate the corresponding pixels/rowbytes, and whatever handle is desired to give clients access to those pixels. More...
 
virtual void updateHandle (Handle, const SkMatrix &, const SkIRect &)=0
 Clients access the handle for a given layer by calling SkCanvas::accessTopRasterHandle(). More...
 

Static Public Member Functions

static std::unique_ptr< SkCanvasMakeCanvas (std::unique_ptr< SkRasterHandleAllocator >, const SkImageInfo &, const Rec *rec=nullptr)
 This creates a canvas which will use the allocator to manage pixel allocations, including all calls to saveLayer(). More...
 

Private Member Functions

Handle allocBitmap (const SkImageInfo &, SkBitmap *)
 

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(...),
        skstd::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.

Member Function Documentation

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.

static std::unique_ptr<SkCanvas> SkRasterHandleAllocator::MakeCanvas ( std::unique_ptr< SkRasterHandleAllocator ,
const SkImageInfo ,
const Rec rec = 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.

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.


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