Flutter Impeller
ahb_swapchain_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 "gtest/gtest.h"
6 
8 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
10 
12 
13 using impeller::testing::GetMockVulkanFunctions;
14 using impeller::testing::MockVulkanContextBuilder;
15 
16 const std::vector<std::string> kAndroidDeviceExtensions = {
17  "VK_KHR_swapchain",
18  "VK_ANDROID_external_memory_android_hardware_buffer",
19  "VK_KHR_sampler_ycbcr_conversion",
20  "VK_KHR_external_memory",
21  "VK_EXT_queue_family_foreign",
22  "VK_KHR_dedicated_allocation",
23 };
24 
26  public:
27  bool IsValid() const override { return true; }
28 
29  ASurfaceControl* GetHandle() const override { return nullptr; }
30 
31  bool RemoveFromParent() const override { return true; }
32 };
33 
34 TEST(AndroidAHBSwapchainTest,
35  AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure) {
36  bool wait_for_fences_called = false;
37  auto const context =
38  MockVulkanContextBuilder()
39  .SetDeviceExtensions(kAndroidDeviceExtensions)
40  .SetAcquireNextImageCallback(
41  [](VkDevice, VkSwapchainKHR, uint64_t, VkSemaphore, VkFence,
42  uint32_t*) -> VkResult { return VK_ERROR_SURFACE_LOST_KHR; })
43  .SetWaitForFencesCallback([&](VkDevice, uint32_t, const VkFence*,
44  VkBool32, uint64_t) -> VkResult {
45  wait_for_fences_called = true;
46  return VK_SUCCESS;
47  })
48  .Build();
49 
50  auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK(
51  context, std::make_shared<FakeSurfaceControl>(), {}, {100, 100}, false));
52 
53  auto image = ahb_swapchain->AcquireNextDrawable();
54  EXPECT_FALSE(image);
55 
56  ahb_swapchain->AcquireNextDrawable();
57  EXPECT_FALSE(wait_for_fences_called);
58 }
59 
60 TEST(AndroidAHBSwapchainTest, AHBSwapchainDtorCallsWaitIdle) {
61  const auto context = MockVulkanContextBuilder()
62  .SetDeviceExtensions(kAndroidDeviceExtensions)
63  .Build();
64 
65  auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK(
66  context, std::make_shared<FakeSurfaceControl>(), {}, {100, 100}, false));
67 
68  ahb_swapchain.reset();
69 
70  auto called_functions = GetMockVulkanFunctions(context->GetDevice());
71  EXPECT_NE(std::find(called_functions->begin(), called_functions->end(),
72  "vkDeviceWaitIdle"),
73  called_functions->end());
74 }
75 
76 } // namespace impeller::android::testing
The implementation of a swapchain that uses hardware buffers presented to a given surface control on ...
A wrapper for ASurfaceControl. https://developer.android.com/ndk/reference/group/native-activity#asur...
bool RemoveFromParent() const override
Remove the surface control from the hierarchy of nodes presented by the system compositor.
TEST(AndroidAHBSwapchainTest, AHBSwapchainNoFenceWaitAfterAcquireNextImageFailure)
const std::vector< std::string > kAndroidDeviceExtensions
std::shared_ptr< ContextGLES > context