OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> |
8 #include <map> | 9 #include <map> |
9 | 10 |
10 #include "ash/ash_root_window_transformer.h" | 11 #include "ash/ash_root_window_transformer.h" |
11 #include "ash/ash_switches.h" | 12 #include "ash/ash_switches.h" |
12 #include "ash/display/display_manager.h" | 13 #include "ash/display/display_manager.h" |
13 #include "ash/display/display_pref_util.h" | 14 #include "ash/display/display_pref_util.h" |
14 #include "ash/host/root_window_host_factory.h" | 15 #include "ash/host/root_window_host_factory.h" |
15 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
16 #include "ash/screen_ash.h" | 17 #include "ash/screen_ash.h" |
17 #include "ash/shell.h" | 18 #include "ash/shell.h" |
18 #include "ash/wm/coordinate_conversion.h" | 19 #include "ash/wm/coordinate_conversion.h" |
19 #include "ash/wm/property_util.h" | 20 #include "ash/wm/property_util.h" |
20 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
21 #include "base/command_line.h" | 22 #include "base/command_line.h" |
22 #include "base/json/json_value_converter.h" | 23 #include "base/json/json_value_converter.h" |
23 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
24 #include "base/stringprintf.h" | 25 #include "base/stringprintf.h" |
25 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
| 28 #include "third_party/skia/include/utils/SkMatrix44.h" |
27 #include "ui/aura/client/cursor_client.h" | 29 #include "ui/aura/client/cursor_client.h" |
28 #include "ui/aura/client/screen_position_client.h" | 30 #include "ui/aura/client/screen_position_client.h" |
29 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
30 #include "ui/aura/root_window.h" | 32 #include "ui/aura/root_window.h" |
31 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
32 #include "ui/aura/window_property.h" | 34 #include "ui/aura/window_property.h" |
33 #include "ui/compositor/compositor.h" | 35 #include "ui/compositor/compositor.h" |
34 #include "ui/compositor/dip_util.h" | 36 #include "ui/compositor/dip_util.h" |
35 #include "ui/gfx/display.h" | 37 #include "ui/gfx/display.h" |
36 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 } | 118 } |
117 | 119 |
118 bool GetDisplayIdFromString(const base::StringPiece& position, int64* field) { | 120 bool GetDisplayIdFromString(const base::StringPiece& position, int64* field) { |
119 return base::StringToInt64(position, field); | 121 return base::StringToInt64(position, field); |
120 } | 122 } |
121 | 123 |
122 internal::DisplayManager* GetDisplayManager() { | 124 internal::DisplayManager* GetDisplayManager() { |
123 return Shell::GetInstance()->display_manager(); | 125 return Shell::GetInstance()->display_manager(); |
124 } | 126 } |
125 | 127 |
| 128 // Round near zero value to zero. |
| 129 void RoundNearZero(gfx::Transform* transform) { |
| 130 const float kEpsilon = 0.001f; |
| 131 SkMatrix44& matrix = transform->matrix(); |
| 132 for (int x = 0; x < 4; ++x) { |
| 133 for (int y = 0; y < 4; ++y) { |
| 134 if (std::abs(SkMScalarToFloat(matrix.get(x, y))) < kEpsilon) |
| 135 matrix.set(x, y, SkFloatToMScalar(0.0f)); |
| 136 } |
| 137 } |
| 138 } |
| 139 |
126 void RotateRootWindow(aura::RootWindow* root_window, | 140 void RotateRootWindow(aura::RootWindow* root_window, |
127 const gfx::Display& display, | 141 const gfx::Display& display, |
128 const internal::DisplayInfo& info) { | 142 const internal::DisplayInfo& info) { |
129 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) | 143 // TODO(oshima): Add animation. (crossfade+rotation, or just cross-fade) |
130 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
131 // Windows 8 bots refused to resize the host window, and | 145 // Windows 8 bots refused to resize the host window, and |
132 // updating the transform results in incorrectly resizing | 146 // updating the transform results in incorrectly resizing |
133 // the root window. Don't apply the transform unless | 147 // the root window. Don't apply the transform unless |
134 // necessary so that unit tests pass on win8 bots. | 148 // necessary so that unit tests pass on win8 bots. |
135 if (info.rotation() == root_window->GetProperty(kRotationPropertyKey)) | 149 if (info.rotation() == root_window->GetProperty(kRotationPropertyKey)) |
136 return; | 150 return; |
137 root_window->SetProperty(kRotationPropertyKey, info.rotation()); | 151 root_window->SetProperty(kRotationPropertyKey, info.rotation()); |
138 #endif | 152 #endif |
139 gfx::Transform rotate; | 153 gfx::Transform rotate; |
140 // TODO(oshima): Manually complute the inverse of the | 154 // TODO(oshima): Manually complute the inverse of the |
141 // rotate+translate matrix to compensate for computation error in | 155 // rotate+translate matrix to compensate for computation error in |
142 // the inverted matrix. Ideally, SkMatrix should have special | 156 // the inverted matrix. Ideally, SkMatrix should have special |
143 // case handling for rotate+translate case. crbug.com/222483. | 157 // case handling for rotate+translate case. crbug.com/222483. |
144 gfx::Transform reverse_rotate; | 158 gfx::Transform reverse_rotate; |
145 | 159 |
146 // The origin is (0, 0), so the translate width/height must be reduced by | 160 // The origin is (0, 0), so the translate width/height must be reduced by |
147 // 1 pixel. | 161 // 1 pixel. |
148 float one_pixel = 1.0f / display.device_scale_factor(); | 162 float one_pixel = 1.0f / display.device_scale_factor(); |
149 switch (info.rotation()) { | 163 switch (info.rotation()) { |
150 case gfx::Display::ROTATE_0: | 164 case gfx::Display::ROTATE_0: |
151 break; | 165 break; |
152 case gfx::Display::ROTATE_90: | 166 case gfx::Display::ROTATE_90: |
153 rotate.Translate(display.bounds().height() - one_pixel, 0); | 167 rotate.Translate(display.bounds().height() - one_pixel, 0); |
154 rotate.Rotate(90); | 168 rotate.Rotate(90); |
155 // Rotate 270 instead of 90 as it will cause calcuration error. | |
156 reverse_rotate.Rotate(270); | 169 reverse_rotate.Rotate(270); |
157 reverse_rotate.Translate(-(display.bounds().height() - one_pixel), 0); | 170 reverse_rotate.Translate(-(display.bounds().height() - one_pixel), 0); |
158 break; | 171 break; |
159 case gfx::Display::ROTATE_270: | 172 case gfx::Display::ROTATE_270: |
160 rotate.Translate(0, display.bounds().width() - one_pixel); | 173 rotate.Translate(0, display.bounds().width() - one_pixel); |
161 rotate.Rotate(270); | 174 rotate.Rotate(270); |
162 reverse_rotate.Rotate(90); | 175 reverse_rotate.Rotate(90); |
163 reverse_rotate.Translate(0, -(display.bounds().width() - one_pixel)); | 176 reverse_rotate.Translate(0, -(display.bounds().width() - one_pixel)); |
164 break; | 177 break; |
165 case gfx::Display::ROTATE_180: | 178 case gfx::Display::ROTATE_180: |
166 rotate.Translate(display.bounds().width() - one_pixel, | 179 rotate.Translate(display.bounds().width() - one_pixel, |
167 display.bounds().height() - one_pixel); | 180 display.bounds().height() - one_pixel); |
168 rotate.Rotate(180); | 181 rotate.Rotate(180); |
169 reverse_rotate.Rotate(180); | 182 reverse_rotate.Rotate(180); |
170 reverse_rotate.Translate(-(display.bounds().width() - one_pixel), | 183 reverse_rotate.Translate(-(display.bounds().width() - one_pixel), |
171 -(display.bounds().height() - one_pixel)); | 184 -(display.bounds().height() - one_pixel)); |
172 break; | 185 break; |
173 } | 186 } |
| 187 RoundNearZero(&rotate); |
| 188 RoundNearZero(&reverse_rotate); |
| 189 |
174 scoped_ptr<aura::RootWindowTransformer> transformer( | 190 scoped_ptr<aura::RootWindowTransformer> transformer( |
175 new AshRootWindowTransformer(root_window, | 191 new AshRootWindowTransformer(root_window, |
176 rotate, | 192 rotate, |
177 reverse_rotate, | 193 reverse_rotate, |
178 info.GetOverscanInsetsInPixel(), | 194 info.GetOverscanInsetsInPixel(), |
179 info.ui_scale())); | 195 info.ui_scale())); |
180 root_window->SetRootWindowTransformer(transformer.Pass()); | 196 root_window->SetRootWindowTransformer(transformer.Pass()); |
181 } | 197 } |
182 | 198 |
183 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, | 199 void SetDisplayPropertiesOnHostWindow(aura::RootWindow* root, |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 } | 1033 } |
1018 | 1034 |
1019 void DisplayController::OnFadeOutForSwapDisplayFinished() { | 1035 void DisplayController::OnFadeOutForSwapDisplayFinished() { |
1020 #if defined(OS_CHROMEOS) | 1036 #if defined(OS_CHROMEOS) |
1021 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); | 1037 SetPrimaryDisplay(ScreenAsh::GetSecondaryDisplay()); |
1022 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); | 1038 Shell::GetInstance()->output_configurator_animation()->StartFadeInAnimation(); |
1023 #endif | 1039 #endif |
1024 } | 1040 } |
1025 | 1041 |
1026 } // namespace ash | 1042 } // namespace ash |
OLD | NEW |