Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 2859723002: Copy NV12 picture buffers on demand on the main thread. (Closed)
Patch Set: connect active texture and restoring bindings Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gpu/command_buffer/service/gles2_cmd_decoder_unittest_textures.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 - setting it to 0 will cause the previous
1926 // binding to be restored 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);
1925 1931
1926 // Returns false if textures were replaced. 1932 // Returns false if textures were replaced.
1927 bool PrepareTexturesForRender(); 1933 bool PrepareTexturesForRender();
1928 void RestoreStateForTextures(); 1934 void RestoreStateForTextures();
1929 1935
1930 // Returns true if GL_FIXED attribs were simulated. 1936 // Returns true if GL_FIXED attribs were simulated.
1931 bool SimulateFixedAttribs( 1937 bool SimulateFixedAttribs(
1932 const char* function_name, 1938 const char* function_name,
1933 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); 1939 GLuint max_vertex_accessed, bool* simulated, GLsizei primcount);
1934 void RestoreStateForSimulatedFixedAttribs(); 1940 void RestoreStateForSimulatedFixedAttribs();
(...skipping 5838 matching lines...) Expand 10 before | Expand all | Expand 10 after
7773 7779
7774 if ((level > 0 && !feature_info_->IsWebGL2OrES3Context()) || 7780 if ((level > 0 && !feature_info_->IsWebGL2OrES3Context()) ||
7775 !texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { 7781 !texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) {
7776 LOCAL_SET_GL_ERROR( 7782 LOCAL_SET_GL_ERROR(
7777 GL_INVALID_VALUE, 7783 GL_INVALID_VALUE,
7778 name, "level out of range"); 7784 name, "level out of range");
7779 return; 7785 return;
7780 } 7786 }
7781 7787
7782 if (texture_ref) 7788 if (texture_ref)
7783 DoCopyTexImageIfNeeded(texture_ref->texture(), textarget); 7789 DoBindOrCopyTexImageIfNeeded(texture_ref->texture(), textarget, 0);
7784 7790
7785 std::vector<GLenum> attachments; 7791 std::vector<GLenum> attachments;
7786 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) { 7792 if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
7787 attachments.push_back(GL_DEPTH_ATTACHMENT); 7793 attachments.push_back(GL_DEPTH_ATTACHMENT);
7788 attachments.push_back(GL_STENCIL_ATTACHMENT); 7794 attachments.push_back(GL_STENCIL_ATTACHMENT);
7789 } else { 7795 } else {
7790 attachments.push_back(attachment); 7796 attachments.push_back(attachment);
7791 } 7797 }
7792 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); 7798 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name);
7793 for (size_t ii = 0; ii < attachments.size(); ++ii) { 7799 for (size_t ii = 0; ii < attachments.size(); ++ii) {
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
9651 gl::GLImage* image) { 9657 gl::GLImage* image) {
9652 // Note: We update the state to COPIED prior to calling CopyTexImage() 9658 // Note: We update the state to COPIED prior to calling CopyTexImage()
9653 // as that allows the GLImage implemenatation to set it back to UNBOUND 9659 // as that allows the GLImage implemenatation to set it back to UNBOUND
9654 // and ensure that CopyTexImage() is called each time the texture is 9660 // and ensure that CopyTexImage() is called each time the texture is
9655 // used. 9661 // used.
9656 texture->SetLevelImageState(textarget, 0, Texture::COPIED); 9662 texture->SetLevelImageState(textarget, 0, Texture::COPIED);
9657 bool rv = image->CopyTexImage(textarget); 9663 bool rv = image->CopyTexImage(textarget);
9658 DCHECK(rv) << "CopyTexImage() failed"; 9664 DCHECK(rv) << "CopyTexImage() failed";
9659 } 9665 }
9660 9666
9661 void GLES2DecoderImpl::DoCopyTexImageIfNeeded(Texture* texture, 9667 bool GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded(Texture* texture,
9662 GLenum textarget) { 9668 GLenum textarget,
9669 GLuint texture_unit) {
9663 // Image is already in use if texture is attached to a framebuffer. 9670 // Image is already in use if texture is attached to a framebuffer.
9664 if (texture && !texture->IsAttachedToFramebuffer()) { 9671 if (texture && !texture->IsAttachedToFramebuffer()) {
9665 Texture::ImageState image_state; 9672 Texture::ImageState image_state;
9666 gl::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state); 9673 gl::GLImage* image = texture->GetLevelImage(textarget, 0, &image_state);
9667 if (image && image_state == Texture::UNBOUND) { 9674 if (image && image_state == Texture::UNBOUND) {
9668 ScopedGLErrorSuppressor suppressor( 9675 ScopedGLErrorSuppressor suppressor(
9669 "GLES2DecoderImpl::DoCopyTexImageIfNeeded", GetErrorState()); 9676 "GLES2DecoderImpl::DoBindOrCopyTexImageIfNeeded", GetErrorState());
9677 if (texture_unit)
9678 glActiveTexture(texture_unit);
9670 glBindTexture(textarget, texture->service_id()); 9679 glBindTexture(textarget, texture->service_id());
Zhenyao Mo 2017/05/25 17:21:58 I am still concerned. Here we changed the tex bind
9671 DoCopyTexImage(texture, textarget, image); 9680 if (image->BindTexImage(textarget)) {
9672 RestoreCurrentTextureBindings(&state_, textarget); 9681 image_state = Texture::BOUND;
9682 } else {
9683 DoCopyTexImage(texture, textarget, image);
9684 }
9685 if (!texture_unit)
9686 RestoreCurrentTextureBindings(&state_, textarget);
9687 return true;
9673 } 9688 }
9674 } 9689 }
9690 return false;
9675 } 9691 }
9676 9692
9677 void GLES2DecoderImpl::DoCopyBufferSubData(GLenum readtarget, 9693 void GLES2DecoderImpl::DoCopyBufferSubData(GLenum readtarget,
9678 GLenum writetarget, 9694 GLenum writetarget,
9679 GLintptr readoffset, 9695 GLintptr readoffset,
9680 GLintptr writeoffset, 9696 GLintptr writeoffset,
9681 GLsizeiptr size) { 9697 GLsizeiptr size) {
9682 // Just delegate it. Some validation is actually done before this. 9698 // Just delegate it. Some validation is actually done before this.
9683 buffer_manager()->ValidateAndDoCopyBufferSubData( 9699 buffer_manager()->ValidateAndDoCopyBufferSubData(
9684 &state_, readtarget, writetarget, readoffset, writeoffset, size); 9700 &state_, readtarget, writetarget, readoffset, writeoffset, size);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
9719 std::string("texture bound to texture unit ") + 9735 std::string("texture bound to texture unit ") +
9720 base::UintToString(texture_unit_index) + 9736 base::UintToString(texture_unit_index) +
9721 " is not renderable. It maybe non-power-of-2 and have" 9737 " is not renderable. It maybe non-power-of-2 and have"
9722 " incompatible texture filtering."); 9738 " incompatible texture filtering.");
9723 } 9739 }
9724 continue; 9740 continue;
9725 } 9741 }
9726 9742
9727 if (textarget != GL_TEXTURE_CUBE_MAP) { 9743 if (textarget != GL_TEXTURE_CUBE_MAP) {
9728 Texture* texture = texture_ref->texture(); 9744 Texture* texture = texture_ref->texture();
9729 Texture::ImageState image_state; 9745 if (DoBindOrCopyTexImageIfNeeded(texture, textarget,
9730 gl::GLImage* image = 9746 GL_TEXTURE0 + texture_unit_index)) {
9731 texture->GetLevelImage(textarget, 0, &image_state);
9732 if (image && image_state == Texture::UNBOUND &&
9733 !texture->IsAttachedToFramebuffer()) {
9734 ScopedGLErrorSuppressor suppressor(
9735 "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState());
9736 textures_set = true; 9747 textures_set = true;
9737 glActiveTexture(GL_TEXTURE0 + texture_unit_index);
9738 DoCopyTexImage(texture, textarget, image);
9739 continue; 9748 continue;
9740 } 9749 }
9741 } 9750 }
9742 } 9751 }
9743 // else: should this be an error? 9752 // else: should this be an error?
9744 } 9753 }
9745 } 9754 }
9746 return !textures_set; 9755 return !textures_set;
9747 } 9756 }
9748 9757
(...skipping 7191 matching lines...) Expand 10 before | Expand all | Expand 10 after
16940 bool unpack_premultiply_alpha_change = 16949 bool unpack_premultiply_alpha_change =
16941 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; 16950 (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0;
16942 // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexImage. 16951 // TODO(qiankun.miao@intel.com): Support level > 0 for CopyTexImage.
16943 if (image && dest_level == 0 && !unpack_flip_y && 16952 if (image && dest_level == 0 && !unpack_flip_y &&
16944 !unpack_premultiply_alpha_change) { 16953 !unpack_premultiply_alpha_change) {
16945 glBindTexture(dest_binding_target, dest_texture->service_id()); 16954 glBindTexture(dest_binding_target, dest_texture->service_id());
16946 if (image->CopyTexImage(dest_target)) 16955 if (image->CopyTexImage(dest_target))
16947 return; 16956 return;
16948 } 16957 }
16949 16958
16950 DoCopyTexImageIfNeeded(source_texture, source_target); 16959 DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0);
16951 16960
16952 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix 16961 // GL_TEXTURE_EXTERNAL_OES texture requires that we apply a transform matrix
16953 // before presenting. 16962 // before presenting.
16954 if (source_target == GL_TEXTURE_EXTERNAL_OES) { 16963 if (source_target == GL_TEXTURE_EXTERNAL_OES) {
16955 if (GLStreamTextureImage* image = 16964 if (GLStreamTextureImage* image =
16956 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 16965 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
16957 source_level)) { 16966 source_level)) {
16958 GLfloat transform_matrix[16]; 16967 GLfloat transform_matrix[16];
16959 image->GetTextureMatrix(transform_matrix); 16968 image->GetTextureMatrix(transform_matrix);
16960 copy_texture_CHROMIUM_->DoCopyTextureWithTransform( 16969 copy_texture_CHROMIUM_->DoCopyTextureWithTransform(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
17152 if (image && dest_level == 0 && !unpack_flip_y && 17161 if (image && dest_level == 0 && !unpack_flip_y &&
17153 !unpack_premultiply_alpha_change) { 17162 !unpack_premultiply_alpha_change) {
17154 ScopedTextureBinder binder(&state_, dest_texture->service_id(), 17163 ScopedTextureBinder binder(&state_, dest_texture->service_id(),
17155 dest_binding_target); 17164 dest_binding_target);
17156 if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset), 17165 if (image->CopyTexSubImage(dest_target, gfx::Point(xoffset, yoffset),
17157 gfx::Rect(x, y, width, height))) { 17166 gfx::Rect(x, y, width, height))) {
17158 return; 17167 return;
17159 } 17168 }
17160 } 17169 }
17161 17170
17162 DoCopyTexImageIfNeeded(source_texture, source_target); 17171 DoBindOrCopyTexImageIfNeeded(source_texture, source_target, 0);
17163 17172
17164 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix 17173 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
17165 // before presenting. 17174 // before presenting.
17166 if (source_target == GL_TEXTURE_EXTERNAL_OES) { 17175 if (source_target == GL_TEXTURE_EXTERNAL_OES) {
17167 if (GLStreamTextureImage* image = 17176 if (GLStreamTextureImage* image =
17168 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES, 17177 source_texture->GetLevelStreamTextureImage(GL_TEXTURE_EXTERNAL_OES,
17169 source_level)) { 17178 source_level)) {
17170 GLfloat transform_matrix[16]; 17179 GLfloat transform_matrix[16];
17171 image->GetTextureMatrix(transform_matrix); 17180 image->GetTextureMatrix(transform_matrix);
17172 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform( 17181 copy_texture_CHROMIUM_->DoCopySubTextureWithTransform(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
17350 } 17359 }
17351 17360
17352 if (image->CopyTexImage(dest_texture->target())) 17361 if (image->CopyTexImage(dest_texture->target()))
17353 return; 17362 return;
17354 } 17363 }
17355 17364
17356 TRACE_EVENT0( 17365 TRACE_EVENT0(
17357 "gpu", 17366 "gpu",
17358 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); 17367 "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback");
17359 17368
17360 DoCopyTexImageIfNeeded(source_texture, source_texture->target()); 17369 DoBindOrCopyTexImageIfNeeded(source_texture, source_texture->target(), 0);
17361 17370
17362 // As a fallback, copy into a non-compressed GL_RGBA texture. 17371 // As a fallback, copy into a non-compressed GL_RGBA texture.
17363 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName); 17372 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(kFunctionName);
17364 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height, 17373 glTexImage2D(dest_texture->target(), 0, GL_RGBA, source_width, source_height,
17365 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); 17374 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
17366 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName); 17375 GLenum error = LOCAL_PEEK_GL_ERROR(kFunctionName);
17367 if (error != GL_NO_ERROR) { 17376 if (error != GL_NO_ERROR) {
17368 RestoreCurrentTextureBindings(&state_, dest_texture->target()); 17377 RestoreCurrentTextureBindings(&state_, dest_texture->target());
17369 return; 17378 return;
17370 } 17379 }
(...skipping 2354 matching lines...) Expand 10 before | Expand all | Expand 10 after
19725 } 19734 }
19726 19735
19727 // Include the auto-generated part of this file. We split this because it means 19736 // 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 19737 // 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. 19738 // instead of having to edit some template or the code generator.
19730 #include "base/macros.h" 19739 #include "base/macros.h"
19731 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19740 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
19732 19741
19733 } // namespace gles2 19742 } // namespace gles2
19734 } // namespace gpu 19743 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/gles2_cmd_decoder_unittest_textures.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698