Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 93b7b46

Browse files
committed
Merge pull request #335 from abarth/pipeline_depth
Increase the graphics pipeline depth to 2
2 parents 6a3fe82 + c1f0e35 commit 93b7b46

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

sky/shell/ui/animator.cc

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
namespace sky {
1212
namespace shell {
1313

14+
const int kPipelineDepth = 2;
15+
1416
Animator::Animator(const Engine::Config& config, Engine* engine)
1517
: config_(config),
1618
engine_(engine),
19+
outstanding_draw_requests_(0),
20+
did_defer_frame_request_(false),
1721
engine_requested_frame_(false),
18-
frame_in_progress_(false),
1922
paused_(false),
2023
weak_factory_(this) {
2124
}
@@ -27,15 +30,19 @@ void Animator::RequestFrame() {
2730
if (engine_requested_frame_)
2831
return;
2932

33+
DCHECK(!did_defer_frame_request_);
34+
3035
TRACE_EVENT_ASYNC_BEGIN0("sky", "Frame request pending", this);
3136
engine_requested_frame_ = true;
3237

33-
if (!frame_in_progress_) {
34-
frame_in_progress_ = true;
35-
base::MessageLoop::current()->PostTask(
36-
FROM_HERE,
37-
base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr()));
38+
if (outstanding_draw_requests_ >= kPipelineDepth) {
39+
did_defer_frame_request_ = true;
40+
return;
3841
}
42+
43+
base::MessageLoop::current()->PostTask(
44+
FROM_HERE,
45+
base::Bind(&Animator::BeginFrame, weak_factory_.GetWeakPtr()));
3946
}
4047

4148
void Animator::Stop() {
@@ -49,31 +56,30 @@ void Animator::Start() {
4956
}
5057

5158
void Animator::BeginFrame() {
52-
DCHECK(frame_in_progress_);
53-
// There could be a request in the message loop at time of cancel.
54-
if (!engine_requested_frame_) {
55-
frame_in_progress_ = false;
59+
if (!engine_requested_frame_)
5660
return;
57-
}
58-
5961
engine_requested_frame_ = false;
6062
TRACE_EVENT_ASYNC_END0("sky", "Frame request pending", this);
6163

6264
engine_->BeginFrame(base::TimeTicks::Now());
65+
skia::RefPtr<SkPicture> picture = engine_->Paint();
66+
67+
outstanding_draw_requests_++;
68+
DCHECK(outstanding_draw_requests_ <= kPipelineDepth);
6369
config_.gpu_task_runner->PostTaskAndReply(
6470
FROM_HERE,
65-
base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, engine_->Paint()),
71+
base::Bind(&GPUDelegate::Draw, config_.gpu_delegate, picture),
6672
base::Bind(&Animator::OnFrameComplete, weak_factory_.GetWeakPtr()));
6773
}
6874

6975
void Animator::OnFrameComplete() {
70-
DCHECK(frame_in_progress_);
71-
frame_in_progress_ = false;
76+
DCHECK(outstanding_draw_requests_ > 0);
77+
--outstanding_draw_requests_;
7278
if (paused_)
7379
return;
7480

75-
if (engine_requested_frame_) {
76-
frame_in_progress_ = true;
81+
if (engine_requested_frame_ && did_defer_frame_request_) {
82+
did_defer_frame_request_ = false;
7783
BeginFrame();
7884
}
7985
}

sky/shell/ui/animator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class Animator {
2727

2828
Engine::Config config_;
2929
Engine* engine_;
30+
int outstanding_draw_requests_;
31+
bool did_defer_frame_request_;
3032
bool engine_requested_frame_;
31-
bool frame_in_progress_;
3233
bool paused_;
3334

3435
base::WeakPtrFactory<Animator> weak_factory_;

0 commit comments

Comments
 (0)