| 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 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1226   void DoGetFramebufferAttachmentParameteriv( | 1226   void DoGetFramebufferAttachmentParameteriv( | 
| 1227       GLenum target, GLenum attachment, GLenum pname, GLint* params); | 1227       GLenum target, GLenum attachment, GLenum pname, GLint* params); | 
| 1228 | 1228 | 
| 1229   // Wrapper for glGetIntegerv. | 1229   // Wrapper for glGetIntegerv. | 
| 1230   void DoGetIntegerv(GLenum pname, GLint* params); | 1230   void DoGetIntegerv(GLenum pname, GLint* params); | 
| 1231 | 1231 | 
| 1232   // Gets the max value in a range in a buffer. | 1232   // Gets the max value in a range in a buffer. | 
| 1233   GLuint DoGetMaxValueInBufferCHROMIUM( | 1233   GLuint DoGetMaxValueInBufferCHROMIUM( | 
| 1234       GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); | 1234       GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); | 
| 1235 | 1235 | 
|  | 1236   // Wrapper for glGetBufferParameteriv. | 
|  | 1237   void DoGetBufferParameteriv( | 
|  | 1238       GLenum target, GLenum pname, GLint* params); | 
|  | 1239 | 
| 1236   // Wrapper for glGetProgramiv. | 1240   // Wrapper for glGetProgramiv. | 
| 1237   void DoGetProgramiv( | 1241   void DoGetProgramiv( | 
| 1238       GLuint program_id, GLenum pname, GLint* params); | 1242       GLuint program_id, GLenum pname, GLint* params); | 
| 1239 | 1243 | 
| 1240   // Wrapper for glRenderbufferParameteriv. | 1244   // Wrapper for glRenderbufferParameteriv. | 
| 1241   void DoGetRenderbufferParameteriv( | 1245   void DoGetRenderbufferParameteriv( | 
| 1242       GLenum target, GLenum pname, GLint* params); | 1246       GLenum target, GLenum pname, GLint* params); | 
| 1243 | 1247 | 
| 1244   // Wrapper for glGetShaderiv | 1248   // Wrapper for glGetShaderiv | 
| 1245   void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); | 1249   void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); | 
| (...skipping 3060 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 4306 void GLES2DecoderImpl::DoGetProgramiv( | 4310 void GLES2DecoderImpl::DoGetProgramiv( | 
| 4307     GLuint program_id, GLenum pname, GLint* params) { | 4311     GLuint program_id, GLenum pname, GLint* params) { | 
| 4308   Program* info = GetProgramInfoNotShader( | 4312   Program* info = GetProgramInfoNotShader( | 
| 4309       program_id, "glGetProgramiv"); | 4313       program_id, "glGetProgramiv"); | 
| 4310   if (!info) { | 4314   if (!info) { | 
| 4311     return; | 4315     return; | 
| 4312   } | 4316   } | 
| 4313   info->GetProgramiv(pname, params); | 4317   info->GetProgramiv(pname, params); | 
| 4314 } | 4318 } | 
| 4315 | 4319 | 
|  | 4320 void GLES2DecoderImpl::DoGetBufferParameteriv( | 
|  | 4321     GLenum target, GLenum pname, GLint* params) { | 
|  | 4322   Buffer* buffer = GetBufferInfoForTarget(target); | 
|  | 4323   if (!buffer) { | 
|  | 4324     SetGLError( | 
|  | 4325         GL_INVALID_OPERATION, "glGetBufferParameteriv", | 
|  | 4326         "no buffer bound for target"); | 
|  | 4327     return; | 
|  | 4328   } | 
|  | 4329   switch (pname) { | 
|  | 4330     case GL_BUFFER_SIZE: | 
|  | 4331       *params = buffer->size(); | 
|  | 4332       break; | 
|  | 4333     case GL_BUFFER_USAGE: | 
|  | 4334       *params = buffer->usage(); | 
|  | 4335       break; | 
|  | 4336     default: | 
|  | 4337       NOTREACHED(); | 
|  | 4338   } | 
|  | 4339 } | 
|  | 4340 | 
| 4316 void GLES2DecoderImpl::DoBindAttribLocation( | 4341 void GLES2DecoderImpl::DoBindAttribLocation( | 
| 4317     GLuint program, GLuint index, const char* name) { | 4342     GLuint program, GLuint index, const char* name) { | 
| 4318   if (!StringIsValidForGLES(name)) { | 4343   if (!StringIsValidForGLES(name)) { | 
| 4319     SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); | 4344     SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); | 
| 4320     return; | 4345     return; | 
| 4321   } | 4346   } | 
| 4322   if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { | 4347   if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { | 
| 4323     SetGLError(GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); | 4348     SetGLError(GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); | 
| 4324     return; | 4349     return; | 
| 4325   } | 4350   } | 
| (...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5730   // it could never be invalid since glUseProgram would have failed. While | 5755   // it could never be invalid since glUseProgram would have failed. While | 
| 5731   // glLinkProgram could later mark the program as invalid the previous | 5756   // glLinkProgram could later mark the program as invalid the previous | 
| 5732   // valid program will still function if it is still the current program. | 5757   // valid program will still function if it is still the current program. | 
| 5733   if (!state_.current_program) { | 5758   if (!state_.current_program) { | 
| 5734     // The program does not exist. | 5759     // The program does not exist. | 
| 5735     // But GL says no ERROR. | 5760     // But GL says no ERROR. | 
| 5736     RenderWarning("Drawing with no current shader program."); | 5761     RenderWarning("Drawing with no current shader program."); | 
| 5737     return false; | 5762     return false; | 
| 5738   } | 5763   } | 
| 5739 | 5764 | 
| 5740   // true if any enabled, used divisor is zero | 5765   return state_.vertex_attrib_manager->ValidateBindings( | 
| 5741   bool divisor0 = false; | 5766       function_name, | 
| 5742   // Validate all attribs currently enabled. If they are used by the current | 5767       this, | 
| 5743   // program then check that they have enough elements to handle the draw call. | 5768       feature_info_.get(), | 
| 5744   // If they are not used by the current program check that they have a buffer | 5769       state_.current_program, | 
| 5745   // assigned. | 5770       max_vertex_accessed, | 
| 5746   const VertexAttribManager::VertexAttribInfoList& infos = | 5771       primcount); | 
| 5747       state_.vertex_attrib_manager->GetEnabledVertexAttribInfos(); |  | 
| 5748   for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |  | 
| 5749        infos.begin(); it != infos.end(); ++it) { |  | 
| 5750     const VertexAttrib* info = *it; |  | 
| 5751     const Program::VertexAttrib* attrib_info = |  | 
| 5752         state_.current_program->GetAttribInfoByLocation(info->index()); |  | 
| 5753     if (attrib_info) { |  | 
| 5754       divisor0 |= (info->divisor() == 0); |  | 
| 5755       GLuint count = info->MaxVertexAccessed(primcount, max_vertex_accessed); |  | 
| 5756       // This attrib is used in the current program. |  | 
| 5757       if (!info->CanAccess(count)) { |  | 
| 5758         SetGLError( |  | 
| 5759             GL_INVALID_OPERATION, function_name, |  | 
| 5760             (std::string( |  | 
| 5761                  "attempt to access out of range vertices in attribute ") + |  | 
| 5762              base::IntToString(info->index())).c_str()); |  | 
| 5763         return false; |  | 
| 5764       } |  | 
| 5765     } else { |  | 
| 5766       // This attrib is not used in the current program. |  | 
| 5767       if (!info->buffer()) { |  | 
| 5768         SetGLError( |  | 
| 5769             GL_INVALID_OPERATION, function_name, |  | 
| 5770             (std::string( |  | 
| 5771                  "attempt to render with no buffer attached to " |  | 
| 5772                  "enabled attribute ") + |  | 
| 5773                  base::IntToString(info->index())).c_str()); |  | 
| 5774         return false; |  | 
| 5775       } |  | 
| 5776     } |  | 
| 5777   } |  | 
| 5778 |  | 
| 5779   if (primcount && !divisor0) { |  | 
| 5780     SetGLError( |  | 
| 5781         GL_INVALID_OPERATION, function_name, |  | 
| 5782         "attempt instanced render with all attributes having " |  | 
| 5783         "non-zero divisors"); |  | 
| 5784     return false; |  | 
| 5785   } |  | 
| 5786 |  | 
| 5787   return true; |  | 
| 5788 } | 5772 } | 
| 5789 | 5773 | 
| 5790 bool GLES2DecoderImpl::SimulateAttrib0( | 5774 bool GLES2DecoderImpl::SimulateAttrib0( | 
| 5791     const char* function_name, GLuint max_vertex_accessed, bool* simulated) { | 5775     const char* function_name, GLuint max_vertex_accessed, bool* simulated) { | 
| 5792   DCHECK(simulated); | 5776   DCHECK(simulated); | 
| 5793   *simulated = false; | 5777   *simulated = false; | 
| 5794 | 5778 | 
| 5795   if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) | 5779   if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) | 
| 5796     return true; | 5780     return true; | 
| 5797 | 5781 | 
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 6138 | 6122 | 
| 6139   if (!CheckBoundFramebuffersValid(function_name)) { | 6123   if (!CheckBoundFramebuffersValid(function_name)) { | 
| 6140     return error::kNoError; | 6124     return error::kNoError; | 
| 6141   } | 6125   } | 
| 6142 | 6126 | 
| 6143   if (count == 0 || (instanced && primcount == 0)) { | 6127   if (count == 0 || (instanced && primcount == 0)) { | 
| 6144     return error::kNoError; | 6128     return error::kNoError; | 
| 6145   } | 6129   } | 
| 6146 | 6130 | 
| 6147   GLuint max_vertex_accessed; | 6131   GLuint max_vertex_accessed; | 
| 6148   if (!state_.vertex_attrib_manager->element_array_buffer()-> | 6132   Buffer* element_array_buffer = | 
| 6149       GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { | 6133       state_.vertex_attrib_manager->element_array_buffer(); | 
|  | 6134 | 
|  | 6135   if (!element_array_buffer->GetMaxValueForRange( | 
|  | 6136       offset, count, type, &max_vertex_accessed)) { | 
| 6150     SetGLError(GL_INVALID_OPERATION, | 6137     SetGLError(GL_INVALID_OPERATION, | 
| 6151                function_name, "range out of bounds for buffer"); | 6138                function_name, "range out of bounds for buffer"); | 
| 6152     return error::kNoError; | 6139     return error::kNoError; | 
| 6153   } | 6140   } | 
| 6154 | 6141 | 
| 6155   if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { | 6142   if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { | 
| 6156     if (!ClearUnclearedTextures()) { | 6143     if (!ClearUnclearedTextures()) { | 
| 6157       SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); | 6144       SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); | 
| 6158       return error::kNoError; | 6145       return error::kNoError; | 
| 6159     } | 6146     } | 
| 6160     bool simulated_attrib_0 = false; | 6147     bool simulated_attrib_0 = false; | 
| 6161     if (!SimulateAttrib0( | 6148     if (!SimulateAttrib0( | 
| 6162         function_name, max_vertex_accessed, &simulated_attrib_0)) { | 6149         function_name, max_vertex_accessed, &simulated_attrib_0)) { | 
| 6163       return error::kNoError; | 6150       return error::kNoError; | 
| 6164     } | 6151     } | 
| 6165     bool simulated_fixed_attribs = false; | 6152     bool simulated_fixed_attribs = false; | 
| 6166     if (SimulateFixedAttribs( | 6153     if (SimulateFixedAttribs( | 
| 6167         function_name, max_vertex_accessed, &simulated_fixed_attribs, | 6154         function_name, max_vertex_accessed, &simulated_fixed_attribs, | 
| 6168         primcount)) { | 6155         primcount)) { | 
| 6169       bool textures_set = SetBlackTextureForNonRenderableTextures(); | 6156       bool textures_set = SetBlackTextureForNonRenderableTextures(); | 
| 6170       ApplyDirtyState(); | 6157       ApplyDirtyState(); | 
|  | 6158       // TODO(gman): Refactor to hide these details in BufferManager or | 
|  | 6159       // VertexAttribManager. | 
| 6171       const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); | 6160       const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); | 
|  | 6161       bool used_client_side_array = false; | 
|  | 6162       if (element_array_buffer->IsClientSideArray()) { | 
|  | 6163         used_client_side_array = true; | 
|  | 6164         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | 
|  | 6165         indices = element_array_buffer->GetRange(offset, 0); | 
|  | 6166       } | 
|  | 6167 | 
| 6172       if (!instanced) { | 6168       if (!instanced) { | 
| 6173         glDrawElements(mode, count, type, indices); | 6169         glDrawElements(mode, count, type, indices); | 
| 6174       } else { | 6170       } else { | 
| 6175         glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); | 6171         glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); | 
| 6176       } | 6172       } | 
|  | 6173 | 
|  | 6174       if (used_client_side_array) { | 
|  | 6175         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, | 
|  | 6176                      element_array_buffer->service_id()); | 
|  | 6177       } | 
|  | 6178 | 
| 6177       ProcessPendingQueries(); | 6179       ProcessPendingQueries(); | 
| 6178       if (textures_set) { | 6180       if (textures_set) { | 
| 6179         RestoreStateForNonRenderableTextures(); | 6181         RestoreStateForNonRenderableTextures(); | 
| 6180       } | 6182       } | 
| 6181       if (simulated_fixed_attribs) { | 6183       if (simulated_fixed_attribs) { | 
| 6182         RestoreStateForSimulatedFixedAttribs(); | 6184         RestoreStateForSimulatedFixedAttribs(); | 
| 6183       } | 6185       } | 
| 6184     } | 6186     } | 
| 6185     if (simulated_attrib_0) { | 6187     if (simulated_attrib_0) { | 
| 6186       RestoreStateForAttrib(0); | 6188       RestoreStateForAttrib(0); | 
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 7184     return; | 7186     return; | 
| 7185   } | 7187   } | 
| 7186   if (!validators_->buffer_usage.IsValid(usage)) { | 7188   if (!validators_->buffer_usage.IsValid(usage)) { | 
| 7187     SetGLErrorInvalidEnum("glBufferData", usage, "usage"); | 7189     SetGLErrorInvalidEnum("glBufferData", usage, "usage"); | 
| 7188     return; | 7190     return; | 
| 7189   } | 7191   } | 
| 7190   if (size < 0) { | 7192   if (size < 0) { | 
| 7191     SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); | 7193     SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); | 
| 7192     return; | 7194     return; | 
| 7193   } | 7195   } | 
| 7194   Buffer* info = GetBufferInfoForTarget(target); | 7196   Buffer* buffer = GetBufferInfoForTarget(target); | 
| 7195   if (!info) { | 7197   if (!buffer) { | 
| 7196     SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); | 7198     SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); | 
| 7197     return; | 7199     return; | 
| 7198   } | 7200   } | 
| 7199 | 7201 | 
| 7200   if (!EnsureGPUMemoryAvailable(size)) { | 7202   if (!EnsureGPUMemoryAvailable(size)) { | 
| 7201     SetGLError(GL_OUT_OF_MEMORY, "glBufferData", "out of memory"); | 7203     SetGLError(GL_OUT_OF_MEMORY, "glBufferData", "out of memory"); | 
| 7202     return; | 7204     return; | 
| 7203   } | 7205   } | 
| 7204 | 7206 | 
| 7205   // Clear the buffer to 0 if no initial data was passed in. | 7207   buffer_manager()->DoBufferData(this, buffer, size, usage, data); | 
| 7206   scoped_array<int8> zero; |  | 
| 7207   if (!data) { |  | 
| 7208     zero.reset(new int8[size]); |  | 
| 7209     memset(zero.get(), 0, size); |  | 
| 7210     data = zero.get(); |  | 
| 7211   } |  | 
| 7212 |  | 
| 7213   CopyRealGLErrorsToWrapper(); |  | 
| 7214   glBufferData(target, size, data, usage); |  | 
| 7215   GLenum error = PeekGLError(); |  | 
| 7216   if (error == GL_NO_ERROR) { |  | 
| 7217     buffer_manager()->SetInfo(info, size, usage); |  | 
| 7218     info->SetRange(0, size, data); |  | 
| 7219   } else { |  | 
| 7220     buffer_manager()->SetInfo(info, 0, usage); |  | 
| 7221   } |  | 
| 7222 } | 7208 } | 
| 7223 | 7209 | 
| 7224 error::Error GLES2DecoderImpl::HandleBufferData( | 7210 error::Error GLES2DecoderImpl::HandleBufferData( | 
| 7225     uint32 immediate_data_size, const cmds::BufferData& c) { | 7211     uint32 immediate_data_size, const cmds::BufferData& c) { | 
| 7226   GLenum target = static_cast<GLenum>(c.target); | 7212   GLenum target = static_cast<GLenum>(c.target); | 
| 7227   GLsizeiptr size = static_cast<GLsizeiptr>(c.size); | 7213   GLsizeiptr size = static_cast<GLsizeiptr>(c.size); | 
| 7228   uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); | 7214   uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); | 
| 7229   uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); | 7215   uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); | 
| 7230   GLenum usage = static_cast<GLenum>(c.usage); | 7216   GLenum usage = static_cast<GLenum>(c.usage); | 
| 7231   const void* data = NULL; | 7217   const void* data = NULL; | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 7248   if (!data) { | 7234   if (!data) { | 
| 7249     return error::kOutOfBounds; | 7235     return error::kOutOfBounds; | 
| 7250   } | 7236   } | 
| 7251   GLenum usage = static_cast<GLenum>(c.usage); | 7237   GLenum usage = static_cast<GLenum>(c.usage); | 
| 7252   DoBufferData(target, size, data, usage); | 7238   DoBufferData(target, size, data, usage); | 
| 7253   return error::kNoError; | 7239   return error::kNoError; | 
| 7254 } | 7240 } | 
| 7255 | 7241 | 
| 7256 void GLES2DecoderImpl::DoBufferSubData( | 7242 void GLES2DecoderImpl::DoBufferSubData( | 
| 7257   GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { | 7243   GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { | 
| 7258   Buffer* info = GetBufferInfoForTarget(target); | 7244   Buffer* buffer = GetBufferInfoForTarget(target); | 
| 7259   if (!info) { | 7245   if (!buffer) { | 
| 7260     SetGLError(GL_INVALID_VALUE, "glBufferSubData", "unknown buffer"); | 7246     SetGLError(GL_INVALID_VALUE, "glBufferSubData", "unknown buffer"); | 
| 7261     return; | 7247     return; | 
| 7262   } | 7248   } | 
| 7263   if (!info->SetRange(offset, size, data)) { | 7249 | 
| 7264     SetGLError(GL_INVALID_VALUE, "glBufferSubData", "out of range"); | 7250   buffer_manager()->DoBufferSubData(this, buffer, offset, size, data); | 
| 7265     return; |  | 
| 7266   } |  | 
| 7267   glBufferSubData(target, offset, size, data); |  | 
| 7268 } | 7251 } | 
| 7269 | 7252 | 
| 7270 bool GLES2DecoderImpl::ClearLevel( | 7253 bool GLES2DecoderImpl::ClearLevel( | 
| 7271     unsigned service_id, | 7254     unsigned service_id, | 
| 7272     unsigned bind_target, | 7255     unsigned bind_target, | 
| 7273     unsigned target, | 7256     unsigned target, | 
| 7274     int level, | 7257     int level, | 
| 7275     unsigned format, | 7258     unsigned format, | 
| 7276     unsigned type, | 7259     unsigned type, | 
| 7277     int width, | 7260     int width, | 
| (...skipping 2893 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 10171   return error::kNoError; | 10154   return error::kNoError; | 
| 10172 } | 10155 } | 
| 10173 | 10156 | 
| 10174 // Include the auto-generated part of this file. We split this because it means | 10157 // Include the auto-generated part of this file. We split this because it means | 
| 10175 // we can easily edit the non-auto generated parts right here in this file | 10158 // we can easily edit the non-auto generated parts right here in this file | 
| 10176 // instead of having to edit some template or the code generator. | 10159 // instead of having to edit some template or the code generator. | 
| 10177 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10160 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 
| 10178 | 10161 | 
| 10179 }  // namespace gles2 | 10162 }  // namespace gles2 | 
| 10180 }  // namespace gpu | 10163 }  // namespace gpu | 
| OLD | NEW | 
|---|