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

Side by Side Diff: remoting/client/gl_renderer_core.cc

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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/memory/ptr_util.h"
7 #include "remoting/client/gl_canvas.h"
8 #include "remoting/client/gl_cursor.h"
9 #include "remoting/client/gl_cursor_feedback.h"
10 #include "remoting/client/gl_desktop.h"
11 #include "remoting/client/gl_math.h"
12 #include "remoting/client/gl_renderer_core.h"
13 #include "remoting/client/sys_opengl.h"
14 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
15
16 namespace remoting {
17
18 namespace {
19
20 class GlRendererCoreImpl : public GlRendererCore {
21 public:
22 GlRendererCoreImpl();
23 ~GlRendererCoreImpl() override;
24 void CreateCanvas(int gl_version) override;
25 void DestroyCanvas() override;
26 bool DrawFrame() override;
27 void SetPixelTransformation(const std::array<float, 9>& matrix) override;
28 void MoveCursor(int x, int y) override;
29 void StartFeedbackAnimation(int x, int y, float diameter) override;
30 void SetCursorVisibility(bool visible) override;
31 void SetDesktopFrame(const webrtc::DesktopFrame& frame) override;
32 void SetCursorShape(const protocol::CursorShapeInfo& shape) override;
33 void SetViewSize(int width, int height) override;
34 void SetCanvasSize(int width, int height) override;
35 int GetCanvasWidth() const override { return canvas_width_; }
36 int GetCanvasHeight() const override { return canvas_height_; }
37
38 private:
39 std::unique_ptr<GlCanvas> canvas_;
40
41 GlCursor cursor_;
42 GlCursorFeedback cursor_feedback_;
43 GlDesktop desktop_;
44
45 int view_width_ = 0;
46 int view_height_ = 0;
47 int canvas_width_ = 0;
48 int canvas_height_ = 0;
49 DISALLOW_COPY_AND_ASSIGN(GlRendererCoreImpl);
50 };
51
52 GlRendererCoreImpl::GlRendererCoreImpl() {}
53
54 GlRendererCoreImpl::~GlRendererCoreImpl() {}
55
56 void GlRendererCoreImpl::CreateCanvas(int gl_version) {
57 // Set the background clear color to black.
58 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
59 canvas_.reset(new GlCanvas(gl_version));
60 desktop_.SetCanvas(canvas_.get());
61 cursor_.SetCanvas(canvas_.get());
62 cursor_feedback_.SetCanvas(canvas_.get());
63 }
64
65 void GlRendererCoreImpl::DestroyCanvas() {
66 cursor_feedback_.SetCanvas(nullptr);
67 cursor_.SetCanvas(nullptr);
68 desktop_.SetCanvas(nullptr);
69 canvas_.reset();
70 }
71
72 bool GlRendererCoreImpl::DrawFrame() {
73 glClear(GL_COLOR_BUFFER_BIT);
74 desktop_.Draw();
75 cursor_.Draw();
76 return cursor_feedback_.Draw();
77 }
78
79 void GlRendererCoreImpl::SetPixelTransformation(
80 const std::array<float, 9>& matrix) {
81 std::array<float, 9> normalized_matrix = matrix;
82 NormalizeTransformationMatrix(view_width_, view_height_, canvas_width_,
83 canvas_height_, &normalized_matrix);
84 canvas_->SetNormalizedTransformation(normalized_matrix);
85 }
86
87 void GlRendererCoreImpl::MoveCursor(int x, int y) {
88 cursor_.SetCursorPosition(x, y);
89 }
90
91 void GlRendererCoreImpl::StartFeedbackAnimation(int x, int y, float diameter) {
92 cursor_feedback_.StartAnimation(static_cast<float>(x) / canvas_width_,
93 static_cast<float>(y) / canvas_height_,
94 diameter / canvas_width_,
95 diameter / canvas_height_);
96 }
97
98 void GlRendererCoreImpl::SetCursorVisibility(bool visible) {
99 cursor_.SetCursorVisible(visible);
100 }
101
102 void GlRendererCoreImpl::SetDesktopFrame(const webrtc::DesktopFrame& frame) {
103 desktop_.SetVideoFrame(std::move(frame));
104 }
105
106 void GlRendererCoreImpl::SetCursorShape(
107 const protocol::CursorShapeInfo& shape) {
108 cursor_.SetCursorShape(shape);
109 }
110
111 void GlRendererCoreImpl::SetViewSize(int width, int height) {
112 glViewport(0, 0, width, height);
113 view_width_ = width;
114 view_height_ = height;
115 }
116
117 void GlRendererCoreImpl::SetCanvasSize(int width, int height) {
118 canvas_width_ = width;
119 canvas_height_ = height;
120 cursor_.SetCanvasSize(width, height);
121 }
122
123 } // namespace
124
125 // static
126 std::unique_ptr<GlRendererCore> GlRendererCore::CreateCore() {
127 return base::WrapUnique(new GlRendererCoreImpl());
128 }
129
130 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698