From e8e4f8c118672529e6edd3e9e0bccef26781137d Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Mon, 7 Aug 2023 12:41:57 -0700 Subject: [PATCH] [Impeller] Flutter GPU: Add GpuContext. (flutter/engine#44359) Move the GpuContext to its new home. I added a `flutter_tester` test that just verifies an exception is gracefully thrown when Impeller isn't available. In a later patch, I'll land a way to eagerly supply the Impeller context on the cpp side to enable testing through the playground (as mentioned in https://github.com/flutter/flutter/issues/127712). --- .../flutter/ci/licenses_golden/excluded_files | 2 + .../ci/licenses_golden/licenses_flutter | 28 +++++++---- engine/src/flutter/lib/gpu/BUILD.gn | 14 ++++-- .../src/flutter/lib/gpu/analysis_options.yaml | 7 +++ .../src/flutter/lib/{ui => }/gpu/context.cc | 47 ++++++++++--------- engine/src/flutter/lib/gpu/context.h | 40 ++++++++++++++++ engine/src/flutter/lib/gpu/export.cc | 11 +++++ engine/src/flutter/lib/gpu/export.h | 11 +++++ engine/src/flutter/lib/gpu/lib/gpu.dart | 15 ++++++ .../src/flutter/lib/gpu/lib/src/context.dart | 28 +++++++++++ .../gpu/{gpu.dart => lib/src/smoketest.dart} | 7 +-- engine/src/flutter/lib/gpu/pubspec.yaml | 14 ++++++ .../flutter/lib/gpu/{gpu.cc => smoketest.cc} | 12 ++--- .../flutter/lib/gpu/{gpu.h => smoketest.h} | 24 ++++------ engine/src/flutter/lib/ui/BUILD.gn | 6 --- engine/src/flutter/lib/ui/dart_ui.cc | 8 ---- engine/src/flutter/lib/ui/gpu/context.h | 37 --------------- engine/src/flutter/testing/dart/gpu_test.dart | 17 ++++++- 18 files changed, 214 insertions(+), 114 deletions(-) create mode 100644 engine/src/flutter/lib/gpu/analysis_options.yaml rename engine/src/flutter/lib/{ui => }/gpu/context.cc (56%) create mode 100644 engine/src/flutter/lib/gpu/context.h create mode 100644 engine/src/flutter/lib/gpu/export.cc create mode 100644 engine/src/flutter/lib/gpu/export.h create mode 100644 engine/src/flutter/lib/gpu/lib/gpu.dart create mode 100644 engine/src/flutter/lib/gpu/lib/src/context.dart rename engine/src/flutter/lib/gpu/{gpu.dart => lib/src/smoketest.dart} (94%) create mode 100644 engine/src/flutter/lib/gpu/pubspec.yaml rename engine/src/flutter/lib/gpu/{gpu.cc => smoketest.cc} (88%) rename engine/src/flutter/lib/gpu/{gpu.h => smoketest.h} (80%) delete mode 100644 engine/src/flutter/lib/ui/gpu/context.h diff --git a/engine/src/flutter/ci/licenses_golden/excluded_files b/engine/src/flutter/ci/licenses_golden/excluded_files index 5beeafd602..a4ce479fdd 100644 --- a/engine/src/flutter/ci/licenses_golden/excluded_files +++ b/engine/src/flutter/ci/licenses_golden/excluded_files @@ -174,6 +174,8 @@ ../../../flutter/impeller/tools/malioc_diff.py ../../../flutter/impeller/tools/xxd.py ../../../flutter/impeller/typographer/typographer_unittests.cc +../../../flutter/lib/gpu/analysis_options.yaml +../../../flutter/lib/gpu/pubspec.yaml ../../../flutter/lib/snapshot/libraries.json ../../../flutter/lib/snapshot/libraries.yaml ../../../flutter/lib/snapshot/pubspec.yaml diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index e5a2f41573..7cf45a5a79 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -1725,9 +1725,15 @@ 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/gpu/context.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/context.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/export.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/export.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/lib/gpu.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/lib/src/context.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/lib/src/smoketest.dart + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/smoketest.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/lib/gpu/smoketest.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 @@ -1749,8 +1755,6 @@ ORIGIN: ../../../flutter/lib/ui/experiments/setup_hooks.dart + ../../../flutter/ ORIGIN: ../../../flutter/lib/ui/experiments/ui.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/floating_point.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/geometry.dart + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/ui/gpu/context.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/lib/ui/gpu/context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/hash_codes.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/hooks.dart + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/ui/io_manager.cc + ../../../flutter/LICENSE @@ -4445,9 +4449,15 @@ 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/gpu/context.cc +FILE: ../../../flutter/lib/gpu/context.h +FILE: ../../../flutter/lib/gpu/export.cc +FILE: ../../../flutter/lib/gpu/export.h +FILE: ../../../flutter/lib/gpu/lib/gpu.dart +FILE: ../../../flutter/lib/gpu/lib/src/context.dart +FILE: ../../../flutter/lib/gpu/lib/src/smoketest.dart +FILE: ../../../flutter/lib/gpu/smoketest.cc +FILE: ../../../flutter/lib/gpu/smoketest.h FILE: ../../../flutter/lib/io/dart_io.cc FILE: ../../../flutter/lib/io/dart_io.h FILE: ../../../flutter/lib/snapshot/libraries_experimental.json @@ -4470,8 +4480,6 @@ FILE: ../../../flutter/lib/ui/experiments/setup_hooks.dart FILE: ../../../flutter/lib/ui/experiments/ui.dart FILE: ../../../flutter/lib/ui/floating_point.h FILE: ../../../flutter/lib/ui/geometry.dart -FILE: ../../../flutter/lib/ui/gpu/context.cc -FILE: ../../../flutter/lib/ui/gpu/context.h FILE: ../../../flutter/lib/ui/hash_codes.dart FILE: ../../../flutter/lib/ui/hooks.dart FILE: ../../../flutter/lib/ui/io_manager.cc diff --git a/engine/src/flutter/lib/gpu/BUILD.gn b/engine/src/flutter/lib/gpu/BUILD.gn index 7b24bf4007..188637666c 100644 --- a/engine/src/flutter/lib/gpu/BUILD.gn +++ b/engine/src/flutter/lib/gpu/BUILD.gn @@ -30,10 +30,16 @@ source_set("gpu") { defines = [] } - sources = [ - "gpu.cc", - "gpu.h", - ] + if (!is_fuchsia) { + sources = [ + "context.cc", + "context.h", + "export.cc", + "export.h", + "smoketest.cc", + "smoketest.h", + ] + } deps = [ "//flutter/impeller", "//flutter/impeller/display_list:skia_conversions", diff --git a/engine/src/flutter/lib/gpu/analysis_options.yaml b/engine/src/flutter/lib/gpu/analysis_options.yaml new file mode 100644 index 0000000000..ee294d5a34 --- /dev/null +++ b/engine/src/flutter/lib/gpu/analysis_options.yaml @@ -0,0 +1,7 @@ +# 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. + +linter: + rules: + - public_member_api_docs diff --git a/engine/src/flutter/lib/ui/gpu/context.cc b/engine/src/flutter/lib/gpu/context.cc similarity index 56% rename from engine/src/flutter/lib/ui/gpu/context.cc rename to engine/src/flutter/lib/gpu/context.cc index c61b4d2e6c..f56e938c6c 100644 --- a/engine/src/flutter/lib/ui/gpu/context.cc +++ b/engine/src/flutter/lib/gpu/context.cc @@ -2,27 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "flutter/lib/ui/gpu/context.h" +#include "flutter/lib/gpu/context.h" -#include -#include +#include -#include "flutter/fml/log_level.h" -#include "flutter/fml/logging.h" -#include "flutter/fml/make_copyable.h" -#include "flutter/fml/memory/ref_ptr.h" +#include "dart_api.h" #include "flutter/lib/ui/ui_dart_state.h" -#include "third_party/tonic/dart_wrappable.h" +#include "fml/make_copyable.h" +#include "tonic/converter/dart_converter.h" namespace flutter { -IMPLEMENT_WRAPPERTYPEINFO(ui, GpuContext); +IMPLEMENT_WRAPPERTYPEINFO(gpu, Context); -std::string GpuContext::InitializeDefault(Dart_Handle wrapper) { - auto dart_state = UIDartState::Current(); +Context::Context(std::shared_ptr context) + : context_(std::move(context)) {} + +Context::~Context() = default; + +} // namespace flutter + +//---------------------------------------------------------------------------- +/// Exports +/// + +Dart_Handle InternalFlutterGpu_Context_InitializeDefault(Dart_Handle wrapper) { + auto dart_state = flutter::UIDartState::Current(); if (!dart_state->IsImpellerEnabled()) { - return "The GpuContext API requires the Impeller rendering backend to be " - "enabled."; + return tonic::ToDart( + "Flutter GPU requires the Impeller rendering backend to be enabled."); } // Grab the Impeller context from the IO manager. @@ -38,17 +46,10 @@ std::string GpuContext::InitializeDefault(Dart_Handle wrapper) { auto impeller_context = impeller_context_future.get(); if (!impeller_context) { - return "Unable to retrieve the Impeller context."; + return tonic::ToDart("Unable to retrieve the Impeller context."); } - auto res = fml::MakeRefCounted(impeller_context); + auto res = fml::MakeRefCounted(impeller_context); res->AssociateWithDartWrapper(wrapper); - return ""; + return Dart_Null(); } - -GpuContext::GpuContext(std::shared_ptr context) - : context_(std::move(context)) {} - -GpuContext::~GpuContext() = default; - -} // namespace flutter diff --git a/engine/src/flutter/lib/gpu/context.h b/engine/src/flutter/lib/gpu/context.h new file mode 100644 index 0000000000..6667e1b29a --- /dev/null +++ b/engine/src/flutter/lib/gpu/context.h @@ -0,0 +1,40 @@ +// 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. + +#pragma once + +#include "dart_api.h" +#include "flutter/lib/gpu/export.h" +#include "flutter/lib/ui/dart_wrapper.h" +#include "impeller/renderer/context.h" + +namespace flutter { + +class Context : public RefCountedDartWrappable { + DEFINE_WRAPPERTYPEINFO(); + FML_FRIEND_MAKE_REF_COUNTED(Context); + + public: + explicit Context(std::shared_ptr context); + ~Context() override; + + private: + std::shared_ptr context_; + + FML_DISALLOW_COPY_AND_ASSIGN(Context); +}; + +} // namespace flutter + +//---------------------------------------------------------------------------- +/// Exports +/// + +extern "C" { + +FLUTTER_GPU_EXPORT +extern Dart_Handle InternalFlutterGpu_Context_InitializeDefault( + Dart_Handle wrapper); + +} // extern "C" diff --git a/engine/src/flutter/lib/gpu/export.cc b/engine/src/flutter/lib/gpu/export.cc new file mode 100644 index 0000000000..43ecb08ef8 --- /dev/null +++ b/engine/src/flutter/lib/gpu/export.cc @@ -0,0 +1,11 @@ +// 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/export.h" + +namespace flutter { + +// + +} // namespace flutter diff --git a/engine/src/flutter/lib/gpu/export.h b/engine/src/flutter/lib/gpu/export.h new file mode 100644 index 0000000000..488b61c59e --- /dev/null +++ b/engine/src/flutter/lib/gpu/export.h @@ -0,0 +1,11 @@ +// 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. + +#pragma once + +#if FML_OS_WIN +#define FLUTTER_GPU_EXPORT __declspec(dllexport) +#else // FML_OS_WIN +#define FLUTTER_GPU_EXPORT __attribute__((visibility("default"))) +#endif // FML_OS_WIN diff --git a/engine/src/flutter/lib/gpu/lib/gpu.dart b/engine/src/flutter/lib/gpu/lib/gpu.dart new file mode 100644 index 0000000000..72cf205f1f --- /dev/null +++ b/engine/src/flutter/lib/gpu/lib/gpu.dart @@ -0,0 +1,15 @@ +// 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. + +/// The Flutter GPU library. +/// +/// To use, import `package:flutter_gpu/gpu.dart`. +/// +/// See also: +/// +/// * [Flutter GPU Wiki page](https://github.com/flutter/flutter/wiki/Flutter-GPU). +library flutter_gpu; + +export 'src/context.dart'; +export 'src/smoketest.dart'; diff --git a/engine/src/flutter/lib/gpu/lib/src/context.dart b/engine/src/flutter/lib/gpu/lib/src/context.dart new file mode 100644 index 0000000000..1c1be14267 --- /dev/null +++ b/engine/src/flutter/lib/gpu/lib/src/context.dart @@ -0,0 +1,28 @@ +// 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 'dart:ffi'; +import 'dart:nativewrappers'; + +/// A handle to a graphics context. Used to create and manage GPU resources. +/// +/// To obtain the default graphics context, use [getContext]. +class GpuContext extends NativeFieldWrapperClass1 { + /// Creates a new graphics context that corresponds to the default Impeller + /// context. + GpuContext._createDefault() { + final String? error = _initializeDefault(); + if (error != null) { + throw Exception(error); + } + } + + /// Associates the default Impeller context with this Context. + @Native( + symbol: 'InternalFlutterGpu_Context_InitializeDefault') + external String? _initializeDefault(); +} + +/// The default graphics context. +final GpuContext gpuContext = GpuContext._createDefault(); diff --git a/engine/src/flutter/lib/gpu/gpu.dart b/engine/src/flutter/lib/gpu/lib/src/smoketest.dart similarity index 94% rename from engine/src/flutter/lib/gpu/gpu.dart rename to engine/src/flutter/lib/gpu/lib/src/smoketest.dart index 039d11585e..1a77d43183 100644 --- a/engine/src/flutter/lib/gpu/gpu.dart +++ b/engine/src/flutter/lib/gpu/lib/src/smoketest.dart @@ -2,8 +2,6 @@ // 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'; @@ -11,10 +9,12 @@ import 'dart:nativewrappers'; @Native(symbol: 'InternalFlutterGpuTestProc') external int testProc(); +/// A single parameter callback. +typedef Callback = void Function(T result); + /// 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 = void Function(T result); @Native( symbol: 'InternalFlutterGpuTestProcWithCallback') external String? testProcWithCallback(Callback callback); @@ -22,6 +22,7 @@ external String? testProcWithCallback(Callback 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 { + /// Default constructor for the test class FlutterGpuTestClass() { _constructor(); } diff --git a/engine/src/flutter/lib/gpu/pubspec.yaml b/engine/src/flutter/lib/gpu/pubspec.yaml new file mode 100644 index 0000000000..a45d82dab1 --- /dev/null +++ b/engine/src/flutter/lib/gpu/pubspec.yaml @@ -0,0 +1,14 @@ +# 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. + +name: flutter_gpu +description: A framework for writing Flutter applications +homepage: https://flutter.dev + +environment: + sdk: '>=3.0.0-0 <4.0.0' + +dependencies: + sky_engine: + sdk: flutter diff --git a/engine/src/flutter/lib/gpu/gpu.cc b/engine/src/flutter/lib/gpu/smoketest.cc similarity index 88% rename from engine/src/flutter/lib/gpu/gpu.cc rename to engine/src/flutter/lib/gpu/smoketest.cc index 4d6bf37bbc..54411d7397 100644 --- a/engine/src/flutter/lib/gpu/gpu.cc +++ b/engine/src/flutter/lib/gpu/smoketest.cc @@ -2,7 +2,7 @@ // 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/lib/gpu/smoketest.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/lib/ui/dart_wrapper.h" #include "flutter/lib/ui/ui_dart_state.h" @@ -23,6 +23,10 @@ FlutterGpuTestClass::~FlutterGpuTestClass() = default; } // namespace flutter +//---------------------------------------------------------------------------- +/// Exports +/// + // TODO(131346): Remove this once we migrate the Dart GPU API into this space. uint32_t InternalFlutterGpuTestProc() { return 1; @@ -52,9 +56,3 @@ 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(); -} diff --git a/engine/src/flutter/lib/gpu/gpu.h b/engine/src/flutter/lib/gpu/smoketest.h similarity index 80% rename from engine/src/flutter/lib/gpu/gpu.h rename to engine/src/flutter/lib/gpu/smoketest.h index 0007845a34..d957b9daac 100644 --- a/engine/src/flutter/lib/gpu/gpu.h +++ b/engine/src/flutter/lib/gpu/smoketest.h @@ -2,22 +2,16 @@ // 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_ +#pragma once #include +#include "flutter/lib/gpu/export.h" #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. @@ -32,26 +26,28 @@ class FlutterGpuTestClass } // namespace flutter +//---------------------------------------------------------------------------- +/// Exports +/// + extern "C" { // TODO(131346): Remove this once we migrate the Dart GPU API into this space. -FLUTTER_EXPORT +FLUTTER_GPU_EXPORT extern uint32_t InternalFlutterGpuTestProc(); // TODO(131346): Remove this once we migrate the Dart GPU API into this space. -FLUTTER_EXPORT +FLUTTER_GPU_EXPORT extern Dart_Handle InternalFlutterGpuTestProcWithCallback(Dart_Handle callback); // TODO(131346): Remove this once we migrate the Dart GPU API into this space. -FLUTTER_EXPORT +FLUTTER_GPU_EXPORT extern void InternalFlutterGpuTestClass_Create(Dart_Handle wrapper); // TODO(131346): Remove this once we migrate the Dart GPU API into this space. -FLUTTER_EXPORT +FLUTTER_GPU_EXPORT extern void InternalFlutterGpuTestClass_Method( flutter::FlutterGpuTestClass* self, int something); } // extern "C" - -#endif // FLUTTER_LIB_GPU_GPU_H_ diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index aae6a6e94a..596dac782b 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -216,12 +216,6 @@ source_set("ui") { "painting/scene/scene_shader.h", ] - # Experimental "Impeller Dart" API. - sources += [ - "gpu/context.cc", - "gpu/context.h", - ] - deps += [ "//flutter/impeller/scene" ] } } diff --git a/engine/src/flutter/lib/ui/dart_ui.cc b/engine/src/flutter/lib/ui/dart_ui.cc index efb5af0a30..b2fdbf88d4 100644 --- a/engine/src/flutter/lib/ui/dart_ui.cc +++ b/engine/src/flutter/lib/ui/dart_ui.cc @@ -12,7 +12,6 @@ #include "flutter/lib/ui/compositing/scene.h" #include "flutter/lib/ui/compositing/scene_builder.h" #include "flutter/lib/ui/dart_runtime_hooks.h" -#include "flutter/lib/ui/gpu/context.h" #include "flutter/lib/ui/isolate_name_server/isolate_name_server_natives.h" #include "flutter/lib/ui/painting/canvas.h" #include "flutter/lib/ui/painting/codec.h" @@ -316,10 +315,6 @@ typedef CanvasPath Path; V(SceneShader, SetCameraTransform, 2) \ V(SceneShader, Dispose, 1) -#define FFI_FUNCTION_LIST_GPU(V) V(GpuContext::InitializeDefault, 1) - -#define FFI_METHOD_LIST_GPU(V) - #endif // IMPELLER_ENABLE_3D #define FFI_FUNCTION_INSERT(FUNCTION, ARGS) \ @@ -352,9 +347,6 @@ void InitDispatcherMap() { #ifdef IMPELLER_ENABLE_3D FFI_FUNCTION_LIST_3D(FFI_FUNCTION_INSERT) FFI_METHOD_LIST_3D(FFI_METHOD_INSERT) - - FFI_FUNCTION_LIST_GPU(FFI_FUNCTION_INSERT) - FFI_METHOD_LIST_GPU(FFI_METHOD_INSERT) #endif // IMPELLER_ENABLE_3D } diff --git a/engine/src/flutter/lib/ui/gpu/context.h b/engine/src/flutter/lib/ui/gpu/context.h deleted file mode 100644 index 5d9056bdb3..0000000000 --- a/engine/src/flutter/lib/ui/gpu/context.h +++ /dev/null @@ -1,37 +0,0 @@ -// 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_UI_GPU_H_ -#define FLUTTER_LIB_UI_GPU_H_ - -#include - -#include "flutter/fml/macros.h" -#include "flutter/fml/memory/ref_counted.h" -#include "flutter/lib/ui/dart_wrapper.h" -#include "impeller/renderer/context.h" -#include "third_party/tonic/dart_library_natives.h" -#include "third_party/tonic/dart_wrappable.h" - -namespace flutter { - -class GpuContext : public RefCountedDartWrappable { - DEFINE_WRAPPERTYPEINFO(); - FML_FRIEND_MAKE_REF_COUNTED(GpuContext); - - public: - explicit GpuContext(std::shared_ptr context); - ~GpuContext() override; - - static std::string InitializeDefault(Dart_Handle wrapper); - - private: - std::shared_ptr context_; - - FML_DISALLOW_COPY_AND_ASSIGN(GpuContext); -}; - -} // namespace flutter - -#endif // FLUTTER_LIB_UI_GPU_H_ diff --git a/engine/src/flutter/testing/dart/gpu_test.dart b/engine/src/flutter/testing/dart/gpu_test.dart index e6fab02478..0c96b6646d 100644 --- a/engine/src/flutter/testing/dart/gpu_test.dart +++ b/engine/src/flutter/testing/dart/gpu_test.dart @@ -5,11 +5,11 @@ // ignore_for_file: avoid_relative_lib_imports import 'package:litetest/litetest.dart'; -import '../../lib/gpu/gpu.dart' as gpu; +import '../../lib/gpu/lib/gpu.dart' as gpu; void main() { // TODO(131346): Remove this once we migrate the Dart GPU API into this space. - test('no crash', () async { + test('smoketest', () async { final int result = gpu.testProc(); expect(result, 1); @@ -21,4 +21,17 @@ void main() { final gpu.FlutterGpuTestClass a = gpu.FlutterGpuTestClass(); a.coolMethod(9847); }); + + test('gpu.context throws exception for incompatible embedders', () async { + try { + // ignore: unnecessary_statements + gpu.gpuContext; // Force the + fail('Exception not thrown'); + } catch (e) { + expect( + e.toString(), + contains( + 'Flutter GPU requires the Impeller rendering backend to be enabled.')); + } + }); }