From 2c4847e59a74da1bdcb9c284b1456c7dfc2866c0 Mon Sep 17 00:00:00 2001 From: "Yan,Shaobo" Date: Tue, 4 Apr 2023 08:57:46 +0000 Subject: [PATCH] Fix bug about requiring unexpected files when compiling on Android In MemoryService implementation, Dawn uses DAWN_PLATFORM_IS() to choose required header files for different OS platform. On Android platform, both DAWN_PLATFORM_IS(LINUX) and DAWN_PLATFORM_IS(ANDROID) are true. This caused some linux platform header files and implementations has been included unexpected when compiling on Android platform. This CL strict the macro condition to ensure Android platform include AHardwareBuffer related files only. Bug:dawn:1593 Change-Id: If64567edf99cd25a3783d8c456a1fc3f6a7dccf2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/126323 Reviewed-by: Corentin Wallez Kokoro: Kokoro Commit-Queue: Shaobo Yan --- src/dawn/common/Platform.h | 8 +++++-- .../vulkan/external_memory/MemoryService.cpp | 22 +++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/dawn/common/Platform.h b/src/dawn/common/Platform.h index dc8d79c01b..d0eeb779bf 100644 --- a/src/dawn/common/Platform.h +++ b/src/dawn/common/Platform.h @@ -51,9 +51,10 @@ #define DAWN_PLATFORM_IS_POSIX 1 #if defined(__ANDROID__) #define DAWN_PLATFORM_IS_ANDROID 1 -#endif -#if defined(DAWN_OS_CHROMEOS) +#elif defined(DAWN_OS_CHROMEOS) #define DAWN_PLATFORM_IS_CHROMEOS 1 +#else +#define DAWN_PLATFORM_IS_LINUX_DESKTOP 1 #endif #elif defined(__APPLE__) @@ -197,6 +198,9 @@ static_assert(sizeof(sizeof(char)) == 4, "Expect sizeof(size_t) == 4"); #if !defined(DAWN_PLATFORM_IS_CHROMEOS) #define DAWN_PLATFORM_IS_CHROMEOS 0 #endif +#if !defined(DAWN_PLATFORM_IS_LINUX_DESKTOP) +#define DAWN_PLATFORM_IS_LINUX_DESKTOP 0 +#endif #if !defined(DAWN_PLATFORM_IS_APPLE) #define DAWN_PLATFORM_IS_APPLE 0 diff --git a/src/dawn/native/vulkan/external_memory/MemoryService.cpp b/src/dawn/native/vulkan/external_memory/MemoryService.cpp index f751d75164..35491d3ad1 100644 --- a/src/dawn/native/vulkan/external_memory/MemoryService.cpp +++ b/src/dawn/native/vulkan/external_memory/MemoryService.cpp @@ -17,10 +17,10 @@ #include "dawn/native/vulkan/DeviceVk.h" #include "dawn/native/vulkan/external_memory/MemoryService.h" -#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) +#if DAWN_PLATFORM_IS(LINUX_DESKTOP) || DAWN_PLATFORM_IS(CHROMEOS) #include "dawn/native/vulkan/external_memory/MemoryServiceImplementationDmaBuf.h" #include "dawn/native/vulkan/external_memory/MemoryServiceImplementationOpaqueFD.h" -#endif // DAWN_PLATFORM_IS(LINUX) +#endif // DAWN_PLATFORM_IS(LINUX_DESKTOP) || DAWN_PLATFORM_IS(CHROMEOS) #if DAWN_PLATFORM_IS(ANDROID) #include "dawn/native/vulkan/external_memory/MemoryServiceImplementationAHardwareBuffer.h" @@ -37,7 +37,7 @@ bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo) { return CheckAHardwareBufferSupport(deviceInfo); #elif DAWN_PLATFORM_IS(FUCHSIA) return CheckZirconHandleSupport(deviceInfo); -#elif DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) +#elif DAWN_PLATFORM_IS(LINUX_DESKTOP) || DAWN_PLATFORM_IS(CHROMEOS) return CheckOpaqueFDSupport(deviceInfo) || CheckDmaBufSupport(deviceInfo); #else return false; @@ -51,7 +51,13 @@ Service::Service(Device* device) { } #endif // DAWN_PLATFORM_IS(FUCHSIA) -#if DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) +#if DAWN_PLATFORM_IS(ANDROID) + if (CheckAHardwareBufferSupport(device->GetDeviceInfo())) { + mServiceImpls[ExternalImageType::AHardwareBuffer] = CreateAHardwareBufferService(device); + } +#endif // DAWN_PLATFORM_IS(ANDROID) + +#if DAWN_PLATFORM_IS(LINUX_DESKTOP) || DAWN_PLATFORM_IS(CHROMEOS) if (CheckOpaqueFDSupport(device->GetDeviceInfo())) { mServiceImpls[ExternalImageType::OpaqueFD] = CreateOpaqueFDService(device); } @@ -59,13 +65,7 @@ Service::Service(Device* device) { if (CheckDmaBufSupport(device->GetDeviceInfo())) { mServiceImpls[ExternalImageType::DmaBuf] = CreateDmaBufService(device); } -#endif // DAWN_PLATFORM_IS(LINUX) || DAWN_PLATFORM_IS(CHROMEOS) - -#if DAWN_PLATFORM_IS(ANDROID) - if (CheckAHardwareBufferSupport(device->GetDeviceInfo())) { - mServiceImpls[ExternalImageType::AHardwareBuffer] = CreateAHardwareBufferService(device); - } -#endif // DAWN_PLATFORM_IS(ANDROID) +#endif // DAWN_PLATFORM_IS(LINUX_DESKTOP) || DAWN_PLATFORM_IS(CHROMEOS) } Service::~Service() = default;