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

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: rebase Created 4 years, 11 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 | « samplecode/SampleLayers.cpp ('k') | src/core/SkPictureFlat.h » ('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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 static bool gTreatSpriteAsBitmap; 107 static bool gTreatSpriteAsBitmap;
108 void SkCanvas::Internal_Private_SetTreatSpriteAsBitmap(bool spriteAsBitmap) { 108 void SkCanvas::Internal_Private_SetTreatSpriteAsBitmap(bool spriteAsBitmap) {
109 gTreatSpriteAsBitmap = spriteAsBitmap; 109 gTreatSpriteAsBitmap = spriteAsBitmap;
110 } 110 }
111 bool SkCanvas::Internal_Private_GetTreatSpriteAsBitmap() { 111 bool SkCanvas::Internal_Private_GetTreatSpriteAsBitmap() {
112 return gTreatSpriteAsBitmap; 112 return gTreatSpriteAsBitmap;
113 } 113 }
114 114
115 // experimental for faster tiled drawing... 115 // experimental for faster tiled drawing...
116 //#define SK_ENABLE_CLIP_QUICKREJECT 116 //#define SK_ENABLE_CLIP_QUICKREJECT
117
118 //#define SK_TRACE_SAVERESTORE 117 //#define SK_TRACE_SAVERESTORE
119 118
120 #ifdef SK_TRACE_SAVERESTORE 119 #ifdef SK_TRACE_SAVERESTORE
121 static int gLayerCounter; 120 static int gLayerCounter;
122 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL ayerCounter); } 121 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL ayerCounter); }
123 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL ayerCounter); } 122 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL ayerCounter); }
124 123
125 static int gRecCounter; 124 static int gRecCounter;
126 static void inc_rec() { ++gRecCounter; printf("----- inc rec %d\n", gRecCoun ter); } 125 static void inc_rec() { ++gRecCounter; printf("----- inc rec %d\n", gRecCoun ter); }
127 static void dec_rec() { --gRecCounter; printf("----- dec rec %d\n", gRecCoun ter); } 126 static void dec_rec() { --gRecCounter; printf("----- dec rec %d\n", gRecCoun ter); }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 * draw onto the previous layer using the xfermode from the ori ginal paint. 473 * draw onto the previous layer using the xfermode from the ori ginal paint.
475 */ 474 */
476 SkPaint tmp; 475 SkPaint tmp;
477 tmp.setImageFilter(fPaint->getImageFilter()); 476 tmp.setImageFilter(fPaint->getImageFilter());
478 tmp.setXfermode(fPaint->getXfermode()); 477 tmp.setXfermode(fPaint->getXfermode());
479 SkRect storage; 478 SkRect storage;
480 if (rawBounds) { 479 if (rawBounds) {
481 // Make rawBounds include all paint outsets except for those due to image filters. 480 // Make rawBounds include all paint outsets except for those due to image filters.
482 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra wBounds, &storage); 481 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra wBounds, &storage);
483 } 482 }
484 (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &t mp, 0), 483 (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &t mp),
485 SkCanvas::kFullLayer_SaveLayerStrate gy); 484 SkCanvas::kFullLayer_SaveLayerStrate gy);
486 fTempLayerForImageFilter = true; 485 fTempLayerForImageFilter = true;
487 // we remove the imagefilter/xfermode inside doNext() 486 // we remove the imagefilter/xfermode inside doNext()
488 } 487 }
489 488
490 if (SkDrawLooper* looper = paint.getLooper()) { 489 if (SkDrawLooper* looper = paint.getLooper()) {
491 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 490 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
492 looper->contextSize()); 491 looper->contextSize());
493 fLooperContext = looper->createContext(canvas, buffer); 492 fLooperContext = looper->createContext(canvas, buffer);
494 fIsSimple = false; 493 fIsSimple = false;
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 SaveLayerRec rec(origRec); 1165 SaveLayerRec rec(origRec);
1167 if (gIgnoreSaveLayerBounds) { 1166 if (gIgnoreSaveLayerBounds) {
1168 rec.fBounds = nullptr; 1167 rec.fBounds = nullptr;
1169 } 1168 }
1170 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); 1169 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec);
1171 fSaveCount += 1; 1170 fSaveCount += 1;
1172 this->internalSaveLayer(rec, strategy); 1171 this->internalSaveLayer(rec, strategy);
1173 return this->getSaveCount() - 1; 1172 return this->getSaveCount() - 1;
1174 } 1173 }
1175 1174
1176 static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, Sk BaseDevice* dst) { 1175 static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt er,
1176 SkBaseDevice* dst, const SkMatrix& ctm) {
1177 1177
1178 SkBitmap srcBM; 1178 SkBitmap srcBM;
1179 1179
1180 #if SK_SUPPORT_GPU 1180 #if SK_SUPPORT_GPU
1181 GrRenderTarget* srcRT = src->accessRenderTarget(); 1181 GrRenderTarget* srcRT = src->accessRenderTarget();
1182 if (srcRT && !srcRT->asTexture() && dst->accessRenderTarget()) { 1182 if (srcRT && !srcRT->asTexture() && dst->accessRenderTarget()) {
1183 // When both the src & the dst are on the gpu but the src doesn't have a texture, 1183 // When both the src & the dst are on the gpu but the src doesn't have a texture,
1184 // we create a temporary texture for the draw. 1184 // we create a temporary texture for the draw.
1185 // TODO: we should actually only copy the portion of the source needed t o apply the image 1185 // TODO: we should actually only copy the portion of the source needed t o apply the image
1186 // filter 1186 // filter
1187 GrContext* context = srcRT->getContext(); 1187 GrContext* context = srcRT->getContext();
1188 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(sr cRT->desc(), true)); 1188 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(sr cRT->desc(), true));
1189 1189
1190 context->copySurface(tex, srcRT); 1190 context->copySurface(tex, srcRT);
1191 1191
1192 GrWrapTextureInBitmap(tex, src->width(), src->height(), src->isOpaque(), &srcBM); 1192 GrWrapTextureInBitmap(tex, src->width(), src->height(), src->isOpaque(), &srcBM);
1193 } else 1193 } else
1194 #endif 1194 #endif
1195 { 1195 {
1196 srcBM = src->accessBitmap(false); 1196 srcBM = src->accessBitmap(false);
1197 } 1197 }
1198 1198
1199 SkCanvas c(dst); 1199 SkCanvas c(dst);
1200 1200
1201 SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm));
1201 SkPaint p; 1202 SkPaint p;
1202 p.setImageFilter(filter); 1203 p.setImageFilter(localF);
1203 c.drawBitmap(srcBM, 0, 0, &p); 1204 const SkScalar x = SkIntToScalar(src->getOrigin().x());
1205 const SkScalar y = SkIntToScalar(src->getOrigin().y());
1206 c.drawBitmap(srcBM, x, y, &p);
1204 } 1207 }
1205 1208
1206 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) { 1209 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) {
1207 const SkRect* bounds = rec.fBounds; 1210 const SkRect* bounds = rec.fBounds;
1208 const SkPaint* paint = rec.fPaint; 1211 const SkPaint* paint = rec.fPaint;
1209 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; 1212 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags;
1210 1213
1211 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 1214 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1212 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; 1215 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag;
1213 #endif 1216 #endif
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); 1264 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps);
1262 if (nullptr == newDev) { 1265 if (nullptr == newDev) {
1263 SkErrorInternals::SetError(kInternalError_SkError, 1266 SkErrorInternals::SetError(kInternalError_SkError,
1264 "Unable to create device for layer.") ; 1267 "Unable to create device for layer.") ;
1265 return; 1268 return;
1266 } 1269 }
1267 forceSpriteOnRestore = true; 1270 forceSpriteOnRestore = true;
1268 } 1271 }
1269 device = newDev; 1272 device = newDev;
1270 } 1273 }
1271
1272 device->setOrigin(ir.fLeft, ir.fTop); 1274 device->setOrigin(ir.fLeft, ir.fTop);
1273 1275
1274 if (0) { 1276 if (rec.fBackdrop) {
1275 draw_filter_into_device(fMCRec->fTopLayer->fDevice, nullptr, device); 1277 draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, devic e, fMCRec->fMatrix);
1276 } 1278 }
1277 1279
1278 DeviceCM* layer = 1280 DeviceCM* layer =
1279 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore); 1281 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri teOnRestore);
1280 device->unref(); 1282 device->unref();
1281 1283
1282 layer->fNext = fMCRec->fTopLayer; 1284 layer->fNext = fMCRec->fTopLayer;
1283 fMCRec->fLayer = layer; 1285 fMCRec->fLayer = layer;
1284 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer 1286 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer
1285 } 1287 }
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after
3022 } 3024 }
3023 3025
3024 if (matrix) { 3026 if (matrix) {
3025 canvas->concat(*matrix); 3027 canvas->concat(*matrix);
3026 } 3028 }
3027 } 3029 }
3028 3030
3029 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3031 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3030 fCanvas->restoreToCount(fSaveCount); 3032 fCanvas->restoreToCount(fSaveCount);
3031 } 3033 }
OLDNEW
« no previous file with comments | « samplecode/SampleLayers.cpp ('k') | src/core/SkPictureFlat.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698