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 "SkSurfaceProps.h" | |
13 #include "SkRefCnt.h" | |
14 | |
15 class SkCanvas; | |
16 class SkPaint; | |
17 | |
18 /** | |
19 * Base class to encapsulate platform-specific bitmap allocations. | |
20 * | |
21 * TBD: in subclass destructors do we expect them to tear down | |
22 * all the bitmaps and contexts they've set up that haven't already | |
23 * been freed? | |
24 * | |
25 * Implementations must track the pairings between the buffer allocated | |
26 * and the matching native context. | |
27 * | |
28 * For example, on Windows one might create an HBITMAP (using | |
29 * CreateDIBSection() with a BITMAPINFOHEADER) and call | |
30 * SkBitmap::installPixels() to point to the same pixels (ppvBits). | |
31 * Keeps a map from ppvBits -> HBITMAP. | |
32 * | |
33 * On Mac, we might allocate space ourselves, passing it to both | |
34 * bitmap.setPixels() and CGBitmapContextCreate(). Keeps a map from | |
35 * data -> CGContextRef. | |
36 */ | |
37 | |
38 class SkRasterCanvasLayerAllocator : public SkRefCnt { | |
39 public: | |
40 SkRasterCanvasLayerAllocator(); | |
41 virtual ~SkRasterCanvasLayerAllocator(); | |
42 | |
43 /** | |
44 * Attempt to allocate a new raster canvas with backing managed by | |
45 * this object. Returns nullptr on failure. | |
46 * TODO(tomhudson): is this the correct place to insert initialData? | |
47 */ | |
48 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
| |
49 const SkSurfaceProps& props, | |
50 void* initialData = nullptr); | |
51 | |
52 /** | |
53 * Returns the native context for the buffer after making sure that its | |
54 * 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
| |
55 * This graphics-system-specific management structure is treated as | |
56 * opaque. | |
57 * Should return nullptr if passed nullptr. | |
58 */ | |
59 virtual void* getNativeContext(void* buffer, | |
60 const SkMatrix& transform, | |
61 const SkIRect& clip_bounds) = 0; | |
62 | |
63 /** | |
64 * 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.
| |
65 * guarantee that both Skia and the backing agree on the | |
66 * state of all pixels. | |
67 */ | |
68 virtual void flush(void* buffer) = 0; | |
69 | |
70 /** | |
71 * Cleans up as necessary an allocated buffer and its matching | |
72 * native context. | |
reed1
2016/09/16 13:15:00
// When is this called?
tomhudson
2016/09/28 21:23:57
Acknowledged.
| |
73 */ | |
74 virtual void free(void* buffer) = 0; | |
75 | |
76 protected: | |
77 /** | |
78 * Allocates a buffer with native-context-specific methods. | |
79 * Takes implementation-specific pointer to initial data. | |
80 * Sets rowBytes; returns a pointer to raw pixel memory which | |
81 * must be able to be passed to SkBitmap::installPixels(), | |
82 * or nullptr on failure. | |
83 */ | |
84 virtual void* allocateLayer(const SkImageInfo& info, size_t* rowBytes, | |
85 void* initialData = nullptr) = 0; | |
86 | |
87 friend class SkBitmapDevice; | |
88 }; | |
89 | |
90 #endif | |
OLD | NEW |