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

Side by Side Diff: remoting/client/gl_canvas.h

Issue 2591363002: Adding drawable to CRD andorid and iOS gl rendering pipeline. (Closed)
Patch Set: Minor cleanup of an unused const. Created 3 years, 12 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 #ifndef REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ 5 #ifndef REMOTING_CLIENT_OPENGL_GL_CANVAS_H_
6 #define REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ 6 #define REMOTING_CLIENT_OPENGL_GL_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/threading/thread_checker.h"
12 #include "remoting/client/sys_opengl.h" 12 #include "remoting/client/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 // Must be constructed after the OpenGL surface is created and destroyed before
19 // the surface is destroyed. 19 // the surface is destroyed.
20 class GlCanvas { 20 class GlCanvas {
21 public: 21 public:
22 // gl_version: version number of the OpenGL ES context. Either 2 or 3. 22 // gl_version: version number of the OpenGL ES context. Either 2 or 3.
23 GlCanvas(int gl_version); 23 GlCanvas(int gl_version);
24 24
25 ~GlCanvas(); 25 virtual ~GlCanvas();
26 26
27 // Sets the transformation matrix. This matrix defines how the canvas should 27 // Sets the transformation matrix. This matrix defines how the canvas should
28 // be shown on the view. 28 // be shown on the view.
29 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. 29 // 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, 30 // 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. 31 // (x, y, 1)) to draw the textures with the right zoom and pan configuration.
32 // 32 //
33 // | m0, m1, m2, | | x | 33 // | m0, m1, m2, | | x |
34 // | m3, m4, m5, | * | y | 34 // | m3, m4, m5, | * | y |
35 // | m6, m7, m8 | | 1 | 35 // | m6, m7, m8 | | 1 |
36 // 36 //
37 // For a typical transformation matrix such that m1=m3=m6=m7=0 and m8=1, m0 37 // 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 38 // and m4 defines the scaling factor of the canvas and m2 and m5 defines the
39 // offset of the upper-left corner in pixel. 39 // offset of the upper-left corner in pixel.
40 void SetTransformationMatrix(const std::array<float, 9>& matrix); 40 void SetTransformationMatrix(const std::array<float, 9>& matrix);
41 41
42 // Sets the size of the view in pixels. 42 // Sets the size of the view in pixels.
43 void SetViewSize(int width, int height); 43 void SetViewSize(int width, int height);
44 44
45 // Clears the frame.
46 virtual void Clear();
47
45 // Draws the texture on the canvas. Nothing will happen if 48 // Draws the texture on the canvas. Nothing will happen if
46 // SetNormalizedTransformation() has not been called. 49 // SetNormalizedTransformation() has not been called.
47 // vertex_buffer: reference to the 2x4x2 float vertex buffer. 50 // vertex_buffer: reference to the 2x4x2 float vertex buffer.
48 // [ four (x, y) position of the texture vertices in pixel 51 // [ four (x, y) position of the texture vertices in pixel
49 // with respect to the canvas, 52 // with respect to the canvas,
50 // four (x, y) position of the vertices in percentage 53 // four (x, y) position of the vertices in percentage
51 // defining the visible area of the texture ] 54 // defining the visible area of the texture ]
52 // alpha_multiplier: Will be multiplied with the alpha channel of the texture. 55 // alpha_multiplier: Will be multiplied with the alpha channel of the texture.
53 // Passing 1 means no change of the transparency of the 56 // Passing 1 means no change of the transparency of the
54 // texture. 57 // texture.
55 void DrawTexture(int texture_id, 58 void DrawTexture(int texture_id,
56 GLuint texture_handle, 59 GLuint texture_handle,
57 GLuint vertex_buffer, 60 GLuint vertex_buffer,
58 float alpha_multiplier); 61 float alpha_multiplier);
59 62
60 // Returns the version number of current OpenGL ES context. Either 2 or 3. 63 // Returns the version number of current OpenGL ES context. Either 2 or 3.
61 int GetGlVersion() const; 64 int GetGlVersion() const;
62 65
63 // Returns the maximum texture resolution limitation. Neither the width nor 66 // Returns the maximum texture resolution limitation. Neither the width nor
64 // the height of the texture can exceed this limitation. 67 // the height of the texture can exceed this limitation.
65 int GetMaxTextureSize() const; 68 int GetMaxTextureSize() const;
66 69
70 static GlCanvas* CreateGlCanvas(int gl_version);
joedow 2016/12/22 19:18:09 If you want the caller to own the instance, the ex
nicholss 2017/01/09 18:50:24 good call. Changing to return a std::unique_prt.
71
67 private: 72 private:
73 friend class FakeGlCanvas;
74 GlCanvas();
68 int gl_version_; 75 int gl_version_;
69 76
70 int max_texture_size_ = 0; 77 int max_texture_size_ = 0;
71 bool transformation_set_ = false; 78 bool transformation_set_ = false;
72 bool view_size_set_ = false; 79 bool view_size_set_ = false;
73 80
74 // Handles. 81 // Handles.
75 GLuint vertex_shader_; 82 GLuint vertex_shader_;
76 GLuint fragment_shader_; 83 GLuint fragment_shader_;
77 GLuint program_; 84 GLuint program_;
78 85
79 // Locations of the corresponding shader attributes. 86 // Locations of the corresponding shader attributes.
80 GLuint transform_location_; 87 GLuint transform_location_;
81 GLuint view_size_location_; 88 GLuint view_size_location_;
82 GLuint texture_location_; 89 GLuint texture_location_;
83 GLuint alpha_multiplier_location_; 90 GLuint alpha_multiplier_location_;
84 GLuint position_location_; 91 GLuint position_location_;
85 GLuint tex_cord_location_; 92 GLuint tex_cord_location_;
86 93
94 bool gl_constructed_;
joedow 2016/12/22 00:29:02 You should use inline inits for primitives instead
nicholss 2017/01/09 18:50:24 this was removed and replaced with the use of an i
95
87 base::ThreadChecker thread_checker_; 96 base::ThreadChecker thread_checker_;
88 97
89 DISALLOW_COPY_AND_ASSIGN(GlCanvas); 98 DISALLOW_COPY_AND_ASSIGN(GlCanvas);
90 }; 99 };
91 100
101 class FakeGlCanvas : public GlCanvas {
Yuwei 2016/12/21 23:41:59 Is this just for testing? I think it will be clear
joedow 2016/12/22 00:29:02 This should go into a separate file, most of the f
nicholss 2016/12/22 16:21:41 This was added to support testing that the draw me
Yuwei 2016/12/22 19:01:10 We do sometimes use interface to make things testa
joedow 2016/12/22 19:18:09 We separate prod and test code routinely. If you
nicholss 2017/01/09 18:50:24 Went ahead and created the interface.
102 public:
103 FakeGlCanvas() {}
104
105 ~FakeGlCanvas() override {}
106 void SetTransformationMatrix(const std::array<float, 9>& matrix) {}
107
108 void SetViewSize(int width, int height) {}
109
110 void Clear() override {}
111
112 void DrawTexture(int texture_id,
113 GLuint texture_handle,
114 GLuint vertex_buffer,
115 float alpha_multiplier) {}
116
117 int GetGlVersion() const { return -1; }
118
119 int GetMaxTextureSize() const { return 0; }
120
121 DISALLOW_COPY_AND_ASSIGN(FakeGlCanvas);
122 };
123
92 } // namespace remoting 124 } // namespace remoting
93 125
94 #endif // REMOTING_CLIENT_OPENGL_GL_CANVAS_H_ 126 #endif // REMOTING_CLIENT_OPENGL_GL_CANVAS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698