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_RENDERER_H_ | 5 #ifndef REMOTING_CLIENT_DISPLAY_GL_RENDERER_H_ |
6 #define REMOTING_CLIENT_DISPLAY_GL_RENDERER_H_ | 6 #define REMOTING_CLIENT_DISPLAY_GL_RENDERER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <vector> | |
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/display/gl_cursor.h" | 15 #include "remoting/client/display/gl_cursor.h" |
15 #include "remoting/client/display/gl_cursor_feedback.h" | 16 #include "remoting/client/display/gl_cursor_feedback.h" |
16 #include "remoting/client/display/gl_desktop.h" | 17 #include "remoting/client/display/gl_desktop.h" |
17 #include "remoting/proto/control.pb.h" | 18 #include "remoting/proto/control.pb.h" |
18 | 19 |
19 namespace webrtc { | 20 namespace webrtc { |
20 class DesktopFrame; | 21 class DesktopFrame; |
21 } // namespace webrtc | 22 } // namespace webrtc |
22 | 23 |
23 namespace remoting { | 24 namespace remoting { |
24 | 25 |
25 namespace protocol { | 26 namespace protocol { |
26 class CursorShapeInfo; | 27 class CursorShapeInfo; |
27 } // namespace protocol | 28 } // namespace protocol |
28 | 29 |
29 class GlCanvas; | 30 class Canvas; |
30 class GlRendererDelegate; | 31 class GlRendererDelegate; |
31 class GlRendererTest; | 32 class GlRendererTest; |
32 | 33 |
33 // Renders desktop and cursor on the OpenGL surface. Can be created on any | 34 // Renders desktop and cursor on the OpenGL surface. Can be created on any |
34 // thread but thereafter must be used and deleted on the same thread (usually | 35 // thread but thereafter must be used and deleted on the same thread (usually |
35 // the display thread. Or any Chromium thread with a task runner attached to | 36 // the display thread. Or any Chromium thread with a task runner attached to |
36 // it) unless otherwise noted. | 37 // it) unless otherwise noted. |
37 // The unit of all length arguments is pixel. | 38 // The unit of all length arguments is pixel. |
38 class GlRenderer { | 39 class GlRenderer { |
39 public: | 40 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, | 76 void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, |
76 const base::Closure& done); | 77 const base::Closure& done); |
77 | 78 |
78 void OnCursorShapeChanged(const protocol::CursorShapeInfo& shape); | 79 void OnCursorShapeChanged(const protocol::CursorShapeInfo& shape); |
79 | 80 |
80 // Called after the EGL/EAGL context is established and the surface is created | 81 // Called after the EGL/EAGL context is established and the surface is created |
81 // (or recreated). Previous desktop frame and canvas transformation will be | 82 // (or recreated). Previous desktop frame and canvas transformation will be |
82 // lost after calling this function. | 83 // lost after calling this function. |
83 // Caller must call OnSurfaceDestroyed() before calling this function if the | 84 // Caller must call OnSurfaceDestroyed() before calling this function if the |
84 // surface is recreated. | 85 // surface is recreated. |
85 void OnSurfaceCreated(int gl_version); | 86 void OnSurfaceCreated(std::unique_ptr<Canvas> canvas); |
86 | 87 |
87 // Sets the size of the view. Called right after OnSurfaceCreated() or | 88 // Sets the size of the view. Called right after OnSurfaceCreated() or |
88 // whenever the view size is changed. | 89 // whenever the view size is changed. |
89 void OnSurfaceChanged(int view_width, int view_height); | 90 void OnSurfaceChanged(int view_width, int view_height); |
90 | 91 |
91 // Called when the surface is destroyed. | 92 // Called when the surface is destroyed. |
92 void OnSurfaceDestroyed(); | 93 void OnSurfaceDestroyed(); |
93 | 94 |
95 void AddDrawable(base::WeakPtr<Drawable> drawable); | |
96 | |
94 // Returns the weak pointer to be used on the display thread. | 97 // Returns the weak pointer to be used on the display thread. |
95 base::WeakPtr<GlRenderer> GetWeakPtr(); | 98 base::WeakPtr<GlRenderer> GetWeakPtr(); |
96 | 99 |
100 // Convenience method to create a Renderer with standard desktop components. | |
101 static std::unique_ptr<GlRenderer> CreateGlRendererWithDesktop(); | |
102 | |
97 private: | 103 private: |
98 friend class GlRendererTest; | 104 friend class GlRendererTest; |
99 | 105 |
100 // Post a rendering task to the task runner of current thread. | 106 // Post a rendering task to the task runner of current thread. |
101 // Do nothing if render_callback_ is not set yet or an existing rendering task | 107 // Do nothing if render_callback_ is not set yet or an existing rendering task |
102 // in the queue will cover changes before this function is called. | 108 // in the queue will cover changes before this function is called. |
103 void RequestRender(); | 109 void RequestRender(); |
104 | 110 |
105 // Draws out everything on current OpenGL buffer and runs closures in | 111 // Draws out everything on current OpenGL buffer and runs closures in |
106 // |pending_done_callbacks_|. | 112 // |pending_done_callbacks_|. |
107 // Nothing will be drawn nor the done callbacks will be run if |delegate_| is | 113 // Nothing will be drawn nor the done callbacks will be run if |delegate_| is |
108 // invalid or !delegate_.CanRenderFrame(). | 114 // invalid or !delegate_.CanRenderFrame(). |
109 void OnRender(); | 115 void OnRender(); |
110 | 116 |
111 base::WeakPtr<GlRendererDelegate> delegate_; | 117 base::WeakPtr<GlRendererDelegate> delegate_; |
112 | 118 |
113 // Done callbacks from OnFrameReceived. Will all be called once rendering | 119 // Done callbacks from OnFrameReceived. Will all be called once rendering |
114 // takes place. | 120 // takes place. |
115 std::queue<base::Closure> pending_done_callbacks_; | 121 std::queue<base::Closure> pending_done_callbacks_; |
116 | 122 |
117 bool render_scheduled_ = false; | 123 bool render_scheduled_ = false; |
118 | 124 |
119 int canvas_width_ = 0; | 125 int canvas_width_ = 0; |
120 int canvas_height_ = 0; | 126 int canvas_height_ = 0; |
121 | 127 |
122 std::unique_ptr<GlCanvas> canvas_; | 128 std::unique_ptr<Canvas> canvas_; |
123 | 129 |
124 GlCursor cursor_; | 130 GlCursor cursor_; |
125 GlCursorFeedback cursor_feedback_; | 131 GlCursorFeedback cursor_feedback_; |
126 GlDesktop desktop_; | 132 GlDesktop desktop_; |
127 | 133 |
134 std::vector<base::WeakPtr<Drawable>> drawables_; | |
Yuwei
2017/01/09 20:28:52
Is it really more useful to store a WeakPtr instea
nicholss
2017/01/09 20:39:24
I absolutely don't want the renderer to own the dr
Yuwei
2017/01/09 22:41:54
This can still be done if you grab the WeakPtr of
| |
135 | |
128 base::ThreadChecker thread_checker_; | 136 base::ThreadChecker thread_checker_; |
129 base::WeakPtr<GlRenderer> weak_ptr_; | 137 base::WeakPtr<GlRenderer> weak_ptr_; |
130 base::WeakPtrFactory<GlRenderer> weak_factory_; | 138 base::WeakPtrFactory<GlRenderer> weak_factory_; |
131 | 139 |
132 DISALLOW_COPY_AND_ASSIGN(GlRenderer); | 140 DISALLOW_COPY_AND_ASSIGN(GlRenderer); |
133 }; | 141 }; |
134 | 142 |
135 } // namespace remoting | 143 } // namespace remoting |
136 | 144 |
137 #endif // REMOTING_CLIENT_DISPLAY_GL_RENDERER_H_ | 145 #endif // REMOTING_CLIENT_DISPLAY_GL_RENDERER_H_ |
OLD | NEW |