Flutter Impeller
entity_pass_target_unittests.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 <memory>
6 
7 #include "flutter/testing/testing.h"
8 #include "gtest/gtest.h"
12 
13 namespace impeller {
14 namespace testing {
15 
18 
19 TEST_P(EntityPassTargetTest, SwapWithMSAATexture) {
20  if (GetContentContext()
21  ->GetDeviceCapabilities()
22  .SupportsImplicitResolvingMSAA()) {
23  GTEST_SKIP() << "Implicit MSAA is used on this device.";
24  }
25  auto content_context = GetContentContext();
26  auto buffer = content_context->GetContext()->CreateCommandBuffer();
27  auto render_target =
28  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
29  *content_context->GetContext(), {100, 100},
30  /*mip_count=*/1);
31 
32  auto entity_pass_target = EntityPassTarget(render_target, false, false);
33 
34  auto color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
35  auto msaa_tex = color0.texture;
36  auto resolve_tex = color0.resolve_texture;
37 
38  FML_DCHECK(content_context);
39  entity_pass_target.Flip(*content_context);
40 
41  color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
42 
43  ASSERT_EQ(msaa_tex, color0.texture);
44  ASSERT_NE(resolve_tex, color0.resolve_texture);
45 }
46 
47 TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {
48  auto content_context = GetContentContext();
49  auto buffer = content_context->GetContext()->CreateCommandBuffer();
50  auto context = content_context->GetContext();
51  auto& allocator = *context->GetResourceAllocator();
52 
53  // Emulate implicit MSAA resolve by making color resolve and msaa texture the
54  // same.
55  RenderTarget render_target;
56  {
57  PixelFormat pixel_format =
58  context->GetCapabilities()->GetDefaultColorFormat();
59 
60  // Create MSAA color texture.
61 
62  TextureDescriptor color0_tex_desc;
63  color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
64  color0_tex_desc.type = TextureType::kTexture2DMultisample;
65  color0_tex_desc.sample_count = SampleCount::kCount4;
66  color0_tex_desc.format = pixel_format;
67  color0_tex_desc.size = ISize{100, 100};
68  color0_tex_desc.usage = TextureUsage::kRenderTarget;
69 
70  auto color0_msaa_tex = allocator.CreateTexture(color0_tex_desc);
71 
72  // Color attachment.
73 
74  ColorAttachment color0;
77  color0.texture = color0_msaa_tex;
78  color0.resolve_texture = color0_msaa_tex;
79 
80  render_target.SetColorAttachment(color0, 0u);
81  render_target.SetStencilAttachment(std::nullopt);
82  }
83 
84  auto entity_pass_target = EntityPassTarget(render_target, false, true);
85 
86  auto color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
87  auto msaa_tex = color0.texture;
88  auto resolve_tex = color0.resolve_texture;
89 
90  ASSERT_EQ(msaa_tex, resolve_tex);
91 
92  FML_DCHECK(content_context);
93  entity_pass_target.Flip(*content_context);
94 
95  color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
96 
97  ASSERT_NE(msaa_tex, color0.texture);
98  ASSERT_NE(resolve_tex, color0.resolve_texture);
99  ASSERT_EQ(color0.texture, color0.resolve_texture);
100 }
101 
102 } // namespace testing
103 } // namespace impeller
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:658
LoadAction load_action
Definition: formats.h:659
std::shared_ptr< Texture > texture
Definition: formats.h:657
StoreAction store_action
Definition: formats.h:660
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...