Chromium Code Reviews| 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 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1912 // Returns true if successful, simulated will be true if attrib0 was | 1912 // Returns true if successful, simulated will be true if attrib0 was |
| 1913 // simulated. | 1913 // simulated. |
| 1914 bool SimulateAttrib0( | 1914 bool SimulateAttrib0( |
| 1915 const char* function_name, GLuint max_vertex_accessed, bool* simulated); | 1915 const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
| 1916 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); | 1916 void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
| 1917 | 1917 |
| 1918 // Copies the image to the texture currently bound to |textarget|. The image | 1918 // Copies the image to the texture currently bound to |textarget|. The image |
| 1919 // state of |texture| is updated to reflect the new state. | 1919 // state of |texture| is updated to reflect the new state. |
| 1920 void DoCopyTexImage(Texture* texture, GLenum textarget, gl::GLImage* image); | 1920 void DoCopyTexImage(Texture* texture, GLenum textarget, gl::GLImage* image); |
| 1921 | 1921 |
| 1922 // This will call DoCopyTexImage if texture has an image but that image is | 1922 // If the texture has an image but that image is not bound or copied to the |
| 1923 // not bound or copied to the texture. | 1923 // texture, this will first attempt to bind it, and if that fails |
| 1924 void DoCopyTexImageIfNeeded(Texture* texture, GLenum textarget); | 1924 // DoCopyTexImage on it. texture_unit is the texture unit it should be bound |
| 1925 // to, or 0 if it doesn't matter. If restore is true then the previous | |
| 1926 // binding should be reset after the operation. This returns true if a copy | |
| 1927 // or bind happened. | |
| 1928 bool DoBindOrCopyTexImageIfNeeded(Texture* texture, | |
| 1929 GLenum textarget, | |
| 1930 GLuint texture_unit, | |
| 1931 bool restore); | |
| 1925 | 1932 |
| 1926 // Returns false if textures were replaced. | 1933 // Returns false if textures were replaced. |
| 1927 bool PrepareTexturesForRender(); | 1934 bool PrepareTexturesForRender(); |
| 1928 void RestoreStateForTextures(); | 1935 void RestoreStateForTextures(); |
| 1929 | 1936 |
| 1930 // Returns true if GL_FIXED attribs were simulated. | 1937 // Returns true if GL_FIXED attribs were simulated. |
| 1931 bool SimulateFixedAttribs( | 1938 bool SimulateFixedAttribs( |
| 1932 const char* function_name, | 1939 const char* function_name, |
| 1933 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); | 1940 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
| 1934 void RestoreStateForSimulatedFixedAttribs(); | 1941 void RestoreStateForSimulatedFixedAttribs(); |
| (...skipping 5838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7773 | 7780 |
| 7774 if ((level > 0 && !feature_info_->IsWebGL2OrES3Context()) || | 7781 if ((level > 0 && !feature_info_->IsWebGL2OrES3Context()) || |
| 7775 !texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { | 7782 !texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
| 7776 LOCAL_SET_GL_ERROR( | 7783 LOCAL_SET_GL_ERROR( |
| 7777 GL_INVALID_VALUE, | 7784 GL_INVALID_VALUE, |
| 7778 name, "level out of range"); | 7785 name, "level out of range"); |
| 7779 return; | 7786 return; |
| 7780 } | 7787 } |
| 7781 | 7788 |
| 7782 if (texture_ref) | 7789 if (texture_ref) |
| 7783 DoCopyTexImageIfNeeded(texture_ref->texture(), textarget); | 7790 DoBindOrCopyTexImageIfNeeded(texture_ref->texture(), textarget, 0, true); |
| 7784 | 7791 |
| 7785 std::vector<GLenum> attachments; | 7792 std::vector<GLenum> attachments; |
| 7786 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { | 7793 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { |
| 7787 attachments.push_back(GL_DEPTH_ATTACHMENT); | 7794 attachments.push_back(GL_DEPTH_ATTACHMENT); |
| 7788 attachments.push_back(GL_STENCIL_ATTACHMENT); | 7795 attachments.push_back(GL_STENCIL_ATTACHMENT); |
| 7789 } else { | 7796 } else { |
| 7790 attachments.push_back(attachment); | 7797 attachments.push_back(attachment); |
| 7791 } | 7798 } |
| 7792 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); | 7799 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 7793 for (size_t ii = 0; ii < attachments.size(); ++ii) { | 7800 for (size_t ii = 0; ii < attachments.size(); ++ii) { |
| (...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9651 gl::GLImage* image) { | 9658 gl::GLImage* image) { |
| 9652 // Note: We update the state to COPIED prior to calling CopyTexImage() | 9659 // Note: We update the state to COPIED prior to calling CopyTexImage() |
| 9653 // as that allows the GLImage implemenatation to set it back to UNBOUND | 9660 // as that allows the GLImage implemenatation to set it back to UNBOUND |
| 9654 // and ensure that CopyTexImage() is called each time the texture is | 9661 // and ensure that CopyTexImage() is called each time the texture is |
| 9655 // used. | 9662 // used. |
| 9656 texture->SetLevelImageState(textarget, 0, Texture::COPIED); | 9663 texture->SetLevelImageState(textarget, 0, Texture::COPIED); |
| 9657 bool rv = image->CopyTexImage(textarget); | 9664 bool rv = image->CopyTexImage(textarget); |
| 9658 DCHECK(rv) << "CopyTexImage() failed"; | 9665 DCHECK(rv) << "CopyTexImage() failed"; |
| 9659 } | 9666 } |
| 9660 | 9667 |
| 9661 void GLES2DecoderImpl::DoCopyTexImageIfNeeded(Texture* texture, | 9668 bool GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded(Texture* texture, |
| 9662 GLenum textarget) { | 9669 GLenum textarget, |
| 9670 GLuint texture_unit, | |
| 9671 bool restore_binding) { | |
| 9663 // Image is already in use if texture is attached to a framebuffer. | 9672 // Image is already in use if texture is attached to a framebuffer. |
| 9664 if (texture && !texture->IsAttachedToFramebuffer()) { | 9673 if (texture && !texture->IsAttachedToFramebuffer()) { |
| 9665 Texture::ImageState image_state; | 9674 Texture::ImageState image_state; |
| 9666 gl::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); | 9675 gl::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); |
| 9667 if (image && image_state == Texture::UNBOUND) { | 9676 if (image && image_state == Texture::UNBOUND) { |
| 9668 ScopedGLErrorSuppressor suppressor( | 9677 ScopedGLErrorSuppressor suppressor( |
| 9669 "GLES2DecoderImpl::DoCopyTexImageIfNeeded", GetErrorState()); | 9678 "GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded", GetErrorState()); |
| 9679 if (texture_unit) | |
| 9680 glActiveTexture(texture_unit); | |
| 9670 glBindTexture(textarget, texture->service_id()); | 9681 glBindTexture(textarget, texture->service_id()); |
| 9671 DoCopyTexImage(texture, textarget, image); | 9682 if (image->BindTexImage(textarget)) { |
| 9672 RestoreCurrentTextureBindings(&state_, textarget); | 9683 image_state = Texture::BOUND; |
| 9684 } else { | |
| 9685 DoCopyTexImage(texture, textarget, image); | |
| 9686 } | |
| 9687 if (restore_binding) | |
| 9688 RestoreCurrentTextureBindings(&state_, textarget); | |
|
Zhenyao Mo
2017/05/24 22:19:28
You need to expend this to take in texture_unit pa
| |
| 9689 return true; | |
| 9673 } | 9690 } |
| 9674 } | 9691 } |
| 9692 return false; | |
| 9675 } | 9693 } |
| 9676 | 9694 |
| 9677 void GLES2DecoderImpl::DoCopyBufferSubData(GLenum readtarget, | 9695 void GLES2DecoderImpl::DoCopyBufferSubData(GLenum readtarget, |
| 9678 GLenum writetarget, | 9696 GLenum writetarget, |
| 9679 GLintptr readoffset, | 9697 GLintptr readoffset, |
| 9680 GLintptr writeoffset, | 9698 GLintptr writeoffset, |
| 9681 GLsizeiptr size) { | 9699 GLsizeiptr size) { |
| 9682 // Just delegate it. Some validation is actually done before this. | 9700 // Just delegate it. Some validation is actually done before this. |
| 9683 buffer_manager()->ValidateAndDoCopyBufferSubData( | 9701 buffer_manager()->ValidateAndDoCopyBufferSubData( |
| 9684 &state_, readtarget, writetarget, readoffset, writeoffset, size); | 9702 &state_, readtarget, writetarget, readoffset, writeoffset, size); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9719 std::string("texture bound to texture unit ") + | 9737 std::string("texture bound to texture unit ") + |
| 9720 base::UintToString(texture_unit_index) + | 9738 base::UintToString(texture_unit_index) + |
| 9721 " is not renderable. It maybe non-power-of-2 and have" | 9739 " is not renderable. It maybe non-power-of-2 and have" |
| 9722 " incompatible texture filtering."); | 9740 " incompatible texture filtering."); |
| 9723 } | 9741 } |
| 9724 continue; | 9742 continue; |
| 9725 } | 9743 } |
| 9726 | 9744 |
| 9727 if (textarget != GL_TEXTURE_CUBE_MAP) { | 9745 if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 9728 Texture* texture = texture_ref->texture(); | 9746 Texture* texture = texture_ref->texture(); |
| 9729 Texture::ImageState image_state; | 9747 if (DoBindOrCopyTexImageIfNeeded(texture, textarget, |
| 9730 gl::GLImage* image = | 9748 GL_TEXTURE0 + texture_unit_index, |
| 9731 texture->GetLevelImage(textarget, 0, &image_state); | 9749 false)) { |
| 9732 if (image && image_state == Texture::UNBOUND && | |
| 9733 !texture->IsAttachedToFramebuffer()) { | |
| 9734 ScopedGLErrorSuppressor suppressor( | |
| 9735 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); | |
| 9736 textures_set = true; | 9750 textures_set = true; |
| 9737 glActiveTexture(GL_TEXTURE0 + texture_unit_index); | |
| 9738 DoCopyTexImage(texture, textarget, image); | |
| 9739 continue; | 9751 continue; |
| 9740 } | 9752 } |
| 9741 } | 9753 } |
| 9742 } | 9754 } |
| 9743 // else: should this be an error? | 9755 // else: should this be an error? |
| 9744 } | 9756 } |
| 9745 } | 9757 } |
| 9746 return !textures_set; | 9758 return !textures_set; |
| 9747 } | 9759 } |
| 9748 | 9760 |
| (...skipping 7191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16940 bool unpack_premultiply_alpha_change = | 16952 bool unpack_premultiply_alpha_change = |
| 16941 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; | 16953 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| 16942 // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexImage. | 16954 // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexImage. |
| 16943 if (image && dest_level == 0 && !unpack_flip_y && | 16955 if (image && dest_level == 0 && !unpack_flip_y && |
| 16944 !unpack_premultiply_alpha_change) { | 16956 !unpack_premultiply_alpha_change) { |
| 16945 glBindTexture(dest_binding_target, dest_texture->service_id()); | 16957 glBindTexture(dest_binding_target, dest_texture->service_id()); |
| 16946 if (image->CopyTexImage(dest_target)) | 16958 if (image->CopyTexImage(dest_target)) |
| 16947 return; | 16959 return; |
| 16948 } | 16960 } |
| 16949 | 16961 |
| 16950 DoCopyTexImageIfNeeded(source_texture, source_target); | 16962 DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0, true); |
| 16951 | 16963 |
| 16952 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix | 16964 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix |
| 16953 // before presenting. | 16965 // before presenting. |
| 16954 if (source_target == GL_TEXTURE_EXTERNAL_OES) { | 16966 if (source_target == GL_TEXTURE_EXTERNAL_OES) { |
| 16955 if (GLStreamTextureImage* image = | 16967 if (GLStreamTextureImage* image = |
| 16956 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, | 16968 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, |
| 16957 source_level)) { | 16969 source_level)) { |
| 16958 GLfloat transform_matrix[16]; | 16970 GLfloat transform_matrix[16]; |
| 16959 image->GetTextureMatrix(transform_matrix); | 16971 image->GetTextureMatrix(transform_matrix); |
| 16960 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( | 16972 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17152 if (image && dest_level == 0 && !unpack_flip_y && | 17164 if (image && dest_level == 0 && !unpack_flip_y && |
| 17153 !unpack_premultiply_alpha_change) { | 17165 !unpack_premultiply_alpha_change) { |
| 17154 ScopedTextureBinder binder(&state_, dest_texture->service_id(), | 17166 ScopedTextureBinder binder(&state_, dest_texture->service_id(), |
| 17155 dest_binding_target); | 17167 dest_binding_target); |
| 17156 if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset), | 17168 if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset), |
| 17157 gfx::Rect(x, y, width, height))) { | 17169 gfx::Rect(x, y, width, height))) { |
| 17158 return; | 17170 return; |
| 17159 } | 17171 } |
| 17160 } | 17172 } |
| 17161 | 17173 |
| 17162 DoCopyTexImageIfNeeded(source_texture, source_target); | 17174 DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0, true); |
| 17163 | 17175 |
| 17164 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix | 17176 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 17165 // before presenting. | 17177 // before presenting. |
| 17166 if (source_target == GL_TEXTURE_EXTERNAL_OES) { | 17178 if (source_target == GL_TEXTURE_EXTERNAL_OES) { |
| 17167 if (GLStreamTextureImage* image = | 17179 if (GLStreamTextureImage* image = |
| 17168 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, | 17180 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, |
| 17169 source_level)) { | 17181 source_level)) { |
| 17170 GLfloat transform_matrix[16]; | 17182 GLfloat transform_matrix[16]; |
| 17171 image->GetTextureMatrix(transform_matrix); | 17183 image->GetTextureMatrix(transform_matrix); |
| 17172 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform( | 17184 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform( |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17350 } | 17362 } |
| 17351 | 17363 |
| 17352 if (image->CopyTexImage(dest_texture->target())) | 17364 if (image->CopyTexImage(dest_texture->target())) |
| 17353 return; | 17365 return; |
| 17354 } | 17366 } |
| 17355 | 17367 |
| 17356 TRACE_EVENT0( | 17368 TRACE_EVENT0( |
| 17357 "gpu", | 17369 "gpu", |
| 17358 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); | 17370 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
| 17359 | 17371 |
| 17360 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); | 17372 DoBindOrCopyTexImageIfNeeded(source_texture, source_texture->target(), 0, |
| 17373 true); | |
| 17361 | 17374 |
| 17362 // As a fallback, copy into a non-compressed GL_RGBA texture. | 17375 // As a fallback, copy into a non-compressed GL_RGBA texture. |
| 17363 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); | 17376 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); |
| 17364 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height, | 17377 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height, |
| 17365 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); | 17378 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 17366 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); | 17379 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); |
| 17367 if (error != GL_NO_ERROR) { | 17380 if (error != GL_NO_ERROR) { |
| 17368 RestoreCurrentTextureBindings(&state_, dest_texture->target()); | 17381 RestoreCurrentTextureBindings(&state_, dest_texture->target()); |
| 17369 return; | 17382 return; |
| 17370 } | 17383 } |
| (...skipping 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 19725 } | 19738 } |
| 19726 | 19739 |
| 19727 // Include the auto-generated part of this file. We split this because it means | 19740 // Include the auto-generated part of this file. We split this because it means |
| 19728 // we can easily edit the non-auto generated parts right here in this file | 19741 // we can easily edit the non-auto generated parts right here in this file |
| 19729 // instead of having to edit some template or the code generator. | 19742 // instead of having to edit some template or the code generator. |
| 19730 #include "base/macros.h" | 19743 #include "base/macros.h" |
| 19731 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 19744 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 19732 | 19745 |
| 19733 } // namespace gles2 | 19746 } // namespace gles2 |
| 19734 } // namespace gpu | 19747 } // namespace gpu |
| OLD | NEW |