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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: remoting/client/gl_renderer_core.cc
diff --git a/remoting/client/gl_renderer_core.cc b/remoting/client/gl_renderer_core.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a4a51aea4589b24662cf35c42a335a32512176bc
--- /dev/null
+++ b/remoting/client/gl_renderer_core.cc
@@ -0,0 +1,130 @@
+// 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.
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "remoting/client/gl_canvas.h"
+#include "remoting/client/gl_cursor.h"
+#include "remoting/client/gl_cursor_feedback.h"
+#include "remoting/client/gl_desktop.h"
+#include "remoting/client/gl_math.h"
+#include "remoting/client/gl_renderer_core.h"
+#include "remoting/client/sys_opengl.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
+
+namespace remoting {
+
+namespace {
+
+class GlRendererCoreImpl : public GlRendererCore {
+ public:
+ GlRendererCoreImpl();
+ ~GlRendererCoreImpl() override;
+ void CreateCanvas(int gl_version) override;
+ void DestroyCanvas() override;
+ bool DrawFrame() override;
+ void SetPixelTransformation(const std::array<float, 9>& matrix) override;
+ void MoveCursor(int x, int y) override;
+ void StartFeedbackAnimation(int x, int y, float diameter) override;
+ void SetCursorVisibility(bool visible) override;
+ void SetDesktopFrame(const webrtc::DesktopFrame& frame) override;
+ void SetCursorShape(const protocol::CursorShapeInfo& shape) override;
+ void SetViewSize(int width, int height) override;
+ void SetCanvasSize(int width, int height) override;
+ int GetCanvasWidth() const override { return canvas_width_; }
+ int GetCanvasHeight() const override { return canvas_height_; }
+
+ private:
+ std::unique_ptr<GlCanvas> canvas_;
+
+ GlCursor cursor_;
+ GlCursorFeedback cursor_feedback_;
+ GlDesktop desktop_;
+
+ int view_width_ = 0;
+ int view_height_ = 0;
+ int canvas_width_ = 0;
+ int canvas_height_ = 0;
+ DISALLOW_COPY_AND_ASSIGN(GlRendererCoreImpl);
+};
+
+GlRendererCoreImpl::GlRendererCoreImpl() {}
+
+GlRendererCoreImpl::~GlRendererCoreImpl() {}
+
+void GlRendererCoreImpl::CreateCanvas(int gl_version) {
+ // Set the background clear color to black.
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ canvas_.reset(new GlCanvas(gl_version));
+ desktop_.SetCanvas(canvas_.get());
+ cursor_.SetCanvas(canvas_.get());
+ cursor_feedback_.SetCanvas(canvas_.get());
+}
+
+void GlRendererCoreImpl::DestroyCanvas() {
+ cursor_feedback_.SetCanvas(nullptr);
+ cursor_.SetCanvas(nullptr);
+ desktop_.SetCanvas(nullptr);
+ canvas_.reset();
+}
+
+bool GlRendererCoreImpl::DrawFrame() {
+ glClear(GL_COLOR_BUFFER_BIT);
+ desktop_.Draw();
+ cursor_.Draw();
+ return cursor_feedback_.Draw();
+}
+
+void GlRendererCoreImpl::SetPixelTransformation(
+ const std::array<float, 9>& matrix) {
+ std::array<float, 9> normalized_matrix = matrix;
+ NormalizeTransformationMatrix(view_width_, view_height_, canvas_width_,
+ canvas_height_, &normalized_matrix);
+ canvas_->SetNormalizedTransformation(normalized_matrix);
+}
+
+void GlRendererCoreImpl::MoveCursor(int x, int y) {
+ cursor_.SetCursorPosition(x, y);
+}
+
+void GlRendererCoreImpl::StartFeedbackAnimation(int x, int y, float diameter) {
+ cursor_feedback_.StartAnimation(static_cast<float>(x) / canvas_width_,
+ static_cast<float>(y) / canvas_height_,
+ diameter / canvas_width_,
+ diameter / canvas_height_);
+}
+
+void GlRendererCoreImpl::SetCursorVisibility(bool visible) {
+ cursor_.SetCursorVisible(visible);
+}
+
+void GlRendererCoreImpl::SetDesktopFrame(const webrtc::DesktopFrame& frame) {
+ desktop_.SetVideoFrame(std::move(frame));
+}
+
+void GlRendererCoreImpl::SetCursorShape(
+ const protocol::CursorShapeInfo& shape) {
+ cursor_.SetCursorShape(shape);
+}
+
+void GlRendererCoreImpl::SetViewSize(int width, int height) {
+ glViewport(0, 0, width, height);
+ view_width_ = width;
+ view_height_ = height;
+}
+
+void GlRendererCoreImpl::SetCanvasSize(int width, int height) {
+ canvas_width_ = width;
+ canvas_height_ = height;
+ cursor_.SetCanvasSize(width, height);
+}
+
+} // namespace
+
+// static
+std::unique_ptr<GlRendererCore> GlRendererCore::CreateCore() {
+ return base::WrapUnique(new GlRendererCoreImpl());
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698