Fix several leaks in the Sky compositor

When tearing down the Sky compostior, we need to destroy the GL context and all
the textures in the resource manager.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/761503004
This commit is contained in:
Adam Barth 2014-11-25 12:11:05 -08:00
parent c7a656aca9
commit 7e05650376
3 changed files with 15 additions and 8 deletions

View File

@ -19,9 +19,9 @@ LayerHost::LayerHost(LayerHostClient* client)
state_(kWaitingForSurfaceService),
frame_requested_(false),
surface_holder_(this, client->GetShell()),
gl_context_(mojo::GLContext::Create(client->GetShell())),
ganesh_context_(gl_context_),
resource_manager_(gl_context_),
gl_context_owner_(client->GetShell()),
ganesh_context_(gl_context()),
resource_manager_(gl_context()),
weak_factory_(this) {
}

View File

@ -8,6 +8,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/gpu/gl_context_owner.h"
#include "mojo/skia/ganesh_context.h"
#include "sky/compositor/layer_host_client.h"
#include "sky/compositor/resource_manager.h"
@ -26,7 +27,7 @@ class LayerHost : public SurfaceHolder::Client {
LayerHostClient* client() const { return client_; }
const base::WeakPtr<mojo::GLContext>& gl_context() const {
return gl_context_;
return gl_context_owner_.context();
}
mojo::GaneshContext* ganesh_context() const {
@ -63,7 +64,7 @@ class LayerHost : public SurfaceHolder::Client {
State state_;
bool frame_requested_;
SurfaceHolder surface_holder_;
base::WeakPtr<mojo::GLContext> gl_context_;
mojo::GLContextOwner gl_context_owner_;
mojo::GaneshContext ganesh_context_;
ResourceManager resource_manager_;
scoped_refptr<Layer> root_layer_;

View File

@ -9,6 +9,7 @@
#endif
#include "base/logging.h"
#include "base/stl_util.h"
#include "gpu/GLES2/gl2chromium.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
@ -24,6 +25,8 @@ ResourceManager::ResourceManager(base::WeakPtr<mojo::GLContext> gl_context)
}
ResourceManager::~ResourceManager() {
STLDeleteContainerPairSecondPointers(resource_to_texture_map_.begin(),
resource_to_texture_map_.end());
}
scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture(
@ -73,11 +76,14 @@ void ResourceManager::ReturnResources(
for (size_t i = 0u; i < resources.size(); ++i) {
mojo::ReturnedResourcePtr resource = resources[i].Pass();
DCHECK_EQ(1, resource->count);
glWaitSyncPointCHROMIUM(resource->sync_point);
mojo::GLTexture* texture = resource_to_texture_map_[resource->id];
auto iter = resource_to_texture_map_.find(resource->id);
if (iter == resource_to_texture_map_.end())
continue;
mojo::GLTexture* texture = iter->second;
DCHECK_NE(0u, texture->texture_id());
resource_to_texture_map_.erase(resource->id);
resource_to_texture_map_.erase(iter);
// TODO(abarth): Consider recycling the texture.
glWaitSyncPointCHROMIUM(resource->sync_point);
delete texture;
}
}