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

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

Issue 22978012: Split SkDevice into SkBaseDevice and SkBitmapDevice (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Updating to ToT (10994) Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkCanvas.h ('k') | include/core/SkDraw.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2010 The Android Open Source Project 3 * Copyright 2010 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkDevice_DEFINED 10 #ifndef SkDevice_DEFINED
11 #define SkDevice_DEFINED 11 #define SkDevice_DEFINED
12 12
13 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
14 #include "SkBitmap.h" 14 #include "SkBitmap.h"
15 #include "SkCanvas.h" 15 #include "SkCanvas.h"
16 #include "SkColor.h" 16 #include "SkColor.h"
17 #include "SkDeviceProperties.h" 17 #include "SkDeviceProperties.h"
18 18
19 class SkClipStack; 19 class SkClipStack;
20 class SkDraw; 20 class SkDraw;
21 struct SkIRect; 21 struct SkIRect;
22 class SkMatrix; 22 class SkMatrix;
23 class SkMetaData; 23 class SkMetaData;
24 class SkRegion; 24 class SkRegion;
25 25
26 class GrRenderTarget; 26 class GrRenderTarget;
27 27
28 class SK_API SkDevice : public SkRefCnt { 28 class SK_API SkBaseDevice : public SkRefCnt {
29 public: 29 public:
30 SK_DECLARE_INST_COUNT(SkDevice) 30 SK_DECLARE_INST_COUNT(SkBaseDevice)
31 31
32 /** 32 /**
33 * Construct a new device with the specified bitmap as its backend. It is 33 * Construct a new device.
34 * valid for the bitmap to have no pixels associated with it. In that case,
35 * any drawing to this device will have no effect.
36 */ 34 */
37 SkDevice(const SkBitmap& bitmap); 35 SkBaseDevice();
38 36
39 /** 37 /**
40 * Construct a new device with the specified bitmap as its backend. It is 38 * Construct a new device.
41 * valid for the bitmap to have no pixels associated with it. In that case,
42 * any drawing to this device will have no effect.
43 */ 39 */
44 SkDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) ; 40 SkBaseDevice(const SkDeviceProperties& deviceProperties);
45 41
46 /** 42 virtual ~SkBaseDevice();
47 * Create a new raster device and have the pixels be automatically
48 * allocated. The rowBytes of the device will be computed automatically
49 * based on the config and the width.
50 *
51 * @param config The desired config for the pixels. If the request cannot
52 * be met, the closest matching support config will be used .
53 * @param width width (in pixels) of the device
54 * @param height height (in pixels) of the device
55 * @param isOpaque Set to true if it is known that all of the pixels will
56 * be drawn to opaquely. Used as an accelerator when drawin g
57 * these pixels to another device.
58 */
59 SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque = fal se);
60
61 /**
62 * Create a new raster device and have the pixels be automatically
63 * allocated. The rowBytes of the device will be computed automatically
64 * based on the config and the width.
65 *
66 * @param config The desired config for the pixels. If the request cannot
67 * be met, the closest matching support config will be used .
68 * @param width width (in pixels) of the device
69 * @param height height (in pixels) of the device
70 * @param isOpaque Set to true if it is known that all of the pixels will
71 * be drawn to opaquely. Used as an accelerator when drawin g
72 * these pixels to another device.
73 * @param deviceProperties Properties which affect compositing.
74 */
75 SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
76 const SkDeviceProperties& deviceProperties);
77
78 virtual ~SkDevice();
79 43
80 /** 44 /**
81 * Creates a device that is of the same type as this device (e.g. SW-raster , 45 * Creates a device that is of the same type as this device (e.g. SW-raster ,
82 * GPU, or PDF). The backing store for this device is created automatically 46 * GPU, or PDF). The backing store for this device is created automatically
83 * (e.g. offscreen pixels or FBO or whatever is appropriate). 47 * (e.g. offscreen pixels or FBO or whatever is appropriate).
84 * 48 *
85 * @param width width of the device to create 49 * @param width width of the device to create
86 * @param height height of the device to create 50 * @param height height of the device to create
87 * @param isOpaque performance hint, set to true if you know that you will 51 * @param isOpaque performance hint, set to true if you know that you will
88 * draw into this device such that all of the pixels will 52 * draw into this device such that all of the pixels will
89 * be opaque. 53 * be opaque.
90 */ 54 */
91 SkDevice* createCompatibleDevice(SkBitmap::Config config, 55 SkBaseDevice* createCompatibleDevice(SkBitmap::Config config,
92 int width, int height, 56 int width, int height,
93 bool isOpaque); 57 bool isOpaque);
94 58
95 SkMetaData& getMetaData(); 59 SkMetaData& getMetaData();
96 60
97 enum Capabilities { 61 enum Capabilities {
98 kGL_Capability = 0x1, //!< mask indicating GL support 62 kGL_Capability = 0x1, //!< mask indicating GL support
99 kVector_Capability = 0x2, //!< mask indicating a vector representation 63 kVector_Capability = 0x2, //!< mask indicating a vector representation
100 kAll_Capabilities = 0x3 64 kAll_Capabilities = 0x3
101 }; 65 };
102 virtual uint32_t getDeviceCapabilities() { return 0; } 66 virtual uint32_t getDeviceCapabilities() = 0;
103 67
104 /** Return the width of the device (in pixels). 68 /** Return the width of the device (in pixels).
105 */ 69 */
106 virtual int width() const { return fBitmap.width(); } 70 virtual int width() const = 0;
107 /** Return the height of the device (in pixels). 71 /** Return the height of the device (in pixels).
108 */ 72 */
109 virtual int height() const { return fBitmap.height(); } 73 virtual int height() const = 0;
110 74
111 /** Return the image properties of the device. */ 75 /** Return the image properties of the device. */
112 virtual const SkDeviceProperties& getDeviceProperties() const { 76 virtual const SkDeviceProperties& getDeviceProperties() const {
113 //Currently, all the properties are leaky. 77 //Currently, all the properties are leaky.
114 return fLeakyProperties; 78 return fLeakyProperties;
115 } 79 }
116 80
117 /** 81 /**
118 * Return the bounds of the device in the coordinate space of the root 82 * Return the bounds of the device in the coordinate space of the root
119 * canvas. The root device will have its top-left at 0,0, but other devices 83 * canvas. The root device will have its top-left at 0,0, but other devices
120 * such as those associated with saveLayer may have a non-zero origin. 84 * such as those associated with saveLayer may have a non-zero origin.
121 */ 85 */
122 void getGlobalBounds(SkIRect* bounds) const; 86 virtual void getGlobalBounds(SkIRect* bounds) const = 0;
123 87
124 /** Returns true if the device's bitmap's config treats every pixels as 88 /** Returns true if the device's bitmap's config treats every pixels as
125 implicitly opaque. 89 implicitly opaque.
126 */ 90 */
127 bool isOpaque() const { return fBitmap.isOpaque(); } 91 virtual bool isOpaque() const = 0;
128 92
129 /** Return the bitmap config of the device's pixels 93 /** DEPRECATED - Return the bitmap config of the device's pixels
130 */ 94 */
131 SkBitmap::Config config() const { return fBitmap.getConfig(); } 95 virtual SkBitmap::Config config() const = 0;
132 96
133 /** Return the bitmap associated with this device. Call this each time you n eed 97 /** Return the bitmap associated with this device. Call this each time you n eed
134 to access the bitmap, as it notifies the subclass to perform any flushin g 98 to access the bitmap, as it notifies the subclass to perform any flushin g
135 etc. before you examine the pixels. 99 etc. before you examine the pixels.
136 @param changePixels set to true if the caller plans to change the pixels 100 @param changePixels set to true if the caller plans to change the pixels
137 @return the device's bitmap 101 @return the device's bitmap
138 */ 102 */
139 const SkBitmap& accessBitmap(bool changePixels); 103 const SkBitmap& accessBitmap(bool changePixels);
140 104
141 /** 105 /**
142 * DEPRECATED: This will be made protected once WebKit stops using it. 106 * DEPRECATED: This will be made protected once WebKit stops using it.
143 * Instead use Canvas' writePixels method. 107 * Instead use Canvas' writePixels method.
144 * 108 *
145 * Similar to draw sprite, this method will copy the pixels in bitmap onto 109 * Similar to draw sprite, this method will copy the pixels in bitmap onto
146 * the device, with the top/left corner specified by (x, y). The pixel 110 * the device, with the top/left corner specified by (x, y). The pixel
147 * values in the device are completely replaced: there is no blending. 111 * values in the device are completely replaced: there is no blending.
148 * 112 *
149 * Currently if bitmap is backed by a texture this is a no-op. This may be 113 * Currently if bitmap is backed by a texture this is a no-op. This may be
150 * relaxed in the future. 114 * relaxed in the future.
151 * 115 *
152 * If the bitmap has config kARGB_8888_Config then the config8888 param 116 * If the bitmap has config kARGB_8888_Config then the config8888 param
153 * will determines how the pixel valuess are intepreted. If the bitmap is 117 * will determines how the pixel valuess are intepreted. If the bitmap is
154 * not kARGB_8888_Config then this parameter is ignored. 118 * not kARGB_8888_Config then this parameter is ignored.
155 */ 119 */
156 virtual void writePixels(const SkBitmap& bitmap, int x, int y, 120 virtual void writePixels(const SkBitmap& bitmap, int x, int y,
157 SkCanvas::Config8888 config8888 = SkCanvas::kNative _Premul_Config8888); 121 SkCanvas::Config8888 config8888 = SkCanvas::kNative _Premul_Config8888) = 0;
158 122
159 /** 123 /**
160 * Return the device's associated gpu render target, or NULL. 124 * Return the device's associated gpu render target, or NULL.
161 */ 125 */
162 virtual GrRenderTarget* accessRenderTarget() { return NULL; } 126 virtual GrRenderTarget* accessRenderTarget() = 0;
163 127
164 128
165 /** 129 /**
166 * Return the device's origin: its offset in device coordinates from 130 * Return the device's origin: its offset in device coordinates from
167 * the default origin in its canvas' matrix/clip 131 * the default origin in its canvas' matrix/clip
168 */ 132 */
169 const SkIPoint& getOrigin() const { return fOrigin; } 133 const SkIPoint& getOrigin() const { return fOrigin; }
170 134
171 /** 135 /**
172 * onAttachToCanvas is invoked whenever a device is installed in a canvas 136 * onAttachToCanvas is invoked whenever a device is installed in a canvas
173 * (i.e., setDevice, saveLayer (for the new device created by the save), 137 * (i.e., setDevice, saveLayer (for the new device created by the save),
174 * and SkCanvas' SkDevice & SkBitmap -taking ctors). It allows the 138 * and SkCanvas' SkBaseDevice & SkBitmap -taking ctors). It allows the
175 * devices to prepare for drawing (e.g., locking their pixels, etc.) 139 * devices to prepare for drawing (e.g., locking their pixels, etc.)
176 */ 140 */
177 virtual void onAttachToCanvas(SkCanvas*) { 141 virtual void onAttachToCanvas(SkCanvas*) {
178 SkASSERT(!fAttachedToCanvas); 142 SkASSERT(!fAttachedToCanvas);
179 this->lockPixels(); 143 this->lockPixels();
180 #ifdef SK_DEBUG 144 #ifdef SK_DEBUG
181 fAttachedToCanvas = true; 145 fAttachedToCanvas = true;
182 #endif 146 #endif
183 }; 147 };
184 148
(...skipping 21 matching lines...) Expand all
206 uint32_t fFlags; // SkPaint::getFlags() 170 uint32_t fFlags; // SkPaint::getFlags()
207 SkPaint::Hinting fHinting; 171 SkPaint::Hinting fHinting;
208 }; 172 };
209 173
210 /** 174 /**
211 * Device may filter the text flags for drawing text here. If it wants to 175 * Device may filter the text flags for drawing text here. If it wants to
212 * make a change to the specified values, it should write them into the 176 * make a change to the specified values, it should write them into the
213 * textflags parameter (output) and return true. If the paint is fine as 177 * textflags parameter (output) and return true. If the paint is fine as
214 * is, then ignore the textflags parameter and return false. 178 * is, then ignore the textflags parameter and return false.
215 * 179 *
216 * The baseclass SkDevice filters based on its depth and blitters. 180 * The baseclass SkBaseDevice filters based on its depth and blitters.
217 */ 181 */
218 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*); 182 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0;
219 183
220 /** 184 /**
221 * 185 *
222 * DEPRECATED: This will be removed in a future change. Device subclasses 186 * DEPRECATED: This will be removed in a future change. Device subclasses
223 * should use the matrix and clip from the SkDraw passed to draw functions. 187 * should use the matrix and clip from the SkDraw passed to draw functions.
224 * 188 *
225 * Called with the correct matrix and clip before this device is drawn 189 * Called with the correct matrix and clip before this device is drawn
226 * to using those settings. If your subclass overrides this, be sure to 190 * to using those settings. If your subclass overrides this, be sure to
227 * call through to the base class as well. 191 * call through to the base class as well.
228 * 192 *
229 * The clipstack is another view of the clip. It records the actual 193 * The clipstack is another view of the clip. It records the actual
230 * geometry that went into building the region. It is present for devices 194 * geometry that went into building the region. It is present for devices
231 * that want to parse it, but is not required: the region is a complete 195 * that want to parse it, but is not required: the region is a complete
232 * picture of the current clip. (i.e. if you regionize all of the geometry 196 * picture of the current clip. (i.e. if you regionize all of the geometry
233 * in the clipstack, you will arrive at an equivalent region to the one 197 * in the clipstack, you will arrive at an equivalent region to the one
234 * passed in). 198 * passed in).
235 */ 199 */
236 virtual void setMatrixClip(const SkMatrix&, const SkRegion&, 200 virtual void setMatrixClip(const SkMatrix&, const SkRegion&,
237 const SkClipStack&); 201 const SkClipStack&) {};
238 202
239 /** Clears the entire device to the specified color (including alpha). 203 /** Clears the entire device to the specified color (including alpha).
240 * Ignores the clip. 204 * Ignores the clip.
241 */ 205 */
242 virtual void clear(SkColor color); 206 virtual void clear(SkColor color) = 0;
243 207
244 /** 208 /**
245 * Deprecated name for clear. 209 * Deprecated name for clear.
246 */ 210 */
247 void eraseColor(SkColor eraseColor) { this->clear(eraseColor); } 211 void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
248 212
249 /** These are called inside the per-device-layer loop for each draw call. 213 /** These are called inside the per-device-layer loop for each draw call.
250 When these are called, we have already applied any saveLayer operations, 214 When these are called, we have already applied any saveLayer operations,
251 and are handling any looping from the paint, and any effects from the 215 and are handling any looping from the paint, and any effects from the
252 DrawFilter. 216 DrawFilter.
253 */ 217 */
254 virtual void drawPaint(const SkDraw&, const SkPaint& paint); 218 virtual void drawPaint(const SkDraw&, const SkPaint& paint) = 0;
255 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun t, 219 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun t,
256 const SkPoint[], const SkPaint& paint); 220 const SkPoint[], const SkPaint& paint) = 0;
257 virtual void drawRect(const SkDraw&, const SkRect& r, 221 virtual void drawRect(const SkDraw&, const SkRect& r,
258 const SkPaint& paint); 222 const SkPaint& paint) = 0;
259 virtual void drawOval(const SkDraw&, const SkRect& oval, 223 virtual void drawOval(const SkDraw&, const SkRect& oval,
260 const SkPaint& paint); 224 const SkPaint& paint) = 0;
261 virtual void drawRRect(const SkDraw&, const SkRRect& rr, 225 virtual void drawRRect(const SkDraw&, const SkRRect& rr,
262 const SkPaint& paint); 226 const SkPaint& paint) = 0;
263 227
264 /** 228 /**
265 * If pathIsMutable, then the implementation is allowed to cast path to a 229 * If pathIsMutable, then the implementation is allowed to cast path to a
266 * non-const pointer and modify it in place (as an optimization). Canvas 230 * non-const pointer and modify it in place (as an optimization). Canvas
267 * may do this to implement helpers such as drawOval, by placing a temp 231 * may do this to implement helpers such as drawOval, by placing a temp
268 * path on the stack to hold the representation of the oval. 232 * path on the stack to hold the representation of the oval.
269 * 233 *
270 * If prePathMatrix is not null, it should logically be applied before any 234 * If prePathMatrix is not null, it should logically be applied before any
271 * stroking or other effects. If there are no effects on the paint that 235 * stroking or other effects. If there are no effects on the paint that
272 * affect the geometry/rasterization, then the pre matrix can just be 236 * affect the geometry/rasterization, then the pre matrix can just be
273 * pre-concated with the current matrix. 237 * pre-concated with the current matrix.
274 */ 238 */
275 virtual void drawPath(const SkDraw&, const SkPath& path, 239 virtual void drawPath(const SkDraw&, const SkPath& path,
276 const SkPaint& paint, 240 const SkPaint& paint,
277 const SkMatrix* prePathMatrix = NULL, 241 const SkMatrix* prePathMatrix = NULL,
278 bool pathIsMutable = false); 242 bool pathIsMutable = false) = 0;
279 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, 243 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
280 const SkMatrix& matrix, const SkPaint& paint); 244 const SkMatrix& matrix, const SkPaint& paint) = 0;
281 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, 245 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
282 int x, int y, const SkPaint& paint); 246 int x, int y, const SkPaint& paint) = 0;
283 247
284 /** 248 /**
285 * The default impl. will create a bitmap-shader from the bitmap, 249 * The default impl. will create a bitmap-shader from the bitmap,
286 * and call drawRect with it. 250 * and call drawRect with it.
287 */ 251 */
288 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, 252 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
289 const SkRect* srcOrNull, const SkRect& dst, 253 const SkRect* srcOrNull, const SkRect& dst,
290 const SkPaint& paint, 254 const SkPaint& paint,
291 SkCanvas::DrawBitmapRectFlags flags); 255 SkCanvas::DrawBitmapRectFlags flags) = 0;
292 256
293 /** 257 /**
294 * Does not handle text decoration. 258 * Does not handle text decoration.
295 * Decorations (underline and stike-thru) will be handled by SkCanvas. 259 * Decorations (underline and stike-thru) will be handled by SkCanvas.
296 */ 260 */
297 virtual void drawText(const SkDraw&, const void* text, size_t len, 261 virtual void drawText(const SkDraw&, const void* text, size_t len,
298 SkScalar x, SkScalar y, const SkPaint& paint); 262 SkScalar x, SkScalar y, const SkPaint& paint) = 0;
299 virtual void drawPosText(const SkDraw&, const void* text, size_t len, 263 virtual void drawPosText(const SkDraw&, const void* text, size_t len,
300 const SkScalar pos[], SkScalar constY, 264 const SkScalar pos[], SkScalar constY,
301 int scalarsPerPos, const SkPaint& paint); 265 int scalarsPerPos, const SkPaint& paint) = 0;
302 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, 266 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
303 const SkPath& path, const SkMatrix* matrix, 267 const SkPath& path, const SkMatrix* matrix,
304 const SkPaint& paint); 268 const SkPaint& paint) = 0;
305 #ifdef SK_BUILD_FOR_ANDROID 269 #ifdef SK_BUILD_FOR_ANDROID
306 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, 270 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
307 const SkPoint pos[], const SkPaint& paint, 271 const SkPoint pos[], const SkPaint& paint,
308 const SkPath& path, const SkMatrix* matrix); 272 const SkPath& path, const SkMatrix* matrix) = 0;
309 #endif 273 #endif
310 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt, 274 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt,
311 const SkPoint verts[], const SkPoint texs[], 275 const SkPoint verts[], const SkPoint texs[],
312 const SkColor colors[], SkXfermode* xmode, 276 const SkColor colors[], SkXfermode* xmode,
313 const uint16_t indices[], int indexCount, 277 const uint16_t indices[], int indexCount,
314 const SkPaint& paint); 278 const SkPaint& paint) = 0;
315 /** The SkDevice passed will be an SkDevice which was returned by a call to 279 /** The SkDevice passed will be an SkDevice which was returned by a call to
316 onCreateCompatibleDevice on this device with kSaveLayer_Usage. 280 onCreateCompatibleDevice on this device with kSaveLayer_Usage.
317 */ 281 */
318 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, 282 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
319 const SkPaint&); 283 const SkPaint&) = 0;
320 284
321 /** 285 /**
322 * On success (returns true), copy the device pixels into the bitmap. 286 * On success (returns true), copy the device pixels into the bitmap.
323 * On failure, the bitmap parameter is left unchanged and false is 287 * On failure, the bitmap parameter is left unchanged and false is
324 * returned. 288 * returned.
325 * 289 *
326 * The device's pixels are converted to the bitmap's config. The only 290 * The device's pixels are converted to the bitmap's config. The only
327 * supported config is kARGB_8888_Config, though this is likely to be 291 * supported config is kARGB_8888_Config, though this is likely to be
328 * relaxed in the future. The meaning of config kARGB_8888_Config is 292 * relaxed in the future. The meaning of config kARGB_8888_Config is
329 * modified by the enum param config8888. The default value interprets 293 * modified by the enum param config8888. The default value interprets
(...skipping 15 matching lines...) Expand all
345 * * If bitmap is texture-backed then readPixels will fail. (This may be 309 * * If bitmap is texture-backed then readPixels will fail. (This may be
346 * relaxed in the future.) 310 * relaxed in the future.)
347 */ 311 */
348 bool readPixels(SkBitmap* bitmap, 312 bool readPixels(SkBitmap* bitmap,
349 int x, int y, 313 int x, int y,
350 SkCanvas::Config8888 config8888); 314 SkCanvas::Config8888 config8888);
351 315
352 /////////////////////////////////////////////////////////////////////////// 316 ///////////////////////////////////////////////////////////////////////////
353 317
354 /** Update as needed the pixel value in the bitmap, so that the caller can 318 /** Update as needed the pixel value in the bitmap, so that the caller can
355 access the pixels directly. Note: only the pixels field should be 319 access the pixels directly.
356 altered. The config/width/height/rowbytes must remain unchanged. 320 @return The device contents as a bitmap
357 @param bitmap The device's bitmap
358 @return Echo the bitmap parameter, or an alternate (shadow) bitmap
359 maintained by the subclass.
360 */ 321 */
361 virtual const SkBitmap& onAccessBitmap(SkBitmap*); 322 virtual const SkBitmap& onAccessBitmap() = 0;
362
363 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
364 // just for subclasses, to assign a custom pixelref
365 SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) {
366 fBitmap.setPixelRef(pr, offset);
367 return pr;
368 }
369 323
370 /** 324 /**
371 * Implements readPixels API. The caller will ensure that: 325 * Implements readPixels API. The caller will ensure that:
372 * 1. bitmap has pixel config kARGB_8888_Config. 326 * 1. bitmap has pixel config kARGB_8888_Config.
373 * 2. bitmap has pixels. 327 * 2. bitmap has pixels.
374 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is 328 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
375 * contained in the device bounds. 329 * contained in the device bounds.
376 */ 330 */
377 virtual bool onReadPixels(const SkBitmap& bitmap, 331 virtual bool onReadPixels(const SkBitmap& bitmap,
378 int x, int y, 332 int x, int y,
379 SkCanvas::Config8888 config8888); 333 SkCanvas::Config8888 config8888) = 0;
380 334
381 /** Called when this device is installed into a Canvas. Balanaced by a call 335 /** Called when this device is installed into a Canvas. Balanaced by a call
382 to unlockPixels() when the device is removed from a Canvas. 336 to unlockPixels() when the device is removed from a Canvas.
383 */ 337 */
384 virtual void lockPixels(); 338 virtual void lockPixels() = 0;
385 virtual void unlockPixels(); 339 virtual void unlockPixels() = 0;
386 340
387 /** 341 /**
388 * Returns true if the device allows processing of this imagefilter. If 342 * Returns true if the device allows processing of this imagefilter. If
389 * false is returned, then the filter is ignored. This may happen for 343 * false is returned, then the filter is ignored. This may happen for
390 * some subclasses that do not support pixel manipulations after drawing 344 * some subclasses that do not support pixel manipulations after drawing
391 * has occurred (e.g. printing). The default implementation returns true. 345 * has occurred (e.g. printing). The default implementation returns true.
392 */ 346 */
393 virtual bool allowImageFilter(SkImageFilter*); 347 virtual bool allowImageFilter(SkImageFilter*) = 0;
394 348
395 /** 349 /**
396 * Override and return true for filters that the device can handle 350 * Override and return true for filters that the device can handle
397 * intrinsically. Doing so means that SkCanvas will pass-through this 351 * intrinsically. Doing so means that SkCanvas will pass-through this
398 * filter to drawSprite and drawDevice (and potentially filterImage). 352 * filter to drawSprite and drawDevice (and potentially filterImage).
399 * Returning false means the SkCanvas will have apply the filter itself, 353 * Returning false means the SkCanvas will have apply the filter itself,
400 * and just pass the resulting image to the device. 354 * and just pass the resulting image to the device.
401 */ 355 */
402 virtual bool canHandleImageFilter(SkImageFilter*); 356 virtual bool canHandleImageFilter(SkImageFilter*) = 0;
403 357
404 /** 358 /**
405 * Related (but not required) to canHandleImageFilter, this method returns 359 * Related (but not required) to canHandleImageFilter, this method returns
406 * true if the device could apply the filter to the src bitmap and return 360 * true if the device could apply the filter to the src bitmap and return
407 * the result (and updates offset as needed). 361 * the result (and updates offset as needed).
408 * If the device does not recognize or support this filter, 362 * If the device does not recognize or support this filter,
409 * it just returns false and leaves result and offset unchanged. 363 * it just returns false and leaves result and offset unchanged.
410 */ 364 */
411 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, 365 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&,
412 SkBitmap* result, SkIPoint* offset); 366 SkBitmap* result, SkIPoint* offset) = 0;
413 367
414 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if 368 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
415 // either is identical to kNative_Premul_Config8888. Otherwise, -1. 369 // either is identical to kNative_Premul_Config8888. Otherwise, -1.
416 static const SkCanvas::Config8888 kPMColorAlias; 370 static const SkCanvas::Config8888 kPMColorAlias;
417 371
418 private: 372 private:
419 friend class SkCanvas; 373 friend class SkCanvas;
420 friend struct DeviceCM; //for setMatrixClip 374 friend struct DeviceCM; //for setMatrixClip
421 friend class SkDraw; 375 friend class SkDraw;
422 friend class SkDrawIter; 376 friend class SkDrawIter;
423 friend class SkDeviceFilteredPaint; 377 friend class SkDeviceFilteredPaint;
424 friend class SkDeviceImageFilterProxy; 378 friend class SkDeviceImageFilterProxy;
425 379
426 friend class SkSurface_Raster; 380 friend class SkSurface_Raster;
381
427 // used to change the backend's pixels (and possibly config/rowbytes) 382 // used to change the backend's pixels (and possibly config/rowbytes)
428 // but cannot change the width/height, so there should be no change to 383 // but cannot change the width/height, so there should be no change to
429 // any clip information. 384 // any clip information.
430 void replaceBitmapBackendForRasterSurface(const SkBitmap&); 385 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0;
431 386
432 // just called by SkCanvas when built as a layer 387 // just called by SkCanvas when built as a layer
433 void setOrigin(int x, int y) { fOrigin.set(x, y); } 388 void setOrigin(int x, int y) { fOrigin.set(x, y); }
434 // just called by SkCanvas for saveLayer 389 // just called by SkCanvas for saveLayer
435 SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, 390 SkBaseDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
436 int width, int height, 391 int width, int height,
437 bool isOpaque); 392 bool isOpaque);
438 393
439 /** 394 /**
440 * Subclasses should override this to implement createCompatibleDevice. 395 * Subclasses should override this to implement createCompatibleDevice.
441 */ 396 */
442 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, 397 virtual SkBaseDevice* onCreateCompatibleDevice(SkBitmap::Config config,
443 int width, int height, 398 int width, int height,
444 bool isOpaque, 399 bool isOpaque,
445 Usage usage); 400 Usage usage) = 0;
446 401
447 /** Causes any deferred drawing to the device to be completed. 402 /** Causes any deferred drawing to the device to be completed.
448 */ 403 */
449 virtual void flush() {} 404 virtual void flush() = 0;
450 405
451 SkBitmap fBitmap;
452 SkIPoint fOrigin; 406 SkIPoint fOrigin;
453 SkMetaData* fMetaData; 407 SkMetaData* fMetaData;
454 /** 408 /**
455 * Leaky properties are those which the device should be applying but it is n't. 409 * Leaky properties are those which the device should be applying but it is n't.
456 * These properties will be applied by the draw, when and as it can. 410 * These properties will be applied by the draw, when and as it can.
457 * If the device does handle a property, that property should be set to the identity value 411 * If the device does handle a property, that property should be set to the identity value
458 * for that property, effectively making it non-leaky. 412 * for that property, effectively making it non-leaky.
459 */ 413 */
460 SkDeviceProperties fLeakyProperties; 414 SkDeviceProperties fLeakyProperties;
461 415
462 #ifdef SK_DEBUG 416 #ifdef SK_DEBUG
463 bool fAttachedToCanvas; 417 bool fAttachedToCanvas;
464 #endif 418 #endif
465 419
466 typedef SkRefCnt INHERITED; 420 typedef SkRefCnt INHERITED;
467 }; 421 };
468 422
469 typedef SkDevice SkBaseDevice;
470
471 #endif 423 #endif
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | include/core/SkDraw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698