Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dart_ui.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
6
7#include <mutex>
8#include <string_view>
9
46
47using tonic::ToDart;
48
49namespace flutter {
50
55
56// List of native static functions used as @Native functions.
57// Items are tuples of ('function_name', 'parameter_count'), where:
58// 'function_name' is the fully qualified name of the native function.
59// 'parameter_count' is the number of parameters the function has.
60//
61// These are used to:
62// - Instantiate FfiDispatcher templates to automatically create FFI Native
63// bindings.
64// If the name does not match a native function, the template will fail to
65// instatiate, resulting in a compile time error.
66// - Resolve the native function pointer associated with an @Native function.
67// If there is a mismatch between name or parameter count an @Native is
68// trying to resolve, an exception will be thrown.
69#define FFI_FUNCTION_LIST(V) \
70 /* Constructors */ \
71 V(Canvas::Create) \
72 V(ColorFilter::Create) \
73 V(FragmentProgram::Create) \
74 V(ReusableFragmentShader::Create) \
75 V(Gradient::Create) \
76 V(ImageFilter::Create) \
77 V(ImageShader::Create) \
78 V(ParagraphBuilder::Create) \
79 V(PathMeasure::Create) \
80 V(Path::Create) \
81 V(PictureRecorder::Create) \
82 V(RSuperellipse::Create) \
83 V(SceneBuilder::Create) \
84 V(SemanticsUpdateBuilder::Create) \
85 /* Other */ \
86 V(FontCollection::LoadFontFromList) \
87 V(ImageDescriptor::initEncoded) \
88 V(Image::decodeImageFromPixelsSync) \
89 V(ImageFilter::equals) \
90 V(ImmutableBuffer::init) \
91 V(ImmutableBuffer::initFromAsset) \
92 V(ImmutableBuffer::initFromFile) \
93 V(ImageDescriptor::initRaw) \
94 V(IsolateNameServerNatives::LookupPortByName) \
95 V(IsolateNameServerNatives::RegisterPortWithName) \
96 V(IsolateNameServerNatives::RemovePortNameMapping) \
97 V(NativeStringAttribute::initLocaleStringAttribute) \
98 V(NativeStringAttribute::initSpellOutStringAttribute) \
99 V(NativeSemanticsFlags::initSemanticsFlags) \
100 V(PlatformConfigurationNativeApi::DefaultRouteName) \
101 V(PlatformConfigurationNativeApi::ScheduleFrame) \
102 V(PlatformConfigurationNativeApi::EndWarmUpFrame) \
103 V(PlatformConfigurationNativeApi::Render) \
104 V(PlatformConfigurationNativeApi::UpdateSemantics) \
105 V(PlatformConfigurationNativeApi::SetApplicationLocale) \
106 V(PlatformConfigurationNativeApi::SetNeedsReportTimings) \
107 V(PlatformConfigurationNativeApi::SetIsolateDebugName) \
108 V(PlatformConfigurationNativeApi::SetSemanticsTreeEnabled) \
109 V(PlatformConfigurationNativeApi::RequestDartPerformanceMode) \
110 V(PlatformConfigurationNativeApi::GetPersistentIsolateData) \
111 V(PlatformConfigurationNativeApi::ComputePlatformResolvedLocale) \
112 V(PlatformConfigurationNativeApi::SendPlatformMessage) \
113 V(PlatformConfigurationNativeApi::RespondToPlatformMessage) \
114 V(PlatformConfigurationNativeApi::GetRootIsolateToken) \
115 V(PlatformConfigurationNativeApi::RegisterBackgroundIsolate) \
116 V(PlatformConfigurationNativeApi::SendPortPlatformMessage) \
117 V(PlatformConfigurationNativeApi::RequestViewFocusChange) \
118 V(PlatformConfigurationNativeApi::SendChannelUpdate) \
119 V(PlatformConfigurationNativeApi::GetScaledFontSize) \
120 V(PlatformIsolateNativeApi::IsRunningOnPlatformThread) \
121 V(PlatformIsolateNativeApi::Spawn) \
122 V(DartRuntimeHooks::Logger_PrintDebugString) \
123 V(DartRuntimeHooks::Logger_PrintString) \
124 V(DartRuntimeHooks::ScheduleMicrotask) \
125 V(DartRuntimeHooks::GetCallbackHandle) \
126 V(DartRuntimeHooks::GetCallbackFromHandle) \
127 V(DartPluginRegistrant_EnsureInitialized) \
128 V(Vertices::init)
129
130// List of native instance methods used as @Native functions.
131// Items are tuples of ('class_name', 'method_name', 'parameter_count'), where:
132// 'class_name' is the name of the class containing the method.
133// 'method_name' is the name of the method.
134// 'parameter_count' is the number of parameters the method has including the
135// implicit `this` parameter.
136//
137// These are used to:
138// - Instantiate FfiDispatcher templates to automatically create FFI Native
139// bindings.
140// If the name does not match a native function, the template will fail to
141// instatiate, resulting in a compile time error.
142// - Resolve the native function pointer associated with an @Native function.
143// If there is a mismatch between names or parameter count an @Native is
144// trying to resolve, an exception will be thrown.
145#define FFI_METHOD_LIST(V) \
146 V(Canvas, clipPath) \
147 V(Canvas, clipRect) \
148 V(Canvas, clipRRect) \
149 V(Canvas, clipRSuperellipse) \
150 V(Canvas, drawArc) \
151 V(Canvas, drawAtlas) \
152 V(Canvas, drawCircle) \
153 V(Canvas, drawColor) \
154 V(Canvas, drawDRRect) \
155 V(Canvas, drawRSuperellipse) \
156 V(Canvas, drawImage) \
157 V(Canvas, drawImageNine) \
158 V(Canvas, drawImageRect) \
159 V(Canvas, drawLine) \
160 V(Canvas, drawOval) \
161 V(Canvas, drawPaint) \
162 V(Canvas, drawPath) \
163 V(Canvas, drawPicture) \
164 V(Canvas, drawPoints) \
165 V(Canvas, drawRRect) \
166 V(Canvas, drawRect) \
167 V(Canvas, drawShadow) \
168 V(Canvas, drawVertices) \
169 V(Canvas, getDestinationClipBounds) \
170 V(Canvas, getLocalClipBounds) \
171 V(Canvas, getSaveCount) \
172 V(Canvas, getTransform) \
173 V(Canvas, restore) \
174 V(Canvas, restoreToCount) \
175 V(Canvas, rotate) \
176 V(Canvas, save) \
177 V(Canvas, saveLayer) \
178 V(Canvas, saveLayerWithoutBounds) \
179 V(Canvas, scale) \
180 V(Canvas, skew) \
181 V(Canvas, transform) \
182 V(Canvas, translate) \
183 V(Codec, dispose) \
184 V(Codec, frameCount) \
185 V(Codec, getNextFrame) \
186 V(Codec, repetitionCount) \
187 V(ColorFilter, initLinearToSrgbGamma) \
188 V(ColorFilter, initMatrix) \
189 V(ColorFilter, initMode) \
190 V(ColorFilter, initSrgbToLinearGamma) \
191 V(EngineLayer, dispose) \
192 V(FragmentProgram, initFromAsset) \
193 V(ReusableFragmentShader, Dispose) \
194 V(ReusableFragmentShader, SetImageSampler) \
195 V(ReusableFragmentShader, ValidateSamplers) \
196 V(ReusableFragmentShader, ValidateImageFilter) \
197 V(Gradient, initLinear) \
198 V(Gradient, initRadial) \
199 V(Gradient, initSweep) \
200 V(Gradient, initTwoPointConical) \
201 V(Image, dispose) \
202 V(Image, width) \
203 V(Image, height) \
204 V(Image, toByteData) \
205 V(Image, colorSpace) \
206 V(ImageDescriptor, bytesPerPixel) \
207 V(ImageDescriptor, dispose) \
208 V(ImageDescriptor, height) \
209 V(ImageDescriptor, instantiateCodec) \
210 V(ImageDescriptor, width) \
211 V(ImageFilter, initBlur) \
212 V(ImageFilter, initDilate) \
213 V(ImageFilter, initErode) \
214 V(ImageFilter, initColorFilter) \
215 V(ImageFilter, initComposeFilter) \
216 V(ImageFilter, initShader) \
217 V(ImageFilter, initMatrix) \
218 V(ImageShader, dispose) \
219 V(ImageShader, initWithImage) \
220 V(ImmutableBuffer, dispose) \
221 V(ImmutableBuffer, length) \
222 V(ParagraphBuilder, addPlaceholder) \
223 V(ParagraphBuilder, addText) \
224 V(ParagraphBuilder, build) \
225 V(ParagraphBuilder, pop) \
226 V(ParagraphBuilder, pushStyle) \
227 V(Paragraph, alphabeticBaseline) \
228 V(Paragraph, computeLineMetrics) \
229 V(Paragraph, didExceedMaxLines) \
230 V(Paragraph, dispose) \
231 V(Paragraph, getClosestGlyphInfo) \
232 V(Paragraph, getGlyphInfoAt) \
233 V(Paragraph, getLineBoundary) \
234 V(Paragraph, getLineMetricsAt) \
235 V(Paragraph, getLineNumberAt) \
236 V(Paragraph, getNumberOfLines) \
237 V(Paragraph, getPositionForOffset) \
238 V(Paragraph, getRectsForPlaceholders) \
239 V(Paragraph, getRectsForRange) \
240 V(Paragraph, getWordBoundary) \
241 V(Paragraph, height) \
242 V(Paragraph, ideographicBaseline) \
243 V(Paragraph, layout) \
244 V(Paragraph, longestLine) \
245 V(Paragraph, maxIntrinsicWidth) \
246 V(Paragraph, minIntrinsicWidth) \
247 V(Paragraph, paint) \
248 V(Paragraph, width) \
249 V(PathMeasure, setPath) \
250 V(PathMeasure, getLength) \
251 V(PathMeasure, getPosTan) \
252 V(PathMeasure, getSegment) \
253 V(PathMeasure, isClosed) \
254 V(PathMeasure, nextContour) \
255 V(Path, addArc) \
256 V(Path, addOval) \
257 V(Path, addPath) \
258 V(Path, addPathWithMatrix) \
259 V(Path, addPolygon) \
260 V(Path, addRRect) \
261 V(Path, addRSuperellipse) \
262 V(Path, addRect) \
263 V(Path, arcTo) \
264 V(Path, arcToPoint) \
265 V(Path, clone) \
266 V(Path, close) \
267 V(Path, conicTo) \
268 V(Path, contains) \
269 V(Path, cubicTo) \
270 V(Path, extendWithPath) \
271 V(Path, extendWithPathAndMatrix) \
272 V(Path, getBounds) \
273 V(Path, getFillType) \
274 V(Path, lineTo) \
275 V(Path, moveTo) \
276 V(Path, op) \
277 V(Path, quadraticBezierTo) \
278 V(Path, relativeArcToPoint) \
279 V(Path, relativeConicTo) \
280 V(Path, relativeCubicTo) \
281 V(Path, relativeLineTo) \
282 V(Path, relativeMoveTo) \
283 V(Path, relativeQuadraticBezierTo) \
284 V(Path, reset) \
285 V(Path, setFillType) \
286 V(Path, shift) \
287 V(Path, transform) \
288 V(PictureRecorder, endRecording) \
289 V(Picture, GetAllocationSize) \
290 V(Picture, dispose) \
291 V(Picture, toImage) \
292 V(Picture, toImageSync) \
293 V(RSuperellipse, contains) \
294 V(SceneBuilder, addPerformanceOverlay) \
295 V(SceneBuilder, addPicture) \
296 V(SceneBuilder, addPlatformView) \
297 V(SceneBuilder, addRetained) \
298 V(SceneBuilder, addTexture) \
299 V(SceneBuilder, build) \
300 V(SceneBuilder, pop) \
301 V(SceneBuilder, pushBackdropFilter) \
302 V(SceneBuilder, pushClipPath) \
303 V(SceneBuilder, pushClipRect) \
304 V(SceneBuilder, pushClipRRect) \
305 V(SceneBuilder, pushClipRSuperellipse) \
306 V(SceneBuilder, pushColorFilter) \
307 V(SceneBuilder, pushImageFilter) \
308 V(SceneBuilder, pushOffset) \
309 V(SceneBuilder, pushOpacity) \
310 V(SceneBuilder, pushShaderMask) \
311 V(SceneBuilder, pushTransformHandle) \
312 V(Scene, dispose) \
313 V(Scene, toImage) \
314 V(Scene, toImageSync) \
315 V(SemanticsUpdateBuilder, build) \
316 V(SemanticsUpdateBuilder, updateCustomAction) \
317 V(SemanticsUpdateBuilder, updateNode) \
318 V(SemanticsUpdate, dispose) \
319 V(Vertices, dispose)
320
321#define FFI_FUNCTION_INSERT(FUNCTION) \
322 g_function_dispatchers.insert(std::make_pair( \
323 std::string_view(#FUNCTION), \
324 reinterpret_cast<void*>( \
325 tonic::FfiDispatcher<void, decltype(&FUNCTION), &FUNCTION>::Call)));
326
327#define FFI_METHOD_INSERT(CLASS, METHOD) \
328 g_function_dispatchers.insert( \
329 std::make_pair(std::string_view(#CLASS "::" #METHOD), \
330 reinterpret_cast<void*>( \
331 tonic::FfiDispatcher<CLASS, decltype(&CLASS::METHOD), \
332 &CLASS::METHOD>::Call)));
333
334namespace {
335
336std::once_flag g_dispatchers_init_flag;
337std::unordered_map<std::string_view, void*> g_function_dispatchers;
338
339void* ResolveFfiNativeFunction(const char* name, uintptr_t args) {
340 auto it = g_function_dispatchers.find(name);
341 return (it != g_function_dispatchers.end()) ? it->second : nullptr;
342}
343
344void InitDispatcherMap() {
347}
348
349} // anonymous namespace
350
351void DartUI::InitForIsolate(const Settings& settings) {
352 std::call_once(g_dispatchers_init_flag, InitDispatcherMap);
353
354 auto dart_ui = Dart_LookupLibrary(ToDart("dart:ui"));
355 if (Dart_IsError(dart_ui)) {
356 Dart_PropagateError(dart_ui);
357 }
358
359 // Set up FFI Native resolver for dart:ui.
360 Dart_Handle result =
361 Dart_SetFfiNativeResolver(dart_ui, ResolveFfiNativeFunction);
362 if (Dart_IsError(result)) {
363 Dart_PropagateError(result);
364 }
365
366 if (settings.enable_impeller) {
367 result = Dart_SetField(dart_ui, ToDart("_impellerEnabled"), Dart_True());
368 if (Dart_IsError(result)) {
369 Dart_PropagateError(result);
370 }
371 }
372
373 if (settings.enable_platform_isolates) {
374 result =
375 Dart_SetField(dart_ui, ToDart("_platformIsolatesEnabled"), Dart_True());
376 if (Dart_IsError(result)) {
377 Dart_PropagateError(result);
378 }
379 }
380
381 result = Dart_SetField(dart_ui, ToDart("_implicitViewId"),
382 Dart_NewInteger(kFlutterImplicitViewId));
383 if (Dart_IsError(result)) {
384 Dart_PropagateError(result);
385 }
386}
387
388} // namespace flutter
static void InitForIsolate(const Settings &settings)
Definition dart_ui.cc:351
#define FFI_FUNCTION_LIST(V)
Definition dart_ui.cc:69
#define FFI_FUNCTION_INSERT(FUNCTION)
Definition dart_ui.cc:321
#define FFI_METHOD_LIST(V)
Definition dart_ui.cc:145
#define FFI_METHOD_INSERT(CLASS, METHOD)
Definition dart_ui.cc:327
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
constexpr int64_t kFlutterImplicitViewId
Definition constants.h:35
DEF_SWITCHES_START aot vmservice shared library name
Definition switch_defs.h:27
CanvasGradient Gradient
Definition dart_ui.cc:53
CanvasPathMeasure PathMeasure
Definition dart_ui.cc:52
CanvasImage Image
Definition dart_ui.cc:51
CanvasPath Path
Definition dart_ui.cc:54
Dart_Handle ToDart(const T &object)
bool enable_platform_isolates
Definition settings.h:365