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  ContentContext& 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  entity_pass_target.Flip(content_context);
39 
40  color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
41 
42  ASSERT_EQ(msaa_tex, color0.texture);
43  ASSERT_NE(resolve_tex, color0.resolve_texture);
44 }
45 
46 TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {
47  ContentContext& content_context = GetContentContext();
48  auto buffer = content_context.GetContext()->CreateCommandBuffer();
49  auto context = content_context.GetContext();
50  auto& allocator = *context->GetResourceAllocator();
51 
52  // Emulate implicit MSAA resolve by making color resolve and msaa texture the
53  // same.
54  RenderTarget render_target;
55  {
56  PixelFormat pixel_format =
57  context->GetCapabilities()->GetDefaultColorFormat();
58 
59  // Create MSAA color texture.
60 
61  TextureDescriptor color0_tex_desc;
62  color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
63  color0_tex_desc.type = TextureType::kTexture2DMultisample;
64  color0_tex_desc.sample_count = SampleCount::kCount4;
65  color0_tex_desc.format = pixel_format;
66  color0_tex_desc.size = ISize{100, 100};
67  color0_tex_desc.usage = TextureUsage::kRenderTarget;
68 
69  auto color0_msaa_tex = allocator.CreateTexture(color0_tex_desc);
70 
71  // Color attachment.
72 
73  ColorAttachment color0;
76  color0.texture = color0_msaa_tex;
77  color0.resolve_texture = color0_msaa_tex;
78 
79  render_target.SetColorAttachment(color0, 0u);
80  render_target.SetStencilAttachment(std::nullopt);
81  }
82 
83  auto entity_pass_target = EntityPassTarget(render_target, false, true);
84 
85  auto color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
86  auto msaa_tex = color0.texture;
87  auto resolve_tex = color0.resolve_texture;
88 
89  ASSERT_EQ(msaa_tex, resolve_tex);
90 
91  entity_pass_target.Flip(content_context);
92 
93  color0 = entity_pass_target.GetRenderTarget().GetColorAttachment(0);
94 
95  ASSERT_NE(msaa_tex, color0.texture);
96  ASSERT_NE(resolve_tex, color0.resolve_texture);
97  ASSERT_EQ(color0.texture, color0.resolve_texture);
98 }
99 
100 } // namespace testing
101 } // namespace impeller
std::shared_ptr< Context > GetContext() const
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< ContextGLES > context
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:910
LoadAction load_action
Definition: formats.h:911
std::shared_ptr< Texture > texture
Definition: formats.h:909
StoreAction store_action
Definition: formats.h:912
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...