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

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

Issue 988413003: Change device creation to see the (optional) layer-paint (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments 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 true, SkCanvas::kFullLayer_SaveLayer Strategy); 302 SkCanvas::kFullLayer_SaveLayerStrate gy);
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, false, stra tegy); 883 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy);
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, false, strategy); 893 this->internalSaveLayer(bounds, paint, flags, 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 bool justForImageFilter, SaveLayerStrategy strat egy) { 898 SaveLayerStrategy strategy) {
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 // Kill the imagefilter if our device doesn't allow it 920 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
921 SkLazyPaint lazyP; 921 if (isOpaque && paint) {
922 if (paint && paint->getImageFilter()) { 922 // TODO: perhaps add a query to filters so we might preserve opaqueness. ..
923 if (!this->getTopDevice()->allowImageFilter(paint->getImageFilter())) { 923 if (paint->getImageFilter() || paint->getColorFilter()) {
924 if (justForImageFilter) { 924 isOpaque = false;
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;
931 } 925 }
932 } 926 }
933
934 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag);
935 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), 927 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(),
936 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); 928 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
937 929
938 SkBaseDevice* device = this->getTopDevice(); 930 SkBaseDevice* device = this->getTopDevice();
939 if (NULL == device) { 931 if (NULL == device) {
940 SkDebugf("Unable to find device for layer."); 932 SkDebugf("Unable to find device for layer.");
941 return; 933 return;
942 } 934 }
943 935
944 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; 936 SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
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 ?
Stephen White 2015/03/13 19:34:48 I don't think so. I think this is related to the u
940 //
945 if (paint && paint->getImageFilter()) { 941 if (paint && paint->getImageFilter()) {
946 usage = SkBaseDevice::kImageFilter_Usage; 942 usage = SkBaseDevice::kPossible_TileUsage;
947 } 943 }
948 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa ge, 944 #endif
949 fProps.pi xelGeometry())); 945 device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, fProps .pixelGeometry()),
946 paint);
950 if (NULL == device) { 947 if (NULL == device) {
951 SkErrorInternals::SetError( kInternalError_SkError, 948 SkErrorInternals::SetError( kInternalError_SkError,
952 "Unable to create device for layer."); 949 "Unable to create device for layer.");
953 return; 950 return;
954 } 951 }
955 952
956 device->setOrigin(ir.fLeft, ir.fTop); 953 device->setOrigin(ir.fLeft, ir.fTop);
957 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip)); 954 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, paint, this, fConservativeRa sterClip));
958 device->unref(); 955 device->unref();
959 956
(...skipping 1562 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 } 2519 }
2523 2520
2524 if (matrix) { 2521 if (matrix) {
2525 canvas->concat(*matrix); 2522 canvas->concat(*matrix);
2526 } 2523 }
2527 } 2524 }
2528 2525
2529 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2526 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2530 fCanvas->restoreToCount(fSaveCount); 2527 fCanvas->restoreToCount(fSaveCount);
2531 } 2528 }
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