Index: include/core/SkRasterCanvasLayerAllocator.h |
diff --git a/include/core/SkRasterCanvasLayerAllocator.h b/include/core/SkRasterCanvasLayerAllocator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7c9a868d358474d2d488a7c09859da04c30a87bd |
--- /dev/null |
+++ b/include/core/SkRasterCanvasLayerAllocator.h |
@@ -0,0 +1,91 @@ |
+/* |
+ * Copyright 2016 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef SkRasterCanvasLayerAllocator_DEFINED |
+#define SkRasterCanvasLayerAllocator_DEFINED |
+ |
+#include "SkImageInfo.h" |
+#include "SkRefCnt.h" |
+#include "SkSurfaceProps.h" |
+ |
+class SkBaseDevice; |
+class SkCanvas; |
+ |
+/** |
+ * Base class to encapsulate platform-specific bitmap allocations. |
+ * |
+ * Bitmaps may outlive this allocator object, so callbacks must be |
+ * used to make sure they get torn down as required by the platform; |
+ * see SkManagedBitmapDevice for a minimal implementation. |
+ * |
+ * Implementations must track the pairings between the buffer allocated |
+ * and the matching native context. |
+ * |
+ * For example, on Windows one might create an HBITMAP (using |
+ * CreateDIBSection() with a BITMAPINFOHEADER) and call |
+ * SkBitmap::installPixels() to point to the same pixels (ppvBits). |
+ * Keeps a map from ppvBits -> HBITMAP or HDC. |
+ * |
+ * On Mac, we might allocate space ourselves, passing it to both |
+ * bitmap.setPixels() and CGBitmapContextCreate(). Keeps a map from |
+ * data -> CGContextRef. |
+ */ |
+ |
+class SK_API SkRasterCanvasLayerAllocator { |
+public: |
+ SkRasterCanvasLayerAllocator(); |
+ virtual ~SkRasterCanvasLayerAllocator(); |
+ |
+ /** |
+ * Attempt to allocate a new raster canvas with backing managed by |
+ * this object. Returns nullptr on failure. If allocation is successful, |
+ * the canvas takes ownership of this allocator. |
+ * The optional parameter initialData is implementation-specific |
+ * pixel data to be used as or copied into the backing. |
+ */ |
+ sk_sp<SkCanvas> createCanvas(const SkImageInfo& info, |
+ const SkSurfaceProps& props, |
+ void* initialData = nullptr); |
+ |
+ /** |
+ * Returns the native context for the buffer after making sure that its |
+ * clip and transform are in sync between native and Skia representations. |
+ * This graphics-system-specific management structure is treated as |
+ * opaque. |
+ * Should return nullptr if passed nullptr. |
+ */ |
+ virtual void* getNativeContext(void* buffer, |
+ const SkMatrix& transform, |
+ const SkIRect& clip_bounds) = 0; |
+ |
+protected: |
+ /** |
+ * Allocates a buffer with native-context-specific methods. |
+ * Takes implementation-specific pointer to initial data. |
+ * Sets rowBytes; returns a pointer to raw pixel memory which |
+ * must be able to be passed to SkBitmap::installPixels(), |
+ * or nullptr on failure. |
+ * Also sets |deallocator| to a function which must be called |
+ * when this layer is released, with |deallocatorPayload| as its |
+ * argument. |
+ */ |
+ virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes, |
+ void (**deallocator)(void*), |
+ void** deallocatorPayload, |
+ void* initialData = nullptr) = 0; |
+ |
+ /** |
+ * Builds a Skia device by calling allocateLayer(). |
+ */ |
+ SkBaseDevice* makeDevice(const SkImageInfo& info, |
+ const SkSurfaceProps& props, |
+ void* initialData = nullptr); |
+ |
+ friend class SkBitmapDevice; // for makeDevice() |
+}; |
+ |
+#endif |