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