5#include "flutter/shell/common/shell_test.h"
6#include "flutter/testing/testing.h"
59 std::vector<UnitlessTime>& events_consumed_at_frame,
60 bool restart_engine =
false) {
66 .simulate_vsync =
true,
71 configuration.SetEntrypoint(
"onPointerDataPacketMain");
76 events_consumed_at_frame.clear();
77 bool will_draw_new_frame =
true;
78 int events_consumed = 0;
80 auto nativeOnPointerDataPacket = [&events_consumed_at_frame,
81 &will_draw_new_frame, &events_consumed,
84 if (will_draw_new_frame) {
86 will_draw_new_frame =
false;
87 events_consumed_at_frame.push_back(events_consumed);
89 events_consumed_at_frame.back() = events_consumed;
95 ASSERT_TRUE(configuration.IsValid());
100 new_configuration.SetEntrypoint(
"onPointerDataPacketMain");
101 ASSERT_TRUE(new_configuration.IsValid());
106 ASSERT_GE(base_latency, 0);
109 int continuous_frame_count = 0;
110 for (
int i = 0;
i < num_events;
i += 1) {
112 int j =
static_cast<int>((delivery_time(
i) - base_latency) / frame_time);
113 if (j == continuous_frame_count) {
114 continuous_frame_count += 1;
116 double random_latency = delivery_time(
i) - j * frame_time - base_latency;
117 ASSERT_GE(random_latency, 0);
118 ASSERT_LT(random_latency, frame_time);
122 ASSERT_LT(j, continuous_frame_count);
127 auto simulation = std::async(std::launch::async, [&]() {
130 for (
int i = 0, j = 0;
i < num_events; j += 1) {
131 double t = j * frame_time;
132 while (
i < num_events && delivery_time(
i) <= t) {
157 ASSERT_GT(events_consumed_at_frame.size(), 0u);
158 ASSERT_EQ(events_consumed_at_frame.back(), num_events);
166 data.change = change;
170 data.pointer_identifier = 0;
172 data.physical_y = dy;
173 data.physical_delta_x = 0.0;
174 data.physical_delta_y = 0.0;
177 data.synthesized = 0;
179 data.pressure_min = 0.0;
180 data.pressure_max = 0.0;
182 data.distance_max = 0.0;
184 data.radius_major = 0.0;
185 data.radius_minor = 0.0;
186 data.radius_min = 0.0;
187 data.radius_max = 0.0;
188 data.orientation = 0.0;
190 data.platformData = 0;
191 data.scroll_delta_x = 0.0;
192 data.scroll_delta_y = 0.0;
201 Generator extreme = [frame_time, base_latency](
int i) {
203 i * frame_time + base_latency +
204 (
i % 2 == 0 ? 0.1 * frame_time : 0.9 * frame_time));
206 constexpr int n = 40;
207 std::vector<int> events_consumed_at_frame;
209 events_consumed_at_frame);
210 int frame_drawn = events_consumed_at_frame.size();
211 ASSERT_GE(frame_drawn, n - 1);
215 events_consumed_at_frame,
true );
216 int frame_drawn_after_restart = events_consumed_at_frame.size();
217 ASSERT_GE(frame_drawn_after_restart, n - 1);
225 Generator double_sampling = [frame_time, base_latency](
int i) {
226 return static_cast<UnitlessTime>(
i * 0.5 * frame_time + base_latency);
228 constexpr int n = 40;
229 std::vector<int> events_consumed_at_frame;
231 events_consumed_at_frame);
234 int frame_drawn = events_consumed_at_frame.size();
235 ASSERT_EQ(frame_drawn, n / 2 + 1);
237 for (
int i = 0;
i < n / 2;
i += 1) {
238 ASSERT_GE(events_consumed_at_frame[
i], 2 *
i - 1);
245 static constexpr double iphone_xs_times[] = {0.15,
292 constexpr int n =
sizeof(iphone_xs_times) /
sizeof(iphone_xs_times[0]);
296 double base_latency_f = 0.0;
297 for (
int i = 0;
i < 10;
i++) {
298 base_latency_f += 0.1;
303 Generator iphone_xs_generator = [frame_time, base_latency](
int i) {
304 return base_latency +
307 std::vector<int> events_consumed_at_frame;
309 frame_time, events_consumed_at_frame);
310 int frame_drawn = events_consumed_at_frame.size();
311 ASSERT_GE(frame_drawn, n - 1);
317 auto settings = CreateSettingsForFixture();
318 std::unique_ptr<Shell>
shell = CreateShell({
321 .simulate_vsync =
true,
326 configuration.SetEntrypoint(
"onPointerDataPacketMain");
329 std::vector<int64_t> result_sequence;
330 auto nativeOnPointerDataPacket = [&reportLatch, &result_sequence](
338 AddNativeCallback(
"NativeOnPointerDataPacket",
340 ASSERT_TRUE(configuration.IsValid());
341 RunEngine(
shell.get(), std::move(configuration));
343 auto packet = std::make_unique<PointerDataPacket>(6);
346 packet->SetPointerData(0,
data);
348 packet->SetPointerData(1,
data);
350 packet->SetPointerData(2,
data);
352 packet->SetPointerData(3,
data);
354 packet->SetPointerData(4,
data);
356 packet->SetPointerData(5,
data);
361 size_t expect_length = 6;
362 ASSERT_EQ(result_sequence.size(), expect_length);
376 DestroyShell(std::move(
shell));
382 auto settings = CreateSettingsForFixture();
383 std::unique_ptr<Shell>
shell = CreateShell({
386 .simulate_vsync =
true,
391 configuration.SetEntrypoint(
"onPointerDataPacketMain");
394 std::vector<int64_t> result_sequence;
395 auto nativeOnPointerDataPacket = [&reportLatch, &result_sequence](
403 AddNativeCallback(
"NativeOnPointerDataPacket",
405 ASSERT_TRUE(configuration.IsValid());
406 RunEngine(
shell.get(), std::move(configuration));
408 auto packet = std::make_unique<PointerDataPacket>(4);
411 packet->SetPointerData(0,
data);
413 packet->SetPointerData(1,
data);
415 packet->SetPointerData(2,
data);
417 packet->SetPointerData(3,
data);
422 size_t expect_length = 6;
423 ASSERT_EQ(result_sequence.size(), expect_length);
439 DestroyShell(std::move(
shell));
static bool IsInstanceRunning()
static RunConfiguration InferFromSettings(const Settings &settings, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
void AddNativeCallback(const std::string &name, Dart_NativeFunction callback)
static void RunEngine(Shell *shell, RunConfiguration configuration)
Settings CreateSettingsForFixture() override
TaskRunners GetTaskRunnersForFixture()
static void VSyncFlush(Shell *shell, bool *will_draw_new_frame=nullptr)
std::unique_ptr< Shell > CreateShell(const Settings &settings, std::optional< TaskRunners > task_runners={})
static void DispatchPointerData(Shell *shell, std::unique_ptr< PointerDataPacket > packet)
static void RestartEngine(Shell *shell, RunConfiguration configuration)
static void DispatchFakePointerData(Shell *shell, double x)
virtual void PostTask(const fml::closure &task) override
struct _Dart_Handle * Dart_Handle
struct _Dart_NativeArguments * Dart_NativeArguments
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
TEST_F(DisplayListTest, Defaults)
std::function< UnitlessTime(int)> Generator
void CreateSimulatedPointerData(PointerData &data, PointerData::Change change, int64_t device, double dx, double dy, int64_t buttons)
static void TestSimulatedInputEvents(ShellTest *fixture, int num_events, UnitlessTime base_latency, Generator delivery_time, UnitlessTime frame_time, std::vector< UnitlessTime > &events_consumed_at_frame, bool restart_engine=false)
constexpr int64_t kImplicitViewId
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
#define CREATE_NATIVE_ENTRY(native_entry)