OLD | NEW |
(Empty) | |
| 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 SkRasterCanvasLayerAllocator_DEFINED |
| 9 #define SkRasterCanvasLayerAllocator_DEFINED |
| 10 |
| 11 #include "SkImageInfo.h" |
| 12 #include "SkRefCnt.h" |
| 13 #include "SkSurfaceProps.h" |
| 14 |
| 15 class SkBaseDevice; |
| 16 class SkCanvas; |
| 17 |
| 18 /** |
| 19 * Base class to encapsulate platform-specific bitmap allocations. |
| 20 * |
| 21 * Bitmaps may outlive this allocator object, so callbacks must be |
| 22 * used to make sure they get torn down as required by the platform; |
| 23 * see SkManagedBitmapDevice for a minimal implementation. |
| 24 * |
| 25 * Implementations must track the pairings between the buffer allocated |
| 26 * and the matching native context. |
| 27 * |
| 28 * For example, on Windows one might create an HBITMAP (using |
| 29 * CreateDIBSection() with a BITMAPINFOHEADER) and call |
| 30 * SkBitmap::installPixels() to point to the same pixels (ppvBits). |
| 31 * Keeps a map from ppvBits -> HBITMAP or HDC. |
| 32 * |
| 33 * On Mac, we might allocate space ourselves, passing it to both |
| 34 * bitmap.setPixels() and CGBitmapContextCreate(). Keeps a map from |
| 35 * data -> CGContextRef. |
| 36 */ |
| 37 |
| 38 class SK_API SkRasterCanvasLayerAllocator { |
| 39 public: |
| 40 SkRasterCanvasLayerAllocator(); |
| 41 virtual ~SkRasterCanvasLayerAllocator(); |
| 42 |
| 43 /** |
| 44 * Attempt to allocate a new raster canvas with backing managed by |
| 45 * this object. Returns nullptr on failure. If allocation is successful, |
| 46 * the canvas takes ownership of this allocator. |
| 47 * The optional parameter initialData is implementation-specific |
| 48 * pixel data to be used as or copied into the backing. |
| 49 */ |
| 50 sk_sp<SkCanvas> createCanvas(const SkImageInfo& info, |
| 51 const SkSurfaceProps& props, |
| 52 void* initialData = nullptr); |
| 53 |
| 54 /** |
| 55 * Returns the native context for the buffer after making sure that its |
| 56 * clip and transform are in sync between native and Skia representations. |
| 57 * This graphics-system-specific management structure is treated as |
| 58 * opaque. |
| 59 * Should return nullptr if passed nullptr. |
| 60 */ |
| 61 virtual void* getNativeContext(void* buffer, |
| 62 const SkMatrix& transform, |
| 63 const SkIRect& clip_bounds) = 0; |
| 64 |
| 65 protected: |
| 66 /** |
| 67 * Allocates a buffer with native-context-specific methods. |
| 68 * Takes implementation-specific pointer to initial data. |
| 69 * Sets rowBytes; returns a pointer to raw pixel memory which |
| 70 * must be able to be passed to SkBitmap::installPixels(), |
| 71 * or nullptr on failure. |
| 72 * Also sets |deallocator| to a function which must be called |
| 73 * when this layer is released, with |deallocatorPayload| as its |
| 74 * argument. |
| 75 */ |
| 76 virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes, |
| 77 void (**deallocator)(void*), |
| 78 void** deallocatorPayload, |
| 79 void* initialData = nullptr) = 0; |
| 80 |
| 81 /** |
| 82 * Builds a Skia device by calling allocateLayer(). |
| 83 */ |
| 84 SkBaseDevice* makeDevice(const SkImageInfo& info, |
| 85 const SkSurfaceProps& props, |
| 86 void* initialData = nullptr); |
| 87 |
| 88 friend class SkBitmapDevice; // for makeDevice() |
| 89 }; |
| 90 |
| 91 #endif |
OLD | NEW |