diff options
author | 2014-06-24 13:10:43 -0700 | |
---|---|---|
committer | 2014-06-24 13:10:43 -0700 | |
commit | 4ec84da746d66e1bcb76ab2f8b94602b8e966589 (patch) | |
tree | 3d889de63a2a91b5111a753f8d62dafd6b009472 /src/gpu/GrLayerCache.cpp | |
parent | 332600fb43fcaaa022c3c0b04ba52b371930fb15 (diff) |
Move allocation of texture from SkGpuDevice to GrLayerCache
In order to atlas the layers the GrLayerCache needs to be given more control over where a given layer's texture is allocated (i.e., it could be a raw scratch texture or in the cache).
R=bsalomon@google.com
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/350183006
Diffstat (limited to 'src/gpu/GrLayerCache.cpp')
-rw-r--r-- | src/gpu/GrLayerCache.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp index f6377bf7e9..86258abf42 100644 --- a/src/gpu/GrLayerCache.cpp +++ b/src/gpu/GrLayerCache.cpp @@ -41,8 +41,8 @@ private: int fLayerID; }; -GrLayerCache::GrLayerCache(GrGpu* gpu) - : fGpu(SkRef(gpu)) +GrLayerCache::GrLayerCache(GrContext* context) + : fContext(context) , fLayerPool(16) { // TODO: may need to increase this later } @@ -57,7 +57,7 @@ void GrLayerCache::init() { // The layer cache only gets 1 plot SkISize textureSize = SkISize::Make(kAtlasTextureWidth, kAtlasTextureHeight); - fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fGpu, kSkia8888_GrPixelConfig, + fAtlasMgr.reset(SkNEW_ARGS(GrAtlasMgr, (fContext->getGpu(), kSkia8888_GrPixelConfig, textureSize, 1, 1, false))); } @@ -75,6 +75,10 @@ GrCachedLayer* GrLayerCache::createLayer(const SkPicture* picture, int layerID) return layer; } +GrCachedLayer* GrLayerCache::findLayer(const SkPicture* picture, int layerID) { + SkASSERT(picture->uniqueID() != SK_InvalidGenID); + return fLayerHash.find(PictureLayerKey(picture->uniqueID(), layerID)); +} GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture, int layerID) { SkASSERT(picture->uniqueID() != SK_InvalidGenID); @@ -82,5 +86,24 @@ GrCachedLayer* GrLayerCache::findLayerOrCreate(const SkPicture* picture, int lay if (NULL == layer) { layer = this->createLayer(picture, layerID); } + return layer; } + +bool GrLayerCache::lock(GrCachedLayer* layer, const GrTextureDesc& desc) { + SkASSERT(NULL == layer->getTexture()); + + // This just uses scratch textures and doesn't cache the texture. + // This can yield a lot of re-rendering + layer->setTexture(fContext->lockAndRefScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); + return false; +} + +void GrLayerCache::unlock(GrCachedLayer* layer) { + if (NULL == layer || NULL == layer->getTexture()) { + return; + } + + fContext->unlockScratchTexture(layer->getTexture()); + layer->setTexture(NULL); +} |