| 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 "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkDeviceImageFilterProxy.h" | 13 #include "SkDeviceImageFilterProxy.h" |
| 14 #include "SkDeviceProperties.h" | 14 #include "SkDeviceProperties.h" |
| 15 #include "SkGpuDevice.h" | 15 #include "SkGpuDevice.h" |
| 16 #include "SkGrPixelRef.h" | 16 #include "SkGrPixelRef.h" |
| 17 #include "SkLayerInfo.h" | 17 #include "SkLayerInfo.h" |
| 18 #include "SkRecordDraw.h" | 18 #include "SkRecordDraw.h" |
| 19 #include "SkSurface.h" | 19 #include "SkSurface.h" |
| 20 #include "SkSurface_Gpu.h" | 20 #include "SkSurface_Gpu.h" |
| 21 #include "SkImagePriv.h" |
| 21 | 22 |
| 22 // Create the layer information for the hoisted layer and secure the | 23 // Create the layer information for the hoisted layer and secure the |
| 23 // required texture/render target resources. | 24 // required texture/render target resources. |
| 24 static void prepare_for_hoisting(GrLayerCache* layerCache, | 25 static void prepare_for_hoisting(GrLayerCache* layerCache, |
| 25 const SkPicture* topLevelPicture, | 26 const SkPicture* topLevelPicture, |
| 26 const SkMatrix& initialMat, | 27 const SkMatrix& initialMat, |
| 27 const SkLayerInfo::BlockInfo& info, | 28 const SkLayerInfo::BlockInfo& info, |
| 28 const SkIRect& srcIR, | 29 const SkIRect& srcIR, |
| 29 const SkIRect& dstIR, | 30 const SkIRect& dstIR, |
| 30 SkTDArray<GrHoistedLayer>* needRendering, | 31 SkTDArray<GrHoistedLayer>* needRendering, |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 pict->drawablePicts(), pict->drawableCount(), | 270 pict->drawablePicts(), pict->drawableCount(), |
| 270 layer->start() + 1, layer->stop(), initialCTM); | 271 layer->start() + 1, layer->stop(), initialCTM); |
| 271 | 272 |
| 272 atlasCanvas->restore(); | 273 atlasCanvas->restore(); |
| 273 } | 274 } |
| 274 | 275 |
| 275 atlasCanvas->flush(); | 276 atlasCanvas->flush(); |
| 276 } | 277 } |
| 277 } | 278 } |
| 278 | 279 |
| 279 SkBitmap wrap_texture(GrTexture* texture) { | 280 static SkImage* wrap_texture(GrTexture* texture) { |
| 280 SkASSERT(texture); | 281 SkASSERT(texture); |
| 281 | |
| 282 SkBitmap result; | 282 SkBitmap result; |
| 283 result.setInfo(texture->surfacePriv().info()); | 283 result.setInfo(texture->surfacePriv().info()); |
| 284 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre
f(); | 284 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre
f(); |
| 285 return result; | 285 return SkNewImageFromBitmapTexture(result, texture->desc().fSampleCnt, |
| 286 SkSurface::kYes_Budgeted); |
| 286 } | 287 } |
| 287 | 288 |
| 288 void GrLayerHoister::FilterLayer(GrContext* context, | 289 void GrLayerHoister::FilterLayer(GrContext* context, |
| 289 SkGpuDevice* device, | 290 SkGpuDevice* device, |
| 290 const GrHoistedLayer& info) { | 291 const GrHoistedLayer& info) { |
| 291 GrCachedLayer* layer = info.fLayer; | 292 GrCachedLayer* layer = info.fLayer; |
| 292 | 293 |
| 293 SkASSERT(layer->filter()); | 294 SkASSERT(layer->filter()); |
| 294 | 295 |
| 295 static const int kDefaultCacheSize = 32 * 1024 * 1024; | 296 static const int kDefaultCacheSize = 32 * 1024 * 1024; |
| 296 | 297 |
| 297 SkBitmap filteredBitmap; | |
| 298 SkIPoint offset = SkIPoint::Make(0, 0); | 298 SkIPoint offset = SkIPoint::Make(0, 0); |
| 299 | 299 |
| 300 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr
cIR().fTop); | 300 const SkIPoint filterOffset = SkIPoint::Make(layer->srcIR().fLeft, layer->sr
cIR().fTop); |
| 301 | 301 |
| 302 SkMatrix totMat = SkMatrix::I(); | 302 SkMatrix totMat = SkMatrix::I(); |
| 303 totMat.preConcat(info.fPreMat); | 303 totMat.preConcat(info.fPreMat); |
| 304 totMat.preConcat(info.fLocalMat); | 304 totMat.preConcat(info.fLocalMat); |
| 305 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO
ffset.fY)); | 305 totMat.postTranslate(-SkIntToScalar(filterOffset.fX), -SkIntToScalar(filterO
ffset.fY)); |
| 306 | 306 |
| 307 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); | 307 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); |
| 308 SkIRect clipBounds = layer->rect(); | 308 SkIRect clipBounds = layer->rect(); |
| 309 | 309 |
| 310 // This cache is transient, and is freed (along with all its contained | 310 // This cache is transient, and is freed (along with all its contained |
| 311 // textures) when it goes out of scope. | 311 // textures) when it goes out of scope. |
| 312 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau
ltCacheSize)); | 312 SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefau
ltCacheSize)); |
| 313 SkImageFilter::Context filterContext(totMat, clipBounds, cache); | 313 SkImageFilter::Context filterContext(totMat, clipBounds, cache); |
| 314 | 314 |
| 315 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeo
metry)); | 315 SkDeviceImageFilterProxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeo
metry)); |
| 316 const SkBitmap src = wrap_texture(layer->texture()); | 316 SkAutoTUnref<SkImage> src(wrap_texture(layer->texture())); |
| 317 | 317 SkAutoTUnref<SkImage> filteredImage; |
| 318 if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitma
p, &offset)) { | 318 if (!layer->filter()->filterImage(&proxy, *src, filterContext, filteredImage
, &offset)) { |
| 319 // Filtering failed. Press on with the unfiltered version. | 319 // Filtering failed. Press on with the unfiltered version. |
| 320 return; | 320 return; |
| 321 } | 321 } |
| 322 | 322 |
| 323 SkIRect newRect = SkIRect::MakeWH(filteredBitmap.width(), filteredBitmap.hei
ght()); | 323 SkIRect newRect = SkIRect::MakeWH(filteredImage->width(), filteredImage->hei
ght()); |
| 324 layer->setTexture(filteredBitmap.getTexture(), newRect); | 324 layer->setTexture(filteredImage->getTexture(), newRect); |
| 325 layer->setOffset(offset); | 325 layer->setOffset(offset); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { | 328 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay
er>& layers) { |
| 329 for (int i = 0; i < layers.count(); ++i) { | 329 for (int i = 0; i < layers.count(); ++i) { |
| 330 GrCachedLayer* layer = layers[i].fLayer; | 330 GrCachedLayer* layer = layers[i].fLayer; |
| 331 const SkPicture* pict = layers[i].fPicture; | 331 const SkPicture* pict = layers[i].fPicture; |
| 332 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcI
R().fTop); | 332 const SkIPoint offset = SkIPoint::Make(layer->srcIR().fLeft, layer->srcI
R().fTop); |
| 333 | 333 |
| 334 // Each non-atlased layer has its own GrTexture | 334 // Each non-atlased layer has its own GrTexture |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 void GrLayerHoister::PurgeCache(GrContext* context) { | 381 void GrLayerHoister::PurgeCache(GrContext* context) { |
| 382 #if !GR_CACHE_HOISTED_LAYERS | 382 #if !GR_CACHE_HOISTED_LAYERS |
| 383 GrLayerCache* layerCache = context->getLayerCache(); | 383 GrLayerCache* layerCache = context->getLayerCache(); |
| 384 | 384 |
| 385 // This code completely clears out the atlas. It is required when | 385 // This code completely clears out the atlas. It is required when |
| 386 // caching is disabled so the atlas doesn't fill up and force more | 386 // caching is disabled so the atlas doesn't fill up and force more |
| 387 // free floating layers | 387 // free floating layers |
| 388 layerCache->purgeAll(); | 388 layerCache->purgeAll(); |
| 389 #endif | 389 #endif |
| 390 } | 390 } |
| OLD | NEW |