Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_external_view.cc
Go to the documentation of this file.
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/shell/platform/embedder/embedder_external_view.h"
6
7#include "flutter/display_list/dl_builder.h"
8#include "flutter/fml/trace_event.h"
9#include "flutter/shell/common/dl_op_spy.h"
10
11#ifdef IMPELLER_SUPPORTS_RENDERING
12#include "impeller/display_list/dl_dispatcher.h" // nogncheck
13#define ENABLE_EXPERIMENTAL_CANVAS false
14#endif // IMPELLER_SUPPORTS_RENDERING
15
16namespace flutter {
17
19 const SkMatrix& transformation) {
20 const auto source_rect = SkRect::MakeWH(size.width(), size.height());
21 const auto transformed_rect = transformation.mapRect(source_rect);
22 return SkISize::Make(transformed_rect.width(), transformed_rect.height());
23}
24
26 const SkISize& frame_size,
27 const SkMatrix& surface_transformation)
28 : EmbedderExternalView(frame_size, surface_transformation, {}, nullptr) {}
29
31 const SkISize& frame_size,
32 const SkMatrix& surface_transformation,
34 std::unique_ptr<EmbeddedViewParams> params)
35 : render_surface_size_(
36 TransformedSurfaceSize(frame_size, surface_transformation)),
37 surface_transformation_(surface_transformation),
38 view_identifier_(view_identifier),
39 embedded_view_params_(std::move(params)),
40 slice_(std::make_unique<DisplayListEmbedderViewSlice>(
41 SkRect::Make(frame_size))) {}
42
44
49
51 return slice_->canvas();
52}
53
55 return render_surface_size_;
56}
57
59 return !HasPlatformView();
60}
61
63 return view_identifier_.platform_view_id.has_value();
64}
65
67 return slice_->getRegion();
68}
69
71 if (has_engine_rendered_contents_.has_value()) {
72 return has_engine_rendered_contents_.value();
73 }
74 TryEndRecording();
75 DlOpSpy dl_op_spy;
76 slice_->dispatch(dl_op_spy);
77 has_engine_rendered_contents_ = dl_op_spy.did_draw() && !slice_->is_empty();
78 // NOLINTNEXTLINE(bugprone-unchecked-optional-access)
79 return has_engine_rendered_contents_.value();
80}
81
86
88 return embedded_view_params_.get();
89}
90
92 bool clear_surface) {
93 TRACE_EVENT0("flutter", "EmbedderExternalView::Render");
94 TryEndRecording();
96 << "Unnecessarily asked to render into a render target when there was "
97 "nothing to render.";
98
99#ifdef IMPELLER_SUPPORTS_RENDERING
100 auto* impeller_target = render_target.GetImpellerRenderTarget();
101 if (impeller_target) {
102 auto aiks_context = render_target.GetAiksContext();
103
104 auto dl_builder = DisplayListBuilder();
105 dl_builder.SetTransform(&surface_transformation_);
106 slice_->render_into(&dl_builder);
107 auto display_list = dl_builder.Build();
108
109#if ENABLE_EXPERIMENTAL_CANVAS
110 auto cull_rect =
111 impeller::IRect::MakeSize(impeller_target->GetRenderTargetSize());
112 SkIRect sk_cull_rect =
113 SkIRect::MakeWH(cull_rect.GetWidth(), cull_rect.GetHeight());
114
115 impeller::TextFrameDispatcher collector(aiks_context->GetContentContext(),
117 display_list->Dispatch(collector, sk_cull_rect);
118
119 impeller::ExperimentalDlDispatcher impeller_dispatcher(
120 aiks_context->GetContentContext(), *impeller_target, cull_rect);
121 display_list->Dispatch(impeller_dispatcher, sk_cull_rect);
122 impeller_dispatcher.FinishRecording();
123 aiks_context->GetContentContext().GetTransientsBuffer().Reset();
124 aiks_context->GetContentContext().GetLazyGlyphAtlas()->ResetTextFrames();
125
126 return true;
127#else
128 auto dispatcher = impeller::DlDispatcher();
129 dispatcher.drawDisplayList(display_list, 1);
130 return aiks_context->Render(dispatcher.EndRecordingAsPicture(),
131 *impeller_target, /*reset_host_buffer=*/true);
132#endif
133 }
134#endif // IMPELLER_SUPPORTS_RENDERING
135
136 auto skia_surface = render_target.GetSkiaSurface();
137 if (!skia_surface) {
138 return false;
139 }
140
141 FML_DCHECK(render_target.GetRenderTargetSize() == render_surface_size_);
142
143 auto canvas = skia_surface->getCanvas();
144 if (!canvas) {
145 return false;
146 }
147 DlSkCanvasAdapter dl_canvas(canvas);
148 int restore_count = dl_canvas.GetSaveCount();
149 dl_canvas.SetTransform(surface_transformation_);
150 if (clear_surface) {
151 dl_canvas.Clear(DlColor::kTransparent());
152 }
153 slice_->render_into(&dl_canvas);
154 dl_canvas.RestoreToCount(restore_count);
155 dl_canvas.Flush();
156
157 return true;
158}
159
160void EmbedderExternalView::TryEndRecording() const {
161 if (slice_->recording_ended()) {
162 return;
163 }
164 slice_->end_recording();
165}
166
167} // namespace flutter
static std::unique_ptr< SkEncoder > Make(SkWStream *dst, const SkPixmap *src, const SkYUVAPixmaps *srcYUVA, const SkColorSpace *srcYUVAColorSpace, const SkJpegEncoder::Options &options)
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Developer-facing API for rendering anything within the engine.
Definition dl_canvas.h:37
void Clear(DlColor color)
Definition dl_canvas.h:131
bool did_draw()
Returns true if any non transparent content has been drawn.
Definition dl_op_spy.cc:9
Backend implementation of |DlCanvas| for |SkCanvas|.
int GetSaveCount() const override
void SetTransform(const SkMatrix *matrix) override
void RestoreToCount(int restore_count) override
const EmbeddedViewParams * GetEmbeddedViewParams() const
RenderTargetDescriptor CreateRenderTargetDescriptor() const
bool Render(const EmbedderRenderTarget &render_target, bool clear_surface=true)
const DlRegion & GetDlRegion() const
ViewIdentifier GetViewIdentifier() const
EmbedderExternalView(const SkISize &frame_size, const SkMatrix &surface_transformation)
Describes a surface whose backing store is managed by the embedder. The type of surface depends on th...
virtual impeller::RenderTarget * GetImpellerRenderTarget() const =0
An impeller render target the rasterizer can use to draw into the backing store.
virtual sk_sp< SkSurface > GetSkiaSurface() const =0
A render surface the rasterizer can use to draw into the backing store of this render target.
virtual std::shared_ptr< impeller::AiksContext > GetAiksContext() const =0
Returns the AiksContext that should be used for rendering, if this render target is backed by Impelle...
virtual SkISize GetRenderTargetSize() const =0
Returns the size of the render target.
Performs a first pass over the display list to collect all text frames.
EmbedderExternalView::ViewIdentifier view_identifier
const EmbeddedViewParams * params
#define FML_DCHECK(condition)
Definition logging.h:103
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259
static SkISize TransformedSurfaceSize(const SkISize &size, const SkMatrix &transformation)
Definition ref_ptr.h:256
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition SkRect.h:56
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609
static constexpr DlColor kTransparent()
Definition dl_color.h:21
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146
#define TRACE_EVENT0(category_group, name)