Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #ifndef SkCanvas_DEFINED | 10 #ifndef SkCanvas_DEFINED |
| 11 #define SkCanvas_DEFINED | 11 #define SkCanvas_DEFINED |
| 12 | 12 |
| 13 #include "SkTypes.h" | 13 #include "SkTypes.h" |
| 14 #include "SkBitmap.h" | 14 #include "SkBitmap.h" |
| 15 #include "SkDeque.h" | 15 #include "SkDeque.h" |
| 16 #include "SkClipStack.h" | 16 #include "SkClipStack.h" |
| 17 #include "SkPaint.h" | 17 #include "SkPaint.h" |
| 18 #include "SkRefCnt.h" | 18 #include "SkRefCnt.h" |
| 19 #include "SkPath.h" | 19 #include "SkPath.h" |
| 20 #include "SkRegion.h" | 20 #include "SkRegion.h" |
| 21 #include "SkScalarCompare.h" | |
| 22 #include "SkXfermode.h" | 21 #include "SkXfermode.h" |
| 23 | 22 |
| 24 class SkBounder; | 23 class SkBounder; |
| 25 class SkBaseDevice; | 24 class SkBaseDevice; |
| 26 class SkDraw; | 25 class SkDraw; |
| 27 class SkDrawFilter; | 26 class SkDrawFilter; |
| 28 class SkMetaData; | 27 class SkMetaData; |
| 29 class SkPicture; | 28 class SkPicture; |
| 30 class SkRRect; | 29 class SkRRect; |
| 31 class SkSurface_Base; | 30 class SkSurface_Base; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 completely clipped out. This is a conservative calculation, meaning | 447 completely clipped out. This is a conservative calculation, meaning |
| 449 that it is possible that if the method returns false, the band may still | 448 that it is possible that if the method returns false, the band may still |
| 450 in fact be clipped out, but the converse is not true. If this method | 449 in fact be clipped out, but the converse is not true. If this method |
| 451 returns true, then the band is guaranteed to be clipped out. | 450 returns true, then the band is guaranteed to be clipped out. |
| 452 @param top The top of the horizontal band to compare with the clip | 451 @param top The top of the horizontal band to compare with the clip |
| 453 @param bottom The bottom of the horizontal and to compare with the clip | 452 @param bottom The bottom of the horizontal and to compare with the clip |
| 454 @return true if the horizontal band is completely clipped out (i.e. does | 453 @return true if the horizontal band is completely clipped out (i.e. does |
| 455 not intersect the current clip) | 454 not intersect the current clip) |
| 456 */ | 455 */ |
| 457 bool quickRejectY(SkScalar top, SkScalar bottom) const { | 456 bool quickRejectY(SkScalar top, SkScalar bottom) const { |
| 458 SkASSERT(SkScalarToCompareType(top) <= SkScalarToCompareType(bottom)); | 457 SkASSERT(top <= bottom); |
| 459 const SkRectCompareType& clipR = this->getLocalClipBoundsCompareType(); | 458 const SkRect& clipR = this->getLocalClipBoundsCompareType(); |
| 460 // In the case where the clip is empty and we are provided with a | 459 // In the case where the clip is empty and we are provided with a |
| 461 // negative top and positive bottom parameter then this test will return | 460 // negative top and positive bottom parameter then this test will return |
| 462 // false even though it will be clipped. We have chosen to exclude that | 461 // false even though it will be clipped. We have chosen to exclude that |
| 463 // check as it is rare and would result double the comparisons. | 462 // check as it is rare and would result double the comparisons. |
| 464 return SkScalarToCompareType(top) >= clipR.fBottom | 463 return top >= clipR.fBottom || bottom <= clipR.fTop; |
| 465 || SkScalarToCompareType(bottom) <= clipR.fTop; | |
| 466 } | 464 } |
| 467 | 465 |
| 468 /** Return the bounds of the current clip (in local coordinates) in the | 466 /** Return the bounds of the current clip (in local coordinates) in the |
| 469 bounds parameter, and return true if it is non-empty. This can be useful | 467 bounds parameter, and return true if it is non-empty. This can be useful |
| 470 in a way similar to quickReject, in that it tells you that drawing | 468 in a way similar to quickReject, in that it tells you that drawing |
| 471 outside of these bounds will be clipped out. | 469 outside of these bounds will be clipped out. |
| 472 */ | 470 */ |
| 473 bool getClipBounds(SkRect* bounds) const; | 471 bool getClipBounds(SkRect* bounds) const; |
| 474 | 472 |
| 475 /** Return the bounds of the current clip, in device coordinates; returns | 473 /** Return the bounds of the current clip, in device coordinates; returns |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 void internalRestore(); | 1091 void internalRestore(); |
| 1094 static void DrawRect(const SkDraw& draw, const SkPaint& paint, | 1092 static void DrawRect(const SkDraw& draw, const SkPaint& paint, |
| 1095 const SkRect& r, SkScalar textSize); | 1093 const SkRect& r, SkScalar textSize); |
| 1096 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, | 1094 static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint, |
| 1097 const char text[], size_t byteLength, | 1095 const char text[], size_t byteLength, |
| 1098 SkScalar x, SkScalar y); | 1096 SkScalar x, SkScalar y); |
| 1099 | 1097 |
| 1100 /* These maintain a cache of the clip bounds in local coordinates, | 1098 /* These maintain a cache of the clip bounds in local coordinates, |
| 1101 (converted to 2s-compliment if floats are slow). | 1099 (converted to 2s-compliment if floats are slow). |
| 1102 */ | 1100 */ |
| 1103 mutable SkRectCompareType fLocalBoundsCompareType; | 1101 mutable SkRect fCachedLocalClipBounds; |
| 1104 mutable bool fLocalBoundsCompareTypeDirty; | 1102 mutable bool fCachedLocalClipBoundsDirty; |
| 1105 bool fAllowSoftClip; | 1103 bool fAllowSoftClip; |
| 1106 bool fAllowSimplifyClip; | 1104 bool fAllowSimplifyClip; |
| 1107 | 1105 |
| 1108 const SkRectCompareType& getLocalClipBoundsCompareType() const { | 1106 const SkRect& getLocalClipBoundsCompareType() const { |
|
f(malita)
2013/12/11 22:30:54
Maybe rename the method to avoid "compareType"?
reed1
2013/12/13 21:15:25
Done.
| |
| 1109 if (fLocalBoundsCompareTypeDirty) { | 1107 if (fCachedLocalClipBoundsDirty) { |
| 1110 this->computeLocalClipBoundsCompareType(); | 1108 if (!this->getClipBounds(&fCachedLocalClipBounds)) { |
| 1111 fLocalBoundsCompareTypeDirty = false; | 1109 fCachedLocalClipBounds.setEmpty(); |
| 1110 } | |
| 1111 fCachedLocalClipBoundsDirty = false; | |
| 1112 } | 1112 } |
| 1113 return fLocalBoundsCompareType; | 1113 return fCachedLocalClipBounds; |
| 1114 } | 1114 } |
| 1115 void computeLocalClipBoundsCompareType() const; | |
| 1116 | |
| 1117 | 1115 |
| 1118 class AutoValidateClip : ::SkNoncopyable { | 1116 class AutoValidateClip : ::SkNoncopyable { |
| 1119 public: | 1117 public: |
| 1120 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { | 1118 explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) { |
| 1121 fCanvas->validateClip(); | 1119 fCanvas->validateClip(); |
| 1122 } | 1120 } |
| 1123 ~AutoValidateClip() { fCanvas->validateClip(); } | 1121 ~AutoValidateClip() { fCanvas->validateClip(); } |
| 1124 | 1122 |
| 1125 private: | 1123 private: |
| 1126 const SkCanvas* fCanvas; | 1124 const SkCanvas* fCanvas; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1188 fCanvas->endCommentGroup(); | 1186 fCanvas->endCommentGroup(); |
| 1189 } | 1187 } |
| 1190 } | 1188 } |
| 1191 | 1189 |
| 1192 private: | 1190 private: |
| 1193 SkCanvas* fCanvas; | 1191 SkCanvas* fCanvas; |
| 1194 }; | 1192 }; |
| 1195 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) | 1193 #define SkAutoCommentBlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoCommentBlock) |
| 1196 | 1194 |
| 1197 #endif | 1195 #endif |
| OLD | NEW |