OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 "GrLayerCache.h" | 8 #include "GrLayerCache.h" |
9 #include "GrLayerHoister.h" | 9 #include "GrLayerHoister.h" |
10 #include "GrRecordReplaceDraw.h" | 10 #include "GrRecordReplaceDraw.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 void GrLayerHoister::DrawLayersToAtlas(GrContext* context, | 228 void GrLayerHoister::DrawLayersToAtlas(GrContext* context, |
229 const SkTDArray<GrHoistedLayer>& atlased)
{ | 229 const SkTDArray<GrHoistedLayer>& atlased)
{ |
230 if (atlased.count() > 0) { | 230 if (atlased.count() > 0) { |
231 // All the atlased layers are rendered into the same GrTexture | 231 // All the atlased layers are rendered into the same GrTexture |
232 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( | 232 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
233 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); | 233 atlased[0].fLayer->texture()->asRenderTa
rget(), NULL)); |
234 | 234 |
235 SkCanvas* atlasCanvas = surface->getCanvas(); | 235 SkCanvas* atlasCanvas = surface->getCanvas(); |
236 | 236 |
| 237 SkPaint clearPaint; |
| 238 clearPaint.setColor(SK_ColorTRANSPARENT); |
| 239 clearPaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref
(); |
| 240 |
237 for (int i = 0; i < atlased.count(); ++i) { | 241 for (int i = 0; i < atlased.count(); ++i) { |
238 const GrCachedLayer* layer = atlased[i].fLayer; | 242 const GrCachedLayer* layer = atlased[i].fLayer; |
239 const SkPicture* pict = atlased[i].fPicture; | 243 const SkPicture* pict = atlased[i].fPicture; |
240 const SkIPoint offset = atlased[i].fOffset; | 244 const SkIPoint offset = atlased[i].fOffset; |
241 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();) | 245 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();) |
242 | 246 |
243 SkASSERT(!layerPaint || !layerPaint->getImageFilter()); | 247 SkASSERT(!layerPaint || !layerPaint->getImageFilter()); |
244 | 248 |
245 atlasCanvas->save(); | 249 atlasCanvas->save(); |
246 | 250 |
247 // Add a rect clip to make sure the rendering doesn't | 251 // Add a rect clip to make sure the rendering doesn't |
248 // extend beyond the boundaries of the atlased sub-rect | 252 // extend beyond the boundaries of the atlased sub-rect |
249 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), | 253 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), |
250 SkIntToScalar(layer->rect().fTop), | 254 SkIntToScalar(layer->rect().fTop), |
251 SkIntToScalar(layer->rect().width())
, | 255 SkIntToScalar(layer->rect().width())
, |
252 SkIntToScalar(layer->rect().height()
)); | 256 SkIntToScalar(layer->rect().height()
)); |
253 atlasCanvas->clipRect(bound); | 257 atlasCanvas->clipRect(bound); |
254 atlasCanvas->clear(0); | 258 |
| 259 // Since 'clear' doesn't respect the clip we need to draw a rect |
| 260 atlasCanvas->drawRect(bound, clearPaint); |
255 | 261 |
256 // '-offset' maps the layer's top/left to the origin. | 262 // '-offset' maps the layer's top/left to the origin. |
257 // Since this layer is atlased, the top/left corner needs | 263 // Since this layer is atlased, the top/left corner needs |
258 // to be offset to the correct location in the backing texture. | 264 // to be offset to the correct location in the backing texture. |
259 SkMatrix initialCTM; | 265 SkMatrix initialCTM; |
260 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of
fset.fY)); | 266 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of
fset.fY)); |
261 initialCTM.preTranslate(bound.fLeft, bound.fTop); | 267 initialCTM.preTranslate(bound.fLeft, bound.fTop); |
262 initialCTM.preConcat(atlased[i].fPreMat); | 268 initialCTM.preConcat(atlased[i].fPreMat); |
263 | 269 |
264 atlasCanvas->setMatrix(initialCTM); | 270 atlasCanvas->setMatrix(initialCTM); |
265 atlasCanvas->concat(atlased[i].fLocalMat); | 271 atlasCanvas->concat(atlased[i].fLocalMat); |
266 | 272 |
267 SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas, | 273 SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas, |
268 pict->drawablePicts(), pict->drawableCount(), | 274 pict->drawablePicts(), pict->drawableCount(), |
269 layer->start() + 1, layer->stop(), initialCTM); | 275 bound, layer->start() + 1, layer->stop(), initia
lCTM); |
270 | 276 |
271 atlasCanvas->restore(); | 277 atlasCanvas->restore(); |
272 } | 278 } |
273 | 279 |
274 atlasCanvas->flush(); | 280 atlasCanvas->flush(); |
275 } | 281 } |
276 } | 282 } |
277 | 283 |
278 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { | 284 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { |
279 for (int i = 0; i < layers.count(); ++i) { | 285 for (int i = 0; i < layers.count(); ++i) { |
(...skipping 10 matching lines...) Expand all Loading... |
290 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); | 296 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); |
291 | 297 |
292 // Add a rect clip to make sure the rendering doesn't | 298 // Add a rect clip to make sure the rendering doesn't |
293 // extend beyond the boundaries of the layer | 299 // extend beyond the boundaries of the layer |
294 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), | 300 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), |
295 SkIntToScalar(layer->rect().fTop), | 301 SkIntToScalar(layer->rect().fTop), |
296 SkIntToScalar(layer->rect().width()), | 302 SkIntToScalar(layer->rect().width()), |
297 SkIntToScalar(layer->rect().height())); | 303 SkIntToScalar(layer->rect().height())); |
298 | 304 |
299 layerCanvas->clipRect(bound); | 305 layerCanvas->clipRect(bound); |
| 306 |
300 layerCanvas->clear(SK_ColorTRANSPARENT); | 307 layerCanvas->clear(SK_ColorTRANSPARENT); |
301 | 308 |
302 SkMatrix initialCTM; | 309 SkMatrix initialCTM; |
303 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset
.fY)); | 310 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset
.fY)); |
304 initialCTM.preConcat(layers[i].fPreMat); | 311 initialCTM.preConcat(layers[i].fPreMat); |
305 | 312 |
306 layerCanvas->setMatrix(initialCTM); | 313 layerCanvas->setMatrix(initialCTM); |
307 layerCanvas->concat(layers[i].fLocalMat); | 314 layerCanvas->concat(layers[i].fLocalMat); |
308 | 315 |
309 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, | 316 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, |
310 pict->drawablePicts(), pict->drawableCount(), | 317 pict->drawablePicts(), pict->drawableCount(), |
311 layer->start()+1, layer->stop(), initialCTM); | 318 bound, layer->start()+1, layer->stop(), initialCTM); |
312 | 319 |
313 layerCanvas->flush(); | 320 layerCanvas->flush(); |
314 } | 321 } |
315 } | 322 } |
316 | 323 |
317 void GrLayerHoister::UnlockLayers(GrContext* context, | 324 void GrLayerHoister::UnlockLayers(GrContext* context, |
318 const SkTDArray<GrHoistedLayer>& layers) { | 325 const SkTDArray<GrHoistedLayer>& layers) { |
319 GrLayerCache* layerCache = context->getLayerCache(); | 326 GrLayerCache* layerCache = context->getLayerCache(); |
320 | 327 |
321 for (int i = 0; i < layers.count(); ++i) { | 328 for (int i = 0; i < layers.count(); ++i) { |
322 layerCache->removeUse(layers[i].fLayer); | 329 layerCache->removeUse(layers[i].fLayer); |
323 } | 330 } |
324 | 331 |
325 SkDEBUGCODE(layerCache->validate();) | 332 SkDEBUGCODE(layerCache->validate();) |
326 } | 333 } |
327 | 334 |
328 void GrLayerHoister::PurgeCache(GrContext* context) { | 335 void GrLayerHoister::PurgeCache(GrContext* context) { |
329 #if !GR_CACHE_HOISTED_LAYERS | 336 #if !GR_CACHE_HOISTED_LAYERS |
330 GrLayerCache* layerCache = context->getLayerCache(); | 337 GrLayerCache* layerCache = context->getLayerCache(); |
331 | 338 |
332 // This code completely clears out the atlas. It is required when | 339 // This code completely clears out the atlas. It is required when |
333 // caching is disabled so the atlas doesn't fill up and force more | 340 // caching is disabled so the atlas doesn't fill up and force more |
334 // free floating layers | 341 // free floating layers |
335 layerCache->purgeAll(); | 342 layerCache->purgeAll(); |
336 #endif | 343 #endif |
337 } | 344 } |
OLD | NEW |