Chromium Code Reviews| Index: src/gpu/GrLayerAtlas.cpp |
| diff --git a/src/gpu/GrLayerAtlas.cpp b/src/gpu/GrLayerAtlas.cpp |
| index 3b30607c8cfc72cea328bbea9eb3023b89842098..7e959dabebfd2e5647c0b1f34982578d7d342e71 100644 |
| --- a/src/gpu/GrLayerAtlas.cpp |
| +++ b/src/gpu/GrLayerAtlas.cpp |
| @@ -6,6 +6,7 @@ |
| * found in the LICENSE file. |
| */ |
| +#include "GrGpuResourcePriv.h" |
| #include "GrLayerAtlas.h" |
| #include "GrRectanizer.h" |
| #include "GrTextureProvider.h" |
| @@ -43,6 +44,39 @@ void GrLayerAtlas::Plot::reset() { |
| } |
| /////////////////////////////////////////////////////////////////////////////// |
| +static void get_layer_atlas_key(GrUniqueKey* result) { |
| + static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| + GrUniqueKey::Builder builder(result, kDomain, 0); |
|
bsalomon
2015/11/05 15:39:25
Can't the key itself be a static?
robertphillips
2015/11/05 19:14:22
Done.
|
| +} |
| + |
| +bool GrLayerAtlas::reattachBackingTexture() { |
| + SkASSERT(!fTexture); |
| + |
| + GrUniqueKey key; |
| + |
| + get_layer_atlas_key(&key); |
| + |
| + fTexture.reset(fTexProvider->findAndRefTextureByUniqueKey(key)); |
| + return SkToBool(fTexture); |
| +} |
| + |
| +void GrLayerAtlas::createBackingTexture() { |
| + SkASSERT(!fTexture); |
| + |
| + GrSurfaceDesc desc; |
| + desc.fFlags = fFlags; |
| + desc.fWidth = fBackingTextureSize.width(); |
| + desc.fHeight = fBackingTextureSize.height(); |
| + desc.fConfig = fPixelConfig; |
| + |
| + fTexture.reset(fTexProvider->createTexture(desc, true, nullptr, 0)); |
| + |
| + GrUniqueKey key; |
| + |
| + get_layer_atlas_key(&key); |
| + |
| + fTexture->resourcePriv().setUniqueKey(key); |
| +} |
| GrLayerAtlas::GrLayerAtlas(GrTextureProvider* texProvider, GrPixelConfig config, |
| GrSurfaceFlags flags, |
| @@ -52,7 +86,6 @@ GrLayerAtlas::GrLayerAtlas(GrTextureProvider* texProvider, GrPixelConfig config, |
| fPixelConfig = config; |
| fFlags = flags; |
| fBackingTextureSize = backingTextureSize; |
| - fTexture = nullptr; |
| int textureWidth = fBackingTextureSize.width(); |
| int textureHeight = fBackingTextureSize.height(); |
| @@ -81,8 +114,14 @@ GrLayerAtlas::GrLayerAtlas(GrTextureProvider* texProvider, GrPixelConfig config, |
| } |
| } |
| +void GrLayerAtlas::resetPlots() { |
| + PlotIter iter; |
| + for (Plot* plot = iter.init(fPlotList, PlotIter::kHead_IterStart); plot; plot = iter.next()) { |
| + plot->reset(); |
| + } |
| +} |
| + |
| GrLayerAtlas::~GrLayerAtlas() { |
| - SkSafeUnref(fTexture); |
| delete[] fPlotArray; |
| } |
| @@ -111,14 +150,7 @@ GrLayerAtlas::Plot* GrLayerAtlas::addToAtlas(ClientPlotUsage* usage, |
| // before we get a new plot, make sure we have a backing texture |
| if (nullptr == fTexture) { |
| - // TODO: Update this to use the cache rather than directly creating a texture. |
| - GrSurfaceDesc desc; |
| - desc.fFlags = fFlags; |
| - desc.fWidth = fBackingTextureSize.width(); |
| - desc.fHeight = fBackingTextureSize.height(); |
| - desc.fConfig = fPixelConfig; |
| - |
| - fTexture = fTexProvider->createTexture(desc, true, nullptr, 0); |
| + this->createBackingTexture(); |
| if (nullptr == fTexture) { |
| return nullptr; |
| } |