OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkCanvasDrawable.h" | 9 #include "SkCanvasDrawable.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 /* This is the record we keep for each save/restore level in the stack. | 164 /* This is the record we keep for each save/restore level in the stack. |
165 Since a level optionally copies the matrix and/or stack, we have pointers | 165 Since a level optionally copies the matrix and/or stack, we have pointers |
166 for these fields. If the value is copied for this level, the copy is | 166 for these fields. If the value is copied for this level, the copy is |
167 stored in the ...Storage field, and the pointer points to that. If the | 167 stored in the ...Storage field, and the pointer points to that. If the |
168 value is not copied for this level, we ignore ...Storage, and just point | 168 value is not copied for this level, we ignore ...Storage, and just point |
169 at the corresponding value in the previous level in the stack. | 169 at the corresponding value in the previous level in the stack. |
170 */ | 170 */ |
171 class SkCanvas::MCRec { | 171 class SkCanvas::MCRec { |
172 public: | 172 public: |
173 SkRasterClip fRasterClip; | |
174 SkMatrix fMatrix; | |
175 SkDrawFilter* fFilter; // the current filter (or null) | 173 SkDrawFilter* fFilter; // the current filter (or null) |
176 DeviceCM* fLayer; | 174 DeviceCM* fLayer; |
177 /* If there are any layers in the stack, this points to the top-most | 175 /* If there are any layers in the stack, this points to the top-most |
178 one that is at or below this level in the stack (so we know what | 176 one that is at or below this level in the stack (so we know what |
179 bitmap/device to draw into from this level. This value is NOT | 177 bitmap/device to draw into from this level. This value is NOT |
180 reference counted, since the real owner is either our fLayer field, | 178 reference counted, since the real owner is either our fLayer field, |
181 or a previous one in a lower level.) | 179 or a previous one in a lower level.) |
182 */ | 180 */ |
183 DeviceCM* fTopLayer; | 181 DeviceCM* fTopLayer; |
| 182 SkRasterClip fRasterClip; |
| 183 SkMatrix fMatrix; |
| 184 int fDeferredSaveCount; |
184 | 185 |
185 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) { | 186 MCRec(bool conservativeRasterClip) : fRasterClip(conservativeRasterClip) { |
186 fMatrix.reset(); | |
187 fFilter = NULL; | 187 fFilter = NULL; |
188 fLayer = NULL; | 188 fLayer = NULL; |
189 fTopLayer = NULL; | 189 fTopLayer = NULL; |
| 190 fMatrix.reset(); |
| 191 fDeferredSaveCount = 0; |
190 | 192 |
191 // don't bother initializing fNext | 193 // don't bother initializing fNext |
192 inc_rec(); | 194 inc_rec(); |
193 } | 195 } |
194 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip) { | 196 MCRec(const MCRec& prev) : fRasterClip(prev.fRasterClip), fMatrix(prev.fMatr
ix) { |
195 fMatrix = prev.fMatrix; | |
196 fFilter = SkSafeRef(prev.fFilter); | 197 fFilter = SkSafeRef(prev.fFilter); |
197 fLayer = NULL; | 198 fLayer = NULL; |
198 fTopLayer = prev.fTopLayer; | 199 fTopLayer = prev.fTopLayer; |
| 200 fDeferredSaveCount = 0; |
199 | 201 |
200 // don't bother initializing fNext | 202 // don't bother initializing fNext |
201 inc_rec(); | 203 inc_rec(); |
202 } | 204 } |
203 ~MCRec() { | 205 ~MCRec() { |
204 SkSafeUnref(fFilter); | 206 SkSafeUnref(fFilter); |
205 SkDELETE(fLayer); | 207 SkDELETE(fLayer); |
206 dec_rec(); | 208 dec_rec(); |
207 } | 209 } |
208 }; | 210 }; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 408 |
407 //////////////////////////////////////////////////////////////////////////// | 409 //////////////////////////////////////////////////////////////////////////// |
408 | 410 |
409 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { | 411 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
410 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; | 412 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; |
411 fCachedLocalClipBounds.setEmpty(); | 413 fCachedLocalClipBounds.setEmpty(); |
412 fCachedLocalClipBoundsDirty = true; | 414 fCachedLocalClipBoundsDirty = true; |
413 fAllowSoftClip = true; | 415 fAllowSoftClip = true; |
414 fAllowSimplifyClip = false; | 416 fAllowSimplifyClip = false; |
415 fDeviceCMDirty = true; | 417 fDeviceCMDirty = true; |
| 418 fSaveCount = 1; |
416 fSaveLayerCount = 0; | 419 fSaveLayerCount = 0; |
417 fCullCount = 0; | 420 fCullCount = 0; |
418 fMetaData = NULL; | 421 fMetaData = NULL; |
419 | 422 |
420 fMCRec = (MCRec*)fMCStack.push_back(); | 423 fMCRec = (MCRec*)fMCStack.push_back(); |
421 new (fMCRec) MCRec(fConservativeRasterClip); | 424 new (fMCRec) MCRec(fConservativeRasterClip); |
422 | 425 |
423 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); | 426 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); |
424 fMCRec->fTopLayer = fMCRec->fLayer; | 427 fMCRec->fTopLayer = fMCRec->fLayer; |
425 | 428 |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 do { | 781 do { |
779 layer->updateMC(totalMatrix, clip, fClipStack, &clip); | 782 layer->updateMC(totalMatrix, clip, fClipStack, &clip); |
780 } while ((layer = layer->fNext) != NULL); | 783 } while ((layer = layer->fNext) != NULL); |
781 } | 784 } |
782 fDeviceCMDirty = false; | 785 fDeviceCMDirty = false; |
783 } | 786 } |
784 } | 787 } |
785 | 788 |
786 /////////////////////////////////////////////////////////////////////////////// | 789 /////////////////////////////////////////////////////////////////////////////// |
787 | 790 |
| 791 void SkCanvas::checkForDeferredSave() { |
| 792 if (fMCRec->fDeferredSaveCount > 0) { |
| 793 fMCRec->fDeferredSaveCount -= 1; |
| 794 this->doSave(); |
| 795 } |
| 796 } |
| 797 |
788 int SkCanvas::getSaveCount() const { | 798 int SkCanvas::getSaveCount() const { |
789 return fMCStack.count(); | 799 #ifdef SK_DEBUG |
| 800 int count = 0; |
| 801 SkDeque::Iter iter(fMCStack, SkDeque::Iter::kFront_IterStart); |
| 802 for (;;) { |
| 803 const MCRec* rec = (const MCRec*)iter.next(); |
| 804 if (!rec) { |
| 805 break; |
| 806 } |
| 807 count += 1 + rec->fDeferredSaveCount; |
| 808 } |
| 809 SkASSERT(count == fSaveCount); |
| 810 #endif |
| 811 return fSaveCount; |
790 } | 812 } |
791 | 813 |
792 int SkCanvas::save() { | 814 int SkCanvas::save() { |
| 815 fSaveCount += 1; |
| 816 fMCRec->fDeferredSaveCount += 1; |
| 817 return this->getSaveCount() - 1; // return our prev value |
| 818 } |
| 819 |
| 820 void SkCanvas::doSave() { |
793 this->willSave(); | 821 this->willSave(); |
794 return this->internalSave(); | 822 this->internalSave(); |
795 } | 823 } |
796 | 824 |
797 void SkCanvas::restore() { | 825 void SkCanvas::restore() { |
798 // check for underflow | 826 if (fMCRec->fDeferredSaveCount > 0) { |
799 if (fMCStack.count() > 1) { | 827 SkASSERT(fSaveCount > 1); |
800 this->willRestore(); | 828 fSaveCount -= 1; |
801 this->internalRestore(); | 829 fMCRec->fDeferredSaveCount -= 1; |
802 this->didRestore(); | 830 } else { |
| 831 // check for underflow |
| 832 if (fMCStack.count() > 1) { |
| 833 this->willRestore(); |
| 834 SkASSERT(fSaveCount > 1); |
| 835 fSaveCount -= 1; |
| 836 this->internalRestore(); |
| 837 this->didRestore(); |
| 838 } |
803 } | 839 } |
804 } | 840 } |
805 | 841 |
806 void SkCanvas::restoreToCount(int count) { | 842 void SkCanvas::restoreToCount(int count) { |
807 // sanity check | 843 // sanity check |
808 if (count < 1) { | 844 if (count < 1) { |
809 count = 1; | 845 count = 1; |
810 } | 846 } |
811 | 847 |
812 int n = this->getSaveCount() - count; | 848 int n = this->getSaveCount() - count; |
813 for (int i = 0; i < n; ++i) { | 849 for (int i = 0; i < n; ++i) { |
814 this->restore(); | 850 this->restore(); |
815 } | 851 } |
816 } | 852 } |
817 | 853 |
818 int SkCanvas::internalSave() { | 854 void SkCanvas::internalSave() { |
819 int saveCount = this->getSaveCount(); // record this before the actual save | |
820 | |
821 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 855 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
822 new (newTop) MCRec(*fMCRec); // balanced in restore() | 856 new (newTop) MCRec(*fMCRec); // balanced in restore() |
823 fMCRec = newTop; | 857 fMCRec = newTop; |
824 | 858 |
825 fClipStack.save(); | 859 fClipStack.save(); |
826 | |
827 return saveCount; | |
828 } | 860 } |
829 | 861 |
830 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 862 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
831 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 863 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
832 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 864 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
833 #else | 865 #else |
834 return true; | 866 return true; |
835 #endif | 867 #endif |
836 } | 868 } |
837 | 869 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 906 } |
875 | 907 |
876 if (intersection) { | 908 if (intersection) { |
877 *intersection = ir; | 909 *intersection = ir; |
878 } | 910 } |
879 return true; | 911 return true; |
880 } | 912 } |
881 | 913 |
882 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { | 914 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { |
883 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); | 915 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); |
884 return this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, fals
e, strategy); | 916 fSaveCount += 1; |
| 917 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, false, stra
tegy); |
| 918 return this->getSaveCount() - 1; |
885 } | 919 } |
886 | 920 |
887 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, | 921 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl
ags) { |
888 SaveFlags flags) { | |
889 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); | 922 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); |
890 return this->internalSaveLayer(bounds, paint, flags, false, strategy); | 923 fSaveCount += 1; |
| 924 this->internalSaveLayer(bounds, paint, flags, false, strategy); |
| 925 return this->getSaveCount() - 1; |
891 } | 926 } |
892 | 927 |
893 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save
Flags flags, | 928 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, |
894 bool justForImageFilter, SaveLayerStrategy strat
egy) { | 929 bool justForImageFilter, SaveLayerStrategy strat
egy) { |
895 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 930 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
896 flags |= kClipToLayer_SaveFlag; | 931 flags |= kClipToLayer_SaveFlag; |
897 #endif | 932 #endif |
898 | 933 |
899 // do this before we create the layer. We don't call the public save() since | 934 // do this before we create the layer. We don't call the public save() since |
900 // that would invoke a possibly overridden virtual | 935 // that would invoke a possibly overridden virtual |
901 int count = this->internalSave(); | 936 this->internalSave(); |
902 | 937 |
903 fDeviceCMDirty = true; | 938 fDeviceCMDirty = true; |
904 | 939 |
905 SkIRect ir; | 940 SkIRect ir; |
906 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 941 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { |
907 return count; | 942 return; |
908 } | 943 } |
909 | 944 |
910 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about | 945 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy
really care about |
911 // the clipRectBounds() call above? | 946 // the clipRectBounds() call above? |
912 if (kNoLayer_SaveLayerStrategy == strategy) { | 947 if (kNoLayer_SaveLayerStrategy == strategy) { |
913 return count; | 948 return; |
914 } | 949 } |
915 | 950 |
916 // Kill the imagefilter if our device doesn't allow it | 951 // Kill the imagefilter if our device doesn't allow it |
917 SkLazyPaint lazyP; | 952 SkLazyPaint lazyP; |
918 if (paint && paint->getImageFilter()) { | 953 if (paint && paint->getImageFilter()) { |
919 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { | 954 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { |
920 if (justForImageFilter) { | 955 if (justForImageFilter) { |
921 // early exit if the layer was just for the imageFilter | 956 // early exit if the layer was just for the imageFilter |
922 return count; | 957 return; |
923 } | 958 } |
924 SkPaint* p = lazyP.set(*paint); | 959 SkPaint* p = lazyP.set(*paint); |
925 p->setImageFilter(NULL); | 960 p->setImageFilter(NULL); |
926 paint = p; | 961 paint = p; |
927 } | 962 } |
928 } | 963 } |
929 | 964 |
930 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 965 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
931 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), | 966 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
932 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 967 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
933 | 968 |
934 SkBaseDevice* device = this->getTopDevice(); | 969 SkBaseDevice* device = this->getTopDevice(); |
935 if (NULL == device) { | 970 if (NULL == device) { |
936 SkDebugf("Unable to find device for layer."); | 971 SkDebugf("Unable to find device for layer."); |
937 return count; | 972 return; |
938 } | 973 } |
939 | 974 |
940 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; | 975 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; |
941 if (paint && paint->getImageFilter()) { | 976 if (paint && paint->getImageFilter()) { |
942 usage = SkBaseDevice::kImageFilter_Usage; | 977 usage = SkBaseDevice::kImageFilter_Usage; |
943 } | 978 } |
944 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa
ge, | 979 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa
ge, |
945 fProps.pi
xelGeometry())); | 980 fProps.pi
xelGeometry())); |
946 if (NULL == device) { | 981 if (NULL == device) { |
947 SkDebugf("Unable to create device for layer."); | 982 SkDebugf("Unable to create device for layer."); |
948 return count; | 983 return; |
949 } | 984 } |
950 | 985 |
951 device->setOrigin(ir.fLeft, ir.fTop); | 986 device->setOrigin(ir.fLeft, ir.fTop); |
952 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 987 DeviceCM* layer = SkNEW_ARGS(DeviceCM, |
953 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); | 988 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); |
954 device->unref(); | 989 device->unref(); |
955 | 990 |
956 layer->fNext = fMCRec->fTopLayer; | 991 layer->fNext = fMCRec->fTopLayer; |
957 fMCRec->fLayer = layer; | 992 fMCRec->fLayer = layer; |
958 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 993 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
959 | 994 |
960 fSaveLayerCount += 1; | 995 fSaveLayerCount += 1; |
961 return count; | |
962 } | 996 } |
963 | 997 |
964 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 998 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
965 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); | 999 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); |
966 } | 1000 } |
967 | 1001 |
968 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha, | 1002 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha, |
969 SaveFlags flags) { | 1003 SaveFlags flags) { |
970 if (0xFF == alpha) { | 1004 if (0xFF == alpha) { |
971 return this->saveLayer(bounds, NULL, flags); | 1005 return this->saveLayer(bounds, NULL, flags); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 fCullStack.top().x(), fCullStack.top().y(), | 1142 fCullStack.top().x(), fCullStack.top().y(), |
1109 fCullStack.top().right(), fCullStack.top().bottom())); | 1143 fCullStack.top().right(), fCullStack.top().bottom())); |
1110 | 1144 |
1111 #ifdef ASSERT_NESTED_CULLING | 1145 #ifdef ASSERT_NESTED_CULLING |
1112 SkDEBUGFAIL("Invalid cull."); | 1146 SkDEBUGFAIL("Invalid cull."); |
1113 #endif | 1147 #endif |
1114 } | 1148 } |
1115 #endif | 1149 #endif |
1116 | 1150 |
1117 void SkCanvas::pushCull(const SkRect& cullRect) { | 1151 void SkCanvas::pushCull(const SkRect& cullRect) { |
| 1152 this->checkForDeferredSave(); |
1118 ++fCullCount; | 1153 ++fCullCount; |
1119 this->onPushCull(cullRect); | 1154 this->onPushCull(cullRect); |
1120 | 1155 |
1121 #ifdef SK_DEBUG | 1156 #ifdef SK_DEBUG |
1122 // Map the cull rect into device space. | 1157 // Map the cull rect into device space. |
1123 SkRect mappedCull; | 1158 SkRect mappedCull; |
1124 this->getTotalMatrix().mapRect(&mappedCull, cullRect); | 1159 this->getTotalMatrix().mapRect(&mappedCull, cullRect); |
1125 | 1160 |
1126 // Take clipping into account. | 1161 // Take clipping into account. |
1127 SkIRect devClip, devCull; | 1162 SkIRect devClip, devCull; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 SkMatrix m; | 1314 SkMatrix m; |
1280 m.setSkew(sx, sy); | 1315 m.setSkew(sx, sy); |
1281 this->concat(m); | 1316 this->concat(m); |
1282 } | 1317 } |
1283 | 1318 |
1284 void SkCanvas::concat(const SkMatrix& matrix) { | 1319 void SkCanvas::concat(const SkMatrix& matrix) { |
1285 if (matrix.isIdentity()) { | 1320 if (matrix.isIdentity()) { |
1286 return; | 1321 return; |
1287 } | 1322 } |
1288 | 1323 |
| 1324 this->checkForDeferredSave(); |
1289 fDeviceCMDirty = true; | 1325 fDeviceCMDirty = true; |
1290 fCachedLocalClipBoundsDirty = true; | 1326 fCachedLocalClipBoundsDirty = true; |
1291 fMCRec->fMatrix.preConcat(matrix); | 1327 fMCRec->fMatrix.preConcat(matrix); |
1292 | 1328 |
1293 this->didConcat(matrix); | 1329 this->didConcat(matrix); |
1294 } | 1330 } |
1295 | 1331 |
1296 void SkCanvas::setMatrix(const SkMatrix& matrix) { | 1332 void SkCanvas::setMatrix(const SkMatrix& matrix) { |
| 1333 this->checkForDeferredSave(); |
1297 fDeviceCMDirty = true; | 1334 fDeviceCMDirty = true; |
1298 fCachedLocalClipBoundsDirty = true; | 1335 fCachedLocalClipBoundsDirty = true; |
1299 fMCRec->fMatrix = matrix; | 1336 fMCRec->fMatrix = matrix; |
1300 this->didSetMatrix(matrix); | 1337 this->didSetMatrix(matrix); |
1301 } | 1338 } |
1302 | 1339 |
1303 void SkCanvas::resetMatrix() { | 1340 void SkCanvas::resetMatrix() { |
1304 SkMatrix matrix; | 1341 SkMatrix matrix; |
1305 | 1342 |
1306 matrix.reset(); | 1343 matrix.reset(); |
1307 this->setMatrix(matrix); | 1344 this->setMatrix(matrix); |
1308 } | 1345 } |
1309 | 1346 |
1310 ////////////////////////////////////////////////////////////////////////////// | 1347 ////////////////////////////////////////////////////////////////////////////// |
1311 | 1348 |
1312 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 1349 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 1350 this->checkForDeferredSave(); |
1313 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1351 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
1314 this->onClipRect(rect, op, edgeStyle); | 1352 this->onClipRect(rect, op, edgeStyle); |
1315 } | 1353 } |
1316 | 1354 |
1317 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg
eStyle) { | 1355 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg
eStyle) { |
1318 #ifdef SK_ENABLE_CLIP_QUICKREJECT | 1356 #ifdef SK_ENABLE_CLIP_QUICKREJECT |
1319 if (SkRegion::kIntersect_Op == op) { | 1357 if (SkRegion::kIntersect_Op == op) { |
1320 if (fMCRec->fRasterClip.isEmpty()) { | 1358 if (fMCRec->fRasterClip.isEmpty()) { |
1321 return false; | 1359 return false; |
1322 } | 1360 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 this->SkCanvas::onClipPath(path, op, edgeStyle); | 1398 this->SkCanvas::onClipPath(path, op, edgeStyle); |
1361 } | 1399 } |
1362 } | 1400 } |
1363 | 1401 |
1364 static void rasterclip_path(SkRasterClip* rc, const SkCanvas* canvas, const SkPa
th& devPath, | 1402 static void rasterclip_path(SkRasterClip* rc, const SkCanvas* canvas, const SkPa
th& devPath, |
1365 SkRegion::Op op, bool doAA) { | 1403 SkRegion::Op op, bool doAA) { |
1366 rc->op(devPath, canvas->getBaseLayerSize(), op, doAA); | 1404 rc->op(devPath, canvas->getBaseLayerSize(), op, doAA); |
1367 } | 1405 } |
1368 | 1406 |
1369 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { | 1407 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 1408 this->checkForDeferredSave(); |
1370 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1409 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
1371 if (rrect.isRect()) { | 1410 if (rrect.isRect()) { |
1372 this->onClipRect(rrect.getBounds(), op, edgeStyle); | 1411 this->onClipRect(rrect.getBounds(), op, edgeStyle); |
1373 } else { | 1412 } else { |
1374 this->onClipRRect(rrect, op, edgeStyle); | 1413 this->onClipRRect(rrect, op, edgeStyle); |
1375 } | 1414 } |
1376 } | 1415 } |
1377 | 1416 |
1378 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { | 1417 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle
edgeStyle) { |
1379 SkRRect transformedRRect; | 1418 SkRRect transformedRRect; |
(...skipping 15 matching lines...) Expand all Loading... |
1395 return; | 1434 return; |
1396 } | 1435 } |
1397 | 1436 |
1398 SkPath path; | 1437 SkPath path; |
1399 path.addRRect(rrect); | 1438 path.addRRect(rrect); |
1400 // call the non-virtual version | 1439 // call the non-virtual version |
1401 this->SkCanvas::onClipPath(path, op, edgeStyle); | 1440 this->SkCanvas::onClipPath(path, op, edgeStyle); |
1402 } | 1441 } |
1403 | 1442 |
1404 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { | 1443 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 1444 this->checkForDeferredSave(); |
1405 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1445 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
1406 SkRect r; | 1446 SkRect r; |
1407 if (!path.isInverseFillType() && path.isRect(&r)) { | 1447 if (!path.isInverseFillType() && path.isRect(&r)) { |
1408 this->onClipRect(r, op, edgeStyle); | 1448 this->onClipRect(r, op, edgeStyle); |
1409 } else { | 1449 } else { |
1410 this->onClipPath(path, op, edgeStyle); | 1450 this->onClipPath(path, op, edgeStyle); |
1411 } | 1451 } |
1412 } | 1452 } |
1413 | 1453 |
1414 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg
eStyle) { | 1454 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg
eStyle) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1477 edgeStyle = kSoft_ClipEdgeStyle; | 1517 edgeStyle = kSoft_ClipEdgeStyle; |
1478 } | 1518 } |
1479 } | 1519 } |
1480 op = SkRegion::kReplace_Op; | 1520 op = SkRegion::kReplace_Op; |
1481 } | 1521 } |
1482 | 1522 |
1483 rasterclip_path(&fMCRec->fRasterClip, this, devPath, op, edgeStyle); | 1523 rasterclip_path(&fMCRec->fRasterClip, this, devPath, op, edgeStyle); |
1484 } | 1524 } |
1485 | 1525 |
1486 void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { | 1526 void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { |
| 1527 this->checkForDeferredSave(); |
1487 this->onClipRegion(rgn, op); | 1528 this->onClipRegion(rgn, op); |
1488 } | 1529 } |
1489 | 1530 |
1490 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { | 1531 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { |
1491 AutoValidateClip avc(this); | 1532 AutoValidateClip avc(this); |
1492 | 1533 |
1493 fDeviceCMDirty = true; | 1534 fDeviceCMDirty = true; |
1494 fCachedLocalClipBoundsDirty = true; | 1535 fCachedLocalClipBoundsDirty = true; |
1495 | 1536 |
1496 // todo: signal fClipStack that we have a region, and therefore (I guess) | 1537 // todo: signal fClipStack that we have a region, and therefore (I guess) |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 } | 2567 } |
2527 | 2568 |
2528 if (matrix) { | 2569 if (matrix) { |
2529 canvas->concat(*matrix); | 2570 canvas->concat(*matrix); |
2530 } | 2571 } |
2531 } | 2572 } |
2532 | 2573 |
2533 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2574 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2534 fCanvas->restoreToCount(fSaveCount); | 2575 fCanvas->restoreToCount(fSaveCount); |
2535 } | 2576 } |
OLD | NEW |