Flutter Engine
vertices_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/lib/ui/painting/vertices.h"
6 
7 #include <memory>
8 
9 #include "flutter/common/task_runners.h"
10 #include "flutter/fml/synchronization/waitable_event.h"
11 #include "flutter/runtime/dart_vm.h"
12 #include "flutter/shell/common/shell_test.h"
13 #include "flutter/shell/common/thread_host.h"
14 #include "flutter/testing/testing.h"
15 
16 namespace flutter {
17 namespace testing {
18 
19 TEST_F(ShellTest, VerticesAccuratelyReportsSize) {
20  auto message_latch = std::make_shared<fml::AutoResetWaitableEvent>();
21 
22  auto nativeValidateVertices = [message_latch](Dart_NativeArguments args) {
23  auto handle = Dart_GetNativeArgument(args, 0);
24  intptr_t peer = 0;
25  Dart_Handle result = Dart_GetNativeInstanceField(
26  handle, tonic::DartWrappable::kPeerIndex, &peer);
27  ASSERT_FALSE(Dart_IsError(result));
28  Vertices* vertices = reinterpret_cast<Vertices*>(peer);
29  // GT because we don't want to be too dependent on platform specific
30  // differences, or minor changes to Skia. The actual value of this on
31  // macOS as of the test writing is 1441890ul. Just need to assert it's
32  // big enough to get the Dart GC's attention.
33  ASSERT_GT(vertices->GetAllocationSize(), 1300000ul);
34  message_latch->Signal();
35  };
36 
37  Settings settings = CreateSettingsForFixture();
38  TaskRunners task_runners("test", // label
39  GetCurrentTaskRunner(), // platform
40  CreateNewThread(), // raster
41  CreateNewThread(), // ui
42  CreateNewThread() // io
43  );
44 
45  AddNativeCallback("ValidateVertices",
46  CREATE_NATIVE_ENTRY(nativeValidateVertices));
47 
48  std::unique_ptr<Shell> shell =
49  CreateShell(std::move(settings), std::move(task_runners));
50 
51  ASSERT_TRUE(shell->IsSetup());
52  auto configuration = RunConfiguration::InferFromSettings(settings);
53  configuration.SetEntrypoint("createVertices");
54 
55  shell->RunEngine(std::move(configuration), [](auto result) {
56  ASSERT_EQ(result, Engine::RunStatus::Success);
57  });
58 
59  message_latch->Wait();
60  DestroyShell(std::move(shell), std::move(task_runners));
61 }
62 
63 } // namespace testing
64 } // namespace flutter
G_BEGIN_DECLS FlValue * args
static RunConfiguration InferFromSettings(const Settings &settings, fml::RefPtr< fml::TaskRunner > io_worker=nullptr)
Attempts to infer a run configuration from the settings object. This tries to create a run configurat...
#define CREATE_NATIVE_ENTRY(native_entry)
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)
size_t GetAllocationSize() const override
Definition: vertices.cc:97