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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 */ | 118 */ |
119 virtual void onDetachFromCanvas() { | 119 virtual void onDetachFromCanvas() { |
120 SkASSERT(fAttachedToCanvas); | 120 SkASSERT(fAttachedToCanvas); |
121 this->unlockPixels(); | 121 this->unlockPixels(); |
122 #ifdef SK_DEBUG | 122 #ifdef SK_DEBUG |
123 fAttachedToCanvas = false; | 123 fAttachedToCanvas = false; |
124 #endif | 124 #endif |
125 }; | 125 }; |
126 | 126 |
127 protected: | 127 protected: |
128 enum Usage { | 128 enum TileUsage { |
129 kGeneral_Usage, | 129 kPossible_TileUsage, //!< the created device may be drawn tiled |
130 kSaveLayer_Usage, // <! internal use only | 130 kNever_TileUsage, //!< the created device will never be drawn tile
d |
131 kImageFilter_Usage // <! internal use only | |
132 }; | 131 }; |
133 | 132 |
134 struct TextFlags { | 133 struct TextFlags { |
135 uint32_t fFlags; // SkPaint::getFlags() | 134 uint32_t fFlags; // SkPaint::getFlags() |
136 }; | 135 }; |
137 | 136 |
138 /** | 137 /** |
139 * Returns the text-related flags, possibly modified based on the state of t
he | 138 * Returns the text-related flags, possibly modified based on the state of t
he |
140 * device (e.g. support for LCD). | 139 * device (e.g. support for LCD). |
141 */ | 140 */ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const SkColor colors[], SkXfermode* xmode, | 223 const SkColor colors[], SkXfermode* xmode, |
225 const uint16_t indices[], int indexCount, | 224 const uint16_t indices[], int indexCount, |
226 const SkPaint& paint) = 0; | 225 const SkPaint& paint) = 0; |
227 // default implementation unrolls the blob runs. | 226 // default implementation unrolls the blob runs. |
228 virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkSc
alar y, | 227 virtual void drawTextBlob(const SkDraw&, const SkTextBlob*, SkScalar x, SkSc
alar y, |
229 const SkPaint& paint, SkDrawFilter* drawFilter); | 228 const SkPaint& paint, SkDrawFilter* drawFilter); |
230 // default implementation calls drawVertices | 229 // default implementation calls drawVertices |
231 virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColo
r colors[4], | 230 virtual void drawPatch(const SkDraw&, const SkPoint cubics[12], const SkColo
r colors[4], |
232 const SkPoint texCoords[4], SkXfermode* xmode, const
SkPaint& paint); | 231 const SkPoint texCoords[4], SkXfermode* xmode, const
SkPaint& paint); |
233 /** The SkDevice passed will be an SkDevice which was returned by a call to | 232 /** The SkDevice passed will be an SkDevice which was returned by a call to |
234 onCreateCompatibleDevice on this device with kSaveLayer_Usage. | 233 onCreateDevice on this device with kNeverTile_TileExpectation. |
235 */ | 234 */ |
236 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, | 235 virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, |
237 const SkPaint&) = 0; | 236 const SkPaint&) = 0; |
238 | 237 |
239 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, con
st SkPath&, | 238 virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len, con
st SkPath&, |
240 const SkMatrix*, const SkPaint&); | 239 const SkMatrix*, const SkPaint&); |
241 bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y
); | 240 bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y
); |
242 | 241 |
243 /////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////// |
244 | 243 |
245 /** Update as needed the pixel value in the bitmap, so that the caller can | 244 /** Update as needed the pixel value in the bitmap, so that the caller can |
246 access the pixels directly. | 245 access the pixels directly. |
247 @return The device contents as a bitmap | 246 @return The device contents as a bitmap |
248 */ | 247 */ |
249 virtual const SkBitmap& onAccessBitmap() = 0; | 248 virtual const SkBitmap& onAccessBitmap() = 0; |
250 | 249 |
251 /** Called when this device is installed into a Canvas. Balanced by a call | 250 /** Called when this device is installed into a Canvas. Balanced by a call |
252 to unlockPixels() when the device is removed from a Canvas. | 251 to unlockPixels() when the device is removed from a Canvas. |
253 */ | 252 */ |
254 virtual void lockPixels() {} | 253 virtual void lockPixels() {} |
255 virtual void unlockPixels() {} | 254 virtual void unlockPixels() {} |
256 | 255 |
257 /** | 256 /** |
258 * Returns true if the device allows processing of this imagefilter. If | |
259 * false is returned, then the filter is ignored. This may happen for | |
260 * some subclasses that do not support pixel manipulations after drawing | |
261 * has occurred (e.g. printing). The default implementation returns true. | |
262 */ | |
263 virtual bool allowImageFilter(const SkImageFilter*) { return true; } | |
264 | |
265 /** | |
266 * Override and return true for filters that the device can handle | 257 * Override and return true for filters that the device can handle |
267 * intrinsically. Doing so means that SkCanvas will pass-through this | 258 * intrinsically. Doing so means that SkCanvas will pass-through this |
268 * filter to drawSprite and drawDevice (and potentially filterImage). | 259 * filter to drawSprite and drawDevice (and potentially filterImage). |
269 * Returning false means the SkCanvas will have apply the filter itself, | 260 * Returning false means the SkCanvas will have apply the filter itself, |
270 * and just pass the resulting image to the device. | 261 * and just pass the resulting image to the device. |
271 */ | 262 */ |
272 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } | 263 virtual bool canHandleImageFilter(const SkImageFilter*) { return false; } |
273 | 264 |
274 /** | 265 /** |
275 * Related (but not required) to canHandleImageFilter, this method returns | 266 * Related (but not required) to canHandleImageFilter, this method returns |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 * 'optimize' call) this entry point should make use of it and return true | 320 * 'optimize' call) this entry point should make use of it and return true |
330 * if all rendering has been done. If false is returned, SkCanvas will | 321 * if all rendering has been done. If false is returned, SkCanvas will |
331 * perform its own rendering pass. It is acceptable for the backend | 322 * perform its own rendering pass. It is acceptable for the backend |
332 * to perform some device-specific warm up tasks and then let SkCanvas | 323 * to perform some device-specific warm up tasks and then let SkCanvas |
333 * perform the main rendering loop (by return false from here). | 324 * perform the main rendering loop (by return false from here). |
334 */ | 325 */ |
335 virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkM
atrix*, | 326 virtual bool EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const SkM
atrix*, |
336 const SkPaint*); | 327 const SkPaint*); |
337 | 328 |
338 struct CreateInfo { | 329 struct CreateInfo { |
339 static SkPixelGeometry AdjustGeometry(const SkImageInfo&, Usage, SkPixel
Geometry geo); | 330 static SkPixelGeometry AdjustGeometry(const SkImageInfo&, TileUsage, SkP
ixelGeometry); |
340 | 331 |
341 // The construct may change the pixel geometry based on usage as needed. | 332 // The constructor may change the pixel geometry based on other paramete
rs. |
342 CreateInfo(const SkImageInfo& info, Usage usage, SkPixelGeometry geo) | 333 CreateInfo(const SkImageInfo& info, TileUsage tileUsage, SkPixelGeometry
geo) |
343 : fInfo(info) | 334 : fInfo(info) |
344 , fUsage(usage) | 335 , fTileUsage(tileUsage) |
345 , fPixelGeometry(AdjustGeometry(info, usage, geo)) | 336 , fPixelGeometry(AdjustGeometry(info, tileUsage, geo)) |
346 {} | 337 {} |
347 | 338 |
348 const SkImageInfo fInfo; | 339 const SkImageInfo fInfo; |
349 const Usage fUsage; | 340 const TileUsage fTileUsage; |
350 const SkPixelGeometry fPixelGeometry; | 341 const SkPixelGeometry fPixelGeometry; |
351 }; | 342 }; |
352 | 343 |
| 344 #ifdef SK_SUPPORT_LEGACY_ONCREATECOMPATIBLEDEVICE |
| 345 // legacy method name -- please override onCreateDevice instead |
353 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) { | 346 virtual SkBaseDevice* onCreateCompatibleDevice(const CreateInfo&) { |
354 return NULL; | 347 return NULL; |
355 } | 348 } |
356 | 349 |
| 350 virtual SkBaseDevice* onCreateDevice(const CreateInfo& cinfo, const SkPaint*
layerPaint) { |
| 351 return this->onCreateCompatibleDevice(cinfo); |
| 352 } |
| 353 #else |
| 354 /** |
| 355 * Create a new device based on CreateInfo. If the paint is not null, then
it represents a |
| 356 * preview of how the new device will be composed with its creator device (
this). |
| 357 */ |
| 358 virtual SkBaseDevice* onCreateDevice(const CreateInfo&, const SkPaint*) { |
| 359 return NULL; |
| 360 } |
| 361 #endif |
| 362 |
357 virtual void initForRootLayer(SkPixelGeometry geo); | 363 virtual void initForRootLayer(SkPixelGeometry geo); |
358 | 364 |
359 private: | 365 private: |
360 friend class SkCanvas; | 366 friend class SkCanvas; |
361 friend struct DeviceCM; //for setMatrixClip | 367 friend struct DeviceCM; //for setMatrixClip |
362 friend class SkDraw; | 368 friend class SkDraw; |
363 friend class SkDrawIter; | 369 friend class SkDrawIter; |
364 friend class SkDeviceFilteredPaint; | 370 friend class SkDeviceFilteredPaint; |
365 friend class SkDeviceImageFilterProxy; | 371 friend class SkDeviceImageFilterProxy; |
366 friend class SkDeferredDevice; // for newSurface | 372 friend class SkDeferredDevice; // for newSurface |
(...skipping 23 matching lines...) Expand all Loading... |
390 SkDeviceProperties* fLeakyProperties; // will always exist. | 396 SkDeviceProperties* fLeakyProperties; // will always exist. |
391 | 397 |
392 #ifdef SK_DEBUG | 398 #ifdef SK_DEBUG |
393 bool fAttachedToCanvas; | 399 bool fAttachedToCanvas; |
394 #endif | 400 #endif |
395 | 401 |
396 typedef SkRefCnt INHERITED; | 402 typedef SkRefCnt INHERITED; |
397 }; | 403 }; |
398 | 404 |
399 #endif | 405 #endif |
OLD | NEW |