| 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 "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 void SkCanvas::restore() { | 788 void SkCanvas::restore() { |
| 789 if (fMCRec->fDeferredSaveCount > 0) { | 789 if (fMCRec->fDeferredSaveCount > 0) { |
| 790 SkASSERT(fSaveCount > 1); | 790 SkASSERT(fSaveCount > 1); |
| 791 fSaveCount -= 1; | 791 fSaveCount -= 1; |
| 792 fMCRec->fDeferredSaveCount -= 1; | 792 fMCRec->fDeferredSaveCount -= 1; |
| 793 } else { | 793 } else { |
| 794 // check for underflow | 794 // check for underflow |
| 795 if (fMCStack.count() > 1) { | 795 if (fMCStack.count() > 1) { |
| 796 this->willRestore(); | 796 this->willRestore(); |
| 797 SkASSERT(fSaveCount > 1); | 797 SkASSERT(fSaveCount > 1); |
| 798 fSaveCount -= 1; | |
| 799 this->internalRestore(); | 798 this->internalRestore(); |
| 800 this->didRestore(); | 799 this->didRestore(); |
| 801 } | 800 } |
| 802 } | 801 } |
| 803 } | 802 } |
| 804 | 803 |
| 805 void SkCanvas::restoreToCount(int count) { | 804 void SkCanvas::restoreToCount(int count) { |
| 806 // sanity check | 805 // sanity check |
| 807 if (count < 1) { | 806 if (count < 1) { |
| 808 count = 1; | 807 count = 1; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 *intersection = ir; | 871 *intersection = ir; |
| 873 } | 872 } |
| 874 return true; | 873 return true; |
| 875 } | 874 } |
| 876 | 875 |
| 877 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { | 876 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { |
| 878 if (gIgnoreSaveLayerBounds) { | 877 if (gIgnoreSaveLayerBounds) { |
| 879 bounds = NULL; | 878 bounds = NULL; |
| 880 } | 879 } |
| 881 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); | 880 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); |
| 882 fSaveCount += 1; | |
| 883 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy); | 881 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy); |
| 884 return this->getSaveCount() - 1; | 882 return this->getSaveCount() - 1; |
| 885 } | 883 } |
| 886 | 884 |
| 887 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl
ags) { | 885 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl
ags) { |
| 888 if (gIgnoreSaveLayerBounds) { | 886 if (gIgnoreSaveLayerBounds) { |
| 889 bounds = NULL; | 887 bounds = NULL; |
| 890 } | 888 } |
| 891 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); | 889 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); |
| 892 fSaveCount += 1; | |
| 893 this->internalSaveLayer(bounds, paint, flags, strategy); | 890 this->internalSaveLayer(bounds, paint, flags, strategy); |
| 894 return this->getSaveCount() - 1; | 891 return this->getSaveCount() - 1; |
| 895 } | 892 } |
| 896 | 893 |
| 897 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, | 894 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, |
| 898 SaveLayerStrategy strategy) { | 895 SaveLayerStrategy strategy) { |
| 899 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 896 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 900 flags |= kClipToLayer_SaveFlag; | 897 flags |= kClipToLayer_SaveFlag; |
| 901 #endif | 898 #endif |
| 902 | 899 |
| 900 fSaveCount += 1; |
| 901 |
| 903 // do this before we create the layer. We don't call the public save() since | 902 // do this before we create the layer. We don't call the public save() since |
| 904 // that would invoke a possibly overridden virtual | 903 // that would invoke a possibly overridden virtual |
| 905 this->internalSave(); | 904 this->internalSave(); |
| 906 | 905 |
| 907 fDeviceCMDirty = true; | 906 fDeviceCMDirty = true; |
| 908 | 907 |
| 909 SkIRect ir; | 908 SkIRect ir; |
| 910 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 909 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { |
| 911 return; | 910 return; |
| 912 } | 911 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 } else { | 970 } else { |
| 972 SkPaint tmpPaint; | 971 SkPaint tmpPaint; |
| 973 tmpPaint.setAlpha(alpha); | 972 tmpPaint.setAlpha(alpha); |
| 974 return this->saveLayer(bounds, &tmpPaint, flags); | 973 return this->saveLayer(bounds, &tmpPaint, flags); |
| 975 } | 974 } |
| 976 } | 975 } |
| 977 | 976 |
| 978 void SkCanvas::internalRestore() { | 977 void SkCanvas::internalRestore() { |
| 979 SkASSERT(fMCStack.count() != 0); | 978 SkASSERT(fMCStack.count() != 0); |
| 980 | 979 |
| 980 fSaveCount -= 1; |
| 981 |
| 981 fDeviceCMDirty = true; | 982 fDeviceCMDirty = true; |
| 982 fCachedLocalClipBoundsDirty = true; | 983 fCachedLocalClipBoundsDirty = true; |
| 983 | 984 |
| 984 fClipStack->restore(); | 985 fClipStack->restore(); |
| 985 | 986 |
| 986 // reserve our layer (if any) | 987 // reserve our layer (if any) |
| 987 DeviceCM* layer = fMCRec->fLayer; // may be null | 988 DeviceCM* layer = fMCRec->fLayer; // may be null |
| 988 // now detach it from fMCRec so we can pop(). Gets freed after its drawn | 989 // now detach it from fMCRec so we can pop(). Gets freed after its drawn |
| 989 fMCRec->fLayer = NULL; | 990 fMCRec->fLayer = NULL; |
| 990 | 991 |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 } | 2521 } |
| 2521 | 2522 |
| 2522 if (matrix) { | 2523 if (matrix) { |
| 2523 canvas->concat(*matrix); | 2524 canvas->concat(*matrix); |
| 2524 } | 2525 } |
| 2525 } | 2526 } |
| 2526 | 2527 |
| 2527 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2528 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2528 fCanvas->restoreToCount(fSaveCount); | 2529 fCanvas->restoreToCount(fSaveCount); |
| 2529 } | 2530 } |
| OLD | NEW |