Flutter Impeller
render_target_cache.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_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
6 #define FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
7 
8 #include <string_view>
10 
11 namespace impeller {
12 
13 /// @brief An implementation of the [RenderTargetAllocator] that caches all
14 /// allocated texture data for one frame.
15 ///
16 /// Any textures unused after a frame are immediately discarded.
18  public:
19  explicit RenderTargetCache(std::shared_ptr<Allocator> allocator,
20  uint32_t keep_alive_frame_count = 4);
21 
22  ~RenderTargetCache() = default;
23 
24  // |RenderTargetAllocator|
25  void Start() override;
26 
27  // |RenderTargetAllocator|
28  void End() override;
29 
31  const Context& context,
32  ISize size,
33  int mip_count,
34  std::string_view label = "Offscreen",
35  RenderTarget::AttachmentConfig color_attachment_config =
37  std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
39  const std::shared_ptr<Texture>& existing_color_texture = nullptr,
40  const std::shared_ptr<Texture>& existing_depth_stencil_texture =
41  nullptr) override;
42 
44  const Context& context,
45  ISize size,
46  int mip_count,
47  std::string_view label = "Offscreen MSAA",
48  RenderTarget::AttachmentConfigMSAA color_attachment_config =
50  std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
52  const std::shared_ptr<Texture>& existing_color_msaa_texture = nullptr,
53  const std::shared_ptr<Texture>& existing_color_resolve_texture = nullptr,
54  const std::shared_ptr<Texture>& existing_depth_stencil_texture =
55  nullptr) override;
56 
57  // visible for testing.
58  size_t CachedTextureCount() const;
59 
60  private:
61  struct RenderTargetData {
62  bool used_this_frame;
63  uint32_t keep_alive_frame_count;
64  RenderTargetConfig config;
65  RenderTarget render_target;
66  };
67 
68  std::vector<RenderTargetData> render_target_data_;
69  uint32_t keep_alive_frame_count_;
70 
71  RenderTargetCache(const RenderTargetCache&) = delete;
72 
73  RenderTargetCache& operator=(const RenderTargetCache&) = delete;
74 
75  public:
76  /// Visible for testing.
77  std::vector<RenderTargetData>::const_iterator GetRenderTargetDataBegin()
78  const {
79  return render_target_data_.begin();
80  }
81 
82  /// Visible for testing.
83  std::vector<RenderTargetData>::const_iterator GetRenderTargetDataEnd() const {
84  return render_target_data_.end();
85  }
86 };
87 
88 } // namespace impeller
89 
90 #endif // FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
To do anything rendering related with Impeller, you need a context.
Definition: context.h:46
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame...
RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
RenderTargetCache(std::shared_ptr< Allocator > allocator, uint32_t keep_alive_frame_count=4)
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataBegin() const
Visible for testing.
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataEnd() const
Visible for testing.
void End() override
Mark the end of a frame workload.
void Start() override
Mark the beginning of a frame workload.
RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
Definition: render_target.h:55
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
Definition: render_target.h:61
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
Definition: render_target.h:68