Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Side by Side Diff: src/core/SkCanvas.cpp

Issue 196323003: Revert of Revert "De-virtualize SkCanvas save/restore." (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkBBoxHierarchyRecord.cpp ('k') | src/core/SkPictureRecord.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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); 351 SkCanvas::kARGB_ClipLayer_SaveFlag, true, fa lse);
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
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
809 int SkCanvas::save(SaveFlags flags) { 813 int SkCanvas::save(SaveFlags flags) {
814 this->onSave(flags);
810 // call shared impl 815 // call shared impl
811 return this->internalSave(flags); 816 return this->internalSave(flags);
812 } 817 }
813 818
814 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { 819 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
815 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 820 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
816 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; 821 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
817 #else 822 #else
818 return true; 823 return true;
819 #endif 824 #endif
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 return false; 861 return false;
857 } 862 }
858 } 863 }
859 864
860 if (intersection) { 865 if (intersection) {
861 *intersection = ir; 866 *intersection = ir;
862 } 867 }
863 return true; 868 return true;
864 } 869 }
865 870
871 bool SkCanvas::onSaveLayer(const SkRect*, const SkPaint*, SaveFlags) {
872 // Do nothing. Subclasses may do something.
873 return true;
874 }
875
866 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, 876 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
867 SaveFlags flags) { 877 SaveFlags flags) {
868 return this->internalSaveLayer(bounds, paint, flags, false); 878 // Overriding classes may return false to signal that we don't need to creat e a layer.
879 bool skipLayer = !this->onSaveLayer(bounds, paint, flags);
880 return this->internalSaveLayer(bounds, paint, flags, false, skipLayer);
869 } 881 }
870 882
871 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, 883 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
872 const SkImageInfo& info) { 884 const SkImageInfo& info) {
873 SkBaseDevice* device = canvas->getDevice(); 885 SkBaseDevice* device = canvas->getDevice();
874 return device ? device->createCompatibleDevice(info) : NULL; 886 return device ? device->createCompatibleDevice(info) : NULL;
875 } 887 }
876 888
877 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, 889 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
878 SaveFlags flags, bool justForImageFilter) { 890 SaveFlags flags, bool justForImageFilter, bool s kipLayer) {
879 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 891 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
880 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); 892 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag);
881 #endif 893 #endif
882 894
883 // do this before we create the layer. We don't call the public save() since 895 // do this before we create the layer. We don't call the public save() since
884 // that would invoke a possibly overridden virtual 896 // that would invoke a possibly overridden virtual
885 int count = this->internalSave(flags); 897 int count = this->internalSave(flags);
886 898
887 fDeviceCMDirty = true; 899 fDeviceCMDirty = true;
888 900
889 SkIRect ir; 901 SkIRect ir;
890 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 902 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) {
891 return count; 903 return count;
892 } 904 }
893 905
906 // FIXME: do onSaveLayer() overriders returning false really care about the clipRectBounds()
907 // call above?
908 if (skipLayer)
909 return count;
910
894 // Kill the imagefilter if our device doesn't allow it 911 // Kill the imagefilter if our device doesn't allow it
895 SkLazyPaint lazyP; 912 SkLazyPaint lazyP;
896 if (paint && paint->getImageFilter()) { 913 if (paint && paint->getImageFilter()) {
897 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { 914 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) {
898 if (justForImageFilter) { 915 if (justForImageFilter) {
899 // early exit if the layer was just for the imageFilter 916 // early exit if the layer was just for the imageFilter
900 return count; 917 return count;
901 } 918 }
902 SkPaint* p = lazyP.set(*paint); 919 SkPaint* p = lazyP.set(*paint);
903 p->setImageFilter(NULL); 920 p->setImageFilter(NULL);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 SaveFlags flags) { 953 SaveFlags flags) {
937 if (0xFF == alpha) { 954 if (0xFF == alpha) {
938 return this->saveLayer(bounds, NULL, flags); 955 return this->saveLayer(bounds, NULL, flags);
939 } else { 956 } else {
940 SkPaint tmpPaint; 957 SkPaint tmpPaint;
941 tmpPaint.setAlpha(alpha); 958 tmpPaint.setAlpha(alpha);
942 return this->saveLayer(bounds, &tmpPaint, flags); 959 return this->saveLayer(bounds, &tmpPaint, flags);
943 } 960 }
944 } 961 }
945 962
963 void SkCanvas::onRestore() {
964 // Do nothing. Subclasses may do something.
965 }
966
946 void SkCanvas::restore() { 967 void SkCanvas::restore() {
947 // check for underflow 968 // check for underflow
948 if (fMCStack.count() > 1) { 969 if (fMCStack.count() > 1) {
970 this->onRestore();
949 this->internalRestore(); 971 this->internalRestore();
950 } 972 }
951 } 973 }
952 974
953 void SkCanvas::internalRestore() { 975 void SkCanvas::internalRestore() {
954 SkASSERT(fMCStack.count() != 0); 976 SkASSERT(fMCStack.count() != 0);
955 977
956 fDeviceCMDirty = true; 978 fDeviceCMDirty = true;
957 fCachedLocalClipBoundsDirty = true; 979 fCachedLocalClipBoundsDirty = true;
958 980
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 if (!bitmap.allocPixels(info)) { 2481 if (!bitmap.allocPixels(info)) {
2460 return NULL; 2482 return NULL;
2461 } 2483 }
2462 2484
2463 // should this functionality be moved into allocPixels()? 2485 // should this functionality be moved into allocPixels()?
2464 if (!bitmap.info().isOpaque()) { 2486 if (!bitmap.info().isOpaque()) {
2465 bitmap.eraseColor(0); 2487 bitmap.eraseColor(0);
2466 } 2488 }
2467 return SkNEW_ARGS(SkCanvas, (bitmap)); 2489 return SkNEW_ARGS(SkCanvas, (bitmap));
2468 } 2490 }
OLDNEW
« no previous file with comments | « src/core/SkBBoxHierarchyRecord.cpp ('k') | src/core/SkPictureRecord.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698