Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1400)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 10535073: Enforce compressed texture restrictions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size); 490 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size);
491 void UpdateParentTextureInfo(); 491 void UpdateParentTextureInfo();
492 virtual bool MakeCurrent(); 492 virtual bool MakeCurrent();
493 virtual void ReleaseCurrent(); 493 virtual void ReleaseCurrent();
494 virtual GLES2Util* GetGLES2Util() { return &util_; } 494 virtual GLES2Util* GetGLES2Util() { return &util_; }
495 virtual gfx::GLContext* GetGLContext() { return context_.get(); } 495 virtual gfx::GLContext* GetGLContext() { return context_.get(); }
496 virtual ContextGroup* GetContextGroup() { return group_.get(); } 496 virtual ContextGroup* GetContextGroup() { return group_.get(); }
497 virtual QueryManager* GetQueryManager() { return query_manager_.get(); } 497 virtual QueryManager* GetQueryManager() { return query_manager_.get(); }
498 virtual bool ProcessPendingQueries(); 498 virtual bool ProcessPendingQueries();
499 499
500 virtual void SetGLError(GLenum error, const char* msg); 500 virtual void SetGLError(
501 GLenum error, const char* function_name, const char* msg);
501 virtual void SetResizeCallback( 502 virtual void SetResizeCallback(
502 const base::Callback<void(gfx::Size)>& callback); 503 const base::Callback<void(gfx::Size)>& callback);
503 504
504 virtual void SetMsgCallback(const MsgCallback& callback); 505 virtual void SetMsgCallback(const MsgCallback& callback);
505 506
506 virtual void SetStreamTextureManager(StreamTextureManager* manager); 507 virtual void SetStreamTextureManager(StreamTextureManager* manager);
507 virtual bool GetServiceTextureId(uint32 client_texture_id, 508 virtual bool GetServiceTextureId(uint32 client_texture_id,
508 uint32* service_texture_id); 509 uint32* service_texture_id);
509 510
510 // Restores the current state to the user's settings. 511 // Restores the current state to the user's settings.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 return program_manager()->GetProgramInfo(client_id); 771 return program_manager()->GetProgramInfo(client_id);
771 } 772 }
772 773
773 // Gets the program info for the given program. If it's not a program 774 // Gets the program info for the given program. If it's not a program
774 // generates a GL error. Returns NULL if not program. 775 // generates a GL error. Returns NULL if not program.
775 ProgramManager::ProgramInfo* GetProgramInfoNotShader( 776 ProgramManager::ProgramInfo* GetProgramInfoNotShader(
776 GLuint client_id, const char* function_name) { 777 GLuint client_id, const char* function_name) {
777 ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); 778 ProgramManager::ProgramInfo* info = GetProgramInfo(client_id);
778 if (!info) { 779 if (!info) {
779 if (GetShaderInfo(client_id)) { 780 if (GetShaderInfo(client_id)) {
780 SetGLError(GL_INVALID_OPERATION, 781 SetGLError(
781 (std::string(function_name) + 782 GL_INVALID_OPERATION, function_name, "shader passed for program");
782 ": shader passed for program").c_str());
783 } else { 783 } else {
784 SetGLError(GL_INVALID_VALUE, 784 SetGLError(GL_INVALID_VALUE, function_name, "unknown program");
785 (std::string(function_name) + ": unknown program").c_str());
786 } 785 }
787 } 786 }
788 return info; 787 return info;
789 } 788 }
790 789
791 790
792 // Creates a ShaderInfo for the given shader. 791 // Creates a ShaderInfo for the given shader.
793 ShaderManager::ShaderInfo* CreateShaderInfo( 792 ShaderManager::ShaderInfo* CreateShaderInfo(
794 GLuint client_id, 793 GLuint client_id,
795 GLuint service_id, 794 GLuint service_id,
796 GLenum shader_type) { 795 GLenum shader_type) {
797 return shader_manager()->CreateShaderInfo( 796 return shader_manager()->CreateShaderInfo(
798 client_id, service_id, shader_type); 797 client_id, service_id, shader_type);
799 } 798 }
800 799
801 // Gets the shader info for the given shader. Returns NULL if none exists. 800 // Gets the shader info for the given shader. Returns NULL if none exists.
802 ShaderManager::ShaderInfo* GetShaderInfo(GLuint client_id) { 801 ShaderManager::ShaderInfo* GetShaderInfo(GLuint client_id) {
803 return shader_manager()->GetShaderInfo(client_id); 802 return shader_manager()->GetShaderInfo(client_id);
804 } 803 }
805 804
806 // Gets the shader info for the given shader. If it's not a shader generates a 805 // Gets the shader info for the given shader. If it's not a shader generates a
807 // GL error. Returns NULL if not shader. 806 // GL error. Returns NULL if not shader.
808 ShaderManager::ShaderInfo* GetShaderInfoNotProgram( 807 ShaderManager::ShaderInfo* GetShaderInfoNotProgram(
809 GLuint client_id, const char* function_name) { 808 GLuint client_id, const char* function_name) {
810 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); 809 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id);
811 if (!info) { 810 if (!info) {
812 if (GetProgramInfo(client_id)) { 811 if (GetProgramInfo(client_id)) {
813 SetGLError( 812 SetGLError(
814 GL_INVALID_OPERATION, 813 GL_INVALID_OPERATION, function_name, "program passed for shader");
815 (std::string(function_name) +
816 ": program passed for shader").c_str());
817 } else { 814 } else {
818 SetGLError(GL_INVALID_VALUE, 815 SetGLError(
819 (std::string(function_name) + ": unknown shader").c_str()); 816 GL_INVALID_VALUE, function_name, "unknown shader");
820 } 817 }
821 } 818 }
822 return info; 819 return info;
823 } 820 }
824 821
825 // Creates a buffer info for the given buffer. 822 // Creates a buffer info for the given buffer.
826 void CreateBufferInfo(GLuint client_id, GLuint service_id) { 823 void CreateBufferInfo(GLuint client_id, GLuint service_id) {
827 return buffer_manager()->CreateBufferInfo(client_id, service_id); 824 return buffer_manager()->CreateBufferInfo(client_id, service_id);
828 } 825 }
829 826
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 // make sure there are no native GL errors before calling some GL function 1179 // make sure there are no native GL errors before calling some GL function
1183 // so that on return we know any error generated was for that specific 1180 // so that on return we know any error generated was for that specific
1184 // command. 1181 // command.
1185 void CopyRealGLErrorsToWrapper(); 1182 void CopyRealGLErrorsToWrapper();
1186 1183
1187 // Clear all real GL errors. This is to prevent the client from seeing any 1184 // Clear all real GL errors. This is to prevent the client from seeing any
1188 // errors caused by GL calls that it was not responsible for issuing. 1185 // errors caused by GL calls that it was not responsible for issuing.
1189 void ClearRealGLErrors(); 1186 void ClearRealGLErrors();
1190 1187
1191 // Checks if the current program and vertex attributes are valid for drawing. 1188 // Checks if the current program and vertex attributes are valid for drawing.
1192 bool IsDrawValid(GLuint max_vertex_accessed, GLsizei primcount); 1189 bool IsDrawValid(
1190 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount);
1193 1191
1194 // Returns true if successful, simulated will be true if attrib0 was 1192 // Returns true if successful, simulated will be true if attrib0 was
1195 // simulated. 1193 // simulated.
1196 bool SimulateAttrib0( 1194 bool SimulateAttrib0(
1197 GLuint max_vertex_accessed, bool* simulated); 1195 const char* function_name, GLuint max_vertex_accessed, bool* simulated);
1198 void RestoreStateForAttrib(GLuint attrib); 1196 void RestoreStateForAttrib(GLuint attrib);
1199 1197
1200 // Returns true if textures were set. 1198 // Returns true if textures were set.
1201 bool SetBlackTextureForNonRenderableTextures(); 1199 bool SetBlackTextureForNonRenderableTextures();
1202 void RestoreStateForNonRenderableTextures(); 1200 void RestoreStateForNonRenderableTextures();
1203 1201
1204 // Returns true if GL_FIXED attribs were simulated. 1202 // Returns true if GL_FIXED attribs were simulated.
1205 bool SimulateFixedAttribs( 1203 bool SimulateFixedAttribs(
1204 const char* function_name,
1206 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); 1205 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount);
1207 void RestoreStateForSimulatedFixedAttribs(); 1206 void RestoreStateForSimulatedFixedAttribs();
1208 1207
1209 // Handle DrawArrays and DrawElements for both instanced and non-instanced 1208 // Handle DrawArrays and DrawElements for both instanced and non-instanced
1210 // cases (primcount is 0 for non-instanced). 1209 // cases (primcount is 0 for non-instanced).
1211 error::Error DoDrawArrays( 1210 error::Error DoDrawArrays(
1211 const char* function_name,
1212 bool instanced, GLenum mode, GLint first, GLsizei count, 1212 bool instanced, GLenum mode, GLint first, GLsizei count,
1213 GLsizei primcount); 1213 GLsizei primcount);
1214 error::Error DoDrawElements( 1214 error::Error DoDrawElements(
1215 const char* function_name,
1215 bool instanced, GLenum mode, GLsizei count, GLenum type, 1216 bool instanced, GLenum mode, GLsizei count, GLenum type,
1216 int32 offset, GLsizei primcount); 1217 int32 offset, GLsizei primcount);
1217 1218
1218 // Gets the buffer id for a given target. 1219 // Gets the buffer id for a given target.
1219 BufferManager::BufferInfo* GetBufferInfoForTarget(GLenum target) { 1220 BufferManager::BufferInfo* GetBufferInfoForTarget(GLenum target) {
1220 DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER); 1221 DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER);
1221 BufferManager::BufferInfo* info = target == GL_ARRAY_BUFFER ? 1222 BufferManager::BufferInfo* info = target == GL_ARRAY_BUFFER ?
1222 bound_array_buffer_ : bound_element_array_buffer_; 1223 bound_array_buffer_ : bound_element_array_buffer_;
1223 return info; 1224 return info;
1224 } 1225 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 void ReleaseIOSurfaceForTexture(GLuint texture_id); 1325 void ReleaseIOSurfaceForTexture(GLuint texture_id);
1325 #endif 1326 #endif
1326 1327
1327 // Validates the combination of texture parameters. For example validates that 1328 // Validates the combination of texture parameters. For example validates that
1328 // for a given format the specific type, level and targets are valid. 1329 // for a given format the specific type, level and targets are valid.
1329 // Synthesizes the correct GL error if invalid. Returns true if valid. 1330 // Synthesizes the correct GL error if invalid. Returns true if valid.
1330 bool ValidateTextureParameters( 1331 bool ValidateTextureParameters(
1331 const char* function_name, 1332 const char* function_name,
1332 GLenum target, GLenum format, GLenum type, GLint level); 1333 GLenum target, GLenum format, GLenum type, GLint level);
1333 1334
1335 bool ValidateCompressedTexDimensions(
1336 const char* function_name,
1337 GLint level, GLsizei width, GLsizei height, GLenum format);
1338 bool ValidateCompressedTexFuncData(
1339 const char* function_name,
1340 GLsizei width, GLsizei height, GLenum format, size_t size);
1341 bool ValidateCompressedTexSubDimensions(
1342 const char* function_name,
1343 GLenum target, GLint level, GLint xoffset, GLint yoffset,
1344 GLsizei width, GLsizei height, GLenum format,
1345 TextureManager::TextureInfo* texture);
1346
1334 void LogMessage(const std::string& msg); 1347 void LogMessage(const std::string& msg);
1335 void RenderWarning(const std::string& msg); 1348 void RenderWarning(const std::string& msg);
1336 void PerformanceWarning(const std::string& msg); 1349 void PerformanceWarning(const std::string& msg);
1337 1350
1338 // Generate a member function prototype for each command in an automated and 1351 // Generate a member function prototype for each command in an automated and
1339 // typesafe way. 1352 // typesafe way.
1340 #define GLES2_CMD_OP(name) \ 1353 #define GLES2_CMD_OP(name) \
1341 Error Handle ## name( \ 1354 Error Handle ## name( \
1342 uint32 immediate_data_size, \ 1355 uint32 immediate_data_size, \
1343 const gles2::name& args); \ 1356 const gles2::name& args); \
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2579 return true; 2592 return true;
2580 } 2593 }
2581 2594
2582 if (framebuffer_manager()->IsComplete(framebuffer)) { 2595 if (framebuffer_manager()->IsComplete(framebuffer)) {
2583 return true; 2596 return true;
2584 } 2597 }
2585 2598
2586 GLenum completeness = framebuffer->IsPossiblyComplete(); 2599 GLenum completeness = framebuffer->IsPossiblyComplete();
2587 if (completeness != GL_FRAMEBUFFER_COMPLETE) { 2600 if (completeness != GL_FRAMEBUFFER_COMPLETE) {
2588 SetGLError( 2601 SetGLError(
2589 GL_INVALID_FRAMEBUFFER_OPERATION, 2602 GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete");
2590 (std::string(func_name) + " framebuffer incomplete").c_str());
2591 return false; 2603 return false;
2592 } 2604 }
2593 2605
2594 // Are all the attachments cleared? 2606 // Are all the attachments cleared?
2595 if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || 2607 if (renderbuffer_manager()->HaveUnclearedRenderbuffers() ||
2596 texture_manager()->HaveUnclearedMips()) { 2608 texture_manager()->HaveUnclearedMips()) {
2597 if (!framebuffer->IsCleared()) { 2609 if (!framebuffer->IsCleared()) {
2598 // Can we clear them? 2610 // Can we clear them?
2599 if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) { 2611 if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) {
2600 SetGLError( 2612 SetGLError(
2601 GL_INVALID_FRAMEBUFFER_OPERATION, 2613 GL_INVALID_FRAMEBUFFER_OPERATION, func_name,
2602 (std::string(func_name) + 2614 "framebuffer incomplete (clear)");
2603 " framebuffer incomplete (clear)").c_str());
2604 return false; 2615 return false;
2605 } 2616 }
2606 ClearUnclearedAttachments(target, framebuffer); 2617 ClearUnclearedAttachments(target, framebuffer);
2607 } 2618 }
2608 } 2619 }
2609 2620
2610 if (!framebuffer_manager()->IsComplete(framebuffer)) { 2621 if (!framebuffer_manager()->IsComplete(framebuffer)) {
2611 if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) { 2622 if (glCheckFramebufferStatusEXT(target) != GL_FRAMEBUFFER_COMPLETE) {
2612 SetGLError( 2623 SetGLError(
2613 GL_INVALID_FRAMEBUFFER_OPERATION, 2624 GL_INVALID_FRAMEBUFFER_OPERATION, func_name,
2614 (std::string(func_name) + 2625 "framebuffer incomplete (check)");
2615 " framebuffer incomplete (check)").c_str());
2616 return false; 2626 return false;
2617 } 2627 }
2618 framebuffer_manager()->MarkAsComplete(framebuffer); 2628 framebuffer_manager()->MarkAsComplete(framebuffer);
2619 } 2629 }
2620 2630
2621 // NOTE: At this point we don't know if the framebuffer is complete but 2631 // NOTE: At this point we don't know if the framebuffer is complete but
2622 // we DO know that everything that needs to be cleared has been cleared. 2632 // we DO know that everything that needs to be cleared has been cleared.
2623 return true; 2633 return true;
2624 } 2634 }
2625 2635
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
3139 3149
3140 GLES2_COMMAND_LIST(GLES2_CMD_OP) 3150 GLES2_COMMAND_LIST(GLES2_CMD_OP)
3141 #undef GLES2_CMD_OP 3151 #undef GLES2_CMD_OP
3142 } 3152 }
3143 if (debug()) { 3153 if (debug()) {
3144 GLenum error; 3154 GLenum error;
3145 while ((error = glGetError()) != GL_NO_ERROR) { 3155 while ((error = glGetError()) != GL_NO_ERROR) {
3146 LOG(ERROR) << "[" << this << "] " 3156 LOG(ERROR) << "[" << this << "] "
3147 << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : " 3157 << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : "
3148 << GetCommandName(command); 3158 << GetCommandName(command);
3149 SetGLError(error, "GL error from driver"); 3159 SetGLError(error, "DoCommand", "GL error from driver");
3150 } 3160 }
3151 } 3161 }
3152 } else { 3162 } else {
3153 result = error::kInvalidArguments; 3163 result = error::kInvalidArguments;
3154 } 3164 }
3155 } else { 3165 } else {
3156 result = DoCommonCommand(command, arg_count, cmd_data); 3166 result = DoCommonCommand(command, arg_count, cmd_data);
3157 } 3167 }
3158 if (result == error::kNoError && current_decoder_error_ != error::kNoError) { 3168 if (result == error::kNoError && current_decoder_error_ != error::kNoError) {
3159 result = current_decoder_error_; 3169 result = current_decoder_error_;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
3194 } 3204 }
3195 3205
3196 void GLES2DecoderImpl::DoFlush() { 3206 void GLES2DecoderImpl::DoFlush() {
3197 glFlush(); 3207 glFlush();
3198 ProcessPendingQueries(); 3208 ProcessPendingQueries();
3199 } 3209 }
3200 3210
3201 void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { 3211 void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) {
3202 GLuint texture_index = texture_unit - GL_TEXTURE0; 3212 GLuint texture_index = texture_unit - GL_TEXTURE0;
3203 if (texture_index >= group_->max_texture_units()) { 3213 if (texture_index >= group_->max_texture_units()) {
3204 SetGLError(GL_INVALID_ENUM, "glActiveTexture: texture_unit out of range."); 3214 SetGLError(
3215 GL_INVALID_ENUM, "glActiveTexture", "texture_unit out of range.");
3205 return; 3216 return;
3206 } 3217 }
3207 active_texture_unit_ = texture_index; 3218 active_texture_unit_ = texture_index;
3208 glActiveTexture(texture_unit); 3219 glActiveTexture(texture_unit);
3209 } 3220 }
3210 3221
3211 void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { 3222 void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) {
3212 BufferManager::BufferInfo* info = NULL; 3223 BufferManager::BufferInfo* info = NULL;
3213 GLuint service_id = 0; 3224 GLuint service_id = 0;
3214 if (client_id != 0) { 3225 if (client_id != 0) {
(...skipping 10 matching lines...) Expand all
3225 CreateBufferInfo(client_id, service_id); 3236 CreateBufferInfo(client_id, service_id);
3226 info = GetBufferInfo(client_id); 3237 info = GetBufferInfo(client_id);
3227 IdAllocatorInterface* id_allocator = 3238 IdAllocatorInterface* id_allocator =
3228 group_->GetIdAllocator(id_namespaces::kBuffers); 3239 group_->GetIdAllocator(id_namespaces::kBuffers);
3229 id_allocator->MarkAsUsed(client_id); 3240 id_allocator->MarkAsUsed(client_id);
3230 } 3241 }
3231 } 3242 }
3232 if (info) { 3243 if (info) {
3233 if (!buffer_manager()->SetTarget(info, target)) { 3244 if (!buffer_manager()->SetTarget(info, target)) {
3234 SetGLError(GL_INVALID_OPERATION, 3245 SetGLError(GL_INVALID_OPERATION,
3235 "glBindBuffer: buffer bound to more than 1 target"); 3246 "glBindBuffer", "buffer bound to more than 1 target");
3236 return; 3247 return;
3237 } 3248 }
3238 service_id = info->service_id(); 3249 service_id = info->service_id();
3239 } 3250 }
3240 switch (target) { 3251 switch (target) {
3241 case GL_ARRAY_BUFFER: 3252 case GL_ARRAY_BUFFER:
3242 bound_array_buffer_ = info; 3253 bound_array_buffer_ = info;
3243 break; 3254 break;
3244 case GL_ELEMENT_ARRAY_BUFFER: 3255 case GL_ELEMENT_ARRAY_BUFFER:
3245 bound_element_array_buffer_ = info; 3256 bound_element_array_buffer_ = info;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 id_allocator->MarkAsUsed(client_id); 3421 id_allocator->MarkAsUsed(client_id);
3411 } 3422 }
3412 } else { 3423 } else {
3413 info = texture_manager()->GetDefaultTextureInfo(target); 3424 info = texture_manager()->GetDefaultTextureInfo(target);
3414 } 3425 }
3415 3426
3416 // Check the texture exists 3427 // Check the texture exists
3417 // Check that we are not trying to bind it to a different target. 3428 // Check that we are not trying to bind it to a different target.
3418 if (info->target() != 0 && info->target() != target) { 3429 if (info->target() != 0 && info->target() != target) {
3419 SetGLError(GL_INVALID_OPERATION, 3430 SetGLError(GL_INVALID_OPERATION,
3420 "glBindTexture: texture bound to more than 1 target."); 3431 "glBindTexture", "texture bound to more than 1 target.");
3421 return; 3432 return;
3422 } 3433 }
3423 if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { 3434 if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) {
3424 SetGLError(GL_INVALID_OPERATION, 3435 SetGLError(GL_INVALID_OPERATION,
3425 "glBindTexture: illegal target for stream texture."); 3436 "glBindTexture", "illegal target for stream texture.");
3426 return; 3437 return;
3427 } 3438 }
3428 if (info->target() == 0) { 3439 if (info->target() == 0) {
3429 texture_manager()->SetInfoTarget(info, target); 3440 texture_manager()->SetInfoTarget(info, target);
3430 } 3441 }
3431 glBindTexture(target, info->service_id()); 3442 glBindTexture(target, info->service_id());
3432 TextureUnit& unit = texture_units_[active_texture_unit_]; 3443 TextureUnit& unit = texture_units_[active_texture_unit_];
3433 unit.bind_target = target; 3444 unit.bind_target = target;
3434 switch (target) { 3445 switch (target) {
3435 case GL_TEXTURE_2D: 3446 case GL_TEXTURE_2D:
(...skipping 22 matching lines...) Expand all
3458 } 3469 }
3459 3470
3460 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { 3471 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) {
3461 if (vertex_attrib_manager_->Enable(index, false)) { 3472 if (vertex_attrib_manager_->Enable(index, false)) {
3462 if (index != 0 || 3473 if (index != 0 ||
3463 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { 3474 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) {
3464 glDisableVertexAttribArray(index); 3475 glDisableVertexAttribArray(index);
3465 } 3476 }
3466 } else { 3477 } else {
3467 SetGLError(GL_INVALID_VALUE, 3478 SetGLError(GL_INVALID_VALUE,
3468 "glDisableVertexAttribArray: index out of range"); 3479 "glDisableVertexAttribArray", "index out of range");
3469 } 3480 }
3470 } 3481 }
3471 3482
3472 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { 3483 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) {
3473 if (vertex_attrib_manager_->Enable(index, true)) { 3484 if (vertex_attrib_manager_->Enable(index, true)) {
3474 glEnableVertexAttribArray(index); 3485 glEnableVertexAttribArray(index);
3475 } else { 3486 } else {
3476 SetGLError(GL_INVALID_VALUE, 3487 SetGLError(GL_INVALID_VALUE,
3477 "glEnableVertexAttribArray: index out of range"); 3488 "glEnableVertexAttribArray", "index out of range");
3478 } 3489 }
3479 } 3490 }
3480 3491
3481 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { 3492 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) {
3482 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 3493 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
3483 if (!info || 3494 if (!info ||
3484 !texture_manager()->CanGenerateMipmaps(info)) { 3495 !texture_manager()->CanGenerateMipmaps(info)) {
3485 SetGLError(GL_INVALID_OPERATION, 3496 SetGLError(GL_INVALID_OPERATION,
3486 "glGenerateMipmaps: Can not generate mips"); 3497 "glGenerateMipmaps", "Can not generate mips");
3487 return; 3498 return;
3488 } 3499 }
3489 3500
3490 if (!texture_manager()->ClearTextureLevel(this, info, target, 0)) { 3501 if (!texture_manager()->ClearTextureLevel(this, info, target, 0)) {
3491 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps: dimensions too big"); 3502 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big");
3492 return; 3503 return;
3493 } 3504 }
3494 3505
3495 CopyRealGLErrorsToWrapper(); 3506 CopyRealGLErrorsToWrapper();
3496 // Workaround for Mac driver bug. In the large scheme of things setting 3507 // Workaround for Mac driver bug. In the large scheme of things setting
3497 // glTexParamter twice for glGenerateMipmap is probably not a lage performance 3508 // glTexParamter twice for glGenerateMipmap is probably not a lage performance
3498 // hit so there's probably no need to make this conditional. The bug appears 3509 // hit so there's probably no need to make this conditional. The bug appears
3499 // to be that if the filtering mode is set to something that doesn't require 3510 // to be that if the filtering mode is set to something that doesn't require
3500 // mipmaps for rendering, or is never set to something other than the default, 3511 // mipmaps for rendering, or is never set to something other than the default,
3501 // then glGenerateMipmap misbehaves. 3512 // then glGenerateMipmap misbehaves.
3502 if (!disable_workarounds_) { 3513 if (!disable_workarounds_) {
3503 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 3514 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3504 } 3515 }
3505 glGenerateMipmapEXT(target); 3516 glGenerateMipmapEXT(target);
3506 if (!disable_workarounds_) { 3517 if (!disable_workarounds_) {
3507 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter()); 3518 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter());
3508 } 3519 }
3509 GLenum error = PeekGLError(); 3520 GLenum error = PeekGLError();
3510 if (error == GL_NO_ERROR) { 3521 if (error == GL_NO_ERROR) {
3511 texture_manager()->MarkMipmapsGenerated(info); 3522 texture_manager()->MarkMipmapsGenerated(info);
3512 } 3523 }
3513 } 3524 }
3514 3525
3515 bool GLES2DecoderImpl::GetHelper( 3526 bool GLES2DecoderImpl::GetHelper(
3516 GLenum pname, GLint* params, GLsizei* num_written) { 3527 GLenum pname, GLint* params, GLsizei* num_written) {
3517 DCHECK(num_written); 3528 DCHECK(num_written);
3518 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 3529 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
3519 switch (pname) { 3530 switch (pname) {
3520 case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 3531 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
3521 *num_written = 1; 3532 *num_written = 1;
3522 if (params) { 3533 if (params) {
3523 *params = GL_RGBA; // We don't support other formats. 3534 *params = GL_RGBA; // We don't support other formats.
3535 }
3536 return true;
3537 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
3538 *num_written = 1;
3539 if (params) {
3540 *params = GL_UNSIGNED_BYTE; // We don't support other types.
3541 }
3542 return true;
3543 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
3544 *num_written = 1;
3545 if (params) {
3546 *params = group_->max_fragment_uniform_vectors();
3547 }
3548 return true;
3549 case GL_MAX_VARYING_VECTORS:
3550 *num_written = 1;
3551 if (params) {
3552 *params = group_->max_varying_vectors();
3553 }
3554 return true;
3555 case GL_MAX_VERTEX_UNIFORM_VECTORS:
3556 *num_written = 1;
3557 if (params) {
3558 *params = group_->max_vertex_uniform_vectors();
3559 }
3560 return true;
3524 } 3561 }
3525 return true;
3526 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
3527 *num_written = 1;
3528 if (params) {
3529 *params = GL_UNSIGNED_BYTE; // We don't support other types.
3530 }
3531 return true;
3532 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
3533 *num_written = 1;
3534 if (params) {
3535 *params = group_->max_fragment_uniform_vectors();
3536 }
3537 return true;
3538 case GL_MAX_VARYING_VECTORS:
3539 *num_written = 1;
3540 if (params) {
3541 *params = group_->max_varying_vectors();
3542 }
3543 return true;
3544 case GL_MAX_VERTEX_UNIFORM_VECTORS:
3545 *num_written = 1;
3546 if (params) {
3547 *params = group_->max_vertex_uniform_vectors();
3548 }
3549 return true;
3550 }
3551 } 3562 }
3552 switch (pname) { 3563 switch (pname) {
3553 case GL_MAX_VIEWPORT_DIMS: 3564 case GL_MAX_VIEWPORT_DIMS:
3554 if (offscreen_target_frame_buffer_.get()) { 3565 if (offscreen_target_frame_buffer_.get()) {
3555 *num_written = 2; 3566 *num_written = 2;
3556 if (params) { 3567 if (params) {
3557 params[0] = renderbuffer_manager()->max_renderbuffer_size(); 3568 params[0] = renderbuffer_manager()->max_renderbuffer_size();
3558 params[1] = renderbuffer_manager()->max_renderbuffer_size(); 3569 params[1] = renderbuffer_manager()->max_renderbuffer_size();
3559 } 3570 }
3560 return true; 3571 return true;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
3876 program_id, "glGetProgramiv"); 3887 program_id, "glGetProgramiv");
3877 if (!info) { 3888 if (!info) {
3878 return; 3889 return;
3879 } 3890 }
3880 info->GetProgramiv(pname, params); 3891 info->GetProgramiv(pname, params);
3881 } 3892 }
3882 3893
3883 void GLES2DecoderImpl::DoBindAttribLocation( 3894 void GLES2DecoderImpl::DoBindAttribLocation(
3884 GLuint program, GLuint index, const char* name) { 3895 GLuint program, GLuint index, const char* name) {
3885 if (!StringIsValidForGLES(name)) { 3896 if (!StringIsValidForGLES(name)) {
3886 SetGLError(GL_INVALID_VALUE, "glBindAttribLocation: Invalid character"); 3897 SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character");
3887 return; 3898 return;
3888 } 3899 }
3889 if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { 3900 if (ProgramManager::IsInvalidPrefix(name, strlen(name))) {
3890 SetGLError(GL_INVALID_OPERATION, "glBindAttribLocation: reserved prefix"); 3901 SetGLError(GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix");
3891 return; 3902 return;
3892 } 3903 }
3893 if (index >= group_->max_vertex_attribs()) { 3904 if (index >= group_->max_vertex_attribs()) {
3894 SetGLError(GL_INVALID_VALUE, "glBindAttribLocation: index out of range"); 3905 SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "index out of range");
3895 return; 3906 return;
3896 } 3907 }
3897 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 3908 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
3898 program, "glBindAttribLocation"); 3909 program, "glBindAttribLocation");
3899 if (!info) { 3910 if (!info) {
3900 return; 3911 return;
3901 } 3912 }
3902 info->SetAttribLocationBinding(name, static_cast<GLint>(index)); 3913 info->SetAttribLocationBinding(name, static_cast<GLint>(index));
3903 glBindAttribLocation(info->service_id(), index, name); 3914 glBindAttribLocation(info->service_id(), index, name);
3904 } 3915 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3953 uint32 immediate_data_size, const gles2::DeleteShader& c) { 3964 uint32 immediate_data_size, const gles2::DeleteShader& c) {
3954 GLuint client_id = c.shader; 3965 GLuint client_id = c.shader;
3955 if (client_id) { 3966 if (client_id) {
3956 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); 3967 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id);
3957 if (info) { 3968 if (info) {
3958 if (!info->IsDeleted()) { 3969 if (!info->IsDeleted()) {
3959 glDeleteShader(info->service_id()); 3970 glDeleteShader(info->service_id());
3960 shader_manager()->MarkAsDeleted(info); 3971 shader_manager()->MarkAsDeleted(info);
3961 } 3972 }
3962 } else { 3973 } else {
3963 SetGLError(GL_INVALID_VALUE, "glDeleteShader: unknown shader"); 3974 SetGLError(GL_INVALID_VALUE, "glDeleteShader", "unknown shader");
3964 } 3975 }
3965 } 3976 }
3966 return error::kNoError; 3977 return error::kNoError;
3967 } 3978 }
3968 3979
3969 error::Error GLES2DecoderImpl::HandleDeleteProgram( 3980 error::Error GLES2DecoderImpl::HandleDeleteProgram(
3970 uint32 immediate_data_size, const gles2::DeleteProgram& c) { 3981 uint32 immediate_data_size, const gles2::DeleteProgram& c) {
3971 GLuint client_id = c.program; 3982 GLuint client_id = c.program;
3972 if (client_id) { 3983 if (client_id) {
3973 ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); 3984 ProgramManager::ProgramInfo* info = GetProgramInfo(client_id);
3974 if (info) { 3985 if (info) {
3975 if (!info->IsDeleted()) { 3986 if (!info->IsDeleted()) {
3976 program_manager()->MarkAsDeleted(shader_manager(), info); 3987 program_manager()->MarkAsDeleted(shader_manager(), info);
3977 } 3988 }
3978 } else { 3989 } else {
3979 SetGLError(GL_INVALID_VALUE, "glDeleteProgram: unknown program"); 3990 SetGLError(GL_INVALID_VALUE, "glDeleteProgram", "unknown program");
3980 } 3991 }
3981 } 3992 }
3982 return error::kNoError; 3993 return error::kNoError;
3983 } 3994 }
3984 3995
3985 void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( 3996 void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM(
3986 GLuint namespace_id, GLsizei n, const GLuint* ids) { 3997 GLuint namespace_id, GLsizei n, const GLuint* ids) {
3987 IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); 3998 IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id);
3988 for (GLsizei ii = 0; ii < n; ++ii) { 3999 for (GLsizei ii = 0; ii < n; ++ii) {
3989 id_allocator->FreeID(ids[ii]); 4000 id_allocator->FreeID(ids[ii]);
3990 } 4001 }
3991 } 4002 }
3992 4003
3993 error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( 4004 error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM(
3994 uint32 immediate_data_size, const gles2::DeleteSharedIdsCHROMIUM& c) { 4005 uint32 immediate_data_size, const gles2::DeleteSharedIdsCHROMIUM& c) {
3995 GLuint namespace_id = static_cast<GLuint>(c.namespace_id); 4006 GLuint namespace_id = static_cast<GLuint>(c.namespace_id);
3996 GLsizei n = static_cast<GLsizei>(c.n); 4007 GLsizei n = static_cast<GLsizei>(c.n);
3997 uint32 data_size; 4008 uint32 data_size;
3998 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { 4009 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
3999 return error::kOutOfBounds; 4010 return error::kOutOfBounds;
4000 } 4011 }
4001 const GLuint* ids = GetSharedMemoryAs<const GLuint*>( 4012 const GLuint* ids = GetSharedMemoryAs<const GLuint*>(
4002 c.ids_shm_id, c.ids_shm_offset, data_size); 4013 c.ids_shm_id, c.ids_shm_offset, data_size);
4003 if (n < 0) { 4014 if (n < 0) {
4004 SetGLError(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM: n < 0"); 4015 SetGLError(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM", "n < 0");
4005 return error::kNoError; 4016 return error::kNoError;
4006 } 4017 }
4007 if (ids == NULL) { 4018 if (ids == NULL) {
4008 return error::kOutOfBounds; 4019 return error::kOutOfBounds;
4009 } 4020 }
4010 DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids); 4021 DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids);
4011 return error::kNoError; 4022 return error::kNoError;
4012 } 4023 }
4013 4024
4014 void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( 4025 void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM(
(...skipping 16 matching lines...) Expand all
4031 GLuint namespace_id = static_cast<GLuint>(c.namespace_id); 4042 GLuint namespace_id = static_cast<GLuint>(c.namespace_id);
4032 GLuint id_offset = static_cast<GLuint>(c.id_offset); 4043 GLuint id_offset = static_cast<GLuint>(c.id_offset);
4033 GLsizei n = static_cast<GLsizei>(c.n); 4044 GLsizei n = static_cast<GLsizei>(c.n);
4034 uint32 data_size; 4045 uint32 data_size;
4035 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { 4046 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
4036 return error::kOutOfBounds; 4047 return error::kOutOfBounds;
4037 } 4048 }
4038 GLuint* ids = GetSharedMemoryAs<GLuint*>( 4049 GLuint* ids = GetSharedMemoryAs<GLuint*>(
4039 c.ids_shm_id, c.ids_shm_offset, data_size); 4050 c.ids_shm_id, c.ids_shm_offset, data_size);
4040 if (n < 0) { 4051 if (n < 0) {
4041 SetGLError(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM: n < 0"); 4052 SetGLError(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM", "n < 0");
4042 return error::kNoError; 4053 return error::kNoError;
4043 } 4054 }
4044 if (ids == NULL) { 4055 if (ids == NULL) {
4045 return error::kOutOfBounds; 4056 return error::kOutOfBounds;
4046 } 4057 }
4047 DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids); 4058 DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids);
4048 return error::kNoError; 4059 return error::kNoError;
4049 } 4060 }
4050 4061
4051 void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( 4062 void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM(
4052 GLuint namespace_id, GLsizei n, const GLuint* ids) { 4063 GLuint namespace_id, GLsizei n, const GLuint* ids) {
4053 IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); 4064 IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id);
4054 for (GLsizei ii = 0; ii < n; ++ii) { 4065 for (GLsizei ii = 0; ii < n; ++ii) {
4055 if (!id_allocator->MarkAsUsed(ids[ii])) { 4066 if (!id_allocator->MarkAsUsed(ids[ii])) {
4056 for (GLsizei jj = 0; jj < ii; ++jj) { 4067 for (GLsizei jj = 0; jj < ii; ++jj) {
4057 id_allocator->FreeID(ids[jj]); 4068 id_allocator->FreeID(ids[jj]);
4058 } 4069 }
4059 SetGLError( 4070 SetGLError(
4060 GL_INVALID_VALUE, 4071 GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM",
4061 "RegisterSharedIdsCHROMIUM: attempt to register " 4072 "attempt to register id that already exists");
4062 "id that already exists");
4063 return; 4073 return;
4064 } 4074 }
4065 } 4075 }
4066 } 4076 }
4067 4077
4068 error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM( 4078 error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM(
4069 uint32 immediate_data_size, const gles2::RegisterSharedIdsCHROMIUM& c) { 4079 uint32 immediate_data_size, const gles2::RegisterSharedIdsCHROMIUM& c) {
4070 GLuint namespace_id = static_cast<GLuint>(c.namespace_id); 4080 GLuint namespace_id = static_cast<GLuint>(c.namespace_id);
4071 GLsizei n = static_cast<GLsizei>(c.n); 4081 GLsizei n = static_cast<GLsizei>(c.n);
4072 uint32 data_size; 4082 uint32 data_size;
4073 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { 4083 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
4074 return error::kOutOfBounds; 4084 return error::kOutOfBounds;
4075 } 4085 }
4076 GLuint* ids = GetSharedMemoryAs<GLuint*>( 4086 GLuint* ids = GetSharedMemoryAs<GLuint*>(
4077 c.ids_shm_id, c.ids_shm_offset, data_size); 4087 c.ids_shm_id, c.ids_shm_offset, data_size);
4078 if (n < 0) { 4088 if (n < 0) {
4079 SetGLError(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM: n < 0"); 4089 SetGLError(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", "n < 0");
4080 return error::kNoError; 4090 return error::kNoError;
4081 } 4091 }
4082 if (ids == NULL) { 4092 if (ids == NULL) {
4083 return error::kOutOfBounds; 4093 return error::kOutOfBounds;
4084 } 4094 }
4085 DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); 4095 DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids);
4086 return error::kNoError; 4096 return error::kNoError;
4087 } 4097 }
4088 4098
4089 void GLES2DecoderImpl::DoClear(GLbitfield mask) { 4099 void GLES2DecoderImpl::DoClear(GLbitfield mask) {
4090 if (CheckBoundFramebuffersValid("glClear")) { 4100 if (CheckBoundFramebuffersValid("glClear")) {
4091 UNSHIPPED_TRACE_EVENT_INSTANT2("test_gpu", "DoClear", "red", clear_red_, 4101 UNSHIPPED_TRACE_EVENT_INSTANT2("test_gpu", "DoClear", "red", clear_red_,
4092 "green", clear_green_); 4102 "green", clear_green_);
4093 ApplyDirtyState(); 4103 ApplyDirtyState();
4094 glClear(mask); 4104 glClear(mask);
4095 } 4105 }
4096 } 4106 }
4097 4107
4098 void GLES2DecoderImpl::DoFramebufferRenderbuffer( 4108 void GLES2DecoderImpl::DoFramebufferRenderbuffer(
4099 GLenum target, GLenum attachment, GLenum renderbuffertarget, 4109 GLenum target, GLenum attachment, GLenum renderbuffertarget,
4100 GLuint client_renderbuffer_id) { 4110 GLuint client_renderbuffer_id) {
4101 FramebufferManager::FramebufferInfo* framebuffer_info = 4111 FramebufferManager::FramebufferInfo* framebuffer_info =
4102 GetFramebufferInfoForTarget(target); 4112 GetFramebufferInfoForTarget(target);
4103 if (!framebuffer_info) { 4113 if (!framebuffer_info) {
4104 SetGLError(GL_INVALID_OPERATION, 4114 SetGLError(GL_INVALID_OPERATION,
4105 "glFramebufferRenderbuffer: no framebuffer bound"); 4115 "glFramebufferRenderbuffer", "no framebuffer bound");
4106 return; 4116 return;
4107 } 4117 }
4108 GLuint service_id = 0; 4118 GLuint service_id = 0;
4109 RenderbufferManager::RenderbufferInfo* info = NULL; 4119 RenderbufferManager::RenderbufferInfo* info = NULL;
4110 if (client_renderbuffer_id) { 4120 if (client_renderbuffer_id) {
4111 info = GetRenderbufferInfo(client_renderbuffer_id); 4121 info = GetRenderbufferInfo(client_renderbuffer_id);
4112 if (!info) { 4122 if (!info) {
4113 SetGLError(GL_INVALID_OPERATION, 4123 SetGLError(GL_INVALID_OPERATION,
4114 "glFramebufferRenderbuffer: unknown renderbuffer"); 4124 "glFramebufferRenderbuffer", "unknown renderbuffer");
4115 return; 4125 return;
4116 } 4126 }
4117 service_id = info->service_id(); 4127 service_id = info->service_id();
4118 } 4128 }
4119 CopyRealGLErrorsToWrapper(); 4129 CopyRealGLErrorsToWrapper();
4120 glFramebufferRenderbufferEXT( 4130 glFramebufferRenderbufferEXT(
4121 target, attachment, renderbuffertarget, service_id); 4131 target, attachment, renderbuffertarget, service_id);
4122 GLenum error = PeekGLError(); 4132 GLenum error = PeekGLError();
4123 if (error == GL_NO_ERROR) { 4133 if (error == GL_NO_ERROR) {
4124 framebuffer_info->AttachRenderbuffer(attachment, info); 4134 framebuffer_info->AttachRenderbuffer(attachment, info);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
4311 return glCheckFramebufferStatusEXT(target); 4321 return glCheckFramebufferStatusEXT(target);
4312 } 4322 }
4313 4323
4314 void GLES2DecoderImpl::DoFramebufferTexture2D( 4324 void GLES2DecoderImpl::DoFramebufferTexture2D(
4315 GLenum target, GLenum attachment, GLenum textarget, 4325 GLenum target, GLenum attachment, GLenum textarget,
4316 GLuint client_texture_id, GLint level) { 4326 GLuint client_texture_id, GLint level) {
4317 FramebufferManager::FramebufferInfo* framebuffer_info = 4327 FramebufferManager::FramebufferInfo* framebuffer_info =
4318 GetFramebufferInfoForTarget(target); 4328 GetFramebufferInfoForTarget(target);
4319 if (!framebuffer_info) { 4329 if (!framebuffer_info) {
4320 SetGLError(GL_INVALID_OPERATION, 4330 SetGLError(GL_INVALID_OPERATION,
4321 "glFramebufferTexture2D: no framebuffer bound."); 4331 "glFramebufferTexture2D", "no framebuffer bound.");
4322 return; 4332 return;
4323 } 4333 }
4324 GLuint service_id = 0; 4334 GLuint service_id = 0;
4325 TextureManager::TextureInfo* info = NULL; 4335 TextureManager::TextureInfo* info = NULL;
4326 if (client_texture_id) { 4336 if (client_texture_id) {
4327 info = GetTextureInfo(client_texture_id); 4337 info = GetTextureInfo(client_texture_id);
4328 if (!info) { 4338 if (!info) {
4329 SetGLError(GL_INVALID_OPERATION, 4339 SetGLError(GL_INVALID_OPERATION,
4330 "glFramebufferTexture2D: unknown texture"); 4340 "glFramebufferTexture2D", "unknown texture");
4331 return; 4341 return;
4332 } 4342 }
4333 service_id = info->service_id(); 4343 service_id = info->service_id();
4334 } 4344 }
4335 4345
4336 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { 4346 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) {
4337 SetGLError(GL_INVALID_VALUE, 4347 SetGLError(GL_INVALID_VALUE,
4338 "glFramebufferTexture2D: level out of range"); 4348 "glFramebufferTexture2D", "level out of range");
4339 return; 4349 return;
4340 } 4350 }
4341 4351
4342 CopyRealGLErrorsToWrapper(); 4352 CopyRealGLErrorsToWrapper();
4343 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); 4353 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level);
4344 GLenum error = PeekGLError(); 4354 GLenum error = PeekGLError();
4345 if (error == GL_NO_ERROR) { 4355 if (error == GL_NO_ERROR) {
4346 framebuffer_info->AttachTexture(attachment, info, textarget, level); 4356 framebuffer_info->AttachTexture(attachment, info, textarget, level);
4347 } 4357 }
4348 if (framebuffer_info == bound_draw_framebuffer_) { 4358 if (framebuffer_info == bound_draw_framebuffer_) {
4349 state_dirty_ = true; 4359 state_dirty_ = true;
4350 } 4360 }
4351 } 4361 }
4352 4362
4353 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( 4363 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv(
4354 GLenum target, GLenum attachment, GLenum pname, GLint* params) { 4364 GLenum target, GLenum attachment, GLenum pname, GLint* params) {
4355 FramebufferManager::FramebufferInfo* framebuffer_info = 4365 FramebufferManager::FramebufferInfo* framebuffer_info =
4356 GetFramebufferInfoForTarget(target); 4366 GetFramebufferInfoForTarget(target);
4357 if (!framebuffer_info) { 4367 if (!framebuffer_info) {
4358 SetGLError(GL_INVALID_OPERATION, 4368 SetGLError(GL_INVALID_OPERATION,
4359 "glFramebufferAttachmentParameteriv: no framebuffer bound"); 4369 "glFramebufferAttachmentParameteriv", "no framebuffer bound");
4360 return; 4370 return;
4361 } 4371 }
4362 glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); 4372 glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params);
4363 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { 4373 if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) {
4364 GLint type = 0; 4374 GLint type = 0;
4365 GLuint client_id = 0; 4375 GLuint client_id = 0;
4366 glGetFramebufferAttachmentParameterivEXT( 4376 glGetFramebufferAttachmentParameterivEXT(
4367 target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); 4377 target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type);
4368 switch (type) { 4378 switch (type) {
4369 case GL_RENDERBUFFER: { 4379 case GL_RENDERBUFFER: {
(...skipping 10 matching lines...) Expand all
4380 *params = client_id; 4390 *params = client_id;
4381 } 4391 }
4382 } 4392 }
4383 4393
4384 void GLES2DecoderImpl::DoGetRenderbufferParameteriv( 4394 void GLES2DecoderImpl::DoGetRenderbufferParameteriv(
4385 GLenum target, GLenum pname, GLint* params) { 4395 GLenum target, GLenum pname, GLint* params) {
4386 RenderbufferManager::RenderbufferInfo* renderbuffer = 4396 RenderbufferManager::RenderbufferInfo* renderbuffer =
4387 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); 4397 GetRenderbufferInfoForTarget(GL_RENDERBUFFER);
4388 if (!renderbuffer) { 4398 if (!renderbuffer) {
4389 SetGLError(GL_INVALID_OPERATION, 4399 SetGLError(GL_INVALID_OPERATION,
4390 "glGetRenderbufferParameteriv: no renderbuffer bound"); 4400 "glGetRenderbufferParameteriv", "no renderbuffer bound");
4391 return; 4401 return;
4392 } 4402 }
4393 switch (pname) { 4403 switch (pname) {
4394 case GL_RENDERBUFFER_INTERNAL_FORMAT: 4404 case GL_RENDERBUFFER_INTERNAL_FORMAT:
4395 *params = renderbuffer->internal_format(); 4405 *params = renderbuffer->internal_format();
4396 break; 4406 break;
4397 case GL_RENDERBUFFER_WIDTH: 4407 case GL_RENDERBUFFER_WIDTH:
4398 *params = renderbuffer->width(); 4408 *params = renderbuffer->width();
4399 break; 4409 break;
4400 case GL_RENDERBUFFER_HEIGHT: 4410 case GL_RENDERBUFFER_HEIGHT:
4401 *params = renderbuffer->height(); 4411 *params = renderbuffer->height();
4402 break; 4412 break;
4403 default: 4413 default:
4404 glGetRenderbufferParameterivEXT(target, pname, params); 4414 glGetRenderbufferParameterivEXT(target, pname, params);
4405 break; 4415 break;
4406 } 4416 }
4407 } 4417 }
4408 4418
4409 void GLES2DecoderImpl::DoBlitFramebufferEXT( 4419 void GLES2DecoderImpl::DoBlitFramebufferEXT(
4410 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, 4420 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
4411 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, 4421 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
4412 GLbitfield mask, GLenum filter) { 4422 GLbitfield mask, GLenum filter) {
4413 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { 4423 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) {
4414 SetGLError(GL_INVALID_OPERATION, 4424 SetGLError(GL_INVALID_OPERATION,
4415 "glBlitFramebufferEXT: function not available"); 4425 "glBlitFramebufferEXT", "function not available");
4416 } 4426 }
4417 if (IsAngle()) { 4427 if (IsAngle()) {
4418 glBlitFramebufferANGLE( 4428 glBlitFramebufferANGLE(
4419 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); 4429 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
4420 } else { 4430 } else {
4421 glBlitFramebufferEXT( 4431 glBlitFramebufferEXT(
4422 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); 4432 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
4423 } 4433 }
4424 UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "DoBlit", "width", srcX1 - srcX0); 4434 UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "DoBlit", "width", srcX1 - srcX0);
4425 } 4435 }
4426 4436
4427 void GLES2DecoderImpl::DoRenderbufferStorageMultisample( 4437 void GLES2DecoderImpl::DoRenderbufferStorageMultisample(
4428 GLenum target, GLsizei samples, GLenum internalformat, 4438 GLenum target, GLsizei samples, GLenum internalformat,
4429 GLsizei width, GLsizei height) { 4439 GLsizei width, GLsizei height) {
4430 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) { 4440 if (!feature_info_->feature_flags().chromium_framebuffer_multisample) {
4431 SetGLError(GL_INVALID_OPERATION, 4441 SetGLError(GL_INVALID_OPERATION,
4432 "glRenderbufferStorageMultisampleEXT: function not available"); 4442 "glRenderbufferStorageMultisampleEXT", "function not available");
4433 return; 4443 return;
4434 } 4444 }
4435 4445
4436 RenderbufferManager::RenderbufferInfo* renderbuffer = 4446 RenderbufferManager::RenderbufferInfo* renderbuffer =
4437 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); 4447 GetRenderbufferInfoForTarget(GL_RENDERBUFFER);
4438 if (!renderbuffer) { 4448 if (!renderbuffer) {
4439 SetGLError(GL_INVALID_OPERATION, 4449 SetGLError(GL_INVALID_OPERATION,
4440 "glGetRenderbufferStorageMultisample: no renderbuffer bound"); 4450 "glGetRenderbufferStorageMultisample", "no renderbuffer bound");
4441 return; 4451 return;
4442 } 4452 }
4443 4453
4444 if (samples > renderbuffer_manager()->max_samples()) { 4454 if (samples > renderbuffer_manager()->max_samples()) {
4445 SetGLError(GL_INVALID_VALUE, 4455 SetGLError(GL_INVALID_VALUE,
4446 "glGetRenderbufferStorageMultisample: samples too large"); 4456 "glGetRenderbufferStorageMultisample", "samples too large");
4447 return; 4457 return;
4448 } 4458 }
4449 4459
4450 if (width > renderbuffer_manager()->max_renderbuffer_size() || 4460 if (width > renderbuffer_manager()->max_renderbuffer_size() ||
4451 height > renderbuffer_manager()->max_renderbuffer_size()) { 4461 height > renderbuffer_manager()->max_renderbuffer_size()) {
4452 SetGLError(GL_INVALID_VALUE, 4462 SetGLError(GL_INVALID_VALUE,
4453 "glGetRenderbufferStorageMultisample: size too large"); 4463 "glGetRenderbufferStorageMultisample", "size too large");
4454 return; 4464 return;
4455 } 4465 }
4456 4466
4457 GLenum impl_format = internalformat; 4467 GLenum impl_format = internalformat;
4458 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 4468 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
4459 switch (impl_format) { 4469 switch (impl_format) {
4460 case GL_DEPTH_COMPONENT16: 4470 case GL_DEPTH_COMPONENT16:
4461 impl_format = GL_DEPTH_COMPONENT; 4471 impl_format = GL_DEPTH_COMPONENT;
4462 break; 4472 break;
4463 case GL_RGBA4: 4473 case GL_RGBA4:
(...skipping 23 matching lines...) Expand all
4487 renderbuffer, samples, internalformat, width, height); 4497 renderbuffer, samples, internalformat, width, height);
4488 } 4498 }
4489 } 4499 }
4490 4500
4491 void GLES2DecoderImpl::DoRenderbufferStorage( 4501 void GLES2DecoderImpl::DoRenderbufferStorage(
4492 GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { 4502 GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {
4493 RenderbufferManager::RenderbufferInfo* renderbuffer = 4503 RenderbufferManager::RenderbufferInfo* renderbuffer =
4494 GetRenderbufferInfoForTarget(GL_RENDERBUFFER); 4504 GetRenderbufferInfoForTarget(GL_RENDERBUFFER);
4495 if (!renderbuffer) { 4505 if (!renderbuffer) {
4496 SetGLError(GL_INVALID_OPERATION, 4506 SetGLError(GL_INVALID_OPERATION,
4497 "glGetRenderbufferStorage: no renderbuffer bound"); 4507 "glGetRenderbufferStorage", "no renderbuffer bound");
4498 return; 4508 return;
4499 } 4509 }
4500 4510
4501 if (width > renderbuffer_manager()->max_renderbuffer_size() || 4511 if (width > renderbuffer_manager()->max_renderbuffer_size() ||
4502 height > renderbuffer_manager()->max_renderbuffer_size()) { 4512 height > renderbuffer_manager()->max_renderbuffer_size()) {
4503 SetGLError(GL_INVALID_VALUE, 4513 SetGLError(GL_INVALID_VALUE,
4504 "glGetRenderbufferStorage: size too large"); 4514 "glGetRenderbufferStorage", "size too large");
4505 return; 4515 return;
4506 } 4516 }
4507 4517
4508 GLenum impl_format = internalformat; 4518 GLenum impl_format = internalformat;
4509 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 4519 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
4510 switch (impl_format) { 4520 switch (impl_format) {
4511 case GL_DEPTH_COMPONENT16: 4521 case GL_DEPTH_COMPONENT16:
4512 impl_format = GL_DEPTH_COMPONENT; 4522 impl_format = GL_DEPTH_COMPONENT;
4513 break; 4523 break;
4514 case GL_RGBA4: 4524 case GL_RGBA4:
(...skipping 30 matching lines...) Expand all
4545 if (info == current_program_.get()) { 4555 if (info == current_program_.get()) {
4546 program_manager()->ClearUniforms(info); 4556 program_manager()->ClearUniforms(info);
4547 } 4557 }
4548 } 4558 }
4549 }; 4559 };
4550 4560
4551 void GLES2DecoderImpl::DoTexParameterf( 4561 void GLES2DecoderImpl::DoTexParameterf(
4552 GLenum target, GLenum pname, GLfloat param) { 4562 GLenum target, GLenum pname, GLfloat param) {
4553 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 4563 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
4554 if (!info) { 4564 if (!info) {
4555 SetGLError(GL_INVALID_VALUE, "glTexParameterf: unknown texture"); 4565 SetGLError(GL_INVALID_VALUE, "glTexParameterf", "unknown texture");
4556 return; 4566 return;
4557 } 4567 }
4558 4568
4559 if (!texture_manager()->SetParameter( 4569 if (!texture_manager()->SetParameter(
4560 info, pname, static_cast<GLint>(param))) { 4570 info, pname, static_cast<GLint>(param))) {
4561 SetGLError(GL_INVALID_ENUM, "glTexParameterf: param GL_INVALID_ENUM"); 4571 SetGLError(GL_INVALID_ENUM, "glTexParameterf", "param GL_INVALID_ENUM");
4562 return; 4572 return;
4563 } 4573 }
4564 glTexParameterf(target, pname, param); 4574 glTexParameterf(target, pname, param);
4565 } 4575 }
4566 4576
4567 void GLES2DecoderImpl::DoTexParameteri( 4577 void GLES2DecoderImpl::DoTexParameteri(
4568 GLenum target, GLenum pname, GLint param) { 4578 GLenum target, GLenum pname, GLint param) {
4569 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 4579 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
4570 if (!info) { 4580 if (!info) {
4571 SetGLError(GL_INVALID_VALUE, "glTexParameteri: unknown texture"); 4581 SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture");
4572 return; 4582 return;
4573 } 4583 }
4574 4584
4575 if (!texture_manager()->SetParameter(info, pname, param)) { 4585 if (!texture_manager()->SetParameter(info, pname, param)) {
4576 SetGLError(GL_INVALID_ENUM, "glTexParameteri: param GL_INVALID_ENUM"); 4586 SetGLError(GL_INVALID_ENUM, "glTexParameteri", "param GL_INVALID_ENUM");
4577 return; 4587 return;
4578 } 4588 }
4579 glTexParameteri(target, pname, param); 4589 glTexParameteri(target, pname, param);
4580 } 4590 }
4581 4591
4582 void GLES2DecoderImpl::DoTexParameterfv( 4592 void GLES2DecoderImpl::DoTexParameterfv(
4583 GLenum target, GLenum pname, const GLfloat* params) { 4593 GLenum target, GLenum pname, const GLfloat* params) {
4584 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 4594 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
4585 if (!info) { 4595 if (!info) {
4586 SetGLError(GL_INVALID_VALUE, "glTexParameterfv: unknown texture"); 4596 SetGLError(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture");
4587 return; 4597 return;
4588 } 4598 }
4589 4599
4590 if (!texture_manager()->SetParameter( 4600 if (!texture_manager()->SetParameter(
4591 info, pname, static_cast<GLint>(params[0]))) { 4601 info, pname, static_cast<GLint>(params[0]))) {
4592 SetGLError(GL_INVALID_ENUM, "glTexParameterfv: param GL_INVALID_ENUM"); 4602 SetGLError(GL_INVALID_ENUM, "glTexParameterfv", "param GL_INVALID_ENUM");
4593 return; 4603 return;
4594 } 4604 }
4595 glTexParameterfv(target, pname, params); 4605 glTexParameterfv(target, pname, params);
4596 } 4606 }
4597 4607
4598 void GLES2DecoderImpl::DoTexParameteriv( 4608 void GLES2DecoderImpl::DoTexParameteriv(
4599 GLenum target, GLenum pname, const GLint* params) { 4609 GLenum target, GLenum pname, const GLint* params) {
4600 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 4610 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
4601 if (!info) { 4611 if (!info) {
4602 SetGLError(GL_INVALID_VALUE, "glTexParameteriv: unknown texture"); 4612 SetGLError(GL_INVALID_VALUE, "glTexParameteriv", "unknown texture");
4603 return; 4613 return;
4604 } 4614 }
4605 4615
4606 if (!texture_manager()->SetParameter(info, pname, *params)) { 4616 if (!texture_manager()->SetParameter(info, pname, *params)) {
4607 SetGLError(GL_INVALID_ENUM, "glTexParameteriv: param GL_INVALID_ENUM"); 4617 SetGLError(GL_INVALID_ENUM, "glTexParameteriv", "param GL_INVALID_ENUM");
4608 return; 4618 return;
4609 } 4619 }
4610 glTexParameteriv(target, pname, params); 4620 glTexParameteriv(target, pname, params);
4611 } 4621 }
4612 4622
4613 bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { 4623 bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) {
4614 if (!current_program_) { 4624 if (!current_program_) {
4615 // The program does not exist. 4625 // The program does not exist.
4616 SetGLError(GL_INVALID_OPERATION, 4626 SetGLError(GL_INVALID_OPERATION, function_name, "no program in use");
4617 (std::string(function_name) + ": no program in use").c_str()); 4627 return false;
4618 return false;
4619 } 4628 }
4620 if (!current_program_->InUse()) { 4629 if (!current_program_->InUse()) {
4621 SetGLError(GL_INVALID_OPERATION, 4630 SetGLError(GL_INVALID_OPERATION, function_name, "program not linked");
4622 (std::string(function_name) + ": program not linked").c_str());
4623 return false; 4631 return false;
4624 } 4632 }
4625 return true; 4633 return true;
4626 } 4634 }
4627 4635
4628 bool GLES2DecoderImpl::CheckCurrentProgramForUniform( 4636 bool GLES2DecoderImpl::CheckCurrentProgramForUniform(
4629 GLint location, const char* function_name) { 4637 GLint location, const char* function_name) {
4630 if (!CheckCurrentProgram(function_name)) { 4638 if (!CheckCurrentProgram(function_name)) {
4631 return false; 4639 return false;
4632 } 4640 }
4633 return location != -1; 4641 return location != -1;
4634 } 4642 }
4635 4643
4636 bool GLES2DecoderImpl::PrepForSetUniformByLocation( 4644 bool GLES2DecoderImpl::PrepForSetUniformByLocation(
4637 GLint fake_location, const char* function_name, 4645 GLint fake_location, const char* function_name,
4638 GLint* real_location, GLenum* type, GLsizei* count) { 4646 GLint* real_location, GLenum* type, GLsizei* count) {
4639 DCHECK(type); 4647 DCHECK(type);
4640 DCHECK(count); 4648 DCHECK(count);
4641 DCHECK(real_location); 4649 DCHECK(real_location);
4642 if (!CheckCurrentProgramForUniform(fake_location, function_name)) { 4650 if (!CheckCurrentProgramForUniform(fake_location, function_name)) {
4643 return false; 4651 return false;
4644 } 4652 }
4645 GLint array_index = -1; 4653 GLint array_index = -1;
4646 const ProgramManager::ProgramInfo::UniformInfo* info = 4654 const ProgramManager::ProgramInfo::UniformInfo* info =
4647 current_program_->GetUniformInfoByFakeLocation( 4655 current_program_->GetUniformInfoByFakeLocation(
4648 fake_location, real_location, &array_index); 4656 fake_location, real_location, &array_index);
4649 if (!info) { 4657 if (!info) {
4650 SetGLError(GL_INVALID_OPERATION, 4658 SetGLError(GL_INVALID_OPERATION, function_name, "unknown location");
4651 (std::string(function_name) + ": unknown location").c_str());
4652 return false; 4659 return false;
4653 } 4660 }
4654 if (*count > 1 && !info->is_array) { 4661 if (*count > 1 && !info->is_array) {
4655 SetGLError( 4662 SetGLError(
4656 GL_INVALID_OPERATION, 4663 GL_INVALID_OPERATION, function_name, "count > 1 for non-array");
4657 (std::string(function_name) + ": count > 1 for non-array").c_str());
4658 return false; 4664 return false;
4659 } 4665 }
4660 *count = std::min(info->size - array_index, *count); 4666 *count = std::min(info->size - array_index, *count);
4661 if (*count <= 0) { 4667 if (*count <= 0) {
4662 return false; 4668 return false;
4663 } 4669 }
4664 *type = info->type; 4670 *type = info->type;
4665 return true; 4671 return true;
4666 } 4672 }
4667 4673
4668 void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { 4674 void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) {
4669 GLenum type = 0; 4675 GLenum type = 0;
4670 GLsizei count = 1; 4676 GLsizei count = 1;
4671 GLint real_location = -1; 4677 GLint real_location = -1;
4672 if (!PrepForSetUniformByLocation( 4678 if (!PrepForSetUniformByLocation(
4673 fake_location, "glUniform1iv", &real_location, &type, &count)) { 4679 fake_location, "glUniform1iv", &real_location, &type, &count)) {
4674 return; 4680 return;
4675 } 4681 }
4676 if (!current_program_->SetSamplers( 4682 if (!current_program_->SetSamplers(
4677 group_->max_texture_units(), fake_location, 1, &v0)) { 4683 group_->max_texture_units(), fake_location, 1, &v0)) {
4678 SetGLError(GL_INVALID_VALUE, "glUniform1i: texture unit out of range"); 4684 SetGLError(GL_INVALID_VALUE, "glUniform1i", "texture unit out of range");
4679 return; 4685 return;
4680 } 4686 }
4681 glUniform1i(real_location, v0); 4687 glUniform1i(real_location, v0);
4682 } 4688 }
4683 4689
4684 void GLES2DecoderImpl::DoUniform1iv( 4690 void GLES2DecoderImpl::DoUniform1iv(
4685 GLint fake_location, GLsizei count, const GLint *value) { 4691 GLint fake_location, GLsizei count, const GLint *value) {
4686 GLenum type = 0; 4692 GLenum type = 0;
4687 GLint real_location = -1; 4693 GLint real_location = -1;
4688 if (!PrepForSetUniformByLocation( 4694 if (!PrepForSetUniformByLocation(
4689 fake_location, "glUniform1iv", &real_location, &type, &count)) { 4695 fake_location, "glUniform1iv", &real_location, &type, &count)) {
4690 return; 4696 return;
4691 } 4697 }
4692 if (type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || 4698 if (type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
4693 type == GL_SAMPLER_EXTERNAL_OES) { 4699 type == GL_SAMPLER_EXTERNAL_OES) {
4694 if (!current_program_->SetSamplers( 4700 if (!current_program_->SetSamplers(
4695 group_->max_texture_units(), fake_location, count, value)) { 4701 group_->max_texture_units(), fake_location, count, value)) {
4696 SetGLError(GL_INVALID_VALUE, "glUniform1iv: texture unit out of range"); 4702 SetGLError(GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range");
4697 return; 4703 return;
4698 } 4704 }
4699 } 4705 }
4700 glUniform1iv(real_location, count, value); 4706 glUniform1iv(real_location, count, value);
4701 } 4707 }
4702 4708
4703 void GLES2DecoderImpl::DoUniform1fv( 4709 void GLES2DecoderImpl::DoUniform1fv(
4704 GLint fake_location, GLsizei count, const GLfloat* value) { 4710 GLint fake_location, GLsizei count, const GLfloat* value) {
4705 GLenum type = 0; 4711 GLenum type = 0;
4706 GLint real_location = -1; 4712 GLint real_location = -1;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
4851 void GLES2DecoderImpl::DoUseProgram(GLuint program) { 4857 void GLES2DecoderImpl::DoUseProgram(GLuint program) {
4852 GLuint service_id = 0; 4858 GLuint service_id = 0;
4853 ProgramManager::ProgramInfo* info = NULL; 4859 ProgramManager::ProgramInfo* info = NULL;
4854 if (program) { 4860 if (program) {
4855 info = GetProgramInfoNotShader(program, "glUseProgram"); 4861 info = GetProgramInfoNotShader(program, "glUseProgram");
4856 if (!info) { 4862 if (!info) {
4857 return; 4863 return;
4858 } 4864 }
4859 if (!info->IsValid()) { 4865 if (!info->IsValid()) {
4860 // Program was not linked successfully. (ie, glLinkProgram) 4866 // Program was not linked successfully. (ie, glLinkProgram)
4861 SetGLError(GL_INVALID_OPERATION, "glUseProgram: program not linked"); 4867 SetGLError(GL_INVALID_OPERATION, "glUseProgram", "program not linked");
4862 return; 4868 return;
4863 } 4869 }
4864 service_id = info->service_id(); 4870 service_id = info->service_id();
4865 } 4871 }
4866 if (current_program_) { 4872 if (current_program_) {
4867 program_manager()->UnuseProgram(shader_manager(), current_program_); 4873 program_manager()->UnuseProgram(shader_manager(), current_program_);
4868 } 4874 }
4869 current_program_ = info; 4875 current_program_ = info;
4870 glUseProgram(service_id); 4876 glUseProgram(service_id);
4871 if (current_program_) { 4877 if (current_program_) {
(...skipping 16 matching lines...) Expand all
4888 if (error != GL_NO_ERROR) { 4894 if (error != GL_NO_ERROR) {
4889 // There was an error, clear the corresponding wrapped error. 4895 // There was an error, clear the corresponding wrapped error.
4890 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); 4896 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error);
4891 } 4897 }
4892 return error; 4898 return error;
4893 } 4899 }
4894 4900
4895 GLenum GLES2DecoderImpl::PeekGLError() { 4901 GLenum GLES2DecoderImpl::PeekGLError() {
4896 GLenum error = glGetError(); 4902 GLenum error = glGetError();
4897 if (error != GL_NO_ERROR) { 4903 if (error != GL_NO_ERROR) {
4898 SetGLError(error, ""); 4904 SetGLError(error, "", "");
4899 } 4905 }
4900 return error; 4906 return error;
4901 } 4907 }
4902 4908
4903 void GLES2DecoderImpl::SetGLError(GLenum error, const char* msg) { 4909 void GLES2DecoderImpl::SetGLError(
4910 GLenum error, const char* function_name, const char* msg) {
4904 if (msg) { 4911 if (msg) {
4905 last_error_ = msg; 4912 last_error_ = msg;
4906 LogMessage(std::string("GL ERROR :") + 4913 LogMessage(std::string("GL ERROR :") +
4907 GLES2Util::GetStringEnum(error) + " : " + msg); 4914 GLES2Util::GetStringEnum(error) + " : " +
4915 function_name + ": " + msg);
4908 } 4916 }
4909 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); 4917 error_bits_ |= GLES2Util::GLErrorToErrorBit(error);
4910 } 4918 }
4911 4919
4912 void GLES2DecoderImpl::LogMessage(const std::string& msg) { 4920 void GLES2DecoderImpl::LogMessage(const std::string& msg) {
4913 if (log_message_count_ < kMaxLogMessages || 4921 if (log_message_count_ < kMaxLogMessages ||
4914 CommandLine::ForCurrentProcess()->HasSwitch( 4922 CommandLine::ForCurrentProcess()->HasSwitch(
4915 switches::kDisableGLErrorLimit)) { 4923 switches::kDisableGLErrorLimit)) {
4916 ++log_message_count_; 4924 ++log_message_count_;
4917 // LOG this unless logging is turned off as any chromium code that 4925 // LOG this unless logging is turned off as any chromium code that
(...skipping 18 matching lines...) Expand all
4936 LogMessage(std::string("RENDER WARNING: ") + msg); 4944 LogMessage(std::string("RENDER WARNING: ") + msg);
4937 } 4945 }
4938 4946
4939 void GLES2DecoderImpl::PerformanceWarning(const std::string& msg) { 4947 void GLES2DecoderImpl::PerformanceWarning(const std::string& msg) {
4940 LogMessage(std::string("PERFORMANCE WARNING: ") + msg); 4948 LogMessage(std::string("PERFORMANCE WARNING: ") + msg);
4941 } 4949 }
4942 4950
4943 void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() { 4951 void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() {
4944 GLenum error; 4952 GLenum error;
4945 while ((error = glGetError()) != GL_NO_ERROR) { 4953 while ((error = glGetError()) != GL_NO_ERROR) {
4946 SetGLError(error, NULL); 4954 SetGLError(error, "", NULL);
4947 } 4955 }
4948 } 4956 }
4949 4957
4950 void GLES2DecoderImpl::ClearRealGLErrors() { 4958 void GLES2DecoderImpl::ClearRealGLErrors() {
4951 GLenum error; 4959 GLenum error;
4952 while ((error = glGetError()) != GL_NO_ERROR) { 4960 while ((error = glGetError()) != GL_NO_ERROR) {
4953 if (error != GL_OUT_OF_MEMORY) { 4961 if (error != GL_OUT_OF_MEMORY) {
4954 // GL_OUT_OF_MEMORY can legally happen on lost device. 4962 // GL_OUT_OF_MEMORY can legally happen on lost device.
4955 NOTREACHED() << "GL error " << error << " was unhandled."; 4963 NOTREACHED() << "GL error " << error << " was unhandled.";
4956 } 4964 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5054 } 5062 }
5055 } 5063 }
5056 } 5064 }
5057 } 5065 }
5058 } 5066 }
5059 } 5067 }
5060 return true; 5068 return true;
5061 } 5069 }
5062 5070
5063 bool GLES2DecoderImpl::IsDrawValid( 5071 bool GLES2DecoderImpl::IsDrawValid(
5064 GLuint max_vertex_accessed, GLsizei primcount) { 5072 const char* function_name, GLuint max_vertex_accessed, GLsizei primcount) {
5065 // NOTE: We specifically do not check current_program->IsValid() because 5073 // NOTE: We specifically do not check current_program->IsValid() because
5066 // it could never be invalid since glUseProgram would have failed. While 5074 // it could never be invalid since glUseProgram would have failed. While
5067 // glLinkProgram could later mark the program as invalid the previous 5075 // glLinkProgram could later mark the program as invalid the previous
5068 // valid program will still function if it is still the current program. 5076 // valid program will still function if it is still the current program.
5069 if (!current_program_) { 5077 if (!current_program_) {
5070 // The program does not exist. 5078 // The program does not exist.
5071 // But GL says no ERROR. 5079 // But GL says no ERROR.
5072 RenderWarning("Drawing with no current shader program."); 5080 RenderWarning("Drawing with no current shader program.");
5073 return false; 5081 return false;
5074 } 5082 }
(...skipping 10 matching lines...) Expand all
5085 infos.begin(); it != infos.end(); ++it) { 5093 infos.begin(); it != infos.end(); ++it) {
5086 const VertexAttribManager::VertexAttribInfo* info = *it; 5094 const VertexAttribManager::VertexAttribInfo* info = *it;
5087 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = 5095 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info =
5088 current_program_->GetAttribInfoByLocation(info->index()); 5096 current_program_->GetAttribInfoByLocation(info->index());
5089 if (attrib_info) { 5097 if (attrib_info) {
5090 divisor0 |= (info->divisor() == 0); 5098 divisor0 |= (info->divisor() == 0);
5091 GLuint count = info->MaxVertexAccessed(primcount, max_vertex_accessed); 5099 GLuint count = info->MaxVertexAccessed(primcount, max_vertex_accessed);
5092 // This attrib is used in the current program. 5100 // This attrib is used in the current program.
5093 if (!info->CanAccess(count)) { 5101 if (!info->CanAccess(count)) {
5094 SetGLError( 5102 SetGLError(
5095 GL_INVALID_OPERATION, 5103 GL_INVALID_OPERATION, function_name,
5096 (std::string( 5104 (std::string(
5097 "glDrawXXX: attempt to access out of range vertices in " 5105 "attempt to access out of range vertices in attribute ") +
5098 "attribute ") + base::IntToString(info->index())).c_str()); 5106 base::IntToString(info->index())).c_str());
5099 return false; 5107 return false;
5100 } 5108 }
5101 } else { 5109 } else {
5102 // This attrib is not used in the current program. 5110 // This attrib is not used in the current program.
5103 if (!info->buffer()) { 5111 if (!info->buffer()) {
5104 SetGLError( 5112 SetGLError(
5105 GL_INVALID_OPERATION, 5113 GL_INVALID_OPERATION, function_name,
5106 (std::string( 5114 (std::string(
5107 "glDrawXXX: attempt to render with no buffer attached to " 5115 "attempt to render with no buffer attached to "
5108 "enabled attribute ") + 5116 "enabled attribute ") +
5109 base::IntToString(info->index())).c_str()); 5117 base::IntToString(info->index())).c_str());
5110 return false; 5118 return false;
5111 } 5119 }
5112 } 5120 }
5113 } 5121 }
5114 5122
5115 if (primcount && !divisor0) { 5123 if (primcount && !divisor0) {
5116 SetGLError( 5124 SetGLError(
5117 GL_INVALID_OPERATION, 5125 GL_INVALID_OPERATION, function_name,
5118 "glDrawXXX: attempt instanced render with all attributes having " 5126 "attempt instanced render with all attributes having "
5119 "non-zero divisors"); 5127 "non-zero divisors");
5120 return false; 5128 return false;
5121 } 5129 }
5122 5130
5123 return true; 5131 return true;
5124 } 5132 }
5125 5133
5126 bool GLES2DecoderImpl::SimulateAttrib0( 5134 bool GLES2DecoderImpl::SimulateAttrib0(
5127 GLuint max_vertex_accessed, bool* simulated) { 5135 const char* function_name, GLuint max_vertex_accessed, bool* simulated) {
5128 DCHECK(simulated); 5136 DCHECK(simulated);
5129 *simulated = false; 5137 *simulated = false;
5130 5138
5131 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) 5139 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2)
5132 return true; 5140 return true;
5133 5141
5134 const VertexAttribManager::VertexAttribInfo* info = 5142 const VertexAttribManager::VertexAttribInfo* info =
5135 vertex_attrib_manager_->GetVertexAttribInfo(0); 5143 vertex_attrib_manager_->GetVertexAttribInfo(0);
5136 // If it's enabled or it's not used then we don't need to do anything. 5144 // If it's enabled or it's not used then we don't need to do anything.
5137 bool attrib_0_used = current_program_->GetAttribInfoByLocation(0) != NULL; 5145 bool attrib_0_used = current_program_->GetAttribInfoByLocation(0) != NULL;
5138 if (info->enabled() && attrib_0_used) { 5146 if (info->enabled() && attrib_0_used) {
5139 return true; 5147 return true;
5140 } 5148 }
5141 5149
5142 // Make a buffer with a single repeated vec4 value enough to 5150 // Make a buffer with a single repeated vec4 value enough to
5143 // simulate the constant value that is supposed to be here. 5151 // simulate the constant value that is supposed to be here.
5144 // This is required to emulate GLES2 on GL. 5152 // This is required to emulate GLES2 on GL.
5145 typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4; 5153 typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4;
5146 5154
5147 GLuint num_vertices = max_vertex_accessed + 1; 5155 GLuint num_vertices = max_vertex_accessed + 1;
5148 GLuint size_needed = 0; 5156 GLuint size_needed = 0;
5149 5157
5150 if (num_vertices == 0 || 5158 if (num_vertices == 0 ||
5151 !SafeMultiply(num_vertices, static_cast<GLuint>(sizeof(Vec4)), 5159 !SafeMultiply(num_vertices, static_cast<GLuint>(sizeof(Vec4)),
5152 &size_needed) || 5160 &size_needed) ||
5153 size_needed > 0x7FFFFFFFU) { 5161 size_needed > 0x7FFFFFFFU) {
5154 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); 5162 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5155 return false; 5163 return false;
5156 } 5164 }
5157 5165
5158 PerformanceWarning( 5166 PerformanceWarning(
5159 "Attribute 0 is disabled. This has signficant performance penalty"); 5167 "Attribute 0 is disabled. This has signficant performance penalty");
5160 5168
5161 CopyRealGLErrorsToWrapper(); 5169 CopyRealGLErrorsToWrapper();
5162 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); 5170 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_);
5163 5171
5164 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; 5172 bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_;
5165 if (new_buffer) { 5173 if (new_buffer) {
5166 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); 5174 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW);
5167 GLenum error = glGetError(); 5175 GLenum error = glGetError();
5168 if (error != GL_NO_ERROR) { 5176 if (error != GL_NO_ERROR) {
5169 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); 5177 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5170 return false; 5178 return false;
5171 } 5179 }
5172 } 5180 }
5173 if (new_buffer || 5181 if (new_buffer ||
5174 (attrib_0_used && 5182 (attrib_0_used &&
5175 (!attrib_0_buffer_matches_value_ || 5183 (!attrib_0_buffer_matches_value_ ||
5176 (info->value().v[0] != attrib_0_value_.v[0] || 5184 (info->value().v[0] != attrib_0_value_.v[0] ||
5177 info->value().v[1] != attrib_0_value_.v[1] || 5185 info->value().v[1] != attrib_0_value_.v[1] ||
5178 info->value().v[2] != attrib_0_value_.v[2] || 5186 info->value().v[2] != attrib_0_value_.v[2] ||
5179 info->value().v[3] != attrib_0_value_.v[3])))) { 5187 info->value().v[3] != attrib_0_value_.v[3])))) {
(...skipping 28 matching lines...) Expand all
5208 bound_array_buffer_ ? bound_array_buffer_->service_id() : 0); 5216 bound_array_buffer_ ? bound_array_buffer_->service_id() : 0);
5209 5217
5210 if (info->enabled()) { 5218 if (info->enabled()) {
5211 glEnableVertexAttribArray(attrib); 5219 glEnableVertexAttribArray(attrib);
5212 } else { 5220 } else {
5213 glDisableVertexAttribArray(attrib); 5221 glDisableVertexAttribArray(attrib);
5214 } 5222 }
5215 } 5223 }
5216 5224
5217 bool GLES2DecoderImpl::SimulateFixedAttribs( 5225 bool GLES2DecoderImpl::SimulateFixedAttribs(
5226 const char* function_name,
5218 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { 5227 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) {
5219 DCHECK(simulated); 5228 DCHECK(simulated);
5220 *simulated = false; 5229 *simulated = false;
5221 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) 5230 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2)
5222 return true; 5231 return true;
5223 5232
5224 if (!vertex_attrib_manager_->HaveFixedAttribs()) { 5233 if (!vertex_attrib_manager_->HaveFixedAttribs()) {
5225 return true; 5234 return true;
5226 } 5235 }
5227 5236
(...skipping 11 matching lines...) Expand all
5239 vertex_attrib_manager_->GetEnabledVertexAttribInfos(); 5248 vertex_attrib_manager_->GetEnabledVertexAttribInfos();
5240 for (VertexAttribManager::VertexAttribInfoList::const_iterator it = 5249 for (VertexAttribManager::VertexAttribInfoList::const_iterator it =
5241 infos.begin(); it != infos.end(); ++it) { 5250 infos.begin(); it != infos.end(); ++it) {
5242 const VertexAttribManager::VertexAttribInfo* info = *it; 5251 const VertexAttribManager::VertexAttribInfo* info = *it;
5243 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = 5252 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info =
5244 current_program_->GetAttribInfoByLocation(info->index()); 5253 current_program_->GetAttribInfoByLocation(info->index());
5245 GLuint max_accessed = info->MaxVertexAccessed(primcount, 5254 GLuint max_accessed = info->MaxVertexAccessed(primcount,
5246 max_vertex_accessed); 5255 max_vertex_accessed);
5247 GLuint num_vertices = max_accessed + 1; 5256 GLuint num_vertices = max_accessed + 1;
5248 if (num_vertices == 0) { 5257 if (num_vertices == 0) {
5249 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); 5258 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5250 return false; 5259 return false;
5251 } 5260 }
5252 if (attrib_info && 5261 if (attrib_info &&
5253 info->CanAccess(max_accessed) && 5262 info->CanAccess(max_accessed) &&
5254 info->type() == GL_FIXED) { 5263 info->type() == GL_FIXED) {
5255 GLuint elements_used = 0; 5264 GLuint elements_used = 0;
5256 if (!SafeMultiply(num_vertices, 5265 if (!SafeMultiply(num_vertices,
5257 static_cast<GLuint>(info->size()), &elements_used) || 5266 static_cast<GLuint>(info->size()), &elements_used) ||
5258 !SafeAdd(elements_needed, elements_used, &elements_needed)) { 5267 !SafeAdd(elements_needed, elements_used, &elements_needed)) {
5259 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); 5268 SetGLError(
5269 GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs");
5260 return false; 5270 return false;
5261 } 5271 }
5262 } 5272 }
5263 } 5273 }
5264 5274
5265 const GLuint kSizeOfFloat = sizeof(float); // NOLINT 5275 const GLuint kSizeOfFloat = sizeof(float); // NOLINT
5266 GLuint size_needed = 0; 5276 GLuint size_needed = 0;
5267 if (!SafeMultiply(elements_needed, kSizeOfFloat, &size_needed) || 5277 if (!SafeMultiply(elements_needed, kSizeOfFloat, &size_needed) ||
5268 size_needed > 0x7FFFFFFFU) { 5278 size_needed > 0x7FFFFFFFU) {
5269 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); 5279 SetGLError(GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs");
5270 return false; 5280 return false;
5271 } 5281 }
5272 5282
5273 CopyRealGLErrorsToWrapper(); 5283 CopyRealGLErrorsToWrapper();
5274 5284
5275 glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); 5285 glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_);
5276 if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { 5286 if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) {
5277 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); 5287 glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW);
5278 GLenum error = glGetError(); 5288 GLenum error = glGetError();
5279 if (error != GL_NO_ERROR) { 5289 if (error != GL_NO_ERROR) {
5280 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: simulating GL_FIXED attribs"); 5290 SetGLError(
5291 GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs");
5281 return false; 5292 return false;
5282 } 5293 }
5283 } 5294 }
5284 5295
5285 // Copy the elements and convert to float 5296 // Copy the elements and convert to float
5286 GLintptr offset = 0; 5297 GLintptr offset = 0;
5287 for (VertexAttribManager::VertexAttribInfoList::const_iterator it = 5298 for (VertexAttribManager::VertexAttribInfoList::const_iterator it =
5288 infos.begin(); it != infos.end(); ++it) { 5299 infos.begin(); it != infos.end(); ++it) {
5289 const VertexAttribManager::VertexAttribInfo* info = *it; 5300 const VertexAttribManager::VertexAttribInfo* info = *it;
5290 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = 5301 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info =
5291 current_program_->GetAttribInfoByLocation(info->index()); 5302 current_program_->GetAttribInfoByLocation(info->index());
5292 GLuint max_accessed = info->MaxVertexAccessed(primcount, 5303 GLuint max_accessed = info->MaxVertexAccessed(primcount,
5293 max_vertex_accessed); 5304 max_vertex_accessed);
5294 GLuint num_vertices = max_accessed + 1; 5305 GLuint num_vertices = max_accessed + 1;
5295 if (num_vertices == 0) { 5306 if (num_vertices == 0) {
5296 SetGLError(GL_OUT_OF_MEMORY, "glDrawXXX: Simulating attrib 0"); 5307 SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0");
5297 return false; 5308 return false;
5298 } 5309 }
5299 if (attrib_info && 5310 if (attrib_info &&
5300 info->CanAccess(max_accessed) && 5311 info->CanAccess(max_accessed) &&
5301 info->type() == GL_FIXED) { 5312 info->type() == GL_FIXED) {
5302 int num_elements = info->size() * kSizeOfFloat; 5313 int num_elements = info->size() * kSizeOfFloat;
5303 int size = num_elements * num_vertices; 5314 int size = num_elements * num_vertices;
5304 scoped_array<float> data(new float[size]); 5315 scoped_array<float> data(new float[size]);
5305 const int32* src = reinterpret_cast<const int32 *>( 5316 const int32* src = reinterpret_cast<const int32 *>(
5306 info->buffer()->GetRange(info->offset(), size)); 5317 info->buffer()->GetRange(info->offset(), size));
(...skipping 13 matching lines...) Expand all
5320 return true; 5331 return true;
5321 } 5332 }
5322 5333
5323 void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { 5334 void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() {
5324 // There's no need to call glVertexAttribPointer because we shadow all the 5335 // There's no need to call glVertexAttribPointer because we shadow all the
5325 // settings and passing GL_FIXED to it will not work. 5336 // settings and passing GL_FIXED to it will not work.
5326 glBindBuffer(GL_ARRAY_BUFFER, 5337 glBindBuffer(GL_ARRAY_BUFFER,
5327 bound_array_buffer_ ? bound_array_buffer_->service_id() : 0); 5338 bound_array_buffer_ ? bound_array_buffer_->service_id() : 0);
5328 } 5339 }
5329 5340
5330 error::Error GLES2DecoderImpl::DoDrawArrays(bool instanced, 5341 error::Error GLES2DecoderImpl::DoDrawArrays(
5331 GLenum mode, 5342 const char* function_name,
5332 GLint first, 5343 bool instanced,
5333 GLsizei count, 5344 GLenum mode,
5334 GLsizei primcount) { 5345 GLint first,
5346 GLsizei count,
5347 GLsizei primcount) {
5335 if (!validators_->draw_mode.IsValid(mode)) { 5348 if (!validators_->draw_mode.IsValid(mode)) {
5336 SetGLError(GL_INVALID_ENUM, "glDrawArrays: mode GL_INVALID_ENUM"); 5349 SetGLError(GL_INVALID_ENUM, function_name, "mode GL_INVALID_ENUM");
5337 return error::kNoError; 5350 return error::kNoError;
5338 } 5351 }
5339 if (count < 0) { 5352 if (count < 0) {
5340 SetGLError(GL_INVALID_VALUE, "glDrawArrays: count < 0"); 5353 SetGLError(GL_INVALID_VALUE, function_name, "count < 0");
5341 return error::kNoError; 5354 return error::kNoError;
5342 } 5355 }
5343 if (primcount < 0) { 5356 if (primcount < 0) {
5344 SetGLError(GL_INVALID_VALUE, "glDrawArrays: primcount < 0"); 5357 SetGLError(GL_INVALID_VALUE, function_name, "primcount < 0");
5345 return error::kNoError; 5358 return error::kNoError;
5346 } 5359 }
5347 if (!CheckBoundFramebuffersValid("glDrawArrays")) { 5360 if (!CheckBoundFramebuffersValid(function_name)) {
5348 return error::kNoError; 5361 return error::kNoError;
5349 } 5362 }
5350 // We have to check this here because the prototype for glDrawArrays 5363 // We have to check this here because the prototype for glDrawArrays
5351 // is GLint not GLsizei. 5364 // is GLint not GLsizei.
5352 if (first < 0) { 5365 if (first < 0) {
5353 SetGLError(GL_INVALID_VALUE, "glDrawArrays: first < 0"); 5366 SetGLError(GL_INVALID_VALUE, function_name, "first < 0");
5354 return error::kNoError; 5367 return error::kNoError;
5355 } 5368 }
5356 5369
5357 if (count == 0 || (instanced && primcount == 0)) { 5370 if (count == 0 || (instanced && primcount == 0)) {
5358 RenderWarning("Render count or primcount is 0."); 5371 RenderWarning("Render count or primcount is 0.");
5359 return error::kNoError; 5372 return error::kNoError;
5360 } 5373 }
5361 5374
5362 GLuint max_vertex_accessed = first + count - 1; 5375 GLuint max_vertex_accessed = first + count - 1;
5363 if (IsDrawValid(max_vertex_accessed, primcount)) { 5376 if (IsDrawValid(function_name, max_vertex_accessed, primcount)) {
5364 if (!ClearUnclearedTextures()) { 5377 if (!ClearUnclearedTextures()) {
5365 SetGLError(GL_INVALID_VALUE, "glDrawArrays: out of memory"); 5378 SetGLError(GL_INVALID_VALUE, function_name, "out of memory");
5366 return error::kNoError; 5379 return error::kNoError;
5367 } 5380 }
5368 bool simulated_attrib_0 = false; 5381 bool simulated_attrib_0 = false;
5369 if (!SimulateAttrib0(max_vertex_accessed, &simulated_attrib_0)) { 5382 if (!SimulateAttrib0(
5383 function_name, max_vertex_accessed, &simulated_attrib_0)) {
5370 return error::kNoError; 5384 return error::kNoError;
5371 } 5385 }
5372 bool simulated_fixed_attribs = false; 5386 bool simulated_fixed_attribs = false;
5373 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs, 5387 if (SimulateFixedAttribs(
5374 primcount)) { 5388 function_name, max_vertex_accessed, &simulated_fixed_attribs,
5389 primcount)) {
5375 bool textures_set = SetBlackTextureForNonRenderableTextures(); 5390 bool textures_set = SetBlackTextureForNonRenderableTextures();
5376 ApplyDirtyState(); 5391 ApplyDirtyState();
5377 if (!instanced) { 5392 if (!instanced) {
5378 glDrawArrays(mode, first, count); 5393 glDrawArrays(mode, first, count);
5379 } else { 5394 } else {
5380 glDrawArraysInstancedANGLE(mode, first, count, primcount); 5395 glDrawArraysInstancedANGLE(mode, first, count, primcount);
5381 } 5396 }
5382 ProcessPendingQueries(); 5397 ProcessPendingQueries();
5383 if (textures_set) { 5398 if (textures_set) {
5384 RestoreStateForNonRenderableTextures(); 5399 RestoreStateForNonRenderableTextures();
5385 } 5400 }
5386 if (simulated_fixed_attribs) { 5401 if (simulated_fixed_attribs) {
5387 RestoreStateForSimulatedFixedAttribs(); 5402 RestoreStateForSimulatedFixedAttribs();
5388 } 5403 }
5389 } 5404 }
5390 if (simulated_attrib_0) { 5405 if (simulated_attrib_0) {
5391 RestoreStateForAttrib(0); 5406 RestoreStateForAttrib(0);
5392 } 5407 }
5393 if (WasContextLost()) { 5408 if (WasContextLost()) {
5394 LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawArrays."; 5409 LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawArrays.";
5395 return error::kLostContext; 5410 return error::kLostContext;
5396 } 5411 }
5397 } 5412 }
5398 return error::kNoError; 5413 return error::kNoError;
5399 } 5414 }
5400 5415
5401 error::Error GLES2DecoderImpl::HandleDrawArrays( 5416 error::Error GLES2DecoderImpl::HandleDrawArrays(
5402 uint32 immediate_data_size, const gles2::DrawArrays& c) { 5417 uint32 immediate_data_size, const gles2::DrawArrays& c) {
5403 return DoDrawArrays(false, 5418 return DoDrawArrays("glDrawArrays",
5419 false,
5404 static_cast<GLenum>(c.mode), 5420 static_cast<GLenum>(c.mode),
5405 static_cast<GLint>(c.first), 5421 static_cast<GLint>(c.first),
5406 static_cast<GLsizei>(c.count), 5422 static_cast<GLsizei>(c.count),
5407 0); 5423 0);
5408 } 5424 }
5409 5425
5410 error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( 5426 error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE(
5411 uint32 immediate_data_size, const gles2::DrawArraysInstancedANGLE& c) { 5427 uint32 immediate_data_size, const gles2::DrawArraysInstancedANGLE& c) {
5412 if (!feature_info_->feature_flags().angle_instanced_arrays) { 5428 if (!feature_info_->feature_flags().angle_instanced_arrays) {
5413 SetGLError(GL_INVALID_OPERATION, 5429 SetGLError(GL_INVALID_OPERATION,
5414 "glDrawArraysInstancedANGLE: function not available"); 5430 "glDrawArraysInstancedANGLE", "function not available");
5415 return error::kNoError; 5431 return error::kNoError;
5416 } 5432 }
5417 return DoDrawArrays(true, 5433 return DoDrawArrays("glDrawArraysIntancedANGLE",
5434 true,
5418 static_cast<GLenum>(c.mode), 5435 static_cast<GLenum>(c.mode),
5419 static_cast<GLint>(c.first), 5436 static_cast<GLint>(c.first),
5420 static_cast<GLsizei>(c.count), 5437 static_cast<GLsizei>(c.count),
5421 static_cast<GLsizei>(c.primcount)); 5438 static_cast<GLsizei>(c.primcount));
5422 } 5439 }
5423 5440
5424 error::Error GLES2DecoderImpl::DoDrawElements(bool instanced, 5441 error::Error GLES2DecoderImpl::DoDrawElements(
5425 GLenum mode, 5442 const char* function_name,
5426 GLsizei count, 5443 bool instanced,
5427 GLenum type, 5444 GLenum mode,
5428 int32 offset, 5445 GLsizei count,
5429 GLsizei primcount) { 5446 GLenum type,
5447 int32 offset,
5448 GLsizei primcount) {
5430 if (!bound_element_array_buffer_) { 5449 if (!bound_element_array_buffer_) {
5431 SetGLError(GL_INVALID_OPERATION, 5450 SetGLError(GL_INVALID_OPERATION,
5432 "glDrawElements: No element array buffer bound"); 5451 function_name, "No element array buffer bound");
5433 return error::kNoError; 5452 return error::kNoError;
5434 } 5453 }
5435 5454
5436 if (count < 0) { 5455 if (count < 0) {
5437 SetGLError(GL_INVALID_VALUE, "glDrawElements: count < 0"); 5456 SetGLError(GL_INVALID_VALUE, function_name, "count < 0");
5438 return error::kNoError; 5457 return error::kNoError;
5439 } 5458 }
5440 if (offset < 0) { 5459 if (offset < 0) {
5441 SetGLError(GL_INVALID_VALUE, "glDrawElements: offset < 0"); 5460 SetGLError(GL_INVALID_VALUE, function_name, "offset < 0");
5442 return error::kNoError; 5461 return error::kNoError;
5443 } 5462 }
5444 if (!validators_->draw_mode.IsValid(mode)) { 5463 if (!validators_->draw_mode.IsValid(mode)) {
5445 SetGLError(GL_INVALID_ENUM, "glDrawElements: mode GL_INVALID_ENUM"); 5464 SetGLError(GL_INVALID_ENUM, function_name, "mode GL_INVALID_ENUM");
5446 return error::kNoError; 5465 return error::kNoError;
5447 } 5466 }
5448 if (!validators_->index_type.IsValid(type)) { 5467 if (!validators_->index_type.IsValid(type)) {
5449 SetGLError(GL_INVALID_ENUM, "glDrawElements: type GL_INVALID_ENUM"); 5468 SetGLError(GL_INVALID_ENUM, function_name, "type GL_INVALID_ENUM");
5450 return error::kNoError; 5469 return error::kNoError;
5451 } 5470 }
5452 if (primcount < 0) { 5471 if (primcount < 0) {
5453 SetGLError(GL_INVALID_VALUE, "glDrawElements: primcount < 0"); 5472 SetGLError(GL_INVALID_VALUE, function_name, "primcount < 0");
5454 return error::kNoError; 5473 return error::kNoError;
5455 } 5474 }
5456 5475
5457 if (!CheckBoundFramebuffersValid("glDrawElements")) { 5476 if (!CheckBoundFramebuffersValid(function_name)) {
5458 return error::kNoError; 5477 return error::kNoError;
5459 } 5478 }
5460 5479
5461 if (count == 0 || (instanced && primcount == 0)) { 5480 if (count == 0 || (instanced && primcount == 0)) {
5462 return error::kNoError; 5481 return error::kNoError;
5463 } 5482 }
5464 5483
5465 GLuint max_vertex_accessed; 5484 GLuint max_vertex_accessed;
5466 if (!bound_element_array_buffer_->GetMaxValueForRange( 5485 if (!bound_element_array_buffer_->GetMaxValueForRange(
5467 offset, count, type, &max_vertex_accessed)) { 5486 offset, count, type, &max_vertex_accessed)) {
5468 SetGLError(GL_INVALID_OPERATION, 5487 SetGLError(GL_INVALID_OPERATION,
5469 "glDrawElements: range out of bounds for buffer"); 5488 function_name, "range out of bounds for buffer");
5470 return error::kNoError; 5489 return error::kNoError;
5471 } 5490 }
5472 5491
5473 if (IsDrawValid(max_vertex_accessed, primcount)) { 5492 if (IsDrawValid(function_name, max_vertex_accessed, primcount)) {
5474 if (!ClearUnclearedTextures()) { 5493 if (!ClearUnclearedTextures()) {
5475 SetGLError(GL_INVALID_VALUE, "glDrawElements: out of memory"); 5494 SetGLError(GL_INVALID_VALUE, function_name, "out of memory");
5476 return error::kNoError; 5495 return error::kNoError;
5477 } 5496 }
5478 bool simulated_attrib_0 = false; 5497 bool simulated_attrib_0 = false;
5479 if (!SimulateAttrib0(max_vertex_accessed, &simulated_attrib_0)) { 5498 if (!SimulateAttrib0(
5499 function_name, max_vertex_accessed, &simulated_attrib_0)) {
5480 return error::kNoError; 5500 return error::kNoError;
5481 } 5501 }
5482 bool simulated_fixed_attribs = false; 5502 bool simulated_fixed_attribs = false;
5483 if (SimulateFixedAttribs(max_vertex_accessed, &simulated_fixed_attribs, 5503 if (SimulateFixedAttribs(
5484 primcount)) { 5504 function_name, max_vertex_accessed, &simulated_fixed_attribs,
5505 primcount)) {
5485 bool textures_set = SetBlackTextureForNonRenderableTextures(); 5506 bool textures_set = SetBlackTextureForNonRenderableTextures();
5486 ApplyDirtyState(); 5507 ApplyDirtyState();
5487 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); 5508 const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset);
5488 if (!instanced) { 5509 if (!instanced) {
5489 glDrawElements(mode, count, type, indices); 5510 glDrawElements(mode, count, type, indices);
5490 } else { 5511 } else {
5491 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); 5512 glDrawElementsInstancedANGLE(mode, count, type, indices, primcount);
5492 } 5513 }
5493 ProcessPendingQueries(); 5514 ProcessPendingQueries();
5494 if (textures_set) { 5515 if (textures_set) {
5495 RestoreStateForNonRenderableTextures(); 5516 RestoreStateForNonRenderableTextures();
5496 } 5517 }
5497 if (simulated_fixed_attribs) { 5518 if (simulated_fixed_attribs) {
5498 RestoreStateForSimulatedFixedAttribs(); 5519 RestoreStateForSimulatedFixedAttribs();
5499 } 5520 }
5500 } 5521 }
5501 if (simulated_attrib_0) { 5522 if (simulated_attrib_0) {
5502 RestoreStateForAttrib(0); 5523 RestoreStateForAttrib(0);
5503 } 5524 }
5504 if (WasContextLost()) { 5525 if (WasContextLost()) {
5505 LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawElements."; 5526 LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawElements.";
5506 return error::kLostContext; 5527 return error::kLostContext;
5507 } 5528 }
5508 } 5529 }
5509 return error::kNoError; 5530 return error::kNoError;
5510 } 5531 }
5511 5532
5512 error::Error GLES2DecoderImpl::HandleDrawElements( 5533 error::Error GLES2DecoderImpl::HandleDrawElements(
5513 uint32 immediate_data_size, const gles2::DrawElements& c) { 5534 uint32 immediate_data_size, const gles2::DrawElements& c) {
5514 return DoDrawElements(false, 5535 return DoDrawElements("glDrawElements",
5536 false,
5515 static_cast<GLenum>(c.mode), 5537 static_cast<GLenum>(c.mode),
5516 static_cast<GLsizei>(c.count), 5538 static_cast<GLsizei>(c.count),
5517 static_cast<GLenum>(c.type), 5539 static_cast<GLenum>(c.type),
5518 static_cast<int32>(c.index_offset), 5540 static_cast<int32>(c.index_offset),
5519 0); 5541 0);
5520 } 5542 }
5521 5543
5522 error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( 5544 error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE(
5523 uint32 immediate_data_size, const gles2::DrawElementsInstancedANGLE& c) { 5545 uint32 immediate_data_size, const gles2::DrawElementsInstancedANGLE& c) {
5524 if (!feature_info_->feature_flags().angle_instanced_arrays) { 5546 if (!feature_info_->feature_flags().angle_instanced_arrays) {
5525 SetGLError(GL_INVALID_OPERATION, 5547 SetGLError(GL_INVALID_OPERATION,
5526 "glDrawElementsInstancedANGLE: function not available"); 5548 "glDrawElementsInstancedANGLE", "function not available");
5527 return error::kNoError; 5549 return error::kNoError;
5528 } 5550 }
5529 return DoDrawElements(true, 5551 return DoDrawElements("glDrawElementsInstancedANGLE",
5552 true,
5530 static_cast<GLenum>(c.mode), 5553 static_cast<GLenum>(c.mode),
5531 static_cast<GLsizei>(c.count), 5554 static_cast<GLsizei>(c.count),
5532 static_cast<GLenum>(c.type), 5555 static_cast<GLenum>(c.type),
5533 static_cast<int32>(c.index_offset), 5556 static_cast<int32>(c.index_offset),
5534 static_cast<GLsizei>(c.primcount)); 5557 static_cast<GLsizei>(c.primcount));
5535 } 5558 }
5536 5559
5537 GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( 5560 GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM(
5538 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { 5561 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) {
5539 GLuint max_vertex_accessed = 0; 5562 GLuint max_vertex_accessed = 0;
5540 BufferManager::BufferInfo* info = GetBufferInfo(buffer_id); 5563 BufferManager::BufferInfo* info = GetBufferInfo(buffer_id);
5541 if (!info) { 5564 if (!info) {
5542 // TODO(gman): Should this be a GL error or a command buffer error? 5565 // TODO(gman): Should this be a GL error or a command buffer error?
5543 SetGLError(GL_INVALID_VALUE, 5566 SetGLError(GL_INVALID_VALUE,
5544 "GetMaxValueInBufferCHROMIUM: unknown buffer"); 5567 "GetMaxValueInBufferCHROMIUM", "unknown buffer");
5545 } else { 5568 } else {
5546 if (!info->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { 5569 if (!info->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) {
5547 // TODO(gman): Should this be a GL error or a command buffer error? 5570 // TODO(gman): Should this be a GL error or a command buffer error?
5548 SetGLError( 5571 SetGLError(
5549 GL_INVALID_OPERATION, 5572 GL_INVALID_OPERATION,
5550 "GetMaxValueInBufferCHROMIUM: range out of bounds for buffer"); 5573 "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer");
5551 } 5574 }
5552 } 5575 }
5553 return max_vertex_accessed; 5576 return max_vertex_accessed;
5554 } 5577 }
5555 5578
5556 // Calls glShaderSource for the various versions of the ShaderSource command. 5579 // Calls glShaderSource for the various versions of the ShaderSource command.
5557 // Assumes that data / data_size points to a piece of memory that is in range 5580 // Assumes that data / data_size points to a piece of memory that is in range
5558 // of whatever context it came from (shared memory, immediate memory, bucket 5581 // of whatever context it came from (shared memory, immediate memory, bucket
5559 // memory.) 5582 // memory.)
5560 error::Error GLES2DecoderImpl::ShaderSourceHelper( 5583 error::Error GLES2DecoderImpl::ShaderSourceHelper(
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
5799 if (!program_info) { 5822 if (!program_info) {
5800 return; 5823 return;
5801 } 5824 }
5802 ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( 5825 ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram(
5803 shader_client_id, "glAttachShader"); 5826 shader_client_id, "glAttachShader");
5804 if (!shader_info) { 5827 if (!shader_info) {
5805 return; 5828 return;
5806 } 5829 }
5807 if (!program_info->AttachShader(shader_manager(), shader_info)) { 5830 if (!program_info->AttachShader(shader_manager(), shader_info)) {
5808 SetGLError(GL_INVALID_OPERATION, 5831 SetGLError(GL_INVALID_OPERATION,
5809 "glAttachShader: can not attach more than" 5832 "glAttachShader", "can not attach more than"
5810 " one shader of the same type."); 5833 " one shader of the same type.");
5811 return; 5834 return;
5812 } 5835 }
5813 glAttachShader(program_info->service_id(), shader_info->service_id()); 5836 glAttachShader(program_info->service_id(), shader_info->service_id());
5814 } 5837 }
5815 5838
5816 void GLES2DecoderImpl::DoDetachShader( 5839 void GLES2DecoderImpl::DoDetachShader(
5817 GLuint program_client_id, GLint shader_client_id) { 5840 GLuint program_client_id, GLint shader_client_id) {
5818 ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader( 5841 ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader(
5819 program_client_id, "glDetachShader"); 5842 program_client_id, "glDetachShader");
5820 if (!program_info) { 5843 if (!program_info) {
5821 return; 5844 return;
5822 } 5845 }
5823 ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( 5846 ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram(
5824 shader_client_id, "glDetachShader"); 5847 shader_client_id, "glDetachShader");
5825 if (!shader_info) { 5848 if (!shader_info) {
5826 return; 5849 return;
5827 } 5850 }
5828 if (!program_info->DetachShader(shader_manager(), shader_info)) { 5851 if (!program_info->DetachShader(shader_manager(), shader_info)) {
5829 SetGLError(GL_INVALID_OPERATION, 5852 SetGLError(GL_INVALID_OPERATION,
5830 "glDetachShader: shader not attached to program"); 5853 "glDetachShader", "shader not attached to program");
5831 return; 5854 return;
5832 } 5855 }
5833 glDetachShader(program_info->service_id(), shader_info->service_id()); 5856 glDetachShader(program_info->service_id(), shader_info->service_id());
5834 } 5857 }
5835 5858
5836 void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { 5859 void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) {
5837 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 5860 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
5838 program_client_id, "glValidateProgram"); 5861 program_client_id, "glValidateProgram");
5839 if (!info) { 5862 if (!info) {
5840 return; 5863 return;
5841 } 5864 }
5842 info->Validate(); 5865 info->Validate();
5843 } 5866 }
5844 5867
5845 void GLES2DecoderImpl::DoGetVertexAttribfv( 5868 void GLES2DecoderImpl::DoGetVertexAttribfv(
5846 GLuint index, GLenum pname, GLfloat* params) { 5869 GLuint index, GLenum pname, GLfloat* params) {
5847 VertexAttribManager::VertexAttribInfo* info = 5870 VertexAttribManager::VertexAttribInfo* info =
5848 vertex_attrib_manager_->GetVertexAttribInfo(index); 5871 vertex_attrib_manager_->GetVertexAttribInfo(index);
5849 if (!info) { 5872 if (!info) {
5850 SetGLError(GL_INVALID_VALUE, "glGetVertexAttribfv: index out of range"); 5873 SetGLError(GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range");
5851 return; 5874 return;
5852 } 5875 }
5853 switch (pname) { 5876 switch (pname) {
5854 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { 5877 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: {
5855 BufferManager::BufferInfo* buffer = info->buffer(); 5878 BufferManager::BufferInfo* buffer = info->buffer();
5856 if (buffer && !buffer->IsDeleted()) { 5879 if (buffer && !buffer->IsDeleted()) {
5857 GLuint client_id; 5880 GLuint client_id;
5858 buffer_manager()->GetClientId(buffer->service_id(), &client_id); 5881 buffer_manager()->GetClientId(buffer->service_id(), &client_id);
5859 *params = static_cast<GLfloat>(client_id); 5882 *params = static_cast<GLfloat>(client_id);
5860 } 5883 }
(...skipping 27 matching lines...) Expand all
5888 NOTREACHED(); 5911 NOTREACHED();
5889 break; 5912 break;
5890 } 5913 }
5891 } 5914 }
5892 5915
5893 void GLES2DecoderImpl::DoGetVertexAttribiv( 5916 void GLES2DecoderImpl::DoGetVertexAttribiv(
5894 GLuint index, GLenum pname, GLint* params) { 5917 GLuint index, GLenum pname, GLint* params) {
5895 VertexAttribManager::VertexAttribInfo* info = 5918 VertexAttribManager::VertexAttribInfo* info =
5896 vertex_attrib_manager_->GetVertexAttribInfo(index); 5919 vertex_attrib_manager_->GetVertexAttribInfo(index);
5897 if (!info) { 5920 if (!info) {
5898 SetGLError(GL_INVALID_VALUE, "glGetVertexAttribiv: index out of range"); 5921 SetGLError(GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range");
5899 return; 5922 return;
5900 } 5923 }
5901 switch (pname) { 5924 switch (pname) {
5902 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { 5925 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: {
5903 BufferManager::BufferInfo* buffer = info->buffer(); 5926 BufferManager::BufferInfo* buffer = info->buffer();
5904 if (buffer && !buffer->IsDeleted()) { 5927 if (buffer && !buffer->IsDeleted()) {
5905 GLuint client_id; 5928 GLuint client_id;
5906 buffer_manager()->GetClientId(buffer->service_id(), &client_id); 5929 buffer_manager()->GetClientId(buffer->service_id(), &client_id);
5907 *params = client_id; 5930 *params = client_id;
5908 } 5931 }
(...skipping 26 matching lines...) Expand all
5935 default: 5958 default:
5936 NOTREACHED(); 5959 NOTREACHED();
5937 break; 5960 break;
5938 } 5961 }
5939 } 5962 }
5940 5963
5941 void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { 5964 void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) {
5942 VertexAttribManager::VertexAttribInfo* info = 5965 VertexAttribManager::VertexAttribInfo* info =
5943 vertex_attrib_manager_->GetVertexAttribInfo(index); 5966 vertex_attrib_manager_->GetVertexAttribInfo(index);
5944 if (!info) { 5967 if (!info) {
5945 SetGLError(GL_INVALID_VALUE, "glVertexAttrib1f: index out of range"); 5968 SetGLError(GL_INVALID_VALUE, "glVertexAttrib1f", "index out of range");
5946 return; 5969 return;
5947 } 5970 }
5948 VertexAttribManager::VertexAttribInfo::Vec4 value; 5971 VertexAttribManager::VertexAttribInfo::Vec4 value;
5949 value.v[0] = v0; 5972 value.v[0] = v0;
5950 value.v[1] = 0.0f; 5973 value.v[1] = 0.0f;
5951 value.v[2] = 0.0f; 5974 value.v[2] = 0.0f;
5952 value.v[3] = 1.0f; 5975 value.v[3] = 1.0f;
5953 info->set_value(value); 5976 info->set_value(value);
5954 glVertexAttrib1f(index, v0); 5977 glVertexAttrib1f(index, v0);
5955 } 5978 }
5956 5979
5957 void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { 5980 void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) {
5958 VertexAttribManager::VertexAttribInfo* info = 5981 VertexAttribManager::VertexAttribInfo* info =
5959 vertex_attrib_manager_->GetVertexAttribInfo(index); 5982 vertex_attrib_manager_->GetVertexAttribInfo(index);
5960 if (!info) { 5983 if (!info) {
5961 SetGLError(GL_INVALID_VALUE, "glVertexAttrib2f: index out of range"); 5984 SetGLError(GL_INVALID_VALUE, "glVertexAttrib2f", "index out of range");
5962 return; 5985 return;
5963 } 5986 }
5964 VertexAttribManager::VertexAttribInfo::Vec4 value; 5987 VertexAttribManager::VertexAttribInfo::Vec4 value;
5965 value.v[0] = v0; 5988 value.v[0] = v0;
5966 value.v[1] = v1; 5989 value.v[1] = v1;
5967 value.v[2] = 0.0f; 5990 value.v[2] = 0.0f;
5968 value.v[3] = 1.0f; 5991 value.v[3] = 1.0f;
5969 info->set_value(value); 5992 info->set_value(value);
5970 glVertexAttrib2f(index, v0, v1); 5993 glVertexAttrib2f(index, v0, v1);
5971 } 5994 }
5972 5995
5973 void GLES2DecoderImpl::DoVertexAttrib3f( 5996 void GLES2DecoderImpl::DoVertexAttrib3f(
5974 GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { 5997 GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) {
5975 VertexAttribManager::VertexAttribInfo* info = 5998 VertexAttribManager::VertexAttribInfo* info =
5976 vertex_attrib_manager_->GetVertexAttribInfo(index); 5999 vertex_attrib_manager_->GetVertexAttribInfo(index);
5977 if (!info) { 6000 if (!info) {
5978 SetGLError(GL_INVALID_VALUE, "glVertexAttrib3f: index out of range"); 6001 SetGLError(GL_INVALID_VALUE, "glVertexAttrib3f", "index out of range");
5979 return; 6002 return;
5980 } 6003 }
5981 VertexAttribManager::VertexAttribInfo::Vec4 value; 6004 VertexAttribManager::VertexAttribInfo::Vec4 value;
5982 value.v[0] = v0; 6005 value.v[0] = v0;
5983 value.v[1] = v1; 6006 value.v[1] = v1;
5984 value.v[2] = v2; 6007 value.v[2] = v2;
5985 value.v[3] = 1.0f; 6008 value.v[3] = 1.0f;
5986 info->set_value(value); 6009 info->set_value(value);
5987 glVertexAttrib3f(index, v0, v1, v2); 6010 glVertexAttrib3f(index, v0, v1, v2);
5988 } 6011 }
5989 6012
5990 void GLES2DecoderImpl::DoVertexAttrib4f( 6013 void GLES2DecoderImpl::DoVertexAttrib4f(
5991 GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { 6014 GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
5992 VertexAttribManager::VertexAttribInfo* info = 6015 VertexAttribManager::VertexAttribInfo* info =
5993 vertex_attrib_manager_->GetVertexAttribInfo(index); 6016 vertex_attrib_manager_->GetVertexAttribInfo(index);
5994 if (!info) { 6017 if (!info) {
5995 SetGLError(GL_INVALID_VALUE, "glVertexAttrib4f: index out of range"); 6018 SetGLError(GL_INVALID_VALUE, "glVertexAttrib4f", "index out of range");
5996 return; 6019 return;
5997 } 6020 }
5998 VertexAttribManager::VertexAttribInfo::Vec4 value; 6021 VertexAttribManager::VertexAttribInfo::Vec4 value;
5999 value.v[0] = v0; 6022 value.v[0] = v0;
6000 value.v[1] = v1; 6023 value.v[1] = v1;
6001 value.v[2] = v2; 6024 value.v[2] = v2;
6002 value.v[3] = v3; 6025 value.v[3] = v3;
6003 info->set_value(value); 6026 info->set_value(value);
6004 glVertexAttrib4f(index, v0, v1, v2, v3); 6027 glVertexAttrib4f(index, v0, v1, v2, v3);
6005 } 6028 }
6006 6029
6007 void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { 6030 void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) {
6008 VertexAttribManager::VertexAttribInfo* info = 6031 VertexAttribManager::VertexAttribInfo* info =
6009 vertex_attrib_manager_->GetVertexAttribInfo(index); 6032 vertex_attrib_manager_->GetVertexAttribInfo(index);
6010 if (!info) { 6033 if (!info) {
6011 SetGLError(GL_INVALID_VALUE, "glVertexAttrib1fv: index out of range"); 6034 SetGLError(GL_INVALID_VALUE, "glVertexAttrib1fv", "index out of range");
6012 return; 6035 return;
6013 } 6036 }
6014 VertexAttribManager::VertexAttribInfo::Vec4 value; 6037 VertexAttribManager::VertexAttribInfo::Vec4 value;
6015 value.v[0] = v[0]; 6038 value.v[0] = v[0];
6016 value.v[1] = 0.0f; 6039 value.v[1] = 0.0f;
6017 value.v[2] = 0.0f; 6040 value.v[2] = 0.0f;
6018 value.v[3] = 1.0f; 6041 value.v[3] = 1.0f;
6019 info->set_value(value); 6042 info->set_value(value);
6020 glVertexAttrib1fv(index, v); 6043 glVertexAttrib1fv(index, v);
6021 } 6044 }
6022 6045
6023 void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { 6046 void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) {
6024 VertexAttribManager::VertexAttribInfo* info = 6047 VertexAttribManager::VertexAttribInfo* info =
6025 vertex_attrib_manager_->GetVertexAttribInfo(index); 6048 vertex_attrib_manager_->GetVertexAttribInfo(index);
6026 if (!info) { 6049 if (!info) {
6027 SetGLError(GL_INVALID_VALUE, "glVertexAttrib2fv: index out of range"); 6050 SetGLError(GL_INVALID_VALUE, "glVertexAttrib2fv", "index out of range");
6028 return; 6051 return;
6029 } 6052 }
6030 VertexAttribManager::VertexAttribInfo::Vec4 value; 6053 VertexAttribManager::VertexAttribInfo::Vec4 value;
6031 value.v[0] = v[0]; 6054 value.v[0] = v[0];
6032 value.v[1] = v[1]; 6055 value.v[1] = v[1];
6033 value.v[2] = 0.0f; 6056 value.v[2] = 0.0f;
6034 value.v[3] = 1.0f; 6057 value.v[3] = 1.0f;
6035 info->set_value(value); 6058 info->set_value(value);
6036 glVertexAttrib2fv(index, v); 6059 glVertexAttrib2fv(index, v);
6037 } 6060 }
6038 6061
6039 void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { 6062 void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) {
6040 VertexAttribManager::VertexAttribInfo* info = 6063 VertexAttribManager::VertexAttribInfo* info =
6041 vertex_attrib_manager_->GetVertexAttribInfo(index); 6064 vertex_attrib_manager_->GetVertexAttribInfo(index);
6042 if (!info) { 6065 if (!info) {
6043 SetGLError(GL_INVALID_VALUE, "glVertexAttrib3fv: index out of range"); 6066 SetGLError(GL_INVALID_VALUE, "glVertexAttrib3fv", "index out of range");
6044 return; 6067 return;
6045 } 6068 }
6046 VertexAttribManager::VertexAttribInfo::Vec4 value; 6069 VertexAttribManager::VertexAttribInfo::Vec4 value;
6047 value.v[0] = v[0]; 6070 value.v[0] = v[0];
6048 value.v[1] = v[1]; 6071 value.v[1] = v[1];
6049 value.v[2] = v[2]; 6072 value.v[2] = v[2];
6050 value.v[3] = 1.0f; 6073 value.v[3] = 1.0f;
6051 info->set_value(value); 6074 info->set_value(value);
6052 glVertexAttrib3fv(index, v); 6075 glVertexAttrib3fv(index, v);
6053 } 6076 }
6054 6077
6055 void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { 6078 void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) {
6056 VertexAttribManager::VertexAttribInfo* info = 6079 VertexAttribManager::VertexAttribInfo* info =
6057 vertex_attrib_manager_->GetVertexAttribInfo(index); 6080 vertex_attrib_manager_->GetVertexAttribInfo(index);
6058 if (!info) { 6081 if (!info) {
6059 SetGLError(GL_INVALID_VALUE, "glVertexAttrib4fv: index out of range"); 6082 SetGLError(GL_INVALID_VALUE, "glVertexAttrib4fv", "index out of range");
6060 return; 6083 return;
6061 } 6084 }
6062 VertexAttribManager::VertexAttribInfo::Vec4 value; 6085 VertexAttribManager::VertexAttribInfo::Vec4 value;
6063 value.v[0] = v[0]; 6086 value.v[0] = v[0];
6064 value.v[1] = v[1]; 6087 value.v[1] = v[1];
6065 value.v[2] = v[2]; 6088 value.v[2] = v[2];
6066 value.v[3] = v[3]; 6089 value.v[3] = v[3];
6067 info->set_value(value); 6090 info->set_value(value);
6068 glVertexAttrib4fv(index, v); 6091 glVertexAttrib4fv(index, v);
6069 } 6092 }
6070 6093
6071 error::Error GLES2DecoderImpl::HandleVertexAttribPointer( 6094 error::Error GLES2DecoderImpl::HandleVertexAttribPointer(
6072 uint32 immediate_data_size, const gles2::VertexAttribPointer& c) { 6095 uint32 immediate_data_size, const gles2::VertexAttribPointer& c) {
6073 if (!bound_array_buffer_ || bound_array_buffer_->IsDeleted()) { 6096 if (!bound_array_buffer_ || bound_array_buffer_->IsDeleted()) {
6074 SetGLError(GL_INVALID_VALUE, 6097 SetGLError(GL_INVALID_VALUE,
6075 "glVertexAttribPointer: no array buffer bound"); 6098 "glVertexAttribPointer", "no array buffer bound");
6076 return error::kNoError; 6099 return error::kNoError;
6077 } 6100 }
6078 6101
6079 GLuint indx = c.indx; 6102 GLuint indx = c.indx;
6080 GLint size = c.size; 6103 GLint size = c.size;
6081 GLenum type = c.type; 6104 GLenum type = c.type;
6082 GLboolean normalized = c.normalized; 6105 GLboolean normalized = c.normalized;
6083 GLsizei stride = c.stride; 6106 GLsizei stride = c.stride;
6084 GLsizei offset = c.offset; 6107 GLsizei offset = c.offset;
6085 const void* ptr = reinterpret_cast<const void*>(offset); 6108 const void* ptr = reinterpret_cast<const void*>(offset);
6086 if (!validators_->vertex_attrib_type.IsValid(type)) { 6109 if (!validators_->vertex_attrib_type.IsValid(type)) {
6087 SetGLError(GL_INVALID_ENUM, 6110 SetGLError(GL_INVALID_ENUM,
6088 "glVertexAttribPointer: type GL_INVALID_ENUM"); 6111 "glVertexAttribPointer", "type GL_INVALID_ENUM");
6089 return error::kNoError; 6112 return error::kNoError;
6090 } 6113 }
6091 if (!validators_->vertex_attrib_size.IsValid(size)) { 6114 if (!validators_->vertex_attrib_size.IsValid(size)) {
6092 SetGLError(GL_INVALID_VALUE, 6115 SetGLError(GL_INVALID_VALUE,
6093 "glVertexAttribPointer: size GL_INVALID_VALUE"); 6116 "glVertexAttribPointer", "size GL_INVALID_VALUE");
6094 return error::kNoError; 6117 return error::kNoError;
6095 } 6118 }
6096 if (indx >= group_->max_vertex_attribs()) { 6119 if (indx >= group_->max_vertex_attribs()) {
6097 SetGLError(GL_INVALID_VALUE, "glVertexAttribPointer: index out of range"); 6120 SetGLError(GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range");
6098 return error::kNoError; 6121 return error::kNoError;
6099 } 6122 }
6100 if (stride < 0) { 6123 if (stride < 0) {
6101 SetGLError(GL_INVALID_VALUE, 6124 SetGLError(GL_INVALID_VALUE,
6102 "glVertexAttribPointer: stride < 0"); 6125 "glVertexAttribPointer", "stride < 0");
6103 return error::kNoError; 6126 return error::kNoError;
6104 } 6127 }
6105 if (stride > 255) { 6128 if (stride > 255) {
6106 SetGLError(GL_INVALID_VALUE, 6129 SetGLError(GL_INVALID_VALUE,
6107 "glVertexAttribPointer: stride > 255"); 6130 "glVertexAttribPointer", "stride > 255");
6108 return error::kNoError; 6131 return error::kNoError;
6109 } 6132 }
6110 if (offset < 0) { 6133 if (offset < 0) {
6111 SetGLError(GL_INVALID_VALUE, 6134 SetGLError(GL_INVALID_VALUE,
6112 "glVertexAttribPointer: offset < 0"); 6135 "glVertexAttribPointer", "offset < 0");
6113 return error::kNoError; 6136 return error::kNoError;
6114 } 6137 }
6115 GLsizei component_size = 6138 GLsizei component_size =
6116 GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); 6139 GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type);
6117 if (offset % component_size > 0) { 6140 if (offset % component_size > 0) {
6118 SetGLError(GL_INVALID_OPERATION, 6141 SetGLError(GL_INVALID_OPERATION,
6119 "glVertexAttribPointer: offset not valid for type"); 6142 "glVertexAttribPointer", "offset not valid for type");
6120 return error::kNoError; 6143 return error::kNoError;
6121 } 6144 }
6122 if (stride % component_size > 0) { 6145 if (stride % component_size > 0) {
6123 SetGLError(GL_INVALID_OPERATION, 6146 SetGLError(GL_INVALID_OPERATION,
6124 "glVertexAttribPointer: stride not valid for type"); 6147 "glVertexAttribPointer", "stride not valid for type");
6125 return error::kNoError; 6148 return error::kNoError;
6126 } 6149 }
6127 vertex_attrib_manager_->SetAttribInfo( 6150 vertex_attrib_manager_->SetAttribInfo(
6128 indx, 6151 indx,
6129 bound_array_buffer_, 6152 bound_array_buffer_,
6130 size, 6153 size,
6131 type, 6154 type,
6132 normalized, 6155 normalized,
6133 stride, 6156 stride,
6134 stride != 0 ? stride : component_size * size, 6157 stride != 0 ? stride : component_size * size,
(...skipping 10 matching lines...) Expand all
6145 viewport_y_ = y; 6168 viewport_y_ = y;
6146 viewport_width_ = std::min(width, viewport_max_width_); 6169 viewport_width_ = std::min(width, viewport_max_width_);
6147 viewport_height_ = std::min(height, viewport_max_height_); 6170 viewport_height_ = std::min(height, viewport_max_height_);
6148 glViewport(x, y, width, height); 6171 glViewport(x, y, width, height);
6149 } 6172 }
6150 6173
6151 error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( 6174 error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE(
6152 uint32 immediate_data_size, const gles2::VertexAttribDivisorANGLE& c) { 6175 uint32 immediate_data_size, const gles2::VertexAttribDivisorANGLE& c) {
6153 if (!feature_info_->feature_flags().angle_instanced_arrays) { 6176 if (!feature_info_->feature_flags().angle_instanced_arrays) {
6154 SetGLError(GL_INVALID_OPERATION, 6177 SetGLError(GL_INVALID_OPERATION,
6155 "glVertexAttribDivisorANGLE: function not available"); 6178 "glVertexAttribDivisorANGLE", "function not available");
6156 } 6179 }
6157 GLuint index = c.index; 6180 GLuint index = c.index;
6158 GLuint divisor = c.divisor; 6181 GLuint divisor = c.divisor;
6159 if (index >= group_->max_vertex_attribs()) { 6182 if (index >= group_->max_vertex_attribs()) {
6160 SetGLError(GL_INVALID_VALUE, 6183 SetGLError(GL_INVALID_VALUE,
6161 "glVertexAttribDivisorANGLE: index out of range"); 6184 "glVertexAttribDivisorANGLE", "index out of range");
6162 return error::kNoError; 6185 return error::kNoError;
6163 } 6186 }
6164 6187
6165 vertex_attrib_manager_->SetDivisor( 6188 vertex_attrib_manager_->SetDivisor(
6166 index, 6189 index,
6167 divisor); 6190 divisor);
6168 glVertexAttribDivisorANGLE(index, divisor); 6191 glVertexAttribDivisorANGLE(index, divisor);
6169 return error::kNoError; 6192 return error::kNoError;
6170 } 6193 }
6171 6194
6172 error::Error GLES2DecoderImpl::HandleReadPixels( 6195 error::Error GLES2DecoderImpl::HandleReadPixels(
6173 uint32 immediate_data_size, const gles2::ReadPixels& c) { 6196 uint32 immediate_data_size, const gles2::ReadPixels& c) {
6174 GLint x = c.x; 6197 GLint x = c.x;
6175 GLint y = c.y; 6198 GLint y = c.y;
6176 GLsizei width = c.width; 6199 GLsizei width = c.width;
6177 GLsizei height = c.height; 6200 GLsizei height = c.height;
6178 GLenum format = c.format; 6201 GLenum format = c.format;
6179 GLenum type = c.type; 6202 GLenum type = c.type;
6180 if (width < 0 || height < 0) { 6203 if (width < 0 || height < 0) {
6181 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions < 0"); 6204 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0");
6182 return error::kNoError; 6205 return error::kNoError;
6183 } 6206 }
6184 typedef gles2::ReadPixels::Result Result; 6207 typedef gles2::ReadPixels::Result Result;
6185 uint32 pixels_size; 6208 uint32 pixels_size;
6186 if (!GLES2Util::ComputeImageDataSizes( 6209 if (!GLES2Util::ComputeImageDataSizes(
6187 width, height, format, type, pack_alignment_, &pixels_size, NULL, NULL)) { 6210 width, height, format, type, pack_alignment_, &pixels_size, NULL, NULL)) {
6188 return error::kOutOfBounds; 6211 return error::kOutOfBounds;
6189 } 6212 }
6190 void* pixels = GetSharedMemoryAs<void*>( 6213 void* pixels = GetSharedMemoryAs<void*>(
6191 c.pixels_shm_id, c.pixels_shm_offset, pixels_size); 6214 c.pixels_shm_id, c.pixels_shm_offset, pixels_size);
6192 Result* result = GetSharedMemoryAs<Result*>( 6215 Result* result = GetSharedMemoryAs<Result*>(
6193 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 6216 c.result_shm_id, c.result_shm_offset, sizeof(*result));
6194 if (!pixels || !result) { 6217 if (!pixels || !result) {
6195 return error::kOutOfBounds; 6218 return error::kOutOfBounds;
6196 } 6219 }
6197 6220
6198 if (!validators_->read_pixel_format.IsValid(format)) { 6221 if (!validators_->read_pixel_format.IsValid(format)) {
6199 SetGLError(GL_INVALID_ENUM, "glReadPixels: format GL_INVALID_ENUM"); 6222 SetGLError(GL_INVALID_ENUM, "glReadPixels", "format GL_INVALID_ENUM");
6200 return error::kNoError; 6223 return error::kNoError;
6201 } 6224 }
6202 if (!validators_->pixel_type.IsValid(type)) { 6225 if (!validators_->pixel_type.IsValid(type)) {
6203 SetGLError(GL_INVALID_ENUM, "glReadPixels: type GL_INVALID_ENUM"); 6226 SetGLError(GL_INVALID_ENUM, "glReadPixels", "type GL_INVALID_ENUM");
6204 return error::kNoError; 6227 return error::kNoError;
6205 } 6228 }
6206 if (width == 0 || height == 0) { 6229 if (width == 0 || height == 0) {
6207 return error::kNoError; 6230 return error::kNoError;
6208 } 6231 }
6209 6232
6210 // Get the size of the current fbo or backbuffer. 6233 // Get the size of the current fbo or backbuffer.
6211 gfx::Size max_size = GetBoundReadFrameBufferSize(); 6234 gfx::Size max_size = GetBoundReadFrameBufferSize();
6212 6235
6213 GLint max_x; 6236 GLint max_x;
6214 GLint max_y; 6237 GLint max_y;
6215 if (!SafeAdd(x, width, &max_x) || !SafeAdd(y, height, &max_y)) { 6238 if (!SafeAdd(x, width, &max_x) || !SafeAdd(y, height, &max_y)) {
6216 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); 6239 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
6217 return error::kNoError; 6240 return error::kNoError;
6218 } 6241 }
6219 6242
6220 if (!CheckBoundFramebuffersValid("glReadPixels")) { 6243 if (!CheckBoundFramebuffersValid("glReadPixels")) {
6221 return error::kNoError; 6244 return error::kNoError;
6222 } 6245 }
6223 6246
6224 CopyRealGLErrorsToWrapper(); 6247 CopyRealGLErrorsToWrapper();
6225 6248
6226 ScopedResolvedFrameBufferBinder binder(this, false, true); 6249 ScopedResolvedFrameBufferBinder binder(this, false, true);
6227 6250
6228 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { 6251 if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) {
6229 // The user requested an out of range area. Get the results 1 line 6252 // The user requested an out of range area. Get the results 1 line
6230 // at a time. 6253 // at a time.
6231 uint32 temp_size; 6254 uint32 temp_size;
6232 uint32 unpadded_row_size; 6255 uint32 unpadded_row_size;
6233 uint32 padded_row_size; 6256 uint32 padded_row_size;
6234 if (!GLES2Util::ComputeImageDataSizes( 6257 if (!GLES2Util::ComputeImageDataSizes(
6235 width, 2, format, type, pack_alignment_, &temp_size, 6258 width, 2, format, type, pack_alignment_, &temp_size,
6236 &unpadded_row_size, &padded_row_size)) { 6259 &unpadded_row_size, &padded_row_size)) {
6237 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); 6260 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
6238 return error::kNoError; 6261 return error::kNoError;
6239 } 6262 }
6240 6263
6241 GLint dest_x_offset = std::max(-x, 0); 6264 GLint dest_x_offset = std::max(-x, 0);
6242 uint32 dest_row_offset; 6265 uint32 dest_row_offset;
6243 if (!GLES2Util::ComputeImageDataSizes( 6266 if (!GLES2Util::ComputeImageDataSizes(
6244 dest_x_offset, 1, format, type, pack_alignment_, &dest_row_offset, NULL, 6267 dest_x_offset, 1, format, type, pack_alignment_, &dest_row_offset, NULL,
6245 NULL)) { 6268 NULL)) {
6246 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); 6269 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
6247 return error::kNoError; 6270 return error::kNoError;
6248 } 6271 }
6249 6272
6250 // Copy each row into the larger dest rect. 6273 // Copy each row into the larger dest rect.
6251 int8* dst = static_cast<int8*>(pixels); 6274 int8* dst = static_cast<int8*>(pixels);
6252 GLint read_x = std::max(0, x); 6275 GLint read_x = std::max(0, x);
6253 GLint read_end_x = std::max(0, std::min(max_size.width(), max_x)); 6276 GLint read_end_x = std::max(0, std::min(max_size.width(), max_x));
6254 GLint read_width = read_end_x - read_x; 6277 GLint read_width = read_end_x - read_x;
6255 for (GLint yy = 0; yy < height; ++yy) { 6278 for (GLint yy = 0; yy < height; ++yy) {
6256 GLint ry = y + yy; 6279 GLint ry = y + yy;
(...skipping 19 matching lines...) Expand all
6276 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 6299 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
6277 if ((channels_exist & 0x0008) == 0 && !disable_workarounds_) { 6300 if ((channels_exist & 0x0008) == 0 && !disable_workarounds_) {
6278 // Set the alpha to 255 because some drivers are buggy in this regard. 6301 // Set the alpha to 255 because some drivers are buggy in this regard.
6279 uint32 temp_size; 6302 uint32 temp_size;
6280 6303
6281 uint32 unpadded_row_size; 6304 uint32 unpadded_row_size;
6282 uint32 padded_row_size; 6305 uint32 padded_row_size;
6283 if (!GLES2Util::ComputeImageDataSizes( 6306 if (!GLES2Util::ComputeImageDataSizes(
6284 width, 2, format, type, pack_alignment_, &temp_size, 6307 width, 2, format, type, pack_alignment_, &temp_size,
6285 &unpadded_row_size, &padded_row_size)) { 6308 &unpadded_row_size, &padded_row_size)) {
6286 SetGLError(GL_INVALID_VALUE, "glReadPixels: dimensions out of range"); 6309 SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range");
6287 return error::kNoError; 6310 return error::kNoError;
6288 } 6311 }
6289 // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time 6312 // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time
6290 // of this implementation. 6313 // of this implementation.
6291 if (type != GL_UNSIGNED_BYTE) { 6314 if (type != GL_UNSIGNED_BYTE) {
6292 SetGLError(GL_INVALID_OPERATION, "unsupported readPixel format"); 6315 SetGLError(
6316 GL_INVALID_OPERATION, "glReadPixels",
6317 "unsupported readPixel format");
6293 return error::kNoError; 6318 return error::kNoError;
6294 } 6319 }
6295 switch (format) { 6320 switch (format) {
6296 case GL_RGBA: 6321 case GL_RGBA:
6297 case GL_BGRA_EXT: 6322 case GL_BGRA_EXT:
6298 case GL_ALPHA: { 6323 case GL_ALPHA: {
6299 int offset = (format == GL_ALPHA) ? 0 : 3; 6324 int offset = (format == GL_ALPHA) ? 0 : 3;
6300 int step = (format == GL_ALPHA) ? 1 : 4; 6325 int step = (format == GL_ALPHA) ? 1 : 4;
6301 uint8* dst = static_cast<uint8*>(pixels) + offset; 6326 uint8* dst = static_cast<uint8*>(pixels) + offset;
6302 for (GLint yy = 0; yy < height; ++yy) { 6327 for (GLint yy = 0; yy < height; ++yy) {
(...skipping 12 matching lines...) Expand all
6315 } 6340 }
6316 6341
6317 return error::kNoError; 6342 return error::kNoError;
6318 } 6343 }
6319 6344
6320 error::Error GLES2DecoderImpl::HandlePixelStorei( 6345 error::Error GLES2DecoderImpl::HandlePixelStorei(
6321 uint32 immediate_data_size, const gles2::PixelStorei& c) { 6346 uint32 immediate_data_size, const gles2::PixelStorei& c) {
6322 GLenum pname = c.pname; 6347 GLenum pname = c.pname;
6323 GLenum param = c.param; 6348 GLenum param = c.param;
6324 if (!validators_->pixel_store.IsValid(pname)) { 6349 if (!validators_->pixel_store.IsValid(pname)) {
6325 SetGLError(GL_INVALID_ENUM, "glPixelStorei: pname GL_INVALID_ENUM"); 6350 SetGLError(GL_INVALID_ENUM, "glPixelStorei", "pname GL_INVALID_ENUM");
6326 return error::kNoError; 6351 return error::kNoError;
6327 } 6352 }
6328 switch (pname) { 6353 switch (pname) {
6329 case GL_PACK_ALIGNMENT: 6354 case GL_PACK_ALIGNMENT:
6330 case GL_UNPACK_ALIGNMENT: 6355 case GL_UNPACK_ALIGNMENT:
6331 if (!validators_->pixel_store_alignment.IsValid(param)) { 6356 if (!validators_->pixel_store_alignment.IsValid(param)) {
6332 SetGLError(GL_INVALID_VALUE, 6357 SetGLError(GL_INVALID_VALUE,
6333 "glPixelSTore: param GL_INVALID_VALUE"); 6358 "glPixelStore", "param GL_INVALID_VALUE");
6334 return error::kNoError; 6359 return error::kNoError;
6335 } 6360 }
6336 break; 6361 break;
6337 case GL_UNPACK_FLIP_Y_CHROMIUM: 6362 case GL_UNPACK_FLIP_Y_CHROMIUM:
6338 unpack_flip_y_ = (param != 0); 6363 unpack_flip_y_ = (param != 0);
6339 return error::kNoError; 6364 return error::kNoError;
6340 case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: 6365 case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM:
6341 unpack_premultiply_alpha_ = (param != 0); 6366 unpack_premultiply_alpha_ = (param != 0);
6342 return error::kNoError; 6367 return error::kNoError;
6343 default: 6368 default:
6344 break; 6369 break;
6345 } 6370 }
6346 glPixelStorei(pname, param); 6371 glPixelStorei(pname, param);
6347 switch (pname) { 6372 switch (pname) {
6348 case GL_PACK_ALIGNMENT: 6373 case GL_PACK_ALIGNMENT:
6349 pack_alignment_ = param; 6374 pack_alignment_ = param;
6350 break; 6375 break;
6351 case GL_PACK_REVERSE_ROW_ORDER_ANGLE: 6376 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6352 break; 6377 break;
6353 case GL_UNPACK_ALIGNMENT: 6378 case GL_UNPACK_ALIGNMENT:
6354 unpack_alignment_ = param; 6379 unpack_alignment_ = param;
6355 break; 6380 break;
6356 default: 6381 default:
6357 // Validation should have prevented us from getting here. 6382 // Validation should have prevented us from getting here.
6358 NOTREACHED(); 6383 NOTREACHED();
6359 break; 6384 break;
6360 } 6385 }
6361 return error::kNoError; 6386 return error::kNoError;
6362 } 6387 }
6363 6388
6364 error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( 6389 error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM(
6365 uint32 immediate_data_size, const gles2::PostSubBufferCHROMIUM& c) { 6390 uint32 immediate_data_size, const gles2::PostSubBufferCHROMIUM& c) {
6366 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); 6391 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM");
6367 if (!context_->HasExtension("GL_CHROMIUM_post_sub_buffer")) { 6392 if (!context_->HasExtension("GL_CHROMIUM_post_sub_buffer")) {
6368 SetGLError(GL_INVALID_OPERATION, 6393 SetGLError(GL_INVALID_OPERATION,
6369 "glPostSubBufferCHROMIUM: command not supported by surface"); 6394 "glPostSubBufferCHROMIUM", "command not supported by surface");
6370 return error::kNoError; 6395 return error::kNoError;
6371 } 6396 }
6372 if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { 6397 if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) {
6373 return error::kNoError; 6398 return error::kNoError;
6374 } else { 6399 } else {
6375 LOG(ERROR) << "Context lost because PostSubBuffer failed."; 6400 LOG(ERROR) << "Context lost because PostSubBuffer failed.";
6376 return error::kLostContext; 6401 return error::kLostContext;
6377 } 6402 }
6378 } 6403 }
6379 6404
6380 error::Error GLES2DecoderImpl::GetAttribLocationHelper( 6405 error::Error GLES2DecoderImpl::GetAttribLocationHelper(
6381 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, 6406 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset,
6382 const std::string& name_str) { 6407 const std::string& name_str) {
6383 if (!StringIsValidForGLES(name_str.c_str())) { 6408 if (!StringIsValidForGLES(name_str.c_str())) {
6384 SetGLError(GL_INVALID_VALUE, "glGetAttribLocation: Invalid character"); 6409 SetGLError(GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character");
6385 return error::kNoError; 6410 return error::kNoError;
6386 } 6411 }
6387 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 6412 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
6388 client_id, "glGetAttribLocation"); 6413 client_id, "glGetAttribLocation");
6389 if (!info) { 6414 if (!info) {
6390 return error::kNoError; 6415 return error::kNoError;
6391 } 6416 }
6392 if (!info->IsValid()) { 6417 if (!info->IsValid()) {
6393 SetGLError(GL_INVALID_OPERATION, "glGetAttribLocation: program not linked"); 6418 SetGLError(
6419 GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked");
6394 return error::kNoError; 6420 return error::kNoError;
6395 } 6421 }
6396 GLint* location = GetSharedMemoryAs<GLint*>( 6422 GLint* location = GetSharedMemoryAs<GLint*>(
6397 location_shm_id, location_shm_offset, sizeof(GLint)); 6423 location_shm_id, location_shm_offset, sizeof(GLint));
6398 if (!location) { 6424 if (!location) {
6399 return error::kOutOfBounds; 6425 return error::kOutOfBounds;
6400 } 6426 }
6401 // Require the client to init this incase the context is lost and we are no 6427 // Require the client to init this incase the context is lost and we are no
6402 // longer executing commands. 6428 // longer executing commands.
6403 if (*location != -1) { 6429 if (*location != -1) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
6444 return error::kInvalidArguments; 6470 return error::kInvalidArguments;
6445 } 6471 }
6446 return GetAttribLocationHelper( 6472 return GetAttribLocationHelper(
6447 c.program, c.location_shm_id, c.location_shm_offset, name_str); 6473 c.program, c.location_shm_id, c.location_shm_offset, name_str);
6448 } 6474 }
6449 6475
6450 error::Error GLES2DecoderImpl::GetUniformLocationHelper( 6476 error::Error GLES2DecoderImpl::GetUniformLocationHelper(
6451 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, 6477 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset,
6452 const std::string& name_str) { 6478 const std::string& name_str) {
6453 if (!StringIsValidForGLES(name_str.c_str())) { 6479 if (!StringIsValidForGLES(name_str.c_str())) {
6454 SetGLError(GL_INVALID_VALUE, "glGetUniformLocation: Invalid character"); 6480 SetGLError(GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character");
6455 return error::kNoError; 6481 return error::kNoError;
6456 } 6482 }
6457 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 6483 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
6458 client_id, "glUniformLocation"); 6484 client_id, "glUniformLocation");
6459 if (!info) { 6485 if (!info) {
6460 return error::kNoError; 6486 return error::kNoError;
6461 } 6487 }
6462 if (!info->IsValid()) { 6488 if (!info->IsValid()) {
6463 SetGLError(GL_INVALID_OPERATION, 6489 SetGLError(
6464 "glGetUniformLocation: program not linked"); 6490 GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked");
6465 return error::kNoError; 6491 return error::kNoError;
6466 } 6492 }
6467 GLint* location = GetSharedMemoryAs<GLint*>( 6493 GLint* location = GetSharedMemoryAs<GLint*>(
6468 location_shm_id, location_shm_offset, sizeof(GLint)); 6494 location_shm_id, location_shm_offset, sizeof(GLint));
6469 if (!location) { 6495 if (!location) {
6470 return error::kOutOfBounds; 6496 return error::kOutOfBounds;
6471 } 6497 }
6472 // Require the client to init this incase the context is lost an we are no 6498 // Require the client to init this incase the context is lost an we are no
6473 // longer executing commands. 6499 // longer executing commands.
6474 if (*location != -1) { 6500 if (*location != -1) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6516 return error::kInvalidArguments; 6542 return error::kInvalidArguments;
6517 } 6543 }
6518 return GetUniformLocationHelper( 6544 return GetUniformLocationHelper(
6519 c.program, c.location_shm_id, c.location_shm_offset, name_str); 6545 c.program, c.location_shm_id, c.location_shm_offset, name_str);
6520 } 6546 }
6521 6547
6522 error::Error GLES2DecoderImpl::HandleGetString( 6548 error::Error GLES2DecoderImpl::HandleGetString(
6523 uint32 immediate_data_size, const gles2::GetString& c) { 6549 uint32 immediate_data_size, const gles2::GetString& c) {
6524 GLenum name = static_cast<GLenum>(c.name); 6550 GLenum name = static_cast<GLenum>(c.name);
6525 if (!validators_->string_type.IsValid(name)) { 6551 if (!validators_->string_type.IsValid(name)) {
6526 SetGLError(GL_INVALID_ENUM, "glGetString: name GL_INVALID_ENUM"); 6552 SetGLError(GL_INVALID_ENUM, "glGetString", "name GL_INVALID_ENUM");
6527 return error::kNoError; 6553 return error::kNoError;
6528 } 6554 }
6529 const char* gl_str = reinterpret_cast<const char*>(glGetString(name)); 6555 const char* gl_str = reinterpret_cast<const char*>(glGetString(name));
6530 const char* str = NULL; 6556 const char* str = NULL;
6531 std::string extensions; 6557 std::string extensions;
6532 switch (name) { 6558 switch (name) {
6533 case GL_VERSION: 6559 case GL_VERSION:
6534 str = "OpenGL ES 2.0 Chromium"; 6560 str = "OpenGL ES 2.0 Chromium";
6535 break; 6561 break;
6536 case GL_SHADING_LANGUAGE_VERSION: 6562 case GL_SHADING_LANGUAGE_VERSION:
(...skipping 29 matching lines...) Expand all
6566 break; 6592 break;
6567 } 6593 }
6568 Bucket* bucket = CreateBucket(c.bucket_id); 6594 Bucket* bucket = CreateBucket(c.bucket_id);
6569 bucket->SetFromString(str); 6595 bucket->SetFromString(str);
6570 return error::kNoError; 6596 return error::kNoError;
6571 } 6597 }
6572 6598
6573 void GLES2DecoderImpl::DoBufferData( 6599 void GLES2DecoderImpl::DoBufferData(
6574 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) { 6600 GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) {
6575 if (!validators_->buffer_target.IsValid(target)) { 6601 if (!validators_->buffer_target.IsValid(target)) {
6576 SetGLError(GL_INVALID_ENUM, "glBufferData: target GL_INVALID_ENUM"); 6602 SetGLError(GL_INVALID_ENUM, "glBufferData", "target GL_INVALID_ENUM");
6577 return; 6603 return;
6578 } 6604 }
6579 if (!validators_->buffer_usage.IsValid(usage)) { 6605 if (!validators_->buffer_usage.IsValid(usage)) {
6580 SetGLError(GL_INVALID_ENUM, "glBufferData: usage GL_INVALID_ENUM"); 6606 SetGLError(GL_INVALID_ENUM, "glBufferData", "usage GL_INVALID_ENUM");
6581 return; 6607 return;
6582 } 6608 }
6583 if (size < 0) { 6609 if (size < 0) {
6584 SetGLError(GL_INVALID_VALUE, "glBufferData: size < 0"); 6610 SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0");
6585 return; 6611 return;
6586 } 6612 }
6587 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); 6613 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target);
6588 if (!info) { 6614 if (!info) {
6589 SetGLError(GL_INVALID_VALUE, "glBufferData: unknown buffer"); 6615 SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer");
6590 return; 6616 return;
6591 } 6617 }
6592 // Clear the buffer to 0 if no initial data was passed in. 6618 // Clear the buffer to 0 if no initial data was passed in.
6593 scoped_array<int8> zero; 6619 scoped_array<int8> zero;
6594 if (!data) { 6620 if (!data) {
6595 zero.reset(new int8[size]); 6621 zero.reset(new int8[size]);
6596 memset(zero.get(), 0, size); 6622 memset(zero.get(), 0, size);
6597 data = zero.get(); 6623 data = zero.get();
6598 } 6624 }
6599 6625
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6642 } 6668 }
6643 GLenum usage = static_cast<GLenum>(c.usage); 6669 GLenum usage = static_cast<GLenum>(c.usage);
6644 DoBufferData(target, size, data, usage); 6670 DoBufferData(target, size, data, usage);
6645 return error::kNoError; 6671 return error::kNoError;
6646 } 6672 }
6647 6673
6648 void GLES2DecoderImpl::DoBufferSubData( 6674 void GLES2DecoderImpl::DoBufferSubData(
6649 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { 6675 GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) {
6650 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); 6676 BufferManager::BufferInfo* info = GetBufferInfoForTarget(target);
6651 if (!info) { 6677 if (!info) {
6652 SetGLError(GL_INVALID_VALUE, "glBufferSubData: unknown buffer"); 6678 SetGLError(GL_INVALID_VALUE, "glBufferSubData", "unknown buffer");
6653 return; 6679 return;
6654 } 6680 }
6655 if (!info->SetRange(offset, size, data)) { 6681 if (!info->SetRange(offset, size, data)) {
6656 SetGLError(GL_INVALID_VALUE, "glBufferSubData: out of range"); 6682 SetGLError(GL_INVALID_VALUE, "glBufferSubData", "out of range");
6657 return; 6683 return;
6658 } 6684 }
6659 if (bufferdata_faster_than_buffersubdata_ && 6685 if (bufferdata_faster_than_buffersubdata_ &&
6660 offset == 0 && size == info->size()) { 6686 offset == 0 && size == info->size()) {
6661 glBufferData(target, size, data, info->usage()); 6687 glBufferData(target, size, data, info->usage());
6662 return; 6688 return;
6663 } 6689 }
6664 glBufferSubData(target, offset, size, data); 6690 glBufferSubData(target, offset, size, data);
6665 } 6691 }
6666 6692
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
6756 WrappedTexImage2D( 6782 WrappedTexImage2D(
6757 target, level, format, width, h, 0, format, type, zero.get()); 6783 target, level, format, width, h, 0, format, type, zero.get());
6758 } 6784 }
6759 y += tile_height; 6785 y += tile_height;
6760 } 6786 }
6761 TextureManager::TextureInfo* info = GetTextureInfoForTarget(bind_target); 6787 TextureManager::TextureInfo* info = GetTextureInfoForTarget(bind_target);
6762 glBindTexture(bind_target, info ? info->service_id() : 0); 6788 glBindTexture(bind_target, info ? info->service_id() : 0);
6763 return true; 6789 return true;
6764 } 6790 }
6765 6791
6792 namespace {
6793
6794 const int kS3TCBlockWidth = 4;
6795 const int kS3TCBlockHeight = 4;
6796 const int kS3TCDXT1BlockSize = 8;
6797 const int kS3TCDXT3AndDXT5BlockSize = 16;
6798
6799 bool IsValidDXTSize(GLint level, GLsizei size) {
6800 return (level && size == 1) ||
6801 (level && size == 2) || !(size % kS3TCBlockWidth);
6802 }
6803
6804 } // anonymous namespace.
6805
6806 bool GLES2DecoderImpl::ValidateCompressedTexFuncData(
6807 const char* function_name,
6808 GLsizei width, GLsizei height, GLenum format, size_t size) {
6809 unsigned int bytes_required = 0;
6810
6811 switch (format) {
6812 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6813 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: {
6814 int num_blocks_across =
6815 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
6816 int num_blocks_down =
6817 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
6818 int num_blocks = num_blocks_across * num_blocks_down;
6819 bytes_required = num_blocks * kS3TCDXT1BlockSize;
6820 break;
6821 }
6822 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
6823 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: {
6824 int num_blocks_across =
6825 (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth;
6826 int num_blocks_down =
6827 (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight;
6828 int num_blocks = num_blocks_across * num_blocks_down;
6829 bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize;
6830 break;
6831 }
6832 default:
6833 SetGLError(GL_INVALID_ENUM, function_name, "invalid format");
6834 return false;
6835 }
6836
6837 if (size != bytes_required) {
6838 SetGLError(
6839 GL_INVALID_VALUE, function_name, "size is not correct for dimensions");
6840 return false;
6841 }
6842
6843 return true;
6844 }
6845
6846 bool GLES2DecoderImpl::ValidateCompressedTexDimensions(
6847 const char* function_name,
6848 GLint level, GLsizei width, GLsizei height, GLenum format) {
6849 switch (format) {
6850 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6851 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6852 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
6853 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: {
6854 if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) {
6855 SetGLError(
6856 GL_INVALID_OPERATION, function_name,
6857 "width or height invalid for level");
6858 return false;
6859 }
6860 return true;
6861 }
6862 default:
6863 return false;
6864 }
6865 }
6866
6867 bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions(
6868 const char* function_name,
6869 GLenum target, GLint level, GLint xoffset, GLint yoffset,
6870 GLsizei width, GLsizei height, GLenum format,
6871 TextureManager::TextureInfo* texture) {
6872 if (xoffset < 0 || yoffset < 0) {
6873 SetGLError(
6874 GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0");
6875 return false;
6876 }
6877
6878 switch (format) {
6879 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
6880 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
6881 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
6882 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: {
6883 const int kBlockWidth = 4;
6884 const int kBlockHeight = 4;
6885 if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) {
6886 SetGLError(
6887 GL_INVALID_OPERATION, function_name,
6888 "xoffset or yoffset not multiple of 4");
6889 return false;
6890 }
6891 GLsizei tex_width = 0;
6892 GLsizei tex_height = 0;
6893 if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) ||
6894 width - xoffset > tex_width ||
6895 height - yoffset > tex_height) {
6896 SetGLError(
6897 GL_INVALID_OPERATION, function_name, "dimensions out of range");
6898 return false;
6899 }
6900 return ValidateCompressedTexDimensions(
6901 function_name, level, width, height, format);
6902 }
6903 default:
6904 return false;
6905 }
6906 }
6907
6766 error::Error GLES2DecoderImpl::DoCompressedTexImage2D( 6908 error::Error GLES2DecoderImpl::DoCompressedTexImage2D(
6767 GLenum target, 6909 GLenum target,
6768 GLint level, 6910 GLint level,
6769 GLenum internal_format, 6911 GLenum internal_format,
6770 GLsizei width, 6912 GLsizei width,
6771 GLsizei height, 6913 GLsizei height,
6772 GLint border, 6914 GLint border,
6773 GLsizei image_size, 6915 GLsizei image_size,
6774 const void* data) { 6916 const void* data) {
6775 // TODO(gman): Validate image_size is correct for width, height and format. 6917 // TODO(gman): Validate image_size is correct for width, height and format.
6776 if (!validators_->texture_target.IsValid(target)) { 6918 if (!validators_->texture_target.IsValid(target)) {
6777 SetGLError(GL_INVALID_ENUM, 6919 SetGLError(GL_INVALID_ENUM,
6778 "glCompressedTexImage2D: target GL_INVALID_ENUM"); 6920 "glCompressedTexImage2D", "target GL_INVALID_ENUM");
6779 return error::kNoError; 6921 return error::kNoError;
6780 } 6922 }
6781 if (!validators_->compressed_texture_format.IsValid( 6923 if (!validators_->compressed_texture_format.IsValid(
6782 internal_format)) { 6924 internal_format)) {
6783 SetGLError(GL_INVALID_ENUM, 6925 SetGLError(GL_INVALID_ENUM,
6784 "glCompressedTexImage2D: internal_format GL_INVALID_ENUM"); 6926 "glCompressedTexImage2D", "internal_format GL_INVALID_ENUM");
6785 return error::kNoError; 6927 return error::kNoError;
6786 } 6928 }
6787 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 6929 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
6788 border != 0) { 6930 border != 0) {
6789 SetGLError(GL_INVALID_VALUE, 6931 SetGLError(GL_INVALID_VALUE,
6790 "glCompressedTexImage2D: dimensions out of range"); 6932 "glCompressedTexImage2D", "dimensions out of range");
6791 return error::kNoError; 6933 return error::kNoError;
6792 } 6934 }
6793 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 6935 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
6794 if (!info) { 6936 if (!info) {
6795 SetGLError(GL_INVALID_VALUE, 6937 SetGLError(GL_INVALID_VALUE,
6796 "glCompressedTexImage2D: unknown texture target"); 6938 "glCompressedTexImage2D", "unknown texture target");
6797 return error::kNoError; 6939 return error::kNoError;
6798 } 6940 }
6799 if (info->IsImmutable()) { 6941 if (info->IsImmutable()) {
6800 SetGLError(GL_INVALID_OPERATION, 6942 SetGLError(GL_INVALID_OPERATION,
6801 "glCompressedTexImage2D: texture is immutable"); 6943 "glCompressedTexImage2D", "texture is immutable");
6802 return error::kNoError; 6944 return error::kNoError;
6803 } 6945 }
6804 6946
6947 if (!ValidateCompressedTexDimensions(
6948 "glCompressedTexImage2D", level, width, height, internal_format) ||
6949 !ValidateCompressedTexFuncData(
6950 "glCompressedTexImage2D", width, height, internal_format, image_size)) {
6951 return error::kNoError;
6952 }
6953
6805 if (info->IsAttachedToFramebuffer()) { 6954 if (info->IsAttachedToFramebuffer()) {
6806 state_dirty_ = true; 6955 state_dirty_ = true;
6807 // TODO(gman): If textures tracked which framebuffers they were attached to 6956 // TODO(gman): If textures tracked which framebuffers they were attached to
6808 // we could just mark those framebuffers as not complete. 6957 // we could just mark those framebuffers as not complete.
6809 framebuffer_manager()->IncFramebufferStateChangeCount(); 6958 framebuffer_manager()->IncFramebufferStateChangeCount();
6810 } 6959 }
6811 6960
6812 scoped_array<int8> zero; 6961 scoped_array<int8> zero;
6813 if (!data) { 6962 if (!data) {
6814 zero.reset(new int8[image_size]); 6963 zero.reset(new int8[image_size]);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
6906 return error::kInvalidArguments; 7055 return error::kInvalidArguments;
6907 } 7056 }
6908 uint32 data_size = bucket->size(); 7057 uint32 data_size = bucket->size();
6909 GLsizei imageSize = data_size; 7058 GLsizei imageSize = data_size;
6910 const void* data = bucket->GetData(0, data_size); 7059 const void* data = bucket->GetData(0, data_size);
6911 if (!data) { 7060 if (!data) {
6912 return error::kInvalidArguments; 7061 return error::kInvalidArguments;
6913 } 7062 }
6914 if (!validators_->texture_target.IsValid(target)) { 7063 if (!validators_->texture_target.IsValid(target)) {
6915 SetGLError( 7064 SetGLError(
6916 GL_INVALID_ENUM, "glCompressedTexSubImage2D: target GL_INVALID_ENUM"); 7065 GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target GL_INVALID_ENUM");
6917 return error::kNoError; 7066 return error::kNoError;
6918 } 7067 }
6919 if (!validators_->compressed_texture_format.IsValid(format)) { 7068 if (!validators_->compressed_texture_format.IsValid(format)) {
6920 SetGLError(GL_INVALID_ENUM, 7069 SetGLError(GL_INVALID_ENUM,
6921 "glCompressedTexSubImage2D: format GL_INVALID_ENUM"); 7070 "glCompressedTexSubImage2D", "format GL_INVALID_ENUM");
6922 return error::kNoError; 7071 return error::kNoError;
6923 } 7072 }
6924 if (width < 0) { 7073 if (width < 0) {
6925 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: width < 0"); 7074 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0");
6926 return error::kNoError; 7075 return error::kNoError;
6927 } 7076 }
6928 if (height < 0) { 7077 if (height < 0) {
6929 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: height < 0"); 7078 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0");
6930 return error::kNoError; 7079 return error::kNoError;
6931 } 7080 }
6932 if (imageSize < 0) { 7081 if (imageSize < 0) {
6933 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D: imageSize < 0"); 7082 SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0");
6934 return error::kNoError; 7083 return error::kNoError;
6935 } 7084 }
6936 DoCompressedTexSubImage2D( 7085 DoCompressedTexSubImage2D(
6937 target, level, xoffset, yoffset, width, height, format, imageSize, data); 7086 target, level, xoffset, yoffset, width, height, format, imageSize, data);
6938 return error::kNoError; 7087 return error::kNoError;
6939 } 7088 }
6940 7089
6941 bool GLES2DecoderImpl::ValidateTextureParameters( 7090 bool GLES2DecoderImpl::ValidateTextureParameters(
6942 const char* function_name, 7091 const char* function_name,
6943 GLenum target, GLenum format, GLenum type, GLint level) { 7092 GLenum target, GLenum format, GLenum type, GLint level) {
6944 if (!feature_info_->GetTextureFormatValidator(format).IsValid(type)) { 7093 if (!feature_info_->GetTextureFormatValidator(format).IsValid(type)) {
6945 SetGLError(GL_INVALID_OPERATION, 7094 SetGLError(GL_INVALID_OPERATION, function_name,
6946 (std::string(function_name) + ": invalid type " + 7095 (std::string("invalid type ") +
6947 GLES2Util::GetStringEnum(type) + " for format " + 7096 GLES2Util::GetStringEnum(type) + " for format " +
6948 GLES2Util::GetStringEnum(format)).c_str()); 7097 GLES2Util::GetStringEnum(format)).c_str());
6949 return false; 7098 return false;
6950 } 7099 }
6951 7100
6952 uint32 channels = GLES2Util::GetChannelsForFormat(format); 7101 uint32 channels = GLES2Util::GetChannelsForFormat(format);
6953 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) { 7102 if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) {
6954 SetGLError(GL_INVALID_OPERATION, 7103 SetGLError(GL_INVALID_OPERATION, function_name,
6955 (std::string(function_name) + ": invalid type " + 7104 (std::string("invalid type ") +
6956 GLES2Util::GetStringEnum(type) + " for format " + 7105 GLES2Util::GetStringEnum(type) + " for format " +
6957 GLES2Util::GetStringEnum(format)).c_str()); 7106 GLES2Util::GetStringEnum(format)).c_str());
6958 return false; 7107 return false;
6959 } 7108 }
6960 return true; 7109 return true;
6961 } 7110 }
6962 7111
6963 error::Error GLES2DecoderImpl::DoTexImage2D( 7112 error::Error GLES2DecoderImpl::DoTexImage2D(
6964 GLenum target, 7113 GLenum target,
6965 GLint level, 7114 GLint level,
6966 GLenum internal_format, 7115 GLenum internal_format,
6967 GLsizei width, 7116 GLsizei width,
6968 GLsizei height, 7117 GLsizei height,
6969 GLint border, 7118 GLint border,
6970 GLenum format, 7119 GLenum format,
6971 GLenum type, 7120 GLenum type,
6972 const void* pixels, 7121 const void* pixels,
6973 uint32 pixels_size) { 7122 uint32 pixels_size) {
6974 if (!validators_->texture_target.IsValid(target)) { 7123 if (!validators_->texture_target.IsValid(target)) {
6975 SetGLError(GL_INVALID_ENUM, "glTexImage2D: target GL_INVALID_ENUM"); 7124 SetGLError(GL_INVALID_ENUM, "glTexImage2D", "target GL_INVALID_ENUM");
6976 return error::kNoError; 7125 return error::kNoError;
6977 } 7126 }
6978 if (!validators_->texture_format.IsValid(internal_format)) { 7127 if (!validators_->texture_format.IsValid(internal_format)) {
6979 SetGLError(GL_INVALID_ENUM, 7128 SetGLError(GL_INVALID_ENUM,
6980 "glTexImage2D: internal_format GL_INVALID_ENUM"); 7129 "glTexImage2D", "internal_format GL_INVALID_ENUM");
6981 return error::kNoError; 7130 return error::kNoError;
6982 } 7131 }
6983 if (!validators_->texture_format.IsValid(format)) { 7132 if (!validators_->texture_format.IsValid(format)) {
6984 SetGLError(GL_INVALID_ENUM, "glTexImage2D: format GL_INVALID_ENUM"); 7133 SetGLError(GL_INVALID_ENUM, "glTexImage2D", "format GL_INVALID_ENUM");
6985 return error::kNoError; 7134 return error::kNoError;
6986 } 7135 }
6987 if (!validators_->pixel_type.IsValid(type)) { 7136 if (!validators_->pixel_type.IsValid(type)) {
6988 SetGLError(GL_INVALID_ENUM, "glTexImage2D: type GL_INVALID_ENUM"); 7137 SetGLError(GL_INVALID_ENUM, "glTexImage2D", "type GL_INVALID_ENUM");
6989 return error::kNoError; 7138 return error::kNoError;
6990 } 7139 }
6991 if (format != internal_format) { 7140 if (format != internal_format) {
6992 SetGLError(GL_INVALID_OPERATION, "glTexImage2D: format != internalFormat"); 7141 SetGLError(GL_INVALID_OPERATION,
7142 "glTexImage2D", "format != internalFormat");
6993 return error::kNoError; 7143 return error::kNoError;
6994 } 7144 }
6995 if (!ValidateTextureParameters("glTexImage2D", target, format, type, level)) { 7145 if (!ValidateTextureParameters("glTexImage2D", target, format, type, level)) {
6996 return error::kNoError; 7146 return error::kNoError;
6997 } 7147 }
6998 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7148 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
6999 border != 0) { 7149 border != 0) {
7000 SetGLError(GL_INVALID_VALUE, "glTexImage2D: dimensions out of range"); 7150 SetGLError(GL_INVALID_VALUE, "glTexImage2D", "dimensions out of range");
7001 return error::kNoError; 7151 return error::kNoError;
7002 } 7152 }
7003 if ((GLES2Util::GetChannelsForFormat(format) & 7153 if ((GLES2Util::GetChannelsForFormat(format) &
7004 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) { 7154 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) {
7005 SetGLError( 7155 SetGLError(
7006 GL_INVALID_OPERATION, 7156 GL_INVALID_OPERATION,
7007 "glTexImage2D: can not supply data for depth or stencil textures"); 7157 "glTexImage2D", "can not supply data for depth or stencil textures");
7008 return error::kNoError; 7158 return error::kNoError;
7009 } 7159 }
7010 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 7160 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
7011 if (!info) { 7161 if (!info) {
7012 SetGLError(GL_INVALID_OPERATION, 7162 SetGLError(GL_INVALID_OPERATION,
7013 "glTexImage2D: unknown texture for target"); 7163 "glTexImage2D", "unknown texture for target");
7014 return error::kNoError; 7164 return error::kNoError;
7015 } 7165 }
7016 7166
7017 if (info->IsImmutable()) { 7167 if (info->IsImmutable()) {
7018 SetGLError(GL_INVALID_OPERATION, 7168 SetGLError(GL_INVALID_OPERATION,
7019 "glTexImage2D: texture is immutable"); 7169 "glTexImage2D", "texture is immutable");
7020 return error::kNoError; 7170 return error::kNoError;
7021 } 7171 }
7022 7172
7023 GLsizei tex_width = 0; 7173 GLsizei tex_width = 0;
7024 GLsizei tex_height = 0; 7174 GLsizei tex_height = 0;
7025 GLenum tex_type = 0; 7175 GLenum tex_type = 0;
7026 GLenum tex_format = 0; 7176 GLenum tex_format = 0;
7027 bool level_is_same = 7177 bool level_is_same =
7028 info->GetLevelSize(target, level, &tex_width, &tex_height) && 7178 info->GetLevelSize(target, level, &tex_width, &tex_height) &&
7029 info->GetLevelType(target, level, &tex_type, &tex_format) && 7179 info->GetLevelType(target, level, &tex_type, &tex_format) &&
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
7134 GLint xoffset, 7284 GLint xoffset,
7135 GLint yoffset, 7285 GLint yoffset,
7136 GLsizei width, 7286 GLsizei width,
7137 GLsizei height, 7287 GLsizei height,
7138 GLenum format, 7288 GLenum format,
7139 GLsizei image_size, 7289 GLsizei image_size,
7140 const void * data) { 7290 const void * data) {
7141 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 7291 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
7142 if (!info) { 7292 if (!info) {
7143 SetGLError(GL_INVALID_OPERATION, 7293 SetGLError(GL_INVALID_OPERATION,
7144 "glCompressedTexSubImage2D: unknown texture for target"); 7294 "glCompressedTexSubImage2D", "unknown texture for target");
7145 return; 7295 return;
7146 } 7296 }
7147 GLenum type = 0; 7297 GLenum type = 0;
7148 GLenum internal_format = 0; 7298 GLenum internal_format = 0;
7149 if (!info->GetLevelType(target, level, &type, &internal_format)) { 7299 if (!info->GetLevelType(target, level, &type, &internal_format)) {
7150 SetGLError( 7300 SetGLError(
7151 GL_INVALID_OPERATION, 7301 GL_INVALID_OPERATION,
7152 "glCompressedTexSubImage2D: level does not exist."); 7302 "glCompressedTexSubImage2D", "level does not exist.");
7153 return; 7303 return;
7154 } 7304 }
7155 if (internal_format != format) { 7305 if (internal_format != format) {
7156 SetGLError( 7306 SetGLError(
7157 GL_INVALID_OPERATION, 7307 GL_INVALID_OPERATION,
7158 "glCompressedTexSubImage2D: format does not match internal format."); 7308 "glCompressedTexSubImage2D", "format does not match internal format.");
7159 return; 7309 return;
7160 } 7310 }
7161 if (!info->ValidForTexture( 7311 if (!info->ValidForTexture(
7162 target, level, xoffset, yoffset, width, height, format, type)) { 7312 target, level, xoffset, yoffset, width, height, format, type)) {
7163 SetGLError(GL_INVALID_VALUE, 7313 SetGLError(GL_INVALID_VALUE,
7164 "glCompressedTexSubImage2D: bad dimensions."); 7314 "glCompressedTexSubImage2D", "bad dimensions.");
7165 return; 7315 return;
7166 } 7316 }
7317
7318 if (!ValidateCompressedTexFuncData(
7319 "glCompressedTexSubImage2D", width, height, format, image_size) ||
7320 !ValidateCompressedTexSubDimensions(
7321 "glCompressedTexSubImage2D",
7322 target, level, xoffset, yoffset, width, height, format, info)) {
7323 return;
7324 }
7325
7326
7167 // Note: There is no need to deal with texture cleared tracking here 7327 // Note: There is no need to deal with texture cleared tracking here
7168 // because the validation above means you can only get here if the level 7328 // because the validation above means you can only get here if the level
7169 // is already a matching compressed format and in that case 7329 // is already a matching compressed format and in that case
7170 // CompressedTexImage2D already cleared the texture. 7330 // CompressedTexImage2D already cleared the texture.
7171 glCompressedTexSubImage2D( 7331 glCompressedTexSubImage2D(
7172 target, level, xoffset, yoffset, width, height, format, image_size, data); 7332 target, level, xoffset, yoffset, width, height, format, image_size, data);
7173 } 7333 }
7174 7334
7175 static void Clip( 7335 static void Clip(
7176 GLint start, GLint range, GLint sourceRange, 7336 GLint start, GLint range, GLint sourceRange,
(...skipping 17 matching lines...) Expand all
7194 GLint level, 7354 GLint level,
7195 GLenum internal_format, 7355 GLenum internal_format,
7196 GLint x, 7356 GLint x,
7197 GLint y, 7357 GLint y,
7198 GLsizei width, 7358 GLsizei width,
7199 GLsizei height, 7359 GLsizei height,
7200 GLint border) { 7360 GLint border) {
7201 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 7361 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
7202 if (!info) { 7362 if (!info) {
7203 SetGLError(GL_INVALID_OPERATION, 7363 SetGLError(GL_INVALID_OPERATION,
7204 "glCopyTexImage2D: unknown texture for target"); 7364 "glCopyTexImage2D", "unknown texture for target");
7205 return; 7365 return;
7206 } 7366 }
7207 if (info->IsImmutable()) { 7367 if (info->IsImmutable()) {
7208 SetGLError(GL_INVALID_OPERATION, 7368 SetGLError(GL_INVALID_OPERATION,
7209 "glCopyTexImage2D: texture is immutable"); 7369 "glCopyTexImage2D", "texture is immutable");
7210 } 7370 }
7211 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7371 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
7212 border != 0) { 7372 border != 0) {
7213 SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D: dimensions out of range"); 7373 SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range");
7214 return; 7374 return;
7215 } 7375 }
7216 if (!ValidateTextureParameters( 7376 if (!ValidateTextureParameters(
7217 "glCopyTexImage2D", target, internal_format, GL_UNSIGNED_BYTE, level)) { 7377 "glCopyTexImage2D", target, internal_format, GL_UNSIGNED_BYTE, level)) {
7218 return; 7378 return;
7219 } 7379 }
7220 7380
7221 // Check we have compatible formats. 7381 // Check we have compatible formats.
7222 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 7382 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
7223 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 7383 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
7224 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); 7384 uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format);
7225 7385
7226 if ((channels_needed & channels_exist) != channels_needed) { 7386 if ((channels_needed & channels_exist) != channels_needed) {
7227 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D: incompatible format"); 7387 SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format");
7228 return; 7388 return;
7229 } 7389 }
7230 7390
7231 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 7391 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
7232 SetGLError( 7392 SetGLError(
7233 GL_INVALID_OPERATION, 7393 GL_INVALID_OPERATION,
7234 "glCopyImage2D: can not be used with depth or stencil textures"); 7394 "glCopyImage2D", "can not be used with depth or stencil textures");
7235 return; 7395 return;
7236 } 7396 }
7237 7397
7238 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { 7398 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) {
7239 return; 7399 return;
7240 } 7400 }
7241 7401
7242 CopyRealGLErrorsToWrapper(); 7402 CopyRealGLErrorsToWrapper();
7243 ScopedResolvedFrameBufferBinder binder(this, false, true); 7403 ScopedResolvedFrameBufferBinder binder(this, false, true);
7244 gfx::Size size = GetBoundReadFrameBufferSize(); 7404 gfx::Size size = GetBoundReadFrameBufferSize();
(...skipping 15 matching lines...) Expand all
7260 7420
7261 if (copyX != x || 7421 if (copyX != x ||
7262 copyY != y || 7422 copyY != y ||
7263 copyWidth != width || 7423 copyWidth != width ||
7264 copyHeight != height) { 7424 copyHeight != height) {
7265 // some part was clipped so clear the texture. 7425 // some part was clipped so clear the texture.
7266 if (!ClearLevel( 7426 if (!ClearLevel(
7267 info->service_id(), info->target(), 7427 info->service_id(), info->target(),
7268 target, level, internal_format, GL_UNSIGNED_BYTE, width, height, 7428 target, level, internal_format, GL_UNSIGNED_BYTE, width, height,
7269 info->IsImmutable())) { 7429 info->IsImmutable())) {
7270 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D: dimensions too big"); 7430 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big");
7271 return; 7431 return;
7272 } 7432 }
7273 if (copyHeight > 0 && copyWidth > 0) { 7433 if (copyHeight > 0 && copyWidth > 0) {
7274 GLint dx = copyX - x; 7434 GLint dx = copyX - x;
7275 GLint dy = copyY - y; 7435 GLint dy = copyY - y;
7276 GLint destX = dx; 7436 GLint destX = dx;
7277 GLint destY = dy; 7437 GLint destY = dy;
7278 glCopyTexSubImage2D(target, level, 7438 glCopyTexSubImage2D(target, level,
7279 destX, destY, copyX, copyY, 7439 destX, destY, copyX, copyY,
7280 copyWidth, copyHeight); 7440 copyWidth, copyHeight);
(...skipping 15 matching lines...) Expand all
7296 GLint level, 7456 GLint level,
7297 GLint xoffset, 7457 GLint xoffset,
7298 GLint yoffset, 7458 GLint yoffset,
7299 GLint x, 7459 GLint x,
7300 GLint y, 7460 GLint y,
7301 GLsizei width, 7461 GLsizei width,
7302 GLsizei height) { 7462 GLsizei height) {
7303 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 7463 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
7304 if (!info) { 7464 if (!info) {
7305 SetGLError(GL_INVALID_OPERATION, 7465 SetGLError(GL_INVALID_OPERATION,
7306 "glCopyTexSubImage2D: unknown texture for target"); 7466 "glCopyTexSubImage2D", "unknown texture for target");
7307 return; 7467 return;
7308 } 7468 }
7309 GLenum type = 0; 7469 GLenum type = 0;
7310 GLenum format = 0; 7470 GLenum format = 0;
7311 if (!info->GetLevelType(target, level, &type, &format) || 7471 if (!info->GetLevelType(target, level, &type, &format) ||
7312 !info->ValidForTexture( 7472 !info->ValidForTexture(
7313 target, level, xoffset, yoffset, width, height, format, type)) { 7473 target, level, xoffset, yoffset, width, height, format, type)) {
7314 SetGLError(GL_INVALID_VALUE, 7474 SetGLError(GL_INVALID_VALUE,
7315 "glCopyTexSubImage2D: bad dimensions."); 7475 "glCopyTexSubImage2D", "bad dimensions.");
7316 return; 7476 return;
7317 } 7477 }
7318 7478
7319 // Check we have compatible formats. 7479 // Check we have compatible formats.
7320 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 7480 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
7321 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 7481 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
7322 uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); 7482 uint32 channels_needed = GLES2Util::GetChannelsForFormat(format);
7323 7483
7324 if ((channels_needed & channels_exist) != channels_needed) { 7484 if ((channels_needed & channels_exist) != channels_needed) {
7325 SetGLError( 7485 SetGLError(
7326 GL_INVALID_OPERATION, "glCopyTexSubImage2D: incompatible format"); 7486 GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format");
7327 return; 7487 return;
7328 } 7488 }
7329 7489
7330 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 7490 if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
7331 SetGLError( 7491 SetGLError(
7332 GL_INVALID_OPERATION, 7492 GL_INVALID_OPERATION,
7333 "glCopySubImage2D: can not be used with depth or stencil textures"); 7493 "glCopySubImage2D", "can not be used with depth or stencil textures");
7334 return; 7494 return;
7335 } 7495 }
7336 7496
7337 if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { 7497 if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) {
7338 return; 7498 return;
7339 } 7499 }
7340 7500
7341 ScopedResolvedFrameBufferBinder binder(this, false, true); 7501 ScopedResolvedFrameBufferBinder binder(this, false, true);
7342 gfx::Size size = GetBoundReadFrameBufferSize(); 7502 gfx::Size size = GetBoundReadFrameBufferSize();
7343 GLint copyX = 0; 7503 GLint copyX = 0;
7344 GLint copyY = 0; 7504 GLint copyY = 0;
7345 GLint copyWidth = 0; 7505 GLint copyWidth = 0;
7346 GLint copyHeight = 0; 7506 GLint copyHeight = 0;
7347 Clip(x, width, size.width(), &copyX, &copyWidth); 7507 Clip(x, width, size.width(), &copyX, &copyWidth);
7348 Clip(y, height, size.height(), &copyY, &copyHeight); 7508 Clip(y, height, size.height(), &copyY, &copyHeight);
7349 7509
7350 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { 7510 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) {
7351 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D: dimensions too big"); 7511 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big");
7352 return; 7512 return;
7353 } 7513 }
7354 7514
7355 if (copyX != x || 7515 if (copyX != x ||
7356 copyY != y || 7516 copyY != y ||
7357 copyWidth != width || 7517 copyWidth != width ||
7358 copyHeight != height) { 7518 copyHeight != height) {
7359 // some part was clipped so clear the sub rect. 7519 // some part was clipped so clear the sub rect.
7360 uint32 pixels_size = 0; 7520 uint32 pixels_size = 0;
7361 if (!GLES2Util::ComputeImageDataSizes( 7521 if (!GLES2Util::ComputeImageDataSizes(
7362 width, height, format, type, unpack_alignment_, &pixels_size, NULL, 7522 width, height, format, type, unpack_alignment_, &pixels_size, NULL,
7363 NULL)) { 7523 NULL)) {
7364 SetGLError(GL_INVALID_VALUE, "glCopyTexSubImage2D: dimensions too large"); 7524 SetGLError(
7525 GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large");
7365 return; 7526 return;
7366 } 7527 }
7367 scoped_array<char> zero(new char[pixels_size]); 7528 scoped_array<char> zero(new char[pixels_size]);
7368 memset(zero.get(), 0, pixels_size); 7529 memset(zero.get(), 0, pixels_size);
7369 glTexSubImage2D( 7530 glTexSubImage2D(
7370 target, level, xoffset, yoffset, width, height, 7531 target, level, xoffset, yoffset, width, height,
7371 format, type, zero.get()); 7532 format, type, zero.get());
7372 } 7533 }
7373 7534
7374 if (copyHeight > 0 && copyWidth > 0) { 7535 if (copyHeight > 0 && copyWidth > 0) {
(...skipping 13 matching lines...) Expand all
7388 GLint xoffset, 7549 GLint xoffset,
7389 GLint yoffset, 7550 GLint yoffset,
7390 GLsizei width, 7551 GLsizei width,
7391 GLsizei height, 7552 GLsizei height,
7392 GLenum format, 7553 GLenum format,
7393 GLenum type, 7554 GLenum type,
7394 const void * data) { 7555 const void * data) {
7395 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 7556 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
7396 if (!info) { 7557 if (!info) {
7397 SetGLError(GL_INVALID_OPERATION, 7558 SetGLError(GL_INVALID_OPERATION,
7398 "glTexSubImage2D: unknown texture for target"); 7559 "glTexSubImage2D", "unknown texture for target");
7399 return; 7560 return;
7400 } 7561 }
7401 GLenum current_type = 0; 7562 GLenum current_type = 0;
7402 GLenum internal_format = 0; 7563 GLenum internal_format = 0;
7403 if (!info->GetLevelType(target, level, &current_type, &internal_format)) { 7564 if (!info->GetLevelType(target, level, &current_type, &internal_format)) {
7404 SetGLError( 7565 SetGLError(
7405 GL_INVALID_OPERATION, 7566 GL_INVALID_OPERATION, "glTexSubImage2D", "level does not exist.");
7406 "glTexSubImage2D: level does not exist.");
7407 return; 7567 return;
7408 } 7568 }
7409 if (format != internal_format) { 7569 if (format != internal_format) {
7410 SetGLError(GL_INVALID_OPERATION, 7570 SetGLError(GL_INVALID_OPERATION,
7411 "glTexSubImage2D: format does not match internal format."); 7571 "glTexSubImage2D", "format does not match internal format.");
7412 return; 7572 return;
7413 } 7573 }
7414 if (type != current_type) { 7574 if (type != current_type) {
7415 SetGLError(GL_INVALID_OPERATION, 7575 SetGLError(GL_INVALID_OPERATION,
7416 "glTexSubImage2D: type does not match type of texture."); 7576 "glTexSubImage2D", "type does not match type of texture.");
7417 return; 7577 return;
7418 } 7578 }
7419 7579
7420 if (!info->ValidForTexture( 7580 if (!info->ValidForTexture(
7421 target, level, xoffset, yoffset, width, height, format, type)) { 7581 target, level, xoffset, yoffset, width, height, format, type)) {
7422 SetGLError(GL_INVALID_VALUE, 7582 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "bad dimensions.");
7423 "glTexSubImage2D: bad dimensions.");
7424 return; 7583 return;
7425 } 7584 }
7426 7585
7427 if ((GLES2Util::GetChannelsForFormat(format) & 7586 if ((GLES2Util::GetChannelsForFormat(format) &
7428 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 7587 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
7429 SetGLError( 7588 SetGLError(
7430 GL_INVALID_OPERATION, 7589 GL_INVALID_OPERATION,
7431 "glTexSubImage2D: can not supply data for depth or stencil textures"); 7590 "glTexSubImage2D", "can not supply data for depth or stencil textures");
7432 return; 7591 return;
7433 } 7592 }
7434 7593
7435 GLsizei tex_width = 0; 7594 GLsizei tex_width = 0;
7436 GLsizei tex_height = 0; 7595 GLsizei tex_height = 0;
7437 bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); 7596 bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height);
7438 DCHECK(ok); 7597 DCHECK(ok);
7439 if (xoffset != 0 || yoffset != 0 || 7598 if (xoffset != 0 || yoffset != 0 ||
7440 width != tex_width || height != tex_height) { 7599 width != tex_width || height != tex_height) {
7441 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { 7600 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) {
7442 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D: dimensions too big"); 7601 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big");
7443 return; 7602 return;
7444 } 7603 }
7445 glTexSubImage2D( 7604 glTexSubImage2D(
7446 target, level, xoffset, yoffset, width, height, format, type, data); 7605 target, level, xoffset, yoffset, width, height, format, type, data);
7447 return; 7606 return;
7448 } 7607 }
7449 7608
7450 if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { 7609 if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) {
7451 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the 7610 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the
7452 // same as internal_foramt. If that changes we'll need to look them up. 7611 // same as internal_foramt. If that changes we'll need to look them up.
(...skipping 22 matching lines...) Expand all
7475 GLenum format = static_cast<GLenum>(c.format); 7634 GLenum format = static_cast<GLenum>(c.format);
7476 GLenum type = static_cast<GLenum>(c.type); 7635 GLenum type = static_cast<GLenum>(c.type);
7477 uint32 data_size; 7636 uint32 data_size;
7478 if (!GLES2Util::ComputeImageDataSizes( 7637 if (!GLES2Util::ComputeImageDataSizes(
7479 width, height, format, type, unpack_alignment_, &data_size, NULL, NULL)) { 7638 width, height, format, type, unpack_alignment_, &data_size, NULL, NULL)) {
7480 return error::kOutOfBounds; 7639 return error::kOutOfBounds;
7481 } 7640 }
7482 const void* pixels = GetSharedMemoryAs<const void*>( 7641 const void* pixels = GetSharedMemoryAs<const void*>(
7483 c.pixels_shm_id, c.pixels_shm_offset, data_size); 7642 c.pixels_shm_id, c.pixels_shm_offset, data_size);
7484 if (!validators_->texture_target.IsValid(target)) { 7643 if (!validators_->texture_target.IsValid(target)) {
7485 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: target GL_INVALID_ENUM"); 7644 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "target GL_INVALID_ENUM");
7486 return error::kNoError; 7645 return error::kNoError;
7487 } 7646 }
7488 if (width < 0) { 7647 if (width < 0) {
7489 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: width < 0"); 7648 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "width < 0");
7490 return error::kNoError; 7649 return error::kNoError;
7491 } 7650 }
7492 if (height < 0) { 7651 if (height < 0) {
7493 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: height < 0"); 7652 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "height < 0");
7494 return error::kNoError; 7653 return error::kNoError;
7495 } 7654 }
7496 if (!validators_->texture_format.IsValid(format)) { 7655 if (!validators_->texture_format.IsValid(format)) {
7497 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: format GL_INVALID_ENUM"); 7656 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "format GL_INVALID_ENUM");
7498 return error::kNoError; 7657 return error::kNoError;
7499 } 7658 }
7500 if (!validators_->pixel_type.IsValid(type)) { 7659 if (!validators_->pixel_type.IsValid(type)) {
7501 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: type GL_INVALID_ENUM"); 7660 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "type GL_INVALID_ENUM");
7502 return error::kNoError; 7661 return error::kNoError;
7503 } 7662 }
7504 if (pixels == NULL) { 7663 if (pixels == NULL) {
7505 return error::kOutOfBounds; 7664 return error::kOutOfBounds;
7506 } 7665 }
7507 DoTexSubImage2D( 7666 DoTexSubImage2D(
7508 target, level, xoffset, yoffset, width, height, format, type, pixels); 7667 target, level, xoffset, yoffset, width, height, format, type, pixels);
7509 return error::kNoError; 7668 return error::kNoError;
7510 } 7669 }
7511 7670
(...skipping 12 matching lines...) Expand all
7524 GLenum format = static_cast<GLenum>(c.format); 7683 GLenum format = static_cast<GLenum>(c.format);
7525 GLenum type = static_cast<GLenum>(c.type); 7684 GLenum type = static_cast<GLenum>(c.type);
7526 uint32 data_size; 7685 uint32 data_size;
7527 if (!GLES2Util::ComputeImageDataSizes( 7686 if (!GLES2Util::ComputeImageDataSizes(
7528 width, height, format, type, unpack_alignment_, &data_size, NULL, NULL)) { 7687 width, height, format, type, unpack_alignment_, &data_size, NULL, NULL)) {
7529 return error::kOutOfBounds; 7688 return error::kOutOfBounds;
7530 } 7689 }
7531 const void* pixels = GetImmediateDataAs<const void*>( 7690 const void* pixels = GetImmediateDataAs<const void*>(
7532 c, data_size, immediate_data_size); 7691 c, data_size, immediate_data_size);
7533 if (!validators_->texture_target.IsValid(target)) { 7692 if (!validators_->texture_target.IsValid(target)) {
7534 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: target GL_INVALID_ENUM"); 7693 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "target GL_INVALID_ENUM");
7535 return error::kNoError; 7694 return error::kNoError;
7536 } 7695 }
7537 if (width < 0) { 7696 if (width < 0) {
7538 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: width < 0"); 7697 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "width < 0");
7539 return error::kNoError; 7698 return error::kNoError;
7540 } 7699 }
7541 if (height < 0) { 7700 if (height < 0) {
7542 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D: height < 0"); 7701 SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "height < 0");
7543 return error::kNoError; 7702 return error::kNoError;
7544 } 7703 }
7545 if (!validators_->texture_format.IsValid(format)) { 7704 if (!validators_->texture_format.IsValid(format)) {
7546 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: format GL_INVALID_ENUM"); 7705 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "format GL_INVALID_ENUM");
7547 return error::kNoError; 7706 return error::kNoError;
7548 } 7707 }
7549 if (!validators_->pixel_type.IsValid(type)) { 7708 if (!validators_->pixel_type.IsValid(type)) {
7550 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D: type GL_INVALID_ENUM"); 7709 SetGLError(GL_INVALID_ENUM, "glTexSubImage2D", "type GL_INVALID_ENUM");
7551 return error::kNoError; 7710 return error::kNoError;
7552 } 7711 }
7553 if (pixels == NULL) { 7712 if (pixels == NULL) {
7554 return error::kOutOfBounds; 7713 return error::kOutOfBounds;
7555 } 7714 }
7556 DoTexSubImage2D( 7715 DoTexSubImage2D(
7557 target, level, xoffset, yoffset, width, height, format, type, pixels); 7716 target, level, xoffset, yoffset, width, height, format, type, pixels);
7558 return error::kNoError; 7717 return error::kNoError;
7559 } 7718 }
7560 7719
7561 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( 7720 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv(
7562 uint32 immediate_data_size, const gles2::GetVertexAttribPointerv& c) { 7721 uint32 immediate_data_size, const gles2::GetVertexAttribPointerv& c) {
7563 GLuint index = static_cast<GLuint>(c.index); 7722 GLuint index = static_cast<GLuint>(c.index);
7564 GLenum pname = static_cast<GLenum>(c.pname); 7723 GLenum pname = static_cast<GLenum>(c.pname);
7565 typedef gles2::GetVertexAttribPointerv::Result Result; 7724 typedef gles2::GetVertexAttribPointerv::Result Result;
7566 Result* result = GetSharedMemoryAs<Result*>( 7725 Result* result = GetSharedMemoryAs<Result*>(
7567 c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); 7726 c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1));
7568 if (!result) { 7727 if (!result) {
7569 return error::kOutOfBounds; 7728 return error::kOutOfBounds;
7570 } 7729 }
7571 // Check that the client initialized the result. 7730 // Check that the client initialized the result.
7572 if (result->size != 0) { 7731 if (result->size != 0) {
7573 return error::kInvalidArguments; 7732 return error::kInvalidArguments;
7574 } 7733 }
7575 if (!validators_->vertex_pointer.IsValid(pname)) { 7734 if (!validators_->vertex_pointer.IsValid(pname)) {
7576 SetGLError(GL_INVALID_ENUM, 7735 SetGLError(GL_INVALID_ENUM,
7577 "glGetVertexAttribPointerv: pname GL_INVALID_ENUM"); 7736 "glGetVertexAttribPointerv", "pname GL_INVALID_ENUM");
7578 return error::kNoError; 7737 return error::kNoError;
7579 } 7738 }
7580 if (index >= group_->max_vertex_attribs()) { 7739 if (index >= group_->max_vertex_attribs()) {
7581 SetGLError(GL_INVALID_VALUE, 7740 SetGLError(GL_INVALID_VALUE,
7582 "glGetVertexAttribPointerv: index out of range."); 7741 "glGetVertexAttribPointerv", "index out of range.");
7583 return error::kNoError; 7742 return error::kNoError;
7584 } 7743 }
7585 result->SetNumResults(1); 7744 result->SetNumResults(1);
7586 *result->GetData() = 7745 *result->GetData() =
7587 vertex_attrib_manager_->GetVertexAttribInfo(index)->offset(); 7746 vertex_attrib_manager_->GetVertexAttribInfo(index)->offset();
7588 return error::kNoError; 7747 return error::kNoError;
7589 } 7748 }
7590 7749
7591 bool GLES2DecoderImpl::GetUniformSetup( 7750 bool GLES2DecoderImpl::GetUniformSetup(
7592 GLuint program, GLint fake_location, 7751 GLuint program, GLint fake_location,
(...skipping 17 matching lines...) Expand all
7610 *result_pointer = result; 7769 *result_pointer = result;
7611 // Set the result size to 0 so the client does not have to check for success. 7770 // Set the result size to 0 so the client does not have to check for success.
7612 result->SetNumResults(0); 7771 result->SetNumResults(0);
7613 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 7772 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
7614 program, "glGetUniform"); 7773 program, "glGetUniform");
7615 if (!info) { 7774 if (!info) {
7616 return false; 7775 return false;
7617 } 7776 }
7618 if (!info->IsValid()) { 7777 if (!info->IsValid()) {
7619 // Program was not linked successfully. (ie, glLinkProgram) 7778 // Program was not linked successfully. (ie, glLinkProgram)
7620 SetGLError(GL_INVALID_OPERATION, "glGetUniform: program not linked"); 7779 SetGLError(GL_INVALID_OPERATION, "glGetUniform", "program not linked");
7621 return false; 7780 return false;
7622 } 7781 }
7623 *service_id = info->service_id(); 7782 *service_id = info->service_id();
7624 GLint array_index = -1; 7783 GLint array_index = -1;
7625 const ProgramManager::ProgramInfo::UniformInfo* uniform_info = 7784 const ProgramManager::ProgramInfo::UniformInfo* uniform_info =
7626 info->GetUniformInfoByFakeLocation( 7785 info->GetUniformInfoByFakeLocation(
7627 fake_location, real_location, &array_index); 7786 fake_location, real_location, &array_index);
7628 if (!uniform_info) { 7787 if (!uniform_info) {
7629 // No such location. 7788 // No such location.
7630 SetGLError(GL_INVALID_OPERATION, "glGetUniform: unknown location"); 7789 SetGLError(GL_INVALID_OPERATION, "glGetUniform", "unknown location");
7631 return false; 7790 return false;
7632 } 7791 }
7633 GLenum type = uniform_info->type; 7792 GLenum type = uniform_info->type;
7634 GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); 7793 GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type);
7635 if (size == 0) { 7794 if (size == 0) {
7636 SetGLError(GL_INVALID_OPERATION, "glGetUniform: unknown type"); 7795 SetGLError(GL_INVALID_OPERATION, "glGetUniform", "unknown type");
7637 return false; 7796 return false;
7638 } 7797 }
7639 result = GetSharedMemoryAs<SizedResult<GLint>*>( 7798 result = GetSharedMemoryAs<SizedResult<GLint>*>(
7640 shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); 7799 shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size));
7641 if (!result) { 7800 if (!result) {
7642 *error = error::kOutOfBounds; 7801 *error = error::kOutOfBounds;
7643 return false; 7802 return false;
7644 } 7803 }
7645 result->size = size; 7804 result->size = size;
7646 *result_type = type; 7805 *result_type = type;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
7705 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 7864 c.result_shm_id, c.result_shm_offset, sizeof(*result));
7706 if (!result) { 7865 if (!result) {
7707 return error::kOutOfBounds; 7866 return error::kOutOfBounds;
7708 } 7867 }
7709 // Check that the client initialized the result. 7868 // Check that the client initialized the result.
7710 if (result->success != 0) { 7869 if (result->success != 0) {
7711 return error::kInvalidArguments; 7870 return error::kInvalidArguments;
7712 } 7871 }
7713 if (!validators_->shader_type.IsValid(shader_type)) { 7872 if (!validators_->shader_type.IsValid(shader_type)) {
7714 SetGLError(GL_INVALID_ENUM, 7873 SetGLError(GL_INVALID_ENUM,
7715 "glGetShaderPrecisionFormat: shader_type GL_INVALID_ENUM"); 7874 "glGetShaderPrecisionFormat", "shader_type GL_INVALID_ENUM");
7716 return error::kNoError; 7875 return error::kNoError;
7717 } 7876 }
7718 if (!validators_->shader_precision.IsValid(precision_type)) { 7877 if (!validators_->shader_precision.IsValid(precision_type)) {
7719 SetGLError(GL_INVALID_ENUM, 7878 SetGLError(GL_INVALID_ENUM,
7720 "glGetShaderPrecisionFormat: precision_type GL_INVALID_ENUM"); 7879 "glGetShaderPrecisionFormat", "precision_type GL_INVALID_ENUM");
7721 return error::kNoError; 7880 return error::kNoError;
7722 } 7881 }
7723 7882
7724 result->success = 1; // true 7883 result->success = 1; // true
7725 switch (precision_type) { 7884 switch (precision_type) {
7726 case GL_LOW_INT: 7885 case GL_LOW_INT:
7727 case GL_MEDIUM_INT: 7886 case GL_MEDIUM_INT:
7728 case GL_HIGH_INT: 7887 case GL_HIGH_INT:
7729 // These values are for a 32-bit twos-complement integer format. 7888 // These values are for a 32-bit twos-complement integer format.
7730 result->min_range = 31; 7889 result->min_range = 31;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7796 return error::kInvalidArguments; 7955 return error::kInvalidArguments;
7797 } 7956 }
7798 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 7957 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
7799 program, "glGetActiveUniform"); 7958 program, "glGetActiveUniform");
7800 if (!info) { 7959 if (!info) {
7801 return error::kNoError; 7960 return error::kNoError;
7802 } 7961 }
7803 const ProgramManager::ProgramInfo::UniformInfo* uniform_info = 7962 const ProgramManager::ProgramInfo::UniformInfo* uniform_info =
7804 info->GetUniformInfo(index); 7963 info->GetUniformInfo(index);
7805 if (!uniform_info) { 7964 if (!uniform_info) {
7806 SetGLError(GL_INVALID_VALUE, "glGetActiveUniform: index out of range"); 7965 SetGLError(GL_INVALID_VALUE, "glGetActiveUniform", "index out of range");
7807 return error::kNoError; 7966 return error::kNoError;
7808 } 7967 }
7809 result->success = 1; // true. 7968 result->success = 1; // true.
7810 result->size = uniform_info->size; 7969 result->size = uniform_info->size;
7811 result->type = uniform_info->type; 7970 result->type = uniform_info->type;
7812 Bucket* bucket = CreateBucket(name_bucket_id); 7971 Bucket* bucket = CreateBucket(name_bucket_id);
7813 bucket->SetFromString(uniform_info->name.c_str()); 7972 bucket->SetFromString(uniform_info->name.c_str());
7814 return error::kNoError; 7973 return error::kNoError;
7815 } 7974 }
7816 7975
(...skipping 13 matching lines...) Expand all
7830 return error::kInvalidArguments; 7989 return error::kInvalidArguments;
7831 } 7990 }
7832 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( 7991 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader(
7833 program, "glGetActiveAttrib"); 7992 program, "glGetActiveAttrib");
7834 if (!info) { 7993 if (!info) {
7835 return error::kNoError; 7994 return error::kNoError;
7836 } 7995 }
7837 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = 7996 const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info =
7838 info->GetAttribInfo(index); 7997 info->GetAttribInfo(index);
7839 if (!attrib_info) { 7998 if (!attrib_info) {
7840 SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib: index out of range"); 7999 SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range");
7841 return error::kNoError; 8000 return error::kNoError;
7842 } 8001 }
7843 result->success = 1; // true. 8002 result->success = 1; // true.
7844 result->size = attrib_info->size; 8003 result->size = attrib_info->size;
7845 result->type = attrib_info->type; 8004 result->type = attrib_info->type;
7846 Bucket* bucket = CreateBucket(name_bucket_id); 8005 Bucket* bucket = CreateBucket(name_bucket_id);
7847 bucket->SetFromString(attrib_info->name.c_str()); 8006 bucket->SetFromString(attrib_info->name.c_str());
7848 return error::kNoError; 8007 return error::kNoError;
7849 } 8008 }
7850 8009
7851 error::Error GLES2DecoderImpl::HandleShaderBinary( 8010 error::Error GLES2DecoderImpl::HandleShaderBinary(
7852 uint32 immediate_data_size, const gles2::ShaderBinary& c) { 8011 uint32 immediate_data_size, const gles2::ShaderBinary& c) {
7853 #if 1 // No binary shader support. 8012 #if 1 // No binary shader support.
7854 SetGLError(GL_INVALID_OPERATION, "glShaderBinary: not supported"); 8013 SetGLError(GL_INVALID_OPERATION, "glShaderBinary", "not supported");
7855 return error::kNoError; 8014 return error::kNoError;
7856 #else 8015 #else
7857 GLsizei n = static_cast<GLsizei>(c.n); 8016 GLsizei n = static_cast<GLsizei>(c.n);
7858 if (n < 0) { 8017 if (n < 0) {
7859 SetGLError(GL_INVALID_VALUE, "glShaderBinary: n < 0"); 8018 SetGLError(GL_INVALID_VALUE, "glShaderBinary", "n < 0");
7860 return error::kNoError; 8019 return error::kNoError;
7861 } 8020 }
7862 GLsizei length = static_cast<GLsizei>(c.length); 8021 GLsizei length = static_cast<GLsizei>(c.length);
7863 if (length < 0) { 8022 if (length < 0) {
7864 SetGLError(GL_INVALID_VALUE, "glShaderBinary: length < 0"); 8023 SetGLError(GL_INVALID_VALUE, "glShaderBinary", "length < 0");
7865 return error::kNoError; 8024 return error::kNoError;
7866 } 8025 }
7867 uint32 data_size; 8026 uint32 data_size;
7868 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { 8027 if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
7869 return error::kOutOfBounds; 8028 return error::kOutOfBounds;
7870 } 8029 }
7871 const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( 8030 const GLuint* shaders = GetSharedMemoryAs<const GLuint*>(
7872 c.shaders_shm_id, c.shaders_shm_offset, data_size); 8031 c.shaders_shm_id, c.shaders_shm_offset, data_size);
7873 GLenum binaryformat = static_cast<GLenum>(c.binaryformat); 8032 GLenum binaryformat = static_cast<GLenum>(c.binaryformat);
7874 const void* binary = GetSharedMemoryAs<const void*>( 8033 const void* binary = GetSharedMemoryAs<const void*>(
7875 c.binary_shm_id, c.binary_shm_offset, length); 8034 c.binary_shm_id, c.binary_shm_offset, length);
7876 if (shaders == NULL || binary == NULL) { 8035 if (shaders == NULL || binary == NULL) {
7877 return error::kOutOfBounds; 8036 return error::kOutOfBounds;
7878 } 8037 }
7879 scoped_array<GLuint> service_ids(new GLuint[n]); 8038 scoped_array<GLuint> service_ids(new GLuint[n]);
7880 for (GLsizei ii = 0; ii < n; ++ii) { 8039 for (GLsizei ii = 0; ii < n; ++ii) {
7881 ShaderManager::ShaderInfo* info = GetShaderInfo(shaders[ii]); 8040 ShaderManager::ShaderInfo* info = GetShaderInfo(shaders[ii]);
7882 if (!info) { 8041 if (!info) {
7883 SetGLError(GL_INVALID_VALUE, "glShaderBinary: unknown shader"); 8042 SetGLError(GL_INVALID_VALUE, "glShaderBinary", "unknown shader");
7884 return error::kNoError; 8043 return error::kNoError;
7885 } 8044 }
7886 service_ids[ii] = info->service_id(); 8045 service_ids[ii] = info->service_id();
7887 } 8046 }
7888 // TODO(gman): call glShaderBinary 8047 // TODO(gman): call glShaderBinary
7889 return error::kNoError; 8048 return error::kNoError;
7890 #endif 8049 #endif
7891 } 8050 }
7892 8051
7893 error::Error GLES2DecoderImpl::HandleSwapBuffers( 8052 error::Error GLES2DecoderImpl::HandleSwapBuffers(
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
8105 // them. 8264 // them.
8106 scoped_array<GLenum> enums(new GLenum[count]); 8265 scoped_array<GLenum> enums(new GLenum[count]);
8107 memcpy(enums.get(), pnames, pnames_size); 8266 memcpy(enums.get(), pnames, pnames_size);
8108 8267
8109 // Count up the space needed for the result. 8268 // Count up the space needed for the result.
8110 uint32 num_results = 0; 8269 uint32 num_results = 0;
8111 for (GLuint ii = 0; ii < count; ++ii) { 8270 for (GLuint ii = 0; ii < count; ++ii) {
8112 uint32 num = util_.GLGetNumValuesReturned(enums[ii]); 8271 uint32 num = util_.GLGetNumValuesReturned(enums[ii]);
8113 if (num == 0) { 8272 if (num == 0) {
8114 SetGLError(GL_INVALID_ENUM, 8273 SetGLError(GL_INVALID_ENUM,
8115 "glGetMulitpleCHROMIUM: pname GL_INVALID_ENUM"); 8274 "glGetMulitpleCHROMIUM", "pname GL_INVALID_ENUM");
8116 return error::kNoError; 8275 return error::kNoError;
8117 } 8276 }
8118 // Num will never be more than 4. 8277 // Num will never be more than 4.
8119 DCHECK_LE(num, 4u); 8278 DCHECK_LE(num, 4u);
8120 if (!SafeAdd(num_results, num, &num_results)) { 8279 if (!SafeAdd(num_results, num, &num_results)) {
8121 return error::kOutOfBounds; 8280 return error::kOutOfBounds;
8122 } 8281 }
8123 } 8282 }
8124 8283
8125 uint32 result_size = 0; 8284 uint32 result_size = 0;
8126 if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { 8285 if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) {
8127 return error::kOutOfBounds; 8286 return error::kOutOfBounds;
8128 } 8287 }
8129 8288
8130 if (result_size != static_cast<uint32>(c.size)) { 8289 if (result_size != static_cast<uint32>(c.size)) {
8131 SetGLError(GL_INVALID_VALUE, 8290 SetGLError(GL_INVALID_VALUE,
8132 "glGetMulitpleCHROMIUM: bad size GL_INVALID_VALUE"); 8291 "glGetMulitpleCHROMIUM", "bad size GL_INVALID_VALUE");
8133 return error::kNoError; 8292 return error::kNoError;
8134 } 8293 }
8135 8294
8136 GLint* results = GetSharedMemoryAs<GLint*>( 8295 GLint* results = GetSharedMemoryAs<GLint*>(
8137 c.results_shm_id, c.results_shm_offset, result_size); 8296 c.results_shm_id, c.results_shm_offset, result_size);
8138 if (results == NULL) { 8297 if (results == NULL) {
8139 return error::kOutOfBounds; 8298 return error::kOutOfBounds;
8140 } 8299 }
8141 8300
8142 // Check the results have been cleared in case the context was lost. 8301 // Check the results have been cleared in case the context was lost.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
8174 info = GetProgramInfo(program); 8333 info = GetProgramInfo(program);
8175 if (!info || !info->IsValid()) { 8334 if (!info || !info->IsValid()) {
8176 return error::kNoError; 8335 return error::kNoError;
8177 } 8336 }
8178 info->GetProgramInfo(program_manager(), bucket); 8337 info->GetProgramInfo(program_manager(), bucket);
8179 return error::kNoError; 8338 return error::kNoError;
8180 } 8339 }
8181 8340
8182 error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { 8341 error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() {
8183 switch (reset_status_) { 8342 switch (reset_status_) {
8184 case GL_NO_ERROR: 8343 case GL_NO_ERROR:
8185 // TODO(kbr): improve the precision of the error code in this case. 8344 // TODO(kbr): improve the precision of the error code in this case.
8186 // Consider delegating to context for error code if MakeCurrent fails. 8345 // Consider delegating to context for error code if MakeCurrent fails.
8187 return error::kUnknown; 8346 return error::kUnknown;
8188 case GL_GUILTY_CONTEXT_RESET_ARB: 8347 case GL_GUILTY_CONTEXT_RESET_ARB:
8189 return error::kGuilty; 8348 return error::kGuilty;
8190 case GL_INNOCENT_CONTEXT_RESET_ARB: 8349 case GL_INNOCENT_CONTEXT_RESET_ARB:
8191 return error::kInnocent; 8350 return error::kInnocent;
8192 case GL_UNKNOWN_CONTEXT_RESET_ARB: 8351 case GL_UNKNOWN_CONTEXT_RESET_ARB:
8193 return error::kUnknown; 8352 return error::kUnknown;
8194 } 8353 }
8195 8354
8196 NOTREACHED(); 8355 NOTREACHED();
8197 return error::kUnknown; 8356 return error::kUnknown;
8198 } 8357 }
8199 8358
8200 bool GLES2DecoderImpl::WasContextLost() { 8359 bool GLES2DecoderImpl::WasContextLost() {
8201 if (context_->WasAllocatedUsingARBRobustness() && has_arb_robustness_) { 8360 if (context_->WasAllocatedUsingARBRobustness() && has_arb_robustness_) {
8202 GLenum status = glGetGraphicsResetStatusARB(); 8361 GLenum status = glGetGraphicsResetStatusARB();
8203 if (status != GL_NO_ERROR) { 8362 if (status != GL_NO_ERROR) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8252 GLenum target = static_cast<GLenum>(c.target); 8411 GLenum target = static_cast<GLenum>(c.target);
8253 GLuint client_id = static_cast<GLuint>(c.id); 8412 GLuint client_id = static_cast<GLuint>(c.id);
8254 int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); 8413 int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id);
8255 uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); 8414 uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset);
8256 8415
8257 switch (target) { 8416 switch (target) {
8258 case GL_COMMANDS_ISSUED_CHROMIUM: 8417 case GL_COMMANDS_ISSUED_CHROMIUM:
8259 break; 8418 break;
8260 default: 8419 default:
8261 if (!feature_info_->feature_flags().occlusion_query_boolean) { 8420 if (!feature_info_->feature_flags().occlusion_query_boolean) {
8262 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT: not enabled"); 8421 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "not enabled");
8263 return error::kNoError; 8422 return error::kNoError;
8264 } 8423 }
8265 break; 8424 break;
8266 } 8425 }
8267 8426
8268 if (current_query_) { 8427 if (current_query_) {
8269 SetGLError( 8428 SetGLError(
8270 GL_INVALID_OPERATION, "glBeginQueryEXT: query already in progress"); 8429 GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress");
8271 return error::kNoError; 8430 return error::kNoError;
8272 } 8431 }
8273 8432
8274 if (client_id == 0) { 8433 if (client_id == 0) {
8275 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT: id is 0"); 8434 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0");
8276 return error::kNoError; 8435 return error::kNoError;
8277 } 8436 }
8278 8437
8279 QueryManager::Query* query = query_manager_->GetQuery(client_id); 8438 QueryManager::Query* query = query_manager_->GetQuery(client_id);
8280 if (!query) { 8439 if (!query) {
8281 // TODO(gman): Decide if we need this check. 8440 // TODO(gman): Decide if we need this check.
8282 // 8441 //
8283 // Checks id was made by glGenQueries 8442 // Checks id was made by glGenQueries
8284 // 8443 //
8285 // From the POV of OpenGL ES 2.0 you need to call glGenQueriesEXT 8444 // From the POV of OpenGL ES 2.0 you need to call glGenQueriesEXT
8286 // for all Query ids but from the POV of the command buffer service maybe 8445 // for all Query ids but from the POV of the command buffer service maybe
8287 // you don't. 8446 // you don't.
8288 // 8447 //
8289 // The client can enforce this. I don't think the service cares. 8448 // The client can enforce this. I don't think the service cares.
8290 // 8449 //
8291 // IdAllocatorInterface* id_allocator = 8450 // IdAllocatorInterface* id_allocator =
8292 // group_->GetIdAllocator(id_namespaces::kQueries); 8451 // group_->GetIdAllocator(id_namespaces::kQueries);
8293 // if (!id_allocator->InUse(client_id)) { 8452 // if (!id_allocator->InUse(client_id)) {
8294 // SetGLError(GL_INVALID_OPERATION, 8453 // SetGLError(GL_INVALID_OPERATION,
8295 // "glBeginQueryEXT: id not made by glGenQueriesEXT"); 8454 // "glBeginQueryEXT", "id not made by glGenQueriesEXT");
8296 // return error::kNoError; 8455 // return error::kNoError;
8297 // } 8456 // }
8298 query = query_manager_->CreateQuery( 8457 query = query_manager_->CreateQuery(
8299 target, client_id, sync_shm_id, sync_shm_offset); 8458 target, client_id, sync_shm_id, sync_shm_offset);
8300 } 8459 }
8301 8460
8302 if (query->target() != target) { 8461 if (query->target() != target) {
8303 SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT: target does not match"); 8462 SetGLError(
8463 GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match");
8304 return error::kNoError; 8464 return error::kNoError;
8305 } else if (query->shm_id() != sync_shm_id || 8465 } else if (query->shm_id() != sync_shm_id ||
8306 query->shm_offset() != sync_shm_offset) { 8466 query->shm_offset() != sync_shm_offset) {
8307 DLOG(ERROR) << "Shared memory used by query not the same as before"; 8467 DLOG(ERROR) << "Shared memory used by query not the same as before";
8308 return error::kInvalidArguments; 8468 return error::kInvalidArguments;
8309 } 8469 }
8310 8470
8311 if (!query_manager_->BeginQuery(query)) { 8471 if (!query_manager_->BeginQuery(query)) {
8312 return error::kOutOfBounds; 8472 return error::kOutOfBounds;
8313 } 8473 }
8314 8474
8315 current_query_ = query; 8475 current_query_ = query;
8316 return error::kNoError; 8476 return error::kNoError;
8317 } 8477 }
8318 8478
8319 error::Error GLES2DecoderImpl::HandleEndQueryEXT( 8479 error::Error GLES2DecoderImpl::HandleEndQueryEXT(
8320 uint32 immediate_data_size, const gles2::EndQueryEXT& c) { 8480 uint32 immediate_data_size, const gles2::EndQueryEXT& c) {
8321 GLenum target = static_cast<GLenum>(c.target); 8481 GLenum target = static_cast<GLenum>(c.target);
8322 uint32 submit_count = static_cast<GLuint>(c.submit_count); 8482 uint32 submit_count = static_cast<GLuint>(c.submit_count);
8323 8483
8324 if (!current_query_) { 8484 if (!current_query_) {
8325 SetGLError(GL_INVALID_OPERATION, "glEndQueryEXT: No active query"); 8485 SetGLError(GL_INVALID_OPERATION, "glEndQueryEXT", "No active query");
8326 return error::kNoError; 8486 return error::kNoError;
8327 } 8487 }
8328 if (current_query_->target() != target) { 8488 if (current_query_->target() != target) {
8329 SetGLError(GL_INVALID_OPERATION, 8489 SetGLError(GL_INVALID_OPERATION,
8330 "glEndQueryEXT: target does not match active query"); 8490 "glEndQueryEXT", "target does not match active query");
8331 return error::kNoError; 8491 return error::kNoError;
8332 } 8492 }
8333 8493
8334 if (!query_manager_->EndQuery(current_query_, submit_count)) { 8494 if (!query_manager_->EndQuery(current_query_, submit_count)) {
8335 return error::kOutOfBounds; 8495 return error::kOutOfBounds;
8336 } 8496 }
8337 8497
8338 current_query_ = NULL; 8498 current_query_ = NULL;
8339 return error::kNoError; 8499 return error::kNoError;
8340 } 8500 }
8341 8501
8342 error::Error GLES2DecoderImpl::HandleCreateStreamTextureCHROMIUM( 8502 error::Error GLES2DecoderImpl::HandleCreateStreamTextureCHROMIUM(
8343 uint32 immediate_data_size, 8503 uint32 immediate_data_size,
8344 const gles2::CreateStreamTextureCHROMIUM& c) { 8504 const gles2::CreateStreamTextureCHROMIUM& c) {
8345 if (!feature_info_->feature_flags().chromium_stream_texture) { 8505 if (!feature_info_->feature_flags().chromium_stream_texture) {
8346 SetGLError(GL_INVALID_OPERATION, 8506 SetGLError(GL_INVALID_OPERATION,
8347 "glOpenStreamTextureCHROMIUM: " 8507 "glOpenStreamTextureCHROMIUM", ""
8348 "not supported."); 8508 "not supported.");
8349 return error::kNoError; 8509 return error::kNoError;
8350 } 8510 }
8351 8511
8352 uint32 client_id = c.client_id; 8512 uint32 client_id = c.client_id;
8353 typedef gles2::CreateStreamTextureCHROMIUM::Result Result; 8513 typedef gles2::CreateStreamTextureCHROMIUM::Result Result;
8354 Result* result = GetSharedMemoryAs<Result*>( 8514 Result* result = GetSharedMemoryAs<Result*>(
8355 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 8515 c.result_shm_id, c.result_shm_offset, sizeof(*result));
8356 8516
8357 if (!result) 8517 if (!result)
8358 return error::kOutOfBounds; 8518 return error::kOutOfBounds;
8359 *result = GL_ZERO; 8519 *result = GL_ZERO;
8360 TextureManager::TextureInfo* info = 8520 TextureManager::TextureInfo* info =
8361 texture_manager()->GetTextureInfo(client_id); 8521 texture_manager()->GetTextureInfo(client_id);
8362 if (!info) { 8522 if (!info) {
8363 SetGLError(GL_INVALID_VALUE, 8523 SetGLError(GL_INVALID_VALUE,
8364 "glCreateStreamTextureCHROMIUM: " 8524 "glCreateStreamTextureCHROMIUM", ""
8365 "bad texture id."); 8525 "bad texture id.");
8366 return error::kNoError; 8526 return error::kNoError;
8367 } 8527 }
8368 8528
8369 if (info->IsStreamTexture()) { 8529 if (info->IsStreamTexture()) {
8370 SetGLError(GL_INVALID_OPERATION, 8530 SetGLError(GL_INVALID_OPERATION,
8371 "glCreateStreamTextureCHROMIUM: " 8531 "glCreateStreamTextureCHROMIUM", ""
8372 "is already a stream texture."); 8532 "is already a stream texture.");
8373 return error::kNoError; 8533 return error::kNoError;
8374 } 8534 }
8375 8535
8376 if (info->target() && info->target() != GL_TEXTURE_EXTERNAL_OES) { 8536 if (info->target() && info->target() != GL_TEXTURE_EXTERNAL_OES) {
8377 SetGLError(GL_INVALID_OPERATION, 8537 SetGLError(GL_INVALID_OPERATION,
8378 "glCreateStreamTextureCHROMIUM: " 8538 "glCreateStreamTextureCHROMIUM", ""
8379 "is already bound to incompatible target."); 8539 "is already bound to incompatible target.");
8380 return error::kNoError; 8540 return error::kNoError;
8381 } 8541 }
8382 8542
8383 if (!stream_texture_manager_) 8543 if (!stream_texture_manager_)
8384 return error::kInvalidArguments; 8544 return error::kInvalidArguments;
8385 8545
8386 GLuint object_id = stream_texture_manager_->CreateStreamTexture( 8546 GLuint object_id = stream_texture_manager_->CreateStreamTexture(
8387 info->service_id(), client_id); 8547 info->service_id(), client_id);
8388 8548
8389 if (object_id) { 8549 if (object_id) {
8390 info->SetStreamTexture(true); 8550 info->SetStreamTexture(true);
8391 } else { 8551 } else {
8392 SetGLError(GL_OUT_OF_MEMORY, 8552 SetGLError(GL_OUT_OF_MEMORY,
8393 "glCreateStreamTextureCHROMIUM: " 8553 "glCreateStreamTextureCHROMIUM", ""
8394 "failed to create platform texture."); 8554 "failed to create platform texture.");
8395 } 8555 }
8396 8556
8397 *result = object_id; 8557 *result = object_id;
8398 return error::kNoError; 8558 return error::kNoError;
8399 } 8559 }
8400 8560
8401 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( 8561 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM(
8402 uint32 immediate_data_size, 8562 uint32 immediate_data_size,
8403 const gles2::DestroyStreamTextureCHROMIUM& c) { 8563 const gles2::DestroyStreamTextureCHROMIUM& c) {
8404 GLuint client_id = c.texture; 8564 GLuint client_id = c.texture;
8405 TextureManager::TextureInfo* info = 8565 TextureManager::TextureInfo* info =
8406 texture_manager()->GetTextureInfo(client_id); 8566 texture_manager()->GetTextureInfo(client_id);
8407 if (info && info->IsStreamTexture()) { 8567 if (info && info->IsStreamTexture()) {
8408 if (!stream_texture_manager_) 8568 if (!stream_texture_manager_)
8409 return error::kInvalidArguments; 8569 return error::kInvalidArguments;
8410 8570
8411 stream_texture_manager_->DestroyStreamTexture(info->service_id()); 8571 stream_texture_manager_->DestroyStreamTexture(info->service_id());
8412 info->SetStreamTexture(false); 8572 info->SetStreamTexture(false);
8413 texture_manager()->SetInfoTarget(info, 0); 8573 texture_manager()->SetInfoTarget(info, 0);
8414 } else { 8574 } else {
8415 SetGLError(GL_INVALID_VALUE, 8575 SetGLError(GL_INVALID_VALUE,
8416 "glDestroyStreamTextureCHROMIUM: bad texture id."); 8576 "glDestroyStreamTextureCHROMIUM", "bad texture id.");
8417 } 8577 }
8418 8578
8419 return error::kNoError; 8579 return error::kNoError;
8420 } 8580 }
8421 8581
8422 #if defined(OS_MACOSX) 8582 #if defined(OS_MACOSX)
8423 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { 8583 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) {
8424 TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( 8584 TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find(
8425 texture_id); 8585 texture_id);
8426 if (it != texture_to_io_surface_map_.end()) { 8586 if (it != texture_to_io_surface_map_.end()) {
8427 // Found a previous IOSurface bound to this texture; release it. 8587 // Found a previous IOSurface bound to this texture; release it.
8428 CFTypeRef surface = it->second; 8588 CFTypeRef surface = it->second;
8429 CFRelease(surface); 8589 CFRelease(surface);
8430 texture_to_io_surface_map_.erase(it); 8590 texture_to_io_surface_map_.erase(it);
8431 } 8591 }
8432 } 8592 }
8433 #endif 8593 #endif
8434 8594
8435 void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( 8595 void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM(
8436 GLenum target, GLsizei width, GLsizei height, 8596 GLenum target, GLsizei width, GLsizei height,
8437 GLuint io_surface_id, GLuint plane) { 8597 GLuint io_surface_id, GLuint plane) {
8438 #if defined(OS_MACOSX) 8598 #if defined(OS_MACOSX)
8439 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { 8599 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) {
8440 SetGLError(GL_INVALID_OPERATION, 8600 SetGLError(
8441 "glTexImageIOSurface2DCHROMIUM: only supported on desktop GL."); 8601 GL_INVALID_OPERATION,
8602 "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL.");
8442 return; 8603 return;
8443 } 8604 }
8444 8605
8445 IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); 8606 IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize();
8446 if (!surface_support) { 8607 if (!surface_support) {
8447 SetGLError(GL_INVALID_OPERATION, 8608 SetGLError(GL_INVALID_OPERATION,
8448 "glTexImageIOSurface2DCHROMIUM: only supported on 10.6."); 8609 "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6.");
8449 return; 8610 return;
8450 } 8611 }
8451 8612
8452 if (target != GL_TEXTURE_RECTANGLE_ARB) { 8613 if (target != GL_TEXTURE_RECTANGLE_ARB) {
8453 // This might be supported in the future, and if we could require 8614 // This might be supported in the future, and if we could require
8454 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we 8615 // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we
8455 // could delete a lot of code. For now, perform strict validation so we 8616 // could delete a lot of code. For now, perform strict validation so we
8456 // know what's going on. 8617 // know what's going on.
8457 SetGLError( 8618 SetGLError(
8458 GL_INVALID_OPERATION, 8619 GL_INVALID_OPERATION,
8459 "glTexImageIOSurface2DCHROMIUM: requires TEXTURE_RECTANGLE_ARB target"); 8620 "glTexImageIOSurface2DCHROMIUM",
8621 "requires TEXTURE_RECTANGLE_ARB target");
8460 return; 8622 return;
8461 } 8623 }
8462 8624
8463 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 8625 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8464 if (!info) { 8626 if (!info) {
8465 SetGLError(GL_INVALID_OPERATION, 8627 SetGLError(GL_INVALID_OPERATION,
8466 "glTexImageIOSurface2DCHROMIUM: no rectangle texture bound"); 8628 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound");
8467 return; 8629 return;
8468 } 8630 }
8469 if (info == texture_manager()->GetDefaultTextureInfo(target)) { 8631 if (info == texture_manager()->GetDefaultTextureInfo(target)) {
8470 // Maybe this is conceptually valid, but disallow it to avoid accidents. 8632 // Maybe this is conceptually valid, but disallow it to avoid accidents.
8471 SetGLError(GL_INVALID_OPERATION, 8633 SetGLError(GL_INVALID_OPERATION,
8472 "glTexImageIOSurface2DCHROMIUM: can't bind default texture"); 8634 "glTexImageIOSurface2DCHROMIUM", "can't bind default texture");
8473 return; 8635 return;
8474 } 8636 }
8475 8637
8476 // Look up the new IOSurface. Note that because of asynchrony 8638 // Look up the new IOSurface. Note that because of asynchrony
8477 // between processes this might fail; during live resizing the 8639 // between processes this might fail; during live resizing the
8478 // plugin process might allocate and release an IOSurface before 8640 // plugin process might allocate and release an IOSurface before
8479 // this process gets a chance to look it up. Hold on to any old 8641 // this process gets a chance to look it up. Hold on to any old
8480 // IOSurface in this case. 8642 // IOSurface in this case.
8481 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); 8643 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id);
8482 if (!surface) { 8644 if (!surface) {
8483 SetGLError(GL_INVALID_OPERATION, 8645 SetGLError(
8484 "glTexImageIOSurface2DCHROMIUM: no IOSurface with the given ID"); 8646 GL_INVALID_OPERATION,
8647 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID");
8485 return; 8648 return;
8486 } 8649 }
8487 8650
8488 // Release any IOSurface previously bound to this texture. 8651 // Release any IOSurface previously bound to this texture.
8489 ReleaseIOSurfaceForTexture(info->service_id()); 8652 ReleaseIOSurfaceForTexture(info->service_id());
8490 8653
8491 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. 8654 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails.
8492 texture_to_io_surface_map_.insert( 8655 texture_to_io_surface_map_.insert(
8493 std::make_pair(info->service_id(), surface)); 8656 std::make_pair(info->service_id(), surface));
8494 8657
8495 CGLContextObj context = 8658 CGLContextObj context =
8496 static_cast<CGLContextObj>(context_->GetHandle()); 8659 static_cast<CGLContextObj>(context_->GetHandle());
8497 8660
8498 CGLError err = surface_support->CGLTexImageIOSurface2D( 8661 CGLError err = surface_support->CGLTexImageIOSurface2D(
8499 context, 8662 context,
8500 target, 8663 target,
8501 GL_RGBA, 8664 GL_RGBA,
8502 width, 8665 width,
8503 height, 8666 height,
8504 GL_BGRA, 8667 GL_BGRA,
8505 GL_UNSIGNED_INT_8_8_8_8_REV, 8668 GL_UNSIGNED_INT_8_8_8_8_REV,
8506 surface, 8669 surface,
8507 plane); 8670 plane);
8508 8671
8509 if (err != kCGLNoError) { 8672 if (err != kCGLNoError) {
8510 SetGLError( 8673 SetGLError(
8511 GL_INVALID_OPERATION, 8674 GL_INVALID_OPERATION,
8512 "glTexImageIOSurface2DCHROMIUM: error in CGLTexImageIOSurface2D"); 8675 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D");
8513 return; 8676 return;
8514 } 8677 }
8515 8678
8516 texture_manager()->SetLevelInfo( 8679 texture_manager()->SetLevelInfo(
8517 info, target, 0, GL_RGBA, width, height, 1, 0, 8680 info, target, 0, GL_RGBA, width, height, 1, 0,
8518 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); 8681 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true);
8519 8682
8520 #else 8683 #else
8521 SetGLError(GL_INVALID_OPERATION, 8684 SetGLError(GL_INVALID_OPERATION,
8522 "glTexImageIOSurface2DCHROMIUM: not supported."); 8685 "glTexImageIOSurface2DCHROMIUM", "not supported.");
8523 #endif 8686 #endif
8524 } 8687 }
8525 8688
8526 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { 8689 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) {
8527 switch (internalformat) { 8690 switch (internalformat) {
8528 case GL_RGB565: 8691 case GL_RGB565:
8529 return GL_RGB; 8692 return GL_RGB;
8530 case GL_RGBA4: 8693 case GL_RGBA4:
8531 return GL_RGBA; 8694 return GL_RGBA;
8532 case GL_RGB5_A1: 8695 case GL_RGB5_A1:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8568 } 8731 }
8569 } 8732 }
8570 8733
8571 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( 8734 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
8572 GLenum target, GLuint source_id, GLuint dest_id, GLint level, 8735 GLenum target, GLuint source_id, GLuint dest_id, GLint level,
8573 GLenum internal_format) { 8736 GLenum internal_format) {
8574 TextureManager::TextureInfo* dest_info = GetTextureInfo(dest_id); 8737 TextureManager::TextureInfo* dest_info = GetTextureInfo(dest_id);
8575 TextureManager::TextureInfo* source_info = GetTextureInfo(source_id); 8738 TextureManager::TextureInfo* source_info = GetTextureInfo(source_id);
8576 8739
8577 if (!source_info || !dest_info) { 8740 if (!source_info || !dest_info) {
8578 SetGLError(GL_INVALID_VALUE, "glCopyTextureCHROMIUM: unknown texture id"); 8741 SetGLError(GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id");
8579 return; 8742 return;
8580 } 8743 }
8581 8744
8582 if (GL_TEXTURE_2D != target) { 8745 if (GL_TEXTURE_2D != target) {
8583 SetGLError(GL_INVALID_VALUE, 8746 SetGLError(GL_INVALID_VALUE,
8584 "glCopyTextureCHROMIUM: invalid texture target"); 8747 "glCopyTextureCHROMIUM", "invalid texture target");
8585 return; 8748 return;
8586 } 8749 }
8587 8750
8588 if (dest_info->target() != GL_TEXTURE_2D || 8751 if (dest_info->target() != GL_TEXTURE_2D ||
8589 source_info->target() != GL_TEXTURE_2D) { 8752 source_info->target() != GL_TEXTURE_2D) {
8590 SetGLError(GL_INVALID_VALUE, 8753 SetGLError(GL_INVALID_VALUE,
8591 "glCopyTextureCHROMIUM: invalid texture target binding"); 8754 "glCopyTextureCHROMIUM", "invalid texture target binding");
8592 return; 8755 return;
8593 } 8756 }
8594 8757
8595 int source_width, source_height, dest_width, dest_height; 8758 int source_width, source_height, dest_width, dest_height;
8596 if (!source_info->GetLevelSize(GL_TEXTURE_2D, 0, &source_width, 8759 if (!source_info->GetLevelSize(GL_TEXTURE_2D, 0, &source_width,
8597 &source_height)) { 8760 &source_height)) {
8598 SetGLError(GL_INVALID_VALUE, 8761 SetGLError(GL_INVALID_VALUE,
8599 "glCopyTextureChromium: source texture has no level 0"); 8762 "glCopyTextureChromium", "source texture has no level 0");
8600 return; 8763 return;
8601 } 8764 }
8602 8765
8603 // Check that this type of texture is allowed. 8766 // Check that this type of texture is allowed.
8604 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, 8767 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width,
8605 source_height, 1)) { 8768 source_height, 1)) {
8606 SetGLError(GL_INVALID_VALUE, 8769 SetGLError(GL_INVALID_VALUE,
8607 "glCopyTextureCHROMIUM: Bad dimensions"); 8770 "glCopyTextureCHROMIUM", "Bad dimensions");
8608 return; 8771 return;
8609 } 8772 }
8610 8773
8611 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is 8774 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
8612 // needed because it takes 10s of milliseconds to initialize. 8775 // needed because it takes 10s of milliseconds to initialize.
8613 if (!copy_texture_CHROMIUM_.get()) { 8776 if (!copy_texture_CHROMIUM_.get()) {
8614 CopyRealGLErrorsToWrapper(); 8777 CopyRealGLErrorsToWrapper();
8615 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); 8778 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager());
8616 copy_texture_CHROMIUM_->Initialize(); 8779 copy_texture_CHROMIUM_->Initialize();
8617 RestoreCurrentFramebufferBindings(); 8780 RestoreCurrentFramebufferBindings();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
8728 8891
8729 void GLES2DecoderImpl::DoTexStorage2DEXT( 8892 void GLES2DecoderImpl::DoTexStorage2DEXT(
8730 GLenum target, 8893 GLenum target,
8731 GLint levels, 8894 GLint levels,
8732 GLenum internal_format, 8895 GLenum internal_format,
8733 GLsizei width, 8896 GLsizei width,
8734 GLsizei height) { 8897 GLsizei height) {
8735 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); 8898 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT");
8736 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || 8899 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) ||
8737 TextureManager::ComputeMipMapCount(width, height, 1) < levels) { 8900 TextureManager::ComputeMipMapCount(width, height, 1) < levels) {
8738 SetGLError(GL_INVALID_VALUE, "glTexStorage2DEXT: dimensions out of range"); 8901 SetGLError(
8902 GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range");
8739 return; 8903 return;
8740 } 8904 }
8741 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 8905 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8742 if (!info) { 8906 if (!info) {
8743 SetGLError(GL_INVALID_OPERATION, 8907 SetGLError(GL_INVALID_OPERATION,
8744 "glTexStorage2DEXT: unknown texture for target"); 8908 "glTexStorage2DEXT", "unknown texture for target");
8745 return; 8909 return;
8746 } 8910 }
8747 if (info->IsAttachedToFramebuffer()) { 8911 if (info->IsAttachedToFramebuffer()) {
8748 state_dirty_ = true; 8912 state_dirty_ = true;
8749 } 8913 }
8750 if (info->IsImmutable()) { 8914 if (info->IsImmutable()) {
8751 SetGLError(GL_INVALID_OPERATION, 8915 SetGLError(GL_INVALID_OPERATION,
8752 "glTexStorage2DEXT: texture is immutable"); 8916 "glTexStorage2DEXT", "texture is immutable");
8753 return; 8917 return;
8754 } 8918 }
8755 CopyRealGLErrorsToWrapper(); 8919 CopyRealGLErrorsToWrapper();
8756 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), 8920 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format),
8757 width, height); 8921 width, height);
8758 GLenum error = PeekGLError(); 8922 GLenum error = PeekGLError();
8759 if (error == GL_NO_ERROR) { 8923 if (error == GL_NO_ERROR) {
8760 GLenum format = ExtractFormatFromStorageFormat(internal_format); 8924 GLenum format = ExtractFormatFromStorageFormat(internal_format);
8761 GLenum type = ExtractTypeFromStorageFormat(internal_format); 8925 GLenum type = ExtractTypeFromStorageFormat(internal_format);
8762 GLsizei level_width = width; 8926 GLsizei level_width = width;
(...skipping 20 matching lines...) Expand all
8783 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM); 8947 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM);
8784 8948
8785 return error::kNoError; 8949 return error::kNoError;
8786 } 8950 }
8787 8951
8788 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, 8952 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target,
8789 const GLbyte* mailbox) { 8953 const GLbyte* mailbox) {
8790 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 8954 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8791 if (!info) { 8955 if (!info) {
8792 SetGLError(GL_INVALID_OPERATION, 8956 SetGLError(GL_INVALID_OPERATION,
8793 "glProduceTextureCHROMIUM: unknown texture for target"); 8957 "glProduceTextureCHROMIUM", "unknown texture for target");
8794 return; 8958 return;
8795 } 8959 }
8796 8960
8797 TextureDefinition* definition = texture_manager()->Save(info); 8961 TextureDefinition* definition = texture_manager()->Save(info);
8798 if (!definition) { 8962 if (!definition) {
8799 SetGLError(GL_INVALID_OPERATION, 8963 SetGLError(GL_INVALID_OPERATION,
8800 "glProduceTextureCHROMIUM: invalid texture"); 8964 "glProduceTextureCHROMIUM", "invalid texture");
8801 return; 8965 return;
8802 } 8966 }
8803 8967
8804 if (!group_->mailbox_manager()->ProduceTexture( 8968 if (!group_->mailbox_manager()->ProduceTexture(
8805 target, 8969 target,
8806 *reinterpret_cast<const MailboxName*>(mailbox), 8970 *reinterpret_cast<const MailboxName*>(mailbox),
8807 definition, 8971 definition,
8808 texture_manager())) { 8972 texture_manager())) {
8809 bool success = texture_manager()->Restore(info, definition); 8973 bool success = texture_manager()->Restore(info, definition);
8810 DCHECK(success); 8974 DCHECK(success);
8811 SetGLError(GL_INVALID_OPERATION, 8975 SetGLError(GL_INVALID_OPERATION,
8812 "glProduceTextureCHROMIUM: invalid mailbox name"); 8976 "glProduceTextureCHROMIUM", "invalid mailbox name");
8813 return; 8977 return;
8814 } 8978 }
8815 8979
8816 BindAndApplyTextureParameters(info); 8980 BindAndApplyTextureParameters(info);
8817 } 8981 }
8818 8982
8819 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, 8983 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target,
8820 const GLbyte* mailbox) { 8984 const GLbyte* mailbox) {
8821 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); 8985 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
8822 if (!info) { 8986 if (!info) {
8823 SetGLError(GL_INVALID_OPERATION, 8987 SetGLError(GL_INVALID_OPERATION,
8824 "glConsumeTextureCHROMIUM: unknown texture for target"); 8988 "glConsumeTextureCHROMIUM", "unknown texture for target");
8825 return; 8989 return;
8826 } 8990 }
8827 8991
8828 scoped_ptr<TextureDefinition> definition( 8992 scoped_ptr<TextureDefinition> definition(
8829 group_->mailbox_manager()->ConsumeTexture( 8993 group_->mailbox_manager()->ConsumeTexture(
8830 target, 8994 target,
8831 *reinterpret_cast<const MailboxName*>(mailbox))); 8995 *reinterpret_cast<const MailboxName*>(mailbox)));
8832 if (!definition.get()) { 8996 if (!definition.get()) {
8833 SetGLError(GL_INVALID_OPERATION, 8997 SetGLError(GL_INVALID_OPERATION,
8834 "glConsumeTextureCHROMIUM: invalid mailbox name"); 8998 "glConsumeTextureCHROMIUM", "invalid mailbox name");
8835 return; 8999 return;
8836 } 9000 }
8837 9001
8838 if (!texture_manager()->Restore(info, definition.release())) { 9002 if (!texture_manager()->Restore(info, definition.release())) {
8839 SetGLError(GL_INVALID_OPERATION, 9003 SetGLError(GL_INVALID_OPERATION,
8840 "glConsumeTextureCHROMIUM: invalid texture"); 9004 "glConsumeTextureCHROMIUM", "invalid texture");
8841 return; 9005 return;
8842 } 9006 }
8843 9007
8844 BindAndApplyTextureParameters(info); 9008 BindAndApplyTextureParameters(info);
8845 } 9009 }
8846 9010
8847 // Include the auto-generated part of this file. We split this because it means 9011 // Include the auto-generated part of this file. We split this because it means
8848 // we can easily edit the non-auto generated parts right here in this file 9012 // we can easily edit the non-auto generated parts right here in this file
8849 // instead of having to edit some template or the code generator. 9013 // instead of having to edit some template or the code generator.
8850 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 9014 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
8851 9015
8852 } // namespace gles2 9016 } // namespace gles2
8853 } // namespace gpu 9017 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/common_decoder.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_autogen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698