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