| 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 bool supports_implicit_msaa)
16 : target_(render_target),
17 supports_read_from_resolve_(supports_read_from_resolve),
18 supports_implicit_msaa_(supports_implicit_msaa) {}
19
20 std::shared_ptr<Texture> EntityPassTarget::Flip(Allocator& allocator) {
21 auto color0 = target_.GetColorAttachments().find(0)->second;
22 if (!color0.resolve_texture) {
23 VALIDATION_LOG << "EntityPassTarget Flip should never be called for a "
24 "non-MSAA target.";
25 // ...because there is never a circumstance where doing so would be
26 // necessary. Unlike MSAA passes, non-MSAA passes can be trivially loaded
27 // with `LoadAction::kLoad`.
28 return color0.texture;
29 }
30
31 if (supports_read_from_resolve_) {
32 // Just return the current resolve texture, which is safe to read in the
33 // next render pass that'll resolve to `target_`.
34 //
35 // Note that this can only be done when MSAA is being used.
36 return color0.resolve_texture;
37 }
38
39 if (!secondary_color_texture_) {
40 // The second texture is allocated lazily to avoid unused allocations.
41 TextureDescriptor new_descriptor =
42 color0.resolve_texture->GetTextureDescriptor();
43 secondary_color_texture_ = allocator.CreateTexture(new_descriptor);
44
45 if (!secondary_color_texture_) {
46 return nullptr;
47 }
48 }
49
50 // If the color0 resolve texture is the same as the texture, then we're
51 // running on the GLES backend with implicit resolve.
52 if (supports_implicit_msaa_) {
53 auto new_secondary = color0.resolve_texture;
54 color0.resolve_texture = secondary_color_texture_;
55 color0.texture = secondary_color_texture_;
56 secondary_color_texture_ = new_secondary;
57 } else {
58 std::swap(color0.resolve_texture, secondary_color_texture_);
59 }
60
61 target_.SetColorAttachment(color0, 0);
62
63 // Return the previous backdrop texture, which is safe to read in the next
64 // render pass that attaches `target_`.
65 return secondary_color_texture_;
66 }
67
68 const RenderTarget& EntityPassTarget::GetRenderTarget() const {
69 return target_;
70 }
71
72 bool EntityPassTarget::IsValid() const {
73 return target_.IsValid();
74 }
75
76 } // namespace impeller
impeller::EntityPassTarget::EntityPassTarget
EntityPassTarget(const RenderTarget &render_target, bool supports_read_from_resolve, bool supports_implicit_msaa)
Definition: entity_pass_target.cc:13
impeller::EntityPassTarget::IsValid
bool IsValid() const
Definition: entity_pass_target.cc:72
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::Allocator
An object that allocates device memory.
Definition: allocator.h:22
impeller::RenderTarget
Definition: render_target.h:49
entity_pass_target.h
impeller::RenderTarget::IsValid
bool IsValid() const
Definition: render_target.cc:34
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
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:37
impeller
Definition: aiks_context.cc:10
impeller::EntityPassTarget::GetRenderTarget
const RenderTarget & GetRenderTarget() const
Definition: entity_pass_target.cc:68
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:20