diff --git a/src/igl/opengl/egl/PlatformDevice.cpp b/src/igl/opengl/egl/PlatformDevice.cpp index ccec01baa5..71bb244370 100644 --- a/src/igl/opengl/egl/PlatformDevice.cpp +++ b/src/igl/opengl/egl/PlatformDevice.cpp @@ -10,6 +10,9 @@ #include #include #include +#if IGL_PLATFORM_ANDROID && __ANDROID_MIN_SDK_VERSION__ >= 26 +#include +#endif #include #include @@ -142,6 +145,35 @@ std::shared_ptr PlatformDevice::createTextureFromNativeDepth(Result* o return texture; } +#if IGL_PLATFORM_ANDROID && __ANDROID_MIN_SDK_VERSION__ >= 26 + +/// returns a android::NativeHWTextureBuffer on platforms supporting it +/// this texture allows CPU and GPU to both read/write memory +std::shared_ptr PlatformDevice::createTextureWithSharedMemory(const TextureDesc& desc, + Result* outResult) { + auto context = static_cast(getSharedContext().get()); + if (context == nullptr) { + Result::setResult(outResult, Result::Code::InvalidOperation, "No EGL context found!"); + return nullptr; + } + + Result subResult; + + auto texture = std::make_shared(getContext(), desc.format); + subResult = texture->create(desc, false); + Result::setResult(outResult, subResult.code, subResult.message); + if (!subResult.isOk()) { + return nullptr; + } + + if (auto resourceTracker = owner_.getResourceTracker()) { + texture->initResourceTracker(resourceTracker); + } + + return texture; +} +#endif + void PlatformDevice::updateSurfaces(EGLSurface readSurface, EGLSurface drawSurface, Result* outResult) { diff --git a/src/igl/opengl/egl/PlatformDevice.h b/src/igl/opengl/egl/PlatformDevice.h index cb16dee9fe..2c5dc53a53 100644 --- a/src/igl/opengl/egl/PlatformDevice.h +++ b/src/igl/opengl/egl/PlatformDevice.h @@ -39,6 +39,15 @@ class PlatformDevice : public opengl::PlatformDevice { /// Returns a texture representing the EGL depth texture associated with this device's context. std::shared_ptr createTextureFromNativeDepth(Result* outResult); +#if IGL_PLATFORM_ANDROID && __ANDROID_MIN_SDK_VERSION__ >= 26 + + /// returns a android::NativeHWTextureBuffer on platforms supporting it + /// this texture allows CPU and GPU to both read/write memory + std::shared_ptr createTextureWithSharedMemory(const TextureDesc& desc, + Result* outResult); + +#endif + /// This function must be called every time the currently bound EGL read and/or draw surfaces /// change, in order to notify IGL of these changes. void updateSurfaces(EGLSurface readSurface, EGLSurface drawSurface, Result* outResult); diff --git a/src/igl/opengl/egl/android/NativeHWBuffer.cpp b/src/igl/opengl/egl/android/NativeHWBuffer.cpp index 2840011854..565fc55316 100644 --- a/src/igl/opengl/egl/android/NativeHWBuffer.cpp +++ b/src/igl/opengl/egl/android/NativeHWBuffer.cpp @@ -16,7 +16,7 @@ #include #include -#if defined(__ANDROID_API__) && __ANDROID_MIN_SDK_VERSION__ >= 26 +#if IGL_PLATFORM_ANDROID && __ANDROID_MIN_SDK_VERSION__ >= 26 #if defined(IGL_API_LOG) && (IGL_DEBUG || defined(IGL_FORCE_ENABLE_LOGS)) #define APILOG_DEC_DRAW_COUNT() \ diff --git a/src/igl/opengl/egl/android/NativeHWBuffer.h b/src/igl/opengl/egl/android/NativeHWBuffer.h index f64899a429..ee10796cc6 100644 --- a/src/igl/opengl/egl/android/NativeHWBuffer.h +++ b/src/igl/opengl/egl/android/NativeHWBuffer.h @@ -9,7 +9,7 @@ #include -#if defined(__ANDROID_API__) && __ANDROID_MIN_SDK_VERSION__ >= 26 +#if IGL_PLATFORM_ANDROID && __ANDROID_MIN_SDK_VERSION__ >= 26 struct AHardwareBuffer;