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

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: Cleanup and adding interfaces based on review feedback.: 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() {}
69
68 GlCanvas::GlCanvas(int gl_version) : gl_version_(gl_version) { 70 GlCanvas::GlCanvas(int gl_version) : gl_version_(gl_version) {
69 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); 71 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
70 72
71 vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert); 73 vertex_shader_ = CompileShader(GL_VERTEX_SHADER, kTexCoordToViewVert);
72 fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag); 74 fragment_shader_ = CompileShader(GL_FRAGMENT_SHADER, kDrawTexFrag);
73 program_ = CreateProgram(vertex_shader_, fragment_shader_); 75 program_ = CreateProgram(vertex_shader_, fragment_shader_);
74 glUseProgram(program_); 76 glUseProgram(program_);
75 77
76 transform_location_ = glGetUniformLocation(program_, "u_transform"); 78 transform_location_ = glGetUniformLocation(program_, "u_transform");
77 view_size_location_ = glGetUniformLocation(program_, "u_viewSize"); 79 view_size_location_ = glGetUniformLocation(program_, "u_viewSize");
(...skipping 11 matching lines...) Expand all
89 GlCanvas::~GlCanvas() { 91 GlCanvas::~GlCanvas() {
90 DCHECK(thread_checker_.CalledOnValidThread()); 92 DCHECK(thread_checker_.CalledOnValidThread());
91 glDisable(GL_BLEND); 93 glDisable(GL_BLEND);
92 glDisableVertexAttribArray(tex_cord_location_); 94 glDisableVertexAttribArray(tex_cord_location_);
93 glDisableVertexAttribArray(position_location_); 95 glDisableVertexAttribArray(position_location_);
94 glDeleteProgram(program_); 96 glDeleteProgram(program_);
95 glDeleteShader(vertex_shader_); 97 glDeleteShader(vertex_shader_);
96 glDeleteShader(fragment_shader_); 98 glDeleteShader(fragment_shader_);
97 } 99 }
98 100
101 void GlCanvas::Clear() {
102 #ifndef NDEBUG
103 // Set the background clear color to bright green for debugging purposes.
104 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
105 #else
106 // Set the background clear color to black.
107 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
108 #endif
109 glClear(GL_COLOR_BUFFER_BIT);
110 }
111
99 void GlCanvas::SetTransformationMatrix(const std::array<float, 9>& matrix) { 112 void GlCanvas::SetTransformationMatrix(const std::array<float, 9>& matrix) {
100 DCHECK(thread_checker_.CalledOnValidThread()); 113 DCHECK(thread_checker_.CalledOnValidThread());
101 std::array<float, 9> transposed_matrix = matrix; 114 std::array<float, 9> transposed_matrix = matrix;
102 TransposeTransformationMatrix(&transposed_matrix); 115 TransposeTransformationMatrix(&transposed_matrix);
103 glUniformMatrix3fv(transform_location_, 1, GL_FALSE, 116 glUniformMatrix3fv(transform_location_, 1, GL_FALSE,
104 transposed_matrix.data()); 117 transposed_matrix.data());
105 transformation_set_ = true; 118 transformation_set_ = true;
106 } 119 }
107 120
108 void GlCanvas::SetViewSize(int width, int height) { 121 void GlCanvas::SetViewSize(int width, int height) {
(...skipping 21 matching lines...) Expand all
130 glVertexAttribPointer(position_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 143 glVertexAttribPointer(position_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0,
131 0); 144 0);
132 glVertexAttribPointer(tex_cord_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0, 145 glVertexAttribPointer(tex_cord_location_, kVertexSize, GL_FLOAT, GL_FALSE, 0,
133 static_cast<float*>(0) + kVertexSize * kVertexCount); 146 static_cast<float*>(0) + kVertexSize * kVertexCount);
134 147
135 glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount); 148 glDrawArrays(GL_TRIANGLE_STRIP, 0, kVertexCount);
136 glBindBuffer(GL_ARRAY_BUFFER, 0); 149 glBindBuffer(GL_ARRAY_BUFFER, 0);
137 glBindTexture(GL_TEXTURE_2D, 0); 150 glBindTexture(GL_TEXTURE_2D, 0);
138 } 151 }
139 152
140 int GlCanvas::GetGlVersion() const { 153 int GlCanvas::GetVersion() const {
141 return gl_version_; 154 return gl_version_;
142 } 155 }
143 156
144 int GlCanvas::GetMaxTextureSize() const { 157 int GlCanvas::GetMaxTextureSize() const {
145 return max_texture_size_; 158 return max_texture_size_;
146 } 159 }
147 160
148 } // namespace remoting 161 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698