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

Side by Side Diff: sky/shell/ui/animator.cc

Issue 1230073002: Teach SkyShell.apk to stop posting frames when not visible (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
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 "sky/shell/ui/animator.h" 5 #include "sky/shell/ui/animator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 10
11 namespace sky { 11 namespace sky {
12 namespace shell { 12 namespace shell {
13 13
14 Animator::Animator(const Engine::Config& config, Engine* engine) 14 Animator::Animator(const Engine::Config& config, Engine* engine)
15 : config_(config), 15 : config_(config),
16 engine_(engine), 16 engine_(engine),
17 engine_requested_frame_(false), 17 engine_requested_frame_(false),
18 frame_in_progress_(false), 18 frame_in_progress_(false),
19 paused_(false),
19 weak_factory_(this) { 20 weak_factory_(this) {
20 } 21 }
21 22
22 Animator::~Animator() { 23 Animator::~Animator() {
23 } 24 }
24 25
25 void Animator::RequestFrame() { 26 void Animator::RequestFrame() {
26 if (engine_requested_frame_) 27 if (engine_requested_frame_)
27 return; 28 return;
28 29
29 TRACE_EVENT_ASYNC_BEGIN0("sky", "Frame request pending", this); 30 TRACE_EVENT_ASYNC_BEGIN0("sky", "Frame request pending", this);
30 engine_requested_frame_ = true; 31 engine_requested_frame_ = true;
31 32
32 if (!frame_in_progress_) { 33 if (!frame_in_progress_) {
33 frame_in_progress_ = true; 34 frame_in_progress_ = true;
34 base::MessageLoop::current()->PostTask( 35 base::MessageLoop::current()->PostTask(
35 FROM_HERE, 36 FROM_HERE,
36 base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr())); 37 base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr()));
37 } 38 }
38 } 39 }
39 40
40 void Animator::CancelFrameRequest() { 41 void Animator::Stop() {
42 paused_ = true;
41 engine_requested_frame_ = false; 43 engine_requested_frame_ = false;
42 } 44 }
43 45
46 void Animator::Start() {
47 paused_ = false;
48 RequestFrame();
49 }
50
44 void Animator::BeginFrame() { 51 void Animator::BeginFrame() {
45 DCHECK(frame_in_progress_); 52 DCHECK(frame_in_progress_);
46 // There could be a request in the message loop at time of cancel. 53 // There could be a request in the message loop at time of cancel.
47 if (!engine_requested_frame_) { 54 if (!engine_requested_frame_) {
48 frame_in_progress_ = false; 55 frame_in_progress_ = false;
49 return; 56 return;
50 } 57 }
51 58
52 engine_requested_frame_ = false; 59 engine_requested_frame_ = false;
53 TRACE_EVENT_ASYNC_END0("sky", "Frame request pending", this); 60 TRACE_EVENT_ASYNC_END0("sky", "Frame request pending", this);
54 61
55 engine_->BeginFrame(base::TimeTicks::Now()); 62 engine_->BeginFrame(base::TimeTicks::Now());
56 config_.gpu_task_runner->PostTaskAndReply( 63 config_.gpu_task_runner->PostTaskAndReply(
57 FROM_HERE, 64 FROM_HERE,
58 base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, engine_->Paint()), 65 base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, engine_->Paint()),
59 base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr())); 66 base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr()));
60 } 67 }
61 68
62 void Animator::OnFrameComplete() { 69 void Animator::OnFrameComplete() {
63 DCHECK(frame_in_progress_); 70 DCHECK(frame_in_progress_);
64 frame_in_progress_ = false; 71 frame_in_progress_ = false;
72 if (paused_)
73 return;
74
65 if (engine_requested_frame_) { 75 if (engine_requested_frame_) {
66 frame_in_progress_ = true; 76 frame_in_progress_ = true;
67 BeginFrame(); 77 BeginFrame();
68 } 78 }
69 } 79 }
70 80
71 } // namespace shell 81 } // namespace shell
72 } // namespace sky 82 } // namespace sky
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698