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

Side by Side Diff: content/common/gpu/client/gl_helper_scaling.cc

Issue 1160863007: DCHECK if shader compilation fails that it's due to context loss. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: glhelperlost: forreal Created 5 years, 6 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
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 "content/common/gpu/client/gl_helper_scaling.h" 5 #include "content/common/gpu/client/gl_helper_scaling.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "gpu/command_buffer/client/context_support.h"
18 #include "gpu/command_buffer/client/gles2_interface.h" 19 #include "gpu/command_buffer/client/gles2_interface.h"
19 #include "third_party/skia/include/core/SkRegion.h" 20 #include "third_party/skia/include/core/SkRegion.h"
20 #include "ui/gfx/geometry/rect.h" 21 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
22 23
23 using gpu::gles2::GLES2Interface; 24 using gpu::gles2::GLES2Interface;
24 25
25 namespace content { 26 namespace content {
26 27
27 GLHelperScaling::GLHelperScaling(GLES2Interface* gl, GLHelper* helper) 28 GLHelperScaling::GLHelperScaling(GLES2Interface* gl,
28 : gl_(gl), helper_(helper), vertex_attributes_buffer_(gl_) { 29 gpu::ContextSupport* context_support,
30 GLHelper* helper)
31 : gl_(gl),
32 context_support_(context_support),
33 helper_(helper),
34 vertex_attributes_buffer_(gl_) {
29 InitBuffer(); 35 InitBuffer();
30 } 36 }
31 37
32 GLHelperScaling::~GLHelperScaling() {} 38 GLHelperScaling::~GLHelperScaling() {}
33 39
34 // Used to keep track of a generated shader program. The program 40 // Used to keep track of a generated shader program. The program
35 // is passed in as text through Setup and is used by calling 41 // is passed in as text through Setup and is used by calling
36 // UseProgram() with the right parameters. Note that |gl_| 42 // UseProgram() with the right parameters. Note that |gl_|
37 // and |helper_| are assumed to live longer than this program. 43 // and |helper_| are assumed to live longer than this program.
38 class ShaderProgram : public base::RefCounted<ShaderProgram> { 44 class ShaderProgram : public base::RefCounted<ShaderProgram> {
39 public: 45 public:
40 ShaderProgram(GLES2Interface* gl, GLHelper* helper) 46 ShaderProgram(GLES2Interface* gl, GLHelper* helper)
41 : gl_(gl), 47 : gl_(gl),
42 helper_(helper), 48 helper_(helper),
43 program_(gl_->CreateProgram()), 49 program_(gl_->CreateProgram()),
44 position_location_(-1), 50 position_location_(-1),
45 texcoord_location_(-1), 51 texcoord_location_(-1),
46 src_subrect_location_(-1), 52 src_subrect_location_(-1),
47 src_pixelsize_location_(-1), 53 src_pixelsize_location_(-1),
48 dst_pixelsize_location_(-1), 54 dst_pixelsize_location_(-1),
49 scaling_vector_location_(-1), 55 scaling_vector_location_(-1),
50 color_weights_location_(-1) {} 56 color_weights_location_(-1) {}
51 57
52 // Compile shader program. 58 // Compile shader program.
53 void Setup(const GLchar* vertex_shader_text, 59 void Setup(gpu::ContextSupport* context_support,
60 const GLchar* vertex_shader_text,
54 const GLchar* fragment_shader_text); 61 const GLchar* fragment_shader_text);
55 62
56 // UseProgram must be called with GL_TEXTURE_2D bound to the 63 // UseProgram must be called with GL_TEXTURE_2D bound to the
57 // source texture and GL_ARRAY_BUFFER bound to a vertex 64 // source texture and GL_ARRAY_BUFFER bound to a vertex
58 // attribute buffer. 65 // attribute buffer.
59 void UseProgram(const gfx::Size& src_size, 66 void UseProgram(const gfx::Size& src_size,
60 const gfx::Rect& src_subrect, 67 const gfx::Rect& src_subrect,
61 const gfx::Size& dst_size, 68 const gfx::Size& dst_size,
62 bool scale_x, 69 bool scale_x,
63 bool flip_y, 70 bool flip_y,
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 } 828 }
822 } 829 }
823 830
824 vertex_program = vertex_header + shared_variables + "void main() {\n" + 831 vertex_program = vertex_header + shared_variables + "void main() {\n" +
825 vertex_program + "}\n"; 832 vertex_program + "}\n";
826 833
827 fragment_program = fragment_directives + fragment_header + 834 fragment_program = fragment_directives + fragment_header +
828 shared_variables + "void main() {\n" + fragment_program + 835 shared_variables + "void main() {\n" + fragment_program +
829 "}\n"; 836 "}\n";
830 837
831 cache_entry->Setup(vertex_program.c_str(), fragment_program.c_str()); 838 cache_entry->Setup(context_support_, vertex_program.c_str(),
839 fragment_program.c_str());
832 } 840 }
833 return cache_entry; 841 return cache_entry;
834 } 842 }
835 843
836 void ShaderProgram::Setup(const GLchar* vertex_shader_text, 844 void ShaderProgram::Setup(gpu::ContextSupport* context_support,
845 const GLchar* vertex_shader_text,
837 const GLchar* fragment_shader_text) { 846 const GLchar* fragment_shader_text) {
838 // Shaders to map the source texture to |dst_texture_|. 847 // Shaders to map the source texture to |dst_texture_|.
839 GLuint vertex_shader = 848 GLuint vertex_shader =
840 helper_->CompileShaderFromSource(vertex_shader_text, GL_VERTEX_SHADER); 849 helper_->CompileShaderFromSource(vertex_shader_text, GL_VERTEX_SHADER);
841 if (vertex_shader == 0) 850 if (vertex_shader == 0)
842 return; 851 return;
843 852
844 gl_->AttachShader(program_, vertex_shader); 853 gl_->AttachShader(program_, vertex_shader);
845 gl_->DeleteShader(vertex_shader); 854 gl_->DeleteShader(vertex_shader);
846 855
(...skipping 16 matching lines...) Expand all
863 texture_location_ = gl_->GetUniformLocation(program_, "s_texture"); 872 texture_location_ = gl_->GetUniformLocation(program_, "s_texture");
864 src_subrect_location_ = gl_->GetUniformLocation(program_, "src_subrect"); 873 src_subrect_location_ = gl_->GetUniformLocation(program_, "src_subrect");
865 src_pixelsize_location_ = gl_->GetUniformLocation(program_, "src_pixelsize"); 874 src_pixelsize_location_ = gl_->GetUniformLocation(program_, "src_pixelsize");
866 dst_pixelsize_location_ = gl_->GetUniformLocation(program_, "dst_pixelsize"); 875 dst_pixelsize_location_ = gl_->GetUniformLocation(program_, "dst_pixelsize");
867 scaling_vector_location_ = 876 scaling_vector_location_ =
868 gl_->GetUniformLocation(program_, "scaling_vector"); 877 gl_->GetUniformLocation(program_, "scaling_vector");
869 color_weights_location_ = gl_->GetUniformLocation(program_, "color_weights"); 878 color_weights_location_ = gl_->GetUniformLocation(program_, "color_weights");
870 // The only reason fetching these attribute locations should fail is 879 // The only reason fetching these attribute locations should fail is
871 // if the context was spontaneously lost (i.e., because the GPU 880 // if the context was spontaneously lost (i.e., because the GPU
872 // process crashed, perhaps deliberately for testing). 881 // process crashed, perhaps deliberately for testing).
873 // Unfortunately, the only way to reliably detect context loss from 882 DCHECK_IMPLIES(!Initialized(), context_support->IsContextLost());
Ken Russell (switch to Gerrit) 2015/05/29 22:42:44 Nice.
874 // GLES2Interface would be to repeatedly call GetError(), and this
875 // seems fragile. Most of the APIs in GLHelper should be updated to
876 // be able to return an error. Fortunately, many users of this code
877 // check for context loss at a higher level.
878 if (!Initialized()) {
879 LOG(ERROR) << "ShaderProgram::Setup: initialization failed (context lost?)";
880 }
881 return; 883 return;
882 } 884 }
883 885
884 void ShaderProgram::UseProgram(const gfx::Size& src_size, 886 void ShaderProgram::UseProgram(const gfx::Size& src_size,
885 const gfx::Rect& src_subrect, 887 const gfx::Rect& src_subrect,
886 const gfx::Size& dst_size, 888 const gfx::Size& dst_size,
887 bool scale_x, 889 bool scale_x,
888 bool flip_y, 890 bool flip_y,
889 GLfloat color_weights[4]) { 891 GLfloat color_weights[4]) {
890 gl_->UseProgram(program_); 892 gl_->UseProgram(program_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 gl_->Uniform2f(dst_pixelsize_location_, 932 gl_->Uniform2f(dst_pixelsize_location_,
931 static_cast<float>(dst_size.width()), 933 static_cast<float>(dst_size.width()),
932 static_cast<float>(dst_size.height())); 934 static_cast<float>(dst_size.height()));
933 935
934 gl_->Uniform2f( 936 gl_->Uniform2f(
935 scaling_vector_location_, scale_x ? 1.0 : 0.0, scale_x ? 0.0 : 1.0); 937 scaling_vector_location_, scale_x ? 1.0 : 0.0, scale_x ? 0.0 : 1.0);
936 gl_->Uniform4fv(color_weights_location_, 1, color_weights); 938 gl_->Uniform4fv(color_weights_location_, 1, color_weights);
937 } 939 }
938 940
939 } // namespace content 941 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/client/gl_helper_scaling.h ('k') | content/common/gpu/client/gl_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698