Flutter Impeller
entity_pass_target.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/entity_pass_target.h
"
6
7
#include "
impeller/base/validation.h
"
8
#include "
impeller/core/formats.h
"
9
#include "
impeller/core/texture.h
"
10
11
namespace
impeller
{
12
13
EntityPassTarget::EntityPassTarget
(
const
RenderTarget
& render_target,
14
bool
supports_read_from_resolve)
15
: target_(render_target),
16
supports_read_from_resolve_(supports_read_from_resolve) {}
17
18
std::shared_ptr<Texture>
EntityPassTarget::Flip
(
Allocator
& allocator) {
19
auto
color0 = target_.
GetColorAttachments
().find(0)->second;
20
if
(!color0.resolve_texture) {
21
VALIDATION_LOG
<<
"EntityPassTarget Flip should never be called for a "
22
"non-MSAA target."
;
23
// ...because there is never a circumstance where doing so would be
24
// necessary. Unlike MSAA passes, non-MSAA passes can be trivially loaded
25
// with `LoadAction::kLoad`.
26
return
color0.texture;
27
}
28
29
if
(supports_read_from_resolve_) {
30
// Just return the current resolve texture, which is safe to read in the
31
// next render pass that'll resolve to `target_`.
32
//
33
// Note that this can only be done when MSAA is being used.
34
return
color0.resolve_texture;
35
}
36
37
if
(!secondary_color_texture_) {
38
// The second texture is allocated lazily to avoid unused allocations.
39
TextureDescriptor
new_descriptor =
40
color0.resolve_texture->GetTextureDescriptor();
41
secondary_color_texture_ = allocator.
CreateTexture
(new_descriptor);
42
43
if
(!secondary_color_texture_) {
44
return
nullptr
;
45
}
46
}
47
48
std::swap(color0.resolve_texture, secondary_color_texture_);
49
50
target_.
SetColorAttachment
(color0, 0);
51
52
// Return the previous backdrop texture, which is safe to read in the next
53
// render pass that attaches `target_`.
54
return
secondary_color_texture_;
55
}
56
57
const
RenderTarget
&
EntityPassTarget::GetRenderTarget
()
const
{
58
return
target_;
59
}
60
61
bool
EntityPassTarget::IsValid
()
const
{
62
return
target_.
IsValid
();
63
}
64
65
}
// namespace impeller
impeller::EntityPassTarget::IsValid
bool IsValid() const
Definition:
entity_pass_target.cc:61
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition:
render_target.cc:180
formats.h
impeller::Allocator::CreateTexture
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition:
allocator.cc:49
impeller::RenderTarget::GetColorAttachments
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
Definition:
render_target.cc:209
validation.h
impeller::EntityPassTarget::EntityPassTarget
EntityPassTarget(const RenderTarget &render_target, bool supports_read_from_resolve)
Definition:
entity_pass_target.cc:13
impeller::Allocator
An object that allocates device memory.
Definition:
allocator.h:25
impeller::RenderTarget
Definition:
render_target.h:48
entity_pass_target.h
impeller::RenderTarget::IsValid
bool IsValid() const
Definition:
render_target.cc:34
VALIDATION_LOG
#define VALIDATION_LOG
Definition:
validation.h:60
texture.h
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
impeller
Definition:
aiks_context.cc:10
impeller::EntityPassTarget::GetRenderTarget
const RenderTarget & GetRenderTarget() const
Definition:
entity_pass_target.cc:57
impeller::EntityPassTarget::Flip
std::shared_ptr< Texture > Flip(Allocator &allocator)
Flips the backdrop and returns a readable texture that can be bound/sampled to restore the previous p...
Definition:
entity_pass_target.cc:18
impeller
entity
entity_pass_target.cc
Generated by
1.8.17