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

[Impeller Scene] Add DisplayList OP and Dart bindings #38676

Merged
merged 24 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ ORIGIN: ../../../flutter/lib/ui/dart_runtime_hooks.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/dart_ui.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/dart_ui.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/dart_wrapper.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/experiments/compositing_3d.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/experiments/scene.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/experiments/ui.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/geometry.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/hash_codes.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -1783,6 +1783,10 @@ ORIGIN: ../../../flutter/lib/ui/painting/picture_recorder.cc + ../../../flutter/
ORIGIN: ../../../flutter/lib/ui/painting/picture_recorder.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/rrect.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/rrect.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/scene/scene_node.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/scene/scene_node.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/scene/scene_shader.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/scene/scene_shader.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/shader.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/shader.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/ui/painting/single_frame_codec.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4175,7 +4179,7 @@ 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/scene.dart
FILE: ../../../flutter/lib/ui/experiments/ui.dart
FILE: ../../../flutter/lib/ui/geometry.dart
FILE: ../../../flutter/lib/ui/hash_codes.dart
Expand Down Expand Up @@ -4255,6 +4259,10 @@ FILE: ../../../flutter/lib/ui/painting/picture_recorder.cc
FILE: ../../../flutter/lib/ui/painting/picture_recorder.h
FILE: ../../../flutter/lib/ui/painting/rrect.cc
FILE: ../../../flutter/lib/ui/painting/rrect.h
FILE: ../../../flutter/lib/ui/painting/scene/scene_node.cc
FILE: ../../../flutter/lib/ui/painting/scene/scene_node.h
FILE: ../../../flutter/lib/ui/painting/scene/scene_shader.cc
FILE: ../../../flutter/lib/ui/painting/scene/scene_shader.h
FILE: ../../../flutter/lib/ui/painting/shader.cc
FILE: ../../../flutter/lib/ui/painting/shader.h
FILE: ../../../flutter/lib/ui/painting/single_frame_codec.cc
Expand Down
1 change: 1 addition & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ source_set("display_list") {
public_deps = [
"//flutter/fml",
"//flutter/impeller/runtime_stage",
"//flutter/impeller/scene",
"//third_party/skia",
]
}
Expand Down
1 change: 1 addition & 0 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ namespace flutter {
V(SetSkColorSource) \
V(SetImageColorSource) \
V(SetRuntimeEffectColorSource) \
V(SetSceneColorSource) \
\
V(ClearImageFilter) \
V(SetPodImageFilter) \
Expand Down
7 changes: 7 additions & 0 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/display_list/display_list_canvas_dispatcher.h"
#include "flutter/display_list/display_list_color_source.h"
#include "flutter/display_list/display_list_ops.h"
#include "fml/logging.h"

namespace flutter {

Expand Down Expand Up @@ -202,6 +203,12 @@ void DisplayListBuilder::onSetColorSource(const DlColorSource* source) {
Push<SetRuntimeEffectColorSourceOp>(0, 0, effect);
break;
}
case DlColorSourceType::kScene: {
const DlSceneColorSource* scene = source->asScene();
FML_DCHECK(scene);
Push<SetSceneColorSourceOp>(0, 0, scene);
break;
}
case DlColorSourceType::kUnknown:
Push<SetSkColorSourceOp>(0, 0, source->skia_object());
break;
Expand Down
46 changes: 46 additions & 0 deletions display_list/display_list_color_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "flutter/display_list/display_list_tile_mode.h"
#include "flutter/display_list/types.h"
#include "flutter/fml/logging.h"
#include "impeller/geometry/matrix.h"
#include "impeller/scene/node.h"
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkRuntimeEffect.h"
Expand All @@ -31,6 +33,7 @@ class DlRadialGradientColorSource;
class DlConicalGradientColorSource;
class DlSweepGradientColorSource;
class DlRuntimeEffectColorSource;
class DlSceneColorSource;
class DlUnknownColorSource;

// The DisplayList ColorSource class. This class implements all of the
Expand All @@ -51,6 +54,7 @@ enum class DlColorSourceType {
kConicalGradient,
kSweepGradient,
kRuntimeEffect,
kScene,
kUnknown
};

Expand Down Expand Up @@ -160,6 +164,8 @@ class DlColorSource
return nullptr;
}

virtual const DlSceneColorSource* asScene() const { return nullptr; }

// If this filter contains images, specifies the owning context for those
// images.
// Images with a DlImage::OwningContext::kRaster must only call skia_object
Expand Down Expand Up @@ -754,6 +760,46 @@ class DlRuntimeEffectColorSource final : public DlColorSource {
FML_DISALLOW_COPY_ASSIGN_AND_MOVE(DlRuntimeEffectColorSource);
};

class DlSceneColorSource final : public DlColorSource {
public:
DlSceneColorSource(std::shared_ptr<impeller::scene::Node> node,
impeller::Matrix camera_matrix)
: node_(std::move(node)), camera_matrix_(camera_matrix) {}

const DlSceneColorSource* asScene() const override { return this; }

std::shared_ptr<DlColorSource> shared() const override {
return std::make_shared<DlSceneColorSource>(node_, camera_matrix_);
}

DlColorSourceType type() const override { return DlColorSourceType::kScene; }
size_t size() const override { return sizeof(*this); }

bool is_opaque() const override { return false; }

std::shared_ptr<impeller::scene::Node> scene_node() const { return node_; }

impeller::Matrix camera_matrix() const { return camera_matrix_; }

sk_sp<SkShader> skia_object() const override { return nullptr; }

protected:
bool equals_(DlColorSource const& other) const override {
FML_DCHECK(other.type() == DlColorSourceType::kScene);
auto that = static_cast<DlSceneColorSource const*>(&other);
if (node_ != that->node_) {
return false;
}
return true;
}

private:
std::shared_ptr<impeller::scene::Node> node_;
impeller::Matrix camera_matrix_; // the view-projection matrix of the scene.

FML_DISALLOW_COPY_ASSIGN_AND_MOVE(DlSceneColorSource);
};

class DlUnknownColorSource final : public DlColorSource {
public:
DlUnknownColorSource(sk_sp<SkShader> shader)
Expand Down
18 changes: 18 additions & 0 deletions display_list/display_list_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ struct SetRuntimeEffectColorSourceOp : DLOp {
}
};

struct SetSceneColorSourceOp : DLOp {
static const auto kType = DisplayListOpType::kSetSceneColorSource;

SetSceneColorSourceOp(const DlSceneColorSource* source)
: source(source->scene_node(), source->camera_matrix()) {}

const DlSceneColorSource source;

void dispatch(DispatchContext& ctx) const {
ctx.dispatcher.setColorSource(&source);
}

DisplayListCompare equals(const SetSceneColorSourceOp* other) const {
return (source == other->source) ? DisplayListCompare::kEqual
: DisplayListCompare::kNotEqual;
}
};

// 4 byte header + 16 byte payload uses 24 total bytes (4 bytes unused)
struct SetSharedImageFilterOp : DLOp {
static const auto kType = DisplayListOpType::kSetSharedImageFilter;
Expand Down
16 changes: 9 additions & 7 deletions impeller/display_list/display_list_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ static std::optional<Paint::ColorSourceType> ToColorSourceType(
return Paint::ColorSourceType::kSweepGradient;
case flutter::DlColorSourceType::kRuntimeEffect:
return Paint::ColorSourceType::kRuntimeEffect;
case flutter::DlColorSourceType::kScene:
return Paint::ColorSourceType::kScene;
case flutter::DlColorSourceType::kUnknown:
return std::nullopt;
}
Expand Down Expand Up @@ -502,15 +504,15 @@ void DisplayListDispatcher::setColorSource(
return;
}
case Paint::ColorSourceType::kScene: {
// const flutter::DlSceneColorSource* scene_color_source =
// source->asScene(); std::shared_ptr<scene::Node> scene_node =
// scene_color_source->node(); Matrix camera_transform =
// scene_color_node->camera_transform();
const flutter::DlSceneColorSource* scene_color_source = source->asScene();
std::shared_ptr<scene::Node> scene_node =
scene_color_source->scene_node();
Matrix camera_transform = scene_color_source->camera_matrix();

paint_.color_source = [/*scene_node, camera_transform*/]() {
paint_.color_source = [scene_node, camera_transform]() {
auto contents = std::make_shared<SceneContents>();
// contents->SetNode(scene_node);
// contents->SetCameraTransform(camera_transform);
contents->SetNode(scene_node);
contents->SetCameraTransform(camera_transform);
return contents;
};
}
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ source_set("ui") {
"painting/picture_recorder.h",
"painting/rrect.cc",
"painting/rrect.h",
"painting/scene/scene_node.cc",
"painting/scene/scene_node.h",
"painting/scene/scene_shader.cc",
"painting/scene/scene_shader.h",
"painting/shader.cc",
"painting/shader.h",
"painting/single_frame_codec.cc",
Expand Down Expand Up @@ -155,6 +159,7 @@ source_set("ui") {
"//flutter/display_list",
"//flutter/fml",
"//flutter/impeller/runtime_stage",
"//flutter/impeller/scene",
"//flutter/runtime:dart_plugin_registrant",
"//flutter/runtime:test_font",
"//flutter/third_party/tonic",
Expand Down
16 changes: 0 additions & 16 deletions lib/ui/compositing/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,6 @@ 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: 0 additions & 9 deletions lib/ui/compositing/scene_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ 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
20 changes: 18 additions & 2 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "flutter/lib/ui/painting/path_measure.h"
#include "flutter/lib/ui/painting/picture.h"
#include "flutter/lib/ui/painting/picture_recorder.h"
#include "flutter/lib/ui/painting/scene/scene_node.h"
#include "flutter/lib/ui/painting/scene/scene_shader.h"
#include "flutter/lib/ui/painting/vertices.h"
#include "flutter/lib/ui/semantics/semantics_update.h"
#include "flutter/lib/ui/semantics/semantics_update_builder.h"
Expand Down Expand Up @@ -295,7 +297,20 @@ typedef CanvasPath Path;
V(Vertices, dispose, 1)

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

#define FFI_FUNCTION_LIST_3D(V) \
V(SceneNode::Create, 1) V(SceneShader::Create, 1)

#define FFI_METHOD_LIST_3D(V) \
V(SceneNode, initFromAsset, 3) \
V(SceneNode, initFromTransform, 2) \
V(SceneNode, AddChild, 2) \
V(SceneNode, SetTransform, 2) \
V(SceneNode, SetAnimationState, 5) \
V(SceneNode, SeekAnimation, 3) \
V(SceneShader, SetCameraTransform, 2) \
V(SceneShader, Dispose, 1)

#endif // IMPELLER_ENABLE_3D

#define FFI_FUNCTION_INSERT(FUNCTION, ARGS) \
Expand Down Expand Up @@ -325,7 +340,8 @@ 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)
FFI_FUNCTION_LIST_3D(FFI_FUNCTION_INSERT)
FFI_METHOD_LIST_3D(FFI_METHOD_INSERT)
#endif // IMPELLER_ENABLE_3D
}

Expand Down
18 changes: 0 additions & 18 deletions lib/ui/experiments/compositing_3d.dart

This file was deleted.

Loading