Skip to content

Commit

Permalink
[Impeller] add --enable-impeller-3d flag to support scene experimenta…
Browse files Browse the repository at this point in the history
…tion (#37990)

* ++

* ++

* ++

* ++

* ++

* ++

* ++

* ++
  • Loading branch information
jonahwilliams authored Dec 3, 2022
1 parent bebc12f commit 2c1e5ef
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ FILE: ../../../flutter/impeller/typographer/typographer_unittests.cc
FILE: ../../../flutter/lib/io/dart_io.cc
FILE: ../../../flutter/lib/io/dart_io.h
FILE: ../../../flutter/lib/snapshot/libraries.json
FILE: ../../../flutter/lib/snapshot/libraries_experimental.json
FILE: ../../../flutter/lib/snapshot/snapshot.h
FILE: ../../../flutter/lib/ui/annotations.dart
FILE: ../../../flutter/lib/ui/channel_buffers.dart
Expand All @@ -1728,6 +1729,8 @@ FILE: ../../../flutter/lib/ui/dart_runtime_hooks.h
FILE: ../../../flutter/lib/ui/dart_ui.cc
FILE: ../../../flutter/lib/ui/dart_ui.h
FILE: ../../../flutter/lib/ui/dart_wrapper.h
FILE: ../../../flutter/lib/ui/experiments/compositing_3d.dart
FILE: ../../../flutter/lib/ui/experiments/ui.dart
FILE: ../../../flutter/lib/ui/geometry.dart
FILE: ../../../flutter/lib/ui/hash_codes.dart
FILE: ../../../flutter/lib/ui/hooks.dart
Expand Down
3 changes: 3 additions & 0 deletions impeller/tools/impeller.gni
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ declare_args() {

# Call glGetError after each OpenGL call and log failures.
impeller_error_check_all_gl_calls = is_debug

# Eperimentally enable 3d code paths.
impeller_enable_3d = false
}

declare_args() {
Expand Down
10 changes: 8 additions & 2 deletions lib/snapshot/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import("//build/compiled_action.gni")
import("//build/fuchsia/sdk.gni")
import("//flutter/common/config.gni")
import("//flutter/impeller/tools/impeller.gni")
import("//flutter/lib/ui/dart_ui.gni")
import("//third_party/dart/utils/compile_platform.gni")

Expand Down Expand Up @@ -315,8 +316,13 @@ source_set("snapshot") {
compile_platform("strong_platform") {
single_root_scheme = "org-dartlang-sdk"
single_root_base = rebase_path("../../../")
libraries_specification_uri =
"org-dartlang-sdk:///flutter/lib/snapshot/libraries.json"
if (impeller_enable_3d) {
libraries_specification_uri =
"org-dartlang-sdk:///flutter/lib/snapshot/libraries_experimental.json"
} else {
libraries_specification_uri =
"org-dartlang-sdk:///flutter/lib/snapshot/libraries.json"
}

outputs = [
"$root_out_dir/flutter_patched_sdk/platform_strong.dill",
Expand Down
17 changes: 17 additions & 0 deletions lib/snapshot/libraries_experimental.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"comment:0": "NOTE: THIS FILE IS GENERATED. DO NOT EDIT.",
"comment:1": "Instead modify 'flutter/lib/snapshot/libraries.yaml' and follow the instructions therein.",
"flutter": {
"include": [
{
"path": "../../../third_party/dart/sdk/lib/libraries.json",
"target": "vm_common"
}
],
"libraries": {
"ui": {
"uri": "../../lib/ui/experiments/ui.dart"
}
}
}
}
3 changes: 3 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ source_set("ui") {
# Required for M_PI and others.
defines += [ "_USE_MATH_DEFINES" ]
}
if (impeller_enable_3d) {
defines += [ "IMPELLER_ENABLE_3D" ]
}
}

if (enable_unittests) {
Expand Down
16 changes: 16 additions & 0 deletions lib/ui/compositing/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ void SceneBuilder::addTexture(double dx,
AddLayer(std::move(layer));
}

#ifdef IMPELLER_ENABLE_3D
// static
void SceneBuilder::addModelLayer(Dart_Handle wrapper,
double dx,
double dy,
double width,
double height,
int64_t viewId) {
auto* scene_builder = tonic::DartConverter<SceneBuilder*>::FromDart(wrapper);
SkMatrix sk_matrix = SkMatrix::Translate(dx, dy);
auto layer = std::make_shared<flutter::TransformLayer>(sk_matrix);
scene_builder->AddLayer(std::move(layer));
}

#endif // IMPELLER_ENABLE_3D

void SceneBuilder::addPlatformView(double dx,
double dy,
double width,
Expand Down
9 changes: 9 additions & 0 deletions lib/ui/compositing/scene_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
res->AssociateWithDartWrapper(wrapper);
}

#ifdef IMPELLER_ENABLE_3D
static void addModelLayer(Dart_Handle wrapper,
double dx,
double dy,
double width,
double height,
int64_t viewId);
#endif // IMPELLER_ENABLE_3D

~SceneBuilder() override;

void pushTransformHandle(Dart_Handle layer_handle,
Expand Down
7 changes: 7 additions & 0 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ typedef CanvasPath Path;
V(SemanticsUpdate, dispose, 1) \
V(Vertices, dispose, 1)

#ifdef IMPELLER_ENABLE_3D
#define FFI_METHOD_LIST_3D(V) V(SceneBuilder::addModelLayer, 7)
#endif // IMPELLER_ENABLE_3D

#define FFI_FUNCTION_INSERT(FUNCTION, ARGS) \
g_function_dispatchers.insert(std::make_pair( \
std::string_view(#FUNCTION), \
Expand All @@ -320,6 +324,9 @@ void* ResolveFfiNativeFunction(const char* name, uintptr_t args) {
void InitDispatcherMap() {
FFI_FUNCTION_LIST(FFI_FUNCTION_INSERT)
FFI_METHOD_LIST(FFI_METHOD_INSERT)
#ifdef IMPELLER_ENABLE_3D
FFI_METHOD_LIST_3D(FFI_FUNCTION_INSERT)
#endif // IMPELLER_ENABLE_3D
}

} // anonymous namespace
Expand Down
18 changes: 18 additions & 0 deletions lib/ui/experiments/compositing_3d.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.
part of dart.ui;

void addModelLayer(
SceneBuilder builder,
int viewId, {
Offset offset = Offset.zero,
double width = 0.0,
double height = 0.0,
}) {
assert(offset != null, 'Offset argument was null');
_addModelLayer(builder, offset.dx, offset.dy, width, height, viewId);
}

@FfiNative<Void Function(Handle, Double, Double, Double, Double, Int64)>('SceneBuilder::addModelLayer')
external void _addModelLayer(Object object, double dx, double dy, double width, double height, int viewId);
43 changes: 43 additions & 0 deletions lib/ui/experiments/ui.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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.

/// Built-in types and core primitives for a Flutter application.
///
/// To use, import `dart:ui`.
///
/// This library exposes the lowest-level services that Flutter frameworks use
/// to bootstrap applications, such as classes for driving the input, graphics
/// text, layout, and rendering subsystems.
library dart.ui;

import 'dart:async';
import 'dart:collection' as collection;
import 'dart:convert';
import 'dart:developer' as developer;
import 'dart:ffi';
import 'dart:io';
import 'dart:isolate' show SendPort;
import 'dart:math' as math;
import 'dart:nativewrappers';
import 'dart:typed_data';

part '../annotations.dart';
part '../channel_buffers.dart';
part '../compositing.dart';
part 'compositing_3d.dart';
part '../geometry.dart';
part '../hash_codes.dart';
part '../hooks.dart';
part '../isolate_name_server.dart';
part '../key.dart';
part '../lerp.dart';
part '../math.dart';
part '../natives.dart';
part '../painting.dart';
part '../platform_dispatcher.dart';
part '../plugins.dart';
part '../pointer.dart';
part '../semantics.dart';
part '../text.dart';
part '../window.dart';
10 changes: 10 additions & 0 deletions tools/gn
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ def to_gn_args(args):
elif os.getenv('FLUTTER_IMPELLER_ENABLE_PLAYGROUND', '0') == '1':
gn_args['impeller_enable_playground'] = True

if args.enable_impeller_3d:
gn_args['impeller_enable_3d'] = True

if args.prebuilt_impellerc is not None:
gn_args['impeller_use_prebuilt_impellerc'] = args.prebuilt_impellerc

Expand Down Expand Up @@ -978,6 +981,13 @@ def parse_args(args):
'https://github.com/flutter/flutter/issues/107357'
)

parser.add_argument(
'--enable-impeller-3d',
default=False,
action='store_true',
help='Enables experimental 3d support.'
)

# Sanitizers.
parser.add_argument('--asan', default=False, action='store_true')
parser.add_argument('--lsan', default=False, action='store_true')
Expand Down

0 comments on commit 2c1e5ef

Please sign in to comment.