Flutter Impeller
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
5
#include "
impeller/entity/render_target_cache.h
"
6
#include "
impeller/renderer/render_target.h
"
7
8
namespace
impeller
{
9
10
RenderTargetCache::RenderTargetCache
(std::shared_ptr<Allocator> allocator)
11
:
RenderTargetAllocator
(
std
::move(allocator)) {}
12
13
void
RenderTargetCache::Start
() {
14
for
(
auto
& td : texture_data_) {
15
td.used_this_frame =
false
;
16
}
17
}
18
19
void
RenderTargetCache::End
() {
20
std::vector<TextureData> retain;
21
22
for
(
const
auto
& td : texture_data_) {
23
if
(td.used_this_frame) {
24
retain.push_back(td);
25
}
26
}
27
texture_data_.swap(retain);
28
}
29
30
size_t
RenderTargetCache::CachedTextureCount
()
const
{
31
return
texture_data_.size();
32
}
33
34
std::shared_ptr<Texture>
RenderTargetCache::CreateTexture
(
35
const
TextureDescriptor
& desc) {
36
FML_DCHECK(desc.
storage_mode
!=
StorageMode::kHostVisible
);
37
FML_DCHECK(desc.
usage
&
38
static_cast<
TextureUsageMask
>
(
TextureUsage::kRenderTarget
));
39
40
for
(
auto
& td : texture_data_) {
41
const
auto
other_desc = td.texture->GetTextureDescriptor();
42
FML_DCHECK(td.texture !=
nullptr
);
43
if
(!td.used_this_frame && desc == other_desc) {
44
td.used_this_frame =
true
;
45
return
td.texture;
46
}
47
}
48
auto
result =
RenderTargetAllocator::CreateTexture
(desc);
49
if
(result ==
nullptr
) {
50
return
result;
51
}
52
texture_data_.push_back(
53
TextureData{.used_this_frame =
true
, .texture = result});
54
return
result;
55
}
56
57
}
// namespace impeller
impeller::TextureUsageMask
uint64_t TextureUsageMask
Definition:
formats.h:274
impeller::RenderTargetCache::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc) override
Create a new render target texture, or recycle a previously allocated render target texture.
Definition:
render_target_cache.cc:34
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition:
texture_descriptor.h:45
impeller::RenderTargetCache::End
void End() override
Mark the end of a frame workload.
Definition:
render_target_cache.cc:19
impeller::RenderTargetCache::RenderTargetCache
RenderTargetCache(std::shared_ptr< Allocator > allocator)
Definition:
render_target_cache.cc:10
impeller::RenderTargetAllocator::CreateTexture
virtual std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Create a new render target texture, or recycle a previously allocated render target texture.
Definition:
render_target.cc:25
impeller::RenderTargetAllocator
a wrapper around the impeller [Allocator] instance that can be used to provide caching of allocated r...
Definition:
render_target.h:22
std
Definition:
comparable.h:98
impeller::RenderTargetCache::Start
void Start() override
Mark the beginning of a frame workload.
Definition:
render_target_cache.cc:13
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition:
texture_descriptor.h:40
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition:
texture_descriptor.h:39
render_target.h
render_target_cache.h
impeller
Definition:
aiks_context.cc:10
impeller::RenderTargetCache::CachedTextureCount
size_t CachedTextureCount() const
Definition:
render_target_cache.cc:30
impeller
entity
render_target_cache.cc
Generated by
1.8.17