OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stack> | 5 #include <stack> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "gpu/command_buffer/client/share_group.h" | 8 #include "gpu/command_buffer/client/share_group.h" |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
12 #include "gpu/command_buffer/client/gles2_implementation.h" | 12 #include "gpu/command_buffer/client/gles2_implementation.h" |
13 #include "gpu/command_buffer/client/program_info_manager.h" | 13 #include "gpu/command_buffer/client/program_info_manager.h" |
14 #include "gpu/command_buffer/common/id_allocator.h" | 14 #include "gpu/command_buffer/common/id_allocator.h" |
15 | 15 |
16 namespace gpu { | 16 namespace gpu { |
17 namespace gles2 { | 17 namespace gles2 { |
18 | 18 |
19 ShareGroupContextData::IdHandlerData::IdHandlerData() : flush_generation_(0) {} | 19 ShareGroupContextData::IdHandlerData::IdHandlerData() : flush_generation_(0) {} |
20 ShareGroupContextData::IdHandlerData::~IdHandlerData() {} | 20 ShareGroupContextData::IdHandlerData::~IdHandlerData() {} |
21 | 21 |
22 COMPILE_ASSERT(gpu::kInvalidResource == 0, | 22 COMPILE_ASSERT(gpu::kInvalidResource == 0, |
23 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); | 23 INVALID_RESOURCE_NOT_0_AS_GL_EXPECTS); |
24 | 24 |
25 // The standard id handler. | 25 // The standard id handler. |
26 class IdHandler : public IdHandlerInterface { | 26 class IdHandler : public IdHandlerInterface { |
27 public: | 27 public: |
28 IdHandler() { } | 28 IdHandler() { } |
29 virtual ~IdHandler() { } | 29 ~IdHandler() override {} |
30 | 30 |
31 // Overridden from IdHandlerInterface. | 31 // Overridden from IdHandlerInterface. |
32 virtual void MakeIds( | 32 void MakeIds(GLES2Implementation* /* gl_impl */, |
33 GLES2Implementation* /* gl_impl */, | 33 GLuint id_offset, |
34 GLuint id_offset, GLsizei n, GLuint* ids) override { | 34 GLsizei n, |
| 35 GLuint* ids) override { |
35 base::AutoLock auto_lock(lock_); | 36 base::AutoLock auto_lock(lock_); |
36 if (id_offset == 0) { | 37 if (id_offset == 0) { |
37 for (GLsizei ii = 0; ii < n; ++ii) { | 38 for (GLsizei ii = 0; ii < n; ++ii) { |
38 ids[ii] = id_allocator_.AllocateID(); | 39 ids[ii] = id_allocator_.AllocateID(); |
39 } | 40 } |
40 } else { | 41 } else { |
41 for (GLsizei ii = 0; ii < n; ++ii) { | 42 for (GLsizei ii = 0; ii < n; ++ii) { |
42 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); | 43 ids[ii] = id_allocator_.AllocateIDAtOrAbove(id_offset); |
43 id_offset = ids[ii] + 1; | 44 id_offset = ids[ii] + 1; |
44 } | 45 } |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 // Overridden from IdHandlerInterface. | 49 // Overridden from IdHandlerInterface. |
49 virtual bool FreeIds( | 50 bool FreeIds(GLES2Implementation* gl_impl, |
50 GLES2Implementation* gl_impl, | 51 GLsizei n, |
51 GLsizei n, const GLuint* ids, DeleteFn delete_fn) override { | 52 const GLuint* ids, |
| 53 DeleteFn delete_fn) override { |
52 base::AutoLock auto_lock(lock_); | 54 base::AutoLock auto_lock(lock_); |
53 | 55 |
54 for (GLsizei ii = 0; ii < n; ++ii) { | 56 for (GLsizei ii = 0; ii < n; ++ii) { |
55 id_allocator_.FreeID(ids[ii]); | 57 id_allocator_.FreeID(ids[ii]); |
56 } | 58 } |
57 | 59 |
58 (gl_impl->*delete_fn)(n, ids); | 60 (gl_impl->*delete_fn)(n, ids); |
59 // We need to ensure that the delete call is evaluated on the service side | 61 // We need to ensure that the delete call is evaluated on the service side |
60 // before any other contexts issue commands using these client ids. | 62 // before any other contexts issue commands using these client ids. |
61 // TODO(vmiura): Can remove this by virtualizing internal ids, however | 63 // TODO(vmiura): Can remove this by virtualizing internal ids, however |
62 // this code only affects PPAPI for now. | 64 // this code only affects PPAPI for now. |
63 gl_impl->helper()->CommandBufferHelper::Flush(); | 65 gl_impl->helper()->CommandBufferHelper::Flush(); |
64 return true; | 66 return true; |
65 } | 67 } |
66 | 68 |
67 // Overridden from IdHandlerInterface. | 69 // Overridden from IdHandlerInterface. |
68 virtual bool MarkAsUsedForBind(GLuint id) override { | 70 bool MarkAsUsedForBind(GLuint id) override { |
69 if (id == 0) | 71 if (id == 0) |
70 return true; | 72 return true; |
71 base::AutoLock auto_lock(lock_); | 73 base::AutoLock auto_lock(lock_); |
72 return id_allocator_.MarkAsUsed(id); | 74 return id_allocator_.MarkAsUsed(id); |
73 } | 75 } |
74 | 76 |
75 virtual void FreeContext(GLES2Implementation* gl_impl) override {} | 77 void FreeContext(GLES2Implementation* gl_impl) override {} |
76 | 78 |
77 private: | 79 private: |
78 base::Lock lock_; | 80 base::Lock lock_; |
79 IdAllocator id_allocator_; | 81 IdAllocator id_allocator_; |
80 }; | 82 }; |
81 | 83 |
82 // An id handler that requires Gen before Bind. | 84 // An id handler that requires Gen before Bind. |
83 class StrictIdHandler : public IdHandlerInterface { | 85 class StrictIdHandler : public IdHandlerInterface { |
84 public: | 86 public: |
85 explicit StrictIdHandler(int id_namespace) : id_namespace_(id_namespace) {} | 87 explicit StrictIdHandler(int id_namespace) : id_namespace_(id_namespace) {} |
86 virtual ~StrictIdHandler() {} | 88 ~StrictIdHandler() override {} |
87 | 89 |
88 // Overridden from IdHandler. | 90 // Overridden from IdHandler. |
89 virtual void MakeIds(GLES2Implementation* gl_impl, | 91 void MakeIds(GLES2Implementation* gl_impl, |
90 GLuint /* id_offset */, | 92 GLuint /* id_offset */, |
91 GLsizei n, | 93 GLsizei n, |
92 GLuint* ids) override { | 94 GLuint* ids) override { |
93 base::AutoLock auto_lock(lock_); | 95 base::AutoLock auto_lock(lock_); |
94 | 96 |
95 // Collect pending FreeIds from other flush_generation. | 97 // Collect pending FreeIds from other flush_generation. |
96 CollectPendingFreeIds(gl_impl); | 98 CollectPendingFreeIds(gl_impl); |
97 | 99 |
98 for (GLsizei ii = 0; ii < n; ++ii) { | 100 for (GLsizei ii = 0; ii < n; ++ii) { |
99 if (!free_ids_.empty()) { | 101 if (!free_ids_.empty()) { |
100 // Allocate a previously freed Id. | 102 // Allocate a previously freed Id. |
101 ids[ii] = free_ids_.top(); | 103 ids[ii] = free_ids_.top(); |
102 free_ids_.pop(); | 104 free_ids_.pop(); |
103 | 105 |
104 // Record kIdInUse state. | 106 // Record kIdInUse state. |
105 DCHECK(id_states_[ids[ii] - 1] == kIdFree); | 107 DCHECK(id_states_[ids[ii] - 1] == kIdFree); |
106 id_states_[ids[ii] - 1] = kIdInUse; | 108 id_states_[ids[ii] - 1] = kIdInUse; |
107 } else { | 109 } else { |
108 // Allocate a new Id. | 110 // Allocate a new Id. |
109 id_states_.push_back(kIdInUse); | 111 id_states_.push_back(kIdInUse); |
110 ids[ii] = id_states_.size(); | 112 ids[ii] = id_states_.size(); |
111 } | 113 } |
112 } | 114 } |
113 } | 115 } |
114 | 116 |
115 // Overridden from IdHandler. | 117 // Overridden from IdHandler. |
116 virtual bool FreeIds(GLES2Implementation* gl_impl, | 118 bool FreeIds(GLES2Implementation* gl_impl, |
117 GLsizei n, | 119 GLsizei n, |
118 const GLuint* ids, | 120 const GLuint* ids, |
119 DeleteFn delete_fn) override { | 121 DeleteFn delete_fn) override { |
120 | |
121 // Delete stub must run before CollectPendingFreeIds. | 122 // Delete stub must run before CollectPendingFreeIds. |
122 (gl_impl->*delete_fn)(n, ids); | 123 (gl_impl->*delete_fn)(n, ids); |
123 | 124 |
124 { | 125 { |
125 base::AutoLock auto_lock(lock_); | 126 base::AutoLock auto_lock(lock_); |
126 | 127 |
127 // Collect pending FreeIds from other flush_generation. | 128 // Collect pending FreeIds from other flush_generation. |
128 CollectPendingFreeIds(gl_impl); | 129 CollectPendingFreeIds(gl_impl); |
129 | 130 |
130 // Save Ids to free in a later flush_generation. | 131 // Save Ids to free in a later flush_generation. |
131 ShareGroupContextData::IdHandlerData* ctxt_data = | 132 ShareGroupContextData::IdHandlerData* ctxt_data = |
132 gl_impl->share_group_context_data()->id_handler_data(id_namespace_); | 133 gl_impl->share_group_context_data()->id_handler_data(id_namespace_); |
133 | 134 |
134 for (GLsizei ii = 0; ii < n; ++ii) { | 135 for (GLsizei ii = 0; ii < n; ++ii) { |
135 GLuint id = ids[ii]; | 136 GLuint id = ids[ii]; |
136 if (id != 0) { | 137 if (id != 0) { |
137 // Save freed Id for later. | 138 // Save freed Id for later. |
138 DCHECK(id_states_[id - 1] == kIdInUse); | 139 DCHECK(id_states_[id - 1] == kIdInUse); |
139 id_states_[id - 1] = kIdPendingFree; | 140 id_states_[id - 1] = kIdPendingFree; |
140 ctxt_data->freed_ids_.push_back(id); | 141 ctxt_data->freed_ids_.push_back(id); |
141 } | 142 } |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 return true; | 146 return true; |
146 } | 147 } |
147 | 148 |
148 // Overridden from IdHandler. | 149 // Overridden from IdHandler. |
149 virtual bool MarkAsUsedForBind(GLuint id) override { | 150 bool MarkAsUsedForBind(GLuint id) override { |
150 #ifndef NDEBUG | 151 #ifndef NDEBUG |
151 if (id != 0) { | 152 if (id != 0) { |
152 base::AutoLock auto_lock(lock_); | 153 base::AutoLock auto_lock(lock_); |
153 DCHECK(id_states_[id - 1] == kIdInUse); | 154 DCHECK(id_states_[id - 1] == kIdInUse); |
154 } | 155 } |
155 #endif | 156 #endif |
156 return true; | 157 return true; |
157 } | 158 } |
158 | 159 |
159 // Overridden from IdHandlerInterface. | 160 // Overridden from IdHandlerInterface. |
160 virtual void FreeContext(GLES2Implementation* gl_impl) override { | 161 void FreeContext(GLES2Implementation* gl_impl) override { |
161 base::AutoLock auto_lock(lock_); | 162 base::AutoLock auto_lock(lock_); |
162 CollectPendingFreeIds(gl_impl); | 163 CollectPendingFreeIds(gl_impl); |
163 } | 164 } |
164 | 165 |
165 private: | 166 private: |
166 enum IdState { kIdFree, kIdPendingFree, kIdInUse }; | 167 enum IdState { kIdFree, kIdPendingFree, kIdInUse }; |
167 | 168 |
168 void CollectPendingFreeIds(GLES2Implementation* gl_impl) { | 169 void CollectPendingFreeIds(GLES2Implementation* gl_impl) { |
169 uint32 flush_generation = gl_impl->helper()->flush_generation(); | 170 uint32 flush_generation = gl_impl->helper()->flush_generation(); |
170 ShareGroupContextData::IdHandlerData* ctxt_data = | 171 ShareGroupContextData::IdHandlerData* ctxt_data = |
(...skipping 15 matching lines...) Expand all Loading... |
186 | 187 |
187 base::Lock lock_; | 188 base::Lock lock_; |
188 std::vector<uint8> id_states_; | 189 std::vector<uint8> id_states_; |
189 std::stack<uint32> free_ids_; | 190 std::stack<uint32> free_ids_; |
190 }; | 191 }; |
191 | 192 |
192 // An id handler for ids that are never reused. | 193 // An id handler for ids that are never reused. |
193 class NonReusedIdHandler : public IdHandlerInterface { | 194 class NonReusedIdHandler : public IdHandlerInterface { |
194 public: | 195 public: |
195 NonReusedIdHandler() : last_id_(0) {} | 196 NonReusedIdHandler() : last_id_(0) {} |
196 virtual ~NonReusedIdHandler() {} | 197 ~NonReusedIdHandler() override {} |
197 | 198 |
198 // Overridden from IdHandlerInterface. | 199 // Overridden from IdHandlerInterface. |
199 virtual void MakeIds( | 200 void MakeIds(GLES2Implementation* /* gl_impl */, |
200 GLES2Implementation* /* gl_impl */, | 201 GLuint id_offset, |
201 GLuint id_offset, GLsizei n, GLuint* ids) override { | 202 GLsizei n, |
| 203 GLuint* ids) override { |
202 base::AutoLock auto_lock(lock_); | 204 base::AutoLock auto_lock(lock_); |
203 for (GLsizei ii = 0; ii < n; ++ii) { | 205 for (GLsizei ii = 0; ii < n; ++ii) { |
204 ids[ii] = ++last_id_ + id_offset; | 206 ids[ii] = ++last_id_ + id_offset; |
205 } | 207 } |
206 } | 208 } |
207 | 209 |
208 // Overridden from IdHandlerInterface. | 210 // Overridden from IdHandlerInterface. |
209 virtual bool FreeIds( | 211 bool FreeIds(GLES2Implementation* gl_impl, |
210 GLES2Implementation* gl_impl, | 212 GLsizei n, |
211 GLsizei n, const GLuint* ids, DeleteFn delete_fn) override { | 213 const GLuint* ids, |
| 214 DeleteFn delete_fn) override { |
212 // Ids are never freed. | 215 // Ids are never freed. |
213 (gl_impl->*delete_fn)(n, ids); | 216 (gl_impl->*delete_fn)(n, ids); |
214 return true; | 217 return true; |
215 } | 218 } |
216 | 219 |
217 // Overridden from IdHandlerInterface. | 220 // Overridden from IdHandlerInterface. |
218 virtual bool MarkAsUsedForBind(GLuint /* id */) override { | 221 bool MarkAsUsedForBind(GLuint /* id */) override { |
219 // This is only used for Shaders and Programs which have no bind. | 222 // This is only used for Shaders and Programs which have no bind. |
220 return false; | 223 return false; |
221 } | 224 } |
222 | 225 |
223 virtual void FreeContext(GLES2Implementation* gl_impl) override {} | 226 void FreeContext(GLES2Implementation* gl_impl) override {} |
224 | 227 |
225 private: | 228 private: |
226 base::Lock lock_; | 229 base::Lock lock_; |
227 GLuint last_id_; | 230 GLuint last_id_; |
228 }; | 231 }; |
229 | 232 |
230 ShareGroup::ShareGroup(bool bind_generates_resource) | 233 ShareGroup::ShareGroup(bool bind_generates_resource) |
231 : bind_generates_resource_(bind_generates_resource) { | 234 : bind_generates_resource_(bind_generates_resource) { |
232 if (bind_generates_resource) { | 235 if (bind_generates_resource) { |
233 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { | 236 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
250 } | 253 } |
251 | 254 |
252 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { | 255 void ShareGroup::set_program_info_manager(ProgramInfoManager* manager) { |
253 program_info_manager_.reset(manager); | 256 program_info_manager_.reset(manager); |
254 } | 257 } |
255 | 258 |
256 ShareGroup::~ShareGroup() {} | 259 ShareGroup::~ShareGroup() {} |
257 | 260 |
258 } // namespace gles2 | 261 } // namespace gles2 |
259 } // namespace gpu | 262 } // namespace gpu |
OLD | NEW |