OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Android Open Source Project | 2 * Copyright 2010 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkDevice_DEFINED | 8 #ifndef SkDevice_DEFINED |
9 #define SkDevice_DEFINED | 9 #define SkDevice_DEFINED |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 */ | 97 */ |
98 const SkBitmap& accessBitmap(bool changePixels); | 98 const SkBitmap& accessBitmap(bool changePixels); |
99 | 99 |
100 bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, in
t y); | 100 bool writePixels(const SkImageInfo&, const void*, size_t rowBytes, int x, in
t y); |
101 | 101 |
102 void* accessPixels(SkImageInfo* info, size_t* rowBytes); | 102 void* accessPixels(SkImageInfo* info, size_t* rowBytes); |
103 | 103 |
104 /** | 104 /** |
105 * Return the device's associated gpu render target, or NULL. | 105 * Return the device's associated gpu render target, or NULL. |
106 */ | 106 */ |
107 virtual GrRenderTarget* accessRenderTarget() = 0; | 107 virtual GrRenderTarget* accessRenderTarget() { return NULL; } |
108 | 108 |
109 | 109 |
110 /** | 110 /** |
111 * Return the device's origin: its offset in device coordinates from | 111 * Return the device's origin: its offset in device coordinates from |
112 * the default origin in its canvas' matrix/clip | 112 * the default origin in its canvas' matrix/clip |
113 */ | 113 */ |
114 const SkIPoint& getOrigin() const { return fOrigin; } | 114 const SkIPoint& getOrigin() const { return fOrigin; } |
115 | 115 |
116 /** | 116 /** |
117 * onAttachToCanvas is invoked whenever a device is installed in a canvas | 117 * onAttachToCanvas is invoked whenever a device is installed in a canvas |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 struct TextFlags { | 150 struct TextFlags { |
151 uint32_t fFlags; // SkPaint::getFlags() | 151 uint32_t fFlags; // SkPaint::getFlags() |
152 SkPaint::Hinting fHinting; | 152 SkPaint::Hinting fHinting; |
153 }; | 153 }; |
154 | 154 |
155 /** | 155 /** |
156 * Device may filter the text flags for drawing text here. If it wants to | 156 * Device may filter the text flags for drawing text here. If it wants to |
157 * make a change to the specified values, it should write them into the | 157 * make a change to the specified values, it should write them into the |
158 * textflags parameter (output) and return true. If the paint is fine as | 158 * textflags parameter (output) and return true. If the paint is fine as |
159 * is, then ignore the textflags parameter and return false. | 159 * is, then ignore the textflags parameter and return false. |
160 * | |
161 * The baseclass SkBaseDevice filters based on its depth and blitters. | |
162 */ | 160 */ |
163 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) = 0; | 161 virtual bool filterTextFlags(const SkPaint& paint, TextFlags*) { return fals
e; } |
164 | 162 |
165 /** | 163 /** |
166 * | 164 * |
167 * DEPRECATED: This will be removed in a future change. Device subclasses | 165 * DEPRECATED: This will be removed in a future change. Device subclasses |
168 * should use the matrix and clip from the SkDraw passed to draw functions. | 166 * should use the matrix and clip from the SkDraw passed to draw functions. |
169 * | 167 * |
170 * Called with the correct matrix and clip before this device is drawn | 168 * Called with the correct matrix and clip before this device is drawn |
171 * to using those settings. If your subclass overrides this, be sure to | 169 * to using those settings. If your subclass overrides this, be sure to |
172 * call through to the base class as well. | 170 * call through to the base class as well. |
173 * | 171 * |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 264 |
267 /** Update as needed the pixel value in the bitmap, so that the caller can | 265 /** Update as needed the pixel value in the bitmap, so that the caller can |
268 access the pixels directly. | 266 access the pixels directly. |
269 @return The device contents as a bitmap | 267 @return The device contents as a bitmap |
270 */ | 268 */ |
271 virtual const SkBitmap& onAccessBitmap() = 0; | 269 virtual const SkBitmap& onAccessBitmap() = 0; |
272 | 270 |
273 /** Called when this device is installed into a Canvas. Balanced by a call | 271 /** Called when this device is installed into a Canvas. Balanced by a call |
274 to unlockPixels() when the device is removed from a Canvas. | 272 to unlockPixels() when the device is removed from a Canvas. |
275 */ | 273 */ |
276 virtual void lockPixels() = 0; | 274 virtual void lockPixels() {} |
277 virtual void unlockPixels() = 0; | 275 virtual void unlockPixels() {} |
278 | 276 |
279 /** | 277 /** |
280 * Returns true if the device allows processing of this imagefilter. If | 278 * Returns true if the device allows processing of this imagefilter. If |
281 * false is returned, then the filter is ignored. This may happen for | 279 * false is returned, then the filter is ignored. This may happen for |
282 * some subclasses that do not support pixel manipulations after drawing | 280 * some subclasses that do not support pixel manipulations after drawing |
283 * has occurred (e.g. printing). The default implementation returns true. | 281 * has occurred (e.g. printing). The default implementation returns true. |
284 */ | 282 */ |
285 virtual bool allowImageFilter(const SkImageFilter*) = 0; | 283 virtual bool allowImageFilter(const SkImageFilter*) { return true; } |
286 | 284 |
287 /** | 285 /** |
288 * Override and return true for filters that the device can handle | 286 * Override and return true for filters that the device can handle |
289 * intrinsically. Doing so means that SkCanvas will pass-through this | 287 * intrinsically. Doing so means that SkCanvas will pass-through this |
290 * filter to drawSprite and drawDevice (and potentially filterImage). | 288 * filter to drawSprite and drawDevice (and potentially filterImage). |
291 * Returning false means the SkCanvas will have apply the filter itself, | 289 * Returning false means the SkCanvas will have apply the filter itself, |
292 * and just pass the resulting image to the device. | 290 * and just pass the resulting image to the device. |
293 */ | 291 */ |
294 virtual bool canHandleImageFilter(const SkImageFilter*) = 0; | 292 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } |
295 | 293 |
296 /** | 294 /** |
297 * Related (but not required) to canHandleImageFilter, this method returns | 295 * Related (but not required) to canHandleImageFilter, this method returns |
298 * true if the device could apply the filter to the src bitmap and return | 296 * true if the device could apply the filter to the src bitmap and return |
299 * the result (and updates offset as needed). | 297 * the result (and updates offset as needed). |
300 * If the device does not recognize or support this filter, | 298 * If the device does not recognize or support this filter, |
301 * it just returns false and leaves result and offset unchanged. | 299 * it just returns false and leaves result and offset unchanged. |
302 */ | 300 */ |
303 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, | 301 virtual bool filterImage(const SkImageFilter*, const SkBitmap&, |
304 const SkImageFilter::Context& ctx, | 302 const SkImageFilter::Context& ctx, |
305 SkBitmap* result, SkIPoint* offset) = 0; | 303 SkBitmap* result, SkIPoint* offset) { |
| 304 return false; |
| 305 } |
306 | 306 |
307 protected: | 307 protected: |
308 // default impl returns NULL | 308 // default impl returns NULL |
309 virtual SkSurface* newSurface(const SkImageInfo&); | 309 virtual SkSurface* newSurface(const SkImageInfo&); |
310 | 310 |
311 // default impl returns NULL | 311 // default impl returns NULL |
312 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); | 312 virtual const void* peekPixels(SkImageInfo*, size_t* rowBytes); |
313 | 313 |
314 /** | 314 /** |
315 * The caller is responsible for "pre-clipping" the dst. The impl can assum
e that the dst | 315 * The caller is responsible for "pre-clipping" the dst. The impl can assum
e that the dst |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 friend class SkDeviceFilteredPaint; | 373 friend class SkDeviceFilteredPaint; |
374 friend class SkDeviceImageFilterProxy; | 374 friend class SkDeviceImageFilterProxy; |
375 friend class SkDeferredDevice; // for newSurface | 375 friend class SkDeferredDevice; // for newSurface |
376 | 376 |
377 friend class SkSurface_Raster; | 377 friend class SkSurface_Raster; |
378 | 378 |
379 // used to change the backend's pixels (and possibly config/rowbytes) | 379 // used to change the backend's pixels (and possibly config/rowbytes) |
380 // but cannot change the width/height, so there should be no change to | 380 // but cannot change the width/height, so there should be no change to |
381 // any clip information. | 381 // any clip information. |
382 // TODO: move to SkBitmapDevice | 382 // TODO: move to SkBitmapDevice |
383 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) = 0; | 383 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) {} |
384 | 384 |
385 // just called by SkCanvas when built as a layer | 385 // just called by SkCanvas when built as a layer |
386 void setOrigin(int x, int y) { fOrigin.set(x, y); } | 386 void setOrigin(int x, int y) { fOrigin.set(x, y); } |
387 // just called by SkCanvas for saveLayer | 387 // just called by SkCanvas for saveLayer |
388 SkBaseDevice* createCompatibleDeviceForSaveLayer(const SkImageInfo&); | 388 SkBaseDevice* createCompatibleDeviceForSaveLayer(const SkImageInfo&); |
389 | 389 |
390 virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) { | 390 virtual SkBaseDevice* onCreateDevice(const SkImageInfo&, Usage) { |
391 return NULL; | 391 return NULL; |
392 } | 392 } |
393 | 393 |
394 /** Causes any deferred drawing to the device to be completed. | 394 /** Causes any deferred drawing to the device to be completed. |
395 */ | 395 */ |
396 virtual void flush() = 0; | 396 virtual void flush() {} |
397 | 397 |
398 SkIPoint fOrigin; | 398 SkIPoint fOrigin; |
399 SkMetaData* fMetaData; | 399 SkMetaData* fMetaData; |
400 | 400 |
401 #ifdef SK_DEBUG | 401 #ifdef SK_DEBUG |
402 bool fAttachedToCanvas; | 402 bool fAttachedToCanvas; |
403 #endif | 403 #endif |
404 | 404 |
405 typedef SkRefCnt INHERITED; | 405 typedef SkRefCnt INHERITED; |
406 }; | 406 }; |
407 | 407 |
408 #endif | 408 #endif |
OLD | NEW |