Flutter Engine
 
Loading...
Searching...
No Matches
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
11
12namespace impeller {
13
14/// @brief An implementation of the [RenderTargetAllocator] that caches all
15/// allocated texture data for one frame.
16///
17/// Any textures unused after a frame are immediately discarded.
19 public:
20 explicit RenderTargetCache(std::shared_ptr<Allocator> allocator,
21 uint32_t keep_alive_frame_count = 4);
22
23 ~RenderTargetCache() = default;
24
25 // |RenderTargetAllocator|
26 void Start() override;
27
28 // |RenderTargetAllocator|
29 void End() override;
30
31 // |RenderTargetAllocator|
32 void DisableCache() override;
33
34 // |RenderTargetAllocator|
35 void EnableCache() override;
36
38 const Context& context,
39 ISize size,
40 int mip_count,
41 std::string_view label = "Offscreen",
42 RenderTarget::AttachmentConfig color_attachment_config =
44 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
46 const std::shared_ptr<Texture>& existing_color_texture = nullptr,
47 const std::shared_ptr<Texture>& existing_depth_stencil_texture =
48 nullptr) override;
49
51 const Context& context,
52 ISize size,
53 int mip_count,
54 std::string_view label = "Offscreen MSAA",
55 RenderTarget::AttachmentConfigMSAA color_attachment_config =
57 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config =
59 const std::shared_ptr<Texture>& existing_color_msaa_texture = nullptr,
60 const std::shared_ptr<Texture>& existing_color_resolve_texture = nullptr,
61 const std::shared_ptr<Texture>& existing_depth_stencil_texture =
62 nullptr) override;
63
64 // visible for testing.
65 size_t CachedTextureCount() const;
66
67 private:
68 struct RenderTargetData {
69 bool used_this_frame;
70 uint32_t keep_alive_frame_count;
71 RenderTargetConfig config;
72 RenderTarget render_target;
73 };
74
75 bool CacheEnabled() const;
76
77 std::vector<RenderTargetData> render_target_data_;
78 uint32_t keep_alive_frame_count_;
79 uint32_t cache_disabled_count_ = 0;
80
81 RenderTargetCache(const RenderTargetCache&) = delete;
82
83 RenderTargetCache& operator=(const RenderTargetCache&) = delete;
84
85 public:
86 /// Visible for testing.
87 std::vector<RenderTargetData>::const_iterator GetRenderTargetDataBegin()
88 const {
89 return render_target_data_.begin();
90 }
91
92 /// Visible for testing.
93 std::vector<RenderTargetData>::const_iterator GetRenderTargetDataEnd() const {
94 return render_target_data_.end();
95 }
96};
97
98} // namespace impeller
99
100#endif // FLUTTER_IMPELLER_ENTITY_RENDER_TARGET_CACHE_H_
To do anything rendering related with Impeller, you need a context.
Definition context.h:65
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
void DisableCache() override
Disable any caching until the next call to EnabledCache.
void EnableCache() override
Re-enable any caching if disabled.
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataBegin() 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
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataEnd() const
Visible for testing.
static constexpr AttachmentConfig kDefaultColorAttachmentConfig
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig