| 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" |
| 11 | 11 |
| 12 #include "SkBigPicture.h" | 12 #include "SkBigPicture.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkGpuDevice.h" | 14 #include "SkGpuDevice.h" |
| 15 #include "SkLayerInfo.h" | 15 #include "SkLayerInfo.h" |
| 16 #include "SkRecordDraw.h" | 16 #include "SkRecordDraw.h" |
| 17 #include "SkSpecialImage.h" |
| 17 #include "SkSurface.h" | 18 #include "SkSurface.h" |
| 18 #include "SkSurface_Gpu.h" | 19 #include "SkSurface_Gpu.h" |
| 19 | 20 |
| 20 // Create the layer information for the hoisted layer and secure the | 21 // Create the layer information for the hoisted layer and secure the |
| 21 // required texture/render target resources. | 22 // required texture/render target resources. |
| 22 static void prepare_for_hoisting(GrLayerCache* layerCache, | 23 static void prepare_for_hoisting(GrLayerCache* layerCache, |
| 23 const SkPicture* topLevelPicture, | 24 const SkPicture* topLevelPicture, |
| 24 const SkMatrix& initialMat, | 25 const SkMatrix& initialMat, |
| 25 const SkLayerInfo::BlockInfo& info, | 26 const SkLayerInfo::BlockInfo& info, |
| 26 const SkIRect& srcIR, | 27 const SkIRect& srcIR, |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 279 |
| 279 void GrLayerHoister::FilterLayer(GrContext* context, | 280 void GrLayerHoister::FilterLayer(GrContext* context, |
| 280 SkGpuDevice* device, | 281 SkGpuDevice* device, |
| 281 const GrHoistedLayer& info) { | 282 const GrHoistedLayer& info) { |
| 282 GrCachedLayer* layer = info.fLayer; | 283 GrCachedLayer* layer = info.fLayer; |
| 283 | 284 |
| 284 SkASSERT(layer->filter()); | 285 SkASSERT(layer->filter()); |
| 285 | 286 |
| 286 static const int kDefaultCacheSize = 32 * 1024 * 1024; | 287 static const int kDefaultCacheSize = 32 * 1024 * 1024; |
| 287 | 288 |
| 288 SkBitmap filteredBitmap; | |
| 289 SkIPoint offset = SkIPoint::Make(0, 0); | |
| 290 | |
| 291 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr
cIR().fTop); | 289 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr
cIR().fTop); |
| 292 | 290 |
| 293 SkMatrix totMat = SkMatrix::I(); | 291 SkMatrix totMat(info.fPreMat); |
| 294 totMat.preConcat(info.fPreMat); | |
| 295 totMat.preConcat(info.fLocalMat); | 292 totMat.preConcat(info.fLocalMat); |
| 296 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO
ffset.fY)); | 293 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO
ffset.fY)); |
| 297 | 294 |
| 298 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); | 295 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); |
| 299 SkIRect clipBounds = layer->rect(); | 296 const SkIRect& clipBounds = layer->rect(); |
| 300 | 297 |
| 301 // This cache is transient, and is freed (along with all its contained | 298 // This cache is transient, and is freed (along with all its contained |
| 302 // textures) when it goes out of scope. | 299 // textures) when it goes out of scope. |
| 303 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau
ltCacheSize)); | 300 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau
ltCacheSize)); |
| 304 SkImageFilter::Context filterContext(totMat, clipBounds, cache); | 301 SkImageFilter::Context filterContext(totMat, clipBounds, cache); |
| 305 | 302 |
| 306 SkImageFilter::DeviceProxy proxy(device); | 303 SkImageFilter::DeviceProxy proxy(device); |
| 307 SkBitmap src; | |
| 308 GrWrapTextureInBitmap(layer->texture(), layer->texture()->width(), layer->te
xture()->height(), | |
| 309 false, &src); | |
| 310 | 304 |
| 311 if (!layer->filter()->filterImageDeprecated(&proxy, src, filterContext, | 305 // TODO: should the layer hoister store stand alone layers as SkSpecialImage
s internally? |
| 312 &filteredBitmap, &offset)) { | 306 const SkIRect subset = SkIRect::MakeWH(layer->texture()->width(), layer->tex
ture()->height()); |
| 307 SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromGpu(&proxy, subset, |
| 308 kNeedNewImageUni
queID_SpecialImage, |
| 309 layer->texture()
)); |
| 310 |
| 311 SkIPoint offset = SkIPoint::Make(0, 0); |
| 312 SkAutoTUnref<SkSpecialImage> result(layer->filter()->filterImage(img, |
| 313 filterConte
xt, |
| 314 &offset)); |
| 315 if (!result) { |
| 313 // Filtering failed. Press on with the unfiltered version. | 316 // Filtering failed. Press on with the unfiltered version. |
| 314 return; | 317 return; |
| 315 } | 318 } |
| 316 | 319 |
| 317 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei
ght()); | 320 SkASSERT(result->peekTexture()); |
| 318 layer->setTexture(filteredBitmap.getTexture(), newRect, false); | 321 layer->setTexture(result->peekTexture(), result->subset(), false); |
| 319 layer->setOffset(offset); | 322 layer->setOffset(offset); |
| 320 } | 323 } |
| 321 | 324 |
| 322 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { | 325 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { |
| 323 for (int i = 0; i < layers.count(); ++i) { | 326 for (int i = 0; i < layers.count(); ++i) { |
| 324 GrCachedLayer* layer = layers[i].fLayer; | 327 GrCachedLayer* layer = layers[i].fLayer; |
| 325 const SkBigPicture* pict = layers[i].fPicture->asSkBigPicture(); | 328 const SkBigPicture* pict = layers[i].fPicture->asSkBigPicture(); |
| 326 if (!pict) { | 329 if (!pict) { |
| 327 // TODO: can we assume / assert this? | 330 // TODO: can we assume / assert this? |
| 328 continue; | 331 continue; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 #if !GR_CACHE_HOISTED_LAYERS | 388 #if !GR_CACHE_HOISTED_LAYERS |
| 386 | 389 |
| 387 // This code completely clears out the atlas. It is required when | 390 // This code completely clears out the atlas. It is required when |
| 388 // caching is disabled so the atlas doesn't fill up and force more | 391 // caching is disabled so the atlas doesn't fill up and force more |
| 389 // free floating layers | 392 // free floating layers |
| 390 layerCache->purgeAll(); | 393 layerCache->purgeAll(); |
| 391 #endif | 394 #endif |
| 392 | 395 |
| 393 layerCache->end(); | 396 layerCache->end(); |
| 394 } | 397 } |
| OLD | NEW |