OLD | NEW |
---|---|
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 |
(...skipping 13 matching lines...) Expand all Loading... | |
24 : gl_context_(gl_context), next_resource_id_(0) { | 24 : gl_context_(gl_context), next_resource_id_(0) { |
25 } | 25 } |
26 | 26 |
27 ResourceManager::~ResourceManager() { | 27 ResourceManager::~ResourceManager() { |
28 STLDeleteContainerPairSecondPointers(resource_to_texture_map_.begin(), | 28 STLDeleteContainerPairSecondPointers(resource_to_texture_map_.begin(), |
29 resource_to_texture_map_.end()); | 29 resource_to_texture_map_.end()); |
30 } | 30 } |
31 | 31 |
32 scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture( | 32 scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture( |
33 const gfx::Size& size) { | 33 const gfx::Size& size) { |
34 if (!available_textures_.empty()) { | |
35 scoped_ptr<mojo::GLTexture> texture(available_textures_.back()); | |
36 available_textures_.back() = nullptr; | |
37 available_textures_.pop_back(); | |
38 if (texture->size() == size) | |
39 return texture.Pass(); | |
40 // Currently we only support caching textures of a constant size. | |
41 available_textures_.clear(); | |
42 } | |
43 | |
34 gl_context_->MakeCurrent(); | 44 gl_context_->MakeCurrent(); |
35 return make_scoped_ptr(new mojo::GLTexture( | 45 return make_scoped_ptr(new mojo::GLTexture( |
36 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); | 46 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); |
37 } | 47 } |
38 | 48 |
39 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( | 49 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( |
40 Layer* layer) { | 50 Layer* layer) { |
41 scoped_ptr<mojo::GLTexture> texture = layer->GetTexture(); | 51 scoped_ptr<mojo::GLTexture> texture = layer->GetTexture(); |
42 mojo::Size size = texture->size(); | 52 mojo::Size size = texture->size(); |
43 | 53 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 gl_context_->MakeCurrent(); | 85 gl_context_->MakeCurrent(); |
76 for (size_t i = 0u; i < resources.size(); ++i) { | 86 for (size_t i = 0u; i < resources.size(); ++i) { |
77 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 87 mojo::ReturnedResourcePtr resource = resources[i].Pass(); |
78 DCHECK_EQ(1, resource->count); | 88 DCHECK_EQ(1, resource->count); |
79 auto iter = resource_to_texture_map_.find(resource->id); | 89 auto iter = resource_to_texture_map_.find(resource->id); |
80 if (iter == resource_to_texture_map_.end()) | 90 if (iter == resource_to_texture_map_.end()) |
81 continue; | 91 continue; |
82 mojo::GLTexture* texture = iter->second; | 92 mojo::GLTexture* texture = iter->second; |
83 DCHECK_NE(0u, texture->texture_id()); | 93 DCHECK_NE(0u, texture->texture_id()); |
84 resource_to_texture_map_.erase(iter); | 94 resource_to_texture_map_.erase(iter); |
85 // TODO(abarth): Consider recycling the texture. | 95 // TODO(abarth): Consider recycling the texture. |
jamesr
2015/01/15 18:51:50
this can go away now
| |
86 glWaitSyncPointCHROMIUM(resource->sync_point); | 96 glWaitSyncPointCHROMIUM(resource->sync_point); |
87 delete texture; | 97 available_textures_.push_back(texture); |
88 } | 98 } |
89 } | 99 } |
90 | 100 |
91 } // namespace examples | 101 } // namespace examples |
OLD | NEW |