| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 fFilter = canvas->getDrawFilter(); | 341 fFilter = canvas->getDrawFilter(); |
| 342 fPaint = NULL; | 342 fPaint = NULL; |
| 343 fSaveCount = canvas->getSaveCount(); | 343 fSaveCount = canvas->getSaveCount(); |
| 344 fDoClearImageFilter = false; | 344 fDoClearImageFilter = false; |
| 345 fDone = false; | 345 fDone = false; |
| 346 | 346 |
| 347 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { | 347 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { |
| 348 SkPaint tmp; | 348 SkPaint tmp; |
| 349 tmp.setImageFilter(fOrigPaint.getImageFilter()); | 349 tmp.setImageFilter(fOrigPaint.getImageFilter()); |
| 350 (void)canvas->internalSaveLayer(bounds, &tmp, | 350 (void)canvas->internalSaveLayer(bounds, &tmp, |
| 351 SkCanvas::kARGB_ClipLayer_SaveFlag, true, fa
lse); | 351 SkCanvas::kARGB_ClipLayer_SaveFlag, true); |
| 352 // we'll clear the imageFilter for the actual draws in next(), so | 352 // we'll clear the imageFilter for the actual draws in next(), so |
| 353 // it will only be applied during the restore(). | 353 // it will only be applied during the restore(). |
| 354 fDoClearImageFilter = true; | 354 fDoClearImageFilter = true; |
| 355 } | 355 } |
| 356 | 356 |
| 357 if (fLooper) { | 357 if (fLooper) { |
| 358 fLooper->init(canvas); | 358 fLooper->init(canvas); |
| 359 fIsSimple = false; | 359 fIsSimple = false; |
| 360 } else { | 360 } else { |
| 361 // can we be marked as simple? | 361 // can we be marked as simple? |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 799 |
| 800 fMCRec = newTop; | 800 fMCRec = newTop; |
| 801 | 801 |
| 802 if (SkCanvas::kClip_SaveFlag & flags) { | 802 if (SkCanvas::kClip_SaveFlag & flags) { |
| 803 fClipStack.save(); | 803 fClipStack.save(); |
| 804 } | 804 } |
| 805 | 805 |
| 806 return saveCount; | 806 return saveCount; |
| 807 } | 807 } |
| 808 | 808 |
| 809 void SkCanvas::onSave(SaveFlags) { | |
| 810 // Do nothing. Subclasses may do something. | |
| 811 } | |
| 812 | |
| 813 int SkCanvas::save(SaveFlags flags) { | 809 int SkCanvas::save(SaveFlags flags) { |
| 814 this->onSave(flags); | |
| 815 // call shared impl | 810 // call shared impl |
| 816 return this->internalSave(flags); | 811 return this->internalSave(flags); |
| 817 } | 812 } |
| 818 | 813 |
| 819 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { | 814 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { |
| 820 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 815 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 821 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; | 816 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; |
| 822 #else | 817 #else |
| 823 return true; | 818 return true; |
| 824 #endif | 819 #endif |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 return false; | 856 return false; |
| 862 } | 857 } |
| 863 } | 858 } |
| 864 | 859 |
| 865 if (intersection) { | 860 if (intersection) { |
| 866 *intersection = ir; | 861 *intersection = ir; |
| 867 } | 862 } |
| 868 return true; | 863 return true; |
| 869 } | 864 } |
| 870 | 865 |
| 871 bool SkCanvas::onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) { | |
| 872 // Do nothing. Subclasses may do something. | |
| 873 return true; | |
| 874 } | |
| 875 | |
| 876 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, | 866 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 877 SaveFlags flags) { | 867 SaveFlags flags) { |
| 878 // Overriding classes may return false to signal that we don't need to creat
e a layer. | 868 return this->internalSaveLayer(bounds, paint, flags, false); |
| 879 bool skipLayer = !this->onSaveLayer(bounds, paint, flags); | |
| 880 return this->internalSaveLayer(bounds, paint, flags, false, skipLayer); | |
| 881 } | 869 } |
| 882 | 870 |
| 883 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, | 871 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, |
| 884 const SkImageInfo& info) { | 872 const SkImageInfo& info) { |
| 885 SkBaseDevice* device = canvas->getDevice(); | 873 SkBaseDevice* device = canvas->getDevice(); |
| 886 return device ? device->createCompatibleDevice(info) : NULL; | 874 return device ? device->createCompatibleDevice(info) : NULL; |
| 887 } | 875 } |
| 888 | 876 |
| 889 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, | 877 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, |
| 890 SaveFlags flags, bool justForImageFilter, bool s
kipLayer) { | 878 SaveFlags flags, bool justForImageFilter) { |
| 891 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 879 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 892 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); | 880 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); |
| 893 #endif | 881 #endif |
| 894 | 882 |
| 895 // do this before we create the layer. We don't call the public save() since | 883 // do this before we create the layer. We don't call the public save() since |
| 896 // that would invoke a possibly overridden virtual | 884 // that would invoke a possibly overridden virtual |
| 897 int count = this->internalSave(flags); | 885 int count = this->internalSave(flags); |
| 898 | 886 |
| 899 fDeviceCMDirty = true; | 887 fDeviceCMDirty = true; |
| 900 | 888 |
| 901 SkIRect ir; | 889 SkIRect ir; |
| 902 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { | 890 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter(
) : NULL)) { |
| 903 return count; | 891 return count; |
| 904 } | 892 } |
| 905 | 893 |
| 906 // FIXME: do onSaveLayer() overriders returning false really care about the
clipRectBounds() | |
| 907 // call above? | |
| 908 if (skipLayer) | |
| 909 return count; | |
| 910 | |
| 911 // Kill the imagefilter if our device doesn't allow it | 894 // Kill the imagefilter if our device doesn't allow it |
| 912 SkLazyPaint lazyP; | 895 SkLazyPaint lazyP; |
| 913 if (paint && paint->getImageFilter()) { | 896 if (paint && paint->getImageFilter()) { |
| 914 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { | 897 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { |
| 915 if (justForImageFilter) { | 898 if (justForImageFilter) { |
| 916 // early exit if the layer was just for the imageFilter | 899 // early exit if the layer was just for the imageFilter |
| 917 return count; | 900 return count; |
| 918 } | 901 } |
| 919 SkPaint* p = lazyP.set(*paint); | 902 SkPaint* p = lazyP.set(*paint); |
| 920 p->setImageFilter(NULL); | 903 p->setImageFilter(NULL); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 SaveFlags flags) { | 936 SaveFlags flags) { |
| 954 if (0xFF == alpha) { | 937 if (0xFF == alpha) { |
| 955 return this->saveLayer(bounds, NULL, flags); | 938 return this->saveLayer(bounds, NULL, flags); |
| 956 } else { | 939 } else { |
| 957 SkPaint tmpPaint; | 940 SkPaint tmpPaint; |
| 958 tmpPaint.setAlpha(alpha); | 941 tmpPaint.setAlpha(alpha); |
| 959 return this->saveLayer(bounds, &tmpPaint, flags); | 942 return this->saveLayer(bounds, &tmpPaint, flags); |
| 960 } | 943 } |
| 961 } | 944 } |
| 962 | 945 |
| 963 void SkCanvas::onRestore() { | |
| 964 // Do nothing. Subclasses may do something. | |
| 965 } | |
| 966 | |
| 967 void SkCanvas::restore() { | 946 void SkCanvas::restore() { |
| 968 // check for underflow | 947 // check for underflow |
| 969 if (fMCStack.count() > 1) { | 948 if (fMCStack.count() > 1) { |
| 970 this->onRestore(); | |
| 971 this->internalRestore(); | 949 this->internalRestore(); |
| 972 } | 950 } |
| 973 } | 951 } |
| 974 | 952 |
| 975 void SkCanvas::internalRestore() { | 953 void SkCanvas::internalRestore() { |
| 976 SkASSERT(fMCStack.count() != 0); | 954 SkASSERT(fMCStack.count() != 0); |
| 977 | 955 |
| 978 fDeviceCMDirty = true; | 956 fDeviceCMDirty = true; |
| 979 fCachedLocalClipBoundsDirty = true; | 957 fCachedLocalClipBoundsDirty = true; |
| 980 | 958 |
| (...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2481 if (!bitmap.allocPixels(info)) { | 2459 if (!bitmap.allocPixels(info)) { |
| 2482 return NULL; | 2460 return NULL; |
| 2483 } | 2461 } |
| 2484 | 2462 |
| 2485 // should this functionality be moved into allocPixels()? | 2463 // should this functionality be moved into allocPixels()? |
| 2486 if (!bitmap.info().isOpaque()) { | 2464 if (!bitmap.info().isOpaque()) { |
| 2487 bitmap.eraseColor(0); | 2465 bitmap.eraseColor(0); |
| 2488 } | 2466 } |
| 2489 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2467 return SkNEW_ARGS(SkCanvas, (bitmap)); |
| 2490 } | 2468 } |
| OLD | NEW |