Fix gfxstream build on Mac
It builds but still doesn't run.
Bug: 241588362
Change-Id: If3c583324ee14ad6d3fa1f644a3735a41cff7e53
diff --git a/snapshot/CMakeLists.txt b/snapshot/CMakeLists.txt
index a9e7638..42b2445 100644
--- a/snapshot/CMakeLists.txt
+++ b/snapshot/CMakeLists.txt
@@ -11,3 +11,7 @@
gfxstream-snapshot
PUBLIC
${GFXSTREAM_REPO_ROOT})
+if (APPLE)
+ target_compile_definitions(
+ gfxstream-snapshot PRIVATE -Dfseeko64=fseek -Dftello64=ftell)
+endif()
diff --git a/stream-servers/CMakeLists.txt b/stream-servers/CMakeLists.txt
index 1cfb3aa..f72cacc 100644
--- a/stream-servers/CMakeLists.txt
+++ b/stream-servers/CMakeLists.txt
@@ -106,6 +106,12 @@
PUBLIC
gfxstream_backend_static)
+if (APPLE)
+ set_target_properties(gfxstream_backend
+ PROPERTIES
+ LINK_FLAGS "-undefined dynamic_lookup -flat_namespace")
+endif()
+
android_install_shared(gfxstream_backend)
# Testing libraries
@@ -245,6 +251,10 @@
gtest
gtest_main
gmock)
+ if (APPLE)
+ target_compile_definitions(Vulkan_unittests PRIVATE -DVK_USE_PLATFORM_METAL_EXT)
+ target_link_libraries(Vulkan_unittests PUBLIC "-framework AppKit")
+ endif()
gtest_discover_tests(
Vulkan_unittests
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
diff --git a/stream-servers/ContextHelper.h b/stream-servers/ContextHelper.h
index 677babb..3f14735 100644
--- a/stream-servers/ContextHelper.h
+++ b/stream-servers/ContextHelper.h
@@ -45,13 +45,13 @@
RecursiveScopedContextBind(ContextHelper* helper) : mHelper(helper) {
if (helper->isBound()) return;
if (!helper->setupContext()) {
- mHelper = NULL;
+ mHelper = nullptr;
return;
}
mNeedUnbind = true;
}
- bool isOk() const { return mHelper != NULL; }
+ bool isOk() const { return mHelper != nullptr; }
~RecursiveScopedContextBind() { release(); }
@@ -60,7 +60,7 @@
mHelper->teardownContext();
mNeedUnbind = false;
}
- mHelper = NULL;
+ mHelper = nullptr;
}
private:
diff --git a/stream-servers/glestranslator/EGL/EglOsApi_darwin.cpp b/stream-servers/glestranslator/EGL/EglOsApi_darwin.cpp
index d10a7eb..a0fee5b 100644
--- a/stream-servers/glestranslator/EGL/EglOsApi_darwin.cpp
+++ b/stream-servers/glestranslator/EGL/EglOsApi_darwin.cpp
@@ -17,10 +17,9 @@
#include "MacNative.h"
-#include "android/base/containers/Lookup.h"
+#include "base/Lookup.h"
+#include "base/SharedLibrary.h"
-#include "emugl/common/lazy_instance.h"
-#include "emugl/common/shared_library.h"
#include "host-common/logging.h"
#include "GLcommon/GLLibrary.h"
@@ -41,8 +40,7 @@
using FinalizedConfigMap =
std::unordered_map<FinalizedConfigKey, void*, FinalizedConfigHash>;
-static emugl::LazyInstance<FinalizedConfigMap> sFinalizedConfigs =
- LAZY_INSTANCE_INIT;
+static FinalizedConfigMap sFinalizedConfigs;
namespace {
@@ -92,10 +90,17 @@
int numNativeFormats = 0;
MacOpenGLProfileVersions maxOpenGLProfile =
MAC_OPENGL_PROFILE_LEGACY;
+ static MacNativeSupportInfo* get() {
+ if (!sSupportInfo) {
+ sSupportInfo = new MacNativeSupportInfo();
+ }
+ return sSupportInfo;
+ }
+private:
+ static MacNativeSupportInfo* sSupportInfo;
};
-static emugl::LazyInstance<MacNativeSupportInfo> sSupportInfo =
- LAZY_INSTANCE_INIT;
+MacNativeSupportInfo* MacNativeSupportInfo::sSupportInfo = nullptr;
class MacPixelFormat : public EglOS::PixelFormat {
public:
@@ -185,7 +190,7 @@
explicit MacDisplay(EGLNativeDisplayType dpy) : mDpy(dpy) {}
virtual EglOS::GlesVersion getMaxGlesVersion() {
- switch (sSupportInfo->maxOpenGLProfile) {
+ switch (MacNativeSupportInfo::get()->maxOpenGLProfile) {
case MAC_OPENGL_PROFILE_LEGACY:
return EglOS::GlesVersion::ES2;
case MAC_OPENGL_PROFILE_3_2:
@@ -199,7 +204,7 @@
virtual void queryConfigs(int renderableType,
EglOS::AddConfigCallback* addConfigFunc,
void* addConfigOpaque) {
- for (int i = 0; i < sSupportInfo->numNativeFormats; i++) {
+ for (int i = 0; i < MacNativeSupportInfo::get()->numNativeFormats; i++) {
pixelFormatToConfig(
i,
addConfigFunc,
@@ -245,7 +250,7 @@
return ret && match;
}
- virtual emugl::SmartPtr<EglOS::Context> createContext(
+ virtual std::shared_ptr<EglOS::Context> createContext(
EGLint profileMask,
const EglOS::PixelFormat* pixelFormat,
EglOS::Context* sharedContext) {
@@ -260,13 +265,13 @@
MacPixelFormat::from(pixelFormat)->handle());
void* nsFormat = nullptr;
- if (auto format = android::base::find(sFinalizedConfigs.get(), key)) {
+ if (auto format = android::base::find(sFinalizedConfigs, key)) {
nsFormat = *format;
} else {
nsFormat =
finalizePixelFormat(isCoreProfile,
MacPixelFormat::from(pixelFormat)->handle());
- sFinalizedConfigs.get()[key] = nsFormat;
+ sFinalizedConfigs[key] = nsFormat;
}
return std::make_shared<MacContext>(
@@ -289,7 +294,7 @@
}
EGLint maxMipmap = info->hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL : 0;
bool isLegacyOpenGL =
- sSupportInfo->maxOpenGLProfile == MAC_OPENGL_PROFILE_LEGACY;
+ MacNativeSupportInfo::get()->maxOpenGLProfile == MAC_OPENGL_PROFILE_LEGACY;
MacSurface* result = new MacSurface(
isLegacyOpenGL
? nsCreatePBuffer(glTexTarget, glTexFormat, maxMipmap,
@@ -363,7 +368,7 @@
static const char kLibName[] =
"/System/Library/Frameworks/OpenGL.framework/OpenGL";
char error[256];
- mLib = emugl::SharedLibrary::open(kLibName, error, sizeof(error));
+ mLib = android::base::SharedLibrary::open(kLibName, error, sizeof(error));
if (!mLib) {
ERR("%s: Could not open GL library %s [%s]\n",
__FUNCTION__, kLibName, error);
@@ -382,7 +387,7 @@
}
private:
- emugl::SharedLibrary* mLib = nullptr;
+ android::base::SharedLibrary* mLib = nullptr;
};
class MacEngine : public EglOS::Engine {
@@ -408,13 +413,16 @@
MacGlLibrary mGlLib;
};
-emugl::LazyInstance<MacEngine> sHostEngine = LAZY_INSTANCE_INIT;
+static MacEngine* sHostEngine = nullptr;
} // namespace
// static
EglOS::Engine* EglOS::Engine::getHostInstance() {
- return sHostEngine.ptr();
+ if (!sHostEngine) {
+ sHostEngine = new MacEngine();
+ }
+ return sHostEngine;
}
diff --git a/stream-servers/testlibs/CMakeLists.txt b/stream-servers/testlibs/CMakeLists.txt
index b77ed89..122ccd6 100644
--- a/stream-servers/testlibs/CMakeLists.txt
+++ b/stream-servers/testlibs/CMakeLists.txt
@@ -32,4 +32,9 @@
PRIVATE
X11
)
+elseif (APPLE)
+ target_link_libraries(
+ OSWindow
+ PRIVATE
+ "-framework AppKit -framework QuartzCore")
endif()
diff --git a/stream-servers/vulkan/CMakeLists.txt b/stream-servers/vulkan/CMakeLists.txt
index 0aadeb4..c65e504 100644
--- a/stream-servers/vulkan/CMakeLists.txt
+++ b/stream-servers/vulkan/CMakeLists.txt
@@ -38,6 +38,8 @@
if (WIN32)
target_compile_definitions(gfxstream-vulkan-server PRIVATE -DVK_USE_PLATFORM_WIN32_KHR)
+elseif (APPLE)
+target_compile_definitions(gfxstream-vulkan-server PRIVATE -DVK_USE_PLATFORM_METAL_EXT)
endif()
if (NOT MSVC)
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index e799249..ac151f0 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -1968,7 +1968,7 @@
return false;
}
- std::size_t bufferCopySize = 0;
+ VkDeviceSize bufferCopySize = 0;
std::vector<VkBufferImageCopy> bufferImageCopies;
if (!getFormatTransferInfo(colorBufferInfo->imageCreateInfoShallow.format,
colorBufferInfo->imageCreateInfoShallow.extent.width,
@@ -2153,7 +2153,7 @@
return false;
}
- std::size_t bufferCopySize = 0;
+ VkDeviceSize bufferCopySize = 0;
std::vector<VkBufferImageCopy> bufferImageCopies;
if (!getFormatTransferInfo(colorBufferInfo->imageCreateInfoShallow.format,
colorBufferInfo->imageCreateInfoShallow.extent.width,
diff --git a/stream-servers/vulkan/VulkanDispatch.cpp b/stream-servers/vulkan/VulkanDispatch.cpp
index af2346e..66bae96 100644
--- a/stream-servers/vulkan/VulkanDispatch.cpp
+++ b/stream-servers/vulkan/VulkanDispatch.cpp
@@ -18,6 +18,7 @@
#include "base/PathUtils.h"
#include "base/SharedLibrary.h"
#include "base/System.h"
+#include "host-common/misc.h"
using android::base::AutoLock;
using android::base::Lock;
@@ -144,7 +145,7 @@
}
}
-#ifdef __APPLE_
+#ifdef __APPLE__
static std::string getMoltenVkPath(const std::string& directory, bool forTesting) {
auto path = android::base::getEnvironmentVariable("ANDROID_EMU_VK_LOADER_PATH");
if (!path.empty()) {
@@ -156,7 +157,7 @@
// VK_MVK_moltenvk, which is required for external memory support.
if (!forTesting && androidIcd == "moltenvk") {
auto path = pj({directory, "lib64", "vulkan", "libMoltenVK.dylib"});
- LOG(VERBOSE) << "Skipping loader and using ICD directly: " << path;
+ // LOG(VERBOSE) << "Skipping loader and using ICD directly: " << path;
return path;
}
return "";