Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 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 SkCanvas_DEFINED | 8 #ifndef SkCanvas_DEFINED |
| 9 #define SkCanvas_DEFINED | 9 #define SkCanvas_DEFINED |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 class SkMetaData; | 30 class SkMetaData; |
| 31 class SkPath; | 31 class SkPath; |
| 32 class SkPicture; | 32 class SkPicture; |
| 33 class SkPixmap; | 33 class SkPixmap; |
| 34 class SkRRect; | 34 class SkRRect; |
| 35 struct SkRSXform; | 35 struct SkRSXform; |
| 36 class SkSurface; | 36 class SkSurface; |
| 37 class SkSurface_Base; | 37 class SkSurface_Base; |
| 38 class SkTextBlob; | 38 class SkTextBlob; |
| 39 | 39 |
| 40 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | |
| 41 #define SK_SUPPORT_LEGACY_SAVEFLAGS | |
|
f(malita)
2015/12/19 18:20:21
Any danger to define multiple times (do we need a
reed1
2015/12/20 03:05:45
Done.
| |
| 42 #endif | |
| 43 | |
| 40 /** \class SkCanvas | 44 /** \class SkCanvas |
| 41 | 45 |
| 42 A Canvas encapsulates all of the state about drawing into a device (bitmap). | 46 A Canvas encapsulates all of the state about drawing into a device (bitmap). |
| 43 This includes a reference to the device itself, and a stack of matrix/clip | 47 This includes a reference to the device itself, and a stack of matrix/clip |
| 44 values. For any given draw call (e.g. drawRect), the geometry of the object | 48 values. For any given draw call (e.g. drawRect), the geometry of the object |
| 45 being drawn is transformed by the concatenation of all the matrices in the | 49 being drawn is transformed by the concatenation of all the matrices in the |
| 46 stack. The transformed geometry is clipped by the intersection of all of | 50 stack. The transformed geometry is clipped by the intersection of all of |
| 47 the clips in the stack. | 51 the clips in the stack. |
| 48 | 52 |
| 49 While the Canvas holds the state of the drawing device, the state (style) | 53 While the Canvas holds the state of the drawing device, the state (style) |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); | 278 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); |
| 275 | 279 |
| 276 /** | 280 /** |
| 277 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap | 281 * Helper for calling writePixels(info, ...) by passing its pixels and rowb ytes. If the bitmap |
| 278 * is just wrapping a texture, returns false and does nothing. | 282 * is just wrapping a texture, returns false and does nothing. |
| 279 */ | 283 */ |
| 280 bool writePixels(const SkBitmap& bitmap, int x, int y); | 284 bool writePixels(const SkBitmap& bitmap, int x, int y); |
| 281 | 285 |
| 282 /////////////////////////////////////////////////////////////////////////// | 286 /////////////////////////////////////////////////////////////////////////// |
| 283 | 287 |
| 288 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 284 enum SaveFlags { | 289 enum SaveFlags { |
| 285 /** save the matrix state, restoring it on restore() */ | 290 /** save the matrix state, restoring it on restore() */ |
| 286 // [deprecated] kMatrix_SaveFlag = 0x01, | 291 // [deprecated] kMatrix_SaveFlag = 0x01, |
| 287 kMatrix_SaveFlag = 0x01, | 292 kMatrix_SaveFlag = 0x01, |
| 288 /** save the clip state, restoring it on restore() */ | 293 /** save the clip state, restoring it on restore() */ |
| 289 // [deprecated] kClip_SaveFlag = 0x02, | 294 // [deprecated] kClip_SaveFlag = 0x02, |
| 290 kClip_SaveFlag = 0x02, | 295 kClip_SaveFlag = 0x02, |
| 291 /** the layer needs to support per-pixel alpha */ | 296 /** the layer needs to support per-pixel alpha */ |
| 292 kHasAlphaLayer_SaveFlag = 0x04, | 297 kHasAlphaLayer_SaveFlag = 0x04, |
| 293 /** the layer needs to support 8-bits per color component */ | 298 /** the layer needs to support 8-bits per color component */ |
| 294 kFullColorLayer_SaveFlag = 0x08, | 299 kFullColorLayer_SaveFlag = 0x08, |
| 295 /** | 300 /** |
| 296 * the layer should clip against the bounds argument | 301 * the layer should clip against the bounds argument |
| 297 * | 302 * |
| 298 * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated a s always on. | 303 * if SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG is undefined, this is treated a s always on. |
| 299 */ | 304 */ |
| 300 kClipToLayer_SaveFlag = 0x10, | 305 kClipToLayer_SaveFlag = 0x10, |
| 301 | 306 |
| 302 // helper masks for common choices | 307 // helper masks for common choices |
| 303 // [deprecated] kMatrixClip_SaveFlag = 0x03, | 308 // [deprecated] kMatrixClip_SaveFlag = 0x03, |
| 304 kMatrixClip_SaveFlag = 0x03, | 309 kMatrixClip_SaveFlag = 0x03, |
| 305 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 310 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 306 kARGB_NoClipLayer_SaveFlag = 0x0F, | 311 kARGB_NoClipLayer_SaveFlag = 0x0F, |
| 307 #endif | 312 #endif |
| 308 kARGB_ClipLayer_SaveFlag = 0x1F | 313 kARGB_ClipLayer_SaveFlag = 0x1F |
| 309 }; | 314 }; |
| 315 #endif | |
| 310 | 316 |
| 311 /** This call saves the current matrix, clip, and drawFilter, and pushes a | 317 /** This call saves the current matrix, clip, and drawFilter, and pushes a |
| 312 copy onto a private stack. Subsequent calls to translate, scale, | 318 copy onto a private stack. Subsequent calls to translate, scale, |
| 313 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all | 319 rotate, skew, concat or clipRect, clipPath, and setDrawFilter all |
| 314 operate on this copy. | 320 operate on this copy. |
| 315 When the balancing call to restore() is made, the previous matrix, clip, | 321 When the balancing call to restore() is made, the previous matrix, clip, |
| 316 and drawFilter are restored. | 322 and drawFilter are restored. |
| 317 | 323 |
| 318 @return The value to pass to restoreToCount() to balance this save() | 324 @return The value to pass to restoreToCount() to balance this save() |
| 319 */ | 325 */ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 336 return this->saveLayer(&bounds, paint); | 342 return this->saveLayer(&bounds, paint); |
| 337 } | 343 } |
| 338 | 344 |
| 339 /** | 345 /** |
| 340 * Temporary name. | 346 * Temporary name. |
| 341 * Will allow any requests for LCD text to be respected, so the caller must be careful to | 347 * Will allow any requests for LCD text to be respected, so the caller must be careful to |
| 342 * only draw on top of opaque sections of the layer to get good results. | 348 * only draw on top of opaque sections of the layer to get good results. |
| 343 */ | 349 */ |
| 344 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int); | 350 int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* pa int); |
| 345 | 351 |
| 352 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 346 /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. | 353 /** DEPRECATED - use saveLayer(const SkRect*, const SkPaint*) instead. |
| 347 | 354 |
| 348 This behaves the same as saveLayer(const SkRect*, const SkPaint*), | 355 This behaves the same as saveLayer(const SkRect*, const SkPaint*), |
| 349 but it allows fine-grained control of which state bits to be saved | 356 but it allows fine-grained control of which state bits to be saved |
| 350 (and subsequently restored). | 357 (and subsequently restored). |
| 351 | 358 |
| 352 @param bounds (may be null) This rect, if non-null, is used as a hint to | 359 @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 353 limit the size of the offscreen, and thus drawing may be | 360 limit the size of the offscreen, and thus drawing may be |
| 354 clipped to it, though that clipping is not guaranteed to | 361 clipped to it, though that clipping is not guaranteed to |
| 355 happen. If exact clipping is desired, use clipRect(). | 362 happen. If exact clipping is desired, use clipRect(). |
| 356 @param paint (may be null) This is copied, and is applied to the | 363 @param paint (may be null) This is copied, and is applied to the |
| 357 offscreen when restore() is called | 364 offscreen when restore() is called |
| 358 @param flags LayerFlags | 365 @param flags LayerFlags |
| 359 @return The value to pass to restoreToCount() to balance this save() | 366 @return The value to pass to restoreToCount() to balance this save() |
| 360 */ | 367 */ |
| 361 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | 368 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") |
| 362 int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); | 369 int saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); |
| 370 #endif | |
| 363 | 371 |
| 364 /** This behaves the same as save(), but in addition it allocates an | 372 /** This behaves the same as save(), but in addition it allocates an |
| 365 offscreen bitmap. All drawing calls are directed there, and only when | 373 offscreen bitmap. All drawing calls are directed there, and only when |
| 366 the balancing call to restore() is made is that offscreen transfered to | 374 the balancing call to restore() is made is that offscreen transfered to |
| 367 the canvas (or the previous layer). | 375 the canvas (or the previous layer). |
| 368 @param bounds (may be null) This rect, if non-null, is used as a hint to | 376 @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 369 limit the size of the offscreen, and thus drawing may be | 377 limit the size of the offscreen, and thus drawing may be |
| 370 clipped to it, though that clipping is not guaranteed to | 378 clipped to it, though that clipping is not guaranteed to |
| 371 happen. If exact clipping is desired, use clipRect(). | 379 happen. If exact clipping is desired, use clipRect(). |
| 372 @param alpha This is applied to the offscreen when restore() is called. | 380 @param alpha This is applied to the offscreen when restore() is called. |
| 373 @return The value to pass to restoreToCount() to balance this save() | 381 @return The value to pass to restoreToCount() to balance this save() |
| 374 */ | 382 */ |
| 375 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); | 383 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha); |
| 376 | 384 |
| 385 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 377 /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. | 386 /** DEPRECATED - use saveLayerAlpha(const SkRect*, U8CPU) instead. |
| 378 | 387 |
| 379 This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), | 388 This behaves the same as saveLayerAlpha(const SkRect*, U8CPU), |
| 380 but it allows fine-grained control of which state bits to be saved | 389 but it allows fine-grained control of which state bits to be saved |
| 381 (and subsequently restored). | 390 (and subsequently restored). |
| 382 | 391 |
| 383 @param bounds (may be null) This rect, if non-null, is used as a hint to | 392 @param bounds (may be null) This rect, if non-null, is used as a hint to |
| 384 limit the size of the offscreen, and thus drawing may be | 393 limit the size of the offscreen, and thus drawing may be |
| 385 clipped to it, though that clipping is not guaranteed to | 394 clipped to it, though that clipping is not guaranteed to |
| 386 happen. If exact clipping is desired, use clipRect(). | 395 happen. If exact clipping is desired, use clipRect(). |
| 387 @param alpha This is applied to the offscreen when restore() is called. | 396 @param alpha This is applied to the offscreen when restore() is called. |
| 388 @param flags LayerFlags | 397 @param flags LayerFlags |
| 389 @return The value to pass to restoreToCount() to balance this save() | 398 @return The value to pass to restoreToCount() to balance this save() |
| 390 */ | 399 */ |
| 391 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") | 400 SK_ATTR_EXTERNALLY_DEPRECATED("SaveFlags use is deprecated") |
| 392 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); | 401 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha, SaveFlags flags); |
| 402 #endif | |
| 393 | 403 |
| 394 enum { | 404 enum { |
| 395 kIsOpaque_SaveLayerFlag = 1 << 0, | 405 kIsOpaque_SaveLayerFlag = 1 << 0, |
| 396 kPreserveLCDText_SaveLayerFlag = 1 << 1, | 406 kPreserveLCDText_SaveLayerFlag = 1 << 1, |
| 397 }; | 407 }; |
| 398 typedef uint32_t SaveLayerFlags; | 408 typedef uint32_t SaveLayerFlags; |
| 399 | 409 |
| 400 struct SaveLayerRec { | 410 struct SaveLayerRec { |
| 401 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { } | 411 SaveLayerRec() : fBounds(nullptr), fPaint(nullptr), fSaveLayerFlags(0) { } |
| 402 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) | 412 SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0) |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 // and offscreen bounds for any margin required by the filter DAG. | 1338 // and offscreen bounds for any margin required by the filter DAG. |
| 1329 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, | 1339 bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersect ion, |
| 1330 const SkImageFilter* imageFilter = NULL); | 1340 const SkImageFilter* imageFilter = NULL); |
| 1331 | 1341 |
| 1332 private: | 1342 private: |
| 1333 enum PrivateSaveLayerFlags { | 1343 enum PrivateSaveLayerFlags { |
| 1334 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31, | 1344 kDontClipToLayer_PrivateSaveLayerFlag = 1 << 31, |
| 1335 }; | 1345 }; |
| 1336 | 1346 |
| 1337 static bool BoundsAffectsClip(SaveLayerFlags); | 1347 static bool BoundsAffectsClip(SaveLayerFlags); |
| 1348 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 1338 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); | 1349 static uint32_t SaveFlagsToSaveLayerFlags(SaveFlags); |
| 1350 #endif | |
| 1351 static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFla gs); | |
| 1339 | 1352 |
| 1340 enum ShaderOverrideOpacity { | 1353 enum ShaderOverrideOpacity { |
| 1341 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) | 1354 kNone_ShaderOverrideOpacity, //!< there is no overriding shader ( bitmap or image) |
| 1342 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque | 1355 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque |
| 1343 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque | 1356 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not b e opaque |
| 1344 }; | 1357 }; |
| 1345 | 1358 |
| 1346 // notify our surface (if we have one) that we are about to draw, so it | 1359 // notify our surface (if we have one) that we are about to draw, so it |
| 1347 // can perform copy-on-write or invalidate any cached images | 1360 // can perform copy-on-write or invalidate any cached images |
| 1348 void predrawNotify(bool willOverwritesEntireSurface = false); | 1361 void predrawNotify(bool willOverwritesEntireSurface = false); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1567 // the caller must respect the restrictions associated with peekPixels(). | 1580 // the caller must respect the restrictions associated with peekPixels(). |
| 1568 bool asROBitmap(SkBitmap*) const; | 1581 bool asROBitmap(SkBitmap*) const; |
| 1569 | 1582 |
| 1570 private: | 1583 private: |
| 1571 SkBitmap fBitmap; // used if peekPixels() fails | 1584 SkBitmap fBitmap; // used if peekPixels() fails |
| 1572 const void* fAddr; // NULL on failure | 1585 const void* fAddr; // NULL on failure |
| 1573 SkImageInfo fInfo; | 1586 SkImageInfo fInfo; |
| 1574 size_t fRowBytes; | 1587 size_t fRowBytes; |
| 1575 }; | 1588 }; |
| 1576 | 1589 |
| 1590 #ifdef SK_SUPPORT_LEGACY_SAVEFLAGS | |
| 1577 static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, | 1591 static inline SkCanvas::SaveFlags operator|(const SkCanvas::SaveFlags lhs, |
| 1578 const SkCanvas::SaveFlags rhs) { | 1592 const SkCanvas::SaveFlags rhs) { |
| 1579 return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast< int>(rhs)); | 1593 return static_cast<SkCanvas::SaveFlags>(static_cast<int>(lhs) | static_cast< int>(rhs)); |
| 1580 } | 1594 } |
| 1581 | 1595 |
| 1582 static inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, | 1596 static inline SkCanvas::SaveFlags& operator|=(SkCanvas::SaveFlags& lhs, |
| 1583 const SkCanvas::SaveFlags rhs) { | 1597 const SkCanvas::SaveFlags rhs) { |
| 1584 lhs = lhs | rhs; | 1598 lhs = lhs | rhs; |
| 1585 return lhs; | 1599 return lhs; |
| 1586 } | 1600 } |
| 1601 #endif | |
| 1587 | 1602 |
| 1588 class SkCanvasClipVisitor { | 1603 class SkCanvasClipVisitor { |
| 1589 public: | 1604 public: |
| 1590 virtual ~SkCanvasClipVisitor(); | 1605 virtual ~SkCanvasClipVisitor(); |
| 1591 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1606 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; |
| 1592 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1607 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; |
| 1593 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1608 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; |
| 1594 }; | 1609 }; |
| 1595 | 1610 |
| 1596 #endif | 1611 #endif |
| OLD | NEW |