未验证 提交 e44c10c9 编写于 作者: L liyuqian 提交者: GitHub

Reland "Share engine layers with the framework" (#6412) (#6468)

This reverts commit 74662ab6.

This should land after https://github.com/flutter/engine/pull/6442

* Add pragma vm:entry-point

Otherwise, an object may be both null and an instance of EnginieLayer at
the same time in Dart.
上级 ba044997
...@@ -561,6 +561,8 @@ TYPE: LicenseType.bsd ...@@ -561,6 +561,8 @@ TYPE: LicenseType.bsd
FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart
FILE: ../../../flutter/fml/paths_unittests.cc FILE: ../../../flutter/fml/paths_unittests.cc
FILE: ../../../flutter/lib/ui/isolate_name_server.dart FILE: ../../../flutter/lib/ui/isolate_name_server.dart
FILE: ../../../flutter/lib/ui/painting/engine_layer.cc
FILE: ../../../flutter/lib/ui/painting/engine_layer.h
FILE: ../../../flutter/lib/ui/painting/image_encoding.cc FILE: ../../../flutter/lib/ui/painting/image_encoding.cc
FILE: ../../../flutter/lib/ui/painting/image_encoding.h FILE: ../../../flutter/lib/ui/painting/image_encoding.h
FILE: ../../../flutter/lib/ui/plugins.dart FILE: ../../../flutter/lib/ui/plugins.dart
......
...@@ -10,7 +10,7 @@ ContainerLayer::ContainerLayer() {} ...@@ -10,7 +10,7 @@ ContainerLayer::ContainerLayer() {}
ContainerLayer::~ContainerLayer() = default; ContainerLayer::~ContainerLayer() = default;
void ContainerLayer::Add(std::unique_ptr<Layer> layer) { void ContainerLayer::Add(std::shared_ptr<Layer> layer) {
layer->set_parent(this); layer->set_parent(this);
layers_.push_back(std::move(layer)); layers_.push_back(std::move(layer));
} }
......
...@@ -15,7 +15,7 @@ class ContainerLayer : public Layer { ...@@ -15,7 +15,7 @@ class ContainerLayer : public Layer {
ContainerLayer(); ContainerLayer();
~ContainerLayer() override; ~ContainerLayer() override;
void Add(std::unique_ptr<Layer> layer); void Add(std::shared_ptr<Layer> layer);
void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
...@@ -23,7 +23,7 @@ class ContainerLayer : public Layer { ...@@ -23,7 +23,7 @@ class ContainerLayer : public Layer {
void UpdateScene(SceneUpdateContext& context) override; void UpdateScene(SceneUpdateContext& context) override;
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
const std::vector<std::unique_ptr<Layer>>& layers() const { return layers_; } const std::vector<std::shared_ptr<Layer>>& layers() const { return layers_; }
protected: protected:
void PrerollChildren(PrerollContext* context, void PrerollChildren(PrerollContext* context,
...@@ -36,7 +36,7 @@ class ContainerLayer : public Layer { ...@@ -36,7 +36,7 @@ class ContainerLayer : public Layer {
#endif // defined(OS_FUCHSIA) #endif // defined(OS_FUCHSIA)
private: private:
std::vector<std::unique_ptr<Layer>> layers_; std::vector<std::shared_ptr<Layer>> layers_;
FML_DISALLOW_COPY_AND_ASSIGN(ContainerLayer); FML_DISALLOW_COPY_AND_ASSIGN(ContainerLayer);
}; };
......
...@@ -39,7 +39,7 @@ class LayerTree { ...@@ -39,7 +39,7 @@ class LayerTree {
Layer* root_layer() const { return root_layer_.get(); } Layer* root_layer() const { return root_layer_.get(); }
void set_root_layer(std::unique_ptr<Layer> root_layer) { void set_root_layer(std::shared_ptr<Layer> root_layer) {
root_layer_ = std::move(root_layer); root_layer_ = std::move(root_layer);
} }
...@@ -74,7 +74,7 @@ class LayerTree { ...@@ -74,7 +74,7 @@ class LayerTree {
private: private:
SkISize frame_size_; // Physical pixels. SkISize frame_size_; // Physical pixels.
std::unique_ptr<Layer> root_layer_; std::shared_ptr<Layer> root_layer_;
fml::TimeDelta construction_time_; fml::TimeDelta construction_time_;
uint32_t rasterizer_tracing_threshold_; uint32_t rasterizer_tracing_threshold_;
bool checkerboard_raster_cache_images_; bool checkerboard_raster_cache_images_;
......
...@@ -23,6 +23,8 @@ source_set("ui") { ...@@ -23,6 +23,8 @@ source_set("ui") {
"painting/canvas.h", "painting/canvas.h",
"painting/codec.cc", "painting/codec.cc",
"painting/codec.h", "painting/codec.h",
"painting/engine_layer.h",
"painting/engine_layer.cc",
"painting/frame_info.cc", "painting/frame_info.cc",
"painting/frame_info.h", "painting/frame_info.h",
"painting/gradient.cc", "painting/gradient.cc",
......
...@@ -69,7 +69,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 { ...@@ -69,7 +69,7 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// This is equivalent to [pushTransform] with a matrix with only translation. /// This is equivalent to [pushTransform] with a matrix with only translation.
/// ///
/// See [pop] for details about the operation stack. /// See [pop] for details about the operation stack.
void pushOffset(double dx, double dy) native 'SceneBuilder_pushOffset'; EngineLayer pushOffset(double dx, double dy) native 'SceneBuilder_pushOffset';
/// Pushes a rectangular clip operation onto the operation stack. /// Pushes a rectangular clip operation onto the operation stack.
/// ///
...@@ -177,10 +177,10 @@ class SceneBuilder extends NativeFieldWrapperClass2 { ...@@ -177,10 +177,10 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// ///
/// See [pop] for details about the operation stack, and [Clip] for different clip modes. /// See [pop] for details about the operation stack, and [Clip] for different clip modes.
// ignore: deprecated_member_use // ignore: deprecated_member_use
void pushPhysicalShape({ Path path, double elevation, Color color, Color shadowColor, Clip clipBehavior = defaultClipBehavior}) { EngineLayer pushPhysicalShape({ Path path, double elevation, Color color, Color shadowColor, Clip clipBehavior = defaultClipBehavior}) {
_pushPhysicalShape(path, elevation, color.value, shadowColor?.value ?? 0xFF000000, clipBehavior.index); return _pushPhysicalShape(path, elevation, color.value, shadowColor?.value ?? 0xFF000000, clipBehavior.index);
} }
void _pushPhysicalShape(Path path, double elevation, int color, int shadowColor, int clipBehavior) native EngineLayer _pushPhysicalShape(Path path, double elevation, int color, int shadowColor, int clipBehavior) native
'SceneBuilder_pushPhysicalShape'; 'SceneBuilder_pushPhysicalShape';
/// Ends the effect of the most recently pushed operation. /// Ends the effect of the most recently pushed operation.
...@@ -191,6 +191,16 @@ class SceneBuilder extends NativeFieldWrapperClass2 { ...@@ -191,6 +191,16 @@ class SceneBuilder extends NativeFieldWrapperClass2 {
/// stack. /// stack.
void pop() native 'SceneBuilder_pop'; void pop() native 'SceneBuilder_pop';
/// Add a retained engine layer subtree from previous frames.
///
/// All the engine layers that are in the subtree of the retained layer will
/// be automatically appended to the current engine layer tree.
///
/// Therefore, when implementing a subclas of the [Layer] concept defined in
/// the rendering layer of Flutter's framework, once this is called, there's
/// no need to call [addToScene] for its children layers.
EngineLayer addRetained(EngineLayer retainedLayer) native 'SceneBuilder_addRetained';
/// Adds an object to the scene that displays performance statistics. /// Adds an object to the scene that displays performance statistics.
/// ///
/// Useful during development to assess the performance of the application. /// Useful during development to assess the performance of the application.
......
...@@ -26,7 +26,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Scene); ...@@ -26,7 +26,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Scene);
DART_BIND_ALL(Scene, FOR_EACH_BINDING) DART_BIND_ALL(Scene, FOR_EACH_BINDING)
fml::RefPtr<Scene> Scene::create(std::unique_ptr<flow::Layer> rootLayer, fml::RefPtr<Scene> Scene::create(std::shared_ptr<flow::Layer> rootLayer,
uint32_t rasterizerTracingThreshold, uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages, bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers) { bool checkerboardOffscreenLayers) {
...@@ -35,7 +35,7 @@ fml::RefPtr<Scene> Scene::create(std::unique_ptr<flow::Layer> rootLayer, ...@@ -35,7 +35,7 @@ fml::RefPtr<Scene> Scene::create(std::unique_ptr<flow::Layer> rootLayer,
checkerboardRasterCacheImages, checkerboardOffscreenLayers); checkerboardRasterCacheImages, checkerboardOffscreenLayers);
} }
Scene::Scene(std::unique_ptr<flow::Layer> rootLayer, Scene::Scene(std::shared_ptr<flow::Layer> rootLayer,
uint32_t rasterizerTracingThreshold, uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages, bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers) bool checkerboardOffscreenLayers)
......
...@@ -24,7 +24,7 @@ class Scene : public RefCountedDartWrappable<Scene> { ...@@ -24,7 +24,7 @@ class Scene : public RefCountedDartWrappable<Scene> {
public: public:
~Scene() override; ~Scene() override;
static fml::RefPtr<Scene> create(std::unique_ptr<flow::Layer> rootLayer, static fml::RefPtr<Scene> create(std::shared_ptr<flow::Layer> rootLayer,
uint32_t rasterizerTracingThreshold, uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages, bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers); bool checkerboardOffscreenLayers);
...@@ -40,7 +40,7 @@ class Scene : public RefCountedDartWrappable<Scene> { ...@@ -40,7 +40,7 @@ class Scene : public RefCountedDartWrappable<Scene> {
static void RegisterNatives(tonic::DartLibraryNatives* natives); static void RegisterNatives(tonic::DartLibraryNatives* natives);
private: private:
explicit Scene(std::unique_ptr<flow::Layer> rootLayer, explicit Scene(std::shared_ptr<flow::Layer> rootLayer,
uint32_t rasterizerTracingThreshold, uint32_t rasterizerTracingThreshold,
bool checkerboardRasterCacheImages, bool checkerboardRasterCacheImages,
bool checkerboardOffscreenLayers); bool checkerboardOffscreenLayers);
......
...@@ -53,6 +53,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, SceneBuilder); ...@@ -53,6 +53,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, SceneBuilder);
V(SceneBuilder, pushShaderMask) \ V(SceneBuilder, pushShaderMask) \
V(SceneBuilder, pushPhysicalShape) \ V(SceneBuilder, pushPhysicalShape) \
V(SceneBuilder, pop) \ V(SceneBuilder, pop) \
V(SceneBuilder, addRetained) \
V(SceneBuilder, addPicture) \ V(SceneBuilder, addPicture) \
V(SceneBuilder, addTexture) \ V(SceneBuilder, addTexture) \
V(SceneBuilder, addChildScene) \ V(SceneBuilder, addChildScene) \
...@@ -80,11 +81,12 @@ void SceneBuilder::pushTransform(const tonic::Float64List& matrix4) { ...@@ -80,11 +81,12 @@ void SceneBuilder::pushTransform(const tonic::Float64List& matrix4) {
PushLayer(std::move(layer)); PushLayer(std::move(layer));
} }
void SceneBuilder::pushOffset(double dx, double dy) { fml::RefPtr<EngineLayer> SceneBuilder::pushOffset(double dx, double dy) {
SkMatrix sk_matrix = SkMatrix::MakeTrans(dx, dy); SkMatrix sk_matrix = SkMatrix::MakeTrans(dx, dy);
auto layer = std::make_unique<flow::TransformLayer>(); auto layer = std::make_shared<flow::TransformLayer>();
layer->set_transform(sk_matrix); layer->set_transform(sk_matrix);
PushLayer(std::move(layer)); PushLayer(layer);
return EngineLayer::MakeRetained(layer);
} }
void SceneBuilder::pushClipRect(double left, void SceneBuilder::pushClipRect(double left,
...@@ -148,21 +150,29 @@ void SceneBuilder::pushShaderMask(Shader* shader, ...@@ -148,21 +150,29 @@ void SceneBuilder::pushShaderMask(Shader* shader,
PushLayer(std::move(layer)); PushLayer(std::move(layer));
} }
void SceneBuilder::pushPhysicalShape(const CanvasPath* path, fml::RefPtr<EngineLayer> SceneBuilder::pushPhysicalShape(const CanvasPath* path,
double elevation, double elevation,
int color, int color,
int shadow_color, int shadow_color,
int clipBehavior) { int clipBehavior) {
const SkPath& sk_path = path->path(); const SkPath& sk_path = path->path();
flow::Clip clip_behavior = static_cast<flow::Clip>(clipBehavior); flow::Clip clip_behavior = static_cast<flow::Clip>(clipBehavior);
auto layer = std::make_unique<flow::PhysicalShapeLayer>(clip_behavior); auto layer = std::make_shared<flow::PhysicalShapeLayer>(clip_behavior);
layer->set_path(sk_path); layer->set_path(sk_path);
layer->set_elevation(elevation); layer->set_elevation(elevation);
layer->set_color(static_cast<SkColor>(color)); layer->set_color(static_cast<SkColor>(color));
layer->set_shadow_color(static_cast<SkColor>(shadow_color)); layer->set_shadow_color(static_cast<SkColor>(shadow_color));
layer->set_device_pixel_ratio( layer->set_device_pixel_ratio(
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio); UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio);
PushLayer(std::move(layer)); PushLayer(layer);
return EngineLayer::MakeRetained(layer);
}
void SceneBuilder::addRetained(fml::RefPtr<EngineLayer> retainedLayer) {
if (!current_layer_) {
return;
}
current_layer_->Add(retainedLayer->Layer());
} }
void SceneBuilder::pop() { void SceneBuilder::pop() {
...@@ -260,7 +270,7 @@ fml::RefPtr<Scene> SceneBuilder::build() { ...@@ -260,7 +270,7 @@ fml::RefPtr<Scene> SceneBuilder::build() {
return scene; return scene;
} }
void SceneBuilder::PushLayer(std::unique_ptr<flow::ContainerLayer> layer) { void SceneBuilder::PushLayer(std::shared_ptr<flow::ContainerLayer> layer) {
FML_DCHECK(layer); FML_DCHECK(layer);
if (!root_layer_) { if (!root_layer_) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "flutter/lib/ui/compositing/scene.h" #include "flutter/lib/ui/compositing/scene.h"
#include "flutter/lib/ui/compositing/scene_host.h" #include "flutter/lib/ui/compositing/scene_host.h"
#include "flutter/lib/ui/dart_wrapper.h" #include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/lib/ui/painting/engine_layer.h"
#include "flutter/lib/ui/painting/image_filter.h" #include "flutter/lib/ui/painting/image_filter.h"
#include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/path.h"
#include "flutter/lib/ui/painting/picture.h" #include "flutter/lib/ui/painting/picture.h"
...@@ -33,7 +34,7 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> { ...@@ -33,7 +34,7 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
~SceneBuilder() override; ~SceneBuilder() override;
void pushTransform(const tonic::Float64List& matrix4); void pushTransform(const tonic::Float64List& matrix4);
void pushOffset(double dx, double dy); fml::RefPtr<EngineLayer> pushOffset(double dx, double dy);
void pushClipRect(double left, void pushClipRect(double left,
double right, double right,
double top, double top,
...@@ -50,11 +51,13 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> { ...@@ -50,11 +51,13 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
double maskRectTop, double maskRectTop,
double maskRectBottom, double maskRectBottom,
int blendMode); int blendMode);
void pushPhysicalShape(const CanvasPath* path, fml::RefPtr<EngineLayer> pushPhysicalShape(const CanvasPath* path,
double elevation, double elevation,
int color, int color,
int shadowColor, int shadowColor,
int clipBehavior); int clipBehavior);
void addRetained(fml::RefPtr<EngineLayer> retainedLayer);
void pop(); void pop();
...@@ -92,14 +95,14 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> { ...@@ -92,14 +95,14 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
private: private:
SceneBuilder(); SceneBuilder();
std::unique_ptr<flow::ContainerLayer> root_layer_; std::shared_ptr<flow::ContainerLayer> root_layer_;
flow::ContainerLayer* current_layer_ = nullptr; flow::ContainerLayer* current_layer_ = nullptr;
int rasterizer_tracing_threshold_ = 0; int rasterizer_tracing_threshold_ = 0;
bool checkerboard_raster_cache_images_ = false; bool checkerboard_raster_cache_images_ = false;
bool checkerboard_offscreen_layers_ = false; bool checkerboard_offscreen_layers_ = false;
void PushLayer(std::unique_ptr<flow::ContainerLayer> layer); void PushLayer(std::shared_ptr<flow::ContainerLayer> layer);
FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder); FML_DISALLOW_COPY_AND_ASSIGN(SceneBuilder);
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "flutter/lib/ui/isolate_name_server/isolate_name_server_natives.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/canvas.h"
#include "flutter/lib/ui/painting/codec.h" #include "flutter/lib/ui/painting/codec.h"
#include "flutter/lib/ui/painting/engine_layer.h"
#include "flutter/lib/ui/painting/frame_info.h" #include "flutter/lib/ui/painting/frame_info.h"
#include "flutter/lib/ui/painting/gradient.h" #include "flutter/lib/ui/painting/gradient.h"
#include "flutter/lib/ui/painting/image.h" #include "flutter/lib/ui/painting/image.h"
...@@ -70,6 +71,7 @@ void DartUI::InitForGlobal() { ...@@ -70,6 +71,7 @@ void DartUI::InitForGlobal() {
CanvasPathMeasure::RegisterNatives(g_natives); CanvasPathMeasure::RegisterNatives(g_natives);
Codec::RegisterNatives(g_natives); Codec::RegisterNatives(g_natives);
DartRuntimeHooks::RegisterNatives(g_natives); DartRuntimeHooks::RegisterNatives(g_natives);
EngineLayer::RegisterNatives(g_natives);
FrameInfo::RegisterNatives(g_natives); FrameInfo::RegisterNatives(g_natives);
ImageFilter::RegisterNatives(g_natives); ImageFilter::RegisterNatives(g_natives);
ImageShader::RegisterNatives(g_natives); ImageShader::RegisterNatives(g_natives);
......
...@@ -1761,6 +1761,14 @@ enum PathOperation { ...@@ -1761,6 +1761,14 @@ enum PathOperation {
reverseDifference, reverseDifference,
} }
/// A handle for the framework to hold and retain an engine layer across frames.
class EngineLayer extends NativeFieldWrapperClass2 {
/// This class is created by the engine, and should not be instantiated
/// or extended directly.
@pragma('vm:entry-point')
EngineLayer._();
}
/// A complex, one-dimensional subset of a plane. /// A complex, one-dimensional subset of a plane.
/// ///
/// A path consists of a number of subpaths, and a _current point_. /// A path consists of a number of subpaths, and a _current point_.
......
// Copyright 2018 The Chromium 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/ui/painting/engine_layer.h"
#include "flutter/flow/layers/container_layer.h"
#include "third_party/tonic/converter/dart_converter.h"
#include "third_party/tonic/dart_args.h"
#include "third_party/tonic/dart_binding_macros.h"
#include "third_party/tonic/dart_library_natives.h"
using tonic::ToDart;
namespace blink {
EngineLayer::~EngineLayer() = default;
IMPLEMENT_WRAPPERTYPEINFO(ui, EngineLayer);
#define FOR_EACH_BINDING(V) // nothing to bind
DART_BIND_ALL(EngineLayer, FOR_EACH_BINDING)
} // namespace blink
// Copyright 2018 The Chromium 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_PAINTING_ENGINE_LAYER_H_
#define FLUTTER_LIB_UI_PAINTING_ENGINE_LAYER_H_
#include "flutter/lib/ui/dart_wrapper.h"
#include "flutter/flow/layers/layer.h"
namespace tonic {
class DartLibraryNatives;
} // namespace tonic
namespace blink {
class EngineLayer;
class EngineLayer : public RefCountedDartWrappable<EngineLayer> {
DEFINE_WRAPPERTYPEINFO();
public:
~EngineLayer() override;
static fml::RefPtr<EngineLayer> MakeRetained(
std::shared_ptr<flow::ContainerLayer> layer) {
return fml::MakeRefCounted<EngineLayer>(layer);
}
static void RegisterNatives(tonic::DartLibraryNatives* natives);
std::shared_ptr<flow::ContainerLayer> Layer() const { return layer_; }
private:
explicit EngineLayer(std::shared_ptr<flow::ContainerLayer> layer)
: layer_(layer) {}
std::shared_ptr<flow::ContainerLayer> layer_;
FML_FRIEND_MAKE_REF_COUNTED(EngineLayer);
};
} // namespace blink
#endif // FLUTTER_LIB_UI_PAINTING_ENGINE_LAYER_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册