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

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

Issue 2196493002: [Chromoting] Unit Tests for GlRenderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittest Created 4 years, 4 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_GL_RENDERER_H_ 5 #ifndef REMOTING_CLIENT_GL_RENDERER_H_
6 #define REMOTING_CLIENT_GL_RENDERER_H_ 6 #define REMOTING_CLIENT_GL_RENDERER_H_
7 7
8 #include <array>
8 #include <queue> 9 #include <queue>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
14 #include "remoting/client/gl_cursor.h"
15 #include "remoting/client/gl_cursor_feedback.h"
16 #include "remoting/client/gl_desktop.h"
17 #include "remoting/proto/control.pb.h" 15 #include "remoting/proto/control.pb.h"
18 16
19 namespace webrtc { 17 namespace webrtc {
20 class DesktopFrame; 18 class DesktopFrame;
21 } // namespace webrtc 19 } // namespace webrtc
22 20
23 namespace remoting { 21 namespace remoting {
24 22
25 namespace protocol { 23 namespace protocol {
26 class CursorShapeInfo; 24 class CursorShapeInfo;
27 } // namespace protocol 25 } // namespace protocol
28 26
29 class GlCanvas; 27 class GlCanvas;
30 class GlRendererDelegate; 28 class GlRendererDelegate;
29 class GlRendererCore;
31 30
32 // Renders desktop and cursor on the OpenGL surface. Can be created on any 31 // Renders desktop and cursor on the OpenGL surface. Can be created on any
33 // thread but thereafter must be used and deleted on the same thread (usually 32 // thread but thereafter must be used and deleted on the same thread (usually
34 // the display thread. Or any Chromium thread with a task runner attached to 33 // the display thread. Or any Chromium thread with a task runner attached to
35 // it) unless otherwise noted. 34 // it) unless otherwise noted.
36 // The unit of all length arguments is pixel. 35 // The unit of all length arguments is pixel.
37 class GlRenderer { 36 class GlRenderer {
38 public: 37 public:
39 explicit GlRenderer(); 38 explicit GlRenderer();
39
40 ~GlRenderer(); 40 ~GlRenderer();
41 41
42 // The delegate can be set on any hread no more than once before calling any 42 // The delegate can be set on any hread no more than once before calling any
43 // On* functions. 43 // On* functions.
44 void SetDelegate(base::WeakPtr<GlRendererDelegate> delegate); 44 void SetDelegate(base::WeakPtr<GlRendererDelegate> delegate);
45 45
46 // Notifies the delegate with the current canvas size. Canvas size will be 46 // Notifies the delegate with the current canvas size. Canvas size will be
47 // (0, 0) if no desktop frame is received yet. 47 // (0, 0) if no desktop frame is received yet.
48 // Caller can use this function to get the canvas size when the surface is 48 // Caller can use this function to get the canvas size when the surface is
49 // recreated. 49 // recreated.
50 void RequestCanvasSize(); 50 void RequestCanvasSize();
51 51
52 // Post a rendering task to the task runner of current thread.
53 //
54 // Notice that On* functions will implicitly call RequestRender() so usually
55 // the caller does NOT need to explicitly call this function unless they need
56 // to manually control the render cycle in some special situations.
57 //
58 // Do nothing if render_callback_ is not set yet or an existing rendering task
59 // in the queue will cover changes before this function is called.
60 void RequestRender();
61
52 // Sets the pixel based transformation matrix related to the size of the 62 // Sets the pixel based transformation matrix related to the size of the
53 // canvas. 63 // canvas.
54 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. 64 // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ].
55 // 65 //
56 // | m0, m1, m2, | | x | 66 // | m0, m1, m2, | | x |
57 // | m3, m4, m5, | * | y | 67 // | m3, m4, m5, | * | y |
58 // | m6, m7, m8 | | 1 | 68 // | m6, m7, m8 | | 1 |
59 // 69 //
60 // The final size of the canvas will be (m0*canvas_width, m4*canvas_height) 70 // The final size of the canvas will be (m0*canvas_width, m4*canvas_height)
61 // and the top-left corner will be (m2, m5) in pixel coordinates. 71 // and the top-left corner will be (m2, m5) in pixel coordinates.
(...skipping 25 matching lines...) Expand all
87 // whenever the view size is changed. 97 // whenever the view size is changed.
88 void OnSurfaceChanged(int view_width, int view_height); 98 void OnSurfaceChanged(int view_width, int view_height);
89 99
90 // Called when the surface is destroyed. 100 // Called when the surface is destroyed.
91 void OnSurfaceDestroyed(); 101 void OnSurfaceDestroyed();
92 102
93 // Returns the weak pointer to be used on the display thread. 103 // Returns the weak pointer to be used on the display thread.
94 base::WeakPtr<GlRenderer> GetWeakPtr(); 104 base::WeakPtr<GlRenderer> GetWeakPtr();
95 105
96 private: 106 private:
97 // Post a rendering task to the task runner of current thread.
98 // Do nothing if render_callback_ is not set yet or an existing rendering task
99 // in the queue will cover changes before this function is called.
100 void RequestRender();
101
102 // Draws out everything on current OpenGL buffer and runs closures in 107 // Draws out everything on current OpenGL buffer and runs closures in
103 // |pending_done_callbacks_|. 108 // |pending_done_callbacks_|.
104 // Nothing will be drawn nor the done callbacks will be run if |delegate_| is 109 // Nothing will be drawn nor the done callbacks will be run if |delegate_| is
105 // invalid or !delegate_.CanRenderFrame(). 110 // invalid or !delegate_.CanRenderFrame().
106 void OnRender(); 111 void OnRender();
107 112
113 std::unique_ptr<GlRendererCore> core_;
114
108 base::WeakPtr<GlRendererDelegate> delegate_; 115 base::WeakPtr<GlRendererDelegate> delegate_;
109 116
110 // Done callbacks from OnFrameReceived. Will all be called once rendering 117 // Done callbacks from OnFrameReceived. Will all be called once rendering
111 // takes place. 118 // takes place.
112 std::queue<base::Closure> pending_done_callbacks_; 119 std::queue<base::Closure> pending_done_callbacks_;
113 120
114 bool render_scheduled_ = false; 121 bool render_scheduled_ = false;
115 122
116 int view_width_ = 0;
117 int view_height_ = 0;
118 int canvas_width_ = 0;
119 int canvas_height_ = 0;
120
121 std::unique_ptr<GlCanvas> canvas_;
122
123 GlCursor cursor_;
124 GlCursorFeedback cursor_feedback_;
125 GlDesktop desktop_;
126
127 base::ThreadChecker thread_checker_; 123 base::ThreadChecker thread_checker_;
128 base::WeakPtr<GlRenderer> weak_ptr_; 124 base::WeakPtr<GlRenderer> weak_ptr_;
129 base::WeakPtrFactory<GlRenderer> weak_factory_; 125 base::WeakPtrFactory<GlRenderer> weak_factory_;
130 126
131 DISALLOW_COPY_AND_ASSIGN(GlRenderer); 127 DISALLOW_COPY_AND_ASSIGN(GlRenderer);
132 }; 128 };
133 129
134 } // namespace remoting 130 } // namespace remoting
135 131
136 #endif // REMOTING_CLIENT_GL_RENDERER_H_ 132 #endif // REMOTING_CLIENT_GL_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698