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] avoid_backing_store_cache If set, create_render_target callback
44  /// will beinvoked every frame for every
45  /// engine composited layer. The result
46  /// will not cached.
47  ///
48  /// @param[in] create_render_target_callback
49  /// The render target callback used to
50  /// request the render target for a layer.
51  /// @param[in] present_callback The callback used to forward a
52  /// collection of layers (backed by
53  /// fulfilled render targets) to the
54  /// embedder for presentation.
55  ///
57  bool avoid_backing_store_cache,
58  const CreateRenderTargetCallback& create_render_target_callback,
59  const PresentCallback& present_callback);
60 
61  //----------------------------------------------------------------------------
62  /// @brief Collects the external view embedder.
63  ///
65 
66  //----------------------------------------------------------------------------
67  /// @brief Sets the surface transformation callback used by the external
68  /// view embedder to ask the platform for the per frame root
69  /// surface transformation.
70  ///
71  /// @param[in] surface_transformation_callback The surface transformation
72  /// callback
73  ///
75  SurfaceTransformationCallback surface_transformation_callback);
76 
77  private:
78  // |ExternalViewEmbedder|
79  void CancelFrame() override;
80 
81  // |ExternalViewEmbedder|
82  void BeginFrame(
83  SkISize frame_size,
84  GrDirectContext* context,
85  double device_pixel_ratio,
86  fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override;
87 
88  // |ExternalViewEmbedder|
89  void PrerollCompositeEmbeddedView(
90  int view_id,
91  std::unique_ptr<EmbeddedViewParams> params) override;
92 
93  // |ExternalViewEmbedder|
94  std::vector<SkCanvas*> GetCurrentCanvases() override;
95 
96  // |ExternalViewEmbedder|
97  SkCanvas* CompositeEmbeddedView(int view_id) override;
98 
99  // |ExternalViewEmbedder|
100  void SubmitFrame(GrDirectContext* context,
101  std::unique_ptr<SurfaceFrame> frame) override;
102 
103  // |ExternalViewEmbedder|
104  SkCanvas* GetRootCanvas() override;
105 
106  private:
107  const bool avoid_backing_store_cache_;
108  const CreateRenderTargetCallback create_render_target_callback_;
109  const PresentCallback present_callback_;
110  SurfaceTransformationCallback surface_transformation_callback_;
111  SkISize pending_frame_size_ = SkISize::Make(0, 0);
112  double pending_device_pixel_ratio_ = 1.0;
113  SkMatrix pending_surface_transformation_;
114  EmbedderExternalView::PendingViews pending_views_;
115  std::vector<EmbedderExternalView::ViewIdentifier> composition_order_;
116  EmbedderRenderTargetCache render_target_cache_;
117 
118  void Reset();
119 
120  SkMatrix GetSurfaceTransformation() const;
121 
122  FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalViewEmbedder);
123 };
124 
125 } // namespace flutter
126 
127 #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.
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.
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
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