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 |
11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkClipOp.h" |
13 #include "SkDeque.h" | 14 #include "SkDeque.h" |
14 #include "SkImage.h" | 15 #include "SkImage.h" |
15 #include "SkPaint.h" | 16 #include "SkPaint.h" |
16 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
17 #include "SkRegion.h" | 18 #include "SkRegion.h" |
18 #include "SkSurfaceProps.h" | 19 #include "SkSurfaceProps.h" |
19 #include "SkXfermode.h" | 20 #include "SkXfermode.h" |
20 #include "SkLights.h" | 21 #include "SkLights.h" |
21 #include "../private/SkShadowParams.h" | 22 #include "../private/SkShadowParams.h" |
22 | 23 |
(...skipping 11 matching lines...) Expand all Loading... |
34 class SkPath; | 35 class SkPath; |
35 class SkPicture; | 36 class SkPicture; |
36 class SkPixmap; | 37 class SkPixmap; |
37 class SkRasterClip; | 38 class SkRasterClip; |
38 class SkRRect; | 39 class SkRRect; |
39 struct SkRSXform; | 40 struct SkRSXform; |
40 class SkSurface; | 41 class SkSurface; |
41 class SkSurface_Base; | 42 class SkSurface_Base; |
42 class SkTextBlob; | 43 class SkTextBlob; |
43 | 44 |
| 45 //#define SK_SUPPORT_LEGACY_CLIP_REGIONOPS |
| 46 |
44 /** \class SkCanvas | 47 /** \class SkCanvas |
45 | 48 |
46 A Canvas encapsulates all of the state about drawing into a device (bitmap). | 49 A Canvas encapsulates all of the state about drawing into a device (bitmap). |
47 This includes a reference to the device itself, and a stack of matrix/clip | 50 This includes a reference to the device itself, and a stack of matrix/clip |
48 values. For any given draw call (e.g. drawRect), the geometry of the object | 51 values. For any given draw call (e.g. drawRect), the geometry of the object |
49 being drawn is transformed by the concatenation of all the matrices in the | 52 being drawn is transformed by the concatenation of all the matrices in the |
50 stack. The transformed geometry is clipped by the intersection of all of | 53 stack. The transformed geometry is clipped by the intersection of all of |
51 the clips in the stack. | 54 the clips in the stack. |
52 | 55 |
53 While the Canvas holds the state of the drawing device, the state (style) | 56 While the Canvas holds the state of the drawing device, the state (style) |
54 of the object being drawn is held by the Paint, which is provided as a | 57 of the object being drawn is held by the Paint, which is provided as a |
55 parameter to each of the draw() methods. The Paint holds attributes such as | 58 parameter to each of the draw() methods. The Paint holds attributes such as |
56 color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), | 59 color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns), |
57 etc. | 60 etc. |
58 */ | 61 */ |
59 class SK_API SkCanvas : public SkRefCnt { | 62 class SK_API SkCanvas : public SkRefCnt { |
60 enum PrivateSaveLayerFlags { | 63 enum PrivateSaveLayerFlags { |
61 kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31, | 64 kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31, |
62 }; | 65 }; |
63 | 66 |
64 public: | 67 public: |
| 68 #ifdef SK_SUPPORT_LEGACY_CLIP_REGIONOPS |
| 69 typedef SkRegion::Op ClipOp; |
| 70 |
| 71 static const ClipOp kDifference_Op = SkRegion::kDifference_Op; |
| 72 static const ClipOp kIntersect_Op = SkRegion::kIntersect_Op; |
| 73 static const ClipOp kUnion_Op = SkRegion::kUnion_Op; |
| 74 static const ClipOp kXOR_Op = SkRegion::kXOR_Op; |
| 75 static const ClipOp kReverseDifference_Op = SkRegion::kReverseDifference_Op
; |
| 76 static const ClipOp kReplace_Op = SkRegion::kReplace_Op; |
| 77 #else |
| 78 typedef SkClipOp ClipOp; |
| 79 |
| 80 static const ClipOp kDifference_Op = kDifference_SkClipOp; |
| 81 static const ClipOp kIntersect_Op = kIntersect_SkClipOp; |
| 82 static const ClipOp kUnion_Op = kUnion_SkClipOp; |
| 83 static const ClipOp kXOR_Op = kXOR_SkClipOp; |
| 84 static const ClipOp kReverseDifference_Op = kReverseDifference_SkClipOp; |
| 85 static const ClipOp kReplace_Op = kReplace_SkClipOp; |
| 86 #endif |
65 /** | 87 /** |
66 * Attempt to allocate raster canvas, matching the ImageInfo, that will dra
w directly into the | 88 * Attempt to allocate raster canvas, matching the ImageInfo, that will dra
w directly into the |
67 * specified pixels. To access the pixels after drawing to them, the caller
should call | 89 * specified pixels. To access the pixels after drawing to them, the caller
should call |
68 * flush() or call peekPixels(...). | 90 * flush() or call peekPixels(...). |
69 * | 91 * |
70 * On failure, return NULL. This can fail for several reasons: | 92 * On failure, return NULL. This can fail for several reasons: |
71 * 1. invalid ImageInfo (e.g. negative dimensions) | 93 * 1. invalid ImageInfo (e.g. negative dimensions) |
72 * 2. unsupported ImageInfo for a canvas | 94 * 2. unsupported ImageInfo for a canvas |
73 * - kUnknown_SkColorType, kIndex_8_SkColorType | 95 * - kUnknown_SkColorType, kIndex_8_SkColorType |
74 * - kUnknown_SkAlphaType | 96 * - kUnknown_SkAlphaType |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 */ | 492 */ |
471 sk_sp<SkLights> getLights() const; | 493 sk_sp<SkLights> getLights() const; |
472 #endif | 494 #endif |
473 | 495 |
474 /** | 496 /** |
475 * Modify the current clip with the specified rectangle. | 497 * Modify the current clip with the specified rectangle. |
476 * @param rect The rect to combine with the current clip | 498 * @param rect The rect to combine with the current clip |
477 * @param op The region op to apply to the current clip | 499 * @param op The region op to apply to the current clip |
478 * @param doAntiAlias true if the clip should be antialiased | 500 * @param doAntiAlias true if the clip should be antialiased |
479 */ | 501 */ |
480 void clipRect(const SkRect& rect, | 502 void clipRect(const SkRect& rect, ClipOp op = kIntersect_Op, bool doAntiAlia
s = false); |
481 SkRegion::Op op = SkRegion::kIntersect_Op, | |
482 bool doAntiAlias = false); | |
483 | 503 |
484 /** | 504 /** |
485 * Modify the current clip with the specified SkRRect. | 505 * Modify the current clip with the specified SkRRect. |
486 * @param rrect The rrect to combine with the current clip | 506 * @param rrect The rrect to combine with the current clip |
487 * @param op The region op to apply to the current clip | 507 * @param op The region op to apply to the current clip |
488 * @param doAntiAlias true if the clip should be antialiased | 508 * @param doAntiAlias true if the clip should be antialiased |
489 */ | 509 */ |
490 void clipRRect(const SkRRect& rrect, | 510 void clipRRect(const SkRRect& rrect, ClipOp op = kIntersect_Op, bool doAntiA
lias = false); |
491 SkRegion::Op op = SkRegion::kIntersect_Op, | |
492 bool doAntiAlias = false); | |
493 | 511 |
494 /** | 512 /** |
495 * Modify the current clip with the specified path. | 513 * Modify the current clip with the specified path. |
496 * @param path The path to combine with the current clip | 514 * @param path The path to combine with the current clip |
497 * @param op The region op to apply to the current clip | 515 * @param op The region op to apply to the current clip |
498 * @param doAntiAlias true if the clip should be antialiased | 516 * @param doAntiAlias true if the clip should be antialiased |
499 */ | 517 */ |
500 void clipPath(const SkPath& path, | 518 void clipPath(const SkPath& path, ClipOp op = kIntersect_Op, bool doAntiAlia
s = false); |
501 SkRegion::Op op = SkRegion::kIntersect_Op, | |
502 bool doAntiAlias = false); | |
503 | 519 |
504 /** EXPERIMENTAL -- only used for testing | 520 /** EXPERIMENTAL -- only used for testing |
505 Set to false to force clips to be hard, even if doAntiAlias=true is | 521 Set to false to force clips to be hard, even if doAntiAlias=true is |
506 passed to clipRect or clipPath. | 522 passed to clipRect or clipPath. |
507 */ | 523 */ |
508 void setAllowSoftClip(bool allow) { | 524 void setAllowSoftClip(bool allow) { |
509 fAllowSoftClip = allow; | 525 fAllowSoftClip = allow; |
510 } | 526 } |
511 | 527 |
512 /** EXPERIMENTAL -- only used for testing | 528 /** EXPERIMENTAL -- only used for testing |
513 Set to simplify clip stack using path ops. | 529 Set to simplify clip stack using path ops. |
514 */ | 530 */ |
515 void setAllowSimplifyClip(bool allow) { | 531 void setAllowSimplifyClip(bool allow) { |
516 fAllowSimplifyClip = allow; | 532 fAllowSimplifyClip = allow; |
517 } | 533 } |
518 | 534 |
519 /** Modify the current clip with the specified region. Note that unlike | 535 /** Modify the current clip with the specified region. Note that unlike |
520 clipRect() and clipPath() which transform their arguments by the current | 536 clipRect() and clipPath() which transform their arguments by the current |
521 matrix, clipRegion() assumes its argument is already in device | 537 matrix, clipRegion() assumes its argument is already in device |
522 coordinates, and so no transformation is performed. | 538 coordinates, and so no transformation is performed. |
523 @param deviceRgn The region to apply to the current clip | 539 @param deviceRgn The region to apply to the current clip |
524 @param op The region op to apply to the current clip | 540 @param op The region op to apply to the current clip |
525 */ | 541 */ |
526 void clipRegion(const SkRegion& deviceRgn, | 542 void clipRegion(const SkRegion& deviceRgn, ClipOp op = kIntersect_Op); |
527 SkRegion::Op op = SkRegion::kIntersect_Op); | |
528 | |
529 /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the | |
530 specified region. This does not intersect or in any other way account | |
531 for the existing clip region. | |
532 @param deviceRgn The region to copy into the current clip. | |
533 */ | |
534 void setClipRegion(const SkRegion& deviceRgn) { | |
535 this->clipRegion(deviceRgn, SkRegion::kReplace_Op); | |
536 } | |
537 | 543 |
538 /** Return true if the specified rectangle, after being transformed by the | 544 /** Return true if the specified rectangle, after being transformed by the |
539 current matrix, would lie completely outside of the current clip. Call | 545 current matrix, would lie completely outside of the current clip. Call |
540 this to check if an area you intend to draw into is clipped out (and | 546 this to check if an area you intend to draw into is clipped out (and |
541 therefore you can skip making the draw calls). | 547 therefore you can skip making the draw calls). |
542 @param rect the rect to compare with the current clip | 548 @param rect the rect to compare with the current clip |
543 @return true if the rect (transformed by the canvas' matrix) does not | 549 @return true if the rect (transformed by the canvas' matrix) does not |
544 intersect with the canvas' clip | 550 intersect with the canvas' clip |
545 */ | 551 */ |
546 bool quickReject(const SkRect& rect) const; | 552 bool quickReject(const SkRect& rect) const; |
(...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1459 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const
SkRect& dst, | 1465 virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const
SkRect& dst, |
1460 const SkPaint*); | 1466 const SkPaint*); |
1461 virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, co
nst SkRect& dst, | 1467 virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, co
nst SkRect& dst, |
1462 const SkPaint*); | 1468 const SkPaint*); |
1463 | 1469 |
1464 enum ClipEdgeStyle { | 1470 enum ClipEdgeStyle { |
1465 kHard_ClipEdgeStyle, | 1471 kHard_ClipEdgeStyle, |
1466 kSoft_ClipEdgeStyle | 1472 kSoft_ClipEdgeStyle |
1467 }; | 1473 }; |
1468 | 1474 |
1469 virtual void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1475 virtual void onClipRect(const SkRect& rect, ClipOp, ClipEdgeStyle); |
1470 virtual void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyl
e edgeStyle); | 1476 virtual void onClipRRect(const SkRRect& rrect, ClipOp, ClipEdgeStyle); |
1471 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e
dgeStyle); | 1477 virtual void onClipPath(const SkPath& path, ClipOp, ClipEdgeStyle); |
1472 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); | 1478 virtual void onClipRegion(const SkRegion& deviceRgn, ClipOp); |
1473 | 1479 |
1474 virtual void onDiscard(); | 1480 virtual void onDiscard(); |
1475 | 1481 |
1476 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
); | 1482 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
); |
1477 | 1483 |
1478 #ifdef SK_EXPERIMENTAL_SHADOWING | 1484 #ifdef SK_EXPERIMENTAL_SHADOWING |
1479 virtual void onDrawShadowedPicture(const SkPicture*, | 1485 virtual void onDrawShadowedPicture(const SkPicture*, |
1480 const SkMatrix*, | 1486 const SkMatrix*, |
1481 const SkPaint*, | 1487 const SkPaint*, |
1482 const SkShadowParams& params); | 1488 const SkShadowParams& params); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 | 1731 |
1726 private: | 1732 private: |
1727 SkCanvas* fCanvas; | 1733 SkCanvas* fCanvas; |
1728 int fSaveCount; | 1734 int fSaveCount; |
1729 }; | 1735 }; |
1730 #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) | 1736 #define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore) |
1731 | 1737 |
1732 class SkCanvasClipVisitor { | 1738 class SkCanvasClipVisitor { |
1733 public: | 1739 public: |
1734 virtual ~SkCanvasClipVisitor(); | 1740 virtual ~SkCanvasClipVisitor(); |
1735 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; | 1741 virtual void clipRect(const SkRect&, SkCanvas::ClipOp, bool antialias) = 0; |
1736 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; | 1742 virtual void clipRRect(const SkRRect&, SkCanvas::ClipOp, bool antialias) = 0
; |
1737 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; | 1743 virtual void clipPath(const SkPath&, SkCanvas::ClipOp, bool antialias) = 0; |
1738 }; | 1744 }; |
1739 | 1745 |
1740 #endif | 1746 #endif |
OLD | NEW |