Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ | |
| 6 #define REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "remoting/client/sys_opengl.h" | |
| 11 | |
| 12 namespace remoting { | |
| 13 | |
| 14 // This class holds zoom and pan configurations of the canvas and is used to | |
| 15 // draw textures on the canvas. | |
| 16 // Must be constructed after the OpenGL surface is created and destroyed before | |
| 17 // the surface is destroyed. | |
| 18 // | |
| 19 // Coordinates to be used for GlCanvas should be normalized texture coordinates. | |
| 20 // In the view of a point on the canvas, the canvas has width 1 and height 1, | |
| 21 // with the origin at the upper-left corner of the canvas. | |
| 22 class GlCanvas { | |
| 23 public: | |
| 24 // gl_version: version number of the OpenGL ES context. Either 2 or 3. | |
| 25 GlCanvas(int gl_version); | |
| 26 | |
| 27 ~GlCanvas(); | |
| 28 | |
| 29 // Sets the normalized transformation matrix. This matrix defines how the | |
| 30 // canvas should be shown on the view. | |
| 31 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. | |
| 32 // The matrix will be multiplied with the positions (with projective space, | |
| 33 // (x, y, 1)) to draw the textures with the right zoom and pan configuration. | |
| 34 // | |
| 35 // | m0, m1, m2, | | x | | |
| 36 // | m3, m4, m5, | * | y | | |
| 37 // | m6, m7, m8 | | 1 | | |
| 38 // | |
| 39 // For a typical transformation matrix such that m1=m3=m6=m7=0 and m8=1, m0 | |
| 40 // and m4 defines the ratio of canvas width or height over view width or | |
| 41 // height. m2 and m5 defines the offset of the upper-left corner in percentage | |
| 42 // of the view's width or height. An identity matrix will stretch the canvas | |
| 43 // to fit the whole view. | |
| 44 void SetNormalizedTransformation(const float* matrix); | |
|
Sergey Ulanov
2016/07/09 01:01:20
nit: would be more typesafe to use std::array<floa
Yuwei
2016/07/09 01:21:24
Just curious will there be performance drawback co
Yuwei
2016/07/11 22:38:23
Done. Also use std::array everywhere else.
Sergey Ulanov
2016/07/13 04:42:11
no, as long as it's passed by reference or pointer
Yuwei
2016/07/13 18:14:16
Acknowledged.
| |
| 45 | |
| 46 // Draws the texture on the canvas. Nothing will happen if | |
| 47 // SetNormalizedTransformation() has not been called. | |
| 48 // vertex_buffer: reference to the 2x4x2 float vertex buffer. | |
| 49 // [ four (x, y) normalized vertex positions on the canvas, | |
| 50 // four (x, y) vertex positions to define the visible area ] | |
| 51 void DrawTexture(int texture_id, GLuint texture_handle, GLuint vertex_buffer); | |
| 52 | |
| 53 // Returns the version number of current OpenGL ES context. Either 2 or 3. | |
| 54 int GetGlVersion() const; | |
| 55 | |
| 56 private: | |
| 57 int gl_version_; | |
| 58 | |
| 59 // True IFF the transformation has been set. | |
| 60 bool transformation_set_ = false; | |
| 61 | |
| 62 // Handles. | |
| 63 GLuint vertex_shader_; | |
| 64 GLuint fragment_shader_; | |
| 65 GLuint program_; | |
| 66 | |
| 67 // Locations of the corresponding shader attributes. | |
| 68 GLuint transform_location_; | |
| 69 GLuint texture_location_; | |
| 70 GLuint position_location_; | |
| 71 GLuint tex_cord_location_; | |
| 72 | |
| 73 base::ThreadChecker thread_checker_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(GlCanvas); | |
| 76 }; | |
| 77 | |
| 78 } // namespace remoting | |
| 79 | |
| 80 #endif // REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ | |
| OLD | NEW |