Skip to content

Commit

Permalink
Allow rendering of frames in a paused animator during a change to scr…
Browse files Browse the repository at this point in the history
…een dimensions (flutter#4333)

Fixes flutter/flutter#12886
  • Loading branch information
jason-simmons authored Nov 9, 2017
1 parent fe6f3ab commit a9319a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion shell/common/animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Animator::Animator(fml::WeakPtr<Rasterizer> rasterizer,
paused_(false),
regenerate_layer_tree_(false),
frame_scheduled_(false),
dimension_change_pending_(false),
weak_factory_(this) {}

Animator::~Animator() = default;
Expand All @@ -42,6 +43,12 @@ void Animator::Start() {
RequestFrame();
}

// Indicate that screen dimensions will be changing in order to force rendering
// of an updated frame even if the animator is currently paused.
void Animator::SetDimensionChangePending() {
dimension_change_pending_ = true;
}

// This Parity is used by the timeline component to correctly align
// GPU Workloads events with their respective Framework Workload.
const char* Animator::FrameParity() {
Expand Down Expand Up @@ -98,6 +105,12 @@ void Animator::BeginFrame(fxl::TimePoint frame_start_time,
}

void Animator::Render(std::unique_ptr<flow::LayerTree> layer_tree) {
if (dimension_change_pending_ &&
layer_tree->frame_size() != last_layer_tree_size_) {
dimension_change_pending_ = false;
}
last_layer_tree_size_ = layer_tree->frame_size();

if (layer_tree) {
// Note the frame time for instrumentation.
layer_tree->set_construction_time(fxl::TimePoint::Now() -
Expand Down Expand Up @@ -134,7 +147,7 @@ void Animator::RequestFrame(bool regenerate_layer_tree) {
if (regenerate_layer_tree) {
regenerate_layer_tree_ = true;
}
if (paused_) {
if (paused_ && !dimension_change_pending_) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions shell/common/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Animator {

void Stop();

void SetDimensionChangePending();

private:
using LayerTreePipeline = flutter::Pipeline<flow::LayerTree>;

Expand Down Expand Up @@ -63,6 +65,8 @@ class Animator {
bool paused_;
bool regenerate_layer_tree_;
bool frame_scheduled_;
bool dimension_change_pending_;
SkISize last_layer_tree_size_;

fml::WeakPtrFactory<Animator> weak_factory_;

Expand Down
5 changes: 5 additions & 0 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ void Engine::SetViewportMetrics(const blink::ViewportMetrics& metrics) {
viewport_metrics_ = metrics;
if (runtime_)
runtime_->SetViewportMetrics(viewport_metrics_);
if (animator_) {
animator_->SetDimensionChangePending();
if (have_surface_)
ScheduleFrame();
}
}

void Engine::DispatchPlatformMessage(
Expand Down

0 comments on commit a9319a1

Please sign in to comment.