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

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: 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
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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 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,
robertphillips 2015/03/10 13:49:25 Can we remove justForImageFilter ?
reed1 2015/03/13 14:07:08 Done.
898 bool justForImageFilter, SaveLayerStrategy strat egy) { 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 // 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;
robertphillips 2015/03/10 13:49:25 What's up with this #if'ed out code ?
reed1 2015/03/13 14:07:08 Done.
937 #if 0
938 // this seems needed for current GMs, but makes us draw slower on the GPU
945 if (paint && paint->getImageFilter()) { 939 if (paint && paint->getImageFilter()) {
946 usage = SkBaseDevice::kImageFilter_Usage; 940 usage = SkBaseDevice::kPossible_TileUsage;
947 } 941 }
948 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa ge, 942 #endif
949 fProps.pi xelGeometry())); 943 device = device->onCreateDevice(SkBaseDevice::CreateInfo(info, usage, fProps .pixelGeometry()),
944 paint);
950 if (NULL == device) { 945 if (NULL == device) {
951 SkErrorInternals::SetError( kInternalError_SkError, 946 SkErrorInternals::SetError( kInternalError_SkError,
952 "Unable to create device for layer."); 947 "Unable to create device for layer.");
953 return; 948 return;
954 } 949 }
955 950
956 device->setOrigin(ir.fLeft, ir.fTop); 951 device->setOrigin(ir.fLeft, ir.fTop);
957 DeviceCM* layer = SkNEW_ARGS(DeviceCM, 952 DeviceCM* layer = SkNEW_ARGS(DeviceCM,
958 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip)); 953 (device, ir.fLeft, ir.fTop, paint, this, fConse rvativeRasterClip));
959 device->unref(); 954 device->unref();
(...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 } 2518 }
2524 2519
2525 if (matrix) { 2520 if (matrix) {
2526 canvas->concat(*matrix); 2521 canvas->concat(*matrix);
2527 } 2522 }
2528 } 2523 }
2529 2524
2530 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2525 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2531 fCanvas->restoreToCount(fSaveCount); 2526 fCanvas->restoreToCount(fSaveCount);
2532 } 2527 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698