From 916274db1d140506a6147d5a21d6dd16775533a3 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Wed, 5 Sep 2018 11:20:37 -0700 Subject: [PATCH 1/3] Add a no-op platform view layer. This will be used for embedding UIViews on iOS. Landing a no-op layer as a first incremental stop to keep PRs small. --- flow/BUILD.gn | 2 ++ flow/layers/embedded_view_layer.cc | 23 +++++++++++++++++ flow/layers/platform_view_layer.cc | 21 ++++++++++++++++ flow/layers/platform_view_layer.h | 39 +++++++++++++++++++++++++++++ lib/ui/compositing.dart | 9 +++++++ lib/ui/compositing/scene_builder.cc | 17 +++++++++++++ lib/ui/compositing/scene_builder.h | 6 +++++ 7 files changed, 117 insertions(+) create mode 100644 flow/layers/embedded_view_layer.cc create mode 100644 flow/layers/platform_view_layer.cc create mode 100644 flow/layers/platform_view_layer.h diff --git a/flow/BUILD.gn b/flow/BUILD.gn index dd4a292dd9d66..c476b4c5bdf48 100644 --- a/flow/BUILD.gn +++ b/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/flow/layers/embedded_view_layer.cc b/flow/layers/embedded_view_layer.cc new file mode 100644 index 0000000000000..825b1aa5efb5b --- /dev/null +++ b/flow/layers/embedded_view_layer.cc @@ -0,0 +1,23 @@ +// 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 { + FML_LOG(ERROR) << "Painting view " << view_id_; +} + +} // namespace flow diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc new file mode 100644 index 0000000000000..0a6a17244e0df --- /dev/null +++ b/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/flow/layers/platform_view_layer.h b/flow/layers/platform_view_layer.h new file mode 100644 index 0000000000000..13b7f5d0f1dae --- /dev/null +++ b/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/lib/ui/compositing.dart b/lib/ui/compositing.dart index 1e2af68025d6e..2957895ce0299 100644 --- a/lib/ui/compositing.dart +++ b/lib/ui/compositing.dart @@ -258,6 +258,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/lib/ui/compositing/scene_builder.cc b/lib/ui/compositing/scene_builder.cc index 439821cf1491e..48e1a3e54a80b 100644 --- a/lib/ui/compositing/scene_builder.cc +++ b/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, addPicture) \ V(SceneBuilder, addTexture) \ V(SceneBuilder, addChildScene) \ @@ -207,6 +209,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/lib/ui/compositing/scene_builder.h b/lib/ui/compositing/scene_builder.h index 8e3ed13a411a3..da627379828e6 100644 --- a/lib/ui/compositing/scene_builder.h +++ b/lib/ui/compositing/scene_builder.h @@ -73,6 +73,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, From 6704f55ecbc1b5d49adee9ba503b64f750d4b802 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Thu, 11 Oct 2018 13:34:03 -0700 Subject: [PATCH 2/3] update licenses file --- ci/licenses_golden/licenses_flutter | 5 ++++- flow/layers/embedded_view_layer.cc | 23 ----------------------- 2 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 flow/layers/embedded_view_layer.cc diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index d3cf0bf9c8179..34f49c4eeacab 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -556,8 +556,11 @@ 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/embedded_view_layer.cc + ../../../LICENSE TYPE: LicenseType.bsd +FILE: ../../../flutter/flow/layers/embedded_view_layer.cc +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/flow/layers/embedded_view_layer.cc b/flow/layers/embedded_view_layer.cc deleted file mode 100644 index 825b1aa5efb5b..0000000000000 --- a/flow/layers/embedded_view_layer.cc +++ /dev/null @@ -1,23 +0,0 @@ -// 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 { - FML_LOG(ERROR) << "Painting view " << view_id_; -} - -} // namespace flow From a9ccd9430da5bb52552e9400ffb77457575ad3aa Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 12 Oct 2018 19:28:46 -0700 Subject: [PATCH 3/3] fix licenses --- ci/licenses_golden/licenses_flutter | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 34f49c4eeacab..b3ee9f3d2ac7c 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -556,9 +556,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ==================================================================================================== LIBRARY: engine -ORIGIN: ../../../flutter/flow/layers/embedded_view_layer.cc + ../../../LICENSE +ORIGIN: ../../../flutter/flow/layers/platform_view_layer.cc + ../../../LICENSE TYPE: LicenseType.bsd -FILE: ../../../flutter/flow/layers/embedded_view_layer.cc 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