Flutter Impeller
swapchain_transients_mtl_unittests.mm
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 "flutter/testing/testing.h"
15 
16 #include <memory>
17 #include <thread>
18 
19 #include "gtest/gtest.h"
20 
21 namespace impeller {
22 namespace testing {
23 
26 
27 TEST_P(SwapchainTransientsMTLTest, CanAllocateSwapchainTextures) {
28  const auto& transients = std::make_shared<SwapchainTransientsMTL>(
29  GetContext()->GetResourceAllocator());
30 
31  transients->SetSizeAndFormat({1, 1}, PixelFormat::kB8G8R8A8UNormInt);
32 
33  auto resolve = transients->GetResolveTexture();
34  EXPECT_NE(resolve, nullptr);
35  EXPECT_NE(transients->GetMSAATexture(), nullptr);
36  EXPECT_NE(transients->GetDepthStencilTexture(), nullptr);
37 
38  // Texture properties are correct for resolve.
39  EXPECT_EQ(resolve->GetTextureDescriptor().size, ISize(1, 1));
40  EXPECT_EQ(resolve->GetTextureDescriptor().format,
42  EXPECT_EQ(resolve->GetTextureDescriptor().sample_count, SampleCount::kCount1);
43  EXPECT_EQ(resolve->GetTextureDescriptor().storage_mode,
45 
46  // Texture properties are correct for MSAA.
47  auto msaa = transients->GetMSAATexture();
48  EXPECT_EQ(msaa->GetTextureDescriptor().size, ISize(1, 1));
49  EXPECT_EQ(msaa->GetTextureDescriptor().format,
51  EXPECT_EQ(msaa->GetTextureDescriptor().sample_count, SampleCount::kCount4);
52  EXPECT_EQ(msaa->GetTextureDescriptor().storage_mode,
54 
55  // Texture properties are correct for Depth+Stencil.
56  auto depth_stencil = transients->GetDepthStencilTexture();
57  EXPECT_EQ(depth_stencil->GetTextureDescriptor().size, ISize(1, 1));
58  EXPECT_EQ(depth_stencil->GetTextureDescriptor().format,
60  EXPECT_EQ(depth_stencil->GetTextureDescriptor().sample_count,
62  EXPECT_EQ(depth_stencil->GetTextureDescriptor().storage_mode,
64 
65  // Textures are cached.
66  EXPECT_EQ(transients->GetResolveTexture(), resolve);
67 
68  // Texture cache is invalidated when size changes.
69  transients->SetSizeAndFormat({2, 2}, PixelFormat::kB8G8R8A8UNormInt);
70  EXPECT_NE(resolve, transients->GetResolveTexture());
71  resolve = transients->GetResolveTexture();
72 
73  // Texture cache is invalidated when pixel format changes.
74  transients->SetSizeAndFormat({2, 2}, PixelFormat::kB10G10R10A10XR);
75  EXPECT_NE(resolve, transients->GetResolveTexture());
76 }
77 
78 } // namespace testing
79 } // namespace impeller
TEST_P(AiksTest, DrawAtlasNoColor)
INSTANTIATE_METAL_PLAYGROUND_SUITE(AllocatorMTLTest)