Flutter Engine
The Flutter Engine
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
11namespace 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
20std::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
69 return target_;
70}
71
73 return target_.IsValid();
74}
75
76} // namespace impeller
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
An object that allocates device memory.
Definition: allocator.h:22
std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Definition: allocator.cc:49
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...
const RenderTarget & GetRenderTarget() const
EntityPassTarget(const RenderTarget &render_target, bool supports_read_from_resolve, bool supports_implicit_msaa)
const std::map< size_t, ColorAttachment > & GetColorAttachments() const
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
#define VALIDATION_LOG
Definition: validation.h:73