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