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

Side by Side Diff: remoting/host/chromeos/point_transformer.cc

Issue 1712343004: Respect display rotation on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use GetTargetTransform() Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "remoting/host/chromeos/point_transformer.h" 5 #include "remoting/host/chromeos/point_transformer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ui/aura/window_tree_host.h" 8 #include "ui/aura/window_tree_host.h"
9 #include "ui/compositor/dip_util.h" 9 #include "ui/compositor/dip_util.h"
10 10
11 namespace remoting { 11 namespace remoting {
12 12
13 PointTransformer::PointTransformer() { 13 PointTransformer::PointTransformer() {
14 root_window_ = ash::Shell::GetPrimaryRootWindow(); 14 root_window_ = ash::Shell::GetPrimaryRootWindow();
15 root_window_->AddObserver(this); 15 root_window_->AddObserver(this);
16 // Set the initial display rotation.
17 OnWindowTransformed(root_window_);
16 } 18 }
17 19
18 PointTransformer::~PointTransformer() { 20 PointTransformer::~PointTransformer() {
19 root_window_->RemoveObserver(this); 21 root_window_->RemoveObserver(this);
20 } 22 }
21 23
22 void PointTransformer::OnWindowTransformed(aura::Window* window) { 24 void PointTransformer::OnWindowTransformed(aura::Window* window) {
23 CHECK_EQ(window, root_window_); 25 CHECK_EQ(window, root_window_);
24 26
25 ui::Layer* layer = root_window_->layer(); 27 ui::Layer* layer = root_window_->layer();
26 float scale = ui::GetDeviceScaleFactor(layer); 28 float scale = ui::GetDeviceScaleFactor(layer);
27 29
28 // |layer->transform()| returns a transform comprising a rotation and a 30 // Use GetTargetTransform() instead of transform() as the layer may be
29 // translation, but in DIPs, so we need to switch device pixels to 31 // animating. GetTargetTransform() returns a transform comprising a rotation
30 // DIPs, apply it, then switch from DIPs back to device pixels. 32 // and a translation, but in DIPs, so we need to switch device pixels to DIPs,
31 gfx::Transform rotation = layer->transform(); 33 // apply it, then switch from DIPs back to device pixels.
34 gfx::Transform rotation = layer->GetTargetTransform();
32 gfx::Transform inverse_rotation; 35 gfx::Transform inverse_rotation;
33 gfx::Transform to_device_pixels; 36 gfx::Transform to_device_pixels;
34 gfx::Transform to_dip; 37 gfx::Transform to_dip;
35 38
36 CHECK(!rotation.GetInverse(&inverse_rotation)) 39 CHECK(rotation.GetInverse(&inverse_rotation))
37 << "Cannot inverse the root transform." << rotation.ToString(); 40 << "Cannot inverse the root transform." << rotation.ToString();
38 41
39 to_device_pixels.Scale(scale, scale); 42 to_device_pixels.Scale(scale, scale);
40 to_dip.Scale(1 / scale, 1 / scale); 43 to_dip.Scale(1 / scale, 1 / scale);
41 44
42 // Matrix transformations are applied from right to left. See annotations. 45 // Matrix transformations are applied from right to left. See annotations.
43 // (3) (2) (1) 46 // (3) (2) (1)
44 root_to_screen_ = to_device_pixels * rotation * to_dip; 47 root_to_screen_ = to_device_pixels * rotation * to_dip;
45 screen_to_root_ = to_device_pixels * inverse_rotation * to_dip; 48 screen_to_root_ = to_device_pixels * inverse_rotation * to_dip;
46 } 49 }
47 50
48 gfx::PointF PointTransformer::ToScreenCoordinates( 51 gfx::PointF PointTransformer::ToScreenCoordinates(
49 const gfx::PointF& root_location) { 52 const gfx::PointF& root_location) {
50 gfx::Point3F screen_location(root_location); 53 gfx::Point3F screen_location(root_location);
51 root_to_screen_.TransformPoint(&screen_location); 54 root_to_screen_.TransformPoint(&screen_location);
52 return screen_location.AsPointF(); 55 return screen_location.AsPointF();
53 } 56 }
54 57
55 gfx::PointF PointTransformer::FromScreenCoordinates( 58 gfx::PointF PointTransformer::FromScreenCoordinates(
56 const gfx::PointF& screen_location) { 59 const gfx::PointF& screen_location) {
57 gfx::Point3F root_location(screen_location); 60 gfx::Point3F root_location(screen_location);
58 screen_to_root_.TransformPoint(&root_location); 61 screen_to_root_.TransformPoint(&root_location);
59 return root_location.AsPointF(); 62 return root_location.AsPointF();
60 } 63 }
61 64
62 } // namespace remoting 65 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698