The Sky compositor should recycle textures

Previously, we were creating a new texture for every frame. Using tracing on a
Nexus 5, that appears to cost about 6ms per frame on the GPU thread. After this
CL, we keep a cache of recently used textures and only allocate a new one when
either (1) we don't have one free or (2) our size requirements have changed.

If our size requirements change, we dump the whole texture cache. In the
future, we'll probably need something fancier if we ever need more than one
size texture per frame.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/845963006
This commit is contained in:
Adam Barth
2015-01-15 11:09:56 -08:00
parent 44bf8e332d
commit 2219ef50b9
2 changed files with 15 additions and 2 deletions

View File

@@ -31,6 +31,16 @@ ResourceManager::~ResourceManager() {
scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture(
const gfx::Size& size) {
if (!available_textures_.empty()) {
scoped_ptr<mojo::GLTexture> texture(available_textures_.back());
available_textures_.back() = nullptr;
available_textures_.pop_back();
if (texture->size() == size)
return texture.Pass();
// Currently we only support caching textures of a constant size.
available_textures_.clear();
}
gl_context_->MakeCurrent();
return make_scoped_ptr(new mojo::GLTexture(
gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size)));
@@ -82,9 +92,8 @@ void ResourceManager::ReturnResources(
mojo::GLTexture* texture = iter->second;
DCHECK_NE(0u, texture->texture_id());
resource_to_texture_map_.erase(iter);
// TODO(abarth): Consider recycling the texture.
glWaitSyncPointCHROMIUM(resource->sync_point);
delete texture;
available_textures_.push_back(texture);
}
}

View File

@@ -6,6 +6,8 @@
#define SKY_COMPOSITOR_RESOURCE_MANAGER_H_
#include "base/containers/hash_tables.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
#include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h"
@@ -37,6 +39,8 @@ class ResourceManager {
uint32_t next_resource_id_;
base::hash_map<uint32_t, mojo::GLTexture*> resource_to_texture_map_;
ScopedVector<mojo::GLTexture> available_textures_;
DISALLOW_COPY_AND_ASSIGN(ResourceManager);
};