| Flutter Impeller |

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
5 #include <android/hardware_buffer.h>
6 #include <memory>
7
8 #include "flutter/testing/testing.h"
9 #include "gtest/gtest.h"
10 #include "impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h"
11 #include "impeller/renderer/backend/vulkan/context_vk.h"
12 #include "impeller/renderer/backend/vulkan/surface_context_vk.h"
13 #include "impeller/toolkit/android/hardware_buffer.h"
14 #include "impeller/toolkit/android/surface_transaction.h"
15
16 namespace impeller::android::testing {
17
18 // Set up context.
19 std::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
30 impeller::ContextVK::Settings settings;
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
40 TEST(AndroidVulkanTest, CanImportRGBA) {
41 if (!HardwareBuffer::IsAvailableOnPlatform()) {
42 GTEST_SKIP() << "Hardware buffers are not supported on this platform.";
43 }
44
45 HardwareBufferDescriptor desc;
46 desc.size = ISize{1, 1};
47 desc.format = HardwareBufferFormat::kR8G8B8A8UNormInt;
48 desc.usage = HardwareBufferUsageFlags::kSampledImage;
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
64 TEST(AndroidVulkanTest, CanImportWithYUB) {
65 if (!HardwareBuffer::IsAvailableOnPlatform()) {
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
ahb_texture_source_vk.h
impeller::AHBTextureSourceVK
A texture source that wraps an instance of AHardwareBuffer.
Definition: ahb_texture_source_vk.h:32
impeller::AHBTextureSourceVK::IsValid
bool IsValid() const
Definition: ahb_texture_source_vk.cc:410
impeller::AHBTextureSourceVK::GetYUVConversion
std::shared_ptr< YUVConversionVK > GetYUVConversion() const override
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
Definition: ahb_texture_source_vk.cc:435
impeller::ContextVK::Create
static std::shared_ptr< ContextVK > Create(Settings settings)
Definition: context_vk.cc:105
impeller::android::HardwareBuffer::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: hardware_buffer.cc:107
hardware_buffer.h
impeller::android::testing
Definition: ahb_texture_source_vk_unittests.cc:16
impeller::android::testing::CreateContext
std::shared_ptr< Context > CreateContext()
Definition: ahb_texture_source_vk_unittests.cc:19
impeller::android::testing::TEST
TEST(AndroidVulkanTest, CanImportRGBA)
Definition: ahb_texture_source_vk_unittests.cc:40
impeller::android::HardwareBufferFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::android::HardwareBufferUsageFlags::kSampledImage
@ kSampledImage
impeller::interop::Create
ScopedObject< Object > Create(CtorArgs &&... args)
Definition: object.h:161
context_vk.h
impeller::ContextVK::Settings
Definition: context_vk.h:79
impeller::ContextVK::Settings::enable_surface_control
bool enable_surface_control
Definition: context_vk.h:85
impeller::ContextVK::Settings::shader_libraries_data
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition: context_vk.h:81
impeller::ContextVK::Settings::proc_address_callback
PFN_vkGetInstanceProcAddr proc_address_callback
Definition: context_vk.h:80
impeller::ContextVK::Settings::enable_gpu_tracing
bool enable_gpu_tracing
Definition: context_vk.h:84
impeller::ContextVK::Settings::enable_validation
bool enable_validation
Definition: context_vk.h:83
impeller::TSize
Definition: size.h:25
impeller::android::HardwareBufferDescriptor
A descriptor use to specify hardware buffer allocations.
Definition: hardware_buffer.h:47
impeller::android::HardwareBufferDescriptor::size
ISize size
Definition: hardware_buffer.h:49
impeller::android::HardwareBufferDescriptor::usage
HardwareBufferUsage usage
Definition: hardware_buffer.h:50
impeller::android::HardwareBufferDescriptor::format
HardwareBufferFormat format
Definition: hardware_buffer.h:48
surface_context_vk.h
surface_transaction.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91