| 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 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 do { | 804 do { |
| 805 layer->updateMC(totalMatrix, clip, fClipStack, &clip); | 805 layer->updateMC(totalMatrix, clip, fClipStack, &clip); |
| 806 } while ((layer = layer->fNext) != NULL); | 806 } while ((layer = layer->fNext) != NULL); |
| 807 } | 807 } |
| 808 fDeviceCMDirty = false; | 808 fDeviceCMDirty = false; |
| 809 } | 809 } |
| 810 } | 810 } |
| 811 | 811 |
| 812 /////////////////////////////////////////////////////////////////////////////// | 812 /////////////////////////////////////////////////////////////////////////////// |
| 813 | 813 |
| 814 int SkCanvas::getSaveCount() const { |
| 815 return fMCStack.count(); |
| 816 } |
| 817 |
| 818 int SkCanvas::save() { |
| 819 this->willSave(); |
| 820 return this->internalSave(); |
| 821 } |
| 822 |
| 823 void SkCanvas::restore() { |
| 824 // check for underflow |
| 825 if (fMCStack.count() > 1) { |
| 826 this->willRestore(); |
| 827 this->internalRestore(); |
| 828 this->didRestore(); |
| 829 } |
| 830 } |
| 831 |
| 832 void SkCanvas::restoreToCount(int count) { |
| 833 // sanity check |
| 834 if (count < 1) { |
| 835 count = 1; |
| 836 } |
| 837 |
| 838 int n = this->getSaveCount() - count; |
| 839 for (int i = 0; i < n; ++i) { |
| 840 this->restore(); |
| 841 } |
| 842 } |
| 843 |
| 814 int SkCanvas::internalSave() { | 844 int SkCanvas::internalSave() { |
| 815 int saveCount = this->getSaveCount(); // record this before the actual save | 845 int saveCount = this->getSaveCount(); // record this before the actual save |
| 816 | 846 |
| 817 MCRec* newTop = (MCRec*)fMCStack.push_back(); | 847 MCRec* newTop = (MCRec*)fMCStack.push_back(); |
| 818 new (newTop) MCRec(*fMCRec); // balanced in restore() | 848 new (newTop) MCRec(*fMCRec); // balanced in restore() |
| 819 fMCRec = newTop; | 849 fMCRec = newTop; |
| 820 | 850 |
| 821 fClipStack.save(); | 851 fClipStack.save(); |
| 822 | 852 |
| 823 return saveCount; | 853 return saveCount; |
| 824 } | 854 } |
| 825 | 855 |
| 826 int SkCanvas::save() { | |
| 827 this->willSave(); | |
| 828 return this->internalSave(); | |
| 829 } | |
| 830 | |
| 831 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 856 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
| 832 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 857 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 833 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 858 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
| 834 #else | 859 #else |
| 835 return true; | 860 return true; |
| 836 #endif | 861 #endif |
| 837 } | 862 } |
| 838 | 863 |
| 839 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, | 864 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, |
| 840 SkIRect* intersection, const SkImageFilter* image
Filter) { | 865 SkIRect* intersection, const SkImageFilter* image
Filter) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 SaveFlags flags) { | 995 SaveFlags flags) { |
| 971 if (0xFF == alpha) { | 996 if (0xFF == alpha) { |
| 972 return this->saveLayer(bounds, NULL, flags); | 997 return this->saveLayer(bounds, NULL, flags); |
| 973 } else { | 998 } else { |
| 974 SkPaint tmpPaint; | 999 SkPaint tmpPaint; |
| 975 tmpPaint.setAlpha(alpha); | 1000 tmpPaint.setAlpha(alpha); |
| 976 return this->saveLayer(bounds, &tmpPaint, flags); | 1001 return this->saveLayer(bounds, &tmpPaint, flags); |
| 977 } | 1002 } |
| 978 } | 1003 } |
| 979 | 1004 |
| 980 void SkCanvas::restore() { | |
| 981 // check for underflow | |
| 982 if (fMCStack.count() > 1) { | |
| 983 this->willRestore(); | |
| 984 this->internalRestore(); | |
| 985 this->didRestore(); | |
| 986 } | |
| 987 } | |
| 988 | |
| 989 void SkCanvas::internalRestore() { | 1005 void SkCanvas::internalRestore() { |
| 990 SkASSERT(fMCStack.count() != 0); | 1006 SkASSERT(fMCStack.count() != 0); |
| 991 | 1007 |
| 992 fDeviceCMDirty = true; | 1008 fDeviceCMDirty = true; |
| 993 fCachedLocalClipBoundsDirty = true; | 1009 fCachedLocalClipBoundsDirty = true; |
| 994 | 1010 |
| 995 fClipStack.restore(); | 1011 fClipStack.restore(); |
| 996 | 1012 |
| 997 // reserve our layer (if any) | 1013 // reserve our layer (if any) |
| 998 DeviceCM* layer = fMCRec->fLayer; // may be null | 1014 DeviceCM* layer = fMCRec->fLayer; // may be null |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1016 // reset this, since internalDrawDevice will have set it to true | 1032 // reset this, since internalDrawDevice will have set it to true |
| 1017 fDeviceCMDirty = true; | 1033 fDeviceCMDirty = true; |
| 1018 | 1034 |
| 1019 SkASSERT(fSaveLayerCount > 0); | 1035 SkASSERT(fSaveLayerCount > 0); |
| 1020 fSaveLayerCount -= 1; | 1036 fSaveLayerCount -= 1; |
| 1021 } | 1037 } |
| 1022 SkDELETE(layer); | 1038 SkDELETE(layer); |
| 1023 } | 1039 } |
| 1024 } | 1040 } |
| 1025 | 1041 |
| 1026 int SkCanvas::getSaveCount() const { | |
| 1027 return fMCStack.count(); | |
| 1028 } | |
| 1029 | |
| 1030 void SkCanvas::restoreToCount(int count) { | |
| 1031 // sanity check | |
| 1032 if (count < 1) { | |
| 1033 count = 1; | |
| 1034 } | |
| 1035 | |
| 1036 int n = this->getSaveCount() - count; | |
| 1037 for (int i = 0; i < n; ++i) { | |
| 1038 this->restore(); | |
| 1039 } | |
| 1040 } | |
| 1041 | |
| 1042 bool SkCanvas::isDrawingToLayer() const { | 1042 bool SkCanvas::isDrawingToLayer() const { |
| 1043 return fSaveLayerCount > 0; | 1043 return fSaveLayerCount > 0; |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 1046 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
| 1047 if (NULL == props) { | 1047 if (NULL == props) { |
| 1048 props = &fProps; | 1048 props = &fProps; |
| 1049 } | 1049 } |
| 1050 return this->onNewSurface(info, *props); | 1050 return this->onNewSurface(info, *props); |
| 1051 } | 1051 } |
| (...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2584 } | 2584 } |
| 2585 | 2585 |
| 2586 if (matrix) { | 2586 if (matrix) { |
| 2587 canvas->concat(*matrix); | 2587 canvas->concat(*matrix); |
| 2588 } | 2588 } |
| 2589 } | 2589 } |
| 2590 | 2590 |
| 2591 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2591 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2592 fCanvas->restoreToCount(fSaveCount); | 2592 fCanvas->restoreToCount(fSaveCount); |
| 2593 } | 2593 } |
| OLD | NEW |