Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: ash/rotator/screen_rotation_animator.cc

Issue 1108343002: Revert of Merge Prevent DisplayPreferences from saving incorrect rotations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2357
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | ash/system/audio/tray_audio.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/rotator/screen_rotation_animator.h" 5 #include "ash/rotator/screen_rotation_animator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 // The time it takes for the rotation animations to run. 61 // The time it takes for the rotation animations to run.
62 const int kRotationDurationInMs = 250; 62 const int kRotationDurationInMs = 250;
63 63
64 // Gets the current display rotation for the display with the specified 64 // Gets the current display rotation for the display with the specified
65 // |display_id|. 65 // |display_id|.
66 gfx::Display::Rotation GetCurrentRotation(int64 display_id) { 66 gfx::Display::Rotation GetCurrentRotation(int64 display_id) {
67 return Shell::GetInstance() 67 return Shell::GetInstance()
68 ->display_manager() 68 ->display_manager()
69 ->GetDisplayInfo(display_id) 69 ->GetDisplayInfo(display_id)
70 .GetActiveRotation(); 70 .rotation();
71 } 71 }
72 72
73 // Returns true if the rotation between |initial_rotation| and |new_rotation| is 73 // Returns true if the rotation between |initial_rotation| and |new_rotation| is
74 // 180 degrees. 74 // 180 degrees.
75 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation, 75 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation,
76 gfx::Display::Rotation new_rotation) { 76 gfx::Display::Rotation new_rotation) {
77 return (initial_rotation + 2) % 4 == new_rotation; 77 return (initial_rotation + 2) % 4 == new_rotation;
78 } 78 }
79 79
80 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when 80 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void LayerCleanupObserver::OnDetachedFromSequence( 147 void LayerCleanupObserver::OnDetachedFromSequence(
148 ui::LayerAnimationSequence* sequence) { 148 ui::LayerAnimationSequence* sequence) {
149 DCHECK_EQ(sequence, sequence_); 149 DCHECK_EQ(sequence, sequence_);
150 sequence_ = nullptr; 150 sequence_ = nullptr;
151 } 151 }
152 152
153 // Set the screen orientation for the given |display| to |new_rotation| and 153 // Set the screen orientation for the given |display| to |new_rotation| and
154 // animate the change. 154 // animate the change.
155 void RotateScreen(int64 display_id, 155 void RotateScreen(int64 display_id,
156 gfx::Display::Rotation new_rotation, 156 gfx::Display::Rotation new_rotation,
157 gfx::Display::RotationSource source,
158 base::TimeDelta duration, 157 base::TimeDelta duration,
159 int rotation_degrees, 158 int rotation_degrees,
160 int rotation_degree_offset, 159 int rotation_degree_offset,
161 gfx::Tween::Type tween_type, 160 gfx::Tween::Type tween_type,
162 bool should_scale) { 161 bool should_scale) {
163 aura::Window* root_window = 162 aura::Window* root_window =
164 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId( 163 Shell::GetInstance()->display_controller()->GetRootWindowForDisplayId(
165 display_id); 164 display_id);
166 165
167 const gfx::Display::Rotation initial_orientation = 166 const gfx::Display::Rotation initial_orientation =
168 GetCurrentRotation(display_id); 167 GetCurrentRotation(display_id);
169 168
170 const gfx::RectF original_screen_bounds = root_window->GetTargetBounds(); 169 const gfx::RectF original_screen_bounds = root_window->GetTargetBounds();
171 // 180 degree rotations should animate clock-wise. 170 // 180 degree rotations should animate clock-wise.
172 const int rotation_factor = 171 const int rotation_factor =
173 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1; 172 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1;
174 173
175 scoped_ptr<ui::LayerTreeOwner> old_layer_tree = 174 scoped_ptr<ui::LayerTreeOwner> old_layer_tree =
176 wm::RecreateLayers(root_window); 175 wm::RecreateLayers(root_window);
177 176
178 // Add the cloned layer tree in to the root, so it will be rendered. 177 // Add the cloned layer tree in to the root, so it will be rendered.
179 root_window->layer()->Add(old_layer_tree->root()); 178 root_window->layer()->Add(old_layer_tree->root());
180 root_window->layer()->StackAtTop(old_layer_tree->root()); 179 root_window->layer()->StackAtTop(old_layer_tree->root());
181 180
182 scoped_ptr<LayerCleanupObserver> layer_cleanup_observer( 181 scoped_ptr<LayerCleanupObserver> layer_cleanup_observer(
183 new LayerCleanupObserver(old_layer_tree.Pass())); 182 new LayerCleanupObserver(old_layer_tree.Pass()));
184 183
185 Shell::GetInstance()->display_manager()->SetDisplayRotation( 184 Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id,
186 display_id, new_rotation, source); 185 new_rotation);
187 186
188 const gfx::RectF rotated_screen_bounds = root_window->GetTargetBounds(); 187 const gfx::RectF rotated_screen_bounds = root_window->GetTargetBounds();
189 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, 188 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2,
190 rotated_screen_bounds.height() / 2); 189 rotated_screen_bounds.height() / 2);
191 190
192 gfx::Point3F new_layer_initial_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); 191 gfx::Point3F new_layer_initial_scale = gfx::Point3F(1.0f, 1.0f, 1.0f);
193 gfx::Point3F old_layer_target_scale = gfx::Point3F(1.0f, 1.0f, 1.0f); 192 gfx::Point3F old_layer_target_scale = gfx::Point3F(1.0f, 1.0f, 1.0f);
194 193
195 if (should_scale) { 194 if (should_scale) {
196 new_layer_initial_scale = gfx::Point3F( 195 new_layer_initial_scale = gfx::Point3F(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 260
262 } // namespace 261 } // namespace
263 262
264 ScreenRotationAnimator::ScreenRotationAnimator(int64 display_id) 263 ScreenRotationAnimator::ScreenRotationAnimator(int64 display_id)
265 : display_id_(display_id) { 264 : display_id_(display_id) {
266 } 265 }
267 266
268 ScreenRotationAnimator::~ScreenRotationAnimator() { 267 ScreenRotationAnimator::~ScreenRotationAnimator() {
269 } 268 }
270 269
271 void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation, 270 void ScreenRotationAnimator::Rotate(gfx::Display::Rotation new_rotation) {
272 gfx::Display::RotationSource source) {
273 const gfx::Display::Rotation current_rotation = 271 const gfx::Display::Rotation current_rotation =
274 GetCurrentRotation(display_id_); 272 GetCurrentRotation(display_id_);
275 273
276 if (current_rotation == new_rotation) 274 if (current_rotation == new_rotation)
277 return; 275 return;
278 276
279 const std::string switch_value = 277 const std::string switch_value =
280 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 278 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
281 switches::kAshEnableScreenRotationAnimation); 279 switches::kAshEnableScreenRotationAnimation);
282 280
283 if (switch_value == kRotationAnimation_None) { 281 if (switch_value == kRotationAnimation_None) {
284 Shell::GetInstance()->display_manager()->SetDisplayRotation( 282 Shell::GetInstance()->display_manager()->SetDisplayRotation(display_id_,
285 display_id_, new_rotation, source); 283 new_rotation);
286 } else if (kRotationAnimation_Default == switch_value || 284 } else if (kRotationAnimation_Default == switch_value ||
287 kRotationAnimation_Partial == switch_value) { 285 kRotationAnimation_Partial == switch_value) {
288 const int rotation_degree_offset = 286 const int rotation_degree_offset =
289 Is180DegreeFlip(current_rotation, new_rotation) 287 Is180DegreeFlip(current_rotation, new_rotation)
290 ? 180 - kPartialRotationDegrees 288 ? 180 - kPartialRotationDegrees
291 : 90 - kPartialRotationDegrees; 289 : 90 - kPartialRotationDegrees;
292 290
293 RotateScreen(display_id_, new_rotation, source, 291 RotateScreen(display_id_, new_rotation,
294 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), 292 base::TimeDelta::FromMilliseconds(kRotationDurationInMs),
295 kPartialRotationDegrees, rotation_degree_offset, 293 kPartialRotationDegrees, rotation_degree_offset,
296 gfx::Tween::FAST_OUT_LINEAR_IN, false /* should_scale */); 294 gfx::Tween::FAST_OUT_LINEAR_IN, false /* should_scale */);
297 } else if (kRotationAnimation_Full == switch_value) { 295 } else if (kRotationAnimation_Full == switch_value) {
298 const int rotation_degrees = 296 const int rotation_degrees =
299 Is180DegreeFlip(current_rotation, new_rotation) ? 180 : 90; 297 Is180DegreeFlip(current_rotation, new_rotation) ? 180 : 90;
300 298
301 RotateScreen(display_id_, new_rotation, source, 299 RotateScreen(display_id_, new_rotation,
302 base::TimeDelta::FromMilliseconds(kRotationDurationInMs), 300 base::TimeDelta::FromMilliseconds(kRotationDurationInMs),
303 rotation_degrees, 0 /* rotation_degree_offset */, 301 rotation_degrees, 0 /* rotation_degree_offset */,
304 gfx::Tween::FAST_OUT_LINEAR_IN, true /* should_scale */); 302 gfx::Tween::FAST_OUT_LINEAR_IN, true /* should_scale */);
305 } else { 303 } else {
306 NOTREACHED(); 304 NOTREACHED();
307 } 305 }
308 } 306 }
309 307
310 } // namespace ash 308 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animator.h ('k') | ash/system/audio/tray_audio.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698