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 <unordered_map>
10 
11 #include "flutter/flow/embedded_views.h"
12 #include "flutter/fml/hash_combine.h"
13 #include "flutter/fml/macros.h"
14 #include "flutter/shell/platform/embedder/embedder_external_view.h"
15 #include "flutter/shell/platform/embedder/embedder_render_target_cache.h"
16 
17 namespace flutter {
18 
19 //------------------------------------------------------------------------------
20 /// @brief The external view embedder used by the generic embedder API.
21 /// This class acts a proxy between the rasterizer and the embedder
22 /// when the rasterizer is rendering into multiple layers. It asks
23 /// the embedder for the render targets for the various layers the
24 /// rasterizer is rendering into, recycles the render targets as
25 /// necessary and converts rasterizer specific metadata into an
26 /// embedder friendly format so that it can present the layers
27 /// on-screen.
28 ///
30  public:
32  std::function<std::unique_ptr<EmbedderRenderTarget>(
33  GrDirectContext* context,
34  const FlutterBackingStoreConfig& config)>;
35  using PresentCallback =
36  std::function<bool(const std::vector<const FlutterLayer*>& layers)>;
37  using SurfaceTransformationCallback = std::function<SkMatrix(void)>;
38 
39  //----------------------------------------------------------------------------
40  /// @brief Creates an external view embedder used by the generic embedder
41  /// API.
42  ///
43  /// @param[in] create_render_target_callback
44  /// The render target callback used to
45  /// request the render target for a layer.
46  /// @param[in] present_callback The callback used to forward a
47  /// collection of layers (backed by
48  /// fulfilled render targets) to the
49  /// embedder for presentation.
50  ///
52  const CreateRenderTargetCallback& create_render_target_callback,
53  const PresentCallback& present_callback);
54 
55  //----------------------------------------------------------------------------
56  /// @brief Collects the external view embedder.
57  ///
59 
60  //----------------------------------------------------------------------------
61  /// @brief Sets the surface transformation callback used by the external
62  /// view embedder to ask the platform for the per frame root
63  /// surface transformation.
64  ///
65  /// @param[in] surface_transformation_callback The surface transformation
66  /// callback
67  ///
69  SurfaceTransformationCallback surface_transformation_callback);
70 
71  private:
72  // |ExternalViewEmbedder|
73  void CancelFrame() override;
74 
75  // |ExternalViewEmbedder|
76  void BeginFrame(
77  SkISize frame_size,
78  GrDirectContext* context,
79  double device_pixel_ratio,
80  fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override;
81 
82  // |ExternalViewEmbedder|
83  void PrerollCompositeEmbeddedView(
84  int view_id,
85  std::unique_ptr<EmbeddedViewParams> params) override;
86 
87  // |ExternalViewEmbedder|
88  std::vector<SkCanvas*> GetCurrentCanvases() override;
89 
90  // |ExternalViewEmbedder|
91  SkCanvas* CompositeEmbeddedView(int view_id) override;
92 
93  // |ExternalViewEmbedder|
94  void SubmitFrame(GrDirectContext* context,
95  std::unique_ptr<SurfaceFrame> frame) override;
96 
97  // |ExternalViewEmbedder|
98  SkCanvas* GetRootCanvas() override;
99 
100  private:
101  const CreateRenderTargetCallback create_render_target_callback_;
102  const PresentCallback present_callback_;
103  SurfaceTransformationCallback surface_transformation_callback_;
104  SkISize pending_frame_size_ = SkISize::Make(0, 0);
105  double pending_device_pixel_ratio_ = 1.0;
106  SkMatrix pending_surface_transformation_;
107  EmbedderExternalView::PendingViews pending_views_;
108  std::vector<EmbedderExternalView::ViewIdentifier> composition_order_;
109  EmbedderRenderTargetCache render_target_cache_;
110 
111  void Reset();
112 
113  SkMatrix GetSurfaceTransformation() const;
114 
115  FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalViewEmbedder);
116 };
117 
118 } // namespace flutter
119 
120 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_EMBEDDER_H_
std::function< SkMatrix(void)> SurfaceTransformationCallback
std::function< bool(const std::vector< const FlutterLayer * > &layers)> PresentCallback
~EmbedderExternalViewEmbedder() override
Collects the external view embedder.
A cache used to reference render targets that are owned by the embedder but needed by th engine to re...
void SetSurfaceTransformationCallback(SurfaceTransformationCallback surface_transformation_callback)
Sets the surface transformation callback used by the external view embedder to ask the platform for t...
std::function< std::unique_ptr< EmbedderRenderTarget >(GrDirectContext *context, const FlutterBackingStoreConfig &config)> CreateRenderTargetCallback
EmbedderExternalViewEmbedder(const CreateRenderTargetCallback &create_render_target_callback, const PresentCallback &present_callback)
Creates an external view embedder used by the generic embedder API.
The external view embedder used by the generic embedder API. This class acts a proxy between the rast...
std::unordered_map< ViewIdentifier, std::unique_ptr< EmbedderExternalView >, ViewIdentifier::Hash, ViewIdentifier::Equal > PendingViews