瀏覽代碼

libobs: Add texture sharing support for macOS/OpenGL

PatTheMav 4 年之前
父節點
當前提交
61ea6e0247

+ 1 - 1
.github/workflows/main.yml

@@ -121,7 +121,7 @@ jobs:
         if: steps.cef-cache.outputs.cache-hit != 'true'
         shell: bash
         run: |
-          curl -L -O https://obs-nightly.s3-us-west-2.amazonaws.com/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64.tar.bz2
+          curl -L -O https://cdn-fastly.obsproject.com/downloads/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64.tar.bz2
           tar -xf ./cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64.tar.bz2 -C ${{ github.workspace }}/cmbuild/
           cd ${{ github.workspace }}/cmbuild/cef_binary_${{ env.CEF_BUILD_VERSION }}_macosx64
           sed -i '.orig' '/add_subdirectory(tests\/ceftests)/d' ./CMakeLists.txt

+ 2 - 2
CI/full-build-macos.sh

@@ -212,13 +212,13 @@ install_cef() {
     hr "Building dependency CEF v${1}"
     ensure_dir ${DEPS_BUILD_DIR}
     step "Download..."
-    ${CURLCMD} --progress-bar -L -C - -O https://obs-nightly.s3-us-west-2.amazonaws.com/cef_binary_${1}_macosx64.tar.bz2
+    ${CURLCMD} --progress-bar -L -C - -O https://cdn-fastly.obsproject.com/downloads/cef_binary_${1}_macosx64.tar.bz2
     step "Unpack..."
     tar -xf ./cef_binary_${1}_macosx64.tar.bz2
     cd ./cef_binary_${1}_macosx64
     step "Fix tests..."
     sed -i '.orig' '/add_subdirectory(tests\/ceftests)/d' ./CMakeLists.txt
-    sed -i '.orig' s/\"10.9\"/\"${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}}\"/ ./cmake/cef_variables.cmake
+    sed -i '.orig' 's/"'$(test "${CEF_BUILD_VERSION:-${CI_CEF_VERSION}}" -le 3770 && echo "10.9" || echo "10.10")'"/"'${MIN_MACOS_VERSION:-${CI_MIN_MACOS_VERSION}}'"/' ./cmake/cef_variables.cmake
     ensure_dir ./build
     step "Run CMAKE..."
     cmake \

+ 15 - 1
libobs-opengl/gl-cocoa.m

@@ -339,7 +339,7 @@ gs_texture_t *device_texture_create_from_iosurface(gs_device_t *device,
 	tex->base.gl_format = convert_gs_format(color_format);
 	tex->base.gl_internal_format = convert_gs_internal_format(color_format);
 	tex->base.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-	tex->base.gl_target = GL_TEXTURE_RECTANGLE;
+	tex->base.gl_target = GL_TEXTURE_RECTANGLE_ARB;
 	tex->base.is_dynamic = false;
 	tex->base.is_render_target = false;
 	tex->base.gen_mipmaps = false;
@@ -381,6 +381,20 @@ fail:
 	return NULL;
 }
 
+gs_texture_t *device_texture_open_shared(gs_device_t *device, uint32_t handle)
+{
+	gs_texture_t *texture = NULL;
+	IOSurfaceRef ref = IOSurfaceLookupFromMachPort((mach_port_t)handle);
+	texture = device_texture_create_from_iosurface(device, ref);
+	CFRelease(ref);
+	return texture;
+}
+
+bool device_shared_texture_available(void)
+{
+	return true;
+}
+
 bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
 {
 	if (!texture)

+ 2 - 0
libobs/graphics/graphics-imports.c

@@ -193,6 +193,8 @@ bool load_graphics_imports(struct gs_exports *exports, void *module,
 
 	/* OSX/Cocoa specific functions */
 #ifdef __APPLE__
+	GRAPHICS_IMPORT(device_shared_texture_available);
+	GRAPHICS_IMPORT_OPTIONAL(device_texture_open_shared);
 	GRAPHICS_IMPORT_OPTIONAL(device_texture_create_from_iosurface);
 	GRAPHICS_IMPORT_OPTIONAL(gs_texture_rebind_iosurface);
 

+ 3 - 0
libobs/graphics/graphics-internal.h

@@ -271,8 +271,11 @@ struct gs_exports {
 	/* OSX/Cocoa specific functions */
 	gs_texture_t *(*device_texture_create_from_iosurface)(gs_device_t *dev,
 							      void *iosurf);
+	gs_texture_t *(*device_texture_open_shared)(gs_device_t *dev,
+						    uint32_t *handle);
 	bool (*gs_texture_rebind_iosurface)(gs_texture_t *texture,
 					    void *iosurf);
+	bool (*device_shared_texture_available)(void);
 
 #elif _WIN32
 	bool (*device_gdi_texture_available)(void);

+ 20 - 0
libobs/graphics/graphics.c

@@ -2756,6 +2756,26 @@ bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf)
 	return graphics->exports.gs_texture_rebind_iosurface(texture, iosurf);
 }
 
+bool gs_shared_texture_available(void)
+{
+	if (!gs_valid("gs_shared_texture_available"))
+		return false;
+
+	return thread_graphics->exports.device_shared_texture_available();
+}
+
+gs_texture_t *gs_texture_open_shared(uint32_t handle)
+{
+	graphics_t *graphics = thread_graphics;
+	if (!gs_valid("gs_texture_open_shared"))
+		return NULL;
+
+	if (graphics->exports.device_texture_open_shared)
+		return graphics->exports.device_texture_open_shared(
+			graphics->device, handle);
+	return NULL;
+}
+
 #elif _WIN32
 
 bool gs_gdi_texture_available(void)

+ 2 - 0
libobs/graphics/graphics.h

@@ -831,6 +831,8 @@ EXPORT void gs_debug_marker_end(void);
  * from shared surface resources */
 EXPORT gs_texture_t *gs_texture_create_from_iosurface(void *iosurf);
 EXPORT bool gs_texture_rebind_iosurface(gs_texture_t *texture, void *iosurf);
+EXPORT gs_texture_t *gs_texture_open_shared(uint32_t handle);
+EXPORT bool gs_shared_texture_available(void);
 
 #elif _WIN32