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  ViewIdentifier(PlatformViewID view_id) : platform_view_id(view_id) {}
30 
31  struct Hash {
32  constexpr std::size_t operator()(const ViewIdentifier& desc) const {
33  if (!desc.platform_view_id.has_value()) {
34  return fml::HashCombine();
35  }
36 
37  return fml::HashCombine(desc.platform_view_id.value());
38  }
39  };
40 
41  struct Equal {
42  constexpr bool operator()(const ViewIdentifier& lhs,
43  const ViewIdentifier& rhs) const {
44  return lhs.platform_view_id == rhs.platform_view_id;
45  }
46  };
47  };
48 
51  SkISize surface_size;
52 
54  SkISize p_surface_size)
55  : view_identifier(p_view_identifier), surface_size(p_surface_size) {}
56 
57  struct Hash {
58  constexpr std::size_t operator()(
59  const RenderTargetDescriptor& desc) const {
60  return fml::HashCombine(desc.surface_size.width(),
61  desc.surface_size.height(),
63  }
64  };
65 
66  struct Equal {
68  const RenderTargetDescriptor& rhs) const {
69  return lhs.surface_size == rhs.surface_size &&
71  rhs.view_identifier);
72  }
73  };
74  };
75 
76  using ViewIdentifierSet = std::unordered_set<ViewIdentifier,
79 
80  using PendingViews = std::unordered_map<ViewIdentifier,
81  std::unique_ptr<EmbedderExternalView>,
82  ViewIdentifier::Hash,
84 
85  EmbedderExternalView(const SkISize& frame_size,
86  const SkMatrix& surface_transformation);
87 
88  EmbedderExternalView(const SkISize& frame_size,
89  const SkMatrix& surface_transformation,
90  ViewIdentifier view_identifier,
91  std::unique_ptr<EmbeddedViewParams> params);
92 
94 
95  bool IsRootView() const;
96 
97  bool HasPlatformView() const;
98 
99  bool HasEngineRenderedContents() const;
100 
101  ViewIdentifier GetViewIdentifier() const;
102 
104 
106 
107  SkCanvas* GetCanvas() const;
108 
109  SkISize GetRenderSurfaceSize() const;
110 
111  bool Render(const EmbedderRenderTarget& render_target);
112 
113  private:
114  const SkISize render_surface_size_;
115  const SkMatrix surface_transformation_;
116  ViewIdentifier view_identifier_;
117  std::unique_ptr<EmbeddedViewParams> embedded_view_params_;
118  std::unique_ptr<SkPictureRecorder> recorder_;
119  std::unique_ptr<CanvasSpy> canvas_spy_;
120 
122 };
123 
124 } // namespace flutter
125 
126 #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)