Flutter Impeller
surface_context_vk_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 <sys/types.h>
6 #include <memory>
7 #include <utility>
8 
9 #include "gtest/gtest.h"
11 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
13 
14 namespace impeller {
15 namespace testing {
16 
17 namespace {
18 vk::UniqueSurfaceKHR CreateSurface(const ContextVK& context) {
19 #if FML_OS_DARWIN
20  impeller::vk::MetalSurfaceCreateInfoEXT createInfo = {};
21  auto [result, surface] =
22  context.GetInstance().createMetalSurfaceEXTUnique(createInfo);
23  FML_DCHECK(result == vk::Result::eSuccess);
24  return std::move(surface);
25 #else
26  return {};
27 #endif // FML_OS_DARWIN
28 }
29 } // namespace
30 
31 TEST(SurfaceContextVK, TearsDownSwapchain) {
32  SetSwapchainImageSize({100, 100});
33  std::shared_ptr<ContextVK> context = MockVulkanContextBuilder().Build();
34 
35  vk::UniqueSurfaceKHR surface = CreateSurface(*context);
36  SurfaceContextVK surface_context(context);
37 
38  EXPECT_TRUE(surface_context.SetWindowSurface(std::move(surface), {100, 100}));
39  EXPECT_NE(surface_context.AcquireNextSurface(), nullptr);
40 
41  surface_context.TeardownSwapchain();
42 
43  EXPECT_EQ(surface_context.AcquireNextSurface(), nullptr);
44 }
45 
46 } // namespace testing
47 } // namespace impeller
bool SetWindowSurface(vk::UniqueSurfaceKHR surface, const ISize &size)
void TeardownSwapchain()
Can be called when the surface is destroyed to reduce memory usage.
std::unique_ptr< Surface > AcquireNextSurface()
TEST(AllocationSizeTest, CanCreateTypedAllocations)