| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 10 #include <vector> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const CommandInfo g_command_info[] = { | 96 const CommandInfo g_command_info[] = { |
| 97 #define GLES2_CMD_OP(name) { \ | 97 #define GLES2_CMD_OP(name) { \ |
| 98 name::kArgFlags, \ | 98 name::kArgFlags, \ |
| 99 sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ | 99 sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ |
| 100 | 100 |
| 101 GLES2_COMMAND_LIST(GLES2_CMD_OP) | 101 GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 102 | 102 |
| 103 #undef GLES2_CMD_OP | 103 #undef GLES2_CMD_OP |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 namespace GLErrorBit { |
| 107 enum GLErrorBit { |
| 108 kNoError = 0, |
| 109 kInvalidEnum = (1 << 0), |
| 110 kInvalidValue = (1 << 1), |
| 111 kInvalidOperation = (1 << 2), |
| 112 kOutOfMemory = (1 << 3), |
| 113 kInvalidFrameBufferOperation = (1 << 4), |
| 114 }; |
| 115 } |
| 116 |
| 117 uint32 GLErrorToErrorBit(GLenum error) { |
| 118 switch (error) { |
| 119 case GL_INVALID_ENUM: |
| 120 return GLErrorBit::kInvalidEnum; |
| 121 case GL_INVALID_VALUE: |
| 122 return GLErrorBit::kInvalidValue; |
| 123 case GL_INVALID_OPERATION: |
| 124 return GLErrorBit::kInvalidOperation; |
| 125 case GL_OUT_OF_MEMORY: |
| 126 return GLErrorBit::kOutOfMemory; |
| 127 case GL_INVALID_FRAMEBUFFER_OPERATION: |
| 128 return GLErrorBit::kInvalidFrameBufferOperation; |
| 129 default: |
| 130 DCHECK(false); |
| 131 return GLErrorBit::kNoError; |
| 132 } |
| 133 } |
| 134 |
| 135 GLenum GLErrorBitToGLError(uint32 error_bit) { |
| 136 switch (error_bit) { |
| 137 case GLErrorBit::kInvalidEnum: |
| 138 return GL_INVALID_ENUM; |
| 139 case GLErrorBit::kInvalidValue: |
| 140 return GL_INVALID_VALUE; |
| 141 case GLErrorBit::kInvalidOperation: |
| 142 return GL_INVALID_OPERATION; |
| 143 case GLErrorBit::kOutOfMemory: |
| 144 return GL_OUT_OF_MEMORY; |
| 145 case GLErrorBit::kInvalidFrameBufferOperation: |
| 146 return GL_INVALID_FRAMEBUFFER_OPERATION; |
| 147 default: |
| 148 DCHECK(false); |
| 149 return GL_NO_ERROR; |
| 150 } |
| 151 } |
| 152 |
| 106 // } // anonymous namespace. | 153 // } // anonymous namespace. |
| 107 | 154 |
| 108 GLES2Decoder::GLES2Decoder(ContextGroup* group) | 155 GLES2Decoder::GLES2Decoder(ContextGroup* group) |
| 109 : group_(group), | 156 : group_(group), |
| 110 #if defined(UNIT_TEST) | 157 #if defined(UNIT_TEST) |
| 111 debug_(false) { | 158 debug_(false) { |
| 112 #elif defined(OS_LINUX) | 159 #elif defined(OS_LINUX) |
| 113 debug_(false), | 160 debug_(false), |
| 114 window_(NULL) { | 161 window_(NULL) { |
| 115 #elif defined(OS_WIN) | 162 #elif defined(OS_WIN) |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 481 |
| 435 // Wrapper for glDisableVertexAttribArray. | 482 // Wrapper for glDisableVertexAttribArray. |
| 436 void DoDisableVertexAttribArray(GLuint index); | 483 void DoDisableVertexAttribArray(GLuint index); |
| 437 | 484 |
| 438 // Wrapper for glEnableVertexAttribArray. | 485 // Wrapper for glEnableVertexAttribArray. |
| 439 void DoEnableVertexAttribArray(GLuint index); | 486 void DoEnableVertexAttribArray(GLuint index); |
| 440 | 487 |
| 441 // Wrapper for glGenerateMipmap | 488 // Wrapper for glGenerateMipmap |
| 442 void DoGenerateMipmap(GLenum target); | 489 void DoGenerateMipmap(GLenum target); |
| 443 | 490 |
| 444 // Wrapper for glGetShaderiv | |
| 445 void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); | |
| 446 | |
| 447 // Wrapper for glGetShaderSource. | 491 // Wrapper for glGetShaderSource. |
| 448 void DoGetShaderSource( | 492 void DoGetShaderSource( |
| 449 GLuint shader, GLsizei bufsize, GLsizei* length, char* dst); | 493 GLuint shader, GLsizei bufsize, GLsizei* length, char* dst); |
| 450 | 494 |
| 451 // Wrapper for glLinkProgram | 495 // Wrapper for glLinkProgram |
| 452 void DoLinkProgram(GLuint program); | 496 void DoLinkProgram(GLuint program); |
| 453 | 497 |
| 454 // Swaps the buffers (copies/renders to the current window). | 498 // Swaps the buffers (copies/renders to the current window). |
| 455 void DoSwapBuffers(); | 499 void DoSwapBuffers(); |
| 456 | 500 |
| (...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 current_program_ = info; | 1795 current_program_ = info; |
| 1752 glUseProgram(program); | 1796 glUseProgram(program); |
| 1753 } | 1797 } |
| 1754 | 1798 |
| 1755 GLenum GLES2DecoderImpl::GetGLError() { | 1799 GLenum GLES2DecoderImpl::GetGLError() { |
| 1756 // Check the GL error first, then our wrapped error. | 1800 // Check the GL error first, then our wrapped error. |
| 1757 GLenum error = glGetError(); | 1801 GLenum error = glGetError(); |
| 1758 if (error == GL_NO_ERROR && error_bits_ != 0) { | 1802 if (error == GL_NO_ERROR && error_bits_ != 0) { |
| 1759 for (uint32 mask = 1; mask != 0; mask = mask << 1) { | 1803 for (uint32 mask = 1; mask != 0; mask = mask << 1) { |
| 1760 if ((error_bits_ & mask) != 0) { | 1804 if ((error_bits_ & mask) != 0) { |
| 1761 error = GLES2Util::GLErrorBitToGLError(mask); | 1805 error = GLErrorBitToGLError(mask); |
| 1762 break; | 1806 break; |
| 1763 } | 1807 } |
| 1764 } | 1808 } |
| 1765 } | 1809 } |
| 1766 | 1810 |
| 1767 if (error != GL_NO_ERROR) { | 1811 if (error != GL_NO_ERROR) { |
| 1768 // There was an error, clear the corresponding wrapped error. | 1812 // There was an error, clear the corresponding wrapped error. |
| 1769 error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); | 1813 error_bits_ &= ~GLErrorToErrorBit(error); |
| 1770 } | 1814 } |
| 1771 return error; | 1815 return error; |
| 1772 } | 1816 } |
| 1773 | 1817 |
| 1774 void GLES2DecoderImpl::SetGLError(GLenum error) { | 1818 void GLES2DecoderImpl::SetGLError(GLenum error) { |
| 1775 error_bits_ |= GLES2Util::GLErrorToErrorBit(error); | 1819 error_bits_ |= GLErrorToErrorBit(error); |
| 1776 } | 1820 } |
| 1777 | 1821 |
| 1778 void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() { | 1822 void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() { |
| 1779 GLenum error; | 1823 GLenum error; |
| 1780 while ((error = glGetError()) != GL_NO_ERROR) { | 1824 while ((error = glGetError()) != GL_NO_ERROR) { |
| 1781 SetGLError(error); | 1825 SetGLError(error); |
| 1782 } | 1826 } |
| 1783 } | 1827 } |
| 1784 | 1828 |
| 1785 bool GLES2DecoderImpl::VertexAttribInfo::CanAccess(GLuint index) { | 1829 bool GLES2DecoderImpl::VertexAttribInfo::CanAccess(GLuint index) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 return; | 2041 return; |
| 1998 } | 2042 } |
| 1999 // TODO(gman): Run shader through compiler that converts GL ES 2.0 shader | 2043 // TODO(gman): Run shader through compiler that converts GL ES 2.0 shader |
| 2000 // to DesktopGL shader and pass that to glShaderSource and then | 2044 // to DesktopGL shader and pass that to glShaderSource and then |
| 2001 // glCompileShader. | 2045 // glCompileShader. |
| 2002 const char* ptr = info->source().c_str(); | 2046 const char* ptr = info->source().c_str(); |
| 2003 glShaderSource(shader, 1, &ptr, NULL); | 2047 glShaderSource(shader, 1, &ptr, NULL); |
| 2004 glCompileShader(shader); | 2048 glCompileShader(shader); |
| 2005 }; | 2049 }; |
| 2006 | 2050 |
| 2007 void GLES2DecoderImpl::DoGetShaderiv( | |
| 2008 GLuint shader, GLenum pname, GLint* params) { | |
| 2009 ShaderManager::ShaderInfo* info = GetShaderInfo(shader); | |
| 2010 if (!info) { | |
| 2011 SetGLError(GL_INVALID_OPERATION); | |
| 2012 return; | |
| 2013 } | |
| 2014 if (pname == GL_SHADER_SOURCE_LENGTH) { | |
| 2015 *params = info->source().size(); | |
| 2016 } else { | |
| 2017 glGetShaderiv(shader, pname, params); | |
| 2018 } | |
| 2019 } | |
| 2020 | |
| 2021 void GLES2DecoderImpl::DoGetShaderSource( | 2051 void GLES2DecoderImpl::DoGetShaderSource( |
| 2022 GLuint shader, GLsizei bufsize, GLsizei* length, char* dst) { | 2052 GLuint shader, GLsizei bufsize, GLsizei* length, char* dst) { |
| 2023 ShaderManager::ShaderInfo* info = GetShaderInfo(shader); | 2053 ShaderManager::ShaderInfo* info = GetShaderInfo(shader); |
| 2024 if (!info) { | 2054 if (!info) { |
| 2025 SetGLError(GL_INVALID_OPERATION); | 2055 SetGLError(GL_INVALID_OPERATION); |
| 2026 return; | 2056 return; |
| 2027 } | 2057 } |
| 2028 const std::string& source = info->source(); | 2058 const std::string& source = info->source(); |
| 2029 GLsizei size = std::min(bufsize - 1, static_cast<GLsizei>(source.size())); | 2059 GLsizei size = std::min(bufsize - 1, static_cast<GLsizei>(source.size())); |
| 2030 if (length) { | 2060 if (length) { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 GLint* location = GetSharedMemoryAs<GLint*>( | 2270 GLint* location = GetSharedMemoryAs<GLint*>( |
| 2241 c.location_shm_id, c.location_shm_offset, sizeof(GLint)); | 2271 c.location_shm_id, c.location_shm_offset, sizeof(GLint)); |
| 2242 if (!location || !name) { | 2272 if (!location || !name) { |
| 2243 return error::kOutOfBounds; | 2273 return error::kOutOfBounds; |
| 2244 } | 2274 } |
| 2245 String name_str(name, name_size); | 2275 String name_str(name, name_size); |
| 2246 *location = info->GetUniformLocation(name_str); | 2276 *location = info->GetUniformLocation(name_str); |
| 2247 return error::kNoError; | 2277 return error::kNoError; |
| 2248 } | 2278 } |
| 2249 | 2279 |
| 2250 error::Error GLES2DecoderImpl::HandleGetString( | |
| 2251 uint32 immediate_data_size, const gles2::GetString& c) { | |
| 2252 GLenum name = static_cast<GLenum>(c.name); | |
| 2253 if (!ValidateGLenumStringType(name)) { | |
| 2254 SetGLError(GL_INVALID_ENUM); | |
| 2255 return error::kNoError; | |
| 2256 } | |
| 2257 Bucket* bucket = CreateBucket(c.bucket_id); | |
| 2258 bucket->SetFromString(reinterpret_cast<const char*>(glGetString(name))); | |
| 2259 return error::kNoError; | |
| 2260 } | |
| 2261 | |
| 2262 error::Error GLES2DecoderImpl::HandleBufferData( | 2280 error::Error GLES2DecoderImpl::HandleBufferData( |
| 2263 uint32 immediate_data_size, const gles2::BufferData& c) { | 2281 uint32 immediate_data_size, const gles2::BufferData& c) { |
| 2264 GLenum target = static_cast<GLenum>(c.target); | 2282 GLenum target = static_cast<GLenum>(c.target); |
| 2265 GLsizeiptr size = static_cast<GLsizeiptr>(c.size); | 2283 GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 2266 uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); | 2284 uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 2267 uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); | 2285 uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 2268 GLenum usage = static_cast<GLenum>(c.usage); | 2286 GLenum usage = static_cast<GLenum>(c.usage); |
| 2269 const void* data = NULL; | 2287 const void* data = NULL; |
| 2270 if (data_shm_id != 0 || data_shm_offset != 0) { | 2288 if (data_shm_id != 0 || data_shm_offset != 0) { |
| 2271 data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); | 2289 data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2412 GLsizei image_size = static_cast<GLsizei>(c.imageSize); | 2430 GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 2413 const void* data = GetImmediateDataAs<const void*>( | 2431 const void* data = GetImmediateDataAs<const void*>( |
| 2414 c, image_size, immediate_data_size); | 2432 c, image_size, immediate_data_size); |
| 2415 if (!data) { | 2433 if (!data) { |
| 2416 return error::kOutOfBounds; | 2434 return error::kOutOfBounds; |
| 2417 } | 2435 } |
| 2418 return DoCompressedTexImage2D( | 2436 return DoCompressedTexImage2D( |
| 2419 target, level, internal_format, width, height, border, image_size, data); | 2437 target, level, internal_format, width, height, border, image_size, data); |
| 2420 } | 2438 } |
| 2421 | 2439 |
| 2440 // TODO(gman): handle CopyTexImage2D because we need to track what was created. |
| 2441 |
| 2422 error::Error GLES2DecoderImpl::DoTexImage2D( | 2442 error::Error GLES2DecoderImpl::DoTexImage2D( |
| 2423 GLenum target, | 2443 GLenum target, |
| 2424 GLint level, | 2444 GLint level, |
| 2425 GLenum internal_format, | 2445 GLenum internal_format, |
| 2426 GLsizei width, | 2446 GLsizei width, |
| 2427 GLsizei height, | 2447 GLsizei height, |
| 2428 GLint border, | 2448 GLint border, |
| 2429 GLenum format, | 2449 GLenum format, |
| 2430 GLenum type, | 2450 GLenum type, |
| 2431 const void* pixels, | 2451 const void* pixels, |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2774 return error::kNoError; | 2794 return error::kNoError; |
| 2775 } | 2795 } |
| 2776 | 2796 |
| 2777 // Include the auto-generated part of this file. We split this because it means | 2797 // Include the auto-generated part of this file. We split this because it means |
| 2778 // we can easily edit the non-auto generated parts right here in this file | 2798 // we can easily edit the non-auto generated parts right here in this file |
| 2779 // instead of having to edit some template or the code generator. | 2799 // instead of having to edit some template or the code generator. |
| 2780 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 2800 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 2781 | 2801 |
| 2782 } // namespace gles2 | 2802 } // namespace gles2 |
| 2783 } // namespace gpu | 2803 } // namespace gpu |
| OLD | NEW |