|
| 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 | + |
| 7 | +#include "impeller/renderer/backend/vulkan/swapchain/ahb/ahb_swapchain_vk.h" |
| 8 | +#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" |
| 9 | +#include "impeller/toolkit/android/surface_control.h" |
| 10 | + |
| 11 | +namespace impeller::android::testing { |
| 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 | + |
| 25 | +class FakeSurfaceControl : public SurfaceControl { |
| 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, AHBSwapchainDtorCallsWaitIdle) { |
| 35 | + const auto context = MockVulkanContextBuilder() |
| 36 | + .SetDeviceExtensions(kAndroidDeviceExtensions) |
| 37 | + .Build(); |
| 38 | + |
| 39 | + auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK( |
| 40 | + context, std::make_shared<FakeSurfaceControl>(), {}, {100, 100}, false)); |
| 41 | + |
| 42 | + ahb_swapchain.reset(); |
| 43 | + |
| 44 | + auto called_functions = GetMockVulkanFunctions(context->GetDevice()); |
| 45 | + EXPECT_NE(std::find(called_functions->begin(), called_functions->end(), |
| 46 | + "vkDeviceWaitIdle"), |
| 47 | + called_functions->end()); |
| 48 | +} |
| 49 | + |
| 50 | +} // namespace impeller::android::testing |
0 commit comments