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 <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return gfx::OVERLAY_TRANSFORM_ROTATE_90; | 166 return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
167 case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: | 167 case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: |
168 return gfx::OVERLAY_TRANSFORM_ROTATE_180; | 168 return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
169 case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: | 169 case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: |
170 return gfx::OVERLAY_TRANSFORM_ROTATE_270; | 170 return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
171 default: | 171 default: |
172 return gfx::OVERLAY_TRANSFORM_INVALID; | 172 return gfx::OVERLAY_TRANSFORM_INVALID; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
| 176 struct Vec4f { |
| 177 Vec4f(Vec4 data) { |
| 178 for (int ii = 0; ii < 4; ++ii) { |
| 179 v[ii] = static_cast<float>(data.v[ii]); |
| 180 } |
| 181 } |
| 182 |
| 183 float v[4]; |
| 184 }; |
| 185 |
176 } // namespace | 186 } // namespace |
177 | 187 |
178 class GLES2DecoderImpl; | 188 class GLES2DecoderImpl; |
179 | 189 |
180 // Local versions of the SET_GL_ERROR macros | 190 // Local versions of the SET_GL_ERROR macros |
181 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ | 191 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
182 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) | 192 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) |
183 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ | 193 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
184 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ | 194 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ |
185 function_name, value, label) | 195 function_name, value, label) |
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 | 1475 |
1466 // Wrapper for glGetShaderiv | 1476 // Wrapper for glGetShaderiv |
1467 void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); | 1477 void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
1468 | 1478 |
1469 // Wrappers for glGetTexParameter. | 1479 // Wrappers for glGetTexParameter. |
1470 void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); | 1480 void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); |
1471 void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); | 1481 void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); |
1472 void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); | 1482 void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); |
1473 | 1483 |
1474 // Wrappers for glGetVertexAttrib. | 1484 // Wrappers for glGetVertexAttrib. |
1475 void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); | 1485 template <typename T> |
1476 void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); | 1486 void DoGetVertexAttribImpl(GLuint index, GLenum pname, T* params); |
| 1487 void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); |
| 1488 void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint* params); |
| 1489 void DoGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params); |
| 1490 void DoGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params); |
1477 | 1491 |
1478 // Wrappers for glIsXXX functions. | 1492 // Wrappers for glIsXXX functions. |
1479 bool DoIsEnabled(GLenum cap); | 1493 bool DoIsEnabled(GLenum cap); |
1480 bool DoIsBuffer(GLuint client_id); | 1494 bool DoIsBuffer(GLuint client_id); |
1481 bool DoIsFramebuffer(GLuint client_id); | 1495 bool DoIsFramebuffer(GLuint client_id); |
1482 bool DoIsProgram(GLuint client_id); | 1496 bool DoIsProgram(GLuint client_id); |
1483 bool DoIsRenderbuffer(GLuint client_id); | 1497 bool DoIsRenderbuffer(GLuint client_id); |
1484 bool DoIsShader(GLuint client_id); | 1498 bool DoIsShader(GLuint client_id); |
1485 bool DoIsTexture(GLuint client_id); | 1499 bool DoIsTexture(GLuint client_id); |
1486 bool DoIsVertexArrayOES(GLuint client_id); | 1500 bool DoIsVertexArrayOES(GLuint client_id); |
(...skipping 5358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6845 return true; | 6859 return true; |
6846 } | 6860 } |
6847 | 6861 |
6848 // Make a buffer with a single repeated vec4 value enough to | 6862 // Make a buffer with a single repeated vec4 value enough to |
6849 // simulate the constant value that is supposed to be here. | 6863 // simulate the constant value that is supposed to be here. |
6850 // This is required to emulate GLES2 on GL. | 6864 // This is required to emulate GLES2 on GL. |
6851 GLuint num_vertices = max_vertex_accessed + 1; | 6865 GLuint num_vertices = max_vertex_accessed + 1; |
6852 uint32 size_needed = 0; | 6866 uint32 size_needed = 0; |
6853 | 6867 |
6854 if (num_vertices == 0 || | 6868 if (num_vertices == 0 || |
6855 !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || | 6869 !SafeMultiplyUint32(num_vertices, sizeof(Vec4f), &size_needed) || |
6856 size_needed > 0x7FFFFFFFU) { | 6870 size_needed > 0x7FFFFFFFU) { |
6857 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); | 6871 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
6858 return false; | 6872 return false; |
6859 } | 6873 } |
6860 | 6874 |
6861 LOCAL_PERFORMANCE_WARNING( | 6875 LOCAL_PERFORMANCE_WARNING( |
6862 "Attribute 0 is disabled. This has signficant performance penalty"); | 6876 "Attribute 0 is disabled. This has signficant performance penalty"); |
6863 | 6877 |
6864 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); | 6878 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
6865 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); | 6879 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
6866 | 6880 |
6867 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; | 6881 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
6868 if (new_buffer) { | 6882 if (new_buffer) { |
6869 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); | 6883 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
6870 GLenum error = glGetError(); | 6884 GLenum error = glGetError(); |
6871 if (error != GL_NO_ERROR) { | 6885 if (error != GL_NO_ERROR) { |
6872 LOCAL_SET_GL_ERROR( | 6886 LOCAL_SET_GL_ERROR( |
6873 GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); | 6887 GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
6874 return false; | 6888 return false; |
6875 } | 6889 } |
6876 } | 6890 } |
6877 | 6891 |
6878 const Vec4& value = state_.attrib_values[0]; | 6892 const Vec4& value = state_.attrib_values[0]; |
6879 if (new_buffer || | 6893 if (new_buffer || |
6880 (attrib_0_used && | 6894 (attrib_0_used && |
6881 (!attrib_0_buffer_matches_value_ || | 6895 (!attrib_0_buffer_matches_value_ || value.v != attrib_0_value_.v))) { |
6882 (value.v[0] != attrib_0_value_.v[0] || | 6896 // TODO(zmo): This is not 100% correct because we might lose data when |
6883 value.v[1] != attrib_0_value_.v[1] || | 6897 // casting to float type, but it is a corner case and once we migrate to |
6884 value.v[2] != attrib_0_value_.v[2] || | 6898 // core profiles on desktop GL, it is no longer relevant. |
6885 value.v[3] != attrib_0_value_.v[3])))) { | 6899 Vec4f fvalue(value); |
6886 std::vector<Vec4> temp(num_vertices, value); | 6900 std::vector<Vec4f> temp(num_vertices, fvalue); |
6887 glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); | 6901 glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
6888 attrib_0_buffer_matches_value_ = true; | 6902 attrib_0_buffer_matches_value_ = true; |
6889 attrib_0_value_ = value; | 6903 attrib_0_value_ = value; |
6890 attrib_0_size_ = size_needed; | 6904 attrib_0_size_ = size_needed; |
6891 } | 6905 } |
6892 | 6906 |
6893 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); | 6907 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
6894 | 6908 |
6895 if (attrib->divisor()) | 6909 if (attrib->divisor()) |
6896 glVertexAttribDivisorANGLE(0, 0); | 6910 glVertexAttribDivisorANGLE(0, 0); |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7589 program_client_id, "glValidateProgram"); | 7603 program_client_id, "glValidateProgram"); |
7590 if (!program) { | 7604 if (!program) { |
7591 return; | 7605 return; |
7592 } | 7606 } |
7593 program->Validate(); | 7607 program->Validate(); |
7594 } | 7608 } |
7595 | 7609 |
7596 void GLES2DecoderImpl::GetVertexAttribHelper( | 7610 void GLES2DecoderImpl::GetVertexAttribHelper( |
7597 const VertexAttrib* attrib, GLenum pname, GLint* params) { | 7611 const VertexAttrib* attrib, GLenum pname, GLint* params) { |
7598 switch (pname) { | 7612 switch (pname) { |
7599 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { | 7613 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 7614 { |
7600 Buffer* buffer = attrib->buffer(); | 7615 Buffer* buffer = attrib->buffer(); |
7601 if (buffer && !buffer->IsDeleted()) { | 7616 if (buffer && !buffer->IsDeleted()) { |
7602 GLuint client_id; | 7617 GLuint client_id; |
7603 buffer_manager()->GetClientId(buffer->service_id(), &client_id); | 7618 buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
7604 *params = client_id; | 7619 *params = client_id; |
7605 } | 7620 } |
7606 break; | 7621 break; |
7607 } | 7622 } |
7608 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: | 7623 case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
7609 *params = attrib->enabled(); | 7624 *params = attrib->enabled(); |
7610 break; | 7625 break; |
7611 case GL_VERTEX_ATTRIB_ARRAY_SIZE: | 7626 case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
7612 *params = attrib->size(); | 7627 *params = attrib->size(); |
7613 break; | 7628 break; |
7614 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: | 7629 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
7615 *params = attrib->gl_stride(); | 7630 *params = attrib->gl_stride(); |
7616 break; | 7631 break; |
7617 case GL_VERTEX_ATTRIB_ARRAY_TYPE: | 7632 case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
7618 *params = attrib->type(); | 7633 *params = attrib->type(); |
7619 break; | 7634 break; |
7620 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: | 7635 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
7621 *params = attrib->normalized(); | 7636 *params = attrib->normalized(); |
7622 break; | 7637 break; |
7623 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: | 7638 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
7624 *params = attrib->divisor(); | 7639 *params = attrib->divisor(); |
7625 break; | 7640 break; |
| 7641 case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 7642 *params = attrib->integer(); |
| 7643 break; |
7626 default: | 7644 default: |
7627 NOTREACHED(); | 7645 NOTREACHED(); |
7628 break; | 7646 break; |
7629 } | 7647 } |
7630 } | 7648 } |
7631 | 7649 |
7632 void GLES2DecoderImpl::DoGetTexParameterfv( | 7650 void GLES2DecoderImpl::DoGetTexParameterfv( |
7633 GLenum target, GLenum pname, GLfloat* params) { | 7651 GLenum target, GLenum pname, GLfloat* params) { |
7634 InitTextureMaxAnisotropyIfNeeded(target, pname); | 7652 InitTextureMaxAnisotropyIfNeeded(target, pname); |
7635 glGetTexParameterfv(target, pname, params); | 7653 glGetTexParameterfv(target, pname, params); |
(...skipping 19 matching lines...) Expand all Loading... |
7655 if (!texture_ref) { | 7673 if (!texture_ref) { |
7656 LOCAL_SET_GL_ERROR( | 7674 LOCAL_SET_GL_ERROR( |
7657 GL_INVALID_OPERATION, | 7675 GL_INVALID_OPERATION, |
7658 "glGetTexParamter{fi}v", "unknown texture for target"); | 7676 "glGetTexParamter{fi}v", "unknown texture for target"); |
7659 return; | 7677 return; |
7660 } | 7678 } |
7661 Texture* texture = texture_ref->texture(); | 7679 Texture* texture = texture_ref->texture(); |
7662 texture->InitTextureMaxAnisotropyIfNeeded(target); | 7680 texture->InitTextureMaxAnisotropyIfNeeded(target); |
7663 } | 7681 } |
7664 | 7682 |
7665 void GLES2DecoderImpl::DoGetVertexAttribfv( | 7683 template <typename T> |
7666 GLuint index, GLenum pname, GLfloat* params) { | 7684 void GLES2DecoderImpl::DoGetVertexAttribImpl( |
| 7685 GLuint index, GLenum pname, T* params) { |
7667 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); | 7686 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
7668 if (!attrib) { | 7687 if (!attrib) { |
7669 LOCAL_SET_GL_ERROR( | 7688 LOCAL_SET_GL_ERROR( |
7670 GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); | 7689 GL_INVALID_VALUE, "glGetVertexAttrib", "index out of range"); |
7671 return; | 7690 return; |
7672 } | 7691 } |
7673 switch (pname) { | 7692 switch (pname) { |
7674 case GL_CURRENT_VERTEX_ATTRIB: { | 7693 case GL_CURRENT_VERTEX_ATTRIB: { |
7675 const Vec4& value = state_.attrib_values[index]; | 7694 const Vec4& value = state_.attrib_values[index]; |
7676 params[0] = value.v[0]; | 7695 params[0] = static_cast<T>(value.v[0]); |
7677 params[1] = value.v[1]; | 7696 params[1] = static_cast<T>(value.v[1]); |
7678 params[2] = value.v[2]; | 7697 params[2] = static_cast<T>(value.v[2]); |
7679 params[3] = value.v[3]; | 7698 params[3] = static_cast<T>(value.v[3]); |
7680 break; | 7699 break; |
7681 } | 7700 } |
7682 default: { | 7701 default: { |
7683 GLint value = 0; | 7702 GLint value = 0; |
7684 GetVertexAttribHelper(attrib, pname, &value); | 7703 GetVertexAttribHelper(attrib, pname, &value); |
7685 *params = static_cast<GLfloat>(value); | 7704 *params = static_cast<T>(value); |
7686 break; | 7705 break; |
7687 } | 7706 } |
7688 } | 7707 } |
7689 } | 7708 } |
7690 | 7709 |
| 7710 void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 7711 GLuint index, GLenum pname, GLfloat* params) { |
| 7712 DoGetVertexAttribImpl<GLfloat>(index, pname, params); |
| 7713 } |
| 7714 |
7691 void GLES2DecoderImpl::DoGetVertexAttribiv( | 7715 void GLES2DecoderImpl::DoGetVertexAttribiv( |
7692 GLuint index, GLenum pname, GLint* params) { | 7716 GLuint index, GLenum pname, GLint* params) { |
7693 VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); | 7717 DoGetVertexAttribImpl<GLint>(index, pname, params); |
7694 if (!attrib) { | 7718 } |
7695 LOCAL_SET_GL_ERROR( | 7719 |
7696 GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); | 7720 void GLES2DecoderImpl::DoGetVertexAttribIiv( |
7697 return; | 7721 GLuint index, GLenum pname, GLint* params) { |
7698 } | 7722 DoGetVertexAttribImpl<GLint>(index, pname, params); |
7699 switch (pname) { | 7723 } |
7700 case GL_CURRENT_VERTEX_ATTRIB: { | 7724 |
7701 const Vec4& value = state_.attrib_values[index]; | 7725 void GLES2DecoderImpl::DoGetVertexAttribIuiv( |
7702 params[0] = static_cast<GLint>(value.v[0]); | 7726 GLuint index, GLenum pname, GLuint* params) { |
7703 params[1] = static_cast<GLint>(value.v[1]); | 7727 DoGetVertexAttribImpl<GLuint>(index, pname, params); |
7704 params[2] = static_cast<GLint>(value.v[2]); | |
7705 params[3] = static_cast<GLint>(value.v[3]); | |
7706 break; | |
7707 } | |
7708 default: | |
7709 GetVertexAttribHelper(attrib, pname, params); | |
7710 break; | |
7711 } | |
7712 } | 7728 } |
7713 | 7729 |
7714 bool GLES2DecoderImpl::SetVertexAttribValue( | 7730 bool GLES2DecoderImpl::SetVertexAttribValue( |
7715 const char* function_name, GLuint index, const GLfloat* value) { | 7731 const char* function_name, GLuint index, const GLfloat* value) { |
7716 if (index >= state_.attrib_values.size()) { | 7732 if (index >= state_.attrib_values.size()) { |
7717 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); | 7733 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
7718 return false; | 7734 return false; |
7719 } | 7735 } |
7720 Vec4& v = state_.attrib_values[index]; | 7736 Vec4& v = state_.attrib_values[index]; |
7721 v.v[0] = value[0]; | 7737 v.v[0] = value[0]; |
(...skipping 5421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13143 } | 13159 } |
13144 } | 13160 } |
13145 | 13161 |
13146 // Include the auto-generated part of this file. We split this because it means | 13162 // Include the auto-generated part of this file. We split this because it means |
13147 // we can easily edit the non-auto generated parts right here in this file | 13163 // we can easily edit the non-auto generated parts right here in this file |
13148 // instead of having to edit some template or the code generator. | 13164 // instead of having to edit some template or the code generator. |
13149 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 13165 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
13150 | 13166 |
13151 } // namespace gles2 | 13167 } // namespace gles2 |
13152 } // namespace gpu | 13168 } // namespace gpu |
OLD | NEW |