Skip to content

Commit

Permalink
Add a no-op platform view layer. (flutter#6505)
Browse files Browse the repository at this point in the history
This will be used for embedding UIViews on iOS.

Landing a no-op layer as a first incremental step to keep PRs small.
  • Loading branch information
amirh authored Oct 13, 2018
1 parent 2bb3afa commit a1bbea7
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions flow/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions flow/layers/platform_view_layer.cc
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions flow/layers/platform_view_layer.h
Original file line number Diff line number Diff line change
@@ -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_
9 changes: 9 additions & 0 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
17 changes: 17 additions & 0 deletions lib/ui/compositing/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) \
Expand Down Expand Up @@ -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<flow::PlatformViewLayer>();
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,
Expand Down
6 changes: 6 additions & 0 deletions lib/ui/compositing/scene_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class SceneBuilder : public RefCountedDartWrappable<SceneBuilder> {
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,
Expand Down

0 comments on commit a1bbea7

Please sign in to comment.