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