Chromium Code Reviews| Index: include/core/SkRasterCanvasLayerAllocator.h |
| diff --git a/include/core/SkRasterCanvasLayerAllocator.h b/include/core/SkRasterCanvasLayerAllocator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..32e0ccdb38a53886c959a49faa7837b68ceb9650 |
| --- /dev/null |
| +++ b/include/core/SkRasterCanvasLayerAllocator.h |
| @@ -0,0 +1,71 @@ |
| +/* |
| + * 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" |
| + |
| +class SkCanvas; |
| +class SkPaint; |
| + |
| +/** |
| + * Base class to encapsulate platform-specific bitmap allocations. |
| + * Must track the pairings between the buffer allocated and the |
| + * matching native context. |
| + * |
| + * 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? |
| + * |
| + * 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, passing it to both bitmap.setPixels() |
| + * and CGBitmapContextCreate(). Keeps a map from data -> CGContextRef. |
| + */ |
| + |
| +class SkRasterCanvasLayerAllocator { |
| +public: |
| + SkRasterCanvasLayerAllocator(); |
| + virtual ~SkRasterCanvasLayerAllocator(); |
| + |
| + /** |
| + * Attempt to allocate a raster canvas. |
| + * Returns nullptr on failure. |
| + */ |
| + SkCanvas* CreateCanvas(const SkImageInfo& info); |
| + |
|
reed1
2016/05/11 18:58:24
Lets try adding the flush() virtual, and see where
tomhudson
2016/05/26 16:36:16
Done.
|
| + /** |
| + * 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; |
| + |
| + /** |
| + * 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)); } |
| + |
| +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; |
|
reed1
2016/05/11 18:58:24
We may have to iterate more on this signature -- w
tomhudson
2016/05/26 16:36:17
Still TODO.
|
| + |
| + friend class SkBitmapDevice; |
| +}; |
| + |
| +#endif |