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

Revert multiple display support for embedder API #21456

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@ FILE: ../../../flutter/shell/common/animator_unittests.cc
FILE: ../../../flutter/shell/common/canvas_spy.cc
FILE: ../../../flutter/shell/common/canvas_spy.h
FILE: ../../../flutter/shell/common/canvas_spy_unittests.cc
FILE: ../../../flutter/shell/common/display.h
FILE: ../../../flutter/shell/common/display_manager.cc
FILE: ../../../flutter/shell/common/display_manager.h
FILE: ../../../flutter/shell/common/engine.cc
FILE: ../../../flutter/shell/common/engine.h
FILE: ../../../flutter/shell/common/engine_unittests.cc
Expand Down
3 changes: 0 additions & 3 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ source_set("common") {
"animator.h",
"canvas_spy.cc",
"canvas_spy.h",
"display.h",
"display_manager.cc",
"display_manager.h",
"engine.cc",
"engine.h",
"isolate_configuration.cc",
Expand Down
4 changes: 4 additions & 0 deletions shell/common/animator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Animator::Animator(Delegate& delegate,

Animator::~Animator() = default;

float Animator::GetDisplayRefreshRate() const {
return waiter_->GetDisplayRefreshRate();
}

void Animator::Stop() {
paused_ = true;
}
Expand Down
2 changes: 2 additions & 0 deletions shell/common/animator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Animator final {

~Animator();

float GetDisplayRefreshRate() const;

void RequestFrame(bool regenerate_layer_tree = true);

void Render(std::unique_ptr<flutter::LayerTree> layer_tree);
Expand Down
55 changes: 0 additions & 55 deletions shell/common/display.h

This file was deleted.

49 changes: 0 additions & 49 deletions shell/common/display_manager.cc

This file was deleted.

59 changes: 0 additions & 59 deletions shell/common/display_manager.h

This file was deleted.

4 changes: 4 additions & 0 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Engine::Engine(Delegate& delegate,

Engine::~Engine() = default;

float Engine::GetDisplayRefreshRate() const {
return animator_->GetDisplayRefreshRate();
}

fml::WeakPtr<Engine> Engine::GetWeakPtr() const {
return weak_factory_.GetWeakPtr();
}
Expand Down
25 changes: 24 additions & 1 deletion shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "flutter/runtime/runtime_controller.h"
#include "flutter/runtime/runtime_delegate.h"
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/display_manager.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/pointer_data_dispatcher.h"
#include "flutter/shell/common/rasterizer.h"
Expand Down Expand Up @@ -329,6 +328,30 @@ class Engine final : public RuntimeDelegate,
///
~Engine() override;

//----------------------------------------------------------------------------
/// @brief Gets the refresh rate in frames per second of the vsync waiter
/// used by the animator managed by this engine. This information
/// is purely advisory and is not used by any component. It is
/// only used by the tooling to visualize frame performance.
///
/// @attention The display refresh rate is useless for frame scheduling
/// because it can vary and more accurate frame specific
/// information is given to the engine by the vsync waiter
/// already. However, this call is used by the tooling to ask very
/// high level questions about display refresh rate. For example,
/// "Is the display 60 or 120Hz?". This information is quite
/// unreliable (not available immediately on launch on some
/// platforms), variable and advisory. It must not be used by any
/// component that claims to use it to perform accurate frame
/// scheduling.
///
/// @return The display refresh rate in frames per second. This may change
/// from frame to frame, throughout the lifecycle of the
/// application, and, may not be available immediately upon
/// application launch.
///
float GetDisplayRefreshRate() const;

//----------------------------------------------------------------------------
/// @return The pointer to this instance of the engine. The engine may
/// only be accessed safely on the UI task runner.
Expand Down
4 changes: 1 addition & 3 deletions shell/common/rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ class Rasterizer final : public SnapshotDelegate {
///
virtual void OnFrameRasterized(const FrameTiming& frame_timing) = 0;

/// Time limit for a smooth frame.
///
/// See: `DisplayManager::GetMainDisplayRefreshRate`.
/// Time limit for a smooth frame. See `Engine::GetDisplayRefreshRate`.
virtual fml::Milliseconds GetFrameBudget() = 0;

/// Target time for the latest frame. See also `Shell::OnAnimatorBeginFrame`
Expand Down
26 changes: 11 additions & 15 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ Shell::Shell(DartVMRef vm, TaskRunners task_runners, Settings settings)
FML_DCHECK(task_runners_.IsValid());
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());

display_manager_ = std::make_unique<DisplayManager>();

// Generate a WeakPtrFactory for use with the raster thread. This does not
// need to wait on a latch because it can only ever be used from the raster
// thread from this class, so we have ordering guarantees.
Expand Down Expand Up @@ -576,6 +574,14 @@ bool Shell::Setup(std::unique_ptr<PlatformView> platform_view,
PersistentCache::GetCacheForProcess()->Purge();
}

// TODO(gw280): The WeakPtr here asserts that we are derefing it on the
// same thread as it was created on. Shell is constructed on the platform
// thread but we need to call into the Engine on the UI thread, so we need
// to use getUnsafe() here to avoid failing the assertion.
//
// https://github.com/flutter/flutter/issues/42947
display_refresh_rate_ = weak_engine_.getUnsafe()->GetDisplayRefreshRate();

return true;
}

Expand Down Expand Up @@ -1254,9 +1260,8 @@ void Shell::OnFrameRasterized(const FrameTiming& timing) {
}

fml::Milliseconds Shell::GetFrameBudget() {
double display_refresh_rate = display_manager_->GetMainDisplayRefreshRate();
if (display_refresh_rate > 0) {
return fml::RefreshRateToFrameBudget(display_refresh_rate);
if (display_refresh_rate_ > 0) {
return fml::RefreshRateToFrameBudget(display_refresh_rate_.load());
} else {
return fml::kDefaultFrameBudget;
}
Expand Down Expand Up @@ -1447,15 +1452,11 @@ bool Shell::OnServiceProtocolGetDisplayRefreshRate(
FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
response->SetObject();
response->AddMember("type", "DisplayRefreshRate", response->GetAllocator());
response->AddMember("fps", display_manager_->GetMainDisplayRefreshRate(),
response->AddMember("fps", engine_->GetDisplayRefreshRate(),
response->GetAllocator());
return true;
}

double Shell::GetMainDisplayRefreshRate() {
return display_manager_->GetMainDisplayRefreshRate();
}

bool Shell::OnServiceProtocolGetSkSLs(
const ServiceProtocol::Handler::ServiceProtocolMap& params,
rapidjson::Document* response) {
Expand Down Expand Up @@ -1617,9 +1618,4 @@ std::shared_ptr<fml::SyncSwitch> Shell::GetIsGpuDisabledSyncSwitch() const {
return is_gpu_disabled_sync_switch_;
}

void Shell::OnDisplayUpdates(DisplayUpdateType update_type,
std::vector<Display> displays) {
display_manager_->HandleDisplayUpdates(update_type, displays);
}

} // namespace flutter
21 changes: 6 additions & 15 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "flutter/runtime/dart_vm_lifecycle.h"
#include "flutter/runtime/service_protocol.h"
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/display_manager.h"
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h"
Expand Down Expand Up @@ -370,17 +369,6 @@ class Shell final : public PlatformView::Delegate,
///
DartVM* GetDartVM();

//----------------------------------------------------------------------------
/// @brief Notifies the display manager of the updates.
///
void OnDisplayUpdates(DisplayUpdateType update_type,
std::vector<Display> displays);

//----------------------------------------------------------------------------
/// @brief Queries the `DisplayManager` for the main display refresh rate.
///
double GetMainDisplayRefreshRate();

private:
using ServiceProtocolHandler =
std::function<bool(const ServiceProtocol::Handler::ServiceProtocolMap&,
Expand Down Expand Up @@ -430,9 +418,12 @@ class Shell final : public PlatformView::Delegate,
// here for easier conversions to Dart objects.
std::vector<int64_t> unreported_timings_;

/// Manages the displays. This class is thread safe, can be accessed from any
/// of the threads.
std::unique_ptr<DisplayManager> display_manager_;
// A cache of `Engine::GetDisplayRefreshRate` (only callable in the UI thread)
// so we can access it from `Rasterizer` (in the raster thread).
//
// The atomic is for extra thread safety as this is written in the UI thread
// and read from the raster thread.
std::atomic<float> display_refresh_rate_ = 0.0f;

// protects expected_frame_size_ which is set on platform thread and read on
// raster thread
Expand Down
4 changes: 4 additions & 0 deletions shell/common/vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
}
}

float VsyncWaiter::GetDisplayRefreshRate() const {
return kUnknownRefreshRateFPS;
}

} // namespace flutter
6 changes: 6 additions & 0 deletions shell/common/vsync_waiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class VsyncWaiter : public std::enable_shared_from_this<VsyncWaiter> {
/// See also |PointerDataDispatcher::ScheduleSecondaryVsyncCallback|.
void ScheduleSecondaryCallback(const fml::closure& callback);

static constexpr float kUnknownRefreshRateFPS = 0.0;

// Get the display's maximum refresh rate in the unit of frame per second.
// Return kUnknownRefreshRateFPS if the refresh rate is unknown.
virtual float GetDisplayRefreshRate() const;

protected:
// On some backends, the |FireCallback| needs to be made from a static C
// method.
Expand Down
Loading