| 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(
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
71 RenderTarget& EntityPassTarget::GetRenderTarget() {
72 return target_;
73 }
74
75 bool EntityPassTarget::IsValid() const {
76 return target_.IsValid();
77 }
78
79 void EntityPassTarget::RemoveSecondary() {
80 secondary_color_texture_ = nullptr;
81 }
82
83 } // namespace impeller
impeller::ContentContext
Definition: content_context.h:138
impeller::ContentContext::GetRenderTargetCache
const std::shared_ptr< RenderTargetAllocator > & GetRenderTargetCache() const
Definition: content_context.h:269
impeller::ContentContext::GetContext
std::shared_ptr< Context > GetContext() const
Definition: content_context.cc:950
impeller::EntityPassTarget::IsValid
bool IsValid() const
Definition: entity_pass_target.cc:75
impeller::EntityPassTarget::GetRenderTarget
RenderTarget & GetRenderTarget()
Definition: entity_pass_target.cc:71
impeller::EntityPassTarget::RemoveSecondary
void RemoveSecondary()
Remove the cached secondary color texture.
Definition: entity_pass_target.cc:79
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::Flip
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...
Definition: entity_pass_target.cc:20
impeller::RenderTarget
Definition: render_target.h:38
impeller::RenderTarget::GetColorAttachment
ColorAttachment GetColorAttachment(size_t index) const
Get the color attachment at [index].
Definition: render_target.cc:233
impeller::RenderTarget::GetRenderTargetTexture
std::shared_ptr< Texture > GetRenderTargetTexture() const
Definition: render_target.cc:176
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:199
impeller::RenderTarget::IsValid
bool IsValid() const
Definition: render_target.cc:23
formats.h
texture.h
entity_pass_target.h
impeller
Definition: allocation.cc:12
impeller::Attachment::resolve_texture
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:658
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:657
impeller::ColorAttachment
Definition: formats.h:665
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91