| OLD | NEW |
| 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/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/gl_helpers.h" | 8 #include "remoting/client/display/gl_helpers.h" |
| 9 #include "remoting/client/gl_math.h" | 9 #include "remoting/client/display/gl_math.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 const int kVertexSize = 2; | 13 const int kVertexSize = 2; |
| 14 const int kVertexCount = 4; | 14 const int kVertexCount = 4; |
| 15 | 15 |
| 16 const char kTexCoordToViewVert[] = | 16 const char kTexCoordToViewVert[] = |
| 17 // Region of the texture to be used (normally the whole texture). | 17 // Region of the texture to be used (normally the whole texture). |
| 18 "varying vec2 v_texCoord;\n" | 18 "varying vec2 v_texCoord;\n" |
| 19 "attribute vec2 a_texCoord;\n" | 19 "attribute vec2 a_texCoord;\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 30 // This matrix translates normalized texture coordinates | 30 // This matrix translates normalized texture coordinates |
| 31 // ([0, 1] starting at upper-left corner) to the view coordinates | 31 // ([0, 1] starting at upper-left corner) to the view coordinates |
| 32 // ([-1, 1] starting at the center of the screen). | 32 // ([-1, 1] starting at the center of the screen). |
| 33 // Note that the matrix is defined in column-major order. | 33 // Note that the matrix is defined in column-major order. |
| 34 "const mat3 tex_to_view = mat3(2, 0, 0,\n" | 34 "const mat3 tex_to_view = mat3(2, 0, 0,\n" |
| 35 " 0, -2, 0,\n" | 35 " 0, -2, 0,\n" |
| 36 " -1, 1, 0);\n" | 36 " -1, 1, 0);\n" |
| 37 "void main() {\n" | 37 "void main() {\n" |
| 38 " v_texCoord = a_texCoord;\n" | 38 " v_texCoord = a_texCoord;\n" |
| 39 | 39 |
| 40 // Transforms coordinates related to the canvas to coordinates | 40 // Transforms coordinates related to the canvas to coordinates |
| 41 // related to the view. | 41 // related to the view. |
| 42 " vec3 trans_position = u_transform * vec3(a_position, 1.0);\n" | 42 " vec3 trans_position = u_transform * vec3(a_position, 1.0);\n" |
| 43 | 43 |
| 44 // Normalize the position by the size of the view. | 44 // Normalize the position by the size of the view. |
| 45 " trans_position.xy /= u_viewSize;\n" | 45 " trans_position.xy /= u_viewSize;\n" |
| 46 | 46 |
| 47 // Transforms texture coordinates to view coordinates and adds | 47 // Transforms texture coordinates to view coordinates and adds |
| 48 // projection component 1. | 48 // projection component 1. |
| 49 " gl_Position = vec4(tex_to_view * trans_position, 1.0);\n" | 49 " gl_Position = vec4(tex_to_view * trans_position, 1.0);\n" |
| 50 "}"; | 50 "}"; |
| 51 | 51 |
| 52 const char kDrawTexFrag[] = | 52 const char kDrawTexFrag[] = |
| 53 "precision mediump float;\n" | 53 "precision mediump float;\n" |
| 54 | 54 |
| 55 // Region on the texture to be used (normally the whole texture). | 55 // Region on the texture to be used (normally the whole texture). |
| 56 "varying vec2 v_texCoord;\n" | 56 "varying vec2 v_texCoord;\n" |
| 57 "uniform sampler2D u_texture;\n" | 57 "uniform sampler2D u_texture;\n" |
| 58 "uniform float u_alpha_multiplier;\n" | 58 "uniform float u_alpha_multiplier;\n" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 std::array<float, 9> transposed_matrix = matrix; | 101 std::array<float, 9> transposed_matrix = matrix; |
| 102 TransposeTransformationMatrix(&transposed_matrix); | 102 TransposeTransformationMatrix(&transposed_matrix); |
| 103 glUniformMatrix3fv(transform_location_, 1, GL_FALSE, | 103 glUniformMatrix3fv(transform_location_, 1, GL_FALSE, |
| 104 transposed_matrix.data()); | 104 transposed_matrix.data()); |
| 105 transformation_set_ = true; | 105 transformation_set_ = true; |
| 106 } | 106 } |
| 107 | 107 |
| 108 void GlCanvas::SetViewSize(int width, int height) { | 108 void GlCanvas::SetViewSize(int width, int height) { |
| 109 DCHECK(width > 0 && height > 0); | 109 DCHECK(width > 0 && height > 0); |
| 110 glViewport(0, 0, width, height); | 110 glViewport(0, 0, width, height); |
| 111 float view_size[2] {width, height}; | 111 float view_size[2]{width, height}; |
| 112 glUniform2fv(view_size_location_, 1, view_size); | 112 glUniform2fv(view_size_location_, 1, view_size); |
| 113 view_size_set_ = true; | 113 view_size_set_ = true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void GlCanvas::DrawTexture(int texture_id, | 116 void GlCanvas::DrawTexture(int texture_id, |
| 117 GLuint texture_handle, | 117 GLuint texture_handle, |
| 118 GLuint vertex_buffer, | 118 GLuint vertex_buffer, |
| 119 float alpha_multiplier) { | 119 float alpha_multiplier) { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 if (!view_size_set_ || !transformation_set_) { | 121 if (!view_size_set_ || !transformation_set_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 139 | 139 |
| 140 int GlCanvas::GetGlVersion() const { | 140 int GlCanvas::GetGlVersion() const { |
| 141 return gl_version_; | 141 return gl_version_; |
| 142 } | 142 } |
| 143 | 143 |
| 144 int GlCanvas::GetMaxTextureSize() const { | 144 int GlCanvas::GetMaxTextureSize() const { |
| 145 return max_texture_size_; | 145 return max_texture_size_; |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace remoting | 148 } // namespace remoting |
| OLD | NEW |