[Flutter GPU] Export symbols from engine, stub for testing on CI. (flutter/engine#44280)

Part of https://github.com/flutter/flutter/issues/131346

Stubs a minimal test of the FFI utilities that `dart:ui` uses, but using
public symbols exported from the engine library. If this goes well, I'll
move the stuff from `dart:ui` into here and begin landing parts of the
API with test coverage.
This commit is contained in:
Brandon DeRosier
2023-08-03 08:11:57 -07:00
committed by GitHub
parent 9f2e5286ad
commit 07c646b28d
11 changed files with 252 additions and 4 deletions

View File

@@ -1716,6 +1716,9 @@ ORIGIN: ../../../flutter/impeller/typographer/text_run.cc + ../../../flutter/LIC
ORIGIN: ../../../flutter/impeller/typographer/text_run.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/typographer/typeface.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/typographer/typeface.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/gpu/gpu.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/gpu/gpu.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/gpu/gpu.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/io/dart_io.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/io/dart_io.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/snapshot/snapshot.h + ../../../flutter/LICENSE
@@ -4415,6 +4418,9 @@ FILE: ../../../flutter/impeller/typographer/text_run.cc
FILE: ../../../flutter/impeller/typographer/text_run.h
FILE: ../../../flutter/impeller/typographer/typeface.cc
FILE: ../../../flutter/impeller/typographer/typeface.h
FILE: ../../../flutter/lib/gpu/gpu.cc
FILE: ../../../flutter/lib/gpu/gpu.dart
FILE: ../../../flutter/lib/gpu/gpu.h
FILE: ../../../flutter/lib/io/dart_io.cc
FILE: ../../../flutter/lib/io/dart_io.h
FILE: ../../../flutter/lib/snapshot/libraries_experimental.json

View File

@@ -5,4 +5,6 @@
kDartVmSnapshotInstructions;
kDartIsolateSnapshotData;
kDartIsolateSnapshotInstructions;
InternalFlutterGpu*;
kInternalFlutterGpu*;
};

View File

@@ -4,3 +4,5 @@ _kDartVmSnapshotData
_kDartVmSnapshotInstructions
_kDartIsolateSnapshotData
_kDartIsolateSnapshotInstructions
_InternalFlutterGpu*
_kInternalFlutterGpu*

View File

@@ -0,0 +1,51 @@
# 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.
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
import("//flutter/testing/testing.gni")
source_set("gpu") {
cflags = [
# Dart gives us doubles. Skia and Impeller work in floats.
# If Dart gives us a double > FLT_MAX or < -FLT_MAX, implicit conversion
# will convert it to either inf/-inf or FLT_MAX/-FLT_MAX (undefined
# behavior). This can result in surprising and difficult to debug behavior
# for Flutter application developers, so it should be explicitly handled
# via SafeNarrow.
"-Wimplicit-float-conversion",
]
if (is_win) {
# This causes build failures in third_party dependencies on Windows.
cflags += [ "-Wno-implicit-int-float-conversion" ]
}
public_configs = [ "//flutter:config" ]
public_deps = []
if (!defined(defines)) {
defines = []
}
sources = [
"gpu.cc",
"gpu.h",
]
deps = [
"//flutter/impeller",
"//flutter/impeller/display_list:skia_conversions",
"//flutter/lib/ui",
"//flutter/third_party/tonic",
]
if (is_win) {
# Required for M_PI and others.
defines += [ "_USE_MATH_DEFINES" ]
}
}
if (enable_unittests) {
}

View File

@@ -0,0 +1,60 @@
// 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/lib/gpu/gpu.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/ui_dart_state.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/dart_wrappable.h"
#include "third_party/tonic/dart_wrapper_info.h"
#include "third_party/tonic/logging/dart_invoke.h"
namespace flutter {
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
IMPLEMENT_WRAPPERTYPEINFO(gpu, FlutterGpuTestClass);
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
FlutterGpuTestClass::~FlutterGpuTestClass() = default;
} // namespace flutter
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
uint32_t InternalFlutterGpuTestProc() {
return 1;
}
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
Dart_Handle InternalFlutterGpuTestProcWithCallback(Dart_Handle callback) {
flutter::UIDartState::ThrowIfUIOperationsProhibited();
if (!Dart_IsClosure(callback)) {
return tonic::ToDart("Callback must be a function");
}
tonic::DartInvoke(callback, {tonic::ToDart(1234)});
return Dart_Null();
}
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
void InternalFlutterGpuTestClass_Create(Dart_Handle wrapper) {
auto res = fml::MakeRefCounted<flutter::FlutterGpuTestClass>();
res->AssociateWithDartWrapper(wrapper);
FML_LOG(INFO) << "FlutterGpuTestClass Wrapped.";
}
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
void InternalFlutterGpuTestClass_Method(flutter::FlutterGpuTestClass* self,
int something) {
FML_LOG(INFO) << "Something: " << something;
}
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
void FlutterGpuTestClass_Dispose(flutter::FlutterGpuTestClass* self,
int something) {
self->ClearDartWrapper();
}

View File

@@ -0,0 +1,39 @@
// 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.
// ignore_for_file: public_member_api_docs
import 'dart:ffi';
import 'dart:nativewrappers';
/// This is a simple test fuction.
@Native<Int32 Function()>(symbol: 'InternalFlutterGpuTestProc')
external int testProc();
/// This is a test callback that follows the same pattern as much of dart:ui --
/// immediately returning an error string and supplying an asynchronous result
/// via callback later.
typedef Callback<T> = void Function(T result);
@Native<Handle Function(Handle)>(
symbol: 'InternalFlutterGpuTestProcWithCallback')
external String? testProcWithCallback(Callback<int> callback);
/// This is a test of NativeFieldWrapperClass1, which is commonly used in
/// dart:ui to enable Dart to dictate the lifetime of a C counterpart.
base class FlutterGpuTestClass extends NativeFieldWrapperClass1 {
FlutterGpuTestClass() {
_constructor();
}
/// This "constructor" is used to instantiate and wrap the C counterpart.
/// This is a common pattern in dart:ui.
@Native<Void Function(Handle)>(symbol: 'InternalFlutterGpuTestClass_Create')
external void _constructor();
/// This is a method that will supply a pointer to the C data counterpart when
/// calling the gunction
@Native<Void Function(Pointer<Void>, Int)>(
symbol: 'InternalFlutterGpuTestClass_Method')
external void coolMethod(int something);
}

View File

@@ -0,0 +1,57 @@
// 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_LIB_GPU_GPU_H_
#define FLUTTER_LIB_GPU_GPU_H_
#include <cstdint>
#include "flutter/lib/ui/dart_wrapper.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/dart_wrapper_info.h"
#if FML_OS_WIN
#define FLUTTER_EXPORT __declspec(dllexport)
#else // FML_OS_WIN
#define FLUTTER_EXPORT __attribute__((visibility("default")))
#endif // FML_OS_WIN
namespace flutter {
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
class FlutterGpuTestClass
: public RefCountedDartWrappable<FlutterGpuTestClass> {
DEFINE_WRAPPERTYPEINFO();
FML_FRIEND_MAKE_REF_COUNTED(FlutterGpuTestClass);
public:
~FlutterGpuTestClass() override;
};
} // namespace flutter
extern "C" {
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
FLUTTER_EXPORT
extern uint32_t InternalFlutterGpuTestProc();
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
FLUTTER_EXPORT
extern Dart_Handle InternalFlutterGpuTestProcWithCallback(Dart_Handle callback);
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
FLUTTER_EXPORT
extern void InternalFlutterGpuTestClass_Create(Dart_Handle wrapper);
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
FLUTTER_EXPORT
extern void InternalFlutterGpuTestClass_Method(
flutter::FlutterGpuTestClass* self,
int something);
} // extern "C"
#endif // FLUTTER_LIB_GPU_GPU_H_

View File

@@ -90,6 +90,7 @@ source_set("runtime") {
}
public_deps = [
"//flutter/lib/gpu",
"//flutter/lib/ui",
"//third_party/rapidjson",
]

View File

@@ -17,6 +17,7 @@ tests = [
"fragment_shader_test.dart",
"geometry_test.dart",
"gesture_settings_test.dart",
"gpu_test.dart",
"gradient_test.dart",
"http_allow_http_connections_test.dart",
"http_disallow_http_connections_test.dart",

View File

@@ -0,0 +1,24 @@
// 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.
// ignore_for_file: avoid_relative_lib_imports
import 'package:litetest/litetest.dart';
import '../../lib/gpu/gpu.dart' as gpu;
void main() {
// TODO(131346): Remove this once we migrate the Dart GPU API into this space.
test('no crash', () async {
final int result = gpu.testProc();
expect(result, 1);
final String? message = gpu.testProcWithCallback((int result) {
expect(result, 1234);
});
expect(message, null);
final gpu.FlutterGpuTestClass a = gpu.FlutterGpuTestClass();
a.coolMethod(9847);
});
}

View File

@@ -94,9 +94,12 @@ int _checkIos(String outPath, String nmPath, Iterable<String> builds) {
continue;
}
final Iterable<NmEntry> unexpectedEntries = NmEntry.parse(nmResult.stdout as String).where((NmEntry entry) {
return !(((entry.type == '(__DATA,__common)' || entry.type == '(__DATA,__const)') && entry.name.startsWith('_Flutter'))
|| (entry.type == '(__DATA,__objc_data)'
&& (entry.name.startsWith(r'_OBJC_METACLASS_$_Flutter') || entry.name.startsWith(r'_OBJC_CLASS_$_Flutter'))));
final bool cSymbol = (entry.type == '(__DATA,__common)' || entry.type == '(__DATA,__const)')
&& entry.name.startsWith('_Flutter');
final bool cInternalSymbol = entry.type == '(__TEXT,__text)' && entry.name.startsWith('_InternalFlutter');
final bool objcSymbol = entry.type == '(__DATA,__objc_data)'
&& (entry.name.startsWith(r'_OBJC_METACLASS_$_Flutter') || entry.name.startsWith(r'_OBJC_CLASS_$_Flutter'));
return !(cSymbol || cInternalSymbol || objcSymbol);
});
if (unexpectedEntries.isNotEmpty) {
print('ERROR: $libFlutter exports unexpected symbols:');
@@ -275,7 +278,9 @@ int _checkLinux(String outPath, String nmPath, Iterable<String> builds) {
}
if (!(entry.name.startsWith('Flutter')
|| entry.name.startsWith('__Flutter')
|| entry.name.startsWith('kFlutter'))) {
|| entry.name.startsWith('kFlutter')
|| entry.name.startsWith('InternalFlutter')
|| entry.name.startsWith('kInternalFlutter'))) {
print('ERROR: $libFlutter exports an unexpected symbol name: ($entry)');
print(' Library has $entries.');
failures++;