Chromium Code Reviews| Index: remoting/client/gl_renderer.h |
| diff --git a/remoting/client/gl_renderer.h b/remoting/client/gl_renderer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..435ee06fcc5a2d646d173ac286fbb98efb9b3118 |
| --- /dev/null |
| +++ b/remoting/client/gl_renderer.h |
| @@ -0,0 +1,164 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef REMOTING_CLIENT_GL_RENDERER_H_ |
| +#define REMOTING_CLIENT_GL_RENDERER_H_ |
| + |
| +#include <queue> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "remoting/client/gl_cursor.h" |
| +#include "remoting/client/gl_cursor_feedback.h" |
| +#include "remoting/client/gl_desktop.h" |
| +#include "remoting/proto/control.pb.h" |
| + |
| +namespace webrtc { |
| +class DesktopFrame; |
| +} // namespace webrtc |
| + |
| +namespace remoting { |
| + |
| +namespace protocol { |
| +class CursorShapeInfo; |
| +} // namespace protocol |
| + |
| +class GlCanvas; |
| + |
| +// Renders desktop and cursor on the OpenGL surface. Can be created on any |
| +// thread but thereafter must be used and deleted on the same thread (usually |
| +// the display thread. Or any Chromium thread with a task runner attached to |
| +// it) unless otherwise noted. |
| +// The unit of all length arguments is pixel. |
| +class GlRenderer { |
| + public: |
| + // void RenderCallback(const base::Closure& draw_closure) |
|
Sergey Ulanov
2016/07/25 19:34:14
this line looks like commented method declaration.
Yuwei
2016/07/25 19:52:18
Just try to show how the header of the callback wi
|
| + // |
| + // The callback should do preparation before and after rendering and call |
| + // |draw_closure| to draw everything on current OpenGL buffer. You don't need |
| + // to run |draw_closure| if it can't be done when running the RenderCallback. |
| + // For example: |
| + // |
| + // if (!egl_context_established_) { |
| + // return; |
| + // } |
| + // draw_closure.Run(); |
| + // SwapBuffers(); |
| + // ui_task_runner_->PostTask(FROM_HERE, render_done_); |
|
Sergey Ulanov
2016/07/25 19:34:13
What is render_done_ and how is it relevant here?
Yuwei
2016/07/25 19:52:18
Just an example of how the caller may implement th
|
| + // |
| + // |draw_closure| must be run on the display thread. |
| + using RenderCallback = base::Callback<void(const base::Closure&)>; |
|
Sergey Ulanov
2016/07/25 19:34:13
So if I understand correctly the handler is respon
Sergey Ulanov
2016/07/25 19:34:13
add name of the argument for the callback, e.g.
ba
Yuwei
2016/07/26 05:01:43
Obsolete.
Yuwei
2016/07/26 05:01:44
Done.
|
| + |
| + // void SizeCallback(int width, int height) |
|
Sergey Ulanov
2016/07/25 19:34:13
remove this line?
Yuwei
2016/07/26 05:01:44
Obsolete.
|
| + using SizeCallback = base::Callback<void(int, int)>; |
|
Sergey Ulanov
2016/07/25 19:34:13
base::Callback<void(int width, int height)>
Yuwei
2016/07/26 05:01:43
Obsolete.
|
| + |
| + explicit GlRenderer(); |
| + ~GlRenderer(); |
| + |
| + // The render callback can be set on any thread no more than once before |
| + // calling any On* functions. |
| + //|callback| will be run on the display thread whenever the canvas need to be |
| + // redrawn. |
| + void SetRenderCallback(const RenderCallback& callback); |
| + |
| + // Sets the callback to be called when the size of the canvas (desktop frame) |
| + // is changed. The callback can be set on any thread no more than once before |
| + // calling any On* functions. |
| + // |callback| will be run on the display thread. |
| + void SetCanvasSizeChangedCallback(const SizeCallback& callback); |
| + |
| + // Calls |canvas_size_changed_callback_| with the current canvas size. Canvas |
| + // size will be (0, 0) if no desktop frame is received yet. |
| + // Caller can use this function to get the canvas size when the surface is |
| + // recreated. |
| + void RequestCanvasSize(); |
| + |
| + // Sets the pixel based transformation matrix related to the size of the |
| + // canvas. |
| + // 3 by 3 transformation matrix, [ m0, m1, m2, m3, m4, m5, m6, m7, m8 ]. |
| + // |
| + // | m0, m1, m2, | | x | |
| + // | m3, m4, m5, | * | y | |
| + // | m6, m7, m8 | | 1 | |
| + // |
| + // The final size of the canvas will be (m0*canvas_width, m4*canvas_height) |
| + // and the top-left corner will be (m2, m5) in pixel coordinates. |
| + void OnPixelTransformationChanged(std::unique_ptr<std::array<float, 9>> mat); |
| + |
| + void OnCursorMoved(int x, int y); |
| + |
| + void OnCursorInputFeedback(int x, int y, float diameter); |
| + |
| + void OnCursorVisibilityChanged(bool visible); |
| + |
| + // Called when a desktop frame is received. |
| + // The size of the canvas is determined by the dimension of the desktop frame. |
| + // |done| will be queued up and called on the display thread after the actual |
| + // rendering happens. |
| + void OnFrameReceived(std::unique_ptr<webrtc::DesktopFrame> frame, |
| + const base::Closure& done); |
| + |
| + void OnCursorShapeChanged(const protocol::CursorShapeInfo& shape); |
| + |
| + // Called after the EGL/EAGL context is established and the surface is created |
| + // (or recreated). Previous desktop frame and canvas transformation will be |
| + // lost after calling this function. |
| + // Caller must call OnSurfaceDestroyed() before calling this function if the |
| + // surface is recreated. |
| + void OnSurfaceCreated(int gl_version); |
| + |
| + // Sets the size of the view. Called right after OnSurfaceCreated() or |
| + // whenever the view size is changed. |
| + void OnSurfaceChanged(int view_width, int view_height); |
| + |
| + // Called when the surface is destroyed. |
| + void OnSurfaceDestroyed(); |
| + |
| + // Returns the weak pointer to be used on the display thread. |
| + base::WeakPtr<GlRenderer> GetWeakPtr(); |
| + |
| + private: |
| + // Post a rendering task to the task runner of current thread. |
| + // Do nothing if render_callback_ is not set yet or an existing rendering task |
| + // in the queue will cover changes before this function is called. |
| + void RequestRender(); |
| + |
| + // Turns off the |render_scheduled_| flag and runs |render_callback_|. |
| + void OnRender(); |
| + |
| + // Draws out everything on current OpenGL buffer and runs closures in |
| + // |pending_done_callbacks_|. |
| + void OnDrawFrame(); |
| + |
| + RenderCallback render_callback_; |
| + |
| + SizeCallback canvas_size_changed_callback_; |
| + |
| + // Done callbacks from OnFrameReceived. Will all be called once rendering |
| + // takes place. |
| + std::queue<base::Closure> pending_done_callbacks_; |
| + |
| + bool render_scheduled_ = false; |
| + |
| + int view_width_ = 0; |
| + int view_height_ = 0; |
| + int canvas_width_ = 0; |
| + int canvas_height_ = 0; |
| + |
| + std::unique_ptr<GlCanvas> canvas_; |
| + |
| + GlCursor cursor_; |
| + GlCursorFeedback cursor_feedback_; |
| + GlDesktop desktop_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + base::WeakPtr<GlRenderer> weak_ptr_; |
| + base::WeakPtrFactory<GlRenderer> weak_factory_; |
| + DISALLOW_COPY_AND_ASSIGN(GlRenderer); |
|
Sergey Ulanov
2016/07/25 19:34:13
nit: empty line here
Yuwei
2016/07/26 05:01:44
Done.
|
| +}; |
| + |
| +} // namespace remoting |
| +#endif // REMOTING_CLIENT_GL_RENDERER_H_ |
|
Sergey Ulanov
2016/07/25 19:34:13
nit: empty line here
Yuwei
2016/07/26 05:01:44
Done.
|