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 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2.h> | 9 #include <GLES2/gl2.h> |
10 #include <GLES2/gl2ext.h> | 10 #include <GLES2/gl2ext.h> |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 util_.set_num_compressed_texture_formats( | 238 util_.set_num_compressed_texture_formats( |
239 capabilities_.num_compressed_texture_formats); | 239 capabilities_.num_compressed_texture_formats); |
240 util_.set_num_shader_binary_formats(capabilities_.num_shader_binary_formats); | 240 util_.set_num_shader_binary_formats(capabilities_.num_shader_binary_formats); |
241 | 241 |
242 texture_units_.reset( | 242 texture_units_.reset( |
243 new TextureUnit[capabilities_.max_combined_texture_image_units]); | 243 new TextureUnit[capabilities_.max_combined_texture_image_units]); |
244 | 244 |
245 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); | 245 query_tracker_.reset(new QueryTracker(mapped_memory_.get())); |
246 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); | 246 buffer_tracker_.reset(new BufferTracker(mapped_memory_.get())); |
247 | 247 |
248 query_id_allocator_.reset(new IdAllocator()); | 248 for (int i = 0; i < id_namespaces::kNumIdNamespaces; ++i) |
249 id_allocators_[i].reset(new IdAllocator()); | |
Zhenyao Mo
2017/04/19 20:24:28
Some of these allocators are never used. Why?
Chandan
2017/04/20 10:56:07
As of now, 3 allocators are created, one each for
| |
250 | |
249 if (support_client_side_arrays_) { | 251 if (support_client_side_arrays_) { |
250 GetIdHandler(id_namespaces::kBuffers)->MakeIds( | 252 GetIdHandler(id_namespaces::kBuffers)->MakeIds( |
251 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); | 253 this, kClientSideArrayId, arraysize(reserved_ids_), &reserved_ids_[0]); |
252 } | 254 } |
253 | 255 |
254 vertex_array_object_manager_.reset(new VertexArrayObjectManager( | 256 vertex_array_object_manager_.reset(new VertexArrayObjectManager( |
255 capabilities_.max_vertex_attribs, reserved_ids_[0], reserved_ids_[1], | 257 capabilities_.max_vertex_attribs, reserved_ids_[0], reserved_ids_[1], |
256 support_client_side_arrays_)); | 258 support_client_side_arrays_)); |
257 | 259 |
258 // GL_BIND_GENERATES_RESOURCE_CHROMIUM state must be the same | 260 // GL_BIND_GENERATES_RESOURCE_CHROMIUM state must be the same |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { | 308 IdHandlerInterface* GLES2Implementation::GetIdHandler(int namespace_id) const { |
307 return share_group_->GetIdHandler(namespace_id); | 309 return share_group_->GetIdHandler(namespace_id); |
308 } | 310 } |
309 | 311 |
310 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( | 312 RangeIdHandlerInterface* GLES2Implementation::GetRangeIdHandler( |
311 int namespace_id) const { | 313 int namespace_id) const { |
312 return share_group_->GetRangeIdHandler(namespace_id); | 314 return share_group_->GetRangeIdHandler(namespace_id); |
313 } | 315 } |
314 | 316 |
315 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { | 317 IdAllocator* GLES2Implementation::GetIdAllocator(int namespace_id) const { |
316 if (namespace_id == id_namespaces::kQueries) | 318 return id_allocators_[namespace_id].get(); |
317 return query_id_allocator_.get(); | |
318 NOTREACHED(); | |
319 return NULL; | |
320 } | 319 } |
321 | 320 |
322 void GLES2Implementation::OnGpuControlLostContext() { | 321 void GLES2Implementation::OnGpuControlLostContext() { |
323 // This should never occur more than once. | 322 // This should never occur more than once. |
324 DCHECK(!lost_context_callback_run_); | 323 DCHECK(!lost_context_callback_run_); |
325 lost_context_callback_run_ = true; | 324 lost_context_callback_run_ = true; |
326 share_group_->Lose(); | 325 share_group_->Lose(); |
327 if (!lost_context_callback_.is_null()) | 326 if (!lost_context_callback_.is_null()) |
328 lost_context_callback_.Run(); | 327 lost_context_callback_.Run(); |
329 } | 328 } |
(...skipping 4061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4391 bound_framebuffer_ = framebuffer; | 4390 bound_framebuffer_ = framebuffer; |
4392 changed = true; | 4391 changed = true; |
4393 } | 4392 } |
4394 break; | 4393 break; |
4395 default: | 4394 default: |
4396 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); | 4395 SetGLErrorInvalidEnum("glBindFramebuffer", target, "target"); |
4397 return; | 4396 return; |
4398 } | 4397 } |
4399 | 4398 |
4400 if (changed) { | 4399 if (changed) { |
4401 GetIdHandler(id_namespaces::kFramebuffers)->MarkAsUsedForBind( | 4400 if (framebuffer != 0) |
4402 this, target, framebuffer, &GLES2Implementation::BindFramebufferStub); | 4401 GetIdAllocator(id_namespaces::kFramebuffers)->MarkAsUsed(framebuffer); |
4402 helper_->BindFramebuffer(target, framebuffer); | |
4403 if (share_group_->bind_generates_resource()) | |
4404 helper_->CommandBufferHelper::OrderingBarrier(); | |
4403 } | 4405 } |
4404 } | 4406 } |
4405 | 4407 |
4406 void GLES2Implementation::BindFramebufferStub(GLenum target, | |
4407 GLuint framebuffer) { | |
4408 helper_->BindFramebuffer(target, framebuffer); | |
4409 if (share_group_->bind_generates_resource()) | |
4410 helper_->CommandBufferHelper::OrderingBarrier(); | |
4411 } | |
4412 | |
4413 void GLES2Implementation::BindRenderbufferHelper( | 4408 void GLES2Implementation::BindRenderbufferHelper( |
4414 GLenum target, GLuint renderbuffer) { | 4409 GLenum target, GLuint renderbuffer) { |
4415 // TODO(gman): See note #1 above. | 4410 // TODO(gman): See note #1 above. |
4416 bool changed = false; | 4411 bool changed = false; |
4417 switch (target) { | 4412 switch (target) { |
4418 case GL_RENDERBUFFER: | 4413 case GL_RENDERBUFFER: |
4419 if (bound_renderbuffer_ != renderbuffer) { | 4414 if (bound_renderbuffer_ != renderbuffer) { |
4420 bound_renderbuffer_ = renderbuffer; | 4415 bound_renderbuffer_ = renderbuffer; |
4421 changed = true; | 4416 changed = true; |
4422 } | 4417 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4566 } | 4561 } |
4567 | 4562 |
4568 void GLES2Implementation::DeleteBuffersStub( | 4563 void GLES2Implementation::DeleteBuffersStub( |
4569 GLsizei n, const GLuint* buffers) { | 4564 GLsizei n, const GLuint* buffers) { |
4570 helper_->DeleteBuffersImmediate(n, buffers); | 4565 helper_->DeleteBuffersImmediate(n, buffers); |
4571 } | 4566 } |
4572 | 4567 |
4573 | 4568 |
4574 void GLES2Implementation::DeleteFramebuffersHelper( | 4569 void GLES2Implementation::DeleteFramebuffersHelper( |
4575 GLsizei n, const GLuint* framebuffers) { | 4570 GLsizei n, const GLuint* framebuffers) { |
4576 if (!GetIdHandler(id_namespaces::kFramebuffers)->FreeIds( | 4571 helper_->DeleteFramebuffersImmediate(n, framebuffers); |
4577 this, n, framebuffers, &GLES2Implementation::DeleteFramebuffersStub)) { | 4572 IdAllocator* id_allocator = GetIdAllocator(id_namespaces::kFramebuffers); |
4578 SetGLError( | |
4579 GL_INVALID_VALUE, | |
4580 "glDeleteFramebuffers", "id not created by this context."); | |
4581 return; | |
4582 } | |
4583 for (GLsizei ii = 0; ii < n; ++ii) { | 4573 for (GLsizei ii = 0; ii < n; ++ii) { |
4574 id_allocator->FreeID(framebuffers[ii]); | |
4584 if (framebuffers[ii] == bound_framebuffer_) { | 4575 if (framebuffers[ii] == bound_framebuffer_) { |
4585 bound_framebuffer_ = 0; | 4576 bound_framebuffer_ = 0; |
4586 } | 4577 } |
4587 if (framebuffers[ii] == bound_read_framebuffer_) { | 4578 if (framebuffers[ii] == bound_read_framebuffer_) { |
4588 bound_read_framebuffer_ = 0; | 4579 bound_read_framebuffer_ = 0; |
4589 } | 4580 } |
4590 } | 4581 } |
4591 } | 4582 } |
4592 | 4583 |
4593 void GLES2Implementation::DeleteFramebuffersStub( | |
4594 GLsizei n, const GLuint* framebuffers) { | |
4595 helper_->DeleteFramebuffersImmediate(n, framebuffers); | |
4596 } | |
4597 | |
4598 void GLES2Implementation::DeleteRenderbuffersHelper( | 4584 void GLES2Implementation::DeleteRenderbuffersHelper( |
4599 GLsizei n, const GLuint* renderbuffers) { | 4585 GLsizei n, const GLuint* renderbuffers) { |
4600 if (!GetIdHandler(id_namespaces::kRenderbuffers)->FreeIds( | 4586 if (!GetIdHandler(id_namespaces::kRenderbuffers)->FreeIds( |
4601 this, n, renderbuffers, &GLES2Implementation::DeleteRenderbuffersStub)) { | 4587 this, n, renderbuffers, &GLES2Implementation::DeleteRenderbuffersStub)) { |
4602 SetGLError( | 4588 SetGLError( |
4603 GL_INVALID_VALUE, | 4589 GL_INVALID_VALUE, |
4604 "glDeleteRenderbuffers", "id not created by this context."); | 4590 "glDeleteRenderbuffers", "id not created by this context."); |
4605 return; | 4591 return; |
4606 } | 4592 } |
4607 for (GLsizei ii = 0; ii < n; ++ii) { | 4593 for (GLsizei ii = 0; ii < n; ++ii) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4643 } | 4629 } |
4644 | 4630 |
4645 void GLES2Implementation::DeleteTexturesStub(GLsizei n, | 4631 void GLES2Implementation::DeleteTexturesStub(GLsizei n, |
4646 const GLuint* textures) { | 4632 const GLuint* textures) { |
4647 helper_->DeleteTexturesImmediate(n, textures); | 4633 helper_->DeleteTexturesImmediate(n, textures); |
4648 } | 4634 } |
4649 | 4635 |
4650 void GLES2Implementation::DeleteVertexArraysOESHelper( | 4636 void GLES2Implementation::DeleteVertexArraysOESHelper( |
4651 GLsizei n, const GLuint* arrays) { | 4637 GLsizei n, const GLuint* arrays) { |
4652 vertex_array_object_manager_->DeleteVertexArrays(n, arrays); | 4638 vertex_array_object_manager_->DeleteVertexArrays(n, arrays); |
4653 if (!GetIdHandler(id_namespaces::kVertexArrays)->FreeIds( | |
4654 this, n, arrays, &GLES2Implementation::DeleteVertexArraysOESStub)) { | |
4655 SetGLError( | |
4656 GL_INVALID_VALUE, | |
4657 "glDeleteVertexArraysOES", "id not created by this context."); | |
4658 return; | |
4659 } | |
4660 } | |
4661 | |
4662 void GLES2Implementation::DeleteVertexArraysOESStub( | |
4663 GLsizei n, const GLuint* arrays) { | |
4664 helper_->DeleteVertexArraysOESImmediate(n, arrays); | 4639 helper_->DeleteVertexArraysOESImmediate(n, arrays); |
4640 IdAllocator* id_allocator = GetIdAllocator(id_namespaces::kVertexArrays); | |
4641 for (GLsizei ii = 0; ii < n; ++ii) | |
4642 id_allocator->FreeID(arrays[ii]); | |
4665 } | 4643 } |
4666 | 4644 |
4667 void GLES2Implementation::DeleteSamplersStub( | 4645 void GLES2Implementation::DeleteSamplersStub( |
4668 GLsizei n, const GLuint* samplers) { | 4646 GLsizei n, const GLuint* samplers) { |
4669 helper_->DeleteSamplersImmediate(n, samplers); | 4647 helper_->DeleteSamplersImmediate(n, samplers); |
4670 } | 4648 } |
4671 | 4649 |
4672 void GLES2Implementation::DeleteSamplersHelper( | 4650 void GLES2Implementation::DeleteSamplersHelper( |
4673 GLsizei n, const GLuint* samplers) { | 4651 GLsizei n, const GLuint* samplers) { |
4674 if (!GetIdHandler(id_namespaces::kSamplers)->FreeIds( | 4652 if (!GetIdHandler(id_namespaces::kSamplers)->FreeIds( |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5559 helper_->PostSubBufferCHROMIUM(x, y, width, height); | 5537 helper_->PostSubBufferCHROMIUM(x, y, width, height); |
5560 helper_->CommandBufferHelper::Flush(); | 5538 helper_->CommandBufferHelper::Flush(); |
5561 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { | 5539 if (swap_buffers_tokens_.size() > kMaxSwapBuffers + 1) { |
5562 helper_->WaitForToken(swap_buffers_tokens_.front()); | 5540 helper_->WaitForToken(swap_buffers_tokens_.front()); |
5563 swap_buffers_tokens_.pop(); | 5541 swap_buffers_tokens_.pop(); |
5564 } | 5542 } |
5565 } | 5543 } |
5566 | 5544 |
5567 void GLES2Implementation::DeleteQueriesEXTHelper( | 5545 void GLES2Implementation::DeleteQueriesEXTHelper( |
5568 GLsizei n, const GLuint* queries) { | 5546 GLsizei n, const GLuint* queries) { |
5547 IdAllocator* id_allocator = GetIdAllocator(id_namespaces::kQueries); | |
5569 for (GLsizei ii = 0; ii < n; ++ii) { | 5548 for (GLsizei ii = 0; ii < n; ++ii) { |
5570 query_tracker_->RemoveQuery(queries[ii]); | 5549 query_tracker_->RemoveQuery(queries[ii]); |
5571 query_id_allocator_->FreeID(queries[ii]); | 5550 id_allocator->FreeID(queries[ii]); |
5572 } | 5551 } |
5573 | 5552 |
5574 helper_->DeleteQueriesEXTImmediate(n, queries); | 5553 helper_->DeleteQueriesEXTImmediate(n, queries); |
5575 } | 5554 } |
5576 | 5555 |
5577 GLboolean GLES2Implementation::IsQueryEXT(GLuint id) { | 5556 GLboolean GLES2Implementation::IsQueryEXT(GLuint id) { |
5578 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 5557 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
5579 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] IsQueryEXT(" << id << ")"); | 5558 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] IsQueryEXT(" << id << ")"); |
5580 | 5559 |
5581 // TODO(gman): To be spec compliant IDs from other contexts sharing | 5560 // TODO(gman): To be spec compliant IDs from other contexts sharing |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5644 SetGLError( | 5623 SetGLError( |
5645 GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); | 5624 GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
5646 return; | 5625 return; |
5647 } | 5626 } |
5648 | 5627 |
5649 if (id == 0) { | 5628 if (id == 0) { |
5650 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); | 5629 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
5651 return; | 5630 return; |
5652 } | 5631 } |
5653 | 5632 |
5654 if (!query_id_allocator_->InUse(id)) { | 5633 if (!GetIdAllocator(id_namespaces::kQueries)->InUse(id)) { |
5655 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "invalid id"); | 5634 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "invalid id"); |
5656 return; | 5635 return; |
5657 } | 5636 } |
5658 | 5637 |
5659 // Extra setups some targets might need. | 5638 // Extra setups some targets might need. |
5660 switch (target) { | 5639 switch (target) { |
5661 case GL_TIME_ELAPSED_EXT: | 5640 case GL_TIME_ELAPSED_EXT: |
5662 if (!query_tracker_->SetDisjointSync(this)) { | 5641 if (!query_tracker_->SetDisjointSync(this)) { |
5663 SetGLError(GL_OUT_OF_MEMORY, | 5642 SetGLError(GL_OUT_OF_MEMORY, |
5664 "glBeginQueryEXT", | 5643 "glBeginQueryEXT", |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5701 SetGLError( | 5680 SetGLError( |
5702 GL_INVALID_ENUM, "glQueryCounterEXT", "unknown query target"); | 5681 GL_INVALID_ENUM, "glQueryCounterEXT", "unknown query target"); |
5703 return; | 5682 return; |
5704 } | 5683 } |
5705 | 5684 |
5706 if (id == 0) { | 5685 if (id == 0) { |
5707 SetGLError(GL_INVALID_OPERATION, "glQueryCounterEXT", "id is 0"); | 5686 SetGLError(GL_INVALID_OPERATION, "glQueryCounterEXT", "id is 0"); |
5708 return; | 5687 return; |
5709 } | 5688 } |
5710 | 5689 |
5711 if (!query_id_allocator_->InUse(id)) { | 5690 if (!GetIdAllocator(id_namespaces::kQueries)->InUse(id)) { |
5712 SetGLError(GL_INVALID_OPERATION, "glQueryCounterEXT", "invalid id"); | 5691 SetGLError(GL_INVALID_OPERATION, "glQueryCounterEXT", "invalid id"); |
5713 return; | 5692 return; |
5714 } | 5693 } |
5715 | 5694 |
5716 // Extra setups some targets might need. | 5695 // Extra setups some targets might need. |
5717 switch (target) { | 5696 switch (target) { |
5718 case GL_TIMESTAMP_EXT: | 5697 case GL_TIMESTAMP_EXT: |
5719 if (!query_tracker_->SetDisjointSync(this)) { | 5698 if (!query_tracker_->SetDisjointSync(this)) { |
5720 SetGLError(GL_OUT_OF_MEMORY, | 5699 SetGLError(GL_OUT_OF_MEMORY, |
5721 "glQueryCounterEXT", | 5700 "glQueryCounterEXT", |
(...skipping 1350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7072 CheckGLError(); | 7051 CheckGLError(); |
7073 } | 7052 } |
7074 | 7053 |
7075 // Include the auto-generated part of this file. We split this because it means | 7054 // Include the auto-generated part of this file. We split this because it means |
7076 // we can easily edit the non-auto generated parts right here in this file | 7055 // we can easily edit the non-auto generated parts right here in this file |
7077 // instead of having to edit some template or the code generator. | 7056 // instead of having to edit some template or the code generator. |
7078 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 7057 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
7079 | 7058 |
7080 } // namespace gles2 | 7059 } // namespace gles2 |
7081 } // namespace gpu | 7060 } // namespace gpu |
OLD | NEW |