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

Side by Side Diff: remoting/client/display/gl_canvas.cc

Issue 2591363002: Adding drawable to CRD andorid and iOS gl rendering pipeline. (Closed)
Patch Set: More like GetZIndex. Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "remoting/client/display/gl_canvas.h" 5 #include "remoting/client/display/gl_canvas.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "remoting/client/display/gl_helpers.h" 8 #include "remoting/client/display/gl_helpers.h"
9 #include "remoting/client/display/gl_math.h" 9 #include "remoting/client/display/gl_math.h"
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 "uniform float u_alpha_multiplier;\n" 58 "uniform float u_alpha_multiplier;\n"
59 "void main() {\n" 59 "void main() {\n"
60 " gl_FragColor = texture2D(u_texture, v_texCoord);\n" 60 " gl_FragColor = texture2D(u_texture, v_texCoord);\n"
61 " gl_FragColor.a *= u_alpha_multiplier;\n" 61 " gl_FragColor.a *= u_alpha_multiplier;\n"
62 "}"; 62 "}";
63 63
64 } // namespace 64 } // namespace
65 65
66 namespace remoting { 66 namespace remoting {
67 67
68 GlCanvas::GlCanvas(int gl_version) : gl_version_(gl_version) { 68 GlCanvas::GlCanvas(int gl_version)
69 : gl_version_(gl_version), weak_factory_(this) {
69 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); 70 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
70 71
71 vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert); 72 vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert);
72 fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag); 73 fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag);
73 program_ = CreateProgram(vertex_shader_, fragment_shader_); 74 program_ = CreateProgram(vertex_shader_, fragment_shader_);
74 glUseProgram(program_); 75 glUseProgram(program_);
75 76
76 transform_location_ = glGetUniformLocation(program_, "u_transform"); 77 transform_location_ = glGetUniformLocation(program_, "u_transform");
77 view_size_location_ = glGetUniformLocation(program_, "u_viewSize"); 78 view_size_location_ = glGetUniformLocation(program_, "u_viewSize");
78 texture_location_ = glGetUniformLocation(program_, "u_texture"); 79 texture_location_ = glGetUniformLocation(program_, "u_texture");
(...skipping 10 matching lines...) Expand all
89 GlCanvas::~GlCanvas() { 90 GlCanvas::~GlCanvas() {
90 DCHECK(thread_checker_.CalledOnValidThread()); 91 DCHECK(thread_checker_.CalledOnValidThread());
91 glDisable(GL_BLEND); 92 glDisable(GL_BLEND);
92 glDisableVertexAttribArray(tex_cord_location_); 93 glDisableVertexAttribArray(tex_cord_location_);
93 glDisableVertexAttribArray(position_location_); 94 glDisableVertexAttribArray(position_location_);
94 glDeleteProgram(program_); 95 glDeleteProgram(program_);
95 glDeleteShader(vertex_shader_); 96 glDeleteShader(vertex_shader_);
96 glDeleteShader(fragment_shader_); 97 glDeleteShader(fragment_shader_);
97 } 98 }
98 99
100 void GlCanvas::Clear() {
101 #ifndef NDEBUG
102 // Set the background clear color to bright green for debugging purposes.
103 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
104 #else
105 // Set the background clear color to black.
106 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
107 #endif
108 glClear(GL_COLOR_BUFFER_BIT);
109 }
110
99 void GlCanvas::SetTransformationMatrix(const std::array<float, 9>& matrix) { 111 void GlCanvas::SetTransformationMatrix(const std::array<float, 9>& matrix) {
100 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
101 std::array<float, 9> transposed_matrix = matrix; 113 std::array<float, 9> transposed_matrix = matrix;
102 TransposeTransformationMatrix(&transposed_matrix); 114 TransposeTransformationMatrix(&transposed_matrix);
103 glUniformMatrix3fv(transform_location_, 1, GL_FALSE, 115 glUniformMatrix3fv(transform_location_, 1, GL_FALSE,
104 transposed_matrix.data()); 116 transposed_matrix.data());
105 transformation_set_ = true; 117 transformation_set_ = true;
106 } 118 }
107 119
108 void GlCanvas::SetViewSize(int width, int height) { 120 void GlCanvas::SetViewSize(int width, int height) {
109 DCHECK(width > 0 && height > 0); 121 DCHECK(width > 0 && height > 0);
110 glViewport(0, 0, width, height); 122 glViewport(0, 0, width, height);
111 float view_size[2]{width, height}; 123 float view_size[2]{width, height};
112 glUniform2fv(view_size_location_, 1, view_size); 124 glUniform2fv(view_size_location_, 1, view_size);
113 view_size_set_ = true; 125 view_size_set_ = true;
114 } 126 }
115 127
116 void GlCanvas::DrawTexture(int texture_id, 128 void GlCanvas::DrawTexture(int texture_id,
117 GLuint texture_handle, 129 int texture_handle,
118 GLuint vertex_buffer, 130 int vertex_buffer,
119 float alpha_multiplier) { 131 float alpha_multiplier) {
120 DCHECK(thread_checker_.CalledOnValidThread()); 132 DCHECK(thread_checker_.CalledOnValidThread());
121 if (!view_size_set_ || !transformation_set_) { 133 if (!view_size_set_ || !transformation_set_) {
122 return; 134 return;
123 } 135 }
124 glActiveTexture(GL_TEXTURE0 + texture_id); 136 glActiveTexture(GL_TEXTURE0 + texture_id);
125 glBindTexture(GL_TEXTURE_2D, texture_handle); 137 glBindTexture(GL_TEXTURE_2D, texture_handle);
126 glUniform1i(texture_location_, texture_id); 138 glUniform1i(texture_location_, texture_id);
127 glUniform1f(alpha_multiplier_location_, alpha_multiplier); 139 glUniform1f(alpha_multiplier_location_, alpha_multiplier);
128 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); 140 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
129 141
130 glVertexAttribPointer(position_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 142 glVertexAttribPointer(position_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0,
131 0); 143 0);
132 glVertexAttribPointer(tex_cord_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 144 glVertexAttribPointer(tex_cord_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0,
133 static_cast<float*>(0) + kVertexSize * kVertexCount); 145 static_cast<float*>(0) + kVertexSize * kVertexCount);
134 146
135 glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount); 147 glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount);
136 glBindBuffer(GL_ARRAY_BUFFER, 0); 148 glBindBuffer(GL_ARRAY_BUFFER, 0);
137 glBindTexture(GL_TEXTURE_2D, 0); 149 glBindTexture(GL_TEXTURE_2D, 0);
138 } 150 }
139 151
140 int GlCanvas::GetGlVersion() const { 152 int GlCanvas::GetVersion() const {
141 return gl_version_; 153 return gl_version_;
142 } 154 }
143 155
144 int GlCanvas::GetMaxTextureSize() const { 156 int GlCanvas::GetMaxTextureSize() const {
145 return max_texture_size_; 157 return max_texture_size_;
146 } 158 }
147 159
160 base::WeakPtr<Canvas> GlCanvas::GetWeakPtr() {
161 DCHECK(thread_checker_.CalledOnValidThread());
162 return weak_factory_.GetWeakPtr();
163 }
164
148 } // namespace remoting 165 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698