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 
6 
10 
11 namespace impeller {
12 
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(
21  const ContentContext& renderer) {
22  ColorAttachment color0 = target_.GetColorAttachment(0);
23  if (!color0.resolve_texture) {
24  VALIDATION_LOG << "EntityPassTarget Flip should never be called for a "
25  "non-MSAA target.";
26  // ...because there is never a circumstance where doing so would be
27  // necessary. Unlike MSAA passes, non-MSAA passes can be trivially loaded
28  // with `LoadAction::kLoad`.
29  return color0.texture;
30  }
31 
32  if (supports_read_from_resolve_) {
33  // Just return the current resolve texture, which is safe to read in the
34  // next render pass that'll resolve to `target_`.
35  //
36  // Note that this can only be done when MSAA is being used.
37  return color0.resolve_texture;
38  }
39 
40  if (!secondary_color_texture_) {
41  // The second texture is allocated lazily to avoid unused allocations.
42  TextureDescriptor new_descriptor =
43  color0.resolve_texture->GetTextureDescriptor();
44  RenderTarget target = renderer.GetRenderTargetCache()->CreateOffscreenMSAA(
45  *renderer.GetContext(), new_descriptor.size, 1);
46  secondary_color_texture_ = target.GetRenderTargetTexture();
47 
48  if (!secondary_color_texture_) {
49  return nullptr;
50  }
51  }
52 
53  // If the color0 resolve texture is the same as the texture, then we're
54  // running on the GLES backend with implicit resolve.
55  if (supports_implicit_msaa_) {
56  auto new_secondary = color0.resolve_texture;
57  color0.resolve_texture = secondary_color_texture_;
58  color0.texture = secondary_color_texture_;
59  secondary_color_texture_ = new_secondary;
60  } else {
61  std::swap(color0.resolve_texture, secondary_color_texture_);
62  }
63 
64  target_.SetColorAttachment(color0, 0);
65 
66  // Return the previous backdrop texture, which is safe to read in the next
67  // render pass that attaches `target_`.
68  return secondary_color_texture_;
69 }
70 
72  return target_;
73 }
74 
76  return target_.IsValid();
77 }
78 
80  secondary_color_texture_ = nullptr;
81 }
82 
83 } // namespace impeller
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
std::shared_ptr< Context > GetContext() const
void RemoveSecondary()
Remove the cached secondary color texture.
EntityPassTarget(const RenderTarget &render_target, bool supports_read_from_resolve, bool supports_implicit_msaa)
std::shared_ptr< Texture > Flip(const ContentContext &renderer)
Flips the backdrop and returns a readable texture that can be bound/sampled to restore the previous p...
ColorAttachment GetColorAttachment(size_t index) const
Get the color attachment at [index].
std::shared_ptr< Texture > GetRenderTargetTexture() const
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:658
std::shared_ptr< Texture > texture
Definition: formats.h:657
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define VALIDATION_LOG
Definition: validation.h:91