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

Unified Diff: remoting/host/chromeos/pixel_rotator.cc

Issue 756643006: Remote assistance on Chrome OS Part IX - Input injection on Ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Ozone_input_injection
Patch Set: Address wez's feedback Created 6 years 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/host/chromeos/pixel_rotator.cc
diff --git a/remoting/host/chromeos/pixel_rotator.cc b/remoting/host/chromeos/pixel_rotator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6e147609549b375f1c0fefeecfe963aeca4177e1
--- /dev/null
+++ b/remoting/host/chromeos/pixel_rotator.cc
@@ -0,0 +1,61 @@
+// Copyright 2014 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 "remoting/host/chromeos/pixel_rotator.h"
+
+#include "ash/shell.h"
+#include "ui/aura/window_tree_host.h"
+#include "ui/compositor/dip_util.h"
+
+namespace remoting {
+
+PixelRotator::PixelRotator()
+ : root_window_(nullptr) {
Wez 2014/12/06 01:55:16 nit: no need to init to nullptr only to then overw
kelvinp 2014/12/08 18:41:43 Done.
+ root_window_ = ash::Shell::GetPrimaryRootWindow();
+ root_window_->AddObserver(this);
+}
+
+PixelRotator::~PixelRotator() {
+ root_window_->RemoveObserver(this);
+}
+
+void PixelRotator::OnWindowTransformed(aura::Window* window) {
+ if (window != root_window_) {
Wez 2014/12/06 01:55:16 Since you only observed the root window, can you e
kelvinp 2014/12/08 18:41:43 Done.
+ return;
+ }
+
+ ui::Layer* layer = root_window_->layer();
+ float scale = ui::GetDeviceScaleFactor(layer);
+
+ // |layer->transform()| returns a transform comprising a rotation and a
+ // translation, but in DIP, so we need to switch device pixels to
Wez 2014/12/06 01:55:16 DIPs
kelvinp 2014/12/08 18:41:43 Done.
+ // DIPs, apply it, then switch from DIPs back to device pixels.
+ gfx::Transform rotation = layer->transform();
+ gfx::Transform inverse_rotation;
+ gfx::Transform to_device_pixels;
+ gfx::Transform to_dip;
+
+ ignore_result(rotation.GetInverse(&inverse_rotation));
Wez 2014/12/06 01:55:16 Do we really want to ignore the result? Consider s
kelvinp 2014/12/08 18:41:43 Done.
+ to_device_pixels.Scale(scale, scale);
+ to_dip.Scale(1 / scale, 1 / scale);
+
+ // Matrix transformations are applied from right to left. See annotations.
+ // (3) (2) (1)
+ transform_ = to_device_pixels * rotation * to_dip;
+ inverse_ = to_device_pixels * inverse_rotation * to_dip;
+}
+
+gfx::PointF PixelRotator::ToScreenPixel(const gfx::PointF& window_location) {
Wez 2014/12/06 01:55:17 nit: suggest root_location, here and elsewhere; ot
kelvinp 2014/12/08 18:41:44 Done.
+ gfx::Point3F screen_location(window_location);
+ transform_.TransformPoint(&screen_location);
+ return screen_location.AsPointF();
+}
+
+gfx::PointF PixelRotator::FromScreenPixel(const gfx::PointF& screen_location) {
+ gfx::Point3F window_location(screen_location);
+ inverse_.TransformPoint(&window_location);
+ return window_location.AsPointF();
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698