gfxstream: Using DETECT_OS_ANDROID from util instead of __ANDROID__

The DETECT_OS_ANDROID constant defined in util/detect_os.h allows
replacing the ocurrences of defined(__ANDROID__) and __ANDROID__. They are
equivalent in functionality but the util's one is easier to read and
write. Also it does not require the define() syntax.

The change involve replacing every ocurrence of defined(__ANDROID__) with
DETECT_OS_ANDROID. Then replacing every ocurrence of #ifdef __ANDROID__
with #if DETECT_OS_ANDROID.

Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32286>
This commit is contained in:
Manuel Dun 2024-11-18 18:01:29 -04:00 committed by Marge Bot
parent dec5523e33
commit 870aa88a5f
12 changed files with 68 additions and 61 deletions

View file

@ -4,26 +4,27 @@
*/
#include "ANativeWindowAndroid.h"
#include "util/detect_os.h"
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
#include <android/native_window.h>
#include <system/window.h>
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
namespace gfxstream {
bool ANativeWindowHelperAndroid::isValid(EGLNativeWindowType window) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
return anw->common.magic == ANDROID_NATIVE_WINDOW_MAGIC;
#else
(void)window;
return false;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
bool ANativeWindowHelperAndroid::isValid(EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anwb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
if (anwb->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) {
return false;
@ -38,130 +39,130 @@ bool ANativeWindowHelperAndroid::isValid(EGLClientBuffer buffer) {
#else
(void)buffer;
return false;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::acquire(EGLNativeWindowType window) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
ANativeWindow_acquire(anw);
#else
(void)window;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::release(EGLNativeWindowType window) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
ANativeWindow_release(anw);
#else
(void)window;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::acquire(EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anwb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
anwb->incStrong(anwb);
#else
(void)buffer;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::release(EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anwb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
anwb->decStrong(anwb);
#else
(void)buffer;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getConsumerUsage(EGLNativeWindowType window, int* usage) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
return anw->query(anw, NATIVE_WINDOW_CONSUMER_USAGE_BITS, usage);
#else
(void)window;
(void)usage;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::setUsage(EGLNativeWindowType window, int usage) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
ANativeWindow_setUsage(anw, usage);
#else
(void)window;
(void)usage;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getWidth(EGLNativeWindowType window) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
return ANativeWindow_getWidth(anw);
#else
(void)window;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getHeight(EGLNativeWindowType window) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
return ANativeWindow_getHeight(anw);
#else
(void)window;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getWidth(EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anwb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return anwb->width;
#else
(void)buffer;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getHeight(EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anwb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return anwb->height;
#else
(void)buffer;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getFormat(EGLClientBuffer buffer, Gralloc* gralloc) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return gralloc->getFormat(anb->handle);
#else
(void)buffer;
(void)gralloc;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
void ANativeWindowHelperAndroid::setSwapInterval(EGLNativeWindowType window, int interval) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
anw->setSwapInterval(anw, interval);
#else
(void)window;
(void)interval;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::queueBuffer(EGLNativeWindowType window, EGLClientBuffer buffer,
int fence) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
auto* anb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return ANativeWindow_queueBuffer(anw, anb, fence);
@ -170,12 +171,12 @@ int ANativeWindowHelperAndroid::queueBuffer(EGLNativeWindowType window, EGLClien
(void)buffer;
(void)fence;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::dequeueBuffer(EGLNativeWindowType window, EGLClientBuffer* buffer,
int* fence) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
auto* anb = reinterpret_cast<ANativeWindowBuffer**>(buffer);
return ANativeWindow_dequeueBuffer(anw, anb, fence);
@ -184,11 +185,11 @@ int ANativeWindowHelperAndroid::dequeueBuffer(EGLNativeWindowType window, EGLCli
(void)buffer;
(void)fence;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::cancelBuffer(EGLNativeWindowType window, EGLClientBuffer buffer) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anw = reinterpret_cast<ANativeWindow*>(window);
auto* anb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return ANativeWindow_cancelBuffer(anw, anb, -1);
@ -196,18 +197,18 @@ int ANativeWindowHelperAndroid::cancelBuffer(EGLNativeWindowType window, EGLClie
(void)window;
(void)buffer;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
int ANativeWindowHelperAndroid::getHostHandle(EGLClientBuffer buffer, Gralloc* gralloc) {
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto* anb = reinterpret_cast<ANativeWindowBuffer*>(buffer);
return gralloc->getHostHandle(anb->handle);
#else
(void)buffer;
(void)gralloc;
return -1;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
}
ANativeWindowHelper* createPlatformANativeWindowHelper() {

View file

@ -4,8 +4,9 @@
*/
#include "gfxstream/guest/GfxStreamGralloc.h"
#include "util/detect_os.h"
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
#include <string>

View file

@ -45,7 +45,7 @@ VirtGpuKumquatDevice::VirtGpuKumquatDevice(enum VirtGpuCapset capset, int32_t de
memset(&mCaps, 0, sizeof(struct VirtGpuCaps));
#ifdef __ANDROID__
#if DETECT_OS_ANDROID
processName = getprogname();
#endif

View file

@ -47,7 +47,7 @@ LinuxVirtGpuDevice::LinuxVirtGpuDevice(enum VirtGpuCapset capset, int32_t descri
memset(&mCaps, 0, sizeof(struct VirtGpuCaps));
#ifdef __ANDROID__
#if DETECT_OS_ANDROID
processName = getprogname();
#endif

View file

@ -3,8 +3,9 @@
* SPDX-License-Identifier: MIT
*/
#include "AndroidHardwareBuffer.h"
#include "util/detect_os.h"
#if defined(__ANDROID__) || defined(__linux__)
#if DETECT_OS_ANDROID || defined(__linux__)
#include <drm_fourcc.h>
#define DRM_FORMAT_YVU420_ANDROID fourcc_code('9', '9', '9', '7')
#define DRM_FORMAT_D16_UNORM fourcc_code('9', '9', '9', '6')
@ -160,7 +161,7 @@ VkResult getAndroidHardwareBufferPropertiesANDROID(
ahbFormatProps->suggestedXChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
ahbFormatProps->suggestedYChromaOffset = VK_CHROMA_LOCATION_MIDPOINT;
#if defined(__ANDROID__) || defined(__linux__)
#if DETECT_OS_ANDROID || defined(__linux__)
if (android_format_is_yuv(format)) {
uint32_t drmFormat = grallocHelper->getFormatDrmFourcc(buffer);
ahbFormatProps->externalFormat = static_cast<uint64_t>(drmFormat);

View file

@ -3,6 +3,7 @@
* SPDX-License-Identifier: MIT
*/
#include "HostVisibleMemoryVirtualization.h"
#include "util/detect_os.h"
#include <set>
@ -20,14 +21,14 @@ CoherentMemory::CoherentMemory(VirtGpuResourceMappingPtr blobMapping, uint64_t s
mBaseAddr = blobMapping->asRawPtr();
}
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
CoherentMemory::CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size,
VkDevice device, VkDeviceMemory memory)
: mSize(size), mBlock(block), mDevice(device), mMemory(memory) {
mHeap = u_mmInit(0, kHostVisibleHeapSize);
mBaseAddr = (uint8_t*)block->mmap(gpuAddr);
}
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
CoherentMemory::~CoherentMemory() {
ResourceTracker::getThreadLocalEncoder()->vkFreeMemorySyncGOOGLE(mDevice, mMemory, nullptr,

View file

@ -9,6 +9,7 @@
#include "VirtGpu.h"
#include "goldfish_address_space.h"
#include "util/u_mm.h"
#include "util/detect_os.h"
constexpr uint64_t kMegaByte = 1048576;
@ -31,10 +32,10 @@ class CoherentMemory {
CoherentMemory(VirtGpuResourceMappingPtr blobMapping, uint64_t size, VkDevice device,
VkDeviceMemory memory);
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
CoherentMemory(GoldfishAddressSpaceBlockPtr block, uint64_t gpuAddr, uint64_t size,
VkDevice device, VkDeviceMemory memory);
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
~CoherentMemory();

View file

@ -1421,12 +1421,12 @@ void ResourceTracker::setupFeatures(const struct GfxStreamVkFeatureInfo* feature
}
mFeatureInfo = *features;
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
if (mFeatureInfo.hasDirectMem) {
mGoldfishAddressSpaceBlockProvider.reset(
new GoldfishAddressSpaceBlockProvider(GoldfishAddressSpaceSubdeviceType::NoSubdevice));
}
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
#ifdef VK_USE_PLATFORM_FUCHSIA
if (mFeatureInfo.hasVulkan) {
@ -2903,7 +2903,7 @@ CoherentMemoryPtr ResourceTracker::createCoherentMemory(
VkEncoder* enc, VkResult& res) {
CoherentMemoryPtr coherentMemory = nullptr;
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
if (mFeatureInfo.hasDirectMem) {
uint64_t gpuAddr = 0;
GoldfishAddressSpaceBlockPtr block = nullptr;
@ -2931,7 +2931,7 @@ CoherentMemoryPtr ResourceTracker::createCoherentMemory(
block, gpuAddr, hostAllocationInfo.allocationSize, device, mem);
}
} else
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
if (mFeatureInfo.hasVirtioGpuNext) {
struct VirtGpuCreateBlob createBlob = {0};
uint64_t hvaSizeId[3];
@ -6353,7 +6353,7 @@ VkResult ResourceTracker::on_vkMapMemoryIntoAddressSpaceGOOGLE_pre(void*, VkResu
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
auto& memInfo = it->second;
GoldfishAddressSpaceBlockPtr block = std::make_shared<GoldfishAddressSpaceBlock>();

View file

@ -758,9 +758,9 @@ class ResourceTracker {
uint64_t coherentMemorySize = 0;
uint64_t coherentMemoryOffset = 0;
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
GoldfishAddressSpaceBlockPtr goldfishBlock = nullptr;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
CoherentMemoryPtr coherentMemory = nullptr;
VirtGpuResourcePtr blobPtr = nullptr;
};
@ -894,9 +894,9 @@ class ResourceTracker {
struct GfxStreamVkFeatureInfo mFeatureInfo = {};
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
std::unique_ptr<GoldfishAddressSpaceBlockProvider> mGoldfishAddressSpaceBlockProvider;
#endif // defined(__ANDROID__)
#endif // DETECT_OS_ANDROID
#if defined(VK_USE_PLATFORM_ANDROID_KHR)
std::unique_ptr<gfxstream::Gralloc> mGralloc = nullptr;

View file

@ -7,6 +7,7 @@
#include <stdlib.h>
#include "util/log.h"
#include "util/detect_os.h"
#define GOLDFISH_VK_OBJECT_DEBUG 0
@ -20,7 +21,7 @@
extern "C" {
#if defined(__ANDROID__) || defined(__Fuchsia__)
#if DETECT_OS_ANDROID || defined(__Fuchsia__)
#define SET_HWVULKAN_DISPATCH_MAGIC res->dispatch.magic = HWVULKAN_DISPATCH_MAGIC;
#elif defined(__linux__)
#define SET_HWVULKAN_DISPATCH_MAGIC res->loaderData.loaderMagic = ICD_LOADER_MAGIC;

View file

@ -3,8 +3,9 @@
* SPDX-License-Identifier: MIT
*/
#pragma once
#include "util/detect_os.h"
#if defined(__ANDROID__) || defined(__Fuchsia__)
#if DETECT_OS_ANDROID || defined(__Fuchsia__)
#include <hardware/hwvulkan.h>
#elif defined(__linux__)
#include <vulkan/vk_icd.h>
@ -38,7 +39,7 @@ struct goldfish_vk_object_list {
struct goldfish_vk_object_list* next;
};
#if defined(__ANDROID__) || defined(__Fuchsia__)
#if DETECT_OS_ANDROID || defined(__Fuchsia__)
#define DECLARE_HWVULKAN_DISPATCH hwvulkan_dispatch_t dispatch;
#elif defined(__linux__)
#define DECLARE_HWVULKAN_DISPATCH VK_LOADER_DATA loaderData;

View file

@ -7,7 +7,7 @@ static ResourceTracker* sResourceTracker = nullptr;
static uint32_t sFeatureBits = 0;
static constexpr uint32_t kWatchdogBufferMax = 1'000;
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
#include <cutils/properties.h>
#endif
@ -16,7 +16,7 @@ class VkEncoder::Impl {
Impl(gfxstream::guest::IOStream* stream) : m_stream(stream), m_logEncodes(false) {
if (!sResourceTracker) sResourceTracker = ResourceTracker::get();
m_stream.incStreamRef();
#if defined(__ANDROID__)
#if DETECT_OS_ANDROID
const char* emuVkLogEncodesPropName = "qemu.vk.log";
char encodeProp[PROPERTY_VALUE_MAX];
if (property_get(emuVkLogEncodesPropName, encodeProp, nullptr) > 0) {