OLD | NEW |
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 Loading... |
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 |
117 //#define SK_TRACE_SAVERESTORE | 118 //#define SK_TRACE_SAVERESTORE |
118 | 119 |
119 #ifdef SK_TRACE_SAVERESTORE | 120 #ifdef SK_TRACE_SAVERESTORE |
120 static int gLayerCounter; | 121 static int gLayerCounter; |
121 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL
ayerCounter); } | 122 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL
ayerCounter); } |
122 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL
ayerCounter); } | 123 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL
ayerCounter); } |
123 | 124 |
124 static int gRecCounter; | 125 static int gRecCounter; |
125 static void inc_rec() { ++gRecCounter; printf("----- inc rec %d\n", gRecCoun
ter); } | 126 static void inc_rec() { ++gRecCounter; printf("----- inc rec %d\n", gRecCoun
ter); } |
126 static void dec_rec() { --gRecCounter; printf("----- dec rec %d\n", gRecCoun
ter); } | 127 static void dec_rec() { --gRecCounter; printf("----- dec rec %d\n", gRecCoun
ter); } |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 * draw onto the previous layer using the xfermode from the ori
ginal paint. | 474 * draw onto the previous layer using the xfermode from the ori
ginal paint. |
474 */ | 475 */ |
475 SkPaint tmp; | 476 SkPaint tmp; |
476 tmp.setImageFilter(fPaint->getImageFilter()); | 477 tmp.setImageFilter(fPaint->getImageFilter()); |
477 tmp.setXfermode(fPaint->getXfermode()); | 478 tmp.setXfermode(fPaint->getXfermode()); |
478 SkRect storage; | 479 SkRect storage; |
479 if (rawBounds) { | 480 if (rawBounds) { |
480 // Make rawBounds include all paint outsets except for those due
to image filters. | 481 // Make rawBounds include all paint outsets except for those due
to image filters. |
481 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra
wBounds, &storage); | 482 rawBounds = &apply_paint_to_bounds_sans_imagefilter(*fPaint, *ra
wBounds, &storage); |
482 } | 483 } |
483 (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &t
mp), | 484 (void)canvas->internalSaveLayer(SkCanvas::SaveLayerRec(rawBounds, &t
mp, 0), |
484 SkCanvas::kFullLayer_SaveLayerStrate
gy); | 485 SkCanvas::kFullLayer_SaveLayerStrate
gy); |
485 fTempLayerForImageFilter = true; | 486 fTempLayerForImageFilter = true; |
486 // we remove the imagefilter/xfermode inside doNext() | 487 // we remove the imagefilter/xfermode inside doNext() |
487 } | 488 } |
488 | 489 |
489 if (SkDrawLooper* looper = paint.getLooper()) { | 490 if (SkDrawLooper* looper = paint.getLooper()) { |
490 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( | 491 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( |
491 looper->contextSize()); | 492 looper->contextSize()); |
492 fLooperContext = looper->createContext(canvas, buffer); | 493 fLooperContext = looper->createContext(canvas, buffer); |
493 fIsSimple = false; | 494 fIsSimple = false; |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 SaveLayerRec rec(origRec); | 1166 SaveLayerRec rec(origRec); |
1166 if (gIgnoreSaveLayerBounds) { | 1167 if (gIgnoreSaveLayerBounds) { |
1167 rec.fBounds = nullptr; | 1168 rec.fBounds = nullptr; |
1168 } | 1169 } |
1169 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); | 1170 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); |
1170 fSaveCount += 1; | 1171 fSaveCount += 1; |
1171 this->internalSaveLayer(rec, strategy); | 1172 this->internalSaveLayer(rec, strategy); |
1172 return this->getSaveCount() - 1; | 1173 return this->getSaveCount() - 1; |
1173 } | 1174 } |
1174 | 1175 |
1175 static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt
er, | 1176 static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, Sk
BaseDevice* dst) { |
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)); | |
1202 SkPaint p; | 1201 SkPaint p; |
1203 p.setImageFilter(localF); | 1202 p.setImageFilter(filter); |
1204 const SkScalar x = SkIntToScalar(src->getOrigin().x()); | 1203 c.drawBitmap(srcBM, 0, 0, &p); |
1205 const SkScalar y = SkIntToScalar(src->getOrigin().y()); | |
1206 c.drawBitmap(srcBM, x, y, &p); | |
1207 } | 1204 } |
1208 | 1205 |
1209 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
tegy) { | 1206 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
tegy) { |
1210 const SkRect* bounds = rec.fBounds; | 1207 const SkRect* bounds = rec.fBounds; |
1211 const SkPaint* paint = rec.fPaint; | 1208 const SkPaint* paint = rec.fPaint; |
1212 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; | 1209 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; |
1213 | 1210 |
1214 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 1211 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
1215 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; | 1212 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; |
1216 #endif | 1213 #endif |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); | 1261 newDev = SkBitmapDevice::Create(createInfo.fInfo, surfaceProps); |
1265 if (nullptr == newDev) { | 1262 if (nullptr == newDev) { |
1266 SkErrorInternals::SetError(kInternalError_SkError, | 1263 SkErrorInternals::SetError(kInternalError_SkError, |
1267 "Unable to create device for layer.")
; | 1264 "Unable to create device for layer.")
; |
1268 return; | 1265 return; |
1269 } | 1266 } |
1270 forceSpriteOnRestore = true; | 1267 forceSpriteOnRestore = true; |
1271 } | 1268 } |
1272 device = newDev; | 1269 device = newDev; |
1273 } | 1270 } |
| 1271 |
1274 device->setOrigin(ir.fLeft, ir.fTop); | 1272 device->setOrigin(ir.fLeft, ir.fTop); |
1275 | 1273 |
1276 if (rec.fBackdrop) { | 1274 if (0) { |
1277 draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, devic
e, fMCRec->fMatrix); | 1275 draw_filter_into_device(fMCRec->fTopLayer->fDevice, nullptr, device); |
1278 } | 1276 } |
1279 | 1277 |
1280 DeviceCM* layer = | 1278 DeviceCM* layer = |
1281 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri
teOnRestore); | 1279 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri
teOnRestore); |
1282 device->unref(); | 1280 device->unref(); |
1283 | 1281 |
1284 layer->fNext = fMCRec->fTopLayer; | 1282 layer->fNext = fMCRec->fTopLayer; |
1285 fMCRec->fLayer = layer; | 1283 fMCRec->fLayer = layer; |
1286 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 1284 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
1287 } | 1285 } |
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3024 } | 3022 } |
3025 | 3023 |
3026 if (matrix) { | 3024 if (matrix) { |
3027 canvas->concat(*matrix); | 3025 canvas->concat(*matrix); |
3028 } | 3026 } |
3029 } | 3027 } |
3030 | 3028 |
3031 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3029 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3032 fCanvas->restoreToCount(fSaveCount); | 3030 fCanvas->restoreToCount(fSaveCount); |
3033 } | 3031 } |
OLD | NEW |