OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
7 #endif | 7 #endif |
8 #include <GLES2/gl2extmojo.h> | 8 #include <GLES2/gl2extmojo.h> |
9 | 9 |
10 #include "mojo/gpu/gl_context.h" | 10 #include "mojo/gpu/gl_context.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // Get the sync point from the sync point map. | 50 // Get the sync point from the sync point map. |
51 auto sync_point_iterator = | 51 auto sync_point_iterator = |
52 resource_to_sync_point_map_.find(available_resource_id); | 52 resource_to_sync_point_map_.find(available_resource_id); |
53 int sync_point = sync_point_iterator->second; | 53 int sync_point = sync_point_iterator->second; |
54 resource_to_sync_point_map_.erase(sync_point_iterator); | 54 resource_to_sync_point_map_.erase(sync_point_iterator); |
55 | 55 |
56 // If the texture is the right size, use it. | 56 // If the texture is the right size, use it. |
57 if (texture_size.width == requested_size.width && | 57 if (texture_size.width == requested_size.width && |
58 texture_size.height == requested_size.height) { | 58 texture_size.height == requested_size.height) { |
59 glWaitSyncPointCHROMIUM(sync_point); | 59 glWaitSyncPointCHROMIUM(sync_point); |
60 return texture_info.Pass(); | 60 return texture_info; |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 // If our context is invalid return an empty scoped ptr. | 64 // If our context is invalid return an empty scoped ptr. |
65 if (!gl_context_) { | 65 if (!gl_context_) { |
66 return scoped_ptr<TextureInfo>(); | 66 return scoped_ptr<TextureInfo>(); |
67 } | 67 } |
68 | 68 |
69 // We couldn't find an existing texture to reuse, create a new one! | 69 // We couldn't find an existing texture to reuse, create a new one! |
70 scoped_ptr<mojo::GLTexture> new_texture( | 70 scoped_ptr<mojo::GLTexture> new_texture( |
71 new mojo::GLTexture(gl_context_, requested_size)); | 71 new mojo::GLTexture(gl_context_, requested_size)); |
72 next_resource_id_++; | 72 next_resource_id_++; |
73 scoped_ptr<TextureInfo> texture_info( | 73 scoped_ptr<TextureInfo> texture_info( |
74 new TextureInfo(new_texture.Pass(), next_resource_id_)); | 74 new TextureInfo(new_texture.Pass(), next_resource_id_)); |
75 return texture_info.Pass(); | 75 return texture_info; |
76 } | 76 } |
77 | 77 |
78 void TextureCache::NotifyPendingResourceReturn( | 78 void TextureCache::NotifyPendingResourceReturn( |
79 uint32_t resource_id, | 79 uint32_t resource_id, |
80 scoped_ptr<mojo::GLTexture> texture) { | 80 scoped_ptr<mojo::GLTexture> texture) { |
81 resource_to_texture_map_[resource_id] = texture.Pass(); | 81 resource_to_texture_map_[resource_id] = texture.Pass(); |
82 } | 82 } |
83 | 83 |
84 // mojo::ResourceReturner | 84 // mojo::ResourceReturner |
85 void TextureCache::ReturnResources( | 85 void TextureCache::ReturnResources( |
86 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 86 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
87 if (!gl_context_) { | 87 if (!gl_context_) { |
88 return; | 88 return; |
89 } | 89 } |
90 gl_context_->MakeCurrent(); | 90 gl_context_->MakeCurrent(); |
91 for (size_t i = 0u; i < resources.size(); ++i) { | 91 for (size_t i = 0u; i < resources.size(); ++i) { |
92 mojo::ReturnedResourcePtr resource = resources[i].Pass(); | 92 mojo::ReturnedResourcePtr resource = resources[i].Pass(); |
93 DCHECK_EQ(1, resource->count); | 93 DCHECK_EQ(1, resource->count); |
94 auto it = resource_to_texture_map_.find(resource->id); | 94 auto it = resource_to_texture_map_.find(resource->id); |
95 // Ignore the returned resource if we haven't been notified of its pending | 95 // Ignore the returned resource if we haven't been notified of its pending |
96 // return. | 96 // return. |
97 if (it != resource_to_texture_map_.end()) { | 97 if (it != resource_to_texture_map_.end()) { |
98 available_textures_.push_back(resource->id); | 98 available_textures_.push_back(resource->id); |
99 resource_to_sync_point_map_[resource->id] = resource->sync_point; | 99 resource_to_sync_point_map_[resource->id] = resource->sync_point; |
100 } | 100 } |
101 } | 101 } |
102 } | 102 } |
103 } // namespace mojo | 103 } // namespace mojo |
OLD | NEW |