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/common/ash_switches.h" | 9 #include "ash/common/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 "third_party/skia/include/core/SkMatrix44.h" |
15 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
16 #include "ui/base/class_property.h" | 17 #include "ui/base/class_property.h" |
17 #include "ui/compositor/dip_util.h" | 18 #include "ui/compositor/dip_util.h" |
18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
19 #include "ui/display/manager/display_manager.h" | 20 #include "ui/display/manager/display_manager.h" |
20 #include "ui/display/manager/managed_display_info.h" | 21 #include "ui/display/manager/managed_display_info.h" |
21 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" |
22 #include "ui/gfx/geometry/insets.h" | 23 #include "ui/gfx/geometry/insets.h" |
23 #include "ui/gfx/geometry/size_conversions.h" | 24 #include "ui/gfx/geometry/size_conversions.h" |
24 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
25 #include "ui/gfx/transform.h" | |
26 | |
27 DECLARE_UI_CLASS_PROPERTY_TYPE(display::Display::Rotation); | |
28 | 26 |
29 namespace ash { | 27 namespace ash { |
30 namespace { | 28 namespace { |
31 | 29 |
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 | |
51 // when the device scale factor is changed, instead of | |
52 // precalculating the transform using fixed value. | |
53 | |
54 gfx::Transform CreateRotationTransform(aura::Window* root_window, | |
55 const display::Display& display) { | |
56 display::ManagedDisplayInfo info = | |
57 Shell::Get()->display_manager()->GetDisplayInfo(display.id()); | |
58 | |
59 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) | |
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 } | |
97 | |
98 gfx::Transform CreateMagnifierTransform(aura::Window* root_window) { | |
99 MagnificationController* magnifier = Shell::Get()->magnification_controller(); | |
100 float magnifier_scale = 1.f; | |
101 gfx::Point magnifier_offset; | |
102 if (magnifier && magnifier->IsEnabled()) { | |
103 magnifier_scale = magnifier->GetScale(); | |
104 magnifier_offset = magnifier->GetWindowPosition(); | |
105 } | |
106 gfx::Transform transform; | |
107 if (magnifier_scale != 1.f) { | |
108 transform.Scale(magnifier_scale, magnifier_scale); | |
109 transform.Translate(-magnifier_offset.x(), -magnifier_offset.y()); | |
110 } | |
111 return transform; | |
112 } | |
113 | |
114 gfx::Transform CreateInsetsAndScaleTransform(const gfx::Insets& insets, | |
115 float device_scale_factor, | |
116 float ui_scale) { | |
117 gfx::Transform transform; | |
118 if (insets.top() != 0 || insets.left() != 0) { | |
119 float x_offset = insets.left() / device_scale_factor; | |
120 float y_offset = insets.top() / device_scale_factor; | |
121 transform.Translate(x_offset, y_offset); | |
122 } | |
123 float inverted_scale = 1.0f / ui_scale; | |
124 transform.Scale(inverted_scale, inverted_scale); | |
125 return transform; | |
126 } | |
127 | |
128 gfx::Transform CreateMirrorTransform(const display::Display& display) { | |
129 gfx::Transform transform; | |
130 transform.matrix().set3x3(-1, 0, 0, 0, 1, 0, 0, 0, 1); | |
131 transform.Translate(-display.size().width(), 0); | |
132 return transform; | |
133 } | |
134 | |
135 // RootWindowTransformer for ash environment. | 30 // RootWindowTransformer for ash environment. |
136 class AshRootWindowTransformer : public RootWindowTransformer { | 31 class AshRootWindowTransformer : public RootWindowTransformer { |
137 public: | 32 public: |
138 AshRootWindowTransformer(aura::Window* root, const display::Display& display) | 33 AshRootWindowTransformer(aura::Window* root, const display::Display& display) |
139 : root_window_(root) { | 34 : root_window_(root) { |
140 display::DisplayManager* display_manager = Shell::Get()->display_manager(); | 35 display::DisplayManager* display_manager = Shell::Get()->display_manager(); |
141 display::ManagedDisplayInfo info = | 36 display::ManagedDisplayInfo info = |
142 display_manager->GetDisplayInfo(display.id()); | 37 display_manager->GetDisplayInfo(display.id()); |
143 host_insets_ = info.GetOverscanInsetsInPixel(); | 38 host_insets_ = info.GetOverscanInsetsInPixel(); |
144 root_window_ui_scale_ = info.GetEffectiveUIScale(); | 39 root_window_ui_scale_ = info.GetEffectiveUIScale(); |
145 root_window_bounds_transform_ = | 40 root_window_bounds_transform_ = |
146 CreateInsetsAndScaleTransform(host_insets_, | 41 CreateInsetsAndScaleTransform(host_insets_, |
147 display.device_scale_factor(), | 42 display.device_scale_factor(), |
148 root_window_ui_scale_) * | 43 root_window_ui_scale_) * |
149 CreateRotationTransform(root, display); | 44 CreateRootWindowRotationTransform(root, display); |
150 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 45 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
151 switches::kAshEnableMirroredScreen)) { | 46 switches::kAshEnableMirroredScreen)) { |
152 // Apply the tranform that flips the screen image horizontally so that | 47 // Apply the tranform that flips the screen image horizontally so that |
153 // the screen looks normal when reflected on a mirror. | 48 // the screen looks normal when reflected on a mirror. |
154 root_window_bounds_transform_ = | 49 root_window_bounds_transform_ = |
155 root_window_bounds_transform_ * CreateMirrorTransform(display); | 50 root_window_bounds_transform_ * CreateMirrorTransform(display); |
156 } | 51 } |
157 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); | 52 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); |
158 | 53 |
159 CHECK(transform_.GetInverse(&invert_transform_)); | 54 CHECK(transform_.GetInverse(&invert_transform_)); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 mirror_display_info); | 219 mirror_display_info); |
325 } | 220 } |
326 | 221 |
327 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop( | 222 RootWindowTransformer* CreateRootWindowTransformerForUnifiedDesktop( |
328 const gfx::Rect& screen_bounds, | 223 const gfx::Rect& screen_bounds, |
329 const display::Display& display) { | 224 const display::Display& display) { |
330 return new PartialBoundsRootWindowTransformer(screen_bounds, display); | 225 return new PartialBoundsRootWindowTransformer(screen_bounds, display); |
331 } | 226 } |
332 | 227 |
333 } // namespace ash | 228 } // namespace ash |
OLD | NEW |