Skia
2D Graphics Library
SkRasterHandleAllocator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkRasterHandleAllocator_DEFINED
9 #define SkRasterHandleAllocator_DEFINED
10 
12 
13 class SkBitmap;
14 class SkCanvas;
15 class SkMatrix;
16 
37 public:
38  virtual ~SkRasterHandleAllocator() = default;
39 
40  // The value that is returned to clients of the canvas that has this allocator installed.
41  typedef void* Handle;
42 
43  struct Rec {
44  // When the allocation goes out of scope, this proc is called to free everything associated
45  // with it: the pixels, the "handle", etc. This is passed the pixel address and fReleaseCtx.
46  void (*fReleaseProc)(void* pixels, void* ctx);
47  void* fReleaseCtx; // context passed to fReleaseProc
48  void* fPixels; // pixels for this allocation
49  size_t fRowBytes; // rowbytes for these pixels
50  Handle fHandle; // public handle returned by SkCanvas::accessTopRasterHandle()
51  };
52 
62  virtual bool allocHandle(const SkImageInfo&, Rec*) = 0;
63 
69  virtual void updateHandle(Handle, const SkMatrix&, const SkIRect&) = 0;
70 
78  static std::unique_ptr<SkCanvas> MakeCanvas(std::unique_ptr<SkRasterHandleAllocator>,
79  const SkImageInfo&, const Rec* rec = nullptr);
80 
81 protected:
85 
86 private:
87  friend class SkBitmapDevice;
88 
89  Handle allocBitmap(const SkImageInfo&, SkBitmap*);
90 };
91 
92 #endif
SkRasterHandleAllocator::SkRasterHandleAllocator
SkRasterHandleAllocator()=default
SkRasterHandleAllocator::operator=
SkRasterHandleAllocator & operator=(const SkRasterHandleAllocator &)=delete
SkRasterHandleAllocator::Handle
void * Handle
Definition: SkRasterHandleAllocator.h:41
SkRasterHandleAllocator::Rec::fHandle
Handle fHandle
Definition: SkRasterHandleAllocator.h:50
SkRasterHandleAllocator::updateHandle
virtual void updateHandle(Handle, const SkMatrix &, const SkIRect &)=0
Clients access the handle for a given layer by calling SkCanvas::accessTopRasterHandle().
SkRasterHandleAllocator
If a client wants to control the allocation of raster layers in a canvas, it should subclass SkRaster...
Definition: SkRasterHandleAllocator.h:36
SkRasterHandleAllocator::allocHandle
virtual bool allocHandle(const SkImageInfo &, Rec *)=0
Given a requested info, allocate the corresponding pixels/rowbytes, and whatever handle is desired to...
SK_API
#define SK_API
Definition: SkTypes.h:181
SkRasterHandleAllocator::MakeCanvas
static std::unique_ptr< SkCanvas > MakeCanvas(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 t...
SkImageInfo
Definition: SkImageInfo.h:283
SkCanvas
Definition: SkCanvas.h:87
SkRasterHandleAllocator::SkRasterHandleAllocator
SkRasterHandleAllocator(const SkRasterHandleAllocator &)=delete
SkRasterHandleAllocator::Rec::fReleaseCtx
void * fReleaseCtx
Definition: SkRasterHandleAllocator.h:47
SkMatrix
Definition: SkMatrix.h:48
SkIRect
Definition: SkRect.h:28
SkRasterHandleAllocator::Rec::fPixels
void * fPixels
Definition: SkRasterHandleAllocator.h:48
SkRasterHandleAllocator::Rec
Definition: SkRasterHandleAllocator.h:43
SkRasterHandleAllocator::~SkRasterHandleAllocator
virtual ~SkRasterHandleAllocator()=default
SkImageInfo.h
SkBitmap
Definition: SkBitmap.h:50
SkRasterHandleAllocator::Rec::fRowBytes
size_t fRowBytes
Definition: SkRasterHandleAllocator.h:49