| 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>
9 #include "impeller/renderer/render_target.h"
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.
17 class RenderTargetCache : public RenderTargetAllocator {
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
30 RenderTarget CreateOffscreen(
31 const Context& context,
32 ISize size,
33 int mip_count,
34 std::string_view label = "Offscreen",
35 RenderTarget::AttachmentConfig color_attachment_config =
36 RenderTarget::kDefaultColorAttachmentConfig,
37 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
38 RenderTarget::kDefaultStencilAttachmentConfig,
39 const std::shared_ptr<Texture>& existing_color_texture = nullptr,
40 const std::shared_ptr<Texture>& existing_depth_stencil_texture =
41 nullptr) override;
42
43 RenderTarget CreateOffscreenMSAA(
44 const Context& context,
45 ISize size,
46 int mip_count,
47 std::string_view label = "Offscreen MSAA",
48 RenderTarget::AttachmentConfigMSAA color_attachment_config =
49 RenderTarget::kDefaultColorAttachmentConfigMSAA,
50 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
51 RenderTarget::kDefaultStencilAttachmentConfig,
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_
impeller::RenderTarget::kDefaultColorAttachmentConfig
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
Definition: render_target.h:55
impeller::RenderTargetCache::RenderTargetCache
RenderTargetCache(std::shared_ptr< Allocator > allocator, uint32_t keep_alive_frame_count=4)
Definition: render_target_cache.cc:11
impeller::RenderTarget::kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
Definition: render_target.h:61
impeller::RenderTargetCache::End
void End() override
Mark the end of a frame workload.
Definition: render_target_cache.cc:22
impeller::RenderTarget::AttachmentConfigMSAA
Definition: render_target.h:47
impeller::RenderTarget::AttachmentConfig
Definition: render_target.h:40
impeller::TSize
Definition: size.h:25
impeller::RenderTargetCache::GetRenderTargetDataEnd
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataEnd() const
Visible for testing.
Definition: render_target_cache.h:83
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:77
impeller::RenderTargetCache::CreateOffscreenMSAA
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
Definition: render_target_cache.cc:87
impeller::RenderTarget
Definition: render_target.h:38
impeller::RenderTargetCache::CreateOffscreen
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
Definition: render_target_cache.cc:36
impeller::RenderTargetAllocator
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
Definition: render_target.h:149
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:16
impeller::RenderTargetCache
An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame...
Definition: render_target_cache.h:17
impeller::RenderTargetConfig
Definition: render_target.h:21
render_target.h
impeller
Definition: allocation.cc:12
impeller::RenderTargetCache::CachedTextureCount
size_t CachedTextureCount() const
Definition: render_target_cache.cc:141