Commit e6ab01f4 by Stephen White

Implement an Android NDK build of SwiftShader using the CMake files.

From the build directory, run: cmake -DCMAKE_TOOLCHAIN_FILE=../build/android.toolchain.cmake .. Everything compiles and links. unittests, vk-unittests and ReactorUnitTests are known to work. A "rundroid.sh" script is provided to upload and run Android binaries. This CL has contains the first draft of an NDK-based FrameBuffer implementation. It stubs out the gralloc calls in Image (consequence: EGLImage likely won't work). NOTE: a small CMake patch is necessary; hopefully we'll find a way around this or land it in CMake: diff cmake-3.10/Modules/Platform/Android/Determine-Compiler-NDK.cmake.bak cmake-3.10/Modules/Platform/Android/Determine-Compiler-NDK.cmake 231c231 < set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_NAME}/prebuilt/${_ANDROID_HOST_DIR}) --- > set(_ANDROID_TOOL_C_COMPILER_EXTERNAL_TOOLCHAIN ${CMAKE_ANDROID_NDK}/toolchains/${_ANDROID_TOOL_LLVM_NAME}/prebuilt/${_ANDROID_HOST_DIR}) Bug: b/129942368 Change-Id: I107a2f719256b6477ad105054ca68c676c05ec5c Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27869 Presubmit-Ready: Stephen White <senorblanco@chromium.org> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarStephen White <senorblanco@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d39c96e9
...@@ -18,6 +18,9 @@ endif() ...@@ -18,6 +18,9 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LINUX ON) set(LINUX ON)
elseif(CMAKE_SYSTEM_NAME MATCHES "Android")
set(ANDROID ON)
set(CMAKE_CXX_FLAGS "-DANDROID_NDK_BUILD")
elseif(WIN32) elseif(WIN32)
elseif(APPLE) elseif(APPLE)
else() else()
...@@ -686,6 +689,8 @@ elseif(LINUX) ...@@ -686,6 +689,8 @@ elseif(LINUX)
set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-linux) set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-linux)
elseif(APPLE) elseif(APPLE)
set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-osx) set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-osx)
elseif(ANDROID)
set(LLVM_INCLUDE_DIR ${LLVM_DIR}/include-android)
endif() endif()
list(APPEND LLVM_INCLUDE_DIR list(APPEND LLVM_INCLUDE_DIR
...@@ -1752,6 +1757,8 @@ elseif(LINUX) ...@@ -1752,6 +1757,8 @@ elseif(LINUX)
list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/linux/include) list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/linux/include)
elseif(APPLE) elseif(APPLE)
list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/darwin/include) list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/darwin/include)
elseif(ANDROID)
list(APPEND LLVM_INCLUDE_DIR ${LLVM_CONFIG_DIR}/android/include)
endif() endif()
list(APPEND LLVM_INCLUDE_DIR list(APPEND LLVM_INCLUDE_DIR
...@@ -2125,6 +2132,14 @@ elseif(APPLE) ...@@ -2125,6 +2132,14 @@ elseif(APPLE)
list(APPEND OPENGL_COMPILER_LIST list(APPEND OPENGL_COMPILER_LIST
${OPENGL_COMPILER_DIR}/ossource_posix.cpp ${OPENGL_COMPILER_DIR}/ossource_posix.cpp
) )
elseif(ANDROID)
list(APPEND SWIFTSHADER_LIST
${SOURCE_DIR}/Main/FrameBufferAndroid.cpp
${SOURCE_DIR}/Main/FrameBufferAndroid.hpp
)
list(APPEND OPENGL_COMPILER_LIST
${OPENGL_COMPILER_DIR}/ossource_posix.cpp
)
endif() endif()
if(WIN32) if(WIN32)
...@@ -2190,6 +2205,9 @@ if(BUILD_EGL) ...@@ -2190,6 +2205,9 @@ if(BUILD_EGL)
COMPILE_DEFINITIONS "EGL_EGLEXT_PROTOTYPES; EGLAPI=; NO_SANITIZE_FUNCTION=;" COMPILE_DEFINITIONS "EGL_EGLEXT_PROTOTYPES; EGLAPI=; NO_SANITIZE_FUNCTION=;"
PREFIX "" PREFIX ""
) )
if (ANDROID)
set_target_properties(libEGL PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libEGL ${SOURCE_DIR}/OpenGL/libEGL) set_shared_library_export_map(libEGL ${SOURCE_DIR}/OpenGL/libEGL)
target_link_libraries(libEGL ${OS_LIBS}) target_link_libraries(libEGL ${OS_LIBS})
add_custom_command( add_custom_command(
...@@ -2210,6 +2228,9 @@ if(BUILD_GLESv2) ...@@ -2210,6 +2228,9 @@ if(BUILD_GLESv2)
COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; GL_API=; GL_APICALL=; GLAPI=; NO_SANITIZE_FUNCTION=;" COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; GL_API=; GL_APICALL=; GLAPI=; NO_SANITIZE_FUNCTION=;"
PREFIX "" PREFIX ""
) )
if (ANDROID)
set_target_properties(libGLESv2 PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libGLESv2 ${SOURCE_DIR}/OpenGL/libGLESv2) set_shared_library_export_map(libGLESv2 ${SOURCE_DIR}/OpenGL/libGLESv2)
target_link_libraries(libGLESv2 SwiftShader ${Reactor} GLCompiler ${OS_LIBS}) target_link_libraries(libGLESv2 SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
add_custom_command( add_custom_command(
...@@ -2230,6 +2251,9 @@ if(BUILD_GLES_CM) ...@@ -2230,6 +2251,9 @@ if(BUILD_GLES_CM)
COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; EGLAPI=; GL_API=; GL_APICALL=; GLAPI=;" COMPILE_DEFINITIONS "GL_GLEXT_PROTOTYPES; EGLAPI=; GL_API=; GL_APICALL=; GLAPI=;"
PREFIX "" PREFIX ""
) )
if (ANDROID)
set_target_properties(libGLES_CM PROPERTIES SUFFIX "_swiftshader.so")
endif ()
set_shared_library_export_map(libGLES_CM ${SOURCE_DIR}/OpenGL/libGLES_CM) set_shared_library_export_map(libGLES_CM ${SOURCE_DIR}/OpenGL/libGLES_CM)
target_link_libraries(libGLES_CM SwiftShader ${Reactor} GLCompiler ${OS_LIBS}) target_link_libraries(libGLES_CM SwiftShader ${Reactor} GLCompiler ${OS_LIBS})
add_custom_command( add_custom_command(
...@@ -2358,6 +2382,9 @@ if(BUILD_TESTS) ...@@ -2358,6 +2382,9 @@ if(BUILD_TESTS)
) )
target_link_libraries(unittests libEGL libGLESv2 ${OS_LIBS}) target_link_libraries(unittests libEGL libGLESv2 ${OS_LIBS})
if(ANDROID)
target_link_libraries(unittests -landroid)
endif()
endif() endif()
if(BUILD_TESTS AND BUILD_VULKAN) if(BUILD_TESTS AND BUILD_VULKAN)
......
set(CMAKE_SYSTEM_NAME Android)
if(NOT $ENV{ANDROID_HOME} STREQUAL "")
set(CMAKE_ANDROID_NDK $ENV{ANDROID_HOME}/ndk-bundle)
else()
set(CMAKE_ANDROID_NDK $ENV{HOME}/Android/Sdk/ndk-bundle)
endif()
set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_STL_TYPE c++_shared)
if(APPLE)
set(CMAKE_RANLIB "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ranlib")
set(CMAKE_AR "${CMAKE_ANDROID_NDK}/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ar")
endif()
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef Debug_hpp #ifndef Debug_hpp
#define Debug_hpp #define Debug_hpp
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "DebugAndroid.hpp" #include "DebugAndroid.hpp"
#else #else
......
...@@ -14,12 +14,16 @@ ...@@ -14,12 +14,16 @@
#include "FrameBufferAndroid.hpp" #include "FrameBufferAndroid.hpp"
#ifndef ANDROID_NDK_BUILD
#include "Common/GrallocAndroid.hpp" #include "Common/GrallocAndroid.hpp"
#include <system/window.h> #include <system/window.h>
#else
#include <android/native_window.h>
#endif
namespace sw namespace sw
{ {
#if !defined(ANDROID_NDK_BUILD)
inline int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer) inline int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer)
{ {
#if ANDROID_PLATFORM_SDK_VERSION > 16 #if ANDROID_PLATFORM_SDK_VERSION > 16
...@@ -46,18 +50,23 @@ namespace sw ...@@ -46,18 +50,23 @@ namespace sw
return window->cancelBuffer(window, buffer); return window->cancelBuffer(window, buffer);
#endif #endif
} }
#endif // !defined(ANDROID_NDK_BUILD)
FrameBufferAndroid::FrameBufferAndroid(ANativeWindow* window, int width, int height) FrameBufferAndroid::FrameBufferAndroid(ANativeWindow* window, int width, int height)
: FrameBuffer(width, height, false, false), : FrameBuffer(width, height, false, false),
nativeWindow(window), buffer(nullptr) nativeWindow(window), buffer(nullptr)
{ {
#ifndef ANDROID_NDK_BUILD
nativeWindow->common.incRef(&nativeWindow->common); nativeWindow->common.incRef(&nativeWindow->common);
native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
#endif
} }
FrameBufferAndroid::~FrameBufferAndroid() FrameBufferAndroid::~FrameBufferAndroid()
{ {
#ifndef ANDROID_NDK_BUILD
nativeWindow->common.decRef(&nativeWindow->common); nativeWindow->common.decRef(&nativeWindow->common);
#endif
} }
void FrameBufferAndroid::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) void FrameBufferAndroid::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
...@@ -72,17 +81,51 @@ namespace sw ...@@ -72,17 +81,51 @@ namespace sw
unlock(); unlock();
} }
#ifndef ANDROID_NDK_BUILD
queueBuffer(nativeWindow, buffer, -1); queueBuffer(nativeWindow, buffer, -1);
#endif
} }
} }
void *FrameBufferAndroid::lock() void *FrameBufferAndroid::lock()
{ {
if(dequeueBuffer(nativeWindow, &buffer) != 0)
#if defined(ANDROID_NDK_BUILD)
ANativeWindow_Buffer surfaceBuffer;
if (ANativeWindow_lock(nativeWindow, &surfaceBuffer, nullptr) != 0) {
TRACE("%s failed to lock buffer %p", __FUNCTION__, buffer);
return nullptr;
}
framebuffer = surfaceBuffer.bits;
if((surfaceBuffer.width < width) || (surfaceBuffer.height < height))
{ {
TRACE("lock failed: buffer of %dx%d too small for window of %dx%d",
surfaceBuffer.width, surfaceBuffer.height, width, height);
return nullptr; return nullptr;
} }
switch(surfaceBuffer.format)
{
case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM: format = FORMAT_A8B8G8R8; break;
case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM: format = FORMAT_X8B8G8R8; break;
case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
TRACE("Unsupported frame buffer format R8G8B8"); ASSERT(false);
format = FORMAT_R8G8B8; // Wrong component order.
break;
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM: format = FORMAT_R5G6B5; break;
default:
TRACE("Unsupported frame buffer format %d", surfaceBuffer.format); ASSERT(false);
format = FORMAT_NULL;
break;
}
stride = surfaceBuffer.stride * Surface::bytes(format);
#else // !defined(ANDROID_NDK_BUILD)
if(dequeueBuffer(nativeWindow, &buffer) != 0)
{
return nullptr;
}
if(GrallocModule::getInstance()->lock(buffer->handle, if(GrallocModule::getInstance()->lock(buffer->handle,
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
0, 0, buffer->width, buffer->height, &framebuffer) != 0) 0, 0, buffer->width, buffer->height, &framebuffer) != 0)
...@@ -117,8 +160,9 @@ namespace sw ...@@ -117,8 +160,9 @@ namespace sw
format = FORMAT_NULL; format = FORMAT_NULL;
break; break;
} }
stride = buffer->stride * Surface::bytes(format); stride = buffer->stride * Surface::bytes(format);
#endif // !defined(ANDROID_NDK_BUILD)
return framebuffer; return framebuffer;
} }
...@@ -132,10 +176,14 @@ namespace sw ...@@ -132,10 +176,14 @@ namespace sw
framebuffer = nullptr; framebuffer = nullptr;
#ifdef ANDROID_NDK_BUILD
ANativeWindow_unlockAndPost(nativeWindow);
#else
if(GrallocModule::getInstance()->unlock(buffer->handle) != 0) if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
{ {
TRACE("%s: badness unlock failed", __FUNCTION__); TRACE("%s: badness unlock failed", __FUNCTION__);
} }
#endif
} }
} }
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#if defined(__ANDROID__) #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h> #include <system/window.h>
#include "../../Common/GrallocAndroid.hpp" #include "../../Common/GrallocAndroid.hpp"
#endif #endif
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#define LOGLOCK(fmt, ...) // TRACE(fmt " tid=%d", ##__VA_ARGS__, gettid()) #define LOGLOCK(fmt, ...) // TRACE(fmt " tid=%d", ##__VA_ARGS__, gettid())
#else #else
...@@ -235,7 +235,7 @@ protected: ...@@ -235,7 +235,7 @@ protected:
void loadStencilData(GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, GLenum format, GLenum type, const void *input, void *buffer); void loadStencilData(GLsizei width, GLsizei height, GLsizei depth, int inputPitch, int inputHeight, GLenum format, GLenum type, const void *input, void *buffer);
}; };
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
inline GLenum GLPixelFormatFromAndroid(int halFormat) inline GLenum GLPixelFormatFromAndroid(int halFormat)
{ {
...@@ -362,7 +362,7 @@ private: ...@@ -362,7 +362,7 @@ private:
} }
}; };
#endif // __ANDROID__ #endif // __ANDROID__ && !defined(ANDROID_NDK_BUILD)
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "common/debug.h" #include "common/debug.h"
#ifdef __ANDROID__ #ifdef __ANDROID__
#if !defined(ANDROID_NDK_BUILD)
#include <utils/String8.h> #include <utils/String8.h>
#if ANDROID_PLATFORM_SDK_VERSION < 27 #if ANDROID_PLATFORM_SDK_VERSION < 27
#include <cutils/log.h> #include <cutils/log.h>
...@@ -26,13 +27,14 @@ ...@@ -26,13 +27,14 @@
#error "ANDROID_PLATFORM_SDK_VERSION is not defined" #error "ANDROID_PLATFORM_SDK_VERSION is not defined"
#endif #endif
#endif #endif
#endif
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
namespace es namespace es
{ {
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
static void output(const char *format, va_list vararg) static void output(const char *format, va_list vararg)
{ {
ALOGI("%s", android::String8::formatV(format, vararg).string()); ALOGI("%s", android::String8::formatV(format, vararg).string());
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef COMMON_DEBUG_H_ #ifndef COMMON_DEBUG_H_
#define COMMON_DEBUG_H_ #define COMMON_DEBUG_H_
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else #else
#include <stdio.h> #include <stdio.h>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef _CONSTANT_UNION_INCLUDED_ #ifndef _CONSTANT_UNION_INCLUDED_
#define _CONSTANT_UNION_INCLUDED_ #define _CONSTANT_UNION_INCLUDED_
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else #else
#include <assert.h> #include <assert.h>
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
// are tracked in the intermediate representation, not the symbol table. // are tracked in the intermediate representation, not the symbol table.
// //
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#else #else
#include <assert.h> #include <assert.h>
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef COMPILER_DEBUG_H_ #ifndef COMPILER_DEBUG_H_
#define COMPILER_DEBUG_H_ #define COMPILER_DEBUG_H_
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "../../Common/DebugAndroid.hpp" #include "../../Common/DebugAndroid.hpp"
#define Trace(...) ((void)0) #define Trace(...) ((void)0)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "common/debug.h" #include "common/debug.h"
#include <EGL/eglext.h> #include <EGL/eglext.h>
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/graphics.h> #include <system/graphics.h>
#endif #endif
...@@ -65,7 +65,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, ...@@ -65,7 +65,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval,
mBlueSize = 8; mBlueSize = 8;
mAlphaSize = 8; mAlphaSize = 8;
mBindToTextureRGBA = EGL_TRUE; mBindToTextureRGBA = EGL_TRUE;
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
mNativeVisualID = HAL_PIXEL_FORMAT_BGRA_8888; mNativeVisualID = HAL_PIXEL_FORMAT_BGRA_8888;
#else #else
mNativeVisualID = 2; // Arbitrary; prefer over ABGR mNativeVisualID = 2; // Arbitrary; prefer over ABGR
...@@ -77,7 +77,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, ...@@ -77,7 +77,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval,
mBlueSize = 8; mBlueSize = 8;
mAlphaSize = 8; mAlphaSize = 8;
mBindToTextureRGBA = EGL_TRUE; mBindToTextureRGBA = EGL_TRUE;
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
mNativeVisualID = HAL_PIXEL_FORMAT_RGBA_8888; mNativeVisualID = HAL_PIXEL_FORMAT_RGBA_8888;
#endif #endif
break; break;
...@@ -86,7 +86,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, ...@@ -86,7 +86,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval,
mGreenSize = 6; mGreenSize = 6;
mBlueSize = 5; mBlueSize = 5;
mAlphaSize = 0; mAlphaSize = 0;
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
mNativeVisualID = HAL_PIXEL_FORMAT_RGB_565; mNativeVisualID = HAL_PIXEL_FORMAT_RGB_565;
#endif #endif
break; break;
...@@ -96,7 +96,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, ...@@ -96,7 +96,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval,
mBlueSize = 8; mBlueSize = 8;
mAlphaSize = 0; mAlphaSize = 0;
mBindToTextureRGB = EGL_TRUE; mBindToTextureRGB = EGL_TRUE;
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
mNativeVisualID = 0x1FF; // HAL_PIXEL_FORMAT_BGRX_8888 mNativeVisualID = 0x1FF; // HAL_PIXEL_FORMAT_BGRX_8888
#else #else
mNativeVisualID = 1; // Arbitrary; prefer over XBGR mNativeVisualID = 1; // Arbitrary; prefer over XBGR
...@@ -108,7 +108,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval, ...@@ -108,7 +108,7 @@ Config::Config(sw::Format displayFormat, EGLint minInterval, EGLint maxInterval,
mBlueSize = 8; mBlueSize = 8;
mAlphaSize = 0; mAlphaSize = 0;
mBindToTextureRGB = EGL_TRUE; mBindToTextureRGB = EGL_TRUE;
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
mNativeVisualID = HAL_PIXEL_FORMAT_RGBX_8888; mNativeVisualID = HAL_PIXEL_FORMAT_RGBX_8888;
#endif #endif
break; break;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "Common/RecursiveLock.hpp" #include "Common/RecursiveLock.hpp"
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h> #include <system/window.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <linux/fb.h> #include <linux/fb.h>
...@@ -671,11 +671,13 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -671,11 +671,13 @@ bool Display::isValidWindow(EGLNativeWindowType window)
ERR("%s called with window==NULL %s:%d", __FUNCTION__, __FILE__, __LINE__); ERR("%s called with window==NULL %s:%d", __FUNCTION__, __FILE__, __LINE__);
return false; return false;
} }
#if !defined(ANDROID_NDK_BUILD)
if(static_cast<ANativeWindow*>(window)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC) if(static_cast<ANativeWindow*>(window)->common.magic != ANDROID_NATIVE_WINDOW_MAGIC)
{ {
ERR("%s called with window==%p bad magic %s:%d", __FUNCTION__, window, __FILE__, __LINE__); ERR("%s called with window==%p bad magic %s:%d", __FUNCTION__, window, __FILE__, __LINE__);
return false; return false;
} }
#endif // !defined(ANDROID_NDK_BUILD)
return true; return true;
#elif defined(USE_X11) #elif defined(USE_X11)
if(nativeDisplay) if(nativeDisplay)
...@@ -782,6 +784,7 @@ sw::Format Display::getDisplayFormat() const ...@@ -782,6 +784,7 @@ sw::Format Display::getDisplayFormat() const
default: UNREACHABLE(bpp); // Unexpected display mode color depth default: UNREACHABLE(bpp); // Unexpected display mode color depth
} }
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
#if !defined(ANDROID_NDK_BUILD)
static const char *const framebuffer[] = static const char *const framebuffer[] =
{ {
"/dev/graphics/fb0", "/dev/graphics/fb0",
...@@ -841,6 +844,7 @@ sw::Format Display::getDisplayFormat() const ...@@ -841,6 +844,7 @@ sw::Format Display::getDisplayFormat() const
} }
} }
} }
#endif // !defined_ANDROID_NDK_BUILD)
// No framebuffer device found, or we're in user space // No framebuffer device found, or we're in user space
return sw::FORMAT_X8B8G8R8; return sw::FORMAT_X8B8G8R8;
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#elif defined(__APPLE__) #elif defined(__APPLE__)
#include "OSXUtils.hpp" #include "OSXUtils.hpp"
#endif #endif
#if defined(__ANDROID__) && defined(ANDROID_NDK_BUILD)
#include <android/native_window.h>
#endif
#include <algorithm> #include <algorithm>
...@@ -339,8 +342,13 @@ bool WindowSurface::checkForResize() ...@@ -339,8 +342,13 @@ bool WindowSurface::checkForResize()
int windowWidth = client.right - client.left; int windowWidth = client.right - client.left;
int windowHeight = client.bottom - client.top; int windowHeight = client.bottom - client.top;
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
#ifdef ANDROID_NDK_BUILD
int windowWidth = ANativeWindow_getWidth(window);
int windowHeight = ANativeWindow_getHeight(window);
#else
int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth); int windowWidth; window->query(window, NATIVE_WINDOW_WIDTH, &windowWidth);
int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight); int windowHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &windowHeight);
#endif
#elif defined(USE_X11) #elif defined(USE_X11)
XWindowAttributes windowAttributes; XWindowAttributes windowAttributes;
Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes); Status status = libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "Common/Version.h" #include "Common/Version.h"
#if defined(__ANDROID__) #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include <system/window.h> #include <system/window.h>
#elif defined(USE_X11) #elif defined(USE_X11)
#include "Main/libX11.hpp" #include "Main/libX11.hpp"
...@@ -1170,7 +1170,7 @@ EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBu ...@@ -1170,7 +1170,7 @@ EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBu
} }
} }
#if defined(__ANDROID__) #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
if(target == EGL_NATIVE_BUFFER_ANDROID) if(target == EGL_NATIVE_BUFFER_ANDROID)
{ {
ANativeWindowBuffer *nativeBuffer = reinterpret_cast<ANativeWindowBuffer*>(buffer); ANativeWindowBuffer *nativeBuffer = reinterpret_cast<ANativeWindowBuffer*>(buffer);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef Debug_hpp #ifndef Debug_hpp
#define Debug_hpp #define Debug_hpp
#ifdef __ANDROID__ #if defined(__ANDROID__) && !defined(ANDROID_NDK_BUILD)
#include "DebugAndroid.hpp" #include "DebugAndroid.hpp"
#else #else
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef Debug_hpp #ifndef Debug_hpp
#define Debug_hpp #define Debug_hpp
#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
#include "DebugAndroid.hpp" #include "DebugAndroid.hpp"
#else #else
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
#elif defined(__APPLE__) #elif defined(__APPLE__)
# include "dlfcn.h" # include "dlfcn.h"
# define OS_MAC 1 # define OS_MAC 1
#elif defined(__ANDROID__)
# include "dlfcn.h"
# define OS_ANDROID 1
#elif defined(__linux__) #elif defined(__linux__)
# include "dlfcn.h" # include "dlfcn.h"
# define OS_LINUX 1 # define OS_LINUX 1
...@@ -55,6 +58,8 @@ bool Driver::loadSwiftShader() ...@@ -55,6 +58,8 @@ bool Driver::loadSwiftShader()
return load("./build/Darwin/libvk_swiftshader.dylib"); return load("./build/Darwin/libvk_swiftshader.dylib");
#elif OS_LINUX #elif OS_LINUX
return load("./build/Linux/libvk_swiftshader.so"); return load("./build/Linux/libvk_swiftshader.so");
#elif OS_ANDROID
return load("libvk_swiftshader.so");
#else #else
# error Unimplemented platform # error Unimplemented platform
#endif #endif
...@@ -73,7 +78,7 @@ bool Driver::load(const char* path) ...@@ -73,7 +78,7 @@ bool Driver::load(const char* path)
{ {
#if OS_WINDOWS #if OS_WINDOWS
dll = LoadLibraryA(path); dll = LoadLibraryA(path);
#elif(OS_MAC || OS_LINUX) #elif(OS_MAC || OS_LINUX || OS_ANDROID)
dll = dlopen(path, RTLD_LAZY | RTLD_LOCAL); dll = dlopen(path, RTLD_LAZY | RTLD_LOCAL);
#else #else
return false; return false;
...@@ -157,7 +162,7 @@ void* Driver::lookup(const char* name) ...@@ -157,7 +162,7 @@ void* Driver::lookup(const char* name)
{ {
#if OS_WINDOWS #if OS_WINDOWS
return GetProcAddress((HMODULE)dll, name); return GetProcAddress((HMODULE)dll, name);
#elif(OS_MAC || OS_LINUX) #elif(OS_MAC || OS_LINUX || OS_ANDROID)
return dlsym(dll, name); return dlsym(dll, name);
#else #else
return nullptr; return nullptr;
......
#!/bin/bash
# Run an Android NDK binary on the connected device.
#
# Example usage:
# $ cd <builddir>
# $ make vk-unittests
# $ ../rundroid vk-unittests
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <executable>"
exit 1
fi
dst_dir=/data/local/tmp
path="$1"
name="$(basename "$path")"
shift
if [ -z "$ANDROID_HOME" ]; then
ANDROID_HOME=$HOME/Android/Sdk
fi
set -e
set -x
for lib in libGLESv2_swiftshader.so libEGL_swiftshader.so libvk_swiftshader.so; do
adb push --sync "$lib" "${dst_dir}/${lib}"
done
adb push --sync "$ANDROID_HOME/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so" "${dst_dir}/libc++_shared.so"
adb push --sync "$path" "${dst_dir}/${name}"
adb shell "cd \"$dst_dir\"; chmod +x \"$name\"; LD_LIBRARY_PATH=. ./$name $*"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment