OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ash/display/root_window_transformers.h" | 5 #include "ash/display/root_window_transformers.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/host/root_window_transformer.h" | 10 #include "ash/host/root_window_transformer.h" |
11 #include "ash/magnifier/magnification_controller.h" | 11 #include "ash/magnifier/magnification_controller.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/utility/transformer_util.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "third_party/skia/include/core/SkMatrix44.h" | |
15 #include "ui/aura/window_event_dispatcher.h" | |
16 #include "ui/base/class_property.h" | |
17 #include "ui/compositor/dip_util.h" | 15 #include "ui/compositor/dip_util.h" |
18 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
19 #include "ui/display/manager/display_manager.h" | 17 #include "ui/display/manager/display_manager.h" |
20 #include "ui/display/manager/managed_display_info.h" | |
21 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
22 #include "ui/gfx/geometry/insets.h" | 19 #include "ui/gfx/geometry/insets.h" |
23 #include "ui/gfx/geometry/size_conversions.h" | 20 #include "ui/gfx/geometry/size_conversions.h" |
24 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
25 #include "ui/gfx/transform.h" | |
26 | |
27 DECLARE_UI_CLASS_PROPERTY_TYPE(display::Display::Rotation); | |
28 | 22 |
29 namespace ash { | 23 namespace ash { |
30 namespace { | 24 namespace { |
31 | 25 |
32 #if defined(OS_WIN) | |
33 DEFINE_UI_CLASS_PROPERTY_KEY(display::Display::Rotation, | |
34 kRotationPropertyKey, | |
35 display::Display::ROTATE_0); | |
36 #endif | |
37 | |
38 // Round near zero value to zero. | |
39 void RoundNearZero(gfx::Transform* transform) { | |
40 const float kEpsilon = 0.001f; | |
41 SkMatrix44& matrix = transform->matrix(); | |
42 for (int x = 0; x < 4; ++x) { | |
43 for (int y = 0; y < 4; ++y) { | |
44 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) | |
45 matrix.set(x, y, SkFloatToMScalar(0.0f)); | |
46 } | |
47 } | |
48 } | |
49 | |
50 // TODO(oshima): Transformers should be able to adjust itself | 26 // TODO(oshima): Transformers should be able to adjust itself |
51 // when the device scale factor is changed, instead of | 27 // when the device scale factor is changed, instead of |
52 // precalculating the transform using fixed value. | 28 // precalculating the transform using fixed value. |
53 | 29 |
54 gfx::Transform CreateRotationTransform(aura::Window* root_window, | 30 // Creates rotation transform for |root_window| to |new_rotation|. This will |
55 const display::Display& display) { | 31 // call |CreateRotationTransform()|, the |old_rotation| will implicitly be |
| 32 // |display::Display::ROTATE_0|. |
| 33 gfx::Transform CreateRootWindowRotationTransform( |
| 34 aura::Window* root_window, |
| 35 const display::Display& display) { |
56 display::ManagedDisplayInfo info = | 36 display::ManagedDisplayInfo info = |
57 Shell::Get()->display_manager()->GetDisplayInfo(display.id()); | 37 Shell::Get()->display_manager()->GetDisplayInfo(display.id()); |
58 | 38 return CreateRotationTransform(display::Display::ROTATE_0, |
59 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) | 39 info.GetActiveRotation(), display); |
60 #if defined(OS_WIN) | |
61 // Windows 8 bots refused to resize the host window, and | |
62 // updating the transform results in incorrectly resizing | |
63 // the root window. Don't apply the transform unless | |
64 // necessary so that unit tests pass on win8 bots. | |
65 if (info.GetActiveRotation() == | |
66 root_window->GetProperty(kRotationPropertyKey)) { | |
67 return gfx::Transform(); | |
68 } | |
69 root_window->SetProperty(kRotationPropertyKey, info.GetActiveRotation()); | |
70 #endif | |
71 | |
72 gfx::Transform rotate; | |
73 // The origin is (0, 0), so the translate width/height must be reduced by | |
74 // 1 pixel. | |
75 float one_pixel = 1.0f / display.device_scale_factor(); | |
76 switch (info.GetActiveRotation()) { | |
77 case display::Display::ROTATE_0: | |
78 break; | |
79 case display::Display::ROTATE_90: | |
80 rotate.Translate(display.bounds().height() - one_pixel, 0); | |
81 rotate.Rotate(90); | |
82 break; | |
83 case display::Display::ROTATE_270: | |
84 rotate.Translate(0, display.bounds().width() - one_pixel); | |
85 rotate.Rotate(270); | |
86 break; | |
87 case display::Display::ROTATE_180: | |
88 rotate.Translate(display.bounds().width() - one_pixel, | |
89 display.bounds().height() - one_pixel); | |
90 rotate.Rotate(180); | |
91 break; | |
92 } | |
93 | |
94 RoundNearZero(&rotate); | |
95 return rotate; | |
96 } | 40 } |
97 | 41 |
98 gfx::Transform CreateMagnifierTransform(aura::Window* root_window) { | 42 gfx::Transform CreateMagnifierTransform(aura::Window* root_window) { |
99 MagnificationController* magnifier = Shell::Get()->magnification_controller(); | 43 MagnificationController* magnifier = Shell::Get()->magnification_controller(); |
100 float magnifier_scale = 1.f; | 44 float magnifier_scale = 1.f; |
101 gfx::Point magnifier_offset; | 45 gfx::Point magnifier_offset; |
102 if (magnifier && magnifier->IsEnabled()) { | 46 if (magnifier && magnifier->IsEnabled()) { |
103 magnifier_scale = magnifier->GetScale(); | 47 magnifier_scale = magnifier->GetScale(); |
104 magnifier_offset = magnifier->GetWindowPosition(); | 48 magnifier_offset = magnifier->GetWindowPosition(); |
105 } | 49 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 : root_window_(root) { | 83 : root_window_(root) { |
140 display::DisplayManager* display_manager = Shell::Get()->display_manager(); | 84 display::DisplayManager* display_manager = Shell::Get()->display_manager(); |
141 display::ManagedDisplayInfo info = | 85 display::ManagedDisplayInfo info = |
142 display_manager->GetDisplayInfo(display.id()); | 86 display_manager->GetDisplayInfo(display.id()); |
143 host_insets_ = info.GetOverscanInsetsInPixel(); | 87 host_insets_ = info.GetOverscanInsetsInPixel(); |
144 root_window_ui_scale_ = info.GetEffectiveUIScale(); | 88 root_window_ui_scale_ = info.GetEffectiveUIScale(); |
145 root_window_bounds_transform_ = | 89 root_window_bounds_transform_ = |
146 CreateInsetsAndScaleTransform(host_insets_, | 90 CreateInsetsAndScaleTransform(host_insets_, |
147 display.device_scale_factor(), | 91 display.device_scale_factor(), |
148 root_window_ui_scale_) * | 92 root_window_ui_scale_) * |
149 CreateRotationTransform(root, display); | 93 CreateRootWindowRotationTransform(root, display); |
150 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 94 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
151 switches::kAshEnableMirroredScreen)) { | 95 switches::kAshEnableMirroredScreen)) { |
152 // Apply the tranform that flips the screen image horizontally so that | 96 // Apply the tranform that flips the screen image horizontally so that |
153 // the screen looks normal when reflected on a mirror. | 97 // the screen looks normal when reflected on a mirror. |
154 root_window_bounds_transform_ = | 98 root_window_bounds_transform_ = |
155 root_window_bounds_transform_ * CreateMirrorTransform(display); | 99 root_window_bounds_transform_ * CreateMirrorTransform(display); |
156 } | 100 } |
157 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); | 101 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); |
158 | 102 |
159 CHECK(transform_.GetInverse(&invert_transform_)); | 103 CHECK(transform_.GetInverse(&invert_transform_)); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 mirror_display_info); | 268 mirror_display_info); |
325 } | 269 } |
326 | 270 |
327 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop( | 271 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop( |
328 const gfx::Rect& screen_bounds, | 272 const gfx::Rect& screen_bounds, |
329 const display::Display& display) { | 273 const display::Display& display) { |
330 return new PartialBoundsRootWindowTransformer(screen_bounds, display); | 274 return new PartialBoundsRootWindowTransformer(screen_bounds, display); |
331 } | 275 } |
332 | 276 |
333 } // namespace ash | 277 } // namespace ash |
OLD | NEW |