Flutter Engine
The Flutter Engine
render_target_cache.cc
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
7
8namespace impeller {
9
10RenderTargetCache::RenderTargetCache(std::shared_ptr<Allocator> allocator)
11 : RenderTargetAllocator(std::move(allocator)) {}
12
14 for (auto& td : render_target_data_) {
15 td.used_this_frame = false;
16 }
17}
18
20 std::vector<RenderTargetData> retain;
21
22 for (const auto& td : render_target_data_) {
23 if (td.used_this_frame) {
24 retain.push_back(td);
25 }
26 }
27 render_target_data_.swap(retain);
28}
29
31 const Context& context,
32 ISize size,
33 int mip_count,
34 const std::string& label,
35 RenderTarget::AttachmentConfig color_attachment_config,
36 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
37 const std::shared_ptr<Texture>& existing_color_texture,
38 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
39 if (size.IsEmpty()) {
40 return {};
41 }
42
43 FML_DCHECK(existing_color_texture == nullptr &&
44 existing_depth_stencil_texture == nullptr);
45 auto config = RenderTargetConfig{
46 .size = size,
47 .mip_count = static_cast<size_t>(mip_count),
48 .has_msaa = false,
49 .has_depth_stencil = stencil_attachment_config.has_value(),
50 };
51 for (auto& render_target_data : render_target_data_) {
52 const auto other_config = render_target_data.config;
53 if (!render_target_data.used_this_frame && other_config == config) {
54 render_target_data.used_this_frame = true;
55 auto color0 = render_target_data.render_target.GetColorAttachments()
56 .find(0u)
57 ->second;
58 auto depth = render_target_data.render_target.GetDepthAttachment();
59 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
61 context, size, mip_count, label, color_attachment_config,
62 stencil_attachment_config, color0.texture, depth_tex);
63 }
64 }
66 context, size, mip_count, label, color_attachment_config,
67 stencil_attachment_config);
68 if (!created_target.IsValid()) {
69 return created_target;
70 }
71 render_target_data_.push_back(
72 RenderTargetData{.used_this_frame = true,
73 .config = config,
74 .render_target = created_target});
75 return created_target;
76}
77
79 const Context& context,
80 ISize size,
81 int mip_count,
82 const std::string& label,
83 RenderTarget::AttachmentConfigMSAA color_attachment_config,
84 std::optional<RenderTarget::AttachmentConfig> stencil_attachment_config,
85 const std::shared_ptr<Texture>& existing_color_msaa_texture,
86 const std::shared_ptr<Texture>& existing_color_resolve_texture,
87 const std::shared_ptr<Texture>& existing_depth_stencil_texture) {
88 if (size.IsEmpty()) {
89 return {};
90 }
91
92 FML_DCHECK(existing_color_msaa_texture == nullptr &&
93 existing_color_resolve_texture == nullptr &&
94 existing_depth_stencil_texture == nullptr);
95 auto config = RenderTargetConfig{
96 .size = size,
97 .mip_count = static_cast<size_t>(mip_count),
98 .has_msaa = true,
99 .has_depth_stencil = stencil_attachment_config.has_value(),
100 };
101 for (auto& render_target_data : render_target_data_) {
102 const auto other_config = render_target_data.config;
103 if (!render_target_data.used_this_frame && other_config == config) {
104 render_target_data.used_this_frame = true;
105 auto color0 = render_target_data.render_target.GetColorAttachments()
106 .find(0u)
107 ->second;
108 auto depth = render_target_data.render_target.GetDepthAttachment();
109 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
111 context, size, mip_count, label, color_attachment_config,
112 stencil_attachment_config, color0.texture, color0.resolve_texture,
113 depth_tex);
114 }
115 }
117 context, size, mip_count, label, color_attachment_config,
118 stencil_attachment_config);
119 if (!created_target.IsValid()) {
120 return created_target;
121 }
122 render_target_data_.push_back(
123 RenderTargetData{.used_this_frame = true,
124 .config = config,
125 .render_target = created_target});
126 return created_target;
127}
128
130 return render_target_data_.size();
131}
132
133} // namespace impeller
To do anything rendering related with Impeller, you need a context.
Definition: context.h:45
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
virtual 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)
virtual 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)
RenderTargetCache(std::shared_ptr< Allocator > allocator)
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
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
void End() override
Mark the end of a frame workload.
void Start() override
Mark the beginning of a frame workload.
#define FML_DCHECK(condition)
Definition: logging.h:103
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256