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