Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f68a7a5

Browse files
committed
[Dart GPU] Export symbols from engine, stub for testing on CI.
1 parent 3e1ee16 commit f68a7a5

File tree

10 files changed

+216
-0
lines changed

10 files changed

+216
-0
lines changed

common/exported_symbols.sym

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
kDartVmSnapshotInstructions;
66
kDartIsolateSnapshotData;
77
kDartIsolateSnapshotInstructions;
8+
FlutterGpu*;
9+
kFlutterGpu*;
810
};

common/exported_symbols_mac.sym

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ _kDartVmSnapshotData
44
_kDartVmSnapshotInstructions
55
_kDartIsolateSnapshotData
66
_kDartIsolateSnapshotInstructions
7+
_FlutterGpu*
8+
_kFlutterGpu*

lib/gpu/BUILD.gn

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
import("//flutter/common/config.gni")
6+
import("//flutter/impeller/tools/impeller.gni")
7+
import("//flutter/testing/testing.gni")
8+
9+
source_set("gpu") {
10+
cflags = [
11+
# Dart gives us doubles. Skia and Impeller work in floats.
12+
# If Dart gives us a double > FLT_MAX or < -FLT_MAX, implicit conversion
13+
# will convert it to either inf/-inf or FLT_MAX/-FLT_MAX (undefined
14+
# behavior). This can result in surprising and difficult to debug behavior
15+
# for Flutter application developers, so it should be explicitly handled
16+
# via SafeNarrow.
17+
"-Wimplicit-float-conversion",
18+
]
19+
20+
if (is_win) {
21+
# This causes build failures in third_party dependencies on Windows.
22+
cflags += [ "-Wno-implicit-int-float-conversion" ]
23+
}
24+
25+
public_configs = [ "//flutter:config" ]
26+
27+
public_deps = []
28+
29+
if (!defined(defines)) {
30+
defines = []
31+
}
32+
33+
sources = [
34+
"gpu.cc",
35+
"gpu.h",
36+
]
37+
deps = [
38+
"//flutter/impeller",
39+
"//flutter/impeller/display_list:skia_conversions",
40+
"//flutter/lib/ui",
41+
"//flutter/third_party/tonic",
42+
]
43+
44+
if (is_win) {
45+
# Required for M_PI and others.
46+
defines += [ "_USE_MATH_DEFINES" ]
47+
}
48+
}
49+
50+
if (enable_unittests) {
51+
}

lib/gpu/gpu.cc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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/gpu/gpu.h"
6+
#include "flutter/fml/memory/ref_ptr.h"
7+
#include "flutter/lib/ui/dart_wrapper.h"
8+
#include "flutter/lib/ui/ui_dart_state.h"
9+
#include "third_party/dart/runtime/include/dart_api.h"
10+
#include "third_party/tonic/converter/dart_converter.h"
11+
#include "third_party/tonic/dart_state.h"
12+
#include "third_party/tonic/dart_wrappable.h"
13+
#include "third_party/tonic/dart_wrapper_info.h"
14+
#include "third_party/tonic/logging/dart_invoke.h"
15+
16+
namespace flutter {
17+
18+
IMPLEMENT_WRAPPERTYPEINFO(gpu, FlutterGpuTestClass);
19+
20+
} // namespace flutter
21+
22+
uint32_t FlutterGpuTestProc() {
23+
return 1;
24+
}
25+
26+
Dart_Handle FlutterGpuTestProcWithCallback(Dart_Handle callback) {
27+
flutter::UIDartState::ThrowIfUIOperationsProhibited();
28+
if (!Dart_IsClosure(callback)) {
29+
return tonic::ToDart("Callback must be a function");
30+
}
31+
32+
tonic::DartInvoke(callback, {tonic::ToDart(1234)});
33+
34+
return Dart_Null();
35+
}
36+
37+
void FlutterGpuTestClass_Create(Dart_Handle wrapper) {
38+
auto res = fml::MakeRefCounted<flutter::FlutterGpuTestClass>();
39+
res->AssociateWithDartWrapper(wrapper);
40+
FML_LOG(ERROR) << "FlutterGpuTestClass Wrapped.";
41+
}
42+
43+
void FlutterGpuTestClass_Method(flutter::FlutterGpuTestClass* self,
44+
int something) {
45+
FML_LOG(ERROR) << "Something: " << something;
46+
}

lib/gpu/gpu.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:ffi';
8+
import 'dart:nativewrappers';
9+
10+
/// This is a simple test fuction.
11+
@Native<Int32 Function()>(symbol: 'FlutterGpuTestProc')
12+
external int testProc();
13+
14+
/// This is a test callback that follows the same pattern as much of dart:ui --
15+
/// immediately returning an error string and supplying an asynchronous result
16+
/// via callback later.
17+
typedef Callback<T> = void Function(T result);
18+
@Native<Handle Function(Handle)>(symbol: 'FlutterGpuTestProcWithCallback')
19+
external String? testProcWithCallback(Callback<int> callback);
20+
21+
/// This is a test of NativeFieldWrapperClass1, which is commonly used in
22+
/// dart:ui to enable Dart to dictate the lifetime of a C counterpart.
23+
base class FlutterGpuTestClass extends NativeFieldWrapperClass1 {
24+
FlutterGpuTestClass() {
25+
_constructor();
26+
}
27+
28+
/// This "constructor" is used to instantiate and wrap the C counterpart.
29+
/// This is a common pattern in dart:ui.
30+
@Native<Void Function(Handle)>(symbol: 'FlutterGpuTestClass_Create')
31+
external void _constructor();
32+
33+
/// This is a method that will supply a pointer to the C data counterpart when
34+
/// calling the function
35+
@Native<Void Function(Pointer<Void>, Int)>(
36+
symbol: 'FlutterGpuTestClass_Method')
37+
external void coolMethod(int something);
38+
}

lib/gpu/gpu.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_LIB_GPU_GPU_H_
6+
#define FLUTTER_LIB_GPU_GPU_H_
7+
8+
#include <cstdint>
9+
10+
#include "flutter/lib/ui/dart_wrapper.h"
11+
#include "third_party/dart/runtime/include/dart_api.h"
12+
#include "third_party/tonic/dart_state.h"
13+
#include "third_party/tonic/dart_wrapper_info.h"
14+
15+
#if FML_OS_WIN
16+
#define FLUTTER_EXPORT __declspec(dllexport)
17+
#else // FML_OS_WIN
18+
#define FLUTTER_EXPORT __attribute__((visibility("default")))
19+
#endif // FML_OS_WIN
20+
21+
namespace flutter {
22+
23+
class FlutterGpuTestClass
24+
: public RefCountedDartWrappable<FlutterGpuTestClass> {
25+
DEFINE_WRAPPERTYPEINFO();
26+
27+
public:
28+
};
29+
30+
} // namespace flutter
31+
32+
extern "C" {
33+
34+
FLUTTER_EXPORT
35+
extern uint32_t FlutterGpuTestProc();
36+
37+
FLUTTER_EXPORT
38+
extern Dart_Handle FlutterGpuTestProcWithCallback(Dart_Handle callback);
39+
40+
FLUTTER_EXPORT
41+
extern void FlutterGpuTestClass_Create(Dart_Handle wrapper);
42+
43+
FLUTTER_EXPORT
44+
extern void FlutterGpuTestClass_Method(flutter::FlutterGpuTestClass* self,
45+
int something);
46+
47+
} // extern "C"
48+
49+
#endif // FLUTTER_LIB_GPU_GPU_H_

runtime/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ source_set("runtime") {
9090
}
9191

9292
public_deps = [
93+
"//flutter/lib/gpu",
9394
"//flutter/lib/ui",
9495
"//third_party/rapidjson",
9596
]

shell/testing/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ executable("testing") {
2727
"//flutter/common",
2828
"//flutter/flow",
2929
"//flutter/fml",
30+
"//flutter/lib/gpu",
3031
"//flutter/lib/snapshot",
3132
"//flutter/shell/common",
3233
"//flutter/shell/gpu:gpu_surface_software",

testing/dart/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tests = [
1717
"fragment_shader_test.dart",
1818
"geometry_test.dart",
1919
"gesture_settings_test.dart",
20+
"gpu_test.dart",
2021
"gradient_test.dart",
2122
"http_allow_http_connections_test.dart",
2223
"http_disallow_http_connections_test.dart",

testing/dart/gpu_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
// ignore_for_file: avoid_relative_lib_imports
6+
7+
import 'dart:ui';
8+
9+
import 'package:litetest/litetest.dart';
10+
import '../../lib/gpu/gpu.dart' as gpu;
11+
12+
void main() {
13+
test('no crash', () async {
14+
final int result = gpu.testProc();
15+
expect(result, 1234);
16+
17+
final String? message = gpu.testProcWithCallback((int result) {
18+
print('Callback called with: $result');
19+
});
20+
expect(message, '');
21+
22+
final gpu.FlutterGpuTestClass a = gpu.FlutterGpuTestClass();
23+
a.coolMethod(9847);
24+
});
25+
}

0 commit comments

Comments
 (0)