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

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

Issue 1008863002: Revert of Change device creation to see the (optional) layer-paint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkDevice.cpp » ('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 * 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 "SkCanvasPriv.h" 9 #include "SkCanvasPriv.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 fFilter = canvas->getDrawFilter(); 292 fFilter = canvas->getDrawFilter();
293 fPaint = &fOrigPaint; 293 fPaint = &fOrigPaint;
294 fSaveCount = canvas->getSaveCount(); 294 fSaveCount = canvas->getSaveCount();
295 fDoClearImageFilter = false; 295 fDoClearImageFilter = false;
296 fDone = false; 296 fDone = false;
297 297
298 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { 298 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) {
299 SkPaint tmp; 299 SkPaint tmp;
300 tmp.setImageFilter(fOrigPaint.getImageFilter()); 300 tmp.setImageFilter(fOrigPaint.getImageFilter());
301 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag, 301 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag,
302 SkCanvas::kFullLayer_SaveLayerStrate gy); 302 true, SkCanvas::kFullLayer_SaveLayer Strategy);
303 // we'll clear the imageFilter for the actual draws in next(), so 303 // we'll clear the imageFilter for the actual draws in next(), so
304 // it will only be applied during the restore(). 304 // it will only be applied during the restore().
305 fDoClearImageFilter = true; 305 fDoClearImageFilter = true;
306 } 306 }
307 307
308 if (SkDrawLooper* looper = paint.getLooper()) { 308 if (SkDrawLooper* looper = paint.getLooper()) {
309 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 309 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
310 looper->contextSize()); 310 looper->contextSize());
311 fLooperContext = looper->createContext(canvas, buffer); 311 fLooperContext = looper->createContext(canvas, buffer);
312 fIsSimple = false; 312 fIsSimple = false;
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 } 873 }
874 return true; 874 return true;
875 } 875 }
876 876
877 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { 877 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
878 if (gIgnoreSaveLayerBounds) { 878 if (gIgnoreSaveLayerBounds) {
879 bounds = NULL; 879 bounds = NULL;
880 } 880 }
881 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag); 881 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag);
882 fSaveCount += 1; 882 fSaveCount += 1;
883 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy); 883 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, false, stra tegy);
884 return this->getSaveCount() - 1; 884 return this->getSaveCount() - 1;
885 } 885 }
886 886
887 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) { 887 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) {
888 if (gIgnoreSaveLayerBounds) { 888 if (gIgnoreSaveLayerBounds) {
889 bounds = NULL; 889 bounds = NULL;
890 } 890 }
891 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); 891 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
892 fSaveCount += 1; 892 fSaveCount += 1;
893 this->internalSaveLayer(bounds, paint, flags, strategy); 893 this->internalSaveLayer(bounds, paint, flags, false, strategy);
894 return this->getSaveCount() - 1; 894 return this->getSaveCount() - 1;
895 } 895 }
896 896
897 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, 897 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags,
898 SaveLayerStrategy strategy) { 898 bool justForImageFilter, SaveLayerStrategy strat egy) {
899 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 899 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
900 flags |= kClipToLayer_SaveFlag; 900 flags |= kClipToLayer_SaveFlag;
901 #endif 901 #endif
902 902
903 // do this before we create the layer. We don't call the public save() since 903 // do this before we create the layer. We don't call the public save() since
904 // that would invoke a possibly overridden virtual 904 // that would invoke a possibly overridden virtual
905 this->internalSave(); 905 this->internalSave();
906 906
907 fDeviceCMDirty = true; 907 fDeviceCMDirty = true;
908 908
909 SkIRect ir; 909 SkIRect ir;
910 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) { 910 if (!this->clipRectBounds(bounds, flags, &ir, paint ? paint->getImageFilter( ) : NULL)) {
911 return; 911 return;
912 } 912 }
913 913
914 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about 914 // FIXME: do willSaveLayer() overriders returning kNoLayer_SaveLayerStrategy really care about
915 // the clipRectBounds() call above? 915 // the clipRectBounds() call above?
916 if (kNoLayer_SaveLayerStrategy == strategy) { 916 if (kNoLayer_SaveLayerStrategy == strategy) {
917 return; 917 return;
918 } 918 }
919 919
920 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); 920 // Kill the imagefilter if our device doesn't allow it
921 if (isOpaque && paint) { 921 SkLazyPaint lazyP;
922 // TODO: perhaps add a query to filters so we might preserve opaqueness. .. 922 if (paint && paint->getImageFilter()) {
923 if (paint->getImageFilter() || paint->getColorFilter()) { 923 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) {
924 isOpaque = false; 924 if (justForImageFilter) {
925 // early exit if the layer was just for the imageFilter
926 return;
927 }
928 SkPaint* p = lazyP.set(*paint);
929 p->setImageFilter(NULL);
930 paint = p;
925 } 931 }
926 } 932 }
933
934 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
927 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), 935 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(),
928 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 936 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
929 937
930 SkBaseDevice* device = this->getTopDevice(); 938 SkBaseDevice* device = this->getTopDevice();
931 if (NULL == device) { 939 if (NULL == device) {
932 SkDebugf("Unable to find device for layer."); 940 SkDebugf("Unable to find device for layer.");
933 return; 941 return;
934 } 942 }
935 943
936 SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; 944 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage;
937 #if 1
938 // this seems needed for current GMs, but makes us draw slower on the GPU
939 // Related to https://code.google.com/p/skia/issues/detail?id=3519 ?
940 //
941 if (paint && paint->getImageFilter()) { 945 if (paint && paint->getImageFilter()) {
942 usage = SkBaseDevice::kPossible_TileUsage; 946 usage = SkBaseDevice::kImageFilter_Usage;
943 } 947 }
944 #endif 948 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa ge,
945 device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, fProps .pixelGeometry()), 949 fProps.pi xelGeometry()));
946 paint);
947 if (NULL == device) { 950 if (NULL == device) {
948 SkErrorInternals::SetError( kInternalError_SkError, 951 SkErrorInternals::SetError( kInternalError_SkError,
949 "Unable to create device for layer."); 952 "Unable to create device for layer.");
950 return; 953 return;
951 } 954 }
952 955
953 device->setOrigin(ir.fLeft, ir.fTop); 956 device->setOrigin(ir.fLeft, ir.fTop);
954 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip)); 957 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip));
955 device->unref(); 958 device->unref();
956 959
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 } 2522 }
2520 2523
2521 if (matrix) { 2524 if (matrix) {
2522 canvas->concat(*matrix); 2525 canvas->concat(*matrix);
2523 } 2526 }
2524 } 2527 }
2525 2528
2526 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2529 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2527 fCanvas->restoreToCount(fSaveCount); 2530 fCanvas->restoreToCount(fSaveCount);
2528 } 2531 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapDevice.cpp ('k') | src/core/SkDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698