Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/host/chromeos/pixel_rotator.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "ui/aura/window_tree_host.h" | |
| 9 #include "ui/compositor/dip_util.h" | |
| 10 | |
| 11 namespace remoting { | |
| 12 | |
| 13 PixelRotator::PixelRotator() | |
| 14 : 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.
| |
| 15 root_window_ = ash::Shell::GetPrimaryRootWindow(); | |
| 16 root_window_->AddObserver(this); | |
| 17 } | |
| 18 | |
| 19 PixelRotator::~PixelRotator() { | |
| 20 root_window_->RemoveObserver(this); | |
| 21 } | |
| 22 | |
| 23 void PixelRotator::OnWindowTransformed(aura::Window* window) { | |
| 24 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.
| |
| 25 return; | |
| 26 } | |
| 27 | |
| 28 ui::Layer* layer = root_window_->layer(); | |
| 29 float scale = ui::GetDeviceScaleFactor(layer); | |
| 30 | |
| 31 // |layer->transform()| returns a transform comprising a rotation and a | |
| 32 // 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.
| |
| 33 // DIPs, apply it, then switch from DIPs back to device pixels. | |
| 34 gfx::Transform rotation = layer->transform(); | |
| 35 gfx::Transform inverse_rotation; | |
| 36 gfx::Transform to_device_pixels; | |
| 37 gfx::Transform to_dip; | |
| 38 | |
| 39 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.
| |
| 40 to_device_pixels.Scale(scale, scale); | |
| 41 to_dip.Scale(1 / scale, 1 / scale); | |
| 42 | |
| 43 // Matrix transformations are applied from right to left. See annotations. | |
| 44 // (3) (2) (1) | |
| 45 transform_ = to_device_pixels * rotation * to_dip; | |
| 46 inverse_ = to_device_pixels * inverse_rotation * to_dip; | |
| 47 } | |
| 48 | |
| 49 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.
| |
| 50 gfx::Point3F screen_location(window_location); | |
| 51 transform_.TransformPoint(&screen_location); | |
| 52 return screen_location.AsPointF(); | |
| 53 } | |
| 54 | |
| 55 gfx::PointF PixelRotator::FromScreenPixel(const gfx::PointF& screen_location) { | |
| 56 gfx::Point3F window_location(screen_location); | |
| 57 inverse_.TransformPoint(&window_location); | |
| 58 return window_location.AsPointF(); | |
| 59 } | |
| 60 | |
| 61 } // namespace remoting | |
| OLD | NEW |