Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(613)

Unified Diff: include/core/SkRasterCanvasLayerAllocator.h

Issue 1763143002: WIP RasterCanvasLayerAllocator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test and some further work Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: include/core/SkRasterCanvasLayerAllocator.h
diff --git a/include/core/SkRasterCanvasLayerAllocator.h b/include/core/SkRasterCanvasLayerAllocator.h
new file mode 100644
index 0000000000000000000000000000000000000000..fce14b02a5f9588875c665ab41b09c710c78bdd0
--- /dev/null
+++ b/include/core/SkRasterCanvasLayerAllocator.h
@@ -0,0 +1,81 @@
+/*
+ * 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"
+
+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 raster canvas.
+ * Returns nullptr on failure.
+ */
+ SkCanvas* CreateCanvas(const SkImageInfo& info);
tomhudson 2016/05/26 16:36:17 If |this| becomes unshareable, probably move Creat
+
+ /**
+ * Given the buffer returned by allocateLayer(),
+ * which should be accessible via SkBitmap::getPixels()
+ * returns the native context.
+ * Should return nullptr if passed nullptr.
+ */
+ virtual void* getNativeContext(void* buffer) = 0;
tomhudson 2016/05/26 16:36:17 If |this| becomes unshareable, can replace with ge
+
+ /**
+ * Perform any OS-dependent synchronization necessary to
+ * guarantee that both Skia and the backing agree on the
+ * state of all pixels.
+ */
+ virtual void flush() = 0;
+
+ /**
+ * Cleans up as necessary an allocated buffer and its matching
+ * native context.
+ */
+ virtual void free(void* buffer, void* nativeContext) = 0;
+
+ void free(void* buffer) { free(buffer, this->getNativeContext(buffer)); }
tomhudson 2016/05/26 16:36:17 If |this| becomes unshareable, can replace with fr
+
+protected:
+ /**
+ * Allocates a buffer with native-context-specific methods.
+ * Sets rowBytes; returns nullptr on failure.
+ */
+ virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes) = 0;
+
+ friend class SkBitmapDevice;
+};
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698