Index: src/gpu/SkGpuDevice.cpp |
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
index 861383bf6a03f48b8edeb3488d0f99a16dc05bf9..d34170cba110160aa42446bbfaa9d319c965923b 100644 |
--- a/src/gpu/SkGpuDevice.cpp |
+++ b/src/gpu/SkGpuDevice.cpp |
@@ -1842,6 +1842,10 @@ void SkGpuDevice::EXPERIMENTAL_purge(const SkPicture* picture) { |
bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* picture) { |
+ if (NULL == picture->fPlayback.get()) { |
+ return false; |
+ } |
+ |
SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); |
const SkPicture::AccelData* data = picture->EXPERIMENTAL_getAccelData(key); |
@@ -1938,60 +1942,50 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi |
SkPicturePlayback::PlaybackReplacements replacements; |
+ // Generate the layer and/or ensure it is locked |
for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
if (pullForward[i]) { |
GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); |
const GPUAccelData::SaveLayerInfo& info = gpuData->saveLayerInfo(i); |
- if (NULL != picture->fPlayback.get()) { |
- SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerInfo = |
+ SkPicturePlayback::PlaybackReplacements::ReplacementInfo* layerInfo = |
replacements.push(); |
- layerInfo->fStart = info.fSaveLayerOpID; |
- layerInfo->fStop = info.fRestoreOpID; |
- layerInfo->fPos = info.fOffset; |
- |
- GrTextureDesc desc; |
- desc.fFlags = kRenderTarget_GrTextureFlagBit; |
- desc.fWidth = info.fSize.fWidth; |
- desc.fHeight = info.fSize.fHeight; |
- desc.fConfig = kSkia8888_GrPixelConfig; |
- // TODO: need to deal with sample count |
- |
- bool bNeedsRendering = true; |
- |
- // This just uses scratch textures and doesn't cache the texture. |
- // This can yield a lot of re-rendering |
- if (NULL == layer->getTexture()) { |
- layer->setTexture(fContext->lockAndRefScratchTexture(desc, |
- GrContext::kApprox_ScratchTexMatch)); |
- if (NULL == layer->getTexture()) { |
- continue; |
- } |
- } else { |
- bNeedsRendering = false; |
- } |
+ layerInfo->fStart = info.fSaveLayerOpID; |
+ layerInfo->fStop = info.fRestoreOpID; |
+ layerInfo->fPos = info.fOffset; |
+ |
+ GrTextureDesc desc; |
+ desc.fFlags = kRenderTarget_GrTextureFlagBit; |
+ desc.fWidth = info.fSize.fWidth; |
+ desc.fHeight = info.fSize.fHeight; |
+ desc.fConfig = kSkia8888_GrPixelConfig; |
+ // TODO: need to deal with sample count |
+ |
+ bool needsRendering = !fContext->getLayerCache()->lock(layer, desc); |
+ if (NULL == layer->getTexture()) { |
+ continue; |
+ } |
- layerInfo->fBM = SkNEW(SkBitmap); |
- wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, layerInfo->fBM); |
+ layerInfo->fBM = SkNEW(SkBitmap); // fBM is allocated so ReplacementInfo can be POD |
+ wrap_texture(layer->getTexture(), desc.fWidth, desc.fHeight, layerInfo->fBM); |
- SkASSERT(info.fPaint); |
- layerInfo->fPaint = info.fPaint; |
+ SkASSERT(info.fPaint); |
+ layerInfo->fPaint = info.fPaint; |
- if (bNeedsRendering) { |
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
- layer->getTexture()->asRenderTarget())); |
+ if (needsRendering) { |
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( |
+ layer->getTexture()->asRenderTarget())); |
- SkCanvas* canvas = surface->getCanvas(); |
+ SkCanvas* canvas = surface->getCanvas(); |
- canvas->setMatrix(info.fCTM); |
- canvas->clear(SK_ColorTRANSPARENT); |
+ canvas->setMatrix(info.fCTM); |
+ canvas->clear(SK_ColorTRANSPARENT); |
- picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRestoreOpID); |
- picture->fPlayback->draw(*canvas, NULL); |
- picture->fPlayback->setDrawLimits(0, 0); |
- canvas->flush(); |
- } |
+ picture->fPlayback->setDrawLimits(info.fSaveLayerOpID, info.fRestoreOpID); |
+ picture->fPlayback->draw(*canvas, NULL); |
+ picture->fPlayback->setDrawLimits(0, 0); |
+ canvas->flush(); |
} |
} |
} |
@@ -2001,13 +1995,10 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* canvas, const SkPicture* pi |
picture->fPlayback->draw(*canvas, NULL); |
picture->fPlayback->setReplacements(NULL); |
+ // unlock the layers |
for (int i = 0; i < gpuData->numSaveLayers(); ++i) { |
- GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(picture, i); |
- |
- if (NULL != layer->getTexture()) { |
- fContext->unlockScratchTexture(layer->getTexture()); |
- layer->setTexture(NULL); |
- } |
+ GrCachedLayer* layer = fContext->getLayerCache()->findLayer(picture, i); |
+ fContext->getLayerCache()->unlock(layer); |
} |
return true; |