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