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 #ifndef REMOTING_CLIENT_DISPLAY_GL_CANVAS_H_ | 5 #ifndef REMOTING_CLIENT_DISPLAY_CANVAS_H_ |
6 #define REMOTING_CLIENT_DISPLAY_GL_CANVAS_H_ | 6 #define REMOTING_CLIENT_DISPLAY_CANVAS_H_ |
7 | 7 |
8 #include <array> | 8 #include <array> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "remoting/client/display/sys_opengl.h" | 12 #include "remoting/client/display/sys_opengl.h" |
13 | 13 |
14 namespace remoting { | 14 namespace remoting { |
15 | 15 |
16 // This class holds zoom and pan configurations of the canvas and is used to | 16 // This class holds zoom and pan configurations of the canvas and is used to |
17 // draw textures on the canvas. | 17 // draw textures on the canvas. |
18 // Must be constructed after the OpenGL surface is created and destroyed before | 18 class Canvas { |
19 // the surface is destroyed. | |
20 class GlCanvas { | |
21 public: | 19 public: |
22 // gl_version: version number of the OpenGL ES context. Either 2 or 3. | 20 Canvas(){}; |
23 GlCanvas(int gl_version); | 21 virtual ~Canvas(){}; |
Sergey Ulanov
2017/01/10 23:24:01
remove ; in these two lines
| |
24 | 22 |
25 ~GlCanvas(); | 23 // Clears the frame. |
24 virtual void Clear() = 0; | |
26 | 25 |
27 // Sets the transformation matrix. This matrix defines how the canvas should | 26 // Sets the transformation matrix. This matrix defines how the canvas should |
28 // be shown on the view. | 27 // be shown on the view. |
29 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. | 28 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. |
30 // The matrix will be multiplied with the positions (with projective space, | 29 // The matrix will be multiplied with the positions (with projective space, |
31 // (x, y, 1)) to draw the textures with the right zoom and pan configuration. | 30 // (x, y, 1)) to draw the textures with the right zoom and pan configuration. |
32 // | 31 // |
33 // | m0, m1, m2, | | x | | 32 // | m0, m1, m2, | | x | |
34 // | m3, m4, m5, | * | y | | 33 // | m3, m4, m5, | * | y | |
35 // | m6, m7, m8 | | 1 | | 34 // | m6, m7, m8 | | 1 | |
36 // | 35 // |
37 // For a typical transformation matrix such that m1=m3=m6=m7=0 and m8=1, m0 | 36 // For a typical transformation matrix such that m1=m3=m6=m7=0 and m8=1, m0 |
38 // and m4 defines the scaling factor of the canvas and m2 and m5 defines the | 37 // and m4 defines the scaling factor of the canvas and m2 and m5 defines the |
39 // offset of the upper-left corner in pixel. | 38 // offset of the upper-left corner in pixel. |
40 void SetTransformationMatrix(const std::array<float, 9>& matrix); | 39 virtual void SetTransformationMatrix(const std::array<float, 9>& matrix) = 0; |
41 | 40 |
42 // Sets the size of the view in pixels. | 41 // Sets the size of the view in pixels. |
43 void SetViewSize(int width, int height); | 42 virtual void SetViewSize(int width, int height) = 0; |
44 | 43 |
45 // Draws the texture on the canvas. Nothing will happen if | 44 // Draws the texture on the canvas. Nothing will happen if |
46 // SetNormalizedTransformation() has not been called. | 45 // SetNormalizedTransformation() has not been called. |
47 // vertex_buffer: reference to the 2x4x2 float vertex buffer. | 46 // vertex_buffer: reference to the 2x4x2 float vertex buffer. |
48 // [ four (x, y) position of the texture vertices in pixel | 47 // [ four (x, y) position of the texture vertices in pixel |
49 // with respect to the canvas, | 48 // with respect to the canvas, |
50 // four (x, y) position of the vertices in percentage | 49 // four (x, y) position of the vertices in percentage |
51 // defining the visible area of the texture ] | 50 // defining the visible area of the texture ] |
52 // alpha_multiplier: Will be multiplied with the alpha channel of the texture. | 51 // alpha_multiplier: Will be multiplied with the alpha channel of the texture. |
53 // Passing 1 means no change of the transparency of the | 52 // Passing 1 means no change of the transparency of the |
54 // texture. | 53 // texture. |
55 void DrawTexture(int texture_id, | 54 virtual void DrawTexture(int texture_id, |
56 GLuint texture_handle, | 55 GLuint texture_handle, |
57 GLuint vertex_buffer, | 56 GLuint vertex_buffer, |
Sergey Ulanov
2017/01/10 23:24:01
probably not for this CL: is this interface suppos
nicholss
2017/01/11 18:56:43
Done.
| |
58 float alpha_multiplier); | 57 float alpha_multiplier) = 0; |
59 | 58 |
60 // Returns the version number of current OpenGL ES context. Either 2 or 3. | 59 // Version if applicable to implementation. |
joedow
2017/01/10 22:01:55
Can this method be defined to return a specific va
| |
61 int GetGlVersion() const; | 60 virtual int GetVersion() const = 0; |
62 | 61 |
63 // Returns the maximum texture resolution limitation. Neither the width nor | 62 // Returns the maximum texture resolution limitation. Neither the width nor |
64 // the height of the texture can exceed this limitation. | 63 // the height of the texture can exceed this limitation. |
65 int GetMaxTextureSize() const; | 64 virtual int GetMaxTextureSize() const = 0; |
65 | |
66 // Intended to be given to a Drawable to draw onto. | |
67 virtual base::WeakPtr<Canvas> GetWeakPtr() = 0; | |
66 | 68 |
67 private: | 69 private: |
68 int gl_version_; | 70 DISALLOW_COPY_AND_ASSIGN(Canvas); |
69 | |
70 int max_texture_size_ = 0; | |
71 bool transformation_set_ = false; | |
72 bool view_size_set_ = false; | |
73 | |
74 // Handles. | |
75 GLuint vertex_shader_; | |
76 GLuint fragment_shader_; | |
77 GLuint program_; | |
78 | |
79 // Locations of the corresponding shader attributes. | |
80 GLuint transform_location_; | |
81 GLuint view_size_location_; | |
82 GLuint texture_location_; | |
83 GLuint alpha_multiplier_location_; | |
84 GLuint position_location_; | |
85 GLuint tex_cord_location_; | |
86 | |
87 base::ThreadChecker thread_checker_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(GlCanvas); | |
90 }; | 71 }; |
91 | 72 |
92 } // namespace remoting | 73 } // namespace remoting |
93 | 74 |
94 #endif // REMOTING_CLIENT_DISPLAY_GL_CANVAS_H_ | 75 #endif // REMOTING_CLIENT_DISPLAY_CANVAS_H_ |
OLD | NEW |