Chromium Code Reviews| 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; | |
|
f(malita)
2014/12/10 19:49:33
I always imagined this to be an unsigned, but yeah
| |
| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 fSaveLayerCount = 0; | 418 fSaveLayerCount = 0; |
| 417 fCullCount = 0; | 419 fCullCount = 0; |
| 418 fMetaData = NULL; | 420 fMetaData = NULL; |
| 419 | 421 |
| 420 fMCRec = (MCRec*)fMCStack.push_back(); | 422 fMCRec = (MCRec*)fMCStack.push_back(); |
| 421 new (fMCRec) MCRec(fConservativeRasterClip); | 423 new (fMCRec) MCRec(fConservativeRasterClip); |
| 422 | 424 |
| 423 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); | 425 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative RasterClip)); |
| 424 fMCRec->fTopLayer = fMCRec->fLayer; | 426 fMCRec->fTopLayer = fMCRec->fLayer; |
| 425 | 427 |
| 428 fCallingWillSave = false; | |
| 429 | |
| 426 fSurfaceBase = NULL; | 430 fSurfaceBase = NULL; |
| 427 | 431 |
| 428 if (device) { | 432 if (device) { |
| 429 device->initForRootLayer(fProps.pixelGeometry()); | 433 device->initForRootLayer(fProps.pixelGeometry()); |
| 430 if (device->forceConservativeRasterClip()) { | 434 if (device->forceConservativeRasterClip()) { |
| 431 fConservativeRasterClip = true; | 435 fConservativeRasterClip = true; |
| 432 } | 436 } |
| 433 device->onAttachToCanvas(this); | 437 device->onAttachToCanvas(this); |
| 434 fMCRec->fLayer->fDevice = SkRef(device); | 438 fMCRec->fLayer->fDevice = SkRef(device); |
| 435 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); | 439 fMCRec->fRasterClip.setRect(device->getGlobalBounds()); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 do { | 782 do { |
| 779 layer->updateMC(totalMatrix, clip, fClipStack, &clip); | 783 layer->updateMC(totalMatrix, clip, fClipStack, &clip); |
| 780 } while ((layer = layer->fNext) != NULL); | 784 } while ((layer = layer->fNext) != NULL); |
| 781 } | 785 } |
| 782 fDeviceCMDirty = false; | 786 fDeviceCMDirty = false; |
| 783 } | 787 } |
| 784 } | 788 } |
| 785 | 789 |
| 786 /////////////////////////////////////////////////////////////////////////////// | 790 /////////////////////////////////////////////////////////////////////////////// |
| 787 | 791 |
| 792 void SkCanvas::checkForDeferredSave() { | |
| 793 if (fMCRec->fDeferredSaveCount > 0) { | |
| 794 fMCRec->fDeferredSaveCount -= 1; | |
| 795 this->doSave(); | |
| 796 } | |
| 797 } | |
| 798 | |
| 788 int SkCanvas::getSaveCount() const { | 799 int SkCanvas::getSaveCount() const { |
|
f(malita)
2014/12/10 19:49:33
To avoid perf surprises, we should probably track
reed1
2014/12/10 20:06:36
Probably true :(
| |
| 789 return fMCStack.count(); | 800 int count = 0; |
| 801 SkDeque::Iter iter(fMCStack, SkDeque::Iter::kFront_IterStart); | |
| 802 for (;;) { | |
| 803 const MCRec* rec = (const MCRec*)iter.next(); | |
|
f(malita)
2014/12/10 19:49:33
I think this will miss all deferred saves on the i
reed1
2014/12/10 20:06:36
next() returns the first one : its a funny pattern
| |
| 804 if (!rec) { | |
| 805 break; | |
| 806 } | |
| 807 count += 1 + rec->fDeferredSaveCount; | |
| 808 } | |
| 809 return count; | |
|
f(malita)
2014/12/10 19:49:33
Would it be simpler to just iterate over all MCRec
reed1
2014/12/10 20:06:35
see above
f(malita)
2014/12/10 20:13:58
Hmm, then something's not clicking: do we need to
| |
| 790 } | 810 } |
| 791 | 811 |
| 792 int SkCanvas::save() { | 812 int SkCanvas::save() { |
| 813 fMCRec->fDeferredSaveCount += 1; | |
| 814 #if 0 | |
| 815 this->checkForDeferredSave(); | |
| 816 #endif | |
| 817 return this->getSaveCount() - 1; // return our prev value | |
| 818 } | |
| 819 | |
| 820 void SkCanvas::doSave() { | |
| 821 fCallingWillSave = true; | |
| 793 this->willSave(); | 822 this->willSave(); |
| 794 return this->internalSave(); | 823 fCallingWillSave = false; |
|
robertphillips
2014/12/10 18:43:53
Do we need this cast ?
reed1
2014/12/10 20:06:35
Done.
| |
| 824 (void)this->internalSave(); | |
| 795 } | 825 } |
| 796 | 826 |
| 797 void SkCanvas::restore() { | 827 void SkCanvas::restore() { |
| 798 // check for underflow | 828 if (fMCRec->fDeferredSaveCount > 0) { |
| 799 if (fMCStack.count() > 1) { | 829 fMCRec->fDeferredSaveCount -= 1; |
| 800 this->willRestore(); | 830 } else { |
| 801 this->internalRestore(); | 831 // check for underflow |
| 802 this->didRestore(); | 832 if (fMCStack.count() > 1) { |
| 833 this->willRestore(); | |
| 834 this->internalRestore(); | |
| 835 this->didRestore(); | |
| 836 } | |
| 803 } | 837 } |
| 804 } | 838 } |
| 805 | 839 |
| 806 void SkCanvas::restoreToCount(int count) { | 840 void SkCanvas::restoreToCount(int count) { |
| 807 // sanity check | 841 // sanity check |
| 808 if (count < 1) { | 842 if (count < 1) { |
| 809 count = 1; | 843 count = 1; |
| 810 } | 844 } |
| 811 | 845 |
| 812 int n = this->getSaveCount() - count; | 846 int n = this->getSaveCount() - count; |
| 813 for (int i = 0; i < n; ++i) { | 847 for (int i = 0; i < n; ++i) { |
| 814 this->restore(); | 848 this->restore(); |
| 815 } | 849 } |
| 816 } | 850 } |
| 817 | 851 |
| 818 int SkCanvas::internalSave() { | 852 void SkCanvas::internalSave() { |
| 819 int saveCount = this->getSaveCount(); // record this before the actual save | |
| 820 | |
| 821 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 853 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
| 822 new (newTop) MCRec(*fMCRec); // balanced in restore() | 854 new (newTop) MCRec(*fMCRec); // balanced in restore() |
| 823 fMCRec = newTop; | 855 fMCRec = newTop; |
| 824 | 856 |
| 825 fClipStack.save(); | 857 fClipStack.save(); |
| 826 | |
| 827 return saveCount; | |
| 828 } | 858 } |
| 829 | 859 |
| 830 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 860 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
| 831 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 861 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 832 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 862 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
| 833 #else | 863 #else |
| 834 return true; | 864 return true; |
| 835 #endif | 865 #endif |
| 836 } | 866 } |
| 837 | 867 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 } | 904 } |
| 875 | 905 |
| 876 if (intersection) { | 906 if (intersection) { |
| 877 *intersection = ir; | 907 *intersection = ir; |
| 878 } | 908 } |
| 879 return true; | 909 return true; |
| 880 } | 910 } |
| 881 | 911 |
| 882 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { | 912 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { |
| 883 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag); | 913 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag); |
| 884 return this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, fals e, strategy); | 914 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, false, stra tegy); |
| 915 return this->getSaveCount() - 1; | |
| 885 } | 916 } |
| 886 | 917 |
| 887 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, | 918 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) { |
| 888 SaveFlags flags) { | |
| 889 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); | 919 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); |
| 890 return this->internalSaveLayer(bounds, paint, flags, false, strategy); | 920 this->internalSaveLayer(bounds, paint, flags, false, strategy); |
| 921 return this->getSaveCount() - 1; | |
| 891 } | 922 } |
| 892 | 923 |
| 893 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save Flags flags, | 924 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, |
| 894 bool justForImageFilter, SaveLayerStrategy strat egy) { | 925 bool justForImageFilter, SaveLayerStrategy strat egy) { |
| 895 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 926 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 896 flags |= kClipToLayer_SaveFlag; | 927 flags |= kClipToLayer_SaveFlag; |
| 897 #endif | 928 #endif |
| 898 | 929 |
| 899 // do this before we create the layer. We don't call the public save() since | 930 // do this before we create the layer. We don't call the public save() since |
| 900 // that would invoke a possibly overridden virtual | 931 // that would invoke a possibly overridden virtual |
| 901 int count = this->internalSave(); | 932 this->internalSave(); |
| 902 | 933 |
| 903 fDeviceCMDirty = true; | 934 fDeviceCMDirty = true; |
| 904 | 935 |
| 905 SkIRect ir; | 936 SkIRect ir; |
| 906 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { | 937 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { |
| 907 return count; | 938 return; |
| 908 } | 939 } |
| 909 | 940 |
| 910 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about | 941 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about |
| 911 // the clipRectBounds() call above? | 942 // the clipRectBounds() call above? |
| 912 if (kNoLayer_SaveLayerStrategy == strategy) { | 943 if (kNoLayer_SaveLayerStrategy == strategy) { |
| 913 return count; | 944 return; |
| 914 } | 945 } |
| 915 | 946 |
| 916 // Kill the imagefilter if our device doesn't allow it | 947 // Kill the imagefilter if our device doesn't allow it |
| 917 SkLazyPaint lazyP; | 948 SkLazyPaint lazyP; |
| 918 if (paint && paint->getImageFilter()) { | 949 if (paint && paint->getImageFilter()) { |
| 919 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { | 950 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { |
| 920 if (justForImageFilter) { | 951 if (justForImageFilter) { |
| 921 // early exit if the layer was just for the imageFilter | 952 // early exit if the layer was just for the imageFilter |
| 922 return count; | 953 return; |
| 923 } | 954 } |
| 924 SkPaint* p = lazyP.set(*paint); | 955 SkPaint* p = lazyP.set(*paint); |
| 925 p->setImageFilter(NULL); | 956 p->setImageFilter(NULL); |
| 926 paint = p; | 957 paint = p; |
| 927 } | 958 } |
| 928 } | 959 } |
| 929 | 960 |
| 930 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 961 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
| 931 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), | 962 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
| 932 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 963 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 933 | 964 |
| 934 SkBaseDevice* device = this->getTopDevice(); | 965 SkBaseDevice* device = this->getTopDevice(); |
| 935 if (NULL == device) { | 966 if (NULL == device) { |
| 936 SkDebugf("Unable to find device for layer."); | 967 SkDebugf("Unable to find device for layer."); |
| 937 return count; | 968 return; |
| 938 } | 969 } |
| 939 | 970 |
| 940 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; | 971 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; |
| 941 if (paint && paint->getImageFilter()) { | 972 if (paint && paint->getImageFilter()) { |
| 942 usage = SkBaseDevice::kImageFilter_Usage; | 973 usage = SkBaseDevice::kImageFilter_Usage; |
| 943 } | 974 } |
| 944 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa ge, | 975 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa ge, |
| 945 fProps.pi xelGeometry())); | 976 fProps.pi xelGeometry())); |
| 946 if (NULL == device) { | 977 if (NULL == device) { |
| 947 SkDebugf("Unable to create device for layer."); | 978 SkDebugf("Unable to create device for layer."); |
| 948 return count; | 979 return; |
| 949 } | 980 } |
| 950 | 981 |
| 951 device->setOrigin(ir.fLeft, ir.fTop); | 982 device->setOrigin(ir.fLeft, ir.fTop); |
| 952 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 983 DeviceCM* layer = SkNEW_ARGS(DeviceCM, |
| 953 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip)); | 984 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip)); |
| 954 device->unref(); | 985 device->unref(); |
| 955 | 986 |
| 956 layer->fNext = fMCRec->fTopLayer; | 987 layer->fNext = fMCRec->fTopLayer; |
| 957 fMCRec->fLayer = layer; | 988 fMCRec->fLayer = layer; |
| 958 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 989 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
| 959 | 990 |
| 960 fSaveLayerCount += 1; | 991 fSaveLayerCount += 1; |
| 961 return count; | |
| 962 } | 992 } |
| 963 | 993 |
| 964 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 994 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
| 965 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); | 995 return this->saveLayerAlpha(bounds, alpha, kARGB_ClipLayer_SaveFlag); |
| 966 } | 996 } |
| 967 | 997 |
| 968 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha, | 998 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha, |
| 969 SaveFlags flags) { | 999 SaveFlags flags) { |
| 970 if (0xFF == alpha) { | 1000 if (0xFF == alpha) { |
| 971 return this->saveLayer(bounds, NULL, flags); | 1001 return this->saveLayer(bounds, NULL, flags); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 SkMatrix m; | 1309 SkMatrix m; |
| 1280 m.setSkew(sx, sy); | 1310 m.setSkew(sx, sy); |
| 1281 this->concat(m); | 1311 this->concat(m); |
| 1282 } | 1312 } |
| 1283 | 1313 |
| 1284 void SkCanvas::concat(const SkMatrix& matrix) { | 1314 void SkCanvas::concat(const SkMatrix& matrix) { |
| 1285 if (matrix.isIdentity()) { | 1315 if (matrix.isIdentity()) { |
| 1286 return; | 1316 return; |
| 1287 } | 1317 } |
| 1288 | 1318 |
| 1319 this->checkForDeferredSave(); | |
| 1289 fDeviceCMDirty = true; | 1320 fDeviceCMDirty = true; |
| 1290 fCachedLocalClipBoundsDirty = true; | 1321 fCachedLocalClipBoundsDirty = true; |
| 1291 fMCRec->fMatrix.preConcat(matrix); | 1322 fMCRec->fMatrix.preConcat(matrix); |
| 1292 | 1323 |
| 1293 this->didConcat(matrix); | 1324 this->didConcat(matrix); |
| 1294 } | 1325 } |
| 1295 | 1326 |
| 1296 void SkCanvas::setMatrix(const SkMatrix& matrix) { | 1327 void SkCanvas::setMatrix(const SkMatrix& matrix) { |
| 1328 this->checkForDeferredSave(); | |
| 1297 fDeviceCMDirty = true; | 1329 fDeviceCMDirty = true; |
| 1298 fCachedLocalClipBoundsDirty = true; | 1330 fCachedLocalClipBoundsDirty = true; |
| 1299 fMCRec->fMatrix = matrix; | 1331 fMCRec->fMatrix = matrix; |
| 1300 this->didSetMatrix(matrix); | 1332 this->didSetMatrix(matrix); |
| 1301 } | 1333 } |
| 1302 | 1334 |
| 1303 void SkCanvas::resetMatrix() { | 1335 void SkCanvas::resetMatrix() { |
| 1304 SkMatrix matrix; | 1336 SkMatrix matrix; |
| 1305 | 1337 |
| 1306 matrix.reset(); | 1338 matrix.reset(); |
| 1307 this->setMatrix(matrix); | 1339 this->setMatrix(matrix); |
| 1308 } | 1340 } |
| 1309 | 1341 |
| 1310 ////////////////////////////////////////////////////////////////////////////// | 1342 ////////////////////////////////////////////////////////////////////////////// |
| 1311 | 1343 |
| 1312 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { | 1344 void SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
| 1345 this->checkForDeferredSave(); | |
| 1313 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1346 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
| 1314 this->onClipRect(rect, op, edgeStyle); | 1347 this->onClipRect(rect, op, edgeStyle); |
| 1315 } | 1348 } |
| 1316 | 1349 |
| 1317 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) { | 1350 void SkCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edg eStyle) { |
| 1318 #ifdef SK_ENABLE_CLIP_QUICKREJECT | 1351 #ifdef SK_ENABLE_CLIP_QUICKREJECT |
| 1319 if (SkRegion::kIntersect_Op == op) { | 1352 if (SkRegion::kIntersect_Op == op) { |
| 1320 if (fMCRec->fRasterClip.isEmpty()) { | 1353 if (fMCRec->fRasterClip.isEmpty()) { |
| 1321 return false; | 1354 return false; |
| 1322 } | 1355 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1360 this->SkCanvas::onClipPath(path, op, edgeStyle); | 1393 this->SkCanvas::onClipPath(path, op, edgeStyle); |
| 1361 } | 1394 } |
| 1362 } | 1395 } |
| 1363 | 1396 |
| 1364 static void rasterclip_path(SkRasterClip* rc, const SkCanvas* canvas, const SkPa th& devPath, | 1397 static void rasterclip_path(SkRasterClip* rc, const SkCanvas* canvas, const SkPa th& devPath, |
| 1365 SkRegion::Op op, bool doAA) { | 1398 SkRegion::Op op, bool doAA) { |
| 1366 rc->op(devPath, canvas->getBaseLayerSize(), op, doAA); | 1399 rc->op(devPath, canvas->getBaseLayerSize(), op, doAA); |
| 1367 } | 1400 } |
| 1368 | 1401 |
| 1369 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { | 1402 void SkCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { |
| 1403 this->checkForDeferredSave(); | |
| 1370 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1404 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
| 1371 if (rrect.isRect()) { | 1405 if (rrect.isRect()) { |
| 1372 this->onClipRect(rrect.getBounds(), op, edgeStyle); | 1406 this->onClipRect(rrect.getBounds(), op, edgeStyle); |
| 1373 } else { | 1407 } else { |
| 1374 this->onClipRRect(rrect, op, edgeStyle); | 1408 this->onClipRRect(rrect, op, edgeStyle); |
| 1375 } | 1409 } |
| 1376 } | 1410 } |
| 1377 | 1411 |
| 1378 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { | 1412 void SkCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) { |
| 1379 SkRRect transformedRRect; | 1413 SkRRect transformedRRect; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1395 return; | 1429 return; |
| 1396 } | 1430 } |
| 1397 | 1431 |
| 1398 SkPath path; | 1432 SkPath path; |
| 1399 path.addRRect(rrect); | 1433 path.addRRect(rrect); |
| 1400 // call the non-virtual version | 1434 // call the non-virtual version |
| 1401 this->SkCanvas::onClipPath(path, op, edgeStyle); | 1435 this->SkCanvas::onClipPath(path, op, edgeStyle); |
| 1402 } | 1436 } |
| 1403 | 1437 |
| 1404 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { | 1438 void SkCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
| 1439 this->checkForDeferredSave(); | |
| 1405 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; | 1440 ClipEdgeStyle edgeStyle = doAA ? kSoft_ClipEdgeStyle : kHard_ClipEdgeStyle; |
| 1406 SkRect r; | 1441 SkRect r; |
| 1407 if (!path.isInverseFillType() && path.isRect(&r)) { | 1442 if (!path.isInverseFillType() && path.isRect(&r)) { |
| 1408 this->onClipRect(r, op, edgeStyle); | 1443 this->onClipRect(r, op, edgeStyle); |
| 1409 } else { | 1444 } else { |
| 1410 this->onClipPath(path, op, edgeStyle); | 1445 this->onClipPath(path, op, edgeStyle); |
| 1411 } | 1446 } |
| 1412 } | 1447 } |
| 1413 | 1448 |
| 1414 void SkCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edg eStyle) { | 1449 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; | 1512 edgeStyle = kSoft_ClipEdgeStyle; |
| 1478 } | 1513 } |
| 1479 } | 1514 } |
| 1480 op = SkRegion::kReplace_Op; | 1515 op = SkRegion::kReplace_Op; |
| 1481 } | 1516 } |
| 1482 | 1517 |
| 1483 rasterclip_path(&fMCRec->fRasterClip, this, devPath, op, edgeStyle); | 1518 rasterclip_path(&fMCRec->fRasterClip, this, devPath, op, edgeStyle); |
| 1484 } | 1519 } |
| 1485 | 1520 |
| 1486 void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { | 1521 void SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { |
| 1522 this->checkForDeferredSave(); | |
| 1487 this->onClipRegion(rgn, op); | 1523 this->onClipRegion(rgn, op); |
| 1488 } | 1524 } |
| 1489 | 1525 |
| 1490 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { | 1526 void SkCanvas::onClipRegion(const SkRegion& rgn, SkRegion::Op op) { |
| 1491 AutoValidateClip avc(this); | 1527 AutoValidateClip avc(this); |
| 1492 | 1528 |
| 1493 fDeviceCMDirty = true; | 1529 fDeviceCMDirty = true; |
| 1494 fCachedLocalClipBoundsDirty = true; | 1530 fCachedLocalClipBoundsDirty = true; |
| 1495 | 1531 |
| 1496 // todo: signal fClipStack that we have a region, and therefore (I guess) | 1532 // 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 } | 2562 } |
| 2527 | 2563 |
| 2528 if (matrix) { | 2564 if (matrix) { |
| 2529 canvas->concat(*matrix); | 2565 canvas->concat(*matrix); |
| 2530 } | 2566 } |
| 2531 } | 2567 } |
| 2532 | 2568 |
| 2533 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2569 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2534 fCanvas->restoreToCount(fSaveCount); | 2570 fCanvas->restoreToCount(fSaveCount); |
| 2535 } | 2571 } |
| OLD | NEW |