| 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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 void DoCopyTexSubImage2D( | 910 void DoCopyTexSubImage2D( |
| 911 GLenum target, | 911 GLenum target, |
| 912 GLint level, | 912 GLint level, |
| 913 GLint xoffset, | 913 GLint xoffset, |
| 914 GLint yoffset, | 914 GLint yoffset, |
| 915 GLint x, | 915 GLint x, |
| 916 GLint y, | 916 GLint y, |
| 917 GLsizei width, | 917 GLsizei width, |
| 918 GLsizei height); | 918 GLsizei height); |
| 919 | 919 |
| 920 // Wrapper for TexSubImage3D. | |
| 921 error::Error DoTexSubImage3D( | |
| 922 GLenum target, | |
| 923 GLint level, | |
| 924 GLint xoffset, | |
| 925 GLint yoffset, | |
| 926 GLint zoffset, | |
| 927 GLsizei width, | |
| 928 GLsizei height, | |
| 929 GLsizei depth, | |
| 930 GLenum format, | |
| 931 GLenum type, | |
| 932 const void * data); | |
| 933 | |
| 934 // Wrapper for TexImageIOSurface2DCHROMIUM. | 920 // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 935 void DoTexImageIOSurface2DCHROMIUM( | 921 void DoTexImageIOSurface2DCHROMIUM( |
| 936 GLenum target, | 922 GLenum target, |
| 937 GLsizei width, | 923 GLsizei width, |
| 938 GLsizei height, | 924 GLsizei height, |
| 939 GLuint io_surface_id, | 925 GLuint io_surface_id, |
| 940 GLuint plane); | 926 GLuint plane); |
| 941 | 927 |
| 942 void DoCopyTextureCHROMIUM(GLuint source_id, | 928 void DoCopyTextureCHROMIUM(GLuint source_id, |
| 943 GLuint dest_id, | 929 GLuint dest_id, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 962 void DoCompressedCopyTextureCHROMIUM(GLuint source_id, GLuint dest_id); | 948 void DoCompressedCopyTextureCHROMIUM(GLuint source_id, GLuint dest_id); |
| 963 | 949 |
| 964 // Wrapper for TexStorage2DEXT. | 950 // Wrapper for TexStorage2DEXT. |
| 965 void DoTexStorage2DEXT( | 951 void DoTexStorage2DEXT( |
| 966 GLenum target, | 952 GLenum target, |
| 967 GLint levels, | 953 GLint levels, |
| 968 GLenum internal_format, | 954 GLenum internal_format, |
| 969 GLsizei width, | 955 GLsizei width, |
| 970 GLsizei height); | 956 GLsizei height); |
| 971 | 957 |
| 958 // Wrapper for TexStorage3D. |
| 959 void DoTexStorage3D( |
| 960 GLenum target, |
| 961 GLint levels, |
| 962 GLenum internal_format, |
| 963 GLsizei width, |
| 964 GLsizei height, |
| 965 GLsizei depth); |
| 966 |
| 972 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); | 967 void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 973 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, | 968 void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| 974 const GLbyte* key); | 969 const GLbyte* key); |
| 975 void ProduceTextureRef(const char* func_name, | 970 void ProduceTextureRef(const char* func_name, |
| 976 TextureRef* texture_ref, | 971 TextureRef* texture_ref, |
| 977 GLenum target, | 972 GLenum target, |
| 978 const GLbyte* data); | 973 const GLbyte* data); |
| 979 | 974 |
| 980 void EnsureTextureForClientId(GLenum target, GLuint client_id); | 975 void EnsureTextureForClientId(GLenum target, GLuint client_id); |
| 981 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); | 976 void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
| (...skipping 10495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11477 NULL, NULL)) { | 11472 NULL, NULL)) { |
| 11478 return error::kOutOfBounds; | 11473 return error::kOutOfBounds; |
| 11479 } | 11474 } |
| 11480 | 11475 |
| 11481 const void* pixels = GetSharedMemoryAs<const void*>( | 11476 const void* pixels = GetSharedMemoryAs<const void*>( |
| 11482 c.pixels_shm_id, c.pixels_shm_offset, data_size); | 11477 c.pixels_shm_id, c.pixels_shm_offset, data_size); |
| 11483 if (!pixels) | 11478 if (!pixels) |
| 11484 return error::kOutOfBounds; | 11479 return error::kOutOfBounds; |
| 11485 | 11480 |
| 11486 TextureManager::DoTexSubImageArguments args = { | 11481 TextureManager::DoTexSubImageArguments args = { |
| 11487 target, level, xoffset, yoffset, width, | 11482 target, level, xoffset, yoffset, 0, width, height, 1, |
| 11488 height, format, type, pixels, data_size}; | 11483 format, type, pixels, data_size, |
| 11484 TextureManager::DoTexSubImageArguments::kTexSubImage2D}; |
| 11489 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, | 11485 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, |
| 11490 &framebuffer_state_, | 11486 &framebuffer_state_, |
| 11491 "glTexSubImage2D", args); | 11487 "glTexSubImage2D", args); |
| 11492 | 11488 |
| 11493 // This may be a slow command. Exit command processing to allow for | 11489 // This may be a slow command. Exit command processing to allow for |
| 11494 // context preemption and GPU watchdog checks. | 11490 // context preemption and GPU watchdog checks. |
| 11495 ExitCommandProcessingEarly(); | 11491 ExitCommandProcessingEarly(); |
| 11496 return error::kNoError; | 11492 return error::kNoError; |
| 11497 } | 11493 } |
| 11498 | 11494 |
| 11499 error::Error GLES2DecoderImpl::DoTexSubImage3D( | |
| 11500 GLenum target, | |
| 11501 GLint level, | |
| 11502 GLint xoffset, | |
| 11503 GLint yoffset, | |
| 11504 GLint zoffset, | |
| 11505 GLsizei width, | |
| 11506 GLsizei height, | |
| 11507 GLsizei depth, | |
| 11508 GLenum format, | |
| 11509 GLenum type, | |
| 11510 const void * data) { | |
| 11511 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( | |
| 11512 &state_, target); | |
| 11513 if (!texture_ref) { | |
| 11514 LOCAL_SET_GL_ERROR( | |
| 11515 GL_INVALID_ENUM, "glTexSubImage3D", "invalid target"); | |
| 11516 } | |
| 11517 | |
| 11518 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexSubImage3D"); | |
| 11519 ScopedTextureUploadTimer timer(&texture_state_); | |
| 11520 glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, | |
| 11521 depth, format, type, data); | |
| 11522 GLenum error = LOCAL_PEEK_GL_ERROR("glTexSubImage3D"); | |
| 11523 if (error == GL_NO_ERROR) { | |
| 11524 // TODO(zmo): This is not 100% correct because only part of the level | |
| 11525 // image is cleared. | |
| 11526 texture_manager()->SetLevelCleared(texture_ref, target, level, true); | |
| 11527 } | |
| 11528 | |
| 11529 // This may be a slow command. Exit command processing to allow for | |
| 11530 // context preemption and GPU watchdog checks. | |
| 11531 ExitCommandProcessingEarly(); | |
| 11532 return error::kNoError; | |
| 11533 } | |
| 11534 | |
| 11535 error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32_t immediate_data_size, | 11495 error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32_t immediate_data_size, |
| 11536 const void* cmd_data) { | 11496 const void* cmd_data) { |
| 11537 if (!unsafe_es3_apis_enabled()) | 11497 if (!unsafe_es3_apis_enabled()) |
| 11538 return error::kUnknownCommand; | 11498 return error::kUnknownCommand; |
| 11539 | 11499 |
| 11540 const gles2::cmds::TexSubImage3D& c = | 11500 const gles2::cmds::TexSubImage3D& c = |
| 11541 *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data); | 11501 *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data); |
| 11542 TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D", | 11502 TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D", |
| 11543 "widthXheight", c.width * c.height, "depth", c.depth); | 11503 "widthXheight", c.width * c.height, "depth", c.depth); |
| 11544 GLboolean internal = static_cast<GLboolean>(c.internal); | 11504 GLboolean internal = static_cast<GLboolean>(c.internal); |
| 11545 if (internal == GL_TRUE && texture_state_.tex_image_failed) | 11505 if (internal == GL_TRUE && texture_state_.tex_image_failed) |
| 11546 return error::kNoError; | 11506 return error::kNoError; |
| 11547 | 11507 |
| 11548 GLenum target = static_cast<GLenum>(c.target); | 11508 GLenum target = static_cast<GLenum>(c.target); |
| 11549 GLint level = static_cast<GLint>(c.level); | 11509 GLint level = static_cast<GLint>(c.level); |
| 11550 GLint xoffset = static_cast<GLint>(c.xoffset); | 11510 GLint xoffset = static_cast<GLint>(c.xoffset); |
| 11551 GLint yoffset = static_cast<GLint>(c.yoffset); | 11511 GLint yoffset = static_cast<GLint>(c.yoffset); |
| 11552 GLint zoffset = static_cast<GLint>(c.zoffset); | 11512 GLint zoffset = static_cast<GLint>(c.zoffset); |
| 11553 GLsizei width = static_cast<GLsizei>(c.width); | 11513 GLsizei width = static_cast<GLsizei>(c.width); |
| 11554 GLsizei height = static_cast<GLsizei>(c.height); | 11514 GLsizei height = static_cast<GLsizei>(c.height); |
| 11555 GLsizei depth = static_cast<GLsizei>(c.depth); | 11515 GLsizei depth = static_cast<GLsizei>(c.depth); |
| 11556 GLenum format = static_cast<GLenum>(c.format); | 11516 GLenum format = static_cast<GLenum>(c.format); |
| 11557 GLenum type = static_cast<GLenum>(c.type); | 11517 GLenum type = static_cast<GLenum>(c.type); |
| 11558 uint32_t data_size; | 11518 uint32_t data_size; |
| 11559 if (!GLES2Util::ComputeImageDataSizes( | 11519 if (!GLES2Util::ComputeImageDataSizes( |
| 11560 width, height, depth, format, type, state_.unpack_alignment, &data_size, | 11520 width, height, depth, format, type, state_.unpack_alignment, &data_size, |
| 11561 NULL, NULL)) { | 11521 NULL, NULL)) { |
| 11562 return error::kOutOfBounds; | 11522 return error::kOutOfBounds; |
| 11563 } | 11523 } |
| 11524 |
| 11564 const void* pixels = GetSharedMemoryAs<const void*>( | 11525 const void* pixels = GetSharedMemoryAs<const void*>( |
| 11565 c.pixels_shm_id, c.pixels_shm_offset, data_size); | 11526 c.pixels_shm_id, c.pixels_shm_offset, data_size); |
| 11566 return DoTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, | 11527 if (!pixels) |
| 11567 height, depth, format, type, pixels); | 11528 return error::kOutOfBounds; |
| 11529 |
| 11530 TextureManager::DoTexSubImageArguments args = { |
| 11531 target, level, xoffset, yoffset, zoffset, width, height, depth, |
| 11532 format, type, pixels, data_size, |
| 11533 TextureManager::DoTexSubImageArguments::kTexSubImage3D}; |
| 11534 texture_manager()->ValidateAndDoTexSubImage(this, &texture_state_, &state_, |
| 11535 &framebuffer_state_, |
| 11536 "glTexSubImage3D", args); |
| 11537 |
| 11538 // This may be a slow command. Exit command processing to allow for |
| 11539 // context preemption and GPU watchdog checks. |
| 11540 ExitCommandProcessingEarly(); |
| 11541 return error::kNoError; |
| 11568 } | 11542 } |
| 11569 | 11543 |
| 11570 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( | 11544 error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
| 11571 uint32_t immediate_data_size, | 11545 uint32_t immediate_data_size, |
| 11572 const void* cmd_data) { | 11546 const void* cmd_data) { |
| 11573 const gles2::cmds::GetVertexAttribPointerv& c = | 11547 const gles2::cmds::GetVertexAttribPointerv& c = |
| 11574 *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); | 11548 *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); |
| 11575 GLuint index = static_cast<GLuint>(c.index); | 11549 GLuint index = static_cast<GLuint>(c.index); |
| 11576 GLenum pname = static_cast<GLenum>(c.pname); | 11550 GLenum pname = static_cast<GLenum>(c.pname); |
| 11577 typedef cmds::GetVertexAttribPointerv::Result Result; | 11551 typedef cmds::GetVertexAttribPointerv::Result Result; |
| (...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13813 level_width, level_height, 1, 0, | 13787 level_width, level_height, 1, 0, |
| 13814 format, type, gfx::Rect()); | 13788 format, type, gfx::Rect()); |
| 13815 } | 13789 } |
| 13816 level_width = std::max(1, level_width >> 1); | 13790 level_width = std::max(1, level_width >> 1); |
| 13817 level_height = std::max(1, level_height >> 1); | 13791 level_height = std::max(1, level_height >> 1); |
| 13818 } | 13792 } |
| 13819 texture->SetImmutable(true); | 13793 texture->SetImmutable(true); |
| 13820 } | 13794 } |
| 13821 } | 13795 } |
| 13822 | 13796 |
| 13797 void GLES2DecoderImpl::DoTexStorage3D( |
| 13798 GLenum target, |
| 13799 GLint levels, |
| 13800 GLenum internal_format, |
| 13801 GLsizei width, |
| 13802 GLsizei height, |
| 13803 GLsizei depth) { |
| 13804 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage3D", |
| 13805 "widthXheight", width * height, "depth", depth); |
| 13806 if (!validators_->texture_3_d_target.IsValid(target)) { |
| 13807 LOCAL_SET_GL_ERROR_INVALID_ENUM("glTexStorage3D", target, "target"); |
| 13808 return; |
| 13809 } |
| 13810 if (levels <= 0) { |
| 13811 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "levels <= 0"); |
| 13812 return; |
| 13813 } |
| 13814 if (!validators_->texture_internal_format_storage.IsValid(internal_format)) { |
| 13815 LOCAL_SET_GL_ERROR_INVALID_ENUM("glTexStorage3D", internal_format, |
| 13816 "internal_format"); |
| 13817 return; |
| 13818 } |
| 13819 if (width <= 0) { |
| 13820 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "width <= 0"); |
| 13821 return; |
| 13822 } |
| 13823 if (height <= 0) { |
| 13824 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "height <= 0"); |
| 13825 return; |
| 13826 } |
| 13827 if (depth <= 0) { |
| 13828 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexStorage3D", "depth <= 0"); |
| 13829 return; |
| 13830 } |
| 13831 if (!texture_manager()->ValidForTarget(target, 0, width, height, depth) || |
| 13832 TextureManager::ComputeMipMapCount( |
| 13833 target, width, height, depth) < levels) { |
| 13834 LOCAL_SET_GL_ERROR( |
| 13835 GL_INVALID_VALUE, "glTexStorage3D", "dimensions out of range"); |
| 13836 return; |
| 13837 } |
| 13838 TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 13839 &state_, target); |
| 13840 if (!texture_ref) { |
| 13841 LOCAL_SET_GL_ERROR( |
| 13842 GL_INVALID_OPERATION, |
| 13843 "glTexStorage3D", "unknown texture for target"); |
| 13844 return; |
| 13845 } |
| 13846 Texture* texture = texture_ref->texture(); |
| 13847 if (texture->IsAttachedToFramebuffer()) { |
| 13848 framebuffer_state_.clear_state_dirty = true; |
| 13849 } |
| 13850 if (texture->IsImmutable()) { |
| 13851 LOCAL_SET_GL_ERROR( |
| 13852 GL_INVALID_OPERATION, "glTexStorage3D", "texture is immutable"); |
| 13853 return; |
| 13854 } |
| 13855 |
| 13856 GLenum format = TextureManager::ExtractFormatFromStorageFormat( |
| 13857 internal_format); |
| 13858 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format); |
| 13859 |
| 13860 { |
| 13861 GLsizei level_width = width; |
| 13862 GLsizei level_height = height; |
| 13863 GLsizei level_depth = depth; |
| 13864 uint32_t estimated_size = 0; |
| 13865 for (int ii = 0; ii < levels; ++ii) { |
| 13866 uint32_t level_size = 0; |
| 13867 if (!GLES2Util::ComputeImageDataSizes( |
| 13868 level_width, level_height, level_depth, format, type, |
| 13869 state_.unpack_alignment, |
| 13870 &estimated_size, NULL, NULL) || |
| 13871 !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
| 13872 LOCAL_SET_GL_ERROR( |
| 13873 GL_OUT_OF_MEMORY, "glTexStorage3D", "dimensions too large"); |
| 13874 return; |
| 13875 } |
| 13876 level_width = std::max(1, level_width >> 1); |
| 13877 level_height = std::max(1, level_height >> 1); |
| 13878 if (target == GL_TEXTURE_3D) |
| 13879 level_depth = std::max(1, level_depth >> 1); |
| 13880 } |
| 13881 if (!EnsureGPUMemoryAvailable(estimated_size)) { |
| 13882 LOCAL_SET_GL_ERROR( |
| 13883 GL_OUT_OF_MEMORY, "glTexStorage3D", "out of memory"); |
| 13884 return; |
| 13885 } |
| 13886 } |
| 13887 |
| 13888 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage3D"); |
| 13889 glTexStorage3D(target, levels, internal_format, width, height, depth); |
| 13890 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage3D"); |
| 13891 if (error == GL_NO_ERROR) { |
| 13892 GLsizei level_width = width; |
| 13893 GLsizei level_height = height; |
| 13894 GLsizei level_depth = depth; |
| 13895 |
| 13896 GLenum cur_format = feature_info_->IsES3Enabled() ? |
| 13897 internal_format : format; |
| 13898 for (int ii = 0; ii < levels; ++ii) { |
| 13899 texture_manager()->SetLevelInfo(texture_ref, target, ii, cur_format, |
| 13900 level_width, level_height, level_depth, 0, |
| 13901 format, type, gfx::Rect()); |
| 13902 level_width = std::max(1, level_width >> 1); |
| 13903 level_height = std::max(1, level_height >> 1); |
| 13904 if (target == GL_TEXTURE_3D) |
| 13905 level_depth = std::max(1, level_depth >> 1); |
| 13906 } |
| 13907 texture->SetImmutable(true); |
| 13908 } |
| 13909 } |
| 13910 |
| 13823 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( | 13911 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
| 13824 uint32_t immediate_data_size, | 13912 uint32_t immediate_data_size, |
| 13825 const void* cmd_data) { | 13913 const void* cmd_data) { |
| 13826 return error::kUnknownCommand; | 13914 return error::kUnknownCommand; |
| 13827 } | 13915 } |
| 13828 | 13916 |
| 13829 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, | 13917 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
| 13830 const GLbyte* data) { | 13918 const GLbyte* data) { |
| 13831 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", | 13919 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
| 13832 "context", logger_.GetLogPrefix(), | 13920 "context", logger_.GetLogPrefix(), |
| (...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15625 } | 15713 } |
| 15626 | 15714 |
| 15627 // Include the auto-generated part of this file. We split this because it means | 15715 // Include the auto-generated part of this file. We split this because it means |
| 15628 // we can easily edit the non-auto generated parts right here in this file | 15716 // we can easily edit the non-auto generated parts right here in this file |
| 15629 // instead of having to edit some template or the code generator. | 15717 // instead of having to edit some template or the code generator. |
| 15630 #include "base/macros.h" | 15718 #include "base/macros.h" |
| 15631 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 15719 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 15632 | 15720 |
| 15633 } // namespace gles2 | 15721 } // namespace gles2 |
| 15634 } // namespace gpu | 15722 } // namespace gpu |
| OLD | NEW |