1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/flow/layers/platform_view_layer.h"
6
7 namespace flutter {
8
PlatformViewLayer(const SkPoint & offset,const SkSize & size,int64_t view_id)9 PlatformViewLayer::PlatformViewLayer(const SkPoint& offset,
10 const SkSize& size,
11 int64_t view_id)
12 : offset_(offset), size_(size), view_id_(view_id) {}
13
14 PlatformViewLayer::~PlatformViewLayer() = default;
15
Preroll(PrerollContext * context,const SkMatrix & matrix)16 void PlatformViewLayer::Preroll(PrerollContext* context,
17 const SkMatrix& matrix) {
18 set_paint_bounds(SkRect::MakeXYWH(offset_.x(), offset_.y(), size_.width(),
19 size_.height()));
20
21 if (context->view_embedder == nullptr) {
22 FML_LOG(ERROR) << "Trying to embed a platform view but the PrerollContext "
23 "does not support embedding";
24 return;
25 }
26 std::unique_ptr<EmbeddedViewParams> params =
27 std::make_unique<EmbeddedViewParams>();
28 params->offsetPixels =
29 SkPoint::Make(matrix.getTranslateX(), matrix.getTranslateY());
30 params->sizePoints = size_;
31 params->mutatorsStack = context->mutators_stack;
32 context->view_embedder->PrerollCompositeEmbeddedView(view_id_,
33 std::move(params));
34 }
35
Paint(PaintContext & context) const36 void PlatformViewLayer::Paint(PaintContext& context) const {
37 if (context.view_embedder == nullptr) {
38 FML_LOG(ERROR) << "Trying to embed a platform view but the PaintContext "
39 "does not support embedding";
40 return;
41 }
42 SkCanvas* canvas = context.view_embedder->CompositeEmbeddedView(view_id_);
43 context.leaf_nodes_canvas = canvas;
44 }
45 } // namespace flutter
46