OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <list> | 10 #include <list> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 namespace { | 77 namespace { |
78 | 78 |
79 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; | 79 static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
80 | 80 |
81 khronos_uint64_t CityHashForAngle(const char* name, unsigned int len) { | 81 khronos_uint64_t CityHashForAngle(const char* name, unsigned int len) { |
82 return static_cast<khronos_uint64_t>( | 82 return static_cast<khronos_uint64_t>( |
83 CityHash64(name, static_cast<size_t>(len))); | 83 CityHash64(name, static_cast<size_t>(len))); |
84 } | 84 } |
85 | 85 |
86 } | 86 } // namespace |
87 | 87 |
88 class GLES2DecoderImpl; | 88 class GLES2DecoderImpl; |
89 | 89 |
90 // Check that certain assumptions the code makes are true. There are places in | 90 // Check that certain assumptions the code makes are true. There are places in |
91 // the code where shared memory is passed direclty to GL. Example, glUniformiv, | 91 // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
92 // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe | 92 // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
93 // a few others) are 32bits. If they are not 32bits the code will have to change | 93 // a few others) are 32bits. If they are not 32bits the code will have to change |
94 // to call those GL functions with service side memory and then copy the results | 94 // to call those GL functions with service side memory and then copy the results |
95 // to shared memory, converting the sizes. | 95 // to shared memory, converting the sizes. |
96 COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT | 96 COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT |
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1120 |
1121 // Wrapper for glCheckFramebufferStatus | 1121 // Wrapper for glCheckFramebufferStatus |
1122 GLenum DoCheckFramebufferStatus(GLenum target); | 1122 GLenum DoCheckFramebufferStatus(GLenum target); |
1123 | 1123 |
1124 // Wrapper for glClear | 1124 // Wrapper for glClear |
1125 error::Error DoClear(GLbitfield mask); | 1125 error::Error DoClear(GLbitfield mask); |
1126 | 1126 |
1127 // Wrappers for various state. | 1127 // Wrappers for various state. |
1128 void DoDepthRangef(GLclampf znear, GLclampf zfar); | 1128 void DoDepthRangef(GLclampf znear, GLclampf zfar); |
1129 void DoHint(GLenum target, GLenum mode); | 1129 void DoHint(GLenum target, GLenum mode); |
1130 void DoSampleCoverage (GLclampf value, GLboolean invert); | 1130 void DoSampleCoverage(GLclampf value, GLboolean invert); |
1131 | 1131 |
1132 // Wrapper for glCompileShader. | 1132 // Wrapper for glCompileShader. |
1133 void DoCompileShader(GLuint shader); | 1133 void DoCompileShader(GLuint shader); |
1134 | 1134 |
1135 // Helper for DeleteSharedIdsCHROMIUM commands. | 1135 // Helper for DeleteSharedIdsCHROMIUM commands. |
1136 void DoDeleteSharedIdsCHROMIUM( | 1136 void DoDeleteSharedIdsCHROMIUM( |
1137 GLuint namespace_id, GLsizei n, const GLuint* ids); | 1137 GLuint namespace_id, GLsizei n, const GLuint* ids); |
1138 | 1138 |
1139 // Wrapper for glDetachShader | 1139 // Wrapper for glDetachShader |
1140 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); | 1140 void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
(...skipping 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3990 *params = 0; | 3990 *params = 0; |
3991 } | 3991 } |
3992 } | 3992 } |
3993 return true; | 3993 return true; |
3994 case GL_ELEMENT_ARRAY_BUFFER_BINDING: | 3994 case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
3995 *num_written = 1; | 3995 *num_written = 1; |
3996 if (params) { | 3996 if (params) { |
3997 if (state_.vertex_attrib_manager->element_array_buffer()) { | 3997 if (state_.vertex_attrib_manager->element_array_buffer()) { |
3998 GLuint client_id = 0; | 3998 GLuint client_id = 0; |
3999 buffer_manager()->GetClientId( | 3999 buffer_manager()->GetClientId( |
4000 state_.vertex_attrib_manager->element_array_buffer( | 4000 state_.vertex_attrib_manager->element_array_buffer()-> |
4001 )->service_id(), &client_id); | 4001 service_id(), &client_id); |
4002 *params = client_id; | 4002 *params = client_id; |
4003 } else { | 4003 } else { |
4004 *params = 0; | 4004 *params = 0; |
4005 } | 4005 } |
4006 } | 4006 } |
4007 return true; | 4007 return true; |
4008 case GL_FRAMEBUFFER_BINDING: | 4008 case GL_FRAMEBUFFER_BINDING: |
4009 // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) | 4009 // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
4010 *num_written = 1; | 4010 *num_written = 1; |
4011 if (params) { | 4011 if (params) { |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4570 break; | 4570 break; |
4571 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: | 4571 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
4572 state_.hint_fragment_shader_derivative = mode; | 4572 state_.hint_fragment_shader_derivative = mode; |
4573 break; | 4573 break; |
4574 default: | 4574 default: |
4575 NOTREACHED(); | 4575 NOTREACHED(); |
4576 } | 4576 } |
4577 glHint(target, mode); | 4577 glHint(target, mode); |
4578 } | 4578 } |
4579 | 4579 |
4580 void GLES2DecoderImpl::DoSampleCoverage (GLclampf value, GLboolean invert) { | 4580 void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
4581 state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); | 4581 state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
4582 state_.sample_coverage_invert = (invert != 0); | 4582 state_.sample_coverage_invert = (invert != 0); |
4583 glSampleCoverage(state_.sample_coverage_value, invert); | 4583 glSampleCoverage(state_.sample_coverage_value, invert); |
4584 } | 4584 } |
4585 | 4585 |
4586 // Assumes framebuffer is complete. | 4586 // Assumes framebuffer is complete. |
4587 void GLES2DecoderImpl::ClearUnclearedAttachments( | 4587 void GLES2DecoderImpl::ClearUnclearedAttachments( |
4588 GLenum target, FramebufferManager::FramebufferInfo* info) { | 4588 GLenum target, FramebufferManager::FramebufferInfo* info) { |
4589 if (target == GL_READ_FRAMEBUFFER_EXT) { | 4589 if (target == GL_READ_FRAMEBUFFER_EXT) { |
4590 // bind this to the DRAW point, clear then bind back to READ | 4590 // bind this to the DRAW point, clear then bind back to READ |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4934 | 4934 |
4935 void GLES2DecoderImpl::DoTexParameteri( | 4935 void GLES2DecoderImpl::DoTexParameteri( |
4936 GLenum target, GLenum pname, GLint param) { | 4936 GLenum target, GLenum pname, GLint param) { |
4937 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); | 4937 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
4938 if (!info) { | 4938 if (!info) { |
4939 SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); | 4939 SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
4940 return; | 4940 return; |
4941 } | 4941 } |
4942 | 4942 |
4943 GLenum error = texture_manager()->SetParameter(info, pname, param); | 4943 GLenum error = texture_manager()->SetParameter(info, pname, param); |
4944 if(error != GL_NO_ERROR) { | 4944 if (error != GL_NO_ERROR) { |
4945 SetGLErrorInvalidParam(error, "glTexParameteri", pname, param); | 4945 SetGLErrorInvalidParam(error, "glTexParameteri", pname, param); |
4946 return; | 4946 return; |
4947 } | 4947 } |
4948 // Texture tracking pools exist only for the command decoder, so | 4948 // Texture tracking pools exist only for the command decoder, so |
4949 // do not pass them on to the native GL implementation. | 4949 // do not pass them on to the native GL implementation. |
4950 if (pname == GL_TEXTURE_POOL_CHROMIUM) { | 4950 if (pname == GL_TEXTURE_POOL_CHROMIUM) { |
4951 return; | 4951 return; |
4952 } | 4952 } |
4953 glTexParameteri(target, pname, param); | 4953 glTexParameteri(target, pname, param); |
4954 } | 4954 } |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6041 | 6041 |
6042 if (!CheckBoundFramebuffersValid(function_name)) { | 6042 if (!CheckBoundFramebuffersValid(function_name)) { |
6043 return error::kNoError; | 6043 return error::kNoError; |
6044 } | 6044 } |
6045 | 6045 |
6046 if (count == 0 || (instanced && primcount == 0)) { | 6046 if (count == 0 || (instanced && primcount == 0)) { |
6047 return error::kNoError; | 6047 return error::kNoError; |
6048 } | 6048 } |
6049 | 6049 |
6050 GLuint max_vertex_accessed; | 6050 GLuint max_vertex_accessed; |
6051 if (!state_.vertex_attrib_manager->element_array_buffer( | 6051 if (!state_.vertex_attrib_manager->element_array_buffer()-> |
6052 )->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { | 6052 GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { |
6053 SetGLError(GL_INVALID_OPERATION, | 6053 SetGLError(GL_INVALID_OPERATION, |
6054 function_name, "range out of bounds for buffer"); | 6054 function_name, "range out of bounds for buffer"); |
6055 return error::kNoError; | 6055 return error::kNoError; |
6056 } | 6056 } |
6057 | 6057 |
6058 if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { | 6058 if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
6059 if (!ClearUnclearedTextures()) { | 6059 if (!ClearUnclearedTextures()) { |
6060 SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); | 6060 SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); |
6061 return error::kNoError; | 6061 return error::kNoError; |
6062 } | 6062 } |
(...skipping 3905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9968 | 9968 |
9969 // Guarantee async textures are always 'cleared' as follows: | 9969 // Guarantee async textures are always 'cleared' as follows: |
9970 // - AsyncTexImage2D can not redefine an existing texture | 9970 // - AsyncTexImage2D can not redefine an existing texture |
9971 // - AsyncTexImage2D must initialize the entire image via non-null buffer. | 9971 // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
9972 // - AsyncTexSubImage2D clears synchronously if not already cleared. | 9972 // - AsyncTexSubImage2D clears synchronously if not already cleared. |
9973 // - Textures become immutable after an async call. | 9973 // - Textures become immutable after an async call. |
9974 // This way we know in all cases that an async texture is always clear. | 9974 // This way we know in all cases that an async texture is always clear. |
9975 if (!info->SafeToRenderFrom()) { | 9975 if (!info->SafeToRenderFrom()) { |
9976 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { | 9976 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
9977 SetGLError(GL_OUT_OF_MEMORY, | 9977 SetGLError(GL_OUT_OF_MEMORY, |
9978 "glAsyncTexSubImage2DCHROMIUM","dimensions too big"); | 9978 "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
9979 return error::kNoError; | 9979 return error::kNoError; |
9980 } | 9980 } |
9981 } | 9981 } |
9982 | 9982 |
9983 // We know the memory/size is safe, so get the real shared memory since | 9983 // We know the memory/size is safe, so get the real shared memory since |
9984 // it might need to be duped to prevent use-after-free of the memory. | 9984 // it might need to be duped to prevent use-after-free of the memory. |
9985 Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); | 9985 Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); |
9986 base::SharedMemory* shared_memory = buffer.shared_memory; | 9986 base::SharedMemory* shared_memory = buffer.shared_memory; |
9987 uint32 shm_size = buffer.size; | 9987 uint32 shm_size = buffer.size; |
9988 uint32 shm_data_offset = c.data_shm_offset; | 9988 uint32 shm_data_offset = c.data_shm_offset; |
(...skipping 17 matching lines...) Expand all Loading... |
10006 return error::kNoError; | 10006 return error::kNoError; |
10007 } | 10007 } |
10008 | 10008 |
10009 // Include the auto-generated part of this file. We split this because it means | 10009 // Include the auto-generated part of this file. We split this because it means |
10010 // we can easily edit the non-auto generated parts right here in this file | 10010 // we can easily edit the non-auto generated parts right here in this file |
10011 // instead of having to edit some template or the code generator. | 10011 // instead of having to edit some template or the code generator. |
10012 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 10012 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
10013 | 10013 |
10014 } // namespace gles2 | 10014 } // namespace gles2 |
10015 } // namespace gpu | 10015 } // namespace gpu |
OLD | NEW |