Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: include/core/SkCanvas.h

Issue 777643003: use ClipOp instead of SkRegion for clipping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkDeque.h" 13 #include "SkDeque.h"
14 #include "SkClipStack.h" 14 #include "SkClipStack.h"
15 #include "SkPaint.h" 15 #include "SkPaint.h"
16 #include "SkRefCnt.h" 16 #include "SkRefCnt.h"
17 #include "SkPath.h" 17 #include "SkPath.h"
18 #include "SkRegion.h" 18 #include "SkRegion.h"
19 #include "SkSurfaceProps.h" 19 #include "SkSurfaceProps.h"
20 #include "SkXfermode.h" 20 #include "SkXfermode.h"
21 21
22 // Undefine this when we change callers to use SkClipOp or legacyClip (temporari ly)
23 //#define SK_SUPPORT_REGION_CLIPOPS
24
25 // Undefine this when we have updated all callers to SkClipOp
26 #define SK_SUPPORT_LEGACY_CLIPOPS
27
22 #ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL 28 #ifdef SK_SUPPORT_LEGACY_DRAWTEXT_VIRTUAL
23 #define SK_LEGACY_DRAWTEXT_VIRTUAL virtual 29 #define SK_LEGACY_DRAWTEXT_VIRTUAL virtual
24 #else 30 #else
25 #define SK_LEGACY_DRAWTEXT_VIRTUAL 31 #define SK_LEGACY_DRAWTEXT_VIRTUAL
26 #endif 32 #endif
27 33
28 class SkBaseDevice; 34 class SkBaseDevice;
29 class SkCanvasClipVisitor; 35 class SkCanvasClipVisitor;
30 class SkCanvasDrawable; 36 class SkCanvasDrawable;
31 class SkDraw; 37 class SkDraw;
32 class SkDrawFilter; 38 class SkDrawFilter;
33 class SkImage; 39 class SkImage;
34 class SkMetaData; 40 class SkMetaData;
35 class SkPicture; 41 class SkPicture;
36 class SkRRect; 42 class SkRRect;
37 class SkSurface; 43 class SkSurface;
38 class SkSurface_Base; 44 class SkSurface_Base;
39 class SkTextBlob; 45 class SkTextBlob;
40 class GrContext; 46 class GrContext;
41 class GrRenderTarget; 47 class GrRenderTarget;
42 48
43 class SkCanvasState; 49 class SkCanvasState;
44 50
51 enum SkClipOp {
52 kIntersect_SkClipOp,
53 kDifference_SkClipOp,
54 };
55
45 /** \class SkCanvas 56 /** \class SkCanvas
46 57
47 A Canvas encapsulates all of the state about drawing into a device (bitmap). 58 A Canvas encapsulates all of the state about drawing into a device (bitmap).
48 This includes a reference to the device itself, and a stack of matrix/clip 59 This includes a reference to the device itself, and a stack of matrix/clip
49 values. For any given draw call (e.g. drawRect), the geometry of the object 60 values. For any given draw call (e.g. drawRect), the geometry of the object
50 being drawn is transformed by the concatenation of all the matrices in the 61 being drawn is transformed by the concatenation of all the matrices in the
51 stack. The transformed geometry is clipped by the intersection of all of 62 stack. The transformed geometry is clipped by the intersection of all of
52 the clips in the stack. 63 the clips in the stack.
53 64
54 While the Canvas holds the state of the drawing device, the state (style) 65 While the Canvas holds the state of the drawing device, the state (style)
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 473
463 /** Replace the current matrix with a copy of the specified matrix. 474 /** Replace the current matrix with a copy of the specified matrix.
464 @param matrix The matrix that will be copied into the current matrix. 475 @param matrix The matrix that will be copied into the current matrix.
465 */ 476 */
466 void setMatrix(const SkMatrix& matrix); 477 void setMatrix(const SkMatrix& matrix);
467 478
468 /** Helper for setMatrix(identity). Sets the current matrix to identity. 479 /** Helper for setMatrix(identity). Sets the current matrix to identity.
469 */ 480 */
470 void resetMatrix(); 481 void resetMatrix();
471 482
483 #ifndef SK_SUPPORT_REGION_CLIPOPS
484 private:
485 #endif
486 void clipRect(const SkRect&, SkRegion::Op, bool doAntiAlias = false);
487 void clipRRect(const SkRRect&, SkRegion::Op, bool doAntiAlias = false);
488 void clipPath(const SkPath&, SkRegion::Op, bool doAntiAlias = false);
489 void clipRegion(const SkRegion&, SkRegion::Op);
490 #ifndef SK_SUPPORT_REGION_CLIPOPS
491 public:
492 #endif
493
494 /* These support SkRegion ops, and are used in the interim until we can remove all
495 * needs for these ops. When all callers only need Intersect or Difference, we will
496 * remove these calls.
497 */
498 #ifdef SK_SUPPORT_LEGACY_CLIPOPS
499 void legacyClipRect(const SkRect& rect, SkRegion::Op op, bool doAntiAlias = false) {
500 this->clipRect(rect, op, doAntiAlias);
501 }
502 void legacyClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAntiAlias = false) {
503 this->clipRRect(rrect, op, doAntiAlias);
504 }
505 void legacyClipPath(const SkPath& path, SkRegion::Op op, bool doAntiAlias = false) {
506 this->clipPath(path, op, doAntiAlias);
507 }
508 void legacyClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
509 this->clipRegion(deviceRgn, op);
510 }
511 #endif
512
472 /** 513 /**
473 * Modify the current clip with the specified rectangle. 514 * Modify the current clip with the specified rectangle.
474 * @param rect The rect to combine with the current clip 515 * @param rect The rect to combine with the current clip
475 * @param op The region op to apply to the current clip 516 * @param op The ClipOp to apply to the current clip
476 * @param doAntiAlias true if the clip should be antialiased 517 * @param doAntiAlias true if the clip should be antialiased
477 */ 518 */
478 void clipRect(const SkRect& rect, 519 void clipRect(const SkRect& rect, SkClipOp op, bool doAntiAlias = false);
479 SkRegion::Op op = SkRegion::kIntersect_Op, 520 void clipRect(const SkRect& rect) {
480 bool doAntiAlias = false); 521 this->clipRect(rect, kIntersect_SkClipOp, false);
522 }
481 523
482 /** 524 /**
483 * Modify the current clip with the specified SkRRect. 525 * Modify the current clip with the specified SkRRect.
484 * @param rrect The rrect to combine with the current clip 526 * @param rrect The rrect to combine with the current clip
485 * @param op The region op to apply to the current clip 527 * @param op The ClipOp to apply to the current clip
486 * @param doAntiAlias true if the clip should be antialiased 528 * @param doAntiAlias true if the clip should be antialiased
487 */ 529 */
488 void clipRRect(const SkRRect& rrect, 530 void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias = false);
489 SkRegion::Op op = SkRegion::kIntersect_Op, 531 void clipRRect(const SkRRect& rrect) {
490 bool doAntiAlias = false); 532 this->clipRRect(rrect, kIntersect_SkClipOp, false);
533 }
491 534
492 /** 535 /**
493 * Modify the current clip with the specified path. 536 * Modify the current clip with the specified path.
494 * @param path The path to combine with the current clip 537 * @param path The path to combine with the current clip
495 * @param op The region op to apply to the current clip 538 * @param op The ClipOp to apply to the current clip
496 * @param doAntiAlias true if the clip should be antialiased 539 * @param doAntiAlias true if the clip should be antialiased
497 */ 540 */
498 void clipPath(const SkPath& path, 541 void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias = false);
499 SkRegion::Op op = SkRegion::kIntersect_Op, 542 void clipPath(const SkPath& path) {
500 bool doAntiAlias = false); 543 this->clipPath(path, kIntersect_SkClipOp, false);
544 }
501 545
502 /** EXPERIMENTAL -- only used for testing 546 /** EXPERIMENTAL -- only used for testing
503 Set to false to force clips to be hard, even if doAntiAlias=true is 547 Set to false to force clips to be hard, even if doAntiAlias=true is
504 passed to clipRect or clipPath. 548 passed to clipRect or clipPath.
505 */ 549 */
506 void setAllowSoftClip(bool allow) { 550 void setAllowSoftClip(bool allow) {
507 fAllowSoftClip = allow; 551 fAllowSoftClip = allow;
508 } 552 }
509 553
510 /** EXPERIMENTAL -- only used for testing 554 /** EXPERIMENTAL -- only used for testing
511 Set to simplify clip stack using path ops. 555 Set to simplify clip stack using path ops.
512 */ 556 */
513 void setAllowSimplifyClip(bool allow) { 557 void setAllowSimplifyClip(bool allow) {
514 fAllowSimplifyClip = allow; 558 fAllowSimplifyClip = allow;
515 } 559 }
516 560
517 /** Modify the current clip with the specified region. Note that unlike 561 /** Modify the current clip with the specified region. Note that unlike
518 clipRect() and clipPath() which transform their arguments by the current 562 clipRect() and clipPath() which transform their arguments by the current
519 matrix, clipRegion() assumes its argument is already in device 563 matrix, clipRegion() assumes its argument is already in device
520 coordinates, and so no transformation is performed. 564 coordinates, and so no transformation is performed.
521 @param deviceRgn The region to apply to the current clip 565 @param deviceRgn The region to apply to the current clip
522 @param op The region op to apply to the current clip 566 @param op The ClipOp to apply to the current clip
523 */ 567 */
524 void clipRegion(const SkRegion& deviceRgn, 568 void clipRegion(const SkRegion& deviceRgn, SkClipOp op = kIntersect_SkClipOp );
525 SkRegion::Op op = SkRegion::kIntersect_Op);
526 569
527 /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the 570 /** Helper for clipRegion(rgn, kReplace_Op). Sets the current clip to the
528 specified region. This does not intersect or in any other way account 571 specified region. This does not intersect or in any other way account
529 for the existing clip region. 572 for the existing clip region.
530 @param deviceRgn The region to copy into the current clip. 573 @param deviceRgn The region to copy into the current clip.
531 */ 574 */
532 void setClipRegion(const SkRegion& deviceRgn) { 575 void setClipRegion(const SkRegion& deviceRgn) {
533 this->clipRegion(deviceRgn, SkRegion::kReplace_Op); 576 this->legacyClipRegion(deviceRgn, SkRegion::kReplace_Op);
534 } 577 }
535 578
536 /** Return true if the specified rectangle, after being transformed by the 579 /** Return true if the specified rectangle, after being transformed by the
537 current matrix, would lie completely outside of the current clip. Call 580 current matrix, would lie completely outside of the current clip. Call
538 this to check if an area you intend to draw into is clipped out (and 581 this to check if an area you intend to draw into is clipped out (and
539 therefore you can skip making the draw calls). 582 therefore you can skip making the draw calls).
540 @param rect the rect to compare with the current clip 583 @param rect the rect to compare with the current clip
541 @return true if the rect (transformed by the canvas' matrix) does not 584 @return true if the rect (transformed by the canvas' matrix) does not
542 intersect with the canvas' clip 585 intersect with the canvas' clip
543 */ 586 */
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 1582
1540 class SkCanvasClipVisitor { 1583 class SkCanvasClipVisitor {
1541 public: 1584 public:
1542 virtual ~SkCanvasClipVisitor(); 1585 virtual ~SkCanvasClipVisitor();
1543 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1586 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1544 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1587 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1545 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1588 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1546 }; 1589 };
1547 1590
1548 #endif 1591 #endif
OLDNEW
« no previous file with comments | « gyp/skia_for_chromium_defines.gypi ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698