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..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 |