OLD | NEW |
---|---|
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 |
(...skipping 12 matching lines...) Expand all Loading... | |
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 SkDevice : public SkRefCnt { |
29 public: | 29 public: |
30 SK_DECLARE_INST_COUNT(SkDevice) | 30 SK_DECLARE_INST_COUNT(SkDevice) |
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 SkDevice(); |
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 SkDevice(const SkDeviceProperties& deviceProperties); |
45 | |
46 /** | |
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 | 41 |
78 virtual ~SkDevice(); | 42 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 SkDevice* 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 /** 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; |
reed1
2013/08/15 14:46:29
Can we remove this guy from the base?
robertphillips
2013/08/15 17:34:07
Done.
| |
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 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 SkDevice 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) = 0; |
291 | 255 |
292 /** | 256 /** |
293 * Does not handle text decoration. | 257 * Does not handle text decoration. |
294 * Decorations (underline and stike-thru) will be handled by SkCanvas. | 258 * Decorations (underline and stike-thru) will be handled by SkCanvas. |
295 */ | 259 */ |
296 virtual void drawText(const SkDraw&, const void* text, size_t len, | 260 virtual void drawText(const SkDraw&, const void* text, size_t len, |
297 SkScalar x, SkScalar y, const SkPaint& paint); | 261 SkScalar x, SkScalar y, const SkPaint& paint) = 0; |
298 virtual void drawPosText(const SkDraw&, const void* text, size_t len, | 262 virtual void drawPosText(const SkDraw&, const void* text, size_t len, |
299 const SkScalar pos[], SkScalar constY, | 263 const SkScalar pos[], SkScalar constY, |
300 int scalarsPerPos, const SkPaint& paint); | 264 int scalarsPerPos, const SkPaint& paint) = 0; |
301 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, | 265 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, |
302 const SkPath& path, const SkMatrix* matrix, | 266 const SkPath& path, const SkMatrix* matrix, |
303 const SkPaint& paint); | 267 const SkPaint& paint) = 0; |
304 #ifdef SK_BUILD_FOR_ANDROID | 268 #ifdef SK_BUILD_FOR_ANDROID |
305 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, | 269 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, |
306 const SkPoint pos[], const SkPaint& paint, | 270 const SkPoint pos[], const SkPaint& paint, |
307 const SkPath& path, const SkMatrix* matrix); | 271 const SkPath& path, const SkMatrix* matrix) = 0; |
308 #endif | 272 #endif |
309 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt, | 273 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt, |
310 const SkPoint verts[], const SkPoint texs[], | 274 const SkPoint verts[], const SkPoint texs[], |
311 const SkColor colors[], SkXfermode* xmode, | 275 const SkColor colors[], SkXfermode* xmode, |
312 const uint16_t indices[], int indexCount, | 276 const uint16_t indices[], int indexCount, |
313 const SkPaint& paint); | 277 const SkPaint& paint) = 0; |
314 /** The SkDevice passed will be an SkDevice which was returned by a call to | 278 /** The SkDevice passed will be an SkDevice which was returned by a call to |
315 onCreateCompatibleDevice on this device with kSaveLayer_Usage. | 279 onCreateCompatibleDevice on this device with kSaveLayer_Usage. |
316 */ | 280 */ |
317 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, | 281 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, |
318 const SkPaint&); | 282 const SkPaint&) = 0; |
319 | 283 |
320 /** | 284 /** |
321 * On success (returns true), copy the device pixels into the bitmap. | 285 * On success (returns true), copy the device pixels into the bitmap. |
322 * On failure, the bitmap parameter is left unchanged and false is | 286 * On failure, the bitmap parameter is left unchanged and false is |
323 * returned. | 287 * returned. |
324 * | 288 * |
325 * The device's pixels are converted to the bitmap's config. The only | 289 * The device's pixels are converted to the bitmap's config. The only |
326 * supported config is kARGB_8888_Config, though this is likely to be | 290 * supported config is kARGB_8888_Config, though this is likely to be |
327 * relaxed in the future. The meaning of config kARGB_8888_Config is | 291 * relaxed in the future. The meaning of config kARGB_8888_Config is |
328 * modified by the enum param config8888. The default value interprets | 292 * modified by the enum param config8888. The default value interprets |
(...skipping 15 matching lines...) Expand all Loading... | |
344 * * If bitmap is texture-backed then readPixels will fail. (This may be | 308 * * If bitmap is texture-backed then readPixels will fail. (This may be |
345 * relaxed in the future.) | 309 * relaxed in the future.) |
346 */ | 310 */ |
347 bool readPixels(SkBitmap* bitmap, | 311 bool readPixels(SkBitmap* bitmap, |
348 int x, int y, | 312 int x, int y, |
349 SkCanvas::Config8888 config8888); | 313 SkCanvas::Config8888 config8888); |
350 | 314 |
351 /////////////////////////////////////////////////////////////////////////// | 315 /////////////////////////////////////////////////////////////////////////// |
352 | 316 |
353 /** Update as needed the pixel value in the bitmap, so that the caller can | 317 /** Update as needed the pixel value in the bitmap, so that the caller can |
354 access the pixels directly. Note: only the pixels field should be | 318 access the pixels directly. |
355 altered. The config/width/height/rowbytes must remain unchanged. | 319 @return The device contents as a bitmap |
356 @param bitmap The device's bitmap | |
357 @return Echo the bitmap parameter, or an alternate (shadow) bitmap | |
358 maintained by the subclass. | |
359 */ | 320 */ |
360 virtual const SkBitmap& onAccessBitmap(SkBitmap*); | 321 virtual const SkBitmap& onAccessBitmap() = 0; |
361 | |
362 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | |
363 // just for subclasses, to assign a custom pixelref | |
364 SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { | |
365 fBitmap.setPixelRef(pr, offset); | |
366 return pr; | |
367 } | |
368 | 322 |
369 /** | 323 /** |
370 * Implements readPixels API. The caller will ensure that: | 324 * Implements readPixels API. The caller will ensure that: |
371 * 1. bitmap has pixel config kARGB_8888_Config. | 325 * 1. bitmap has pixel config kARGB_8888_Config. |
372 * 2. bitmap has pixels. | 326 * 2. bitmap has pixels. |
373 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is | 327 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is |
374 * contained in the device bounds. | 328 * contained in the device bounds. |
375 */ | 329 */ |
376 virtual bool onReadPixels(const SkBitmap& bitmap, | 330 virtual bool onReadPixels(const SkBitmap& bitmap, |
377 int x, int y, | 331 int x, int y, |
378 SkCanvas::Config8888 config8888); | 332 SkCanvas::Config8888 config8888) = 0; |
379 | 333 |
380 /** Called when this device is installed into a Canvas. Balanaced by a call | 334 /** Called when this device is installed into a Canvas. Balanaced by a call |
381 to unlockPixels() when the device is removed from a Canvas. | 335 to unlockPixels() when the device is removed from a Canvas. |
382 */ | 336 */ |
383 virtual void lockPixels(); | 337 virtual void lockPixels() = 0; |
384 virtual void unlockPixels(); | 338 virtual void unlockPixels() = 0; |
385 | 339 |
386 /** | 340 /** |
387 * Returns true if the device allows processing of this imagefilter. If | 341 * Returns true if the device allows processing of this imagefilter. If |
388 * false is returned, then the filter is ignored. This may happen for | 342 * false is returned, then the filter is ignored. This may happen for |
389 * some subclasses that do not support pixel manipulations after drawing | 343 * some subclasses that do not support pixel manipulations after drawing |
390 * has occurred (e.g. printing). The default implementation returns true. | 344 * has occurred (e.g. printing). The default implementation returns true. |
391 */ | 345 */ |
392 virtual bool allowImageFilter(SkImageFilter*); | 346 virtual bool allowImageFilter(SkImageFilter*) = 0; |
393 | 347 |
394 /** | 348 /** |
395 * Override and return true for filters that the device can handle | 349 * Override and return true for filters that the device can handle |
396 * intrinsically. Doing so means that SkCanvas will pass-through this | 350 * intrinsically. Doing so means that SkCanvas will pass-through this |
397 * filter to drawSprite and drawDevice (and potentially filterImage). | 351 * filter to drawSprite and drawDevice (and potentially filterImage). |
398 * Returning false means the SkCanvas will have apply the filter itself, | 352 * Returning false means the SkCanvas will have apply the filter itself, |
399 * and just pass the resulting image to the device. | 353 * and just pass the resulting image to the device. |
400 */ | 354 */ |
401 virtual bool canHandleImageFilter(SkImageFilter*); | 355 virtual bool canHandleImageFilter(SkImageFilter*) = 0; |
402 | 356 |
403 /** | 357 /** |
404 * Related (but not required) to canHandleImageFilter, this method returns | 358 * Related (but not required) to canHandleImageFilter, this method returns |
405 * true if the device could apply the filter to the src bitmap and return | 359 * true if the device could apply the filter to the src bitmap and return |
406 * the result (and updates offset as needed). | 360 * the result (and updates offset as needed). |
407 * If the device does not recognize or support this filter, | 361 * If the device does not recognize or support this filter, |
408 * it just returns false and leaves result and offset unchanged. | 362 * it just returns false and leaves result and offset unchanged. |
409 */ | 363 */ |
410 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, | 364 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, |
411 SkBitmap* result, SkIPoint* offset); | 365 SkBitmap* result, SkIPoint* offset) = 0; |
412 | 366 |
413 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if | 367 // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if |
414 // either is identical to kNative_Premul_Config8888. Otherwise, -1. | 368 // either is identical to kNative_Premul_Config8888. Otherwise, -1. |
415 static const SkCanvas::Config8888 kPMColorAlias; | 369 static const SkCanvas::Config8888 kPMColorAlias; |
416 | 370 |
417 private: | 371 private: |
418 friend class SkCanvas; | 372 friend class SkCanvas; |
419 friend struct DeviceCM; //for setMatrixClip | 373 friend struct DeviceCM; //for setMatrixClip |
420 friend class SkDraw; | 374 friend class SkDraw; |
421 friend class SkDrawIter; | 375 friend class SkDrawIter; |
422 friend class SkDeviceFilteredPaint; | 376 friend class SkDeviceFilteredPaint; |
423 friend class SkDeviceImageFilterProxy; | 377 friend class SkDeviceImageFilterProxy; |
424 | 378 |
425 friend class SkSurface_Raster; | 379 friend class SkSurface_Raster; |
380 | |
426 // used to change the backend's pixels (and possibly config/rowbytes) | 381 // used to change the backend's pixels (and possibly config/rowbytes) |
427 // but cannot change the width/height, so there should be no change to | 382 // but cannot change the width/height, so there should be no change to |
428 // any clip information. | 383 // any clip information. |
429 void replaceBitmapBackendForRasterSurface(const SkBitmap&); | 384 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0; |
430 | 385 |
431 // just called by SkCanvas when built as a layer | 386 // just called by SkCanvas when built as a layer |
432 void setOrigin(int x, int y) { fOrigin.set(x, y); } | 387 void setOrigin(int x, int y) { fOrigin.set(x, y); } |
433 // just called by SkCanvas for saveLayer | 388 // just called by SkCanvas for saveLayer |
434 SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, | 389 SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config, |
435 int width, int height, | 390 int width, int height, |
436 bool isOpaque); | 391 bool isOpaque); |
437 | 392 |
438 /** | 393 /** |
439 * Subclasses should override this to implement createCompatibleDevice. | 394 * Subclasses should override this to implement createCompatibleDevice. |
440 */ | 395 */ |
441 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, | 396 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, |
442 int width, int height, | 397 int width, int height, |
443 bool isOpaque, | 398 bool isOpaque, |
444 Usage usage); | 399 Usage usage) = 0; |
445 | 400 |
446 /** Causes any deferred drawing to the device to be completed. | 401 /** Causes any deferred drawing to the device to be completed. |
447 */ | 402 */ |
448 virtual void flush() {} | 403 virtual void flush() = 0; |
449 | 404 |
450 SkBitmap fBitmap; | |
451 SkIPoint fOrigin; | 405 SkIPoint fOrigin; |
452 SkMetaData* fMetaData; | 406 SkMetaData* fMetaData; |
453 /** | 407 /** |
454 * Leaky properties are those which the device should be applying but it is n't. | 408 * Leaky properties are those which the device should be applying but it is n't. |
455 * These properties will be applied by the draw, when and as it can. | 409 * These properties will be applied by the draw, when and as it can. |
456 * If the device does handle a property, that property should be set to the identity value | 410 * If the device does handle a property, that property should be set to the identity value |
457 * for that property, effectively making it non-leaky. | 411 * for that property, effectively making it non-leaky. |
458 */ | 412 */ |
459 SkDeviceProperties fLeakyProperties; | 413 SkDeviceProperties fLeakyProperties; |
460 | 414 |
461 #ifdef SK_DEBUG | 415 #ifdef SK_DEBUG |
462 bool fAttachedToCanvas; | 416 bool fAttachedToCanvas; |
463 #endif | 417 #endif |
464 | 418 |
465 typedef SkRefCnt INHERITED; | 419 typedef SkRefCnt INHERITED; |
466 }; | 420 }; |
467 | 421 |
422 /////////////////////////////////////////////////////////////////////////////// | |
423 class SK_API SkRasterDevice : public SkDevice { | |
424 public: | |
425 SK_DECLARE_INST_COUNT(SkRasterDevice) | |
426 | |
427 /** | |
428 * Construct a new device with the specified bitmap as its backend. It is | |
429 * valid for the bitmap to have no pixels associated with it. In that case, | |
430 * any drawing to this device will have no effect. | |
431 */ | |
432 SkRasterDevice(const SkBitmap& bitmap); | |
433 | |
434 /** | |
435 * Construct a new device with the specified bitmap as its backend. It is | |
436 * valid for the bitmap to have no pixels associated with it. In that case, | |
437 * any drawing to this device will have no effect. | |
438 */ | |
439 SkRasterDevice(const SkBitmap& bitmap, const SkDeviceProperties& devicePrope rties); | |
440 | |
441 /** | |
442 * Create a new raster device and have the pixels be automatically | |
443 * allocated. The rowBytes of the device will be computed automatically | |
444 * based on the config and the width. | |
445 * | |
446 * @param config The desired config for the pixels. If the request cannot | |
447 * be met, the closest matching support config will be used . | |
448 * @param width width (in pixels) of the device | |
449 * @param height height (in pixels) of the device | |
450 * @param isOpaque Set to true if it is known that all of the pixels will | |
451 * be drawn to opaquely. Used as an accelerator when drawin g | |
452 * these pixels to another device. | |
453 */ | |
454 SkRasterDevice(SkBitmap::Config config, int width, int height, bool isOpaque ); | |
455 | |
456 /** | |
457 * Create a new raster device and have the pixels be automatically | |
458 * allocated. The rowBytes of the device will be computed automatically | |
459 * based on the config and the width. | |
460 * | |
461 * @param config The desired config for the pixels. If the request cannot | |
462 * be met, the closest matching support config will be used . | |
463 * @param width width (in pixels) of the device | |
464 * @param height height (in pixels) of the device | |
465 * @param isOpaque Set to true if it is known that all of the pixels will | |
466 * be drawn to opaquely. Used as an accelerator when drawin g | |
467 * these pixels to another device. | |
468 * @param deviceProperties Properties which affect compositing. | |
469 */ | |
470 SkRasterDevice(SkBitmap::Config config, int width, int height, bool isOpaque , | |
471 const SkDeviceProperties& deviceProperties); | |
472 | |
473 virtual ~SkRasterDevice(); | |
474 | |
475 virtual uint32_t getDeviceCapabilities() SK_OVERRIDE { return 0; } | |
476 | |
477 /** Return the width of the device (in pixels). | |
478 */ | |
479 virtual int width() const SK_OVERRIDE { return fBitmap.width(); } | |
480 /** Return the height of the device (in pixels). | |
481 */ | |
482 virtual int height() const SK_OVERRIDE { return fBitmap.height(); } | |
483 | |
484 /** | |
485 * Return the bounds of the device in the coordinate space of the root | |
486 * canvas. The root device will have its top-left at 0,0, but other devices | |
487 * such as those associated with saveLayer may have a non-zero origin. | |
488 */ | |
489 virtual void getGlobalBounds(SkIRect* bounds) const SK_OVERRIDE; | |
490 | |
491 /** Returns true if the device's bitmap's config treats every pixels as | |
492 implicitly opaque. | |
493 */ | |
494 virtual bool isOpaque() const SK_OVERRIDE { return fBitmap.isOpaque(); } | |
495 | |
496 /** Return the bitmap config of the device's pixels | |
497 */ | |
498 virtual SkBitmap::Config config() const SK_OVERRIDE { return fBitmap.getConf ig(); } | |
499 | |
500 /** | |
501 * DEPRECATED: This will be made protected once WebKit stops using it. | |
502 * Instead use Canvas' writePixels method. | |
503 * | |
504 * Similar to draw sprite, this method will copy the pixels in bitmap onto | |
505 * the device, with the top/left corner specified by (x, y). The pixel | |
506 * values in the device are completely replaced: there is no blending. | |
507 * | |
508 * Currently if bitmap is backed by a texture this is a no-op. This may be | |
509 * relaxed in the future. | |
510 * | |
511 * If the bitmap has config kARGB_8888_Config then the config8888 param | |
512 * will determines how the pixel valuess are intepreted. If the bitmap is | |
513 * not kARGB_8888_Config then this parameter is ignored. | |
514 */ | |
515 virtual void writePixels(const SkBitmap& bitmap, int x, int y, | |
516 SkCanvas::Config8888 config8888) SK_OVERRIDE; | |
517 | |
518 /** | |
519 * Return the device's associated gpu render target, or NULL. | |
520 */ | |
521 virtual GrRenderTarget* accessRenderTarget() SK_OVERRIDE { return NULL; } | |
522 | |
523 protected: | |
524 /** | |
525 * Device may filter the text flags for drawing text here. If it wants to | |
526 * make a change to the specified values, it should write them into the | |
527 * textflags parameter (output) and return true. If the paint is fine as | |
528 * is, then ignore the textflags parameter and return false. | |
529 * | |
530 * The baseclass SkDevice filters based on its depth and blitters. | |
531 */ | |
532 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) SK_OVERRIDE; | |
533 | |
534 /** Clears the entire device to the specified color (including alpha). | |
535 * Ignores the clip. | |
536 */ | |
537 virtual void clear(SkColor color) SK_OVERRIDE; | |
538 | |
539 /** These are called inside the per-device-layer loop for each draw call. | |
540 When these are called, we have already applied any saveLayer operations, | |
541 and are handling any looping from the paint, and any effects from the | |
542 DrawFilter. | |
543 */ | |
544 virtual void drawPaint(const SkDraw&, const SkPaint& paint) SK_OVERRIDE; | |
545 virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t coun t, | |
546 const SkPoint[], const SkPaint& paint) SK_OVERRIDE; | |
547 virtual void drawRect(const SkDraw&, const SkRect& r, | |
548 const SkPaint& paint) SK_OVERRIDE; | |
549 virtual void drawOval(const SkDraw&, const SkRect& oval, | |
550 const SkPaint& paint) SK_OVERRIDE; | |
551 virtual void drawRRect(const SkDraw&, const SkRRect& rr, | |
552 const SkPaint& paint) SK_OVERRIDE; | |
553 | |
554 /** | |
555 * If pathIsMutable, then the implementation is allowed to cast path to a | |
556 * non-const pointer and modify it in place (as an optimization). Canvas | |
557 * may do this to implement helpers such as drawOval, by placing a temp | |
558 * path on the stack to hold the representation of the oval. | |
559 * | |
560 * If prePathMatrix is not null, it should logically be applied before any | |
561 * stroking or other effects. If there are no effects on the paint that | |
562 * affect the geometry/rasterization, then the pre matrix can just be | |
563 * pre-concated with the current matrix. | |
564 */ | |
565 virtual void drawPath(const SkDraw&, const SkPath& path, | |
566 const SkPaint& paint, | |
567 const SkMatrix* prePathMatrix = NULL, | |
568 bool pathIsMutable = false) SK_OVERRIDE; | |
569 virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap, | |
570 const SkMatrix& matrix, const SkPaint& paint) SK_OVE RRIDE; | |
571 virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, | |
572 int x, int y, const SkPaint& paint) SK_OVERRIDE; | |
573 | |
574 /** | |
575 * The default impl. will create a bitmap-shader from the bitmap, | |
576 * and call drawRect with it. | |
577 */ | |
578 virtual void drawBitmapRect(const SkDraw&, const SkBitmap&, | |
579 const SkRect* srcOrNull, const SkRect& dst, | |
580 const SkPaint& paint) SK_OVERRIDE; | |
581 | |
582 /** | |
583 * Does not handle text decoration. | |
584 * Decorations (underline and stike-thru) will be handled by SkCanvas. | |
585 */ | |
586 virtual void drawText(const SkDraw&, const void* text, size_t len, | |
587 SkScalar x, SkScalar y, const SkPaint& paint) SK_OVERR IDE; | |
588 virtual void drawPosText(const SkDraw&, const void* text, size_t len, | |
589 const SkScalar pos[], SkScalar constY, | |
590 int scalarsPerPos, const SkPaint& paint) SK_OVERRID E; | |
591 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, | |
592 const SkPath& path, const SkMatrix* matrix, | |
593 const SkPaint& paint) SK_OVERRIDE; | |
594 #ifdef SK_BUILD_FOR_ANDROID | |
595 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len, | |
596 const SkPoint pos[], const SkPaint& paint, | |
597 const SkPath& path, const SkMatrix* matrix) S K_OVERRIDE; | |
468 #endif | 598 #endif |
599 virtual void drawVertices(const SkDraw&, SkCanvas::VertexMode, int vertexCou nt, | |
600 const SkPoint verts[], const SkPoint texs[], | |
601 const SkColor colors[], SkXfermode* xmode, | |
602 const uint16_t indices[], int indexCount, | |
603 const SkPaint& paint) SK_OVERRIDE; | |
604 /** The SkDevice passed will be an SkDevice which was returned by a call to | |
605 onCreateCompatibleDevice on this device with kSaveLayer_Usage. | |
606 */ | |
607 virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y, | |
608 const SkPaint&) SK_OVERRIDE; | |
609 | |
610 /////////////////////////////////////////////////////////////////////////// | |
611 | |
612 /** Update as needed the pixel value in the bitmap, so that the caller can | |
613 access the pixels directly. Note: only the pixels field should be | |
614 altered. The config/width/height/rowbytes must remain unchanged. | |
615 @return the device contents as a bitmap | |
616 */ | |
617 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE; | |
618 | |
619 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | |
620 // just for subclasses, to assign a custom pixelref | |
621 SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) { | |
622 fBitmap.setPixelRef(pr, offset); | |
623 return pr; | |
624 } | |
625 | |
626 /** | |
627 * Implements readPixels API. The caller will ensure that: | |
628 * 1. bitmap has pixel config kARGB_8888_Config. | |
629 * 2. bitmap has pixels. | |
630 * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is | |
631 * contained in the device bounds. | |
632 */ | |
633 virtual bool onReadPixels(const SkBitmap& bitmap, | |
634 int x, int y, | |
635 SkCanvas::Config8888 config8888) SK_OVERRIDE; | |
636 | |
637 /** Called when this device is installed into a Canvas. Balanced by a call | |
638 to unlockPixels() when the device is removed from a Canvas. | |
639 */ | |
640 virtual void lockPixels() SK_OVERRIDE; | |
641 virtual void unlockPixels() SK_OVERRIDE; | |
642 | |
643 /** | |
644 * Returns true if the device allows processing of this imagefilter. If | |
645 * false is returned, then the filter is ignored. This may happen for | |
646 * some subclasses that do not support pixel manipulations after drawing | |
647 * has occurred (e.g. printing). The default implementation returns true. | |
648 */ | |
649 virtual bool allowImageFilter(SkImageFilter*) SK_OVERRIDE; | |
650 | |
651 /** | |
652 * Override and return true for filters that the device can handle | |
653 * intrinsically. Doing so means that SkCanvas will pass-through this | |
654 * filter to drawSprite and drawDevice (and potentially filterImage). | |
655 * Returning false means the SkCanvas will have apply the filter itself, | |
656 * and just pass the resulting image to the device. | |
657 */ | |
658 virtual bool canHandleImageFilter(SkImageFilter*) SK_OVERRIDE; | |
659 | |
660 /** | |
661 * Related (but not required) to canHandleImageFilter, this method returns | |
662 * true if the device could apply the filter to the src bitmap and return | |
663 * the result (and updates offset as needed). | |
664 * If the device does not recognize or support this filter, | |
665 * it just returns false and leaves result and offset unchanged. | |
666 */ | |
667 virtual bool filterImage(SkImageFilter*, const SkBitmap&, const SkMatrix&, | |
668 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | |
669 | |
670 private: | |
671 friend class SkCanvas; | |
672 friend struct DeviceCM; //for setMatrixClip | |
673 friend class SkDraw; | |
674 friend class SkDrawIter; | |
675 friend class SkDeviceFilteredPaint; | |
676 friend class SkDeviceImageFilterProxy; | |
677 | |
678 friend class SkSurface_Raster; | |
679 | |
680 // used to change the backend's pixels (and possibly config/rowbytes) | |
681 // but cannot change the width/height, so there should be no change to | |
682 // any clip information. | |
683 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI DE; | |
684 | |
685 /** | |
686 * Subclasses should override this to implement createCompatibleDevice. | |
687 */ | |
688 virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config, | |
689 int width, int height, | |
690 bool isOpaque, | |
691 Usage usage) SK_OVERRIDE; | |
692 | |
693 /** Causes any deferred drawing to the device to be completed. | |
694 */ | |
695 virtual void flush() SK_OVERRIDE {} | |
696 | |
697 SkBitmap fBitmap; | |
698 | |
699 typedef SkDevice INHERITED; | |
700 }; | |
701 | |
702 #endif | |
OLD | NEW |