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/display/display_info.h" | 9 #include "ash/display/display_info.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) | 43 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) |
44 matrix.set(x, y, SkFloatToMScalar(0.0f)); | 44 matrix.set(x, y, SkFloatToMScalar(0.0f)); |
45 } | 45 } |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 // TODO(oshima): Transformers should be able to adjust itself | 49 // TODO(oshima): Transformers should be able to adjust itself |
50 // when the device scale factor is changed, instead of | 50 // when the device scale factor is changed, instead of |
51 // precalculating the transform using fixed value. | 51 // precalculating the transform using fixed value. |
52 | 52 |
53 gfx::Transform CreateRotationTransform(aura::RootWindow* root_window, | 53 gfx::Transform CreateRotationTransform(aura::Window* root_window, |
54 const gfx::Display& display) { | 54 const gfx::Display& display) { |
55 DisplayInfo info = | 55 DisplayInfo info = |
56 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); | 56 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); |
57 | 57 |
58 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) | 58 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) |
59 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
60 // Windows 8 bots refused to resize the host window, and | 60 // Windows 8 bots refused to resize the host window, and |
61 // updating the transform results in incorrectly resizing | 61 // updating the transform results in incorrectly resizing |
62 // the root window. Don't apply the transform unless | 62 // the root window. Don't apply the transform unless |
63 // necessary so that unit tests pass on win8 bots. | 63 // necessary so that unit tests pass on win8 bots. |
(...skipping 21 matching lines...) Expand all Loading... |
85 rotate.Translate(display.bounds().width() - one_pixel, | 85 rotate.Translate(display.bounds().width() - one_pixel, |
86 display.bounds().height() - one_pixel); | 86 display.bounds().height() - one_pixel); |
87 rotate.Rotate(180); | 87 rotate.Rotate(180); |
88 break; | 88 break; |
89 } | 89 } |
90 | 90 |
91 RoundNearZero(&rotate); | 91 RoundNearZero(&rotate); |
92 return rotate; | 92 return rotate; |
93 } | 93 } |
94 | 94 |
95 gfx::Transform CreateMagnifierTransform(aura::RootWindow* root_window) { | 95 gfx::Transform CreateMagnifierTransform(aura::Window* root_window) { |
96 MagnificationController* magnifier = | 96 MagnificationController* magnifier = |
97 Shell::GetInstance()->magnification_controller(); | 97 Shell::GetInstance()->magnification_controller(); |
98 float magnifier_scale = 1.f; | 98 float magnifier_scale = 1.f; |
99 gfx::Point magnifier_offset; | 99 gfx::Point magnifier_offset; |
100 if (magnifier && magnifier->IsEnabled()) { | 100 if (magnifier && magnifier->IsEnabled()) { |
101 magnifier_scale = magnifier->GetScale(); | 101 magnifier_scale = magnifier->GetScale(); |
102 magnifier_offset = magnifier->GetWindowPosition(); | 102 magnifier_offset = magnifier->GetWindowPosition(); |
103 } | 103 } |
104 gfx::Transform transform; | 104 gfx::Transform transform; |
105 if (magnifier_scale != 1.f) { | 105 if (magnifier_scale != 1.f) { |
(...skipping 10 matching lines...) Expand all Loading... |
116 if (insets.top() != 0 || insets.left() != 0) { | 116 if (insets.top() != 0 || insets.left() != 0) { |
117 float x_offset = insets.left() / device_scale_factor; | 117 float x_offset = insets.left() / device_scale_factor; |
118 float y_offset = insets.top() / device_scale_factor; | 118 float y_offset = insets.top() / device_scale_factor; |
119 transform.Translate(x_offset, y_offset); | 119 transform.Translate(x_offset, y_offset); |
120 } | 120 } |
121 float inverted_scale = 1.0f / ui_scale; | 121 float inverted_scale = 1.0f / ui_scale; |
122 transform.Scale(inverted_scale, inverted_scale); | 122 transform.Scale(inverted_scale, inverted_scale); |
123 return transform; | 123 return transform; |
124 } | 124 } |
125 | 125 |
126 gfx::Transform CreateOverscanAndUIScaleTransform(aura::RootWindow* root_window, | 126 gfx::Transform CreateOverscanAndUIScaleTransform(aura::Window* root_window, |
127 const gfx::Display& display) { | 127 const gfx::Display& display) { |
128 DisplayInfo info = | 128 DisplayInfo info = |
129 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); | 129 Shell::GetInstance()->display_manager()->GetDisplayInfo(display.id()); |
130 return CreateInsetsAndScaleTransform( | 130 return CreateInsetsAndScaleTransform( |
131 info.GetOverscanInsetsInPixel(), | 131 info.GetOverscanInsetsInPixel(), |
132 ui::GetDeviceScaleFactor(root_window->layer()), | 132 ui::GetDeviceScaleFactor(root_window->layer()), |
133 info.ui_scale()); | 133 info.ui_scale()); |
134 } | 134 } |
135 | 135 |
136 // RootWindowTransformer for ash environment. | 136 // RootWindowTransformer for ash environment. |
137 class AshRootWindowTransformer : public aura::RootWindowTransformer { | 137 class AshRootWindowTransformer : public aura::RootWindowTransformer { |
138 public: | 138 public: |
139 AshRootWindowTransformer(aura::RootWindow* root, | 139 AshRootWindowTransformer(aura::Window* root, |
140 const gfx::Display& display) | 140 const gfx::Display& display) |
141 : root_window_(root) { | 141 : root_window_(root) { |
142 root_window_bounds_transform_ = | 142 root_window_bounds_transform_ = |
143 CreateOverscanAndUIScaleTransform(root, display) * | 143 CreateOverscanAndUIScaleTransform(root, display) * |
144 CreateRotationTransform(root, display); | 144 CreateRotationTransform(root, display); |
145 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); | 145 transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); |
146 CHECK(transform_.GetInverse(&invert_transform_)); | 146 CHECK(transform_.GetInverse(&invert_transform_)); |
147 | 147 |
148 DisplayInfo info = Shell::GetInstance()->display_manager()-> | 148 DisplayInfo info = Shell::GetInstance()->display_manager()-> |
149 GetDisplayInfo(display.id()); | 149 GetDisplayInfo(display.id()); |
(...skipping 28 matching lines...) Expand all Loading... |
178 return gfx::Rect(gfx::ToFlooredSize(new_bounds.size())); | 178 return gfx::Rect(gfx::ToFlooredSize(new_bounds.size())); |
179 } | 179 } |
180 | 180 |
181 virtual gfx::Insets GetHostInsets() const OVERRIDE { | 181 virtual gfx::Insets GetHostInsets() const OVERRIDE { |
182 return host_insets_; | 182 return host_insets_; |
183 } | 183 } |
184 | 184 |
185 private: | 185 private: |
186 virtual ~AshRootWindowTransformer() {} | 186 virtual ~AshRootWindowTransformer() {} |
187 | 187 |
188 aura::RootWindow* root_window_; | 188 aura::Window* root_window_; |
189 gfx::Transform transform_; | 189 gfx::Transform transform_; |
190 | 190 |
191 // The accurate representation of the inverse of the |transform_|. | 191 // The accurate representation of the inverse of the |transform_|. |
192 // This is used to avoid computation error caused by | 192 // This is used to avoid computation error caused by |
193 // |gfx::Transform::GetInverse|. | 193 // |gfx::Transform::GetInverse|. |
194 gfx::Transform invert_transform_; | 194 gfx::Transform invert_transform_; |
195 | 195 |
196 // The transform of the root window bounds. This is used to calculate | 196 // The transform of the root window bounds. This is used to calculate |
197 // the size of root window. | 197 // the size of root window. |
198 gfx::Transform root_window_bounds_transform_; | 198 gfx::Transform root_window_bounds_transform_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 gfx::Transform transform_; | 270 gfx::Transform transform_; |
271 gfx::Rect root_bounds_; | 271 gfx::Rect root_bounds_; |
272 gfx::Insets insets_; | 272 gfx::Insets insets_; |
273 | 273 |
274 DISALLOW_COPY_AND_ASSIGN(MirrorRootWindowTransformer); | 274 DISALLOW_COPY_AND_ASSIGN(MirrorRootWindowTransformer); |
275 }; | 275 }; |
276 | 276 |
277 } // namespace | 277 } // namespace |
278 | 278 |
279 aura::RootWindowTransformer* CreateRootWindowTransformerForDisplay( | 279 aura::RootWindowTransformer* CreateRootWindowTransformerForDisplay( |
280 aura::RootWindow* root, | 280 aura::Window* root, |
281 const gfx::Display& display) { | 281 const gfx::Display& display) { |
282 return new AshRootWindowTransformer(root, display); | 282 return new AshRootWindowTransformer(root, display); |
283 } | 283 } |
284 | 284 |
285 aura::RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( | 285 aura::RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( |
286 const DisplayInfo& source_display_info, | 286 const DisplayInfo& source_display_info, |
287 const DisplayInfo& mirror_display_info) { | 287 const DisplayInfo& mirror_display_info) { |
288 return new MirrorRootWindowTransformer(source_display_info, | 288 return new MirrorRootWindowTransformer(source_display_info, |
289 mirror_display_info); | 289 mirror_display_info); |
290 } | 290 } |
291 | 291 |
292 } // namespace internal | 292 } // namespace internal |
293 } // namespace ash | 293 } // namespace ash |
OLD | NEW |