Flutter Engine
embedder_external_view.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_H_
6 #define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_
7 
8 #include <optional>
9 #include <unordered_map>
10 #include <unordered_set>
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/common/canvas_spy.h"
16 #include "flutter/shell/platform/embedder/embedder_render_target.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 
19 namespace flutter {
20 
22  public:
23  using PlatformViewID = int64_t;
24  struct ViewIdentifier {
25  std::optional<PlatformViewID> platform_view_id;
26 
28 
29  explicit ViewIdentifier(PlatformViewID view_id)
30  : platform_view_id(view_id) {}
31 
32  struct Hash {
33  constexpr std::size_t operator()(const ViewIdentifier& desc) const {
34  if (!desc.platform_view_id.has_value()) {
35  return fml::HashCombine();
36  }
37 
38  return fml::HashCombine(desc.platform_view_id.value());
39  }
40  };
41 
42  struct Equal {
43  constexpr bool operator()(const ViewIdentifier& lhs,
44  const ViewIdentifier& rhs) const {
45  return lhs.platform_view_id == rhs.platform_view_id;
46  }
47  };
48  };
49 
52  SkISize surface_size;
53 
55  SkISize p_surface_size)
56  : view_identifier(p_view_identifier), surface_size(p_surface_size) {}
57 
58  struct Hash {
59  constexpr std::size_t operator()(
60  const RenderTargetDescriptor& desc) const {
61  return fml::HashCombine(desc.surface_size.width(),
62  desc.surface_size.height(),
64  }
65  };
66 
67  struct Equal {
69  const RenderTargetDescriptor& rhs) const {
70  return lhs.surface_size == rhs.surface_size &&
72  rhs.view_identifier);
73  }
74  };
75  };
76 
77  using ViewIdentifierSet = std::unordered_set<ViewIdentifier,
80 
81  using PendingViews = std::unordered_map<ViewIdentifier,
82  std::unique_ptr<EmbedderExternalView>,
83  ViewIdentifier::Hash,
85 
86  EmbedderExternalView(const SkISize& frame_size,
87  const SkMatrix& surface_transformation);
88 
89  EmbedderExternalView(const SkISize& frame_size,
90  const SkMatrix& surface_transformation,
91  ViewIdentifier view_identifier,
92  std::unique_ptr<EmbeddedViewParams> params);
93 
95 
96  bool IsRootView() const;
97 
98  bool HasPlatformView() const;
99 
100  bool HasEngineRenderedContents() const;
101 
102  ViewIdentifier GetViewIdentifier() const;
103 
105 
107 
108  SkCanvas* GetCanvas() const;
109 
110  SkISize GetRenderSurfaceSize() const;
111 
112  bool Render(const EmbedderRenderTarget& render_target);
113 
114  private:
115  const SkISize render_surface_size_;
116  const SkMatrix surface_transformation_;
117  ViewIdentifier view_identifier_;
118  std::unique_ptr<EmbeddedViewParams> embedded_view_params_;
119  std::unique_ptr<SkPictureRecorder> recorder_;
120  std::unique_ptr<CanvasSpy> canvas_spy_;
121 
123 };
124 
125 } // namespace flutter
126 
127 #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_
constexpr std::size_t HashCombine()
Definition: hash_combine.h:25
ViewIdentifier GetViewIdentifier() const
constexpr bool operator()(const ViewIdentifier &lhs, const ViewIdentifier &rhs) const
bool operator()(const RenderTargetDescriptor &lhs, const RenderTargetDescriptor &rhs) const
const EmbeddedViewParams * GetEmbeddedViewParams() const
Describes a surface whose backing store is managed by the embedder. The type of surface depends on th...
constexpr std::size_t operator()(const RenderTargetDescriptor &desc) const
RenderTargetDescriptor CreateRenderTargetDescriptor() const
RenderTargetDescriptor(ViewIdentifier p_view_identifier, SkISize p_surface_size)
constexpr std::size_t operator()(const ViewIdentifier &desc) const
EmbedderExternalView(const SkISize &frame_size, const SkMatrix &surface_transformation)
std::optional< PlatformViewID > platform_view_id
std::unordered_set< ViewIdentifier, ViewIdentifier::Hash, ViewIdentifier::Equal > ViewIdentifierSet
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
std::unordered_map< ViewIdentifier, std::unique_ptr< EmbedderExternalView >, ViewIdentifier::Hash, ViewIdentifier::Equal > PendingViews
bool Render(const EmbedderRenderTarget &render_target)