Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_unittests_util.h
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#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_UNITTESTS_UTIL_H_
6#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_UNITTESTS_UTIL_H_
7
8#define FML_USED_ON_EMBEDDER
9
10#include <future>
11#include <utility>
12
13#include "flutter/fml/mapping.h"
14#include "flutter/fml/message_loop.h"
15#include "flutter/fml/paths.h"
16#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
17#include "flutter/shell/platform/embedder/tests/embedder_config_builder.h"
18#include "flutter/shell/platform/embedder/tests/embedder_test.h"
20
21namespace flutter {
22namespace testing {
23
25 GrDirectContext* context);
26
28
29/// @brief Prepends a prefix to the name which is unique to the test
30/// context type. This is useful for tests that use
31/// EmbedderTestMultiBackend and require different fixtures per
32/// backend. For OpenGL, the name remains unchanged.
33/// @param[in] backend The test context type used to determine the prepended
34/// prefix (e.g. `vk_[name]` for Vulkan).
35/// @param[in] name The name of the fixture without any special prefixes.
37 const std::string& name);
38
39/// @brief Resolves a render target type for a given backend description.
40/// This is useful for tests that use EmbedderTestMultiBackend.
41/// @param[in] backend The test context type to resolve the render
42/// target for.
43/// @param[in] opengl_framebuffer Ignored for all non-OpenGL backends. Flutter
44/// supports rendering to both OpenGL textures
45/// and framebuffers. When false, the OpenGL
46/// texture render target type is returned.
49 bool opengl_framebuffer);
50
51/// @brief Configures per-backend properties for a given backing store.
52/// @param[in] backing_store The backing store to configure.
53/// @param[in] backend The test context type used to decide which
54/// backend the backing store will be used with.
55/// @param[in] opengl_framebuffer Ignored for all non-OpenGL backends. Flutter
56/// supports rendering to both OpenGL textures
57/// and framebuffers. When false, the backing
58/// store is configured to be an OpenGL texture.
61 bool opengl_framebuffer);
62
63bool WriteImageToDisk(const fml::UniqueFD& directory,
64 const std::string& name,
65 const sk_sp<SkImage>& image);
66
67bool ImageMatchesFixture(const std::string& fixture_file_name,
68 const sk_sp<SkImage>& scene_image);
69
70bool ImageMatchesFixture(const std::string& fixture_file_name,
71 std::future<sk_sp<SkImage>>& scene_image);
72
74 const std::vector<uint8_t>& bytes);
75
76bool SurfacePixelDataMatchesBytes(std::future<SkSurface*>& surface_future,
77 const std::vector<uint8_t>& bytes);
78
80 const FlutterPlatformViewMutation** mutations,
81 size_t count,
83 const std::function<void(const FlutterPlatformViewMutation& mutation)>&
84 handler);
85
87 const FlutterPlatformView* view,
89 const std::function<void(const FlutterPlatformViewMutation& mutation)>&
90 handler);
91
93 const FlutterPlatformViewMutation** mutations,
94 size_t count);
95
97
98//------------------------------------------------------------------------------
99/// @brief A task runner that we expect the embedder to provide but whose
100/// implementation is a real FML task runner.
101///
103 public:
104 using TaskExpiryCallback = std::function<void(FlutterTask)>;
106 TaskExpiryCallback on_task_expired)
107 : identifier_(++sEmbedderTaskRunnerIdentifiers),
108 real_task_runner_(std::move(real_task_runner)),
109 on_task_expired_(std::move(on_task_expired)) {
110 FML_CHECK(real_task_runner_);
111 FML_CHECK(on_task_expired_);
112
113 task_runner_description_.struct_size = sizeof(FlutterTaskRunnerDescription);
114 task_runner_description_.user_data = this;
115 task_runner_description_.runs_task_on_current_thread_callback =
116 [](void* user_data) -> bool {
117 return reinterpret_cast<EmbedderTestTaskRunner*>(user_data)
118 ->real_task_runner_->RunsTasksOnCurrentThread();
119 };
120 task_runner_description_.post_task_callback = [](FlutterTask task,
121 uint64_t target_time_nanos,
122 void* user_data) -> void {
123 auto thiz = reinterpret_cast<EmbedderTestTaskRunner*>(user_data);
124
125 auto target_time = fml::TimePoint::FromEpochDelta(
126 fml::TimeDelta::FromNanoseconds(target_time_nanos));
127 auto on_task_expired = thiz->on_task_expired_;
128 auto invoke_task = [task, on_task_expired]() { on_task_expired(task); };
129 auto real_task_runner = thiz->real_task_runner_;
130
131 real_task_runner->PostTaskForTime(invoke_task, target_time);
132 };
133 task_runner_description_.identifier = identifier_;
134 }
135
137 return task_runner_description_;
138 }
139
140 private:
141 static std::atomic_size_t sEmbedderTaskRunnerIdentifiers;
142 const size_t identifier_;
143 fml::RefPtr<fml::TaskRunner> real_task_runner_;
144 TaskExpiryCallback on_task_expired_;
145 FlutterTaskRunnerDescription task_runner_description_ = {};
146
147 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestTaskRunner);
148};
149
150} // namespace testing
151} // namespace flutter
152
153#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_UNITTESTS_UTIL_H_
const char * backend
int count
A task runner that we expect the embedder to provide but whose implementation is a real FML task runn...
const FlutterTaskRunnerDescription & GetFlutterTaskRunnerDescription()
EmbedderTestTaskRunner(fml::RefPtr< fml::TaskRunner > real_task_runner, TaskExpiryCallback on_task_expired)
std::function< void(FlutterTask)> TaskExpiryCallback
virtual bool RunsTasksOnCurrentThread()
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition time_delta.h:40
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition time_point.h:43
FlutterPlatformViewMutationType
Definition embedder.h:1686
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
static bool b
struct MyStruct a[10]
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
bool WriteImageToDisk(const fml::UniqueFD &directory, const std::string &name, const sk_sp< SkImage > &image)
sk_sp< SkSurface > CreateRenderSurface(const FlutterLayer &layer, GrDirectContext *context)
void FilterMutationsByType(const FlutterPlatformViewMutation **mutations, size_t count, FlutterPlatformViewMutationType type, const std::function< void(const FlutterPlatformViewMutation &mutation)> &handler)
bool SurfacePixelDataMatchesBytes(SkSurface *surface, const std::vector< uint8_t > &bytes)
void ConfigureBackingStore(FlutterBackingStore &backing_store, EmbedderTestContextType backend, bool opengl_framebuffer)
Configures per-backend properties for a given backing store.
bool RasterImagesAreSame(const sk_sp< SkImage > &a, const sk_sp< SkImage > &b)
SkMatrix GetTotalMutationTransformationMatrix(const FlutterPlatformViewMutation **mutations, size_t count)
std::string FixtureNameForBackend(EmbedderTestContextType backend, const std::string &name)
Prepends a prefix to the name which is unique to the test context type. This is useful for tests that...
bool ImageMatchesFixture(const std::string &fixture_file_name, const sk_sp< SkImage > &scene_image)
EmbedderTestBackingStoreProducer::RenderTargetType GetRenderTargetFromBackend(EmbedderTestContextType backend, bool opengl_framebuffer)
Resolves a render target type for a given backend description. This is useful for tests that use Embe...
DEF_SWITCHES_START aot vmservice shared library name
Definition switches.h:32
Definition ref_ptr.h:256
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition embedder.h:1564
BoolCallback runs_task_on_current_thread_callback
Definition embedder.h:1570
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition embedder.h:1581