| 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()) { | 34 scoped_ptr<mojo::GLTexture> texture = texture_cache_.GetTexture(size); |
| 35 scoped_ptr<mojo::GLTexture> texture(available_textures_.back()); | 35 if (texture) |
| 36 available_textures_.back() = nullptr; | 36 return texture.Pass(); |
| 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 | |
| 44 gl_context_->MakeCurrent(); | 37 gl_context_->MakeCurrent(); |
| 45 return make_scoped_ptr(new mojo::GLTexture( | 38 return make_scoped_ptr(new mojo::GLTexture( |
| 46 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); | 39 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size))); |
| 47 } | 40 } |
| 48 | 41 |
| 49 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( | 42 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource( |
| 50 Layer* layer) { | 43 Layer* layer) { |
| 51 scoped_ptr<mojo::GLTexture> texture = layer->GetTexture(); | 44 scoped_ptr<mojo::GLTexture> texture = layer->GetTexture(); |
| 52 mojo::Size size = texture->size(); | 45 mojo::Size size = texture->size(); |
| 53 | 46 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 75 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 83 DCHECK(resources.size()); | 76 DCHECK(resources.size()); |
| 84 | 77 |
| 85 gl_context_->MakeCurrent(); | 78 gl_context_->MakeCurrent(); |
| 86 for (size_t i = 0u; i < resources.size(); ++i) { | 79 for (size_t i = 0u; i < resources.size(); ++i) { |
| 87 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 80 mojo::ReturnedResourcePtr resource = resources[i].Pass(); |
| 88 DCHECK_EQ(1, resource->count); | 81 DCHECK_EQ(1, resource->count); |
| 89 auto iter = resource_to_texture_map_.find(resource->id); | 82 auto iter = resource_to_texture_map_.find(resource->id); |
| 90 if (iter == resource_to_texture_map_.end()) | 83 if (iter == resource_to_texture_map_.end()) |
| 91 continue; | 84 continue; |
| 92 mojo::GLTexture* texture = iter->second; | 85 scoped_ptr<mojo::GLTexture> texture(iter->second); |
| 93 DCHECK_NE(0u, texture->texture_id()); | 86 DCHECK_NE(0u, texture->texture_id()); |
| 94 resource_to_texture_map_.erase(iter); | 87 resource_to_texture_map_.erase(iter); |
| 95 glWaitSyncPointCHROMIUM(resource->sync_point); | 88 glWaitSyncPointCHROMIUM(resource->sync_point); |
| 96 available_textures_.push_back(texture); | 89 texture_cache_.PutTexture(texture.Pass()); |
| 97 } | 90 } |
| 98 } | 91 } |
| 99 | 92 |
| 100 } // namespace examples | 93 } // namespace examples |
| OLD | NEW |