OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 }; | 124 }; |
125 | 125 |
126 static bool IsAngle() { | 126 static bool IsAngle() { |
127 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
128 return gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; | 128 return gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
129 #else | 129 #else |
130 return false; | 130 return false; |
131 #endif | 131 #endif |
132 } | 132 } |
133 | 133 |
| 134 // Return true if a character belongs to the ASCII subset as defined in |
| 135 // GLSL ES 1.0 spec section 3.1. |
| 136 static bool CharacterIsValidForGLES(unsigned char c) { |
| 137 // Printing characters are valid except " $ ` @ \ ' DEL. |
| 138 if (c >= 32 && c <= 126 && |
| 139 c != '"' && |
| 140 c != '$' && |
| 141 c != '`' && |
| 142 c != '@' && |
| 143 c != '\\' && |
| 144 c != '\'') { |
| 145 return true; |
| 146 } |
| 147 // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 148 // are also valid. |
| 149 if (c >= 9 && c <= 13) { |
| 150 return true; |
| 151 } |
| 152 |
| 153 return false; |
| 154 } |
| 155 |
| 156 static bool StringIsValidForGLES(const char* str) { |
| 157 for (; *str; ++str) { |
| 158 if (!CharacterIsValidForGLES(*str)) { |
| 159 return false; |
| 160 } |
| 161 } |
| 162 return true; |
| 163 } |
| 164 |
134 static void WrappedTexImage2D( | 165 static void WrappedTexImage2D( |
135 GLenum target, | 166 GLenum target, |
136 GLint level, | 167 GLint level, |
137 GLenum internal_format, | 168 GLenum internal_format, |
138 GLsizei width, | 169 GLsizei width, |
139 GLsizei height, | 170 GLsizei height, |
140 GLint border, | 171 GLint border, |
141 GLenum format, | 172 GLenum format, |
142 GLenum type, | 173 GLenum type, |
143 const void* pixels) { | 174 const void* pixels) { |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 RenderbufferManager::RenderbufferInfo* info = | 823 RenderbufferManager::RenderbufferInfo* info = |
793 renderbuffer_manager()->GetRenderbufferInfo(client_id); | 824 renderbuffer_manager()->GetRenderbufferInfo(client_id); |
794 return (info && !info->IsDeleted()) ? info : NULL; | 825 return (info && !info->IsDeleted()) ? info : NULL; |
795 } | 826 } |
796 | 827 |
797 // Removes the renderbuffer info for the given renderbuffer. | 828 // Removes the renderbuffer info for the given renderbuffer. |
798 void RemoveRenderbufferInfo(GLuint client_id) { | 829 void RemoveRenderbufferInfo(GLuint client_id) { |
799 renderbuffer_manager()->RemoveRenderbufferInfo(client_id); | 830 renderbuffer_manager()->RemoveRenderbufferInfo(client_id); |
800 } | 831 } |
801 | 832 |
| 833 void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
| 834 |
802 error::Error GetAttribLocationHelper( | 835 error::Error GetAttribLocationHelper( |
803 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, | 836 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
804 const std::string& name_str); | 837 const std::string& name_str); |
805 | 838 |
806 error::Error GetUniformLocationHelper( | 839 error::Error GetUniformLocationHelper( |
807 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, | 840 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
808 const std::string& name_str); | 841 const std::string& name_str); |
809 | 842 |
810 // Helper for glShaderSource. | 843 // Helper for glShaderSource. |
811 error::Error ShaderSourceHelper( | 844 error::Error ShaderSourceHelper( |
(...skipping 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3310 void GLES2DecoderImpl::DoGetProgramiv( | 3343 void GLES2DecoderImpl::DoGetProgramiv( |
3311 GLuint program_id, GLenum pname, GLint* params) { | 3344 GLuint program_id, GLenum pname, GLint* params) { |
3312 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | 3345 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
3313 program_id, "glGetProgramiv"); | 3346 program_id, "glGetProgramiv"); |
3314 if (!info) { | 3347 if (!info) { |
3315 return; | 3348 return; |
3316 } | 3349 } |
3317 info->GetProgramiv(pname, params); | 3350 info->GetProgramiv(pname, params); |
3318 } | 3351 } |
3319 | 3352 |
| 3353 void GLES2DecoderImpl::DoBindAttribLocation( |
| 3354 GLuint program, GLuint index, const char* name) { |
| 3355 if (!StringIsValidForGLES(name)) { |
| 3356 SetGLError(GL_INVALID_VALUE, "glBindAttribLocation: Invalid character"); |
| 3357 return; |
| 3358 } |
| 3359 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 3360 program, "glBindAttribLocation"); |
| 3361 if (!info) { |
| 3362 return; |
| 3363 } |
| 3364 glBindAttribLocation(info->service_id(), index, name); |
| 3365 } |
| 3366 |
3320 error::Error GLES2DecoderImpl::HandleBindAttribLocation( | 3367 error::Error GLES2DecoderImpl::HandleBindAttribLocation( |
3321 uint32 immediate_data_size, const gles2::BindAttribLocation& c) { | 3368 uint32 immediate_data_size, const gles2::BindAttribLocation& c) { |
3322 GLuint program = static_cast<GLuint>(c.program); | 3369 GLuint program = static_cast<GLuint>(c.program); |
3323 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | |
3324 program, "glBindAttribLocation"); | |
3325 if (!info) { | |
3326 return error::kNoError; | |
3327 } | |
3328 GLuint index = static_cast<GLuint>(c.index); | 3370 GLuint index = static_cast<GLuint>(c.index); |
3329 uint32 name_size = c.data_size; | 3371 uint32 name_size = c.data_size; |
3330 const char* name = GetSharedMemoryAs<const char*>( | 3372 const char* name = GetSharedMemoryAs<const char*>( |
3331 c.name_shm_id, c.name_shm_offset, name_size); | 3373 c.name_shm_id, c.name_shm_offset, name_size); |
3332 if (name == NULL) { | 3374 if (name == NULL) { |
3333 return error::kOutOfBounds; | 3375 return error::kOutOfBounds; |
3334 } | 3376 } |
3335 String name_str(name, name_size); | 3377 String name_str(name, name_size); |
3336 glBindAttribLocation(info->service_id(), index, name_str.c_str()); | 3378 DoBindAttribLocation(program, index, name_str.c_str()); |
3337 return error::kNoError; | 3379 return error::kNoError; |
3338 } | 3380 } |
3339 | 3381 |
3340 error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( | 3382 error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( |
3341 uint32 immediate_data_size, const gles2::BindAttribLocationImmediate& c) { | 3383 uint32 immediate_data_size, const gles2::BindAttribLocationImmediate& c) { |
3342 GLuint program = static_cast<GLuint>(c.program); | 3384 GLuint program = static_cast<GLuint>(c.program); |
3343 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | |
3344 program, "glBindAttribLocation"); | |
3345 if (!info) { | |
3346 return error::kNoError; | |
3347 } | |
3348 GLuint index = static_cast<GLuint>(c.index); | 3385 GLuint index = static_cast<GLuint>(c.index); |
3349 uint32 name_size = c.data_size; | 3386 uint32 name_size = c.data_size; |
3350 const char* name = GetImmediateDataAs<const char*>( | 3387 const char* name = GetImmediateDataAs<const char*>( |
3351 c, name_size, immediate_data_size); | 3388 c, name_size, immediate_data_size); |
3352 if (name == NULL) { | 3389 if (name == NULL) { |
3353 return error::kOutOfBounds; | 3390 return error::kOutOfBounds; |
3354 } | 3391 } |
3355 String name_str(name, name_size); | 3392 String name_str(name, name_size); |
3356 glBindAttribLocation(info->service_id(), index, name_str.c_str()); | 3393 DoBindAttribLocation(program, index, name_str.c_str()); |
3357 return error::kNoError; | 3394 return error::kNoError; |
3358 } | 3395 } |
3359 | 3396 |
3360 error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( | 3397 error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
3361 uint32 immediate_data_size, const gles2::BindAttribLocationBucket& c) { | 3398 uint32 immediate_data_size, const gles2::BindAttribLocationBucket& c) { |
3362 GLuint program = static_cast<GLuint>(c.program); | 3399 GLuint program = static_cast<GLuint>(c.program); |
3363 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | |
3364 program, "glBindAttribLocation"); | |
3365 if (!info) { | |
3366 return error::kNoError; | |
3367 } | |
3368 GLuint index = static_cast<GLuint>(c.index); | 3400 GLuint index = static_cast<GLuint>(c.index); |
3369 Bucket* bucket = GetBucket(c.name_bucket_id); | 3401 Bucket* bucket = GetBucket(c.name_bucket_id); |
3370 if (!bucket || bucket->size() == 0) { | 3402 if (!bucket || bucket->size() == 0) { |
3371 return error::kInvalidArguments; | 3403 return error::kInvalidArguments; |
3372 } | 3404 } |
3373 std::string name_str; | 3405 std::string name_str; |
3374 if (!bucket->GetAsString(&name_str)) { | 3406 if (!bucket->GetAsString(&name_str)) { |
3375 return error::kInvalidArguments; | 3407 return error::kInvalidArguments; |
3376 } | 3408 } |
3377 glBindAttribLocation(info->service_id(), index, name_str.c_str()); | 3409 DoBindAttribLocation(program, index, name_str.c_str()); |
3378 return error::kNoError; | 3410 return error::kNoError; |
3379 } | 3411 } |
3380 | 3412 |
3381 error::Error GLES2DecoderImpl::HandleDeleteShader( | 3413 error::Error GLES2DecoderImpl::HandleDeleteShader( |
3382 uint32 immediate_data_size, const gles2::DeleteShader& c) { | 3414 uint32 immediate_data_size, const gles2::DeleteShader& c) { |
3383 GLuint client_id = c.shader; | 3415 GLuint client_id = c.shader; |
3384 if (client_id) { | 3416 if (client_id) { |
3385 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); | 3417 ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); |
3386 if (info) { | 3418 if (info) { |
3387 if (!info->IsDeleted()) { | 3419 if (!info->IsDeleted()) { |
(...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4673 } | 4705 } |
4674 return max_vertex_accessed; | 4706 return max_vertex_accessed; |
4675 } | 4707 } |
4676 | 4708 |
4677 // Calls glShaderSource for the various versions of the ShaderSource command. | 4709 // Calls glShaderSource for the various versions of the ShaderSource command. |
4678 // Assumes that data / data_size points to a piece of memory that is in range | 4710 // Assumes that data / data_size points to a piece of memory that is in range |
4679 // of whatever context it came from (shared memory, immediate memory, bucket | 4711 // of whatever context it came from (shared memory, immediate memory, bucket |
4680 // memory.) | 4712 // memory.) |
4681 error::Error GLES2DecoderImpl::ShaderSourceHelper( | 4713 error::Error GLES2DecoderImpl::ShaderSourceHelper( |
4682 GLuint client_id, const char* data, uint32 data_size) { | 4714 GLuint client_id, const char* data, uint32 data_size) { |
| 4715 std::string str(data, data + data_size); |
| 4716 if (!StringIsValidForGLES(str.c_str())) { |
| 4717 SetGLError(GL_INVALID_VALUE, "glShaderSource: Invalid character"); |
| 4718 return error::kNoError; |
| 4719 } |
4683 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( | 4720 ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
4684 client_id, "glShaderSource"); | 4721 client_id, "glShaderSource"); |
4685 if (!info) { | 4722 if (!info) { |
4686 return error::kNoError; | 4723 return error::kNoError; |
4687 } | 4724 } |
4688 // Note: We don't actually call glShaderSource here. We wait until | 4725 // Note: We don't actually call glShaderSource here. We wait until |
4689 // the call to glCompileShader. | 4726 // the call to glCompileShader. |
4690 info->UpdateSource(std::string(data, data + data_size).c_str()); | 4727 info->UpdateSource(str.c_str()); |
4691 return error::kNoError; | 4728 return error::kNoError; |
4692 } | 4729 } |
4693 | 4730 |
4694 error::Error GLES2DecoderImpl::HandleShaderSource( | 4731 error::Error GLES2DecoderImpl::HandleShaderSource( |
4695 uint32 immediate_data_size, const gles2::ShaderSource& c) { | 4732 uint32 immediate_data_size, const gles2::ShaderSource& c) { |
4696 uint32 data_size = c.data_size; | 4733 uint32 data_size = c.data_size; |
4697 const char* data = GetSharedMemoryAs<const char*>( | 4734 const char* data = GetSharedMemoryAs<const char*>( |
4698 c.data_shm_id, c.data_shm_offset, data_size); | 4735 c.data_shm_id, c.data_shm_offset, data_size); |
4699 if (!data) { | 4736 if (!data) { |
4700 return error::kOutOfBounds; | 4737 return error::kOutOfBounds; |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5433 // Validation should have prevented us from getting here. | 5470 // Validation should have prevented us from getting here. |
5434 NOTREACHED(); | 5471 NOTREACHED(); |
5435 break; | 5472 break; |
5436 } | 5473 } |
5437 return error::kNoError; | 5474 return error::kNoError; |
5438 } | 5475 } |
5439 | 5476 |
5440 error::Error GLES2DecoderImpl::GetAttribLocationHelper( | 5477 error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
5441 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, | 5478 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
5442 const std::string& name_str) { | 5479 const std::string& name_str) { |
| 5480 if (!StringIsValidForGLES(name_str.c_str())) { |
| 5481 SetGLError(GL_INVALID_VALUE, "glGetAttribLocation: Invalid character"); |
| 5482 return error::kNoError; |
| 5483 } |
5443 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | 5484 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
5444 client_id, "glGetAttribLocation"); | 5485 client_id, "glGetAttribLocation"); |
5445 if (!info) { | 5486 if (!info) { |
5446 return error::kNoError; | 5487 return error::kNoError; |
5447 } | 5488 } |
5448 if (!info->IsValid()) { | 5489 if (!info->IsValid()) { |
5449 SetGLError(GL_INVALID_OPERATION, "glGetAttribLocation: program not linked"); | 5490 SetGLError(GL_INVALID_OPERATION, "glGetAttribLocation: program not linked"); |
5450 return error::kNoError; | 5491 return error::kNoError; |
5451 } | 5492 } |
5452 GLint* location = GetSharedMemoryAs<GLint*>( | 5493 GLint* location = GetSharedMemoryAs<GLint*>( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 if (!bucket->GetAsString(&name_str)) { | 5540 if (!bucket->GetAsString(&name_str)) { |
5500 return error::kInvalidArguments; | 5541 return error::kInvalidArguments; |
5501 } | 5542 } |
5502 return GetAttribLocationHelper( | 5543 return GetAttribLocationHelper( |
5503 c.program, c.location_shm_id, c.location_shm_offset, name_str); | 5544 c.program, c.location_shm_id, c.location_shm_offset, name_str); |
5504 } | 5545 } |
5505 | 5546 |
5506 error::Error GLES2DecoderImpl::GetUniformLocationHelper( | 5547 error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
5507 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, | 5548 GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
5508 const std::string& name_str) { | 5549 const std::string& name_str) { |
| 5550 if (!StringIsValidForGLES(name_str.c_str())) { |
| 5551 SetGLError(GL_INVALID_VALUE, "glGetUniformLocation: Invalid character"); |
| 5552 return error::kNoError; |
| 5553 } |
5509 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( | 5554 ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
5510 client_id, "glUniformLocation"); | 5555 client_id, "glUniformLocation"); |
5511 if (!info) { | 5556 if (!info) { |
5512 return error::kNoError; | 5557 return error::kNoError; |
5513 } | 5558 } |
5514 if (!info->IsValid()) { | 5559 if (!info->IsValid()) { |
5515 SetGLError(GL_INVALID_OPERATION, | 5560 SetGLError(GL_INVALID_OPERATION, |
5516 "glGetUniformLocation: program not linked"); | 5561 "glGetUniformLocation: program not linked"); |
5517 return error::kNoError; | 5562 return error::kNoError; |
5518 } | 5563 } |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7125 return error::kNoError; | 7170 return error::kNoError; |
7126 } | 7171 } |
7127 | 7172 |
7128 // Include the auto-generated part of this file. We split this because it means | 7173 // Include the auto-generated part of this file. We split this because it means |
7129 // we can easily edit the non-auto generated parts right here in this file | 7174 // we can easily edit the non-auto generated parts right here in this file |
7130 // instead of having to edit some template or the code generator. | 7175 // instead of having to edit some template or the code generator. |
7131 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 7176 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
7132 | 7177 |
7133 } // namespace gles2 | 7178 } // namespace gles2 |
7134 } // namespace gpu | 7179 } // namespace gpu |
OLD | NEW |