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

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

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 8 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_animation_unittest.cc ('k') | ash/rotator/window_rotation.h » ('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 <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation, 55 bool Is180DegreeFlip(gfx::Display::Rotation initial_rotation,
56 gfx::Display::Rotation new_rotation) { 56 gfx::Display::Rotation new_rotation) {
57 return (initial_rotation + 2) % 4 == new_rotation; 57 return (initial_rotation + 2) % 4 == new_rotation;
58 } 58 }
59 59
60 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when 60 // A LayerAnimationObserver that will destroy the contained LayerTreeOwner when
61 // notified that a layer animation has ended or was aborted. 61 // notified that a layer animation has ended or was aborted.
62 class LayerCleanupObserver : public ui::LayerAnimationObserver { 62 class LayerCleanupObserver : public ui::LayerAnimationObserver {
63 public: 63 public:
64 explicit LayerCleanupObserver( 64 explicit LayerCleanupObserver(
65 scoped_ptr<ui::LayerTreeOwner> layer_tree_owner); 65 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner);
66 ~LayerCleanupObserver() override; 66 ~LayerCleanupObserver() override;
67 67
68 // Get the root layer of the owned layer tree. 68 // Get the root layer of the owned layer tree.
69 ui::Layer* GetRootLayer(); 69 ui::Layer* GetRootLayer();
70 70
71 // ui::LayerAnimationObserver: 71 // ui::LayerAnimationObserver:
72 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override; 72 void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override;
73 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override; 73 void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
74 void OnLayerAnimationScheduled( 74 void OnLayerAnimationScheduled(
75 ui::LayerAnimationSequence* sequence) override {} 75 ui::LayerAnimationSequence* sequence) override {}
76 76
77 protected: 77 protected:
78 // ui::LayerAnimationObserver: 78 // ui::LayerAnimationObserver:
79 bool RequiresNotificationWhenAnimatorDestroyed() const override { 79 bool RequiresNotificationWhenAnimatorDestroyed() const override {
80 return true; 80 return true;
81 } 81 }
82 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override; 82 void OnAttachedToSequence(ui::LayerAnimationSequence* sequence) override;
83 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override; 83 void OnDetachedFromSequence(ui::LayerAnimationSequence* sequence) override;
84 84
85 private: 85 private:
86 // Aborts the active animations of the layer, and recurses upon its child 86 // Aborts the active animations of the layer, and recurses upon its child
87 // layers. 87 // layers.
88 void AbortAnimations(ui::Layer* layer); 88 void AbortAnimations(ui::Layer* layer);
89 89
90 // The owned layer tree. 90 // The owned layer tree.
91 scoped_ptr<ui::LayerTreeOwner> layer_tree_owner_; 91 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner_;
92 92
93 // The LayerAnimationSequence that |this| has been attached to. Defaults to 93 // The LayerAnimationSequence that |this| has been attached to. Defaults to
94 // nullptr. 94 // nullptr.
95 ui::LayerAnimationSequence* sequence_; 95 ui::LayerAnimationSequence* sequence_;
96 96
97 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver); 97 DISALLOW_COPY_AND_ASSIGN(LayerCleanupObserver);
98 }; 98 };
99 99
100 LayerCleanupObserver::LayerCleanupObserver( 100 LayerCleanupObserver::LayerCleanupObserver(
101 scoped_ptr<ui::LayerTreeOwner> layer_tree_owner) 101 std::unique_ptr<ui::LayerTreeOwner> layer_tree_owner)
102 : layer_tree_owner_(std::move(layer_tree_owner)), sequence_(nullptr) {} 102 : layer_tree_owner_(std::move(layer_tree_owner)), sequence_(nullptr) {}
103 103
104 LayerCleanupObserver::~LayerCleanupObserver() { 104 LayerCleanupObserver::~LayerCleanupObserver() {
105 // We must eplicitly detach from |sequence_| because we return true from 105 // We must eplicitly detach from |sequence_| because we return true from
106 // RequiresNotificationWhenAnimatorDestroyed. 106 // RequiresNotificationWhenAnimatorDestroyed.
107 if (sequence_) 107 if (sequence_)
108 sequence_->RemoveObserver(this); 108 sequence_->RemoveObserver(this);
109 AbortAnimations(layer_tree_owner_->root()); 109 AbortAnimations(layer_tree_owner_->root());
110 } 110 }
111 111
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1; 161 (initial_orientation + 3) % 4 == new_rotation ? 1 : -1;
162 162
163 const int old_layer_initial_rotation_degrees = 163 const int old_layer_initial_rotation_degrees =
164 (Is180DegreeFlip(initial_orientation, new_rotation) ? 180 : 90); 164 (Is180DegreeFlip(initial_orientation, new_rotation) ? 180 : 90);
165 165
166 const base::TimeDelta duration = 166 const base::TimeDelta duration =
167 base::TimeDelta::FromMilliseconds(kRotationDurationInMs); 167 base::TimeDelta::FromMilliseconds(kRotationDurationInMs);
168 168
169 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN; 169 const gfx::Tween::Type tween_type = gfx::Tween::FAST_OUT_LINEAR_IN;
170 170
171 scoped_ptr<ui::LayerTreeOwner> old_layer_tree = 171 std::unique_ptr<ui::LayerTreeOwner> old_layer_tree =
172 wm::RecreateLayers(root_window); 172 wm::RecreateLayers(root_window);
173 173
174 // Add the cloned layer tree in to the root, so it will be rendered. 174 // Add the cloned layer tree in to the root, so it will be rendered.
175 root_window->layer()->Add(old_layer_tree->root()); 175 root_window->layer()->Add(old_layer_tree->root());
176 root_window->layer()->StackAtTop(old_layer_tree->root()); 176 root_window->layer()->StackAtTop(old_layer_tree->root());
177 177
178 scoped_ptr<LayerCleanupObserver> layer_cleanup_observer( 178 std::unique_ptr<LayerCleanupObserver> layer_cleanup_observer(
179 new LayerCleanupObserver(std::move(old_layer_tree))); 179 new LayerCleanupObserver(std::move(old_layer_tree)));
180 180
181 Shell::GetInstance()->display_manager()->SetDisplayRotation( 181 Shell::GetInstance()->display_manager()->SetDisplayRotation(
182 display_id, new_rotation, source); 182 display_id, new_rotation, source);
183 183
184 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds(); 184 const gfx::Rect rotated_screen_bounds = root_window->GetTargetBounds();
185 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2, 185 const gfx::Point pivot = gfx::Point(rotated_screen_bounds.width() / 2,
186 rotated_screen_bounds.height() / 2); 186 rotated_screen_bounds.height() / 2);
187 187
188 // We must animate each non-cloned child layer individually because the cloned 188 // We must animate each non-cloned child layer individually because the cloned
189 // layer was added as a child to |root_window|'s layer so that it will be 189 // layer was added as a child to |root_window|'s layer so that it will be
190 // rendered. 190 // rendered.
191 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and 191 // TODO(bruthig): Add a NOT_DRAWN layer in between the root_window's layer and
192 // its current children so that we only need to initiate two 192 // its current children so that we only need to initiate two
193 // LayerAnimationSequences. One for the new layers and one for the old layer. 193 // LayerAnimationSequences. One for the new layers and one for the old layer.
194 for (ui::Layer* child_layer : root_window->layer()->children()) { 194 for (ui::Layer* child_layer : root_window->layer()->children()) {
195 // Skip the cloned layer because it has a different animation. 195 // Skip the cloned layer because it has a different animation.
196 if (child_layer == layer_cleanup_observer->GetRootLayer()) 196 if (child_layer == layer_cleanup_observer->GetRootLayer())
197 continue; 197 continue;
198 198
199 scoped_ptr<ScreenRotationAnimation> screen_rotation( 199 std::unique_ptr<ScreenRotationAnimation> screen_rotation(
200 new ScreenRotationAnimation( 200 new ScreenRotationAnimation(
201 child_layer, kRotationDegrees * rotation_factor, 201 child_layer, kRotationDegrees * rotation_factor,
202 0 /* end_degrees */, child_layer->opacity(), 202 0 /* end_degrees */, child_layer->opacity(),
203 1.0f /* target_opacity */, pivot, duration, tween_type)); 203 1.0f /* target_opacity */, pivot, duration, tween_type));
204 204
205 ui::LayerAnimator* animator = child_layer->GetAnimator(); 205 ui::LayerAnimator* animator = child_layer->GetAnimator();
206 animator->set_preemption_strategy( 206 animator->set_preemption_strategy(
207 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 207 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
208 scoped_ptr<ui::LayerAnimationSequence> animation_sequence( 208 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence(
209 new ui::LayerAnimationSequence(screen_rotation.release())); 209 new ui::LayerAnimationSequence(screen_rotation.release()));
210 animator->StartAnimation(animation_sequence.release()); 210 animator->StartAnimation(animation_sequence.release());
211 } 211 }
212 212
213 // The old layer will also be transformed into the new orientation. We will 213 // The old layer will also be transformed into the new orientation. We will
214 // translate it so that the old layer's center point aligns with the new 214 // translate it so that the old layer's center point aligns with the new
215 // orientation's center point and use that center point as the pivot for the 215 // orientation's center point and use that center point as the pivot for the
216 // rotation animation. 216 // rotation animation.
217 gfx::Transform translate_transform; 217 gfx::Transform translate_transform;
218 translate_transform.Translate( 218 translate_transform.Translate(
219 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2, 219 (rotated_screen_bounds.width() - original_screen_bounds.width()) / 2,
220 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2); 220 (rotated_screen_bounds.height() - original_screen_bounds.height()) / 2);
221 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform); 221 layer_cleanup_observer->GetRootLayer()->SetTransform(translate_transform);
222 222
223 scoped_ptr<ScreenRotationAnimation> screen_rotation( 223 std::unique_ptr<ScreenRotationAnimation> screen_rotation(
224 new ScreenRotationAnimation( 224 new ScreenRotationAnimation(
225 layer_cleanup_observer->GetRootLayer(), 225 layer_cleanup_observer->GetRootLayer(),
226 old_layer_initial_rotation_degrees * rotation_factor, 226 old_layer_initial_rotation_degrees * rotation_factor,
227 (old_layer_initial_rotation_degrees - kRotationDegrees) * 227 (old_layer_initial_rotation_degrees - kRotationDegrees) *
228 rotation_factor, 228 rotation_factor,
229 layer_cleanup_observer->GetRootLayer()->opacity(), 229 layer_cleanup_observer->GetRootLayer()->opacity(),
230 0.0f /* target_opacity */, pivot, duration, tween_type)); 230 0.0f /* target_opacity */, pivot, duration, tween_type));
231 231
232 ui::LayerAnimator* animator = 232 ui::LayerAnimator* animator =
233 layer_cleanup_observer->GetRootLayer()->GetAnimator(); 233 layer_cleanup_observer->GetRootLayer()->GetAnimator();
234 animator->set_preemption_strategy( 234 animator->set_preemption_strategy(
235 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 235 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
236 scoped_ptr<ui::LayerAnimationSequence> animation_sequence( 236 std::unique_ptr<ui::LayerAnimationSequence> animation_sequence(
237 new ui::LayerAnimationSequence(screen_rotation.release())); 237 new ui::LayerAnimationSequence(screen_rotation.release()));
238 // Add an observer so that the cloned layers can be cleaned up with the 238 // Add an observer so that the cloned layers can be cleaned up with the
239 // animation completes/aborts. 239 // animation completes/aborts.
240 animation_sequence->AddObserver(layer_cleanup_observer.release()); 240 animation_sequence->AddObserver(layer_cleanup_observer.release());
241 animator->StartAnimation(animation_sequence.release()); 241 animator->StartAnimation(animation_sequence.release());
242 } 242 }
243 243
244 } // namespace 244 } // namespace
245 245
246 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id) 246 ScreenRotationAnimator::ScreenRotationAnimator(int64_t display_id)
(...skipping 14 matching lines...) Expand all
261 const gfx::Display::Rotation current_rotation = 261 const gfx::Display::Rotation current_rotation =
262 GetCurrentRotation(display_id_); 262 GetCurrentRotation(display_id_);
263 263
264 if (current_rotation == new_rotation) 264 if (current_rotation == new_rotation)
265 return; 265 return;
266 266
267 RotateScreen(display_id_, new_rotation, source); 267 RotateScreen(display_id_, new_rotation, source);
268 } 268 }
269 269
270 } // namespace ash 270 } // namespace ash
OLDNEW
« no previous file with comments | « ash/rotator/screen_rotation_animation_unittest.cc ('k') | ash/rotator/window_rotation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698