Flutter Engine
 
Loading...
Searching...
No Matches
ahb_texture_source_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
6#include <memory>
7
9#include "gtest/gtest.h"
15
17
18// Set up context.
19std::shared_ptr<Context> CreateContext() {
20 auto vulkan_dylib = fml::NativeLibrary::Create("libvulkan.so");
21 auto instance_proc_addr =
22 vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
23 "vkGetInstanceProcAddr");
24
25 if (!instance_proc_addr.has_value()) {
26 VALIDATION_LOG << "Could not setup Vulkan proc table.";
27 return nullptr;
28 }
29
31 settings.proc_address_callback = instance_proc_addr.value();
32 settings.shader_libraries_data = {};
33 settings.enable_validation = false;
34 settings.enable_gpu_tracing = false;
35 settings.enable_surface_control = false;
36
37 return ContextVK::Create(std::move(settings));
38}
39
40TEST(AndroidVulkanTest, CanImportRGBA) {
42 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
43 }
44
46 desc.size = ISize{1, 1};
49
50 auto ahb = std::make_unique<HardwareBuffer>(desc);
51 ASSERT_TRUE(ahb);
52 auto context_vk = CreateContext();
53 ASSERT_TRUE(context_vk);
54
55 AHBTextureSourceVK source(context_vk, std::move(ahb),
56 /*is_swapchain_image=*/false);
57
58 EXPECT_TRUE(source.IsValid());
59 EXPECT_EQ(source.GetYUVConversion(), nullptr);
60
61 context_vk->Shutdown();
62}
63
64TEST(AndroidVulkanTest, CanImportWithYUB) {
66 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
67 }
68
69 AHardwareBuffer_Desc desc;
70 desc.width = 16;
71 desc.height = 16;
72 desc.format = AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420;
73 desc.stride = 0;
74 desc.layers = 1;
75 desc.rfu0 = 0;
76 desc.rfu1 = 0;
77 desc.usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE |
78 AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK |
79 AHARDWAREBUFFER_USAGE_CPU_READ_MASK;
80
81 EXPECT_EQ(AHardwareBuffer_isSupported(&desc), 1);
82
83 AHardwareBuffer* buffer = nullptr;
84 ASSERT_EQ(AHardwareBuffer_allocate(&desc, &buffer), 0);
85
86 auto context_vk = CreateContext();
87 ASSERT_TRUE(context_vk);
88
89 AHBTextureSourceVK source(context_vk, buffer, desc);
90
91 EXPECT_TRUE(source.IsValid());
92 EXPECT_NE(source.GetYUVConversion(), nullptr);
93
94 context_vk->Shutdown();
95}
96
97} // namespace impeller::android::testing
static fml::RefPtr< NativeLibrary > Create(const char *path)
A texture source that wraps an instance of AHardwareBuffer.
std::shared_ptr< YUVConversionVK > GetYUVConversion() const override
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
static std::shared_ptr< ContextVK > Create(Settings settings)
TEST(AndroidVulkanTest, CanImportRGBA)
std::shared_ptr< Context > CreateContext()
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition context_vk.h:81
PFN_vkGetInstanceProcAddr proc_address_callback
Definition context_vk.h:80
A descriptor use to specify hardware buffer allocations.
#define VALIDATION_LOG
Definition validation.h:91