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 class SkSurfaceProps;
17 
38 public:
39  virtual ~SkRasterHandleAllocator() = default;
40 
41  // The value that is returned to clients of the canvas that has this allocator installed.
42  typedef void* Handle;
43 
44  struct Rec {
45  // When the allocation goes out of scope, this proc is called to free everything associated
46  // with it: the pixels, the "handle", etc. This is passed the pixel address and fReleaseCtx.
47  void (*fReleaseProc)(void* pixels, void* ctx);
48  void* fReleaseCtx; // context passed to fReleaseProc
49  void* fPixels; // pixels for this allocation
50  size_t fRowBytes; // rowbytes for these pixels
51  Handle fHandle; // public handle returned by SkCanvas::accessTopRasterHandle()
52  };
53 
63  virtual bool allocHandle(const SkImageInfo&, Rec*) = 0;
64 
70  virtual void updateHandle(Handle, const SkMatrix&, const SkIRect&) = 0;
71 
79  static std::unique_ptr<SkCanvas> MakeCanvas(std::unique_ptr<SkRasterHandleAllocator>,
80  const SkImageInfo&, const Rec* rec = nullptr,
81  const SkSurfaceProps* props = nullptr);
82 
83 protected:
87 
88 private:
89  friend class SkBitmapDevice;
90 
91  Handle allocBitmap(const SkImageInfo&, SkBitmap*);
92 };
93 
94 #endif
SkBitmap describes a two-dimensional raster pixel array.
Definition: SkBitmap.h:59
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
Definition: SkCanvas.h:99
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
If a client wants to control the allocation of raster layers in a canvas, it should subclass SkRaster...
Definition: SkRasterHandleAllocator.h:37
static std::unique_ptr< SkCanvas > MakeCanvas(std::unique_ptr< SkRasterHandleAllocator >, const SkImageInfo &, const Rec *rec=nullptr, const SkSurfaceProps *props=nullptr)
This creates a canvas which will use the allocator to manage pixel allocations, including all calls t...
SkRasterHandleAllocator()=default
SkRasterHandleAllocator & operator=(const SkRasterHandleAllocator &)=delete
virtual void updateHandle(Handle, const SkMatrix &, const SkIRect &)=0
Clients access the handle for a given layer by calling SkCanvas::accessTopRasterHandle().
virtual ~SkRasterHandleAllocator()=default
virtual bool allocHandle(const SkImageInfo &, Rec *)=0
Given a requested info, allocate the corresponding pixels/rowbytes, and whatever handle is desired to...
void * Handle
Definition: SkRasterHandleAllocator.h:42
SkRasterHandleAllocator(const SkRasterHandleAllocator &)=delete
Describes properties and constraints of a given SkSurface.
Definition: SkSurfaceProps.h:52
SkIRect holds four 32-bit integer coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:32
Describes pixel dimensions and encoding.
Definition: SkImageInfo.h:194
Definition: SkRasterHandleAllocator.h:44
Handle fHandle
Definition: SkRasterHandleAllocator.h:51
size_t fRowBytes
Definition: SkRasterHandleAllocator.h:50
void * fPixels
Definition: SkRasterHandleAllocator.h:49
void * fReleaseCtx
Definition: SkRasterHandleAllocator.h:48