Flutter Engine
The Flutter Engine
embedder_external_view_embedder.h
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#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
6#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
7
8#include <map>
9#include <memory>
10#include <unordered_map>
11
12#include "flutter/flow/embedded_views.h"
13#include "flutter/fml/hash_combine.h"
14#include "flutter/fml/macros.h"
15#include "flutter/shell/platform/embedder/embedder_external_view.h"
16#include "flutter/shell/platform/embedder/embedder_render_target_cache.h"
17
18namespace flutter {
19
20//------------------------------------------------------------------------------
21/// @brief The external view embedder used by the generic embedder API.
22/// This class acts a proxy between the rasterizer and the embedder
23/// when the rasterizer is rendering into multiple layers. It asks
24/// the embedder for the render targets for the various layers the
25/// rasterizer is rendering into, recycles the render targets as
26/// necessary and converts rasterizer specific metadata into an
27/// embedder friendly format so that it can present the layers
28/// on-screen.
29///
31 public:
33 std::function<std::unique_ptr<EmbedderRenderTarget>(
34 GrDirectContext* context,
35 const std::shared_ptr<impeller::AiksContext>& aiks_context,
36 const FlutterBackingStoreConfig& config)>;
38 std::function<bool(FlutterViewId view_id,
39 const std::vector<const FlutterLayer*>& layers)>;
41
42 //----------------------------------------------------------------------------
43 /// @brief Creates an external view embedder used by the generic embedder
44 /// API.
45 ///
46 /// @param[in] avoid_backing_store_cache If set, create_render_target_callback
47 /// will beinvoked every frame for every
48 /// engine composited layer. The result
49 /// will not cached.
50 ///
51 /// @param[in] create_render_target_callback
52 /// The render target callback used to
53 /// request the render target for a layer.
54 /// @param[in] present_callback The callback used to forward a
55 /// collection of layers (backed by
56 /// fulfilled render targets) to the
57 /// embedder for presentation.
58 ///
60 bool avoid_backing_store_cache,
61 const CreateRenderTargetCallback& create_render_target_callback,
62 const PresentCallback& present_callback);
63
64 //----------------------------------------------------------------------------
65 /// @brief Collects the external view embedder.
66 ///
68
69 // |ExternalViewEmbedder|
70 void CollectView(int64_t view_id) override;
71
72 //----------------------------------------------------------------------------
73 /// @brief Sets the surface transformation callback used by the external
74 /// view embedder to ask the platform for the per frame root
75 /// surface transformation.
76 ///
77 /// @param[in] surface_transformation_callback The surface transformation
78 /// callback
79 ///
81 SurfaceTransformationCallback surface_transformation_callback);
82
83 private:
84 // |ExternalViewEmbedder|
85 void CancelFrame() override;
86
87 // |ExternalViewEmbedder|
88 void BeginFrame(GrDirectContext* context,
90 raster_thread_merger) override;
91
92 // |ExternalViewEmbedder|
93 void PrepareFlutterView(SkISize frame_size,
94 double device_pixel_ratio) override;
95
96 // |ExternalViewEmbedder|
97 void PrerollCompositeEmbeddedView(
98 int64_t view_id,
99 std::unique_ptr<EmbeddedViewParams> params) override;
100
101 // |ExternalViewEmbedder|
102 DlCanvas* CompositeEmbeddedView(int64_t view_id) override;
103
104 // |ExternalViewEmbedder|
105 void SubmitFlutterView(
106 int64_t flutter_view_id,
107 GrDirectContext* context,
108 const std::shared_ptr<impeller::AiksContext>& aiks_context,
109 std::unique_ptr<SurfaceFrame> frame) override;
110
111 // |ExternalViewEmbedder|
112 DlCanvas* GetRootCanvas() override;
113
114 private:
115 const bool avoid_backing_store_cache_;
116 const CreateRenderTargetCallback create_render_target_callback_;
117 const PresentCallback present_callback_;
118 SurfaceTransformationCallback surface_transformation_callback_;
119 SkISize pending_frame_size_ = SkISize::Make(0, 0);
120 double pending_device_pixel_ratio_ = 1.0;
121 SkMatrix pending_surface_transformation_;
123 std::vector<EmbedderExternalView::ViewIdentifier> composition_order_;
124 // The render target caches for views. Each key is a view ID.
125 std::unordered_map<int64_t, EmbedderRenderTargetCache> render_target_caches_;
126
127 void Reset();
128
129 SkMatrix GetSurfaceTransformation() const;
130
131 FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalViewEmbedder);
132};
133
134} // namespace flutter
135
136#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
Developer-facing API for rendering anything within the engine.
Definition: dl_canvas.h:38
The external view embedder used by the generic embedder API. This class acts a proxy between the rast...
EmbedderExternalViewEmbedder(bool avoid_backing_store_cache, const CreateRenderTargetCallback &create_render_target_callback, const PresentCallback &present_callback)
Creates an external view embedder used by the generic embedder API.
std::function< SkMatrix(void)> SurfaceTransformationCallback
~EmbedderExternalViewEmbedder() override
Collects the external view embedder.
std::function< bool(FlutterViewId view_id, const std::vector< const FlutterLayer * > &layers)> PresentCallback
std::function< std::unique_ptr< EmbedderRenderTarget >(GrDirectContext *context, const std::shared_ptr< impeller::AiksContext > &aiks_context, const FlutterBackingStoreConfig &config)> CreateRenderTargetCallback
void SetSurfaceTransformationCallback(SurfaceTransformationCallback surface_transformation_callback)
Sets the surface transformation callback used by the external view embedder to ask the platform for t...
std::unordered_map< ViewIdentifier, std::unique_ptr< EmbedderExternalView >, ViewIdentifier::Hash, ViewIdentifier::Equal > PendingViews
const EmbeddedViewParams * params
double frame
Definition: examples.cpp:31
Dart_NativeFunction function
Definition: fuchsia.cc:51
int64_t FlutterViewId
Definition: flutter_view.h:13
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20