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

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: SkDumpCanvas fix. 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
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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 int SkCanvas::save(SaveFlags flags) { 809 int SkCanvas::save(SaveFlags flags) {
810 this->onSave(flags);
810 // call shared impl 811 // call shared impl
811 return this->internalSave(flags); 812 return this->internalSave(flags);
812 } 813 }
813 814
814 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) { 815 static bool bounds_affects_clip(SkCanvas::SaveFlags flags) {
815 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 816 #ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
816 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0; 817 return (flags & SkCanvas::kClipToLayer_SaveFlag) != 0;
817 #else 818 #else
818 return true; 819 return true;
819 #endif 820 #endif
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 } 859 }
859 860
860 if (intersection) { 861 if (intersection) {
861 *intersection = ir; 862 *intersection = ir;
862 } 863 }
863 return true; 864 return true;
864 } 865 }
865 866
866 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, 867 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
867 SaveFlags flags) { 868 SaveFlags flags) {
868 return this->internalSaveLayer(bounds, paint, flags, false); 869 // Overriding classes may return false to signal that we don't need to creat e a layer.
870 bool skipLayer = !this->onSaveLayer(bounds, paint, flags);
871 return this->internalSaveLayer(bounds, paint, flags, false, skipLayer);
869 } 872 }
870 873
871 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas, 874 static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
872 const SkImageInfo& info) { 875 const SkImageInfo& info) {
873 SkBaseDevice* device = canvas->getDevice(); 876 SkBaseDevice* device = canvas->getDevice();
874 return device ? device->createCompatibleDevice(info) : NULL; 877 return device ? device->createCompatibleDevice(info) : NULL;
875 } 878 }
876 879
877 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, 880 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
878 SaveFlags flags, bool justForImageFilter) { 881 SaveFlags flags, bool justForImageFilter, bool s kipLayer) {
879 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 882 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
880 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag); 883 flags = (SaveFlags)(flags | kClipToLayer_SaveFlag);
881 #endif 884 #endif
882 885
883 // do this before we create the layer. We don't call the public save() since 886 // do this before we create the layer. We don't call the public save() since
884 // that would invoke a possibly overridden virtual 887 // that would invoke a possibly overridden virtual
885 int count = this->internalSave(flags); 888 int count = this->internalSave(flags);
886 889
887 fDeviceCMDirty = true; 890 fDeviceCMDirty = true;
888 891
889 SkIRect ir; 892 SkIRect ir;
890 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 893 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) {
891 return count; 894 return count;
892 } 895 }
893 896
897 if (skipLayer)
898 return count;
899
894 // Kill the imagefilter if our device doesn't allow it 900 // Kill the imagefilter if our device doesn't allow it
895 SkLazyPaint lazyP; 901 SkLazyPaint lazyP;
896 if (paint && paint->getImageFilter()) { 902 if (paint && paint->getImageFilter()) {
897 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { 903 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) {
898 if (justForImageFilter) { 904 if (justForImageFilter) {
899 // early exit if the layer was just for the imageFilter 905 // early exit if the layer was just for the imageFilter
900 return count; 906 return count;
901 } 907 }
902 SkPaint* p = lazyP.set(*paint); 908 SkPaint* p = lazyP.set(*paint);
903 p->setImageFilter(NULL); 909 p->setImageFilter(NULL);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 } else { 945 } else {
940 SkPaint tmpPaint; 946 SkPaint tmpPaint;
941 tmpPaint.setAlpha(alpha); 947 tmpPaint.setAlpha(alpha);
942 return this->saveLayer(bounds, &tmpPaint, flags); 948 return this->saveLayer(bounds, &tmpPaint, flags);
943 } 949 }
944 } 950 }
945 951
946 void SkCanvas::restore() { 952 void SkCanvas::restore() {
947 // check for underflow 953 // check for underflow
948 if (fMCStack.count() > 1) { 954 if (fMCStack.count() > 1) {
955 this->onRestore();
949 this->internalRestore(); 956 this->internalRestore();
950 } 957 }
951 } 958 }
952 959
953 void SkCanvas::internalRestore() { 960 void SkCanvas::internalRestore() {
954 SkASSERT(fMCStack.count() != 0); 961 SkASSERT(fMCStack.count() != 0);
955 962
956 fDeviceCMDirty = true; 963 fDeviceCMDirty = true;
957 fCachedLocalClipBoundsDirty = true; 964 fCachedLocalClipBoundsDirty = true;
958 965
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 if (!bitmap.allocPixels(info)) { 2466 if (!bitmap.allocPixels(info)) {
2460 return NULL; 2467 return NULL;
2461 } 2468 }
2462 2469
2463 // should this functionality be moved into allocPixels()? 2470 // should this functionality be moved into allocPixels()?
2464 if (!bitmap.info().isOpaque()) { 2471 if (!bitmap.info().isOpaque()) {
2465 bitmap.eraseColor(0); 2472 bitmap.eraseColor(0);
2466 } 2473 }
2467 return SkNEW_ARGS(SkCanvas, (bitmap)); 2474 return SkNEW_ARGS(SkCanvas, (bitmap));
2468 } 2475 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698