|
| 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 | + |
| 21 | +class EmbedderExternalView { |
| 22 | + public: |
| 23 | + using PlatformViewID = int64_t; |
| 24 | + struct ViewIdentifier { |
| 25 | + std::optional<PlatformViewID> platform_view_id; |
| 26 | + |
| 27 | + ViewIdentifier() {} |
| 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 | + |
| 49 | + struct RenderTargetDescriptor { |
| 50 | + ViewIdentifier view_identifier; |
| 51 | + SkISize surface_size; |
| 52 | + |
| 53 | + RenderTargetDescriptor(ViewIdentifier p_view_identifier, |
| 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(), |
| 62 | + ViewIdentifier::Hash{}(desc.view_identifier)); |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | + struct Equal { |
| 67 | + bool operator()(const RenderTargetDescriptor& lhs, |
| 68 | + const RenderTargetDescriptor& rhs) const { |
| 69 | + return lhs.surface_size == rhs.surface_size && |
| 70 | + ViewIdentifier::Equal{}(lhs.view_identifier, |
| 71 | + rhs.view_identifier); |
| 72 | + } |
| 73 | + }; |
| 74 | + }; |
| 75 | + |
| 76 | + using ViewIdentifierSet = std::unordered_set<ViewIdentifier, |
| 77 | + ViewIdentifier::Hash, |
| 78 | + ViewIdentifier::Equal>; |
| 79 | + |
| 80 | + using PendingViews = std::unordered_map<ViewIdentifier, |
| 81 | + std::unique_ptr<EmbedderExternalView>, |
| 82 | + ViewIdentifier::Hash, |
| 83 | + ViewIdentifier::Equal>; |
| 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 | + |
| 93 | + ~EmbedderExternalView(); |
| 94 | + |
| 95 | + bool IsRootView() const; |
| 96 | + |
| 97 | + bool HasPlatformView() const; |
| 98 | + |
| 99 | + bool HasEngineRenderedContents() const; |
| 100 | + |
| 101 | + ViewIdentifier GetViewIdentifier() const; |
| 102 | + |
| 103 | + const EmbeddedViewParams* GetEmbeddedViewParams() const; |
| 104 | + |
| 105 | + RenderTargetDescriptor CreateRenderTargetDescriptor() const; |
| 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 | + |
| 121 | + FML_DISALLOW_COPY_AND_ASSIGN(EmbedderExternalView); |
| 122 | +}; |
| 123 | + |
| 124 | +} // namespace flutter |
| 125 | + |
| 126 | +#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_EXTERNAL_VIEW_H_ |
0 commit comments