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 <limits.h> | 7 #include <limits.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 11257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11268 GLenum target = static_cast<GLenum>(c.target); | 11268 GLenum target = static_cast<GLenum>(c.target); |
11269 GLint level = static_cast<GLint>(c.level); | 11269 GLint level = static_cast<GLint>(c.level); |
11270 GLint internal_format = static_cast<GLint>(c.internalformat); | 11270 GLint internal_format = static_cast<GLint>(c.internalformat); |
11271 GLsizei width = static_cast<GLsizei>(c.width); | 11271 GLsizei width = static_cast<GLsizei>(c.width); |
11272 GLsizei height = static_cast<GLsizei>(c.height); | 11272 GLsizei height = static_cast<GLsizei>(c.height); |
11273 GLint border = static_cast<GLint>(c.border); | 11273 GLint border = static_cast<GLint>(c.border); |
11274 GLenum format = static_cast<GLenum>(c.format); | 11274 GLenum format = static_cast<GLenum>(c.format); |
11275 GLenum type = static_cast<GLenum>(c.type); | 11275 GLenum type = static_cast<GLenum>(c.type); |
11276 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); | 11276 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); |
11277 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); | 11277 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); |
| 11278 |
| 11279 if (width < 0 || height < 0) { |
| 11280 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexImage2D", "dimensions < 0"); |
| 11281 return error::kNoError; |
| 11282 } |
| 11283 |
| 11284 PixelStoreParams params; |
| 11285 if (state_.bound_pixel_unpack_buffer.get()) { |
| 11286 if (pixels_shm_id) |
| 11287 return error::kInvalidArguments; |
| 11288 params = state_.GetUnpackParams(ContextState::k2D); |
| 11289 } else { |
| 11290 if (!pixels_shm_id && pixels_shm_offset) |
| 11291 return error::kInvalidArguments; |
| 11292 // When reading from client buffer, the command buffer client side took |
| 11293 // the responsibility to take the pixels from the client buffer and |
| 11294 // unpack them according to the full ES3 pack parameters as source, all |
| 11295 // parameters for 0 (except for alignment) as destination mem for the |
| 11296 // service side. |
| 11297 params.alignment = state_.unpack_alignment; |
| 11298 } |
11278 uint32_t pixels_size; | 11299 uint32_t pixels_size; |
11279 if (!GLES2Util::ComputeImageDataSizes( | 11300 uint32_t skip_size; |
11280 width, height, 1, format, type, state_.unpack_alignment, &pixels_size, | 11301 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1, |
11281 NULL, NULL)) { | 11302 format, type, |
| 11303 params, |
| 11304 &pixels_size, |
| 11305 nullptr, |
| 11306 nullptr, |
| 11307 &skip_size, |
| 11308 nullptr)) { |
11282 return error::kOutOfBounds; | 11309 return error::kOutOfBounds; |
11283 } | 11310 } |
11284 const void* pixels = NULL; | 11311 DCHECK_EQ(0u, skip_size); |
11285 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { | 11312 |
| 11313 const void* pixels; |
| 11314 if (pixels_shm_id) { |
11286 pixels = GetSharedMemoryAs<const void*>( | 11315 pixels = GetSharedMemoryAs<const void*>( |
11287 pixels_shm_id, pixels_shm_offset, pixels_size); | 11316 pixels_shm_id, pixels_shm_offset, pixels_size); |
11288 if (!pixels) { | 11317 if (!pixels) |
11289 return error::kOutOfBounds; | 11318 return error::kOutOfBounds; |
11290 } | 11319 } else { |
| 11320 pixels = reinterpret_cast<const void*>(pixels_shm_offset); |
11291 } | 11321 } |
11292 | 11322 |
11293 // For testing only. Allows us to stress the ability to respond to OOM errors. | 11323 // For testing only. Allows us to stress the ability to respond to OOM errors. |
11294 if (workarounds().simulate_out_of_memory_on_large_textures && | 11324 if (workarounds().simulate_out_of_memory_on_large_textures && |
11295 (width * height >= 4096 * 4096)) { | 11325 (width * height >= 4096 * 4096)) { |
11296 LOCAL_SET_GL_ERROR( | 11326 LOCAL_SET_GL_ERROR( |
11297 GL_OUT_OF_MEMORY, | 11327 GL_OUT_OF_MEMORY, |
11298 "glTexImage2D", "synthetic out of memory"); | 11328 "glTexImage2D", "synthetic out of memory"); |
11299 return error::kNoError; | 11329 return error::kNoError; |
11300 } | 11330 } |
(...skipping 25 matching lines...) Expand all Loading... |
11326 GLint level = static_cast<GLint>(c.level); | 11356 GLint level = static_cast<GLint>(c.level); |
11327 GLint internal_format = static_cast<GLint>(c.internalformat); | 11357 GLint internal_format = static_cast<GLint>(c.internalformat); |
11328 GLsizei width = static_cast<GLsizei>(c.width); | 11358 GLsizei width = static_cast<GLsizei>(c.width); |
11329 GLsizei height = static_cast<GLsizei>(c.height); | 11359 GLsizei height = static_cast<GLsizei>(c.height); |
11330 GLsizei depth = static_cast<GLsizei>(c.depth); | 11360 GLsizei depth = static_cast<GLsizei>(c.depth); |
11331 GLint border = static_cast<GLint>(c.border); | 11361 GLint border = static_cast<GLint>(c.border); |
11332 GLenum format = static_cast<GLenum>(c.format); | 11362 GLenum format = static_cast<GLenum>(c.format); |
11333 GLenum type = static_cast<GLenum>(c.type); | 11363 GLenum type = static_cast<GLenum>(c.type); |
11334 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); | 11364 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); |
11335 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); | 11365 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); |
| 11366 |
| 11367 if (width < 0 || height < 0 || depth < 0) { |
| 11368 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexImage3D", "dimensions < 0"); |
| 11369 return error::kNoError; |
| 11370 } |
| 11371 |
| 11372 PixelStoreParams params; |
| 11373 if (state_.bound_pixel_unpack_buffer.get()) { |
| 11374 if (pixels_shm_id) |
| 11375 return error::kInvalidArguments; |
| 11376 params = state_.GetUnpackParams(ContextState::k3D); |
| 11377 } else { |
| 11378 if (!pixels_shm_id && pixels_shm_offset) |
| 11379 return error::kInvalidArguments; |
| 11380 // When reading from client buffer, the command buffer client side took |
| 11381 // the responsibility to take the pixels from the client buffer and |
| 11382 // unpack them according to the full ES3 pack parameters as source, all |
| 11383 // parameters for 0 (except for alignment) as destination mem for the |
| 11384 // service side. |
| 11385 params.alignment = state_.unpack_alignment; |
| 11386 } |
11336 uint32_t pixels_size; | 11387 uint32_t pixels_size; |
11337 if (!GLES2Util::ComputeImageDataSizes( | 11388 uint32_t skip_size; |
11338 width, height, depth, format, type, state_.unpack_alignment, &pixels_size, | 11389 if (!GLES2Util::ComputeImageDataSizesES3(width, height, depth, |
11339 NULL, NULL)) { | 11390 format, type, |
| 11391 params, |
| 11392 &pixels_size, |
| 11393 nullptr, |
| 11394 nullptr, |
| 11395 &skip_size, |
| 11396 nullptr)) { |
11340 return error::kOutOfBounds; | 11397 return error::kOutOfBounds; |
11341 } | 11398 } |
11342 const void* pixels = NULL; | 11399 DCHECK_EQ(0u, skip_size); |
11343 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { | 11400 |
| 11401 const void* pixels; |
| 11402 if (pixels_shm_id) { |
11344 pixels = GetSharedMemoryAs<const void*>( | 11403 pixels = GetSharedMemoryAs<const void*>( |
11345 pixels_shm_id, pixels_shm_offset, pixels_size); | 11404 pixels_shm_id, pixels_shm_offset, pixels_size); |
11346 if (!pixels) { | 11405 if (!pixels) |
11347 return error::kOutOfBounds; | 11406 return error::kOutOfBounds; |
11348 } | 11407 } else { |
| 11408 pixels = reinterpret_cast<const void*>(pixels_shm_offset); |
11349 } | 11409 } |
11350 | 11410 |
11351 // For testing only. Allows us to stress the ability to respond to OOM errors. | 11411 // For testing only. Allows us to stress the ability to respond to OOM errors. |
11352 if (workarounds().simulate_out_of_memory_on_large_textures && | 11412 if (workarounds().simulate_out_of_memory_on_large_textures && |
11353 (width * height * depth >= 4096 * 4096)) { | 11413 (width * height * depth >= 4096 * 4096)) { |
11354 LOCAL_SET_GL_ERROR( | 11414 LOCAL_SET_GL_ERROR( |
11355 GL_OUT_OF_MEMORY, | 11415 GL_OUT_OF_MEMORY, |
11356 "glTexImage3D", "synthetic out of memory"); | 11416 "glTexImage3D", "synthetic out of memory"); |
11357 return error::kNoError; | 11417 return error::kNoError; |
11358 } | 11418 } |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11720 return error::kNoError; | 11780 return error::kNoError; |
11721 | 11781 |
11722 GLenum target = static_cast<GLenum>(c.target); | 11782 GLenum target = static_cast<GLenum>(c.target); |
11723 GLint level = static_cast<GLint>(c.level); | 11783 GLint level = static_cast<GLint>(c.level); |
11724 GLint xoffset = static_cast<GLint>(c.xoffset); | 11784 GLint xoffset = static_cast<GLint>(c.xoffset); |
11725 GLint yoffset = static_cast<GLint>(c.yoffset); | 11785 GLint yoffset = static_cast<GLint>(c.yoffset); |
11726 GLsizei width = static_cast<GLsizei>(c.width); | 11786 GLsizei width = static_cast<GLsizei>(c.width); |
11727 GLsizei height = static_cast<GLsizei>(c.height); | 11787 GLsizei height = static_cast<GLsizei>(c.height); |
11728 GLenum format = static_cast<GLenum>(c.format); | 11788 GLenum format = static_cast<GLenum>(c.format); |
11729 GLenum type = static_cast<GLenum>(c.type); | 11789 GLenum type = static_cast<GLenum>(c.type); |
11730 uint32_t data_size; | 11790 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); |
11731 if (!GLES2Util::ComputeImageDataSizes( | 11791 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); |
11732 width, height, 1, format, type, state_.unpack_alignment, &data_size, | 11792 |
11733 NULL, NULL)) { | 11793 if (width < 0 || height < 0) { |
| 11794 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexSubImage2D", "dimensions < 0"); |
| 11795 return error::kNoError; |
| 11796 } |
| 11797 |
| 11798 PixelStoreParams params; |
| 11799 if (state_.bound_pixel_unpack_buffer.get()) { |
| 11800 if (pixels_shm_id) |
| 11801 return error::kInvalidArguments; |
| 11802 params = state_.GetUnpackParams(ContextState::k2D); |
| 11803 } else { |
| 11804 // When reading from client buffer, the command buffer client side took |
| 11805 // the responsibility to take the pixels from the client buffer and |
| 11806 // unpack them according to the full ES3 pack parameters as source, all |
| 11807 // parameters for 0 (except for alignment) as destination mem for the |
| 11808 // service side. |
| 11809 params.alignment = state_.unpack_alignment; |
| 11810 } |
| 11811 uint32_t pixels_size; |
| 11812 uint32_t skip_size; |
| 11813 if (!GLES2Util::ComputeImageDataSizesES3(width, height, 1, |
| 11814 format, type, |
| 11815 params, |
| 11816 &pixels_size, |
| 11817 nullptr, |
| 11818 nullptr, |
| 11819 &skip_size, |
| 11820 nullptr)) { |
11734 return error::kOutOfBounds; | 11821 return error::kOutOfBounds; |
11735 } | 11822 } |
| 11823 DCHECK_EQ(0u, skip_size); |
11736 | 11824 |
11737 const void* pixels = GetSharedMemoryAs<const void*>( | 11825 const void* pixels; |
11738 c.pixels_shm_id, c.pixels_shm_offset, data_size); | 11826 if (pixels_shm_id) { |
11739 if (!pixels) | 11827 pixels = GetSharedMemoryAs<const void*>( |
11740 return error::kOutOfBounds; | 11828 pixels_shm_id, pixels_shm_offset, pixels_size); |
| 11829 if (!pixels) |
| 11830 return error::kOutOfBounds; |
| 11831 } else { |
| 11832 pixels = reinterpret_cast<const void*>(pixels_shm_offset); |
| 11833 } |
11741 | 11834 |
11742 TextureManager::DoTexSubImageArguments args = { | 11835 TextureManager::DoTexSubImageArguments args = { |
11743 target, level, xoffset, yoffset, 0, width, height, 1, | 11836 target, level, xoffset, yoffset, 0, width, height, 1, |
11744 format, type, pixels, data_size, | 11837 format, type, pixels, pixels_size, |
11745 TextureManager::DoTexSubImageArguments::kTexSubImage2D}; | 11838 TextureManager::DoTexSubImageArguments::kTexSubImage2D}; |
11746 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, | 11839 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, |
11747 &framebuffer_state_, | 11840 &framebuffer_state_, |
11748 "glTexSubImage2D", args); | 11841 "glTexSubImage2D", args); |
11749 | 11842 |
11750 // This may be a slow command. Exit command processing to allow for | 11843 // This may be a slow command. Exit command processing to allow for |
11751 // context preemption and GPU watchdog checks. | 11844 // context preemption and GPU watchdog checks. |
11752 ExitCommandProcessingEarly(); | 11845 ExitCommandProcessingEarly(); |
11753 return error::kNoError; | 11846 return error::kNoError; |
11754 } | 11847 } |
(...skipping 14 matching lines...) Expand all Loading... |
11769 GLenum target = static_cast<GLenum>(c.target); | 11862 GLenum target = static_cast<GLenum>(c.target); |
11770 GLint level = static_cast<GLint>(c.level); | 11863 GLint level = static_cast<GLint>(c.level); |
11771 GLint xoffset = static_cast<GLint>(c.xoffset); | 11864 GLint xoffset = static_cast<GLint>(c.xoffset); |
11772 GLint yoffset = static_cast<GLint>(c.yoffset); | 11865 GLint yoffset = static_cast<GLint>(c.yoffset); |
11773 GLint zoffset = static_cast<GLint>(c.zoffset); | 11866 GLint zoffset = static_cast<GLint>(c.zoffset); |
11774 GLsizei width = static_cast<GLsizei>(c.width); | 11867 GLsizei width = static_cast<GLsizei>(c.width); |
11775 GLsizei height = static_cast<GLsizei>(c.height); | 11868 GLsizei height = static_cast<GLsizei>(c.height); |
11776 GLsizei depth = static_cast<GLsizei>(c.depth); | 11869 GLsizei depth = static_cast<GLsizei>(c.depth); |
11777 GLenum format = static_cast<GLenum>(c.format); | 11870 GLenum format = static_cast<GLenum>(c.format); |
11778 GLenum type = static_cast<GLenum>(c.type); | 11871 GLenum type = static_cast<GLenum>(c.type); |
11779 uint32_t data_size; | 11872 uint32_t pixels_shm_id = static_cast<uint32_t>(c.pixels_shm_id); |
11780 if (!GLES2Util::ComputeImageDataSizes( | 11873 uint32_t pixels_shm_offset = static_cast<uint32_t>(c.pixels_shm_offset); |
11781 width, height, depth, format, type, state_.unpack_alignment, &data_size, | 11874 |
11782 NULL, NULL)) { | 11875 if (width < 0 || height < 0 || depth < 0) { |
| 11876 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexSubImage3D", "dimensions < 0"); |
| 11877 return error::kNoError; |
| 11878 } |
| 11879 |
| 11880 PixelStoreParams params; |
| 11881 if (state_.bound_pixel_unpack_buffer.get()) { |
| 11882 if (pixels_shm_id) |
| 11883 return error::kInvalidArguments; |
| 11884 params = state_.GetUnpackParams(ContextState::k3D); |
| 11885 } else { |
| 11886 // When reading from client buffer, the command buffer client side took |
| 11887 // the responsibility to take the pixels from the client buffer and |
| 11888 // unpack them according to the full ES3 pack parameters as source, all |
| 11889 // parameters for 0 (except for alignment) as destination mem for the |
| 11890 // service side. |
| 11891 params.alignment = state_.unpack_alignment; |
| 11892 } |
| 11893 uint32_t pixels_size; |
| 11894 uint32_t skip_size; |
| 11895 if (!GLES2Util::ComputeImageDataSizesES3(width, height, depth, |
| 11896 format, type, |
| 11897 params, |
| 11898 &pixels_size, |
| 11899 nullptr, |
| 11900 nullptr, |
| 11901 &skip_size, |
| 11902 nullptr)) { |
11783 return error::kOutOfBounds; | 11903 return error::kOutOfBounds; |
11784 } | 11904 } |
| 11905 DCHECK_EQ(0u, skip_size); |
11785 | 11906 |
11786 const void* pixels = GetSharedMemoryAs<const void*>( | 11907 const void* pixels; |
11787 c.pixels_shm_id, c.pixels_shm_offset, data_size); | 11908 if (pixels_shm_id) { |
11788 if (!pixels) | 11909 pixels = GetSharedMemoryAs<const void*>( |
11789 return error::kOutOfBounds; | 11910 pixels_shm_id, pixels_shm_offset, pixels_size); |
| 11911 if (!pixels) |
| 11912 return error::kOutOfBounds; |
| 11913 } else { |
| 11914 pixels = reinterpret_cast<const void*>(pixels_shm_offset); |
| 11915 } |
11790 | 11916 |
11791 TextureManager::DoTexSubImageArguments args = { | 11917 TextureManager::DoTexSubImageArguments args = { |
11792 target, level, xoffset, yoffset, zoffset, width, height, depth, | 11918 target, level, xoffset, yoffset, zoffset, width, height, depth, |
11793 format, type, pixels, data_size, | 11919 format, type, pixels, pixels_size, |
11794 TextureManager::DoTexSubImageArguments::kTexSubImage3D}; | 11920 TextureManager::DoTexSubImageArguments::kTexSubImage3D}; |
11795 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, | 11921 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, |
11796 &framebuffer_state_, | 11922 &framebuffer_state_, |
11797 "glTexSubImage3D", args); | 11923 "glTexSubImage3D", args); |
11798 | 11924 |
11799 // This may be a slow command. Exit command processing to allow for | 11925 // This may be a slow command. Exit command processing to allow for |
11800 // context preemption and GPU watchdog checks. | 11926 // context preemption and GPU watchdog checks. |
11801 ExitCommandProcessingEarly(); | 11927 ExitCommandProcessingEarly(); |
11802 return error::kNoError; | 11928 return error::kNoError; |
11803 } | 11929 } |
(...skipping 4198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16002 } | 16128 } |
16003 | 16129 |
16004 // Include the auto-generated part of this file. We split this because it means | 16130 // Include the auto-generated part of this file. We split this because it means |
16005 // we can easily edit the non-auto generated parts right here in this file | 16131 // we can easily edit the non-auto generated parts right here in this file |
16006 // instead of having to edit some template or the code generator. | 16132 // instead of having to edit some template or the code generator. |
16007 #include "base/macros.h" | 16133 #include "base/macros.h" |
16008 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 16134 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
16009 | 16135 |
16010 } // namespace gles2 | 16136 } // namespace gles2 |
16011 } // namespace gpu | 16137 } // namespace gpu |
OLD | NEW |