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

Side by Side Diff: include/core/SkRasterCanvasLayerAllocator.h

Issue 1763143002: WIP RasterCanvasLayerAllocator (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add allocator-constancy sanitycheck Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(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
13 class SkCanvas;
14 class SkPaint;
15
16 /**
17 * Base class to encapsulate platform-specific bitmap allocations.
18 * Must track the pairings between the buffer allocated and the
19 * matching native context.
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 * For example, on Windows one might create an HBITMAP (using
26 * CreateDIBSection() with a BITMAPINFOHEADER) and call
27 * SkBitmap::installPixels() to point to the same pixels (ppvBits).
28 * Keeps a map from ppvBits -> HBITMAP.
29 *
30 * On Mac, we might allocate space, passing it to both bitmap.setPixels()
31 * and CGBitmapContextCreate(). Keeps a map from data -> CGContextRef.
32 */
33
34 class SkRasterCanvasLayerAllocator {
35 public:
36 SkRasterCanvasLayerAllocator();
37 virtual ~SkRasterCanvasLayerAllocator();
38
39 /**
40 * Attempt to allocate a raster canvas.
41 * Returns nullptr on failure.
42 */
43 SkCanvas* CreateCanvas(const SkImageInfo& info);
44
reed1 2016/05/11 18:58:24 Lets try adding the flush() virtual, and see where
tomhudson 2016/05/26 16:36:16 Done.
45 /**
46 * Given the buffer returned by allocateLayer(),
47 * which should be accessible via SkBitmap::getPixels()
48 * returns the native context.
49 * Should return nullptr if passed nullptr.
50 */
51 virtual void* getNativeContext(void* buffer) = 0;
52
53 /**
54 * Cleans up as necessary an allocated buffer and its matching
55 * native context.
56 */
57 virtual void free(void* buffer, void* nativeContext) = 0;
58
59 void free(void* buffer) { free(buffer, this->getNativeContext(buffer)); }
60
61 protected:
62 /**
63 * Allocates a buffer with native-context-specific methods.
64 * Sets rowBytes; returns nullptr on failure.
65 */
66 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.
67
68 friend class SkBitmapDevice;
69 };
70
71 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698