Make SwiftShader compile on Mac (with unimplemented functions)
Change-Id: Iaef054314fb27632513397412ca9dc22b67a70ce
Reviewed-on: https://swiftshader-review.googlesource.com/4380
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44d3372..d5131a4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,7 +74,7 @@
endif()
if(MSVC)
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS "/DEF:\"${DIR}/${TARGET}.def\"")
- else()
+ elseif(LINUX)
# Both hash-style are needed, because we want both gold and
# GNU ld to be able to read our libraries (maybe?).
# The version script only exports the API functions and
@@ -354,6 +354,14 @@
list(APPEND OPENGL_COMPILER_LIST
${OPENGL_COMPILER_DIR}/ossource_posix.cpp
)
+elseif(APPLE)
+ list(APPEND SWIFTSHADER_LIST
+ ${SOURCE_DIR}/Main/FrameBufferOSX.mm
+ ${SOURCE_DIR}/Main/FrameBufferOSX.hpp
+ )
+ list(APPEND OPENGL_COMPILER_LIST
+ ${OPENGL_COMPILER_DIR}/ossource_posix.cpp
+ )
endif()
if(WIN32)
diff --git a/src/Common/Thread.hpp b/src/Common/Thread.hpp
index 3f5d867..d57dd41 100644
--- a/src/Common/Thread.hpp
+++ b/src/Common/Thread.hpp
@@ -119,8 +119,6 @@
{
#if defined(_WIN32)
Sleep(milliseconds);
- #elif defined(__APPLE__)
- nap(milliseconds);
#else
usleep(1000 * milliseconds);
#endif
diff --git a/src/Main/FrameBufferOSX.hpp b/src/Main/FrameBufferOSX.hpp
new file mode 100644
index 0000000..bbd8493
--- /dev/null
+++ b/src/Main/FrameBufferOSX.hpp
@@ -0,0 +1,25 @@
+#ifndef sw_FrameBufferOSX_hpp
+#define sw_FrameBufferOSX_hpp
+
+#include "Main/FrameBuffer.hpp"
+
+@class CALayer;
+
+namespace sw
+{
+ class FrameBufferOSX : public FrameBuffer
+ {
+ public:
+ FrameBufferOSX(CALayer *window, int width, int height) : FrameBuffer(width, height, false, false) {};
+
+ ~FrameBufferOSX() override {};
+
+ void flip(void *source, Format sourceFormat, size_t sourceStride) override;
+ void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override {};
+
+ void *lock() override {return nullptr;};
+ void unlock() override {};
+ };
+}
+
+#endif // sw_FrameBufferOSX
diff --git a/src/Main/FrameBufferOSX.mm b/src/Main/FrameBufferOSX.mm
new file mode 100644
index 0000000..0ed083c
--- /dev/null
+++ b/src/Main/FrameBufferOSX.mm
@@ -0,0 +1,14 @@
+#include "FrameBufferOSX.hpp"
+
+namespace sw
+{
+ void FrameBufferOSX::flip(void *source, Format sourceFormat, size_t sourceStride)
+ {
+ blit(source, 0, 0, sourceFormat, sourceStride);
+ }
+}
+
+sw::FrameBuffer *createFrameBuffer(void *display, CALayer *layer, int width, int height)
+{
+ return new sw::FrameBufferOSX(layer, width, height);
+}
diff --git a/src/OpenGL/libEGL/Display.cpp b/src/OpenGL/libEGL/Display.cpp
index 4ec679b..4c1c7e2 100644
--- a/src/OpenGL/libEGL/Display.cpp
+++ b/src/OpenGL/libEGL/Display.cpp
@@ -544,7 +544,7 @@
return false;
}
return true;
- #else
+ #elif defined(__linux__)
if(platform == EGL_PLATFORM_X11_EXT)
{
XWindowAttributes windowAttributes;
@@ -552,6 +552,10 @@
return status == True;
}
+ #elif defined(__APPLE__)
+ return true;
+ #else
+ #error "Display::isValidWindow unimplemented for this platform"
#endif
return false;
@@ -664,7 +668,7 @@
// No framebuffer device found, or we're in user space
return sw::FORMAT_X8B8G8R8;
- #else
+ #elif defined(__linux__)
if(platform == EGL_PLATFORM_X11_EXT)
{
Screen *screen = libX11->XDefaultScreenOfDisplay((::Display*)nativeDisplay);
@@ -683,6 +687,10 @@
return sw::FORMAT_X8R8G8B8;
}
else UNREACHABLE(platform);
+ #elif defined(__APPLE__)
+ return sw::FORMAT_X8R8G8B8;
+ #else
+ #error "Display::isValidWindow unimplemented for this platform"
#endif
return sw::FORMAT_X8R8G8B8;
diff --git a/src/OpenGL/libEGL/Surface.cpp b/src/OpenGL/libEGL/Surface.cpp
index 538d010..b6599da 100644
--- a/src/OpenGL/libEGL/Surface.cpp
+++ b/src/OpenGL/libEGL/Surface.cpp
@@ -244,11 +244,15 @@
int height; window->query(window, NATIVE_WINDOW_HEIGHT, &height);
return reset(width, height);
- #else
+ #elif defined(__linux__)
XWindowAttributes windowAttributes;
libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
return reset(windowAttributes.width, windowAttributes.height);
+ #elif defined(__APPLE__)
+ return true;
+ #else
+ #error "WindowSurface::initialize unimplemented for this platform"
#endif
}
@@ -284,12 +288,18 @@
#elif defined(__ANDROID__)
int clientWidth; window->query(window, NATIVE_WINDOW_WIDTH, &clientWidth);
int clientHeight; window->query(window, NATIVE_WINDOW_HEIGHT, &clientHeight);
- #else
+ #elif defined(__linux__)
XWindowAttributes windowAttributes;
libX11->XGetWindowAttributes((::Display*)display->getNativeDisplay(), window, &windowAttributes);
int clientWidth = windowAttributes.width;
int clientHeight = windowAttributes.height;
+ #elif defined(__APPLE__)
+ int clientWidth = 0;
+ int clientHeight = 0;
+ return true;
+ #else
+ #error "WindowSurface::checkForResize unimplemented for this platform"
#endif
bool sizeDirty = (clientWidth != width) || (clientHeight != height);