Chromium Code Reviews| 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 friend class ScopedFrameBufferReadPixelHelper; | 722 friend class ScopedFrameBufferReadPixelHelper; |
| 723 friend class ScopedResolvedFrameBufferBinder; | 723 friend class ScopedResolvedFrameBufferBinder; |
| 724 friend class BackFramebuffer; | 724 friend class BackFramebuffer; |
| 725 | 725 |
| 726 enum FramebufferOperation { | 726 enum FramebufferOperation { |
| 727 kFramebufferDiscard, | 727 kFramebufferDiscard, |
| 728 kFramebufferInvalidate, | 728 kFramebufferInvalidate, |
| 729 kFramebufferInvalidateSub | 729 kFramebufferInvalidateSub |
| 730 }; | 730 }; |
| 731 | 731 |
| 732 enum BindIndexedBufferFunctionType { | |
| 733 kBindBufferBase, | |
| 734 kBindBufferRange | |
| 735 }; | |
| 736 | |
| 732 // Initialize or re-initialize the shader translator. | 737 // Initialize or re-initialize the shader translator. |
| 733 bool InitializeShaderTranslator(); | 738 bool InitializeShaderTranslator(); |
| 734 | 739 |
| 735 void UpdateCapabilities(); | 740 void UpdateCapabilities(); |
| 736 | 741 |
| 737 // Helpers for the glGen and glDelete functions. | 742 // Helpers for the glGen and glDelete functions. |
| 738 bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); | 743 bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 739 void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); | 744 void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 740 bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); | 745 bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 741 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); | 746 void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1391 // Wrapper for glBindBuffer since we need to track the current targets. | 1396 // Wrapper for glBindBuffer since we need to track the current targets. |
| 1392 void DoBindBuffer(GLenum target, GLuint buffer); | 1397 void DoBindBuffer(GLenum target, GLuint buffer); |
| 1393 | 1398 |
| 1394 // Wrapper for glBindBufferBase since we need to track the current targets. | 1399 // Wrapper for glBindBufferBase since we need to track the current targets. |
| 1395 void DoBindBufferBase(GLenum target, GLuint index, GLuint buffer); | 1400 void DoBindBufferBase(GLenum target, GLuint index, GLuint buffer); |
| 1396 | 1401 |
| 1397 // Wrapper for glBindBufferRange since we need to track the current targets. | 1402 // Wrapper for glBindBufferRange since we need to track the current targets. |
| 1398 void DoBindBufferRange(GLenum target, GLuint index, GLuint buffer, | 1403 void DoBindBufferRange(GLenum target, GLuint index, GLuint buffer, |
| 1399 GLintptr offset, GLsizeiptr size); | 1404 GLintptr offset, GLsizeiptr size); |
| 1400 | 1405 |
| 1406 // Helper for DoBindBufferBase and DoBindBufferRange. | |
| 1407 void BindIndexedBufferImpl(GLenum target, GLuint index, GLuint buffer, | |
| 1408 GLintptr offset, GLsizeiptr size, | |
| 1409 BindIndexedBufferFunctionType function_type, | |
| 1410 const char* function_name); | |
| 1411 | |
| 1401 // Wrapper for glBindFramebuffer since we need to track the current targets. | 1412 // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1402 void DoBindFramebuffer(GLenum target, GLuint framebuffer); | 1413 void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1403 | 1414 |
| 1404 // Wrapper for glBindRenderbuffer since we need to track the current targets. | 1415 // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1405 void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); | 1416 void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1406 | 1417 |
| 1407 // Wrapper for glBindTexture since we need to track the current targets. | 1418 // Wrapper for glBindTexture since we need to track the current targets. |
| 1408 void DoBindTexture(GLenum target, GLuint texture); | 1419 void DoBindTexture(GLenum target, GLuint texture); |
| 1409 | 1420 |
| 1410 // Wrapper for glBindSampler since we need to track the current targets. | 1421 // Wrapper for glBindSampler since we need to track the current targets. |
| (...skipping 3234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4645 GL_INVALID_OPERATION, | 4656 GL_INVALID_OPERATION, |
| 4646 "glBindBuffer", "buffer bound to more than 1 target"); | 4657 "glBindBuffer", "buffer bound to more than 1 target"); |
| 4647 return; | 4658 return; |
| 4648 } | 4659 } |
| 4649 service_id = buffer->service_id(); | 4660 service_id = buffer->service_id(); |
| 4650 } | 4661 } |
| 4651 state_.SetBoundBuffer(target, buffer); | 4662 state_.SetBoundBuffer(target, buffer); |
| 4652 glBindBuffer(target, service_id); | 4663 glBindBuffer(target, service_id); |
| 4653 } | 4664 } |
| 4654 | 4665 |
| 4655 void GLES2DecoderImpl::DoBindBufferBase(GLenum target, GLuint index, | 4666 void GLES2DecoderImpl::BindIndexedBufferImpl( |
| 4656 GLuint client_id) { | 4667 GLenum target, GLuint index, GLuint client_id, |
| 4657 Buffer* buffer = NULL; | 4668 GLintptr offset, GLsizeiptr size, |
| 4669 BindIndexedBufferFunctionType function_type, const char* function_name) { | |
| 4670 switch (target) { | |
| 4671 case GL_TRANSFORM_FEEDBACK_BUFFER: { | |
| 4672 if (index >= group_->max_transform_feedback_separate_attribs()) { | |
| 4673 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 4674 "index out of range"); | |
| 4675 return; | |
| 4676 } | |
| 4677 // TODO(zmo): Check transform feedback isn't currently active. | |
| 4678 break; | |
| 4679 } | |
| 4680 case GL_UNIFORM_BUFFER: { | |
| 4681 if (index >= group_->max_uniform_buffer_bindings()) { | |
| 4682 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 4683 "index out of range"); | |
| 4684 return; | |
| 4685 } | |
| 4686 break; | |
| 4687 } | |
| 4688 default: | |
| 4689 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "invalid target"); | |
| 4690 return; | |
| 4691 } | |
| 4692 | |
| 4693 if (function_type == kBindBufferRange) { | |
| 4694 switch (target) { | |
| 4695 case GL_TRANSFORM_FEEDBACK_BUFFER: | |
| 4696 if ((size % 4 != 0) || (offset % 4 != 0)) { | |
| 4697 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 4698 "size or offset are not multiples of 4"); | |
| 4699 return; | |
| 4700 } | |
| 4701 break; | |
| 4702 case GL_UNIFORM_BUFFER: { | |
| 4703 if (offset % group_->uniform_buffer_offset_alignment() != 0) { | |
| 4704 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, | |
| 4705 "offset is not a multiple of UNIFORM_BUFFER_OFFSET_ALIGNMENT"); | |
| 4706 return; | |
| 4707 } | |
| 4708 break; | |
| 4709 } | |
| 4710 default: | |
| 4711 NOTREACHED(); | |
| 4712 break; | |
| 4713 } | |
| 4714 | |
| 4715 if (client_id != 0) { | |
| 4716 if (size <= 0) { | |
| 4717 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "size <= 0"); | |
| 4718 return; | |
| 4719 } | |
| 4720 if (offset < 0) { | |
| 4721 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); | |
| 4722 return; | |
| 4723 } | |
| 4724 } | |
| 4725 } | |
| 4726 | |
| 4727 Buffer* buffer = nullptr; | |
| 4658 GLuint service_id = 0; | 4728 GLuint service_id = 0; |
| 4659 if (client_id != 0) { | 4729 if (client_id != 0) { |
| 4660 buffer = GetBuffer(client_id); | 4730 buffer = GetBuffer(client_id); |
| 4661 if (!buffer) { | 4731 if (!buffer) { |
| 4662 if (!group_->bind_generates_resource()) { | 4732 if (!group_->bind_generates_resource()) { |
| 4663 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | 4733 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 4664 "glBindBufferBase", | |
| 4665 "id not generated by glGenBuffers"); | 4734 "id not generated by glGenBuffers"); |
| 4666 return; | 4735 return; |
| 4667 } | 4736 } |
| 4668 | |
| 4669 // It's a new id so make a buffer for it. | |
| 4670 glGenBuffersARB(1, &service_id); | |
| 4671 CreateBuffer(client_id, service_id); | |
| 4672 buffer = GetBuffer(client_id); | |
| 4673 } | |
| 4674 } | |
| 4675 LogClientServiceForInfo(buffer, client_id, "glBindBufferBase"); | |
| 4676 if (buffer) { | |
| 4677 // TODO(kbr): track indexed bound buffers. | |
| 4678 service_id = buffer->service_id(); | |
| 4679 } | |
| 4680 switch (target) { | |
| 4681 case GL_TRANSFORM_FEEDBACK_BUFFER: { | |
| 4682 GLint max_transform_feedback_separate_attribs = 0; | |
| 4683 DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, | |
| 4684 &max_transform_feedback_separate_attribs); | |
| 4685 if (index >= | |
| 4686 static_cast<GLuint>(max_transform_feedback_separate_attribs)) { | |
| 4687 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | |
| 4688 "glBindBufferBase", "index out of range"); | |
| 4689 return; | |
| 4690 } | |
| 4691 break; | |
| 4692 } | |
| 4693 case GL_UNIFORM_BUFFER: { | |
| 4694 GLint max_uniform_buffer_bindings = 0; | |
| 4695 DoGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, | |
| 4696 &max_uniform_buffer_bindings); | |
| 4697 if (index >= static_cast<GLuint>(max_uniform_buffer_bindings)) { | |
| 4698 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, | |
| 4699 "glBindBufferBase", "index out of range"); | |
| 4700 return; | |
| 4701 } | |
| 4702 break; | |
| 4703 } | |
| 4704 default: | |
| 4705 LOCAL_SET_GL_ERROR_INVALID_ENUM( | |
| 4706 "glBindBufferBase", target, "invalid target"); | |
| 4707 return; | |
| 4708 } | |
| 4709 state_.SetBoundBuffer(target, buffer); | |
| 4710 glBindBufferBase(target, index, service_id); | |
| 4711 } | |
| 4712 | |
| 4713 void GLES2DecoderImpl::DoBindBufferRange(GLenum target, GLuint index, | |
| 4714 GLuint client_id, | |
| 4715 GLintptr offset, | |
| 4716 GLsizeiptr size) { | |
| 4717 Buffer* buffer = NULL; | |
| 4718 GLuint service_id = 0; | |
| 4719 if (client_id != 0) { | |
| 4720 buffer = GetBuffer(client_id); | |
| 4721 if (!buffer) { | |
| 4722 if (!group_->bind_generates_resource()) { | |
| 4723 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, | |
| 4724 "glBindBufferRange", | |
| 4725 "id not generated by glGenBuffers"); | |
| 4726 return; | |
| 4727 } | |
| 4728 | 4737 |
| 4729 // It's a new id so make a buffer for it. | 4738 // It's a new id so make a buffer for it. |
| 4730 glGenBuffersARB(1, &service_id); | 4739 glGenBuffersARB(1, &service_id); |
| 4731 CreateBuffer(client_id, service_id); | 4740 CreateBuffer(client_id, service_id); |
| 4732 buffer = GetBuffer(client_id); | 4741 buffer = GetBuffer(client_id); |
| 4742 DCHECK(buffer); | |
| 4733 } | 4743 } |
| 4734 } | |
| 4735 LogClientServiceForInfo(buffer, client_id, "glBindBufferRange"); | |
| 4736 if (buffer) { | |
| 4737 // TODO(kbr): track indexed bound buffers. | |
| 4738 service_id = buffer->service_id(); | 4744 service_id = buffer->service_id(); |
| 4739 } | 4745 } |
| 4740 glBindBufferRange(target, index, service_id, offset, size); | 4746 LogClientServiceForInfo(buffer, client_id, function_name); |
| 4747 | |
| 4748 switch (function_type) { | |
| 4749 case kBindBufferBase: | |
| 4750 glBindBufferBase(target, index, service_id); | |
| 4751 break; | |
| 4752 case kBindBufferRange: | |
| 4753 // On Desktop GL 4.1 or lower, clamp the offset/size not to exceed the | |
|
piman
2016/04/20 21:14:35
nit: is that a TODO? Mark it so (this reads as if
Zhenyao Mo
2016/04/20 22:08:50
Done.
| |
| 4754 // size of the buffer. crbug.com/604436. | |
| 4755 glBindBufferRange(target, index, service_id, offset, size); | |
| 4756 break; | |
| 4757 } | |
| 4758 // TODO(kbr): track indexed bound buffers. | |
| 4759 } | |
| 4760 | |
| 4761 void GLES2DecoderImpl::DoBindBufferBase(GLenum target, GLuint index, | |
| 4762 GLuint client_id) { | |
| 4763 BindIndexedBufferImpl(target, index, client_id, 0, 0, | |
| 4764 kBindBufferBase, "glBindBufferBase"); | |
| 4765 } | |
| 4766 | |
| 4767 void GLES2DecoderImpl::DoBindBufferRange(GLenum target, GLuint index, | |
| 4768 GLuint client_id, | |
| 4769 GLintptr offset, | |
| 4770 GLsizeiptr size) { | |
| 4771 BindIndexedBufferImpl(target, index, client_id, offset, size, | |
| 4772 kBindBufferRange, "glBindBufferRange"); | |
| 4741 } | 4773 } |
| 4742 | 4774 |
| 4743 bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { | 4775 bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { |
| 4744 Framebuffer* framebuffer = | 4776 Framebuffer* framebuffer = |
| 4745 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); | 4777 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 4746 if (framebuffer) | 4778 if (framebuffer) |
| 4747 return framebuffer->HasAlphaMRT(); | 4779 return framebuffer->HasAlphaMRT(); |
| 4748 return BackBufferHasAlpha(); | 4780 return BackBufferHasAlpha(); |
| 4749 } | 4781 } |
| 4750 | 4782 |
| (...skipping 11761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16512 } | 16544 } |
| 16513 | 16545 |
| 16514 // Include the auto-generated part of this file. We split this because it means | 16546 // Include the auto-generated part of this file. We split this because it means |
| 16515 // we can easily edit the non-auto generated parts right here in this file | 16547 // we can easily edit the non-auto generated parts right here in this file |
| 16516 // instead of having to edit some template or the code generator. | 16548 // instead of having to edit some template or the code generator. |
| 16517 #include "base/macros.h" | 16549 #include "base/macros.h" |
| 16518 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 16550 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 16519 | 16551 |
| 16520 } // namespace gles2 | 16552 } // namespace gles2 |
| 16521 } // namespace gpu | 16553 } // namespace gpu |
| OLD | NEW |