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

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

Issue 1523053003: add backdrop option to SaveLayerRec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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
« samplecode/SampleLayers.cpp ('K') | « samplecode/SampleLayers.cpp ('k') | no next file » | 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 */ 473 */
474 SkPaint tmp; 474 SkPaint tmp;
475 tmp.setImageFilter(fPaint->getImageFilter()); 475 tmp.setImageFilter(fPaint->getImageFilter());
476 tmp.setXfermode(fPaint->getXfermode()); 476 tmp.setXfermode(fPaint->getXfermode());
477 SkRect storage; 477 SkRect storage;
478 if (rawBounds) { 478 if (rawBounds) {
479 // Make rawBounds include all paint outsets except for those due to image filters. 479 // Make rawBounds include all paint outsets except for those due to image filters.
480 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra wBounds, &storage); 480 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra wBounds, &storage);
481 } 481 }
482 (void)canvas->internalSaveLayer(rawBounds, &tmp, SkCanvas::kARGB_Cli pLayer_SaveFlag, 482 (void)canvas->internalSaveLayer(rawBounds, &tmp, SkCanvas::kARGB_Cli pLayer_SaveFlag,
483 SkCanvas::kFullLayer_SaveLayerStrate gy); 483 SkCanvas::kFullLayer_SaveLayerStrate gy, nullptr);
484 fTempLayerForImageFilter = true; 484 fTempLayerForImageFilter = true;
485 // we remove the imagefilter/xfermode inside doNext() 485 // we remove the imagefilter/xfermode inside doNext()
486 } 486 }
487 487
488 if (SkDrawLooper* looper = paint.getLooper()) { 488 if (SkDrawLooper* looper = paint.getLooper()) {
489 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 489 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
490 looper->contextSize()); 490 looper->contextSize());
491 fLooperContext = looper->createContext(canvas, buffer); 491 fLooperContext = looper->createContext(canvas, buffer);
492 fIsSimple = false; 492 fIsSimple = false;
493 } else { 493 } else {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 fMCRec->fRasterClip.setRect(ir); 1114 fMCRec->fRasterClip.setRect(ir);
1115 } 1115 }
1116 1116
1117 if (intersection) { 1117 if (intersection) {
1118 *intersection = ir; 1118 *intersection = ir;
1119 } 1119 }
1120 return true; 1120 return true;
1121 } 1121 }
1122 1122
1123 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) { 1123 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint) {
1124 return this->saveLayerWithPickup(bounds, paint, nullptr);
1125 }
1126
1127 int SkCanvas::saveLayerWithPickup(const SkRect* bounds, const SkPaint* paint,
1128 SkImageFilter* pickup) {
1124 if (gIgnoreSaveLayerBounds) { 1129 if (gIgnoreSaveLayerBounds) {
1125 bounds = nullptr; 1130 bounds = nullptr;
1126 } 1131 }
1127 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa yer_SaveFlag); 1132 SaveFlags flags = kARGB_ClipLayer_SaveFlag;
1133 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
1128 fSaveCount += 1; 1134 fSaveCount += 1;
1129 this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, strategy); 1135 this->internalSaveLayer(bounds, paint, flags, strategy, pickup);
1130 return this->getSaveCount() - 1; 1136 return this->getSaveCount() - 1;
1131 } 1137 }
1132 1138
1133 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) { 1139 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags fl ags) {
1134 if (gIgnoreSaveLayerBounds) { 1140 if (gIgnoreSaveLayerBounds) {
1135 bounds = nullptr; 1141 bounds = nullptr;
1136 } 1142 }
1137 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); 1143 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags);
1138 fSaveCount += 1; 1144 fSaveCount += 1;
1139 this->internalSaveLayer(bounds, paint, flags, strategy); 1145 this->internalSaveLayer(bounds, paint, flags, strategy, nullptr);
1140 return this->getSaveCount() - 1; 1146 return this->getSaveCount() - 1;
1141 } 1147 }
1142 1148
1143 int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPai nt* paint) { 1149 int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPai nt* paint) {
1144 unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag ; 1150 unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag ;
1145 return this->saveLayer(bounds, paint, (SaveFlags)flags); 1151 return this->saveLayer(bounds, paint, (SaveFlags)flags);
1146 } 1152 }
1147 1153
1154 static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, Sk BaseDevice* dst) {
1155 SkCanvas c(dst);
1156
1157 const SkBitmap& srcBM = src->accessBitmap(false);
1158 SkPaint p;
1159 p.setImageFilter(filter);
1160 c.drawBitmap(srcBM, 0, 0, &p);
1161 }
1148 1162
1149 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags, 1163 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav eFlags flags,
1150 SaveLayerStrategy strategy) { 1164 SaveLayerStrategy strategy, SkImageFilter* pick up) {
1151 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 1165 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1152 flags |= kClipToLayer_SaveFlag; 1166 flags |= kClipToLayer_SaveFlag;
1153 #endif 1167 #endif
1154 1168
1155 // do this before we create the layer. We don't call the public save() since 1169 // do this before we create the layer. We don't call the public save() since
1156 // that would invoke a possibly overridden virtual 1170 // that would invoke a possibly overridden virtual
1157 this->internalSave(); 1171 this->internalSave();
1158 1172
1159 fDeviceCMDirty = true; 1173 fDeviceCMDirty = true;
1160 1174
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); 1215 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps);
1202 if (nullptr == newDev) { 1216 if (nullptr == newDev) {
1203 SkErrorInternals::SetError(kInternalError_SkError, 1217 SkErrorInternals::SetError(kInternalError_SkError,
1204 "Unable to create device for layer.") ; 1218 "Unable to create device for layer.") ;
1205 return; 1219 return;
1206 } 1220 }
1207 forceSpriteOnRestore = true; 1221 forceSpriteOnRestore = true;
1208 } 1222 }
1209 device = newDev; 1223 device = newDev;
1210 } 1224 }
1225 device->setOrigin(ir.fLeft, ir.fTop);
1211 1226
1212 device->setOrigin(ir.fLeft, ir.fTop); 1227 if (pickup) {
1228 draw_filter_into_device(fMCRec->fTopLayer->fDevice, pickup, device);
1229 }
1230
1213 DeviceCM* layer = 1231 DeviceCM* layer =
1214 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore); 1232 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore);
1215 device->unref(); 1233 device->unref();
1216 1234
1217 layer->fNext = fMCRec->fTopLayer; 1235 layer->fNext = fMCRec->fTopLayer;
1218 fMCRec->fLayer = layer; 1236 fMCRec->fLayer = layer;
1219 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1237 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1220 } 1238 }
1221 1239
1222 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { 1240 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 } 3031 }
3014 3032
3015 if (matrix) { 3033 if (matrix) {
3016 canvas->concat(*matrix); 3034 canvas->concat(*matrix);
3017 } 3035 }
3018 } 3036 }
3019 3037
3020 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3038 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3021 fCanvas->restoreToCount(fSaveCount); 3039 fCanvas->restoreToCount(fSaveCount);
3022 } 3040 }
OLDNEW
« samplecode/SampleLayers.cpp ('K') | « samplecode/SampleLayers.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698