From 117dbfaeb105260908cbf823ad6f758fdc30f6e1 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 12 Oct 2018 19:40:21 -0700 Subject: [PATCH] Add a no-op platform view layer. (flutter/engine#6505) This will be used for embedding UIViews on iOS. Landing a no-op layer as a first incremental step to keep PRs small. --- .../ci/licenses_golden/licenses_flutter | 4 +- engine/src/flutter/flow/BUILD.gn | 2 + .../flow/layers/platform_view_layer.cc | 21 ++++++++++ .../flutter/flow/layers/platform_view_layer.h | 39 +++++++++++++++++++ engine/src/flutter/lib/ui/compositing.dart | 9 +++++ .../lib/ui/compositing/scene_builder.cc | 17 ++++++++ .../lib/ui/compositing/scene_builder.h | 6 +++ 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 engine/src/flutter/flow/layers/platform_view_layer.cc create mode 100644 engine/src/flutter/flow/layers/platform_view_layer.h diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index d46098891b..fa453415c1 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -556,8 +556,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== LIBRARY: engine -ORIGIN: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart + ../../../LICENSE +ORIGIN: ../../../flutter/flow/layers/platform_view_layer.cc + ../../../LICENSE TYPE: LicenseType.bsd +FILE: ../../../flutter/flow/layers/platform_view_layer.cc +FILE: ../../../flutter/flow/layers/platform_view_layer.h FILE: ../../../flutter/flutter_kernel_transformers/lib/track_widget_constructor_locations.dart FILE: ../../../flutter/fml/paths_unittests.cc FILE: ../../../flutter/lib/ui/isolate_name_server.dart diff --git a/engine/src/flutter/flow/BUILD.gn b/engine/src/flutter/flow/BUILD.gn index dd4a292dd9..c476b4c5bd 100644 --- a/engine/src/flutter/flow/BUILD.gn +++ b/engine/src/flutter/flow/BUILD.gn @@ -34,6 +34,8 @@ source_set("flow") { "layers/physical_shape_layer.h", "layers/picture_layer.cc", "layers/picture_layer.h", + "layers/platform_view_layer.cc", + "layers/platform_view_layer.h", "layers/shader_mask_layer.cc", "layers/shader_mask_layer.h", "layers/texture_layer.cc", diff --git a/engine/src/flutter/flow/layers/platform_view_layer.cc b/engine/src/flutter/flow/layers/platform_view_layer.cc new file mode 100644 index 0000000000..0a6a17244e --- /dev/null +++ b/engine/src/flutter/flow/layers/platform_view_layer.cc @@ -0,0 +1,21 @@ +// 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/flow/layers/platform_view_layer.h" + +namespace flow { + +PlatformViewLayer::PlatformViewLayer() = default; + +PlatformViewLayer::~PlatformViewLayer() = default; + +void PlatformViewLayer::Preroll(PrerollContext* context, + const SkMatrix& matrix) { + set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(), + size_.height())); +} + +void PlatformViewLayer::Paint(PaintContext& context) const {} + +} // namespace flow diff --git a/engine/src/flutter/flow/layers/platform_view_layer.h b/engine/src/flutter/flow/layers/platform_view_layer.h new file mode 100644 index 0000000000..13b7f5d0f1 --- /dev/null +++ b/engine/src/flutter/flow/layers/platform_view_layer.h @@ -0,0 +1,39 @@ +// 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_FLOW_LAYERS_PLATFORM_VIEW_LAYER_H_ +#define FLUTTER_FLOW_LAYERS_PLATFORM_VIEW_LAYER_H_ + +#include "flutter/flow/layers/layer.h" +#include "third_party/skia/include/core/SkSurface.h" +#include "third_party/skia/include/gpu/GrBackendSurface.h" +#include "third_party/skia/include/gpu/GrContext.h" +#include "third_party/skia/include/gpu/GrTexture.h" +#include "third_party/skia/include/gpu/GrTypes.h" + +namespace flow { + +class PlatformViewLayer : public Layer { + public: + PlatformViewLayer(); + ~PlatformViewLayer() override; + + void set_offset(const SkPoint& offset) { offset_ = offset; } + void set_size(const SkSize& size) { size_ = size; } + void set_view_id(int64_t view_id) { view_id_ = view_id; } + + void Preroll(PrerollContext* context, const SkMatrix& matrix) override; + void Paint(PaintContext& context) const override; + + private: + SkPoint offset_; + SkSize size_; + int64_t view_id_; + + FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewLayer); +}; + +} // namespace flow + +#endif // FLUTTER_FLOW_LAYERS_PLATFORM_VIEW_LAYER_H_ diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index f2e5fb049c..8c3d9261d6 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -268,6 +268,15 @@ class SceneBuilder extends NativeFieldWrapperClass2 { } void _addTexture(double dx, double dy, double width, double height, int textureId, bool freeze) native 'SceneBuilder_addTexture'; + /// Adds a platform view (e.g an iOS UIView) to the scene. + /// + /// This is work in progress and is not currently supported on any platform. + void addPlatformView(int viewId, { Offset offset: Offset.zero, double width: 0.0, double height: 0.0}) { + assert(offset != null, 'Offset argument was null'); + _addPlatformView(offset.dx, offset.dy, width, height, viewId); + } + void _addPlatformView(double dx, double dy, double width, double height, int viewId) native 'SceneBuilder_addPlatformView'; + /// (Fuchsia-only) Adds a scene rendered by another application to the scene /// for this application. void addChildScene({ diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.cc b/engine/src/flutter/lib/ui/compositing/scene_builder.cc index 98888d77ad..76137c4649 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.cc +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.cc @@ -19,6 +19,7 @@ #include "flutter/flow/layers/performance_overlay_layer.h" #include "flutter/flow/layers/physical_shape_layer.h" #include "flutter/flow/layers/picture_layer.h" +#include "flutter/flow/layers/platform_view_layer.h" #include "flutter/flow/layers/shader_mask_layer.h" #include "flutter/flow/layers/texture_layer.h" #include "flutter/flow/layers/transform_layer.h" @@ -53,6 +54,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, SceneBuilder); V(SceneBuilder, pushShaderMask) \ V(SceneBuilder, pushPhysicalShape) \ V(SceneBuilder, pop) \ + V(SceneBuilder, addPlatformView) \ V(SceneBuilder, addRetained) \ V(SceneBuilder, addPicture) \ V(SceneBuilder, addTexture) \ @@ -217,6 +219,21 @@ void SceneBuilder::addTexture(double dx, current_layer_->Add(std::move(layer)); } +void SceneBuilder::addPlatformView(double dx, + double dy, + double width, + double height, + int64_t viewId) { + if (!current_layer_) { + return; + } + auto layer = std::make_unique(); + layer->set_offset(SkPoint::Make(dx, dy)); + layer->set_size(SkSize::Make(width, height)); + layer->set_view_id(viewId); + current_layer_->Add(std::move(layer)); +} + void SceneBuilder::addChildScene(double dx, double dy, double width, diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.h b/engine/src/flutter/lib/ui/compositing/scene_builder.h index e8638e6aee..8674d004ab 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.h +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.h @@ -76,6 +76,12 @@ class SceneBuilder : public RefCountedDartWrappable { int64_t textureId, bool freeze); + void addPlatformView(double dx, + double dy, + double width, + double height, + int64_t viewId); + void addChildScene(double dx, double dy, double width,