OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #ifndef SkRasterCanvasLayerAllocator_DEFINED | |
9 #define SkRasterCanvasLayerAllocator_DEFINED | |
10 | |
11 #include "SkImageInfo.h" | |
12 #include "SkRefCnt.h" | |
13 | |
14 class SkCanvas; | |
15 class SkPaint; | |
16 | |
17 /** | |
18 * Base class to encapsulate platform-specific bitmap allocations. | |
19 * | |
20 * TBD: in subclass destructors do we expect them to tear down | |
21 * all the bitmaps and contexts they've set up that haven't already | |
22 * been freed? | |
23 * | |
24 * Implementations must track the pairings between the buffer allocated | |
25 * and the matching native context. | |
26 * | |
27 * For example, on Windows one might create an HBITMAP (using | |
28 * CreateDIBSection() with a BITMAPINFOHEADER) and call | |
29 * SkBitmap::installPixels() to point to the same pixels (ppvBits). | |
30 * Keeps a map from ppvBits -> HBITMAP. | |
31 * | |
32 * On Mac, we might allocate space ourselves, passing it to both | |
33 * bitmap.setPixels() and CGBitmapContextCreate(). Keeps a map from | |
34 * data -> CGContextRef. | |
35 */ | |
36 | |
37 class SkRasterCanvasLayerAllocator : public SkRefCnt { | |
38 public: | |
39 SkRasterCanvasLayerAllocator(); | |
40 virtual ~SkRasterCanvasLayerAllocator(); | |
41 | |
42 /** | |
43 * Attempt to allocate a raster canvas. | |
44 * Returns nullptr on failure. | |
45 */ | |
46 SkCanvas* CreateCanvas(const SkImageInfo& info); | |
tomhudson
2016/05/26 16:36:17
If |this| becomes unshareable, probably move Creat
| |
47 | |
48 /** | |
49 * Given the buffer returned by allocateLayer(), | |
50 * which should be accessible via SkBitmap::getPixels() | |
51 * returns the native context. | |
52 * Should return nullptr if passed nullptr. | |
53 */ | |
54 virtual void* getNativeContext(void* buffer) = 0; | |
tomhudson
2016/05/26 16:36:17
If |this| becomes unshareable, can replace with ge
| |
55 | |
56 /** | |
57 * Perform any OS-dependent synchronization necessary to | |
58 * guarantee that both Skia and the backing agree on the | |
59 * state of all pixels. | |
60 */ | |
61 virtual void flush() = 0; | |
62 | |
63 /** | |
64 * Cleans up as necessary an allocated buffer and its matching | |
65 * native context. | |
66 */ | |
67 virtual void free(void* buffer, void* nativeContext) = 0; | |
68 | |
69 void free(void* buffer) { free(buffer, this->getNativeContext(buffer)); } | |
tomhudson
2016/05/26 16:36:17
If |this| becomes unshareable, can replace with fr
| |
70 | |
71 protected: | |
72 /** | |
73 * Allocates a buffer with native-context-specific methods. | |
74 * Sets rowBytes; returns nullptr on failure. | |
75 */ | |
76 virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes) = 0; | |
77 | |
78 friend class SkBitmapDevice; | |
79 }; | |
80 | |
81 #endif | |
OLD | NEW |