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