Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: sky/compositor/resource_manager.cc

Issue 761503004: Fix several leaks in the Sky compositor (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix typo Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/compositor/layer_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sky/compositor/resource_manager.h" 5 #include "sky/compositor/resource_manager.h"
6 6
7 #ifndef GL_GLEXT_PROTOTYPES 7 #ifndef GL_GLEXT_PROTOTYPES
8 #define GL_GLEXT_PROTOTYPES 8 #define GL_GLEXT_PROTOTYPES
9 #endif 9 #endif
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h"
12 #include "gpu/GLES2/gl2chromium.h" 13 #include "gpu/GLES2/gl2chromium.h"
13 #include "gpu/GLES2/gl2extchromium.h" 14 #include "gpu/GLES2/gl2extchromium.h"
14 #include "mojo/converters/geometry/geometry_type_converters.h" 15 #include "mojo/converters/geometry/geometry_type_converters.h"
15 #include "mojo/gpu/gl_context.h" 16 #include "mojo/gpu/gl_context.h"
16 #include "mojo/gpu/gl_texture.h" 17 #include "mojo/gpu/gl_texture.h"
17 #include "mojo/public/c/gles2/gles2.h" 18 #include "mojo/public/c/gles2/gles2.h"
18 #include "sky/compositor/layer.h" 19 #include "sky/compositor/layer.h"
19 20
20 namespace sky { 21 namespace sky {
21 22
22 ResourceManager::ResourceManager(base::WeakPtr<mojo::GLContext> gl_context) 23 ResourceManager::ResourceManager(base::WeakPtr<mojo::GLContext> gl_context)
23 : gl_context_(gl_context), next_resource_id_(0) { 24 : gl_context_(gl_context), next_resource_id_(0) {
24 } 25 }
25 26
26 ResourceManager::~ResourceManager() { 27 ResourceManager::~ResourceManager() {
28 STLDeleteContainerPairSecondPointers(resource_to_texture_map_.begin(),
29 resource_to_texture_map_.end());
ojan 2014/11/25 19:27:47 git cl format plz
27 } 30 }
28 31
29 scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture( 32 scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture(
30 const gfx::Size& size) { 33 const gfx::Size& size) {
31 gl_context_->MakeCurrent(); 34 gl_context_->MakeCurrent();
32 return make_scoped_ptr(new mojo::GLTexture( 35 return make_scoped_ptr(new mojo::GLTexture(
33 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); 36 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size)));
34 } 37 }
35 38
36 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( 39 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource(
(...skipping 29 matching lines...) Expand all
66 } 69 }
67 70
68 void ResourceManager::ReturnResources( 71 void ResourceManager::ReturnResources(
69 mojo::Array<mojo::ReturnedResourcePtr> resources) { 72 mojo::Array<mojo::ReturnedResourcePtr> resources) {
70 DCHECK(resources.size()); 73 DCHECK(resources.size());
71 74
72 gl_context_->MakeCurrent(); 75 gl_context_->MakeCurrent();
73 for (size_t i = 0u; i < resources.size(); ++i) { 76 for (size_t i = 0u; i < resources.size(); ++i) {
74 mojo::ReturnedResourcePtr resource = resources[i].Pass(); 77 mojo::ReturnedResourcePtr resource = resources[i].Pass();
75 DCHECK_EQ(1, resource->count); 78 DCHECK_EQ(1, resource->count);
79 auto iter = resource_to_texture_map_.find(resource->id);
80 if (iter == resource_to_texture_map_.end())
81 continue;
82 mojo::GLTexture* texture = iter->second;
83 DCHECK_NE(0u, texture->texture_id());
84 resource_to_texture_map_.erase(iter);
85 // TODO(abarth): Consider recycling the texture.
76 glWaitSyncPointCHROMIUM(resource->sync_point); 86 glWaitSyncPointCHROMIUM(resource->sync_point);
77 mojo::GLTexture* texture = resource_to_texture_map_[resource->id];
78 DCHECK_NE(0u, texture->texture_id());
79 resource_to_texture_map_.erase(resource->id);
80 // TODO(abarth): Consider recycling the texture.
81 delete texture; 87 delete texture;
82 } 88 }
83 } 89 }
84 90
85 } // namespace examples 91 } // namespace examples
OLDNEW
« no previous file with comments | « sky/compositor/layer_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698