| 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 <list> | 10 #include <list> |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 936 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 937 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, | 937 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| 938 const GLbyte* key); | 938 const GLbyte* key); |
| 939 void ProduceTextureRef(std::string func_name, TextureRef* texture_ref, | 939 void ProduceTextureRef(std::string func_name, TextureRef* texture_ref, |
| 940 GLenum target, const GLbyte* data); | 940 GLenum target, const GLbyte* data); |
| 941 | 941 |
| 942 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); | 942 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 943 void DoCreateAndConsumeTextureCHROMIUM(GLenum target, const GLbyte* key, | 943 void DoCreateAndConsumeTextureCHROMIUM(GLenum target, const GLbyte* key, |
| 944 GLuint client_id); | 944 GLuint client_id); |
| 945 | 945 |
| 946 void DoSubscribeUniformCHROMIUM(GLint locaton, GLenum target); |
| 947 void DoUnsubscribeUniformCHROMIUM(GLint location); |
| 948 void DoPopulateSubscribedUniformsCHROMIUM(); |
| 949 |
| 946 void DoBindTexImage2DCHROMIUM( | 950 void DoBindTexImage2DCHROMIUM( |
| 947 GLenum target, | 951 GLenum target, |
| 948 GLint image_id); | 952 GLint image_id); |
| 949 void DoReleaseTexImage2DCHROMIUM( | 953 void DoReleaseTexImage2DCHROMIUM( |
| 950 GLenum target, | 954 GLenum target, |
| 951 GLint image_id); | 955 GLint image_id); |
| 952 | 956 |
| 953 void DoTraceEndCHROMIUM(void); | 957 void DoTraceEndCHROMIUM(void); |
| 954 | 958 |
| 955 void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); | 959 void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 // -1. If the current program is not valid generates the appropriate GL | 1189 // -1. If the current program is not valid generates the appropriate GL |
| 1186 // error. Returns true if the current program is in a usable state and | 1190 // error. Returns true if the current program is in a usable state and |
| 1187 // location is not -1. | 1191 // location is not -1. |
| 1188 bool CheckCurrentProgramForUniform(GLint location, const char* function_name); | 1192 bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1189 | 1193 |
| 1190 // Checks if the current program samples a texture that is also the color | 1194 // Checks if the current program samples a texture that is also the color |
| 1191 // image of the current bound framebuffer, i.e., the source and destination | 1195 // image of the current bound framebuffer, i.e., the source and destination |
| 1192 // of the draw operation are the same. | 1196 // of the draw operation are the same. |
| 1193 bool CheckDrawingFeedbackLoops(); | 1197 bool CheckDrawingFeedbackLoops(); |
| 1194 | 1198 |
| 1199 // Checks if |api_type| is valid for the given uniform |
| 1200 // If the api type is not valid generates the appropriate GL |
| 1201 // error. Returns true if |api_type| is valid for the uniform |
| 1202 bool CheckUniformForApiType(const Program::UniformInfo* info, |
| 1203 const char* function_name, |
| 1204 Program::UniformApiType api_type); |
| 1205 |
| 1195 // Gets the type of a uniform for a location in the current program. Sets GL | 1206 // Gets the type of a uniform for a location in the current program. Sets GL |
| 1196 // errors if the current program is not valid. Returns true if the current | 1207 // errors if the current program is not valid. Returns true if the current |
| 1197 // program is valid and the location exists. Adjusts count so it | 1208 // program is valid and the location exists. Adjusts count so it |
| 1198 // does not overflow the uniform. | 1209 // does not overflow the uniform. |
| 1199 bool PrepForSetUniformByLocation(GLint fake_location, | 1210 bool PrepForSetUniformByLocation(GLint fake_location, |
| 1200 const char* function_name, | 1211 const char* function_name, |
| 1201 Program::UniformApiType api_type, | 1212 Program::UniformApiType api_type, |
| 1202 GLint* real_location, | 1213 GLint* real_location, |
| 1203 GLenum* type, | 1214 GLenum* type, |
| 1204 GLsizei* count); | 1215 GLsizei* count); |
| 1205 | 1216 |
| 1217 void PopulateSubscribedUniforms(Program* program); |
| 1218 |
| 1206 // Gets the service id for any simulated backbuffer fbo. | 1219 // Gets the service id for any simulated backbuffer fbo. |
| 1207 GLuint GetBackbufferServiceId() const; | 1220 GLuint GetBackbufferServiceId() const; |
| 1208 | 1221 |
| 1209 // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv | 1222 // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1210 bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); | 1223 bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1211 | 1224 |
| 1212 // Helper for glGetVertexAttrib | 1225 // Helper for glGetVertexAttrib |
| 1213 void GetVertexAttribHelper( | 1226 void GetVertexAttribHelper( |
| 1214 const VertexAttrib* attrib, GLenum pname, GLint* param); | 1227 const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1215 | 1228 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 GLint level, GLsizei width, GLsizei height, GLenum format); | 1588 GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1576 bool ValidateCompressedTexFuncData( | 1589 bool ValidateCompressedTexFuncData( |
| 1577 const char* function_name, | 1590 const char* function_name, |
| 1578 GLsizei width, GLsizei height, GLenum format, size_t size); | 1591 GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1579 bool ValidateCompressedTexSubDimensions( | 1592 bool ValidateCompressedTexSubDimensions( |
| 1580 const char* function_name, | 1593 const char* function_name, |
| 1581 GLenum target, GLint level, GLint xoffset, GLint yoffset, | 1594 GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1582 GLsizei width, GLsizei height, GLenum format, | 1595 GLsizei width, GLsizei height, GLenum format, |
| 1583 Texture* texture); | 1596 Texture* texture); |
| 1584 | 1597 |
| 1598 bool ValidateSubscribeUniform(GLint fake_location, GLenum target); |
| 1599 |
| 1585 void RenderWarning(const char* filename, int line, const std::string& msg); | 1600 void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1586 void PerformanceWarning( | 1601 void PerformanceWarning( |
| 1587 const char* filename, int line, const std::string& msg); | 1602 const char* filename, int line, const std::string& msg); |
| 1588 | 1603 |
| 1589 const FeatureInfo::FeatureFlags& features() const { | 1604 const FeatureInfo::FeatureFlags& features() const { |
| 1590 return feature_info_->feature_flags(); | 1605 return feature_info_->feature_flags(); |
| 1591 } | 1606 } |
| 1592 | 1607 |
| 1593 const FeatureInfo::Workarounds& workarounds() const { | 1608 const FeatureInfo::Workarounds& workarounds() const { |
| 1594 return feature_info_->workarounds(); | 1609 return feature_info_->workarounds(); |
| (...skipping 4170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5765 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; | 5780 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
| 5766 TextureRef* texture_ref = | 5781 TextureRef* texture_ref = |
| 5767 texture_unit.GetInfoForSamplerType(GL_SAMPLER_2D).get(); | 5782 texture_unit.GetInfoForSamplerType(GL_SAMPLER_2D).get(); |
| 5768 if (attachment->IsTexture(texture_ref)) | 5783 if (attachment->IsTexture(texture_ref)) |
| 5769 return true; | 5784 return true; |
| 5770 } | 5785 } |
| 5771 } | 5786 } |
| 5772 return false; | 5787 return false; |
| 5773 } | 5788 } |
| 5774 | 5789 |
| 5790 bool GLES2DecoderImpl::CheckUniformForApiType( |
| 5791 const Program::UniformInfo* info, |
| 5792 const char* function_name, |
| 5793 Program::UniformApiType api_type) { |
| 5794 DCHECK(info); |
| 5795 if ((api_type & info->accepts_api_type) == 0) { |
| 5796 LOCAL_SET_GL_ERROR( |
| 5797 GL_INVALID_OPERATION, function_name, "wrong uniform function for type"); |
| 5798 return false; |
| 5799 } |
| 5800 return true; |
| 5801 } |
| 5802 |
| 5775 bool GLES2DecoderImpl::PrepForSetUniformByLocation( | 5803 bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
| 5776 GLint fake_location, | 5804 GLint fake_location, |
| 5777 const char* function_name, | 5805 const char* function_name, |
| 5778 Program::UniformApiType api_type, | 5806 Program::UniformApiType api_type, |
| 5779 GLint* real_location, | 5807 GLint* real_location, |
| 5780 GLenum* type, | 5808 GLenum* type, |
| 5781 GLsizei* count) { | 5809 GLsizei* count) { |
| 5782 DCHECK(type); | 5810 DCHECK(type); |
| 5783 DCHECK(count); | 5811 DCHECK(count); |
| 5784 DCHECK(real_location); | 5812 DCHECK(real_location); |
| 5785 | 5813 |
| 5786 if (!CheckCurrentProgramForUniform(fake_location, function_name)) { | 5814 if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
| 5787 return false; | 5815 return false; |
| 5788 } | 5816 } |
| 5789 GLint array_index = -1; | 5817 GLint array_index = -1; |
| 5790 const Program::UniformInfo* info = | 5818 const Program::UniformInfo* info = |
| 5791 state_.current_program->GetUniformInfoByFakeLocation( | 5819 state_.current_program->GetUniformInfoByFakeLocation( |
| 5792 fake_location, real_location, &array_index); | 5820 fake_location, real_location, &array_index); |
| 5793 if (!info) { | 5821 if (!info) { |
| 5794 LOCAL_SET_GL_ERROR( | 5822 LOCAL_SET_GL_ERROR( |
| 5795 GL_INVALID_OPERATION, function_name, "unknown location"); | 5823 GL_INVALID_OPERATION, function_name, "unknown location"); |
| 5796 return false; | 5824 return false; |
| 5797 } | 5825 } |
| 5798 | 5826 if (!CheckUniformForApiType(info, function_name, api_type)) { |
| 5799 if ((api_type & info->accepts_api_type) == 0) { | |
| 5800 LOCAL_SET_GL_ERROR( | |
| 5801 GL_INVALID_OPERATION, function_name, | |
| 5802 "wrong uniform function for type"); | |
| 5803 return false; | 5827 return false; |
| 5804 } | 5828 } |
| 5805 if (*count > 1 && !info->is_array) { | 5829 if (*count > 1 && !info->is_array) { |
| 5806 LOCAL_SET_GL_ERROR( | 5830 LOCAL_SET_GL_ERROR( |
| 5807 GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); | 5831 GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
| 5808 return false; | 5832 return false; |
| 5809 } | 5833 } |
| 5810 *count = std::min(info->size - array_index, *count); | 5834 *count = std::min(info->size - array_index, *count); |
| 5811 if (*count <= 0) { | 5835 if (*count <= 0) { |
| 5812 return false; | 5836 return false; |
| 5813 } | 5837 } |
| 5814 *type = info->type; | 5838 *type = info->type; |
| 5815 return true; | 5839 return true; |
| 5816 } | 5840 } |
| 5817 | 5841 |
| 5842 void GLES2DecoderImpl::PopulateSubscribedUniforms(Program* program) { |
| 5843 const Program::SubscriptionMap& subscription_map = |
| 5844 program->subscription_map(); |
| 5845 for (Program::SubscriptionMap::const_iterator it = subscription_map.begin(); |
| 5846 it != subscription_map.end(); |
| 5847 ++it) { |
| 5848 // TODO(orglofch): |
| 5849 } |
| 5850 } |
| 5851 |
| 5818 void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { | 5852 void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 5819 GLenum type = 0; | 5853 GLenum type = 0; |
| 5820 GLsizei count = 1; | 5854 GLsizei count = 1; |
| 5821 GLint real_location = -1; | 5855 GLint real_location = -1; |
| 5822 if (!PrepForSetUniformByLocation(fake_location, | 5856 if (!PrepForSetUniformByLocation(fake_location, |
| 5823 "glUniform1i", | 5857 "glUniform1i", |
| 5824 Program::kUniform1i, | 5858 Program::kUniform1i, |
| 5825 &real_location, | 5859 &real_location, |
| 5826 &type, | 5860 &type, |
| 5827 &count)) { | 5861 &count)) { |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6068 program_manager()->UnuseProgram(shader_manager(), | 6102 program_manager()->UnuseProgram(shader_manager(), |
| 6069 state_.current_program.get()); | 6103 state_.current_program.get()); |
| 6070 } | 6104 } |
| 6071 state_.current_program = program; | 6105 state_.current_program = program; |
| 6072 LogClientServiceMapping("glUseProgram", program_id, service_id); | 6106 LogClientServiceMapping("glUseProgram", program_id, service_id); |
| 6073 glUseProgram(service_id); | 6107 glUseProgram(service_id); |
| 6074 if (state_.current_program.get()) { | 6108 if (state_.current_program.get()) { |
| 6075 program_manager()->UseProgram(state_.current_program.get()); | 6109 program_manager()->UseProgram(state_.current_program.get()); |
| 6076 if (workarounds().clear_uniforms_before_first_program_use) | 6110 if (workarounds().clear_uniforms_before_first_program_use) |
| 6077 program_manager()->ClearUniforms(program); | 6111 program_manager()->ClearUniforms(program); |
| 6112 if (program->needs_update_subscriptions()) { |
| 6113 PopulateSubscribedUniforms(program); |
| 6114 } |
| 6078 } | 6115 } |
| 6079 } | 6116 } |
| 6080 | 6117 |
| 6081 void GLES2DecoderImpl::RenderWarning( | 6118 void GLES2DecoderImpl::RenderWarning( |
| 6082 const char* filename, int line, const std::string& msg) { | 6119 const char* filename, int line, const std::string& msg) { |
| 6083 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); | 6120 logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
| 6084 } | 6121 } |
| 6085 | 6122 |
| 6086 void GLES2DecoderImpl::PerformanceWarning( | 6123 void GLES2DecoderImpl::PerformanceWarning( |
| 6087 const char* filename, int line, const std::string& msg) { | 6124 const char* filename, int line, const std::string& msg) { |
| (...skipping 4578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10666 if (texture->target() != target) { | 10703 if (texture->target() != target) { |
| 10667 LOCAL_SET_GL_ERROR( | 10704 LOCAL_SET_GL_ERROR( |
| 10668 GL_INVALID_OPERATION, | 10705 GL_INVALID_OPERATION, |
| 10669 "glCreateAndConsumeTextureCHROMIUM", "invalid target"); | 10706 "glCreateAndConsumeTextureCHROMIUM", "invalid target"); |
| 10670 return; | 10707 return; |
| 10671 } | 10708 } |
| 10672 | 10709 |
| 10673 texture_ref = texture_manager()->Consume(client_id, texture); | 10710 texture_ref = texture_manager()->Consume(client_id, texture); |
| 10674 } | 10711 } |
| 10675 | 10712 |
| 10713 bool GLES2DecoderImpl::ValidateSubscribeUniform(GLint fake_location, |
| 10714 GLenum target) { |
| 10715 if (!CheckCurrentProgramForUniform(fake_location, |
| 10716 "glSubscribeUniformCHROMIUM")) { |
| 10717 return false; |
| 10718 } |
| 10719 GLint array_index = -1; |
| 10720 GLint real_location = -1; |
| 10721 const Program::UniformInfo* info = |
| 10722 state_.current_program->GetUniformInfoByFakeLocation( |
| 10723 fake_location, &real_location, &array_index); |
| 10724 if (!info) { |
| 10725 LOCAL_SET_GL_ERROR( |
| 10726 GL_INVALID_OPERATION, "glSubscribeUniformCHROMIUM", "unknown location"); |
| 10727 return false; |
| 10728 } |
| 10729 if (!CheckUniformForApiType( |
| 10730 info, |
| 10731 "glSubscribeUniformCHROMIUM", |
| 10732 program_manager()->ApiTypeForSubscriptionTarget(target))) { |
| 10733 return false; |
| 10734 } |
| 10735 return true; |
| 10736 } |
| 10737 |
| 10738 void GLES2DecoderImpl::DoSubscribeUniformCHROMIUM(GLint location, |
| 10739 GLenum target) { |
| 10740 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoSubscribeUniformCHROMIUM"); |
| 10741 if (!ValidateSubscribeUniform(location, target)) { |
| 10742 return; |
| 10743 } |
| 10744 if (state_.current_program.get()) { |
| 10745 state_.current_program.get()->AddSubscription(location, target); |
| 10746 } |
| 10747 } |
| 10748 |
| 10749 void GLES2DecoderImpl::DoUnsubscribeUniformCHROMIUM(GLint location) { |
| 10750 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoUnsubscribeUniformCHROMIUM"); |
| 10751 if (!CheckCurrentProgramForUniform(location, |
| 10752 "glUnsubscribeUniformCHROMIUM")) { |
| 10753 return; |
| 10754 } |
| 10755 if (state_.current_program.get()) { |
| 10756 state_.current_program.get()->RemoveSubscription(location); |
| 10757 } |
| 10758 } |
| 10759 |
| 10760 void GLES2DecoderImpl::DoPopulateSubscribedUniformsCHROMIUM() { |
| 10761 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoPopulateSubscribedUniformsCHROMIUM"); |
| 10762 program_manager()->ActivateUniformSubscriptionState(); |
| 10763 // Defer population of other programs until calls to DoUseProgram |
| 10764 if (state_.current_program.get() && |
| 10765 state_.current_program.get()->needs_update_subscriptions()) { |
| 10766 PopulateSubscribedUniforms(state_.current_program.get()); |
| 10767 } |
| 10768 } |
| 10769 |
| 10676 void GLES2DecoderImpl::DoInsertEventMarkerEXT( | 10770 void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 10677 GLsizei length, const GLchar* marker) { | 10771 GLsizei length, const GLchar* marker) { |
| 10678 if (!marker) { | 10772 if (!marker) { |
| 10679 marker = ""; | 10773 marker = ""; |
| 10680 } | 10774 } |
| 10681 debug_marker_manager_.SetMarker( | 10775 debug_marker_manager_.SetMarker( |
| 10682 length ? std::string(marker, length) : std::string(marker)); | 10776 length ? std::string(marker, length) : std::string(marker)); |
| 10683 } | 10777 } |
| 10684 | 10778 |
| 10685 void GLES2DecoderImpl::DoPushGroupMarkerEXT( | 10779 void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11228 } | 11322 } |
| 11229 } | 11323 } |
| 11230 | 11324 |
| 11231 // Include the auto-generated part of this file. We split this because it means | 11325 // Include the auto-generated part of this file. We split this because it means |
| 11232 // we can easily edit the non-auto generated parts right here in this file | 11326 // we can easily edit the non-auto generated parts right here in this file |
| 11233 // instead of having to edit some template or the code generator. | 11327 // instead of having to edit some template or the code generator. |
| 11234 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 11328 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 11235 | 11329 |
| 11236 } // namespace gles2 | 11330 } // namespace gles2 |
| 11237 } // namespace gpu | 11331 } // namespace gpu |
| OLD | NEW |