Embedder API Support for display settings (flutter/engine#21355)
Embedders can now notify shell during startup about the various displays and their corresponding settings. Adds a notion of Display update type which can later include chages to displays during runtime such as addition / removal / reconfiguration of displays. We also remove the responsibility of providing the refresh rate from `vsync_waiter` to `DisplayManager`. Rewires existing platform implementations of the said API to use `Shell::OnDisplayUpdate` to notify the display manager of the startup configuration. DisplayManager is also thread-safe to account for rasterizer and UI thread accesses.
This commit is contained in:
@@ -599,6 +599,9 @@ 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
|
||||
|
||||
@@ -64,6 +64,9 @@ 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",
|
||||
|
||||
@@ -53,10 +53,6 @@ Animator::Animator(Delegate& delegate,
|
||||
|
||||
Animator::~Animator() = default;
|
||||
|
||||
float Animator::GetDisplayRefreshRate() const {
|
||||
return waiter_->GetDisplayRefreshRate();
|
||||
}
|
||||
|
||||
void Animator::Stop() {
|
||||
paused_ = true;
|
||||
}
|
||||
|
||||
@@ -47,8 +47,6 @@ class Animator final {
|
||||
|
||||
~Animator();
|
||||
|
||||
float GetDisplayRefreshRate() const;
|
||||
|
||||
void RequestFrame(bool regenerate_layer_tree = true);
|
||||
|
||||
void Render(std::unique_ptr<flutter::LayerTree> layer_tree);
|
||||
|
||||
55
engine/src/flutter/shell/common/display.h
Normal file
55
engine/src/flutter/shell/common/display.h
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_COMMON_DISPLAY_H_
|
||||
#define FLUTTER_SHELL_COMMON_DISPLAY_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace flutter {
|
||||
|
||||
/// Unique ID per display that is stable until the Flutter application restarts.
|
||||
/// See also: `flutter::Display`
|
||||
typedef uint64_t DisplayId;
|
||||
|
||||
/// To be used when the display refresh rate is unknown.
|
||||
static constexpr double kUnknownDisplayRefreshRate = 0;
|
||||
|
||||
/// Display refers to a graphics hardware system consisting of a framebuffer,
|
||||
/// typically a monitor or a screen. This class holds the various display
|
||||
/// settings.
|
||||
class Display {
|
||||
public:
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Construct a new Display object in case where the display id of the
|
||||
/// display is known. In cases where there is more than one display, every
|
||||
/// display is expected to have a display id.
|
||||
///
|
||||
Display(DisplayId display_id, double refresh_rate)
|
||||
: display_id_(display_id), refresh_rate_(refresh_rate) {}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Construct a new Display object when there is only a single display.
|
||||
/// When there are multiple displays, every display must have a display id.
|
||||
///
|
||||
explicit Display(double refresh_rate)
|
||||
: display_id_({}), refresh_rate_(refresh_rate) {}
|
||||
|
||||
~Display() = default;
|
||||
|
||||
// Get the display's maximum refresh rate in the unit of frame per second.
|
||||
// Return `kUnknownDisplayRefreshRate` if the refresh rate is unknown.
|
||||
double GetRefreshRate() const { return refresh_rate_; }
|
||||
|
||||
/// Returns the `DisplayId` of the display.
|
||||
std::optional<DisplayId> GetDisplayId() const { return display_id_; }
|
||||
|
||||
private:
|
||||
std::optional<DisplayId> display_id_;
|
||||
double refresh_rate_;
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_DISPLAY_H_
|
||||
49
engine/src/flutter/shell/common/display_manager.cc
Normal file
49
engine/src/flutter/shell/common/display_manager.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "flutter/shell/common/display_manager.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
DisplayManager::DisplayManager() = default;
|
||||
|
||||
DisplayManager::~DisplayManager() = default;
|
||||
|
||||
double DisplayManager::GetMainDisplayRefreshRate() const {
|
||||
std::scoped_lock lock(displays_mutex_);
|
||||
if (displays_.empty()) {
|
||||
return kUnknownDisplayRefreshRate;
|
||||
} else {
|
||||
return displays_[0].GetRefreshRate();
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::HandleDisplayUpdates(DisplayUpdateType update_type,
|
||||
std::vector<Display> displays) {
|
||||
std::scoped_lock lock(displays_mutex_);
|
||||
CheckDisplayConfiguration(displays);
|
||||
switch (update_type) {
|
||||
case DisplayUpdateType::kStartup:
|
||||
FML_CHECK(displays_.empty());
|
||||
displays_ = displays;
|
||||
return;
|
||||
default:
|
||||
FML_CHECK(false) << "Unknown DisplayUpdateType.";
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager::CheckDisplayConfiguration(
|
||||
std::vector<Display> displays) const {
|
||||
FML_CHECK(!displays.empty());
|
||||
if (displays.size() > 1) {
|
||||
for (auto& display : displays) {
|
||||
FML_CHECK(display.GetDisplayId().has_value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
59
engine/src/flutter/shell/common/display_manager.h
Normal file
59
engine/src/flutter/shell/common/display_manager.h
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_
|
||||
#define FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/shell/common/display.h"
|
||||
|
||||
namespace flutter {
|
||||
|
||||
/// The update type parameter that is passed to
|
||||
/// `DisplayManager::HandleDisplayUpdates`.
|
||||
enum class DisplayUpdateType {
|
||||
/// `flutter::Display`s that were active during start-up. A display is
|
||||
/// considered active if:
|
||||
/// 1. The frame buffer hardware is connected.
|
||||
/// 2. The display is drawable, e.g. it isn't being mirrored from another
|
||||
/// connected display or sleeping.
|
||||
kStartup
|
||||
};
|
||||
|
||||
/// Manages lifecycle of the connected displays. This class is thread-safe.
|
||||
class DisplayManager {
|
||||
public:
|
||||
DisplayManager();
|
||||
|
||||
~DisplayManager();
|
||||
|
||||
/// Returns the display refresh rate of the main display. In cases where there
|
||||
/// is only one display connected, it will return that. We do not yet support
|
||||
/// cases where there are multiple displays.
|
||||
///
|
||||
/// When there are no registered displays, it returns
|
||||
/// `kUnknownDisplayRefreshRate`.
|
||||
double GetMainDisplayRefreshRate() const;
|
||||
|
||||
/// Handles the display updates.
|
||||
void HandleDisplayUpdates(DisplayUpdateType update_type,
|
||||
std::vector<Display> displays);
|
||||
|
||||
private:
|
||||
/// Guards `displays_` vector.
|
||||
mutable std::mutex displays_mutex_;
|
||||
std::vector<Display> displays_;
|
||||
|
||||
/// Checks that the provided display configuration is valid. Currently this
|
||||
/// ensures that all the displays have an id in the case there are multiple
|
||||
/// displays. In case where there is a single display, it is valid for the
|
||||
/// display to not have an id.
|
||||
void CheckDisplayConfiguration(std::vector<Display> displays) const;
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
#endif // FLUTTER_SHELL_COMMON_DISPLAY_MANAGER_H_
|
||||
@@ -97,10 +97,6 @@ Engine::Engine(Delegate& delegate,
|
||||
|
||||
Engine::~Engine() = default;
|
||||
|
||||
float Engine::GetDisplayRefreshRate() const {
|
||||
return animator_->GetDisplayRefreshRate();
|
||||
}
|
||||
|
||||
fml::WeakPtr<Engine> Engine::GetWeakPtr() const {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#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"
|
||||
@@ -328,30 +329,6 @@ 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.
|
||||
|
||||
@@ -68,7 +68,9 @@ class Rasterizer final : public SnapshotDelegate {
|
||||
///
|
||||
virtual void OnFrameRasterized(const FrameTiming& frame_timing) = 0;
|
||||
|
||||
/// Time limit for a smooth frame. See `Engine::GetDisplayRefreshRate`.
|
||||
/// Time limit for a smooth frame.
|
||||
///
|
||||
/// See: `DisplayManager::GetMainDisplayRefreshRate`.
|
||||
virtual fml::Milliseconds GetFrameBudget() = 0;
|
||||
|
||||
/// Target time for the latest frame. See also `Shell::OnAnimatorBeginFrame`
|
||||
|
||||
@@ -333,6 +333,8 @@ 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.
|
||||
@@ -574,14 +576,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -1260,8 +1254,9 @@ void Shell::OnFrameRasterized(const FrameTiming& timing) {
|
||||
}
|
||||
|
||||
fml::Milliseconds Shell::GetFrameBudget() {
|
||||
if (display_refresh_rate_ > 0) {
|
||||
return fml::RefreshRateToFrameBudget(display_refresh_rate_.load());
|
||||
double display_refresh_rate = display_manager_->GetMainDisplayRefreshRate();
|
||||
if (display_refresh_rate > 0) {
|
||||
return fml::RefreshRateToFrameBudget(display_refresh_rate);
|
||||
} else {
|
||||
return fml::kDefaultFrameBudget;
|
||||
}
|
||||
@@ -1452,11 +1447,15 @@ bool Shell::OnServiceProtocolGetDisplayRefreshRate(
|
||||
FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
|
||||
response->SetObject();
|
||||
response->AddMember("type", "DisplayRefreshRate", response->GetAllocator());
|
||||
response->AddMember("fps", engine_->GetDisplayRefreshRate(),
|
||||
response->AddMember("fps", display_manager_->GetMainDisplayRefreshRate(),
|
||||
response->GetAllocator());
|
||||
return true;
|
||||
}
|
||||
|
||||
double Shell::GetMainDisplayRefreshRate() {
|
||||
return display_manager_->GetMainDisplayRefreshRate();
|
||||
}
|
||||
|
||||
bool Shell::OnServiceProtocolGetSkSLs(
|
||||
const ServiceProtocol::Handler::ServiceProtocolMap& params,
|
||||
rapidjson::Document* response) {
|
||||
@@ -1618,4 +1617,9 @@ 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
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#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"
|
||||
@@ -369,6 +370,17 @@ 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&,
|
||||
@@ -418,12 +430,9 @@ class Shell final : public PlatformView::Delegate,
|
||||
// here for easier conversions to Dart objects.
|
||||
std::vector<int64_t> unreported_timings_;
|
||||
|
||||
// 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;
|
||||
/// Manages the displays. This class is thread safe, can be accessed from any
|
||||
/// of the threads.
|
||||
std::unique_ptr<DisplayManager> display_manager_;
|
||||
|
||||
// protects expected_frame_size_ which is set on platform thread and read on
|
||||
// raster thread
|
||||
|
||||
@@ -134,8 +134,4 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
|
||||
}
|
||||
}
|
||||
|
||||
float VsyncWaiter::GetDisplayRefreshRate() const {
|
||||
return kUnknownRefreshRateFPS;
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -30,12 +30,6 @@ 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.
|
||||
|
||||
@@ -75,6 +75,8 @@ AndroidShellHolder::AndroidShellHolder(
|
||||
);
|
||||
}
|
||||
weak_platform_view = platform_view_android->GetWeakPtr();
|
||||
shell.OnDisplayUpdates(DisplayUpdateType::kStartup,
|
||||
{Display(jni_facade->GetDisplayRefreshRate())});
|
||||
return platform_view_android;
|
||||
};
|
||||
|
||||
|
||||
@@ -93,6 +93,8 @@ class JNIMock final : public PlatformViewAndroidJNI {
|
||||
FlutterViewComputePlatformResolvedLocale,
|
||||
(std::vector<std::string> supported_locales_data),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(double, GetDisplayRefreshRate, (), (override));
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -193,6 +193,8 @@ class PlatformViewAndroidJNI {
|
||||
virtual std::unique_ptr<std::vector<std::string>>
|
||||
FlutterViewComputePlatformResolvedLocale(
|
||||
std::vector<std::string> supported_locales_data) = 0;
|
||||
|
||||
virtual double GetDisplayRefreshRate() = 0;
|
||||
};
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -1315,4 +1315,21 @@ PlatformViewAndroidJNIImpl::FlutterViewComputePlatformResolvedLocale(
|
||||
return out;
|
||||
}
|
||||
|
||||
double PlatformViewAndroidJNIImpl::GetDisplayRefreshRate() {
|
||||
JNIEnv* env = fml::jni::AttachCurrentThread();
|
||||
|
||||
auto java_object = java_object_.get(env);
|
||||
if (java_object.is_null()) {
|
||||
return kUnknownDisplayRefreshRate;
|
||||
}
|
||||
|
||||
jclass clazz = env->GetObjectClass(java_object.obj());
|
||||
if (clazz == nullptr) {
|
||||
return kUnknownDisplayRefreshRate;
|
||||
}
|
||||
|
||||
jfieldID fid = env->GetStaticFieldID(clazz, "refreshRateFPS", "F");
|
||||
return static_cast<double>(env->GetStaticFloatField(clazz, fid));
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@@ -78,6 +78,8 @@ class PlatformViewAndroidJNIImpl final : public PlatformViewAndroidJNI {
|
||||
FlutterViewComputePlatformResolvedLocale(
|
||||
std::vector<std::string> supported_locales_data) override;
|
||||
|
||||
double GetDisplayRefreshRate() override;
|
||||
|
||||
private:
|
||||
// Reference to FlutterJNI object.
|
||||
const fml::jni::JavaObjectWeakGlobalRef java_object_;
|
||||
|
||||
@@ -38,19 +38,6 @@ void VsyncWaiterAndroid::AwaitVSync() {
|
||||
});
|
||||
}
|
||||
|
||||
float VsyncWaiterAndroid::GetDisplayRefreshRate() const {
|
||||
JNIEnv* env = fml::jni::AttachCurrentThread();
|
||||
if (g_vsync_waiter_class == nullptr) {
|
||||
return kUnknownRefreshRateFPS;
|
||||
}
|
||||
jclass clazz = g_vsync_waiter_class->obj();
|
||||
if (clazz == nullptr) {
|
||||
return kUnknownRefreshRateFPS;
|
||||
}
|
||||
jfieldID fid = env->GetStaticFieldID(clazz, "refreshRateFPS", "F");
|
||||
return env->GetStaticFloatField(clazz, fid);
|
||||
}
|
||||
|
||||
// static
|
||||
void VsyncWaiterAndroid::OnNativeVsync(JNIEnv* env,
|
||||
jclass jcaller,
|
||||
|
||||
@@ -22,8 +22,6 @@ class VsyncWaiterAndroid final : public VsyncWaiter {
|
||||
|
||||
~VsyncWaiterAndroid() override;
|
||||
|
||||
float GetDisplayRefreshRate() const override;
|
||||
|
||||
private:
|
||||
// |VsyncWaiter|
|
||||
void AwaitVSync() override;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/connection_collection.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h"
|
||||
#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h"
|
||||
#import "flutter/shell/platform/darwin/ios/ios_surface.h"
|
||||
#import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
|
||||
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
|
||||
@@ -539,6 +540,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
} else {
|
||||
[self setupChannels];
|
||||
[self onLocaleUpdated:nil];
|
||||
[self initializeDisplays];
|
||||
if (!_platformViewsController) {
|
||||
_platformViewsController.reset(new flutter::FlutterPlatformViewsController());
|
||||
}
|
||||
@@ -553,6 +555,12 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
return _shell != nullptr;
|
||||
}
|
||||
|
||||
- (void)initializeDisplays {
|
||||
double refresh_rate = [[[DisplayLinkManager alloc] init] displayRefreshRate];
|
||||
auto display = flutter::Display(refresh_rate);
|
||||
_shell->OnDisplayUpdates(flutter::DisplayUpdateType::kStartup, {display});
|
||||
}
|
||||
|
||||
- (BOOL)run {
|
||||
return [self runWithEntrypoint:FlutterDefaultDartEntrypoint
|
||||
libraryURI:nil
|
||||
|
||||
@@ -10,7 +10,33 @@
|
||||
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
|
||||
#include "flutter/shell/common/vsync_waiter.h"
|
||||
|
||||
@class VSyncClient;
|
||||
@interface DisplayLinkManager : NSObject
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief The display refresh rate used for reporting purposes. The engine does not care
|
||||
/// about this for frame scheduling. It is only used by tools for instrumentation. The
|
||||
/// engine uses the duration field of the link per frame for frame scheduling.
|
||||
///
|
||||
/// @attention Do not use the this call in frame scheduling. It is only meant for reporting.
|
||||
///
|
||||
/// @return The refresh rate in frames per second.
|
||||
///
|
||||
- (double)displayRefreshRate;
|
||||
|
||||
@end
|
||||
|
||||
@interface VSyncClient : NSObject
|
||||
|
||||
- (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
|
||||
callback:(flutter::VsyncWaiter::Callback)callback;
|
||||
|
||||
- (void)await;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
namespace flutter {
|
||||
|
||||
@@ -26,9 +52,6 @@ class VsyncWaiterIOS final : public VsyncWaiter {
|
||||
// |VsyncWaiter|
|
||||
void AwaitVSync() override;
|
||||
|
||||
// |VsyncWaiter|
|
||||
float GetDisplayRefreshRate() const override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(VsyncWaiterIOS);
|
||||
};
|
||||
|
||||
|
||||
@@ -15,28 +15,6 @@
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
|
||||
@interface VSyncClient : NSObject
|
||||
|
||||
- (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
|
||||
callback:(flutter::VsyncWaiter::Callback)callback;
|
||||
|
||||
- (void)await;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief The display refresh rate used for reporting purposes. The engine does not care
|
||||
/// about this for frame scheduling. It is only used by tools for instrumentation. The
|
||||
/// engine uses the duration field of the link per frame for frame scheduling.
|
||||
///
|
||||
/// @attention Do not use the this call in frame scheduling. It is only meant for reporting.
|
||||
///
|
||||
/// @return The refresh rate in frames per second.
|
||||
///
|
||||
- (float)displayRefreshRate;
|
||||
|
||||
@end
|
||||
|
||||
namespace flutter {
|
||||
|
||||
VsyncWaiterIOS::VsyncWaiterIOS(flutter::TaskRunners task_runners)
|
||||
@@ -57,16 +35,11 @@ void VsyncWaiterIOS::AwaitVSync() {
|
||||
[client_.get() await];
|
||||
}
|
||||
|
||||
// |VsyncWaiter|
|
||||
float VsyncWaiterIOS::GetDisplayRefreshRate() const {
|
||||
return [client_.get() displayRefreshRate];
|
||||
}
|
||||
|
||||
} // namespace flutter
|
||||
|
||||
@implementation VSyncClient {
|
||||
flutter::VsyncWaiter::Callback callback_;
|
||||
fml::scoped_nsobject<CADisplayLink> display_link_;
|
||||
CADisplayLink* display_link_;
|
||||
}
|
||||
|
||||
- (instancetype)initWithTaskRunner:(fml::RefPtr<fml::TaskRunner>)task_runner
|
||||
@@ -75,14 +48,11 @@ float VsyncWaiterIOS::GetDisplayRefreshRate() const {
|
||||
|
||||
if (self) {
|
||||
callback_ = std::move(callback);
|
||||
display_link_ = fml::scoped_nsobject<CADisplayLink> {
|
||||
[[CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)] retain]
|
||||
};
|
||||
display_link_.get().paused = YES;
|
||||
display_link_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)];
|
||||
display_link_.paused = YES;
|
||||
|
||||
task_runner->PostTask([client = [self retain]]() {
|
||||
[client->display_link_.get() addToRunLoop:[NSRunLoop currentRunLoop]
|
||||
forMode:NSRunLoopCommonModes];
|
||||
[client->display_link_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
|
||||
[client release];
|
||||
});
|
||||
}
|
||||
@@ -90,9 +60,52 @@ float VsyncWaiterIOS::GetDisplayRefreshRate() const {
|
||||
return self;
|
||||
}
|
||||
|
||||
- (float)displayRefreshRate {
|
||||
- (void)await {
|
||||
display_link_.paused = NO;
|
||||
}
|
||||
|
||||
- (void)onDisplayLink:(CADisplayLink*)link {
|
||||
TRACE_EVENT0("flutter", "VSYNC");
|
||||
|
||||
CFTimeInterval delay = CACurrentMediaTime() - link.timestamp;
|
||||
fml::TimePoint frame_start_time = fml::TimePoint::Now() - fml::TimeDelta::FromSecondsF(delay);
|
||||
fml::TimePoint frame_target_time = frame_start_time + fml::TimeDelta::FromSecondsF(link.duration);
|
||||
|
||||
display_link_.paused = YES;
|
||||
|
||||
callback_(frame_start_time, frame_target_time);
|
||||
}
|
||||
|
||||
- (void)invalidate {
|
||||
[display_link_ invalidate];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self invalidate];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation DisplayLinkManager {
|
||||
CADisplayLink* display_link_;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
display_link_ = [CADisplayLink displayLinkWithTarget:self selector:@selector(onDisplayLink:)];
|
||||
display_link_.paused = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (double)displayRefreshRate {
|
||||
if (@available(iOS 10.3, *)) {
|
||||
auto preferredFPS = display_link_.get().preferredFramesPerSecond; // iOS 10.0
|
||||
auto preferredFPS = display_link_.preferredFramesPerSecond; // iOS 10.0
|
||||
|
||||
// From Docs:
|
||||
// The default value for preferredFramesPerSecond is 0. When this value is 0, the preferred
|
||||
@@ -109,29 +122,12 @@ float VsyncWaiterIOS::GetDisplayRefreshRate() const {
|
||||
}
|
||||
}
|
||||
|
||||
- (void)await {
|
||||
display_link_.get().paused = NO;
|
||||
}
|
||||
|
||||
- (void)onDisplayLink:(CADisplayLink*)link {
|
||||
TRACE_EVENT0("flutter", "VSYNC");
|
||||
|
||||
CFTimeInterval delay = CACurrentMediaTime() - link.timestamp;
|
||||
fml::TimePoint frame_start_time = fml::TimePoint::Now() - fml::TimeDelta::FromSecondsF(delay);
|
||||
fml::TimePoint frame_target_time = frame_start_time + fml::TimeDelta::FromSecondsF(link.duration);
|
||||
|
||||
display_link_.get().paused = YES;
|
||||
|
||||
callback_(frame_start_time, frame_target_time);
|
||||
}
|
||||
|
||||
- (void)invalidate {
|
||||
// [CADisplayLink invalidate] is thread-safe.
|
||||
[display_link_.get() invalidate];
|
||||
// no-op.
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[self invalidate];
|
||||
[display_link_ invalidate];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -1955,3 +1956,58 @@ FlutterEngineResult FlutterEnginePostCallbackOnAllNativeThreads(
|
||||
"Internal error while attempting to post "
|
||||
"tasks to all threads.");
|
||||
}
|
||||
|
||||
namespace {
|
||||
static bool ValidDisplayConfiguration(const FlutterEngineDisplay* displays,
|
||||
size_t display_count) {
|
||||
std::set<FlutterEngineDisplayId> display_ids;
|
||||
for (size_t i = 0; i < display_count; i++) {
|
||||
if (displays[i].single_display && display_count != 1) {
|
||||
return false;
|
||||
}
|
||||
display_ids.insert(displays[i].display_id);
|
||||
}
|
||||
|
||||
return display_ids.size() == display_count;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
|
||||
FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
|
||||
const FlutterEngineDisplaysUpdateType update_type,
|
||||
const FlutterEngineDisplay* embedder_displays,
|
||||
size_t display_count) {
|
||||
if (raw_engine == nullptr) {
|
||||
return LOG_EMBEDDER_ERROR(kInvalidArguments, "Invalid engine handle.");
|
||||
}
|
||||
|
||||
if (!ValidDisplayConfiguration(embedder_displays, display_count)) {
|
||||
return LOG_EMBEDDER_ERROR(
|
||||
kInvalidArguments,
|
||||
"Invalid FlutterEngineDisplay configuration specified.");
|
||||
}
|
||||
|
||||
auto engine = reinterpret_cast<flutter::EmbedderEngine*>(raw_engine);
|
||||
|
||||
switch (update_type) {
|
||||
case kFlutterEngineDisplaysUpdateTypeStartup: {
|
||||
std::vector<flutter::Display> displays;
|
||||
for (size_t i = 0; i < display_count; i++) {
|
||||
flutter::Display display =
|
||||
flutter::Display(embedder_displays[i].refresh_rate);
|
||||
if (!embedder_displays[i].single_display) {
|
||||
display = flutter::Display(embedder_displays[i].display_id,
|
||||
embedder_displays[i].refresh_rate);
|
||||
}
|
||||
displays.push_back(display);
|
||||
}
|
||||
engine->GetShell().OnDisplayUpdates(flutter::DisplayUpdateType::kStartup,
|
||||
displays);
|
||||
return kSuccess;
|
||||
}
|
||||
default:
|
||||
return LOG_EMBEDDER_ERROR(
|
||||
kInvalidArguments,
|
||||
"Invalid FlutterEngineDisplaysUpdateType type specified.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -963,6 +963,56 @@ typedef const FlutterLocale* (*FlutterComputePlatformResolvedLocaleCallback)(
|
||||
const FlutterLocale** /* supported_locales*/,
|
||||
size_t /* Number of locales*/);
|
||||
|
||||
/// Display refers to a graphics hardware system consisting of a framebuffer,
|
||||
/// typically a monitor or a screen. This ID is unique per display and is
|
||||
/// stable until the Flutter application restarts.
|
||||
typedef uint64_t FlutterEngineDisplayId;
|
||||
|
||||
typedef struct {
|
||||
/// This size of this struct. Must be sizeof(FlutterDisplay).
|
||||
size_t struct_size;
|
||||
|
||||
FlutterEngineDisplayId display_id;
|
||||
|
||||
/// This is set to true if the embedder only has one display. In cases where
|
||||
/// this is set to true, the value of display_id is ignored. In cases where
|
||||
/// this is not set to true, it is expected that a valid display_id be
|
||||
/// provided.
|
||||
bool single_display;
|
||||
|
||||
/// This represents the refresh period in frames per second. This value may be
|
||||
/// zero if the device is not running or unavaliable or unknown.
|
||||
double refresh_rate;
|
||||
} FlutterEngineDisplay;
|
||||
|
||||
/// The update type parameter that is passed to
|
||||
/// `FlutterEngineNotifyDisplayUpdate`.
|
||||
typedef enum {
|
||||
/// `FlutterEngineDisplay`s that were active during start-up. A display is
|
||||
/// considered active if:
|
||||
/// 1. The frame buffer hardware is connected.
|
||||
/// 2. The display is drawable, e.g. it isn't being mirrored from another
|
||||
/// connected display or sleeping.
|
||||
kFlutterEngineDisplaysUpdateTypeStartup,
|
||||
kFlutterEngineDisplaysUpdateTypeCount,
|
||||
} FlutterEngineDisplaysUpdateType;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Posts updates corresponding to display changes to a running engine
|
||||
/// instance.
|
||||
///
|
||||
/// @param[in] update_type The type of update pushed to the engine.
|
||||
/// @param[in] displays The displays affected by this update.
|
||||
/// @param[in] display_count Size of the displays array, must be at least 1.
|
||||
///
|
||||
/// @return the result of the call made to the engine.
|
||||
///
|
||||
FlutterEngineResult FlutterEngineNotifyDisplayUpdate(
|
||||
FLUTTER_API_SYMBOL(FlutterEngine) engine,
|
||||
FlutterEngineDisplaysUpdateType update_type,
|
||||
const FlutterEngineDisplay* displays,
|
||||
size_t display_count);
|
||||
|
||||
typedef int64_t FlutterEngineDartPort;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -3127,5 +3127,230 @@ TEST_F(EmbedderTest, PresentInfoContainsValidFBOId) {
|
||||
frame_latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, SetSingleDisplayConfigurationWithDisplayId) {
|
||||
auto& context = GetEmbedderContext(ContextType::kOpenGLContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint("empty_scene");
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest",
|
||||
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
FlutterEngineDisplay display;
|
||||
display.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display.display_id = 1;
|
||||
display.refresh_rate = 20;
|
||||
|
||||
std::vector<FlutterEngineDisplay> displays = {display};
|
||||
|
||||
const FlutterEngineResult result = FlutterEngineNotifyDisplayUpdate(
|
||||
engine.get(), kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
|
||||
displays.size());
|
||||
ASSERT_EQ(result, kSuccess);
|
||||
|
||||
flutter::Shell& shell = ToEmbedderEngine(engine.get())->GetShell();
|
||||
ASSERT_EQ(shell.GetMainDisplayRefreshRate(), display.refresh_rate);
|
||||
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 800;
|
||||
event.height = 600;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, SetSingleDisplayConfigurationWithoutDisplayId) {
|
||||
auto& context = GetEmbedderContext(ContextType::kOpenGLContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint("empty_scene");
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest",
|
||||
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
FlutterEngineDisplay display;
|
||||
display.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display.single_display = true;
|
||||
display.refresh_rate = 20;
|
||||
|
||||
std::vector<FlutterEngineDisplay> displays = {display};
|
||||
|
||||
const FlutterEngineResult result = FlutterEngineNotifyDisplayUpdate(
|
||||
engine.get(), kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
|
||||
displays.size());
|
||||
ASSERT_EQ(result, kSuccess);
|
||||
|
||||
flutter::Shell& shell = ToEmbedderEngine(engine.get())->GetShell();
|
||||
ASSERT_EQ(shell.GetMainDisplayRefreshRate(), display.refresh_rate);
|
||||
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 800;
|
||||
event.height = 600;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, SetValidMultiDisplayConfiguration) {
|
||||
auto& context = GetEmbedderContext(ContextType::kOpenGLContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint("empty_scene");
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest",
|
||||
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
FlutterEngineDisplay display_1;
|
||||
display_1.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_1.display_id = 1;
|
||||
display_1.single_display = false;
|
||||
display_1.refresh_rate = 20;
|
||||
|
||||
FlutterEngineDisplay display_2;
|
||||
display_2.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_2.display_id = 2;
|
||||
display_2.single_display = false;
|
||||
display_2.refresh_rate = 60;
|
||||
|
||||
std::vector<FlutterEngineDisplay> displays = {display_1, display_2};
|
||||
|
||||
const FlutterEngineResult result = FlutterEngineNotifyDisplayUpdate(
|
||||
engine.get(), kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
|
||||
displays.size());
|
||||
ASSERT_EQ(result, kSuccess);
|
||||
|
||||
flutter::Shell& shell = ToEmbedderEngine(engine.get())->GetShell();
|
||||
ASSERT_EQ(shell.GetMainDisplayRefreshRate(), display_1.refresh_rate);
|
||||
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 800;
|
||||
event.height = 600;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, MultipleDisplaysWithSingleDisplayTrueIsInvalid) {
|
||||
auto& context = GetEmbedderContext(ContextType::kOpenGLContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint("empty_scene");
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest",
|
||||
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
FlutterEngineDisplay display_1;
|
||||
display_1.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_1.display_id = 1;
|
||||
display_1.single_display = true;
|
||||
display_1.refresh_rate = 20;
|
||||
|
||||
FlutterEngineDisplay display_2;
|
||||
display_2.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_2.display_id = 2;
|
||||
display_2.single_display = true;
|
||||
display_2.refresh_rate = 60;
|
||||
|
||||
std::vector<FlutterEngineDisplay> displays = {display_1, display_2};
|
||||
|
||||
const FlutterEngineResult result = FlutterEngineNotifyDisplayUpdate(
|
||||
engine.get(), kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
|
||||
displays.size());
|
||||
ASSERT_NE(result, kSuccess);
|
||||
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 800;
|
||||
event.height = 600;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
TEST_F(EmbedderTest, MultipleDisplaysWithSameDisplayIdIsInvalid) {
|
||||
auto& context = GetEmbedderContext(ContextType::kOpenGLContext);
|
||||
|
||||
EmbedderConfigBuilder builder(context);
|
||||
builder.SetOpenGLRendererConfig(SkISize::Make(800, 600));
|
||||
builder.SetCompositor();
|
||||
builder.SetDartEntrypoint("empty_scene");
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
context.AddNativeCallback(
|
||||
"SignalNativeTest",
|
||||
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
|
||||
|
||||
auto engine = builder.LaunchEngine();
|
||||
|
||||
ASSERT_TRUE(engine.is_valid());
|
||||
|
||||
FlutterEngineDisplay display_1;
|
||||
display_1.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_1.display_id = 1;
|
||||
display_1.single_display = false;
|
||||
display_1.refresh_rate = 20;
|
||||
|
||||
FlutterEngineDisplay display_2;
|
||||
display_2.struct_size = sizeof(FlutterEngineDisplay);
|
||||
display_2.display_id = 1;
|
||||
display_2.single_display = false;
|
||||
display_2.refresh_rate = 60;
|
||||
|
||||
std::vector<FlutterEngineDisplay> displays = {display_1, display_2};
|
||||
|
||||
const FlutterEngineResult result = FlutterEngineNotifyDisplayUpdate(
|
||||
engine.get(), kFlutterEngineDisplaysUpdateTypeStartup, displays.data(),
|
||||
displays.size());
|
||||
ASSERT_NE(result, kSuccess);
|
||||
|
||||
FlutterWindowMetricsEvent event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
event.width = 800;
|
||||
event.height = 600;
|
||||
event.pixel_ratio = 1.0;
|
||||
ASSERT_EQ(FlutterEngineSendWindowMetricsEvent(engine.get(), &event),
|
||||
kSuccess);
|
||||
|
||||
latch.Wait();
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
Reference in New Issue
Block a user