Index: include/core/SkRasterCanvasLayerAllocator.h |
diff --git a/include/core/SkRasterCanvasLayerAllocator.h b/include/core/SkRasterCanvasLayerAllocator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e1544c52db4df894acce69c19114e9e8ca14fd75 |
--- /dev/null |
+++ b/include/core/SkRasterCanvasLayerAllocator.h |
@@ -0,0 +1,90 @@ |
+/* |
+ * 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 "SkSurfaceProps.h" |
+#include "SkRefCnt.h" |
+ |
+class SkCanvas; |
+class SkPaint; |
+ |
+/** |
+ * Base class to encapsulate platform-specific bitmap allocations. |
+ * |
+ * TBD: in subclass destructors do we expect them to tear down |
+ * all the bitmaps and contexts they've set up that haven't already |
+ * been freed? |
+ * |
+ * 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. |
+ * |
+ * On Mac, we might allocate space ourselves, passing it to both |
+ * bitmap.setPixels() and CGBitmapContextCreate(). Keeps a map from |
+ * data -> CGContextRef. |
+ */ |
+ |
+class SkRasterCanvasLayerAllocator : public SkRefCnt { |
+public: |
+ SkRasterCanvasLayerAllocator(); |
+ virtual ~SkRasterCanvasLayerAllocator(); |
+ |
+ /** |
+ * Attempt to allocate a new raster canvas with backing managed by |
+ * this object. Returns nullptr on failure. |
+ * TODO(tomhudson): is this the correct place to insert initialData? |
+ */ |
+ SkCanvas* CreateCanvas(const SkImageInfo& info, |
f(malita)
2016/09/16 13:39:01
nit: non-static -> "createCanvas()"?
Also, would
tomhudson
2016/09/28 21:23:57
Done.
Although it's really a weird member functio
|
+ 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. |
reed1
2016/09/16 13:15:00
// What is "buffer"?
I wonder if it would help do
|
+ * 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; |
+ |
+ /** |
+ * Perform any OS-dependent synchronization necessary to |
reed1
2016/09/16 13:15:00
// When is this called?
tomhudson
2016/09/28 21:23:57
Acknowledged.
|
+ * guarantee that both Skia and the backing agree on the |
+ * state of all pixels. |
+ */ |
+ virtual void flush(void* buffer) = 0; |
+ |
+ /** |
+ * Cleans up as necessary an allocated buffer and its matching |
+ * native context. |
reed1
2016/09/16 13:15:00
// When is this called?
tomhudson
2016/09/28 21:23:57
Acknowledged.
|
+ */ |
+ virtual void free(void* buffer) = 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. |
+ */ |
+ virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes, |
+ void* initialData = nullptr) = 0; |
+ |
+ friend class SkBitmapDevice; |
+}; |
+ |
+#endif |