Flutter Impeller
impeller::EntityPassTarget Class Reference

#include <entity_pass_target.h>

Public Member Functions

 EntityPassTarget (const RenderTarget &render_target, bool supports_read_from_resolve, bool supports_implicit_msaa)
 
std::shared_ptr< TextureFlip (Allocator &allocator)
 Flips the backdrop and returns a readable texture that can be bound/sampled to restore the previous pass. More...
 
const RenderTargetGetRenderTarget () const
 
bool IsValid () const
 

Detailed Description

Definition at line 15 of file entity_pass_target.h.

Constructor & Destructor Documentation

◆ EntityPassTarget()

impeller::EntityPassTarget::EntityPassTarget ( const RenderTarget render_target,
bool  supports_read_from_resolve,
bool  supports_implicit_msaa 
)
explicit

Definition at line 13 of file entity_pass_target.cc.

16  : target_(render_target),
17  supports_read_from_resolve_(supports_read_from_resolve),
18  supports_implicit_msaa_(supports_implicit_msaa) {}

Member Function Documentation

◆ Flip()

std::shared_ptr< Texture > impeller::EntityPassTarget::Flip ( Allocator allocator)

Flips the backdrop and returns a readable texture that can be bound/sampled to restore the previous pass.

After this method is called, a new RenderPass that attaches the result of GetRenderTarget is guaranteed to be able to read the previous pass's backdrop texture (which is returned by this method).

Definition at line 20 of file entity_pass_target.cc.

20  {
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 }

References impeller::Allocator::CreateTexture(), impeller::RenderTarget::GetColorAttachments(), impeller::RenderTarget::SetColorAttachment(), and VALIDATION_LOG.

Referenced by impeller::InlinePassContext::GetRenderPass().

◆ GetRenderTarget()

const RenderTarget & impeller::EntityPassTarget::GetRenderTarget ( ) const

◆ IsValid()

bool impeller::EntityPassTarget::IsValid ( ) const

Definition at line 72 of file entity_pass_target.cc.

72  {
73  return target_.IsValid();
74 }

References impeller::RenderTarget::IsValid().

Referenced by impeller::InlinePassContext::IsValid().


The documentation for this class was generated from the following files:
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:169
impeller::RenderTarget::GetColorAttachments
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
Definition: render_target.cc:198
impeller::RenderTarget::IsValid
bool IsValid() const
Definition: render_target.cc:23
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73