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

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

Issue 194713008: De-virtualize SkCanvas save/restore. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Rebased 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 fCanvas = canvas; 340 fCanvas = canvas;
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, SkCanvas::kARGB_ClipLa yer_SaveFlag,
351 SkCanvas::kARGB_ClipLayer_SaveFlag, true); 351 true, SkCanvas::kFullLayer_SaveLayer Strategy);
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 (SkDrawLooper* looper = paint.getLooper()) { 357 if (SkDrawLooper* looper = paint.getLooper()) {
358 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 358 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
359 looper->contextSize()); 359 looper->contextSize());
360 fLooperContext = looper->createContext(canvas, buffer); 360 fLooperContext = looper->createContext(canvas, buffer);
361 fIsSimple = false; 361 fIsSimple = false;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 803
804 fMCRec = newTop; 804 fMCRec = newTop;
805 805
806 if (SkCanvas::kClip_SaveFlag & flags) { 806 if (SkCanvas::kClip_SaveFlag & flags) {
807 fClipStack.save(); 807 fClipStack.save();
808 } 808 }
809 809
810 return saveCount; 810 return saveCount;
811 } 811 }
812 812
813 void SkCanvas::willSave(SaveFlags) {
814 // Do nothing. Subclasses may do something.
815 }
816
813 int SkCanvas::save(SaveFlags flags) { 817 int SkCanvas::save(SaveFlags flags) {
818 this->willSave(flags);
814 // call shared impl 819 // call shared impl
815 return this->internalSave(flags); 820 return this->internalSave(flags);
816 } 821 }
817 822
818 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { 823 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
819 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 824 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
820 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; 825 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
821 #else 826 #else
822 return true; 827 return true;
823 #endif 828 #endif
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 return false; 865 return false;
861 } 866 }
862 } 867 }
863 868
864 if (intersection) { 869 if (intersection) {
865 *intersection = ir; 870 *intersection = ir;
866 } 871 }
867 return true; 872 return true;
868 } 873 }
869 874
875 SkCanvas::SaveLayerStrategy SkCanvas::willSaveLayer(const SkRect*, const SkPaint *, SaveFlags) {
876
877 // Do nothing. Subclasses may do something.
878 return kFullLayer_SaveLayerStrategy;
879 }
880
870 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, 881 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
871 SaveFlags flags) { 882 SaveFlags flags) {
872 return this->internalSaveLayer(bounds, paint, flags, false); 883 // Overriding classes may return false to signal that we don't need to creat e a layer.
884 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
885 return this->internalSaveLayer(bounds, paint, flags, false, strategy);
873 } 886 }
874 887
875 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, 888 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
876 const SkImageInfo& info) { 889 const SkImageInfo& info) {
877 SkBaseDevice* device = canvas->getDevice(); 890 SkBaseDevice* device = canvas->getDevice();
878 return device ? device->createCompatibleDevice(info) : NULL; 891 return device ? device->createCompatibleDevice(info) : NULL;
879 } 892 }
880 893
881 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, 894 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save Flags flags,
882 SaveFlags flags, bool justForImageFilter) { 895 bool justForImageFilter, SaveLayerStrategy strat egy) {
883 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 896 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
884 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); 897 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag);
885 #endif 898 #endif
886 899
887 // do this before we create the layer. We don't call the public save() since 900 // do this before we create the layer. We don't call the public save() since
888 // that would invoke a possibly overridden virtual 901 // that would invoke a possibly overridden virtual
889 int count = this->internalSave(flags); 902 int count = this->internalSave(flags);
890 903
891 fDeviceCMDirty = true; 904 fDeviceCMDirty = true;
892 905
893 SkIRect ir; 906 SkIRect ir;
894 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 907 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) {
895 return count; 908 return count;
896 } 909 }
897 910
911 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
912 // the clipRectBounds() call above?
913 if (kNoLayer_SaveLayerStrategy == strategy) {
914 return count;
915 }
916
898 // Kill the imagefilter if our device doesn't allow it 917 // Kill the imagefilter if our device doesn't allow it
899 SkLazyPaint lazyP; 918 SkLazyPaint lazyP;
900 if (paint && paint->getImageFilter()) { 919 if (paint && paint->getImageFilter()) {
901 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { 920 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) {
902 if (justForImageFilter) { 921 if (justForImageFilter) {
903 // early exit if the layer was just for the imageFilter 922 // early exit if the layer was just for the imageFilter
904 return count; 923 return count;
905 } 924 }
906 SkPaint* p = lazyP.set(*paint); 925 SkPaint* p = lazyP.set(*paint);
907 p->setImageFilter(NULL); 926 p->setImageFilter(NULL);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 SaveFlags flags) { 959 SaveFlags flags) {
941 if (0xFF == alpha) { 960 if (0xFF == alpha) {
942 return this->saveLayer(bounds, NULL, flags); 961 return this->saveLayer(bounds, NULL, flags);
943 } else { 962 } else {
944 SkPaint tmpPaint; 963 SkPaint tmpPaint;
945 tmpPaint.setAlpha(alpha); 964 tmpPaint.setAlpha(alpha);
946 return this->saveLayer(bounds, &tmpPaint, flags); 965 return this->saveLayer(bounds, &tmpPaint, flags);
947 } 966 }
948 } 967 }
949 968
969 void SkCanvas::willRestore() {
970 // Do nothing. Subclasses may do something.
971 }
972
950 void SkCanvas::restore() { 973 void SkCanvas::restore() {
951 // check for underflow 974 // check for underflow
952 if (fMCStack.count() > 1) { 975 if (fMCStack.count() > 1) {
976 this->willRestore();
953 this->internalRestore(); 977 this->internalRestore();
954 } 978 }
955 } 979 }
956 980
957 void SkCanvas::internalRestore() { 981 void SkCanvas::internalRestore() {
958 SkASSERT(fMCStack.count() != 0); 982 SkASSERT(fMCStack.count() != 0);
959 983
960 fDeviceCMDirty = true; 984 fDeviceCMDirty = true;
961 fCachedLocalClipBoundsDirty = true; 985 fCachedLocalClipBoundsDirty = true;
962 986
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after
2477 if (!bitmap.allocPixels(info)) { 2501 if (!bitmap.allocPixels(info)) {
2478 return NULL; 2502 return NULL;
2479 } 2503 }
2480 2504
2481 // should this functionality be moved into allocPixels()? 2505 // should this functionality be moved into allocPixels()?
2482 if (!bitmap.info().isOpaque()) { 2506 if (!bitmap.info().isOpaque()) {
2483 bitmap.eraseColor(0); 2507 bitmap.eraseColor(0);
2484 } 2508 }
2485 return SkNEW_ARGS(SkCanvas, (bitmap)); 2509 return SkNEW_ARGS(SkCanvas, (bitmap));
2486 } 2510 }
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