From 879a9d218361d6fd4a2b6c323f526507a6307976 Mon Sep 17 00:00:00 2001 From: Matt Gajownik Date: Sun, 28 Apr 2024 21:34:22 +1000 Subject: [PATCH] Enable building with CEF 6367 This allows compiling OBS Browser with Chromium 124-based CEF versions. This also enables basic support for the new, official, shared texture API, purely because building without it would be *more* difficult. Sources: - https://bitbucket.org/chromiumembedded/cef/commits/260dd0ca2 --- browser-client.cpp | 22 ++++++++++++++++++++-- browser-client.hpp | 12 ++++++++---- obs-browser-source.cpp | 2 +- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/browser-client.cpp b/browser-client.cpp index d91ca7024..1c0ca264e 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -373,7 +373,11 @@ void BrowserClient::UpdateExtraTexture() void BrowserClient::OnAcceleratedPaint(CefRefPtr, PaintElementType type, const RectList &, +#if CHROME_VERSION_BUILD >= 6367 + const CefAcceleratedPaintInfo &info) +#else void *shared_handle) +#endif { if (type != PET_VIEW) { // TODO Overlay texture on top of bs->texture @@ -384,7 +388,7 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, return; } -#ifndef _WIN32 +#if !defined(_WIN32) && CHROME_VERSION_BUILD < 6367 if (shared_handle == bs->last_handle) return; #endif @@ -399,12 +403,20 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, bs->texture = nullptr; } -#if defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 +#if defined(__APPLE__) && CHROME_VERSION_BUILD > 6367 + bs->texture = gs_texture_create_from_iosurface( + (IOSurfaceRef)(uintptr_t)info.shared_texture_io_surface); +#elif defined(__APPLE__) && CHROME_VERSION_BUILD > 4183 bs->texture = gs_texture_create_from_iosurface( (IOSurfaceRef)(uintptr_t)shared_handle); #elif defined(_WIN32) && CHROME_VERSION_BUILD > 4183 bs->texture = +#if CHROME_VERSION_BUILD >= 6367 + gs_texture_open_nt_shared( + (uint32_t)(uintptr_t)info.shared_texture_handle); +#else gs_texture_open_nt_shared((uint32_t)(uintptr_t)shared_handle); +#endif //if (bs->texture) // gs_texture_acquire_sync(bs->texture, 1, INFINITE); @@ -415,7 +427,13 @@ void BrowserClient::OnAcceleratedPaint(CefRefPtr, UpdateExtraTexture(); obs_leave_graphics(); +#if defined(__APPLE__) && CHROME_VERSION_BUILD >= 6367 + bs->last_handle = info.shared_texture_io_surface; +#elif CHROME_VERSION_BUILD >= 6367 + bs->last_handle = info.shared_texture_handle; +#else bs->last_handle = shared_handle; +#endif } #ifdef CEF_ON_ACCELERATED_PAINT2 diff --git a/browser-client.hpp b/browser-client.hpp index cbff1201e..36dd5d89c 100644 --- a/browser-client.hpp +++ b/browser-client.hpp @@ -135,10 +135,14 @@ class BrowserClient : public CefClient, const void *buffer, int width, int height) override; #ifdef ENABLE_BROWSER_SHARED_TEXTURE - virtual void OnAcceleratedPaint(CefRefPtr browser, - PaintElementType type, - const RectList &dirtyRects, - void *shared_handle) override; + virtual void + OnAcceleratedPaint(CefRefPtr browser, PaintElementType type, + const RectList &dirtyRects, +#if CHROME_VERSION_BUILD >= 6367 + const CefAcceleratedPaintInfo &info) override; +#else + void *shared_handle) override; +#endif #ifdef CEF_ON_ACCELERATED_PAINT2 virtual void OnAcceleratedPaint2(CefRefPtr browser, PaintElementType type, diff --git a/obs-browser-source.cpp b/obs-browser-source.cpp index 09b301718..258bbcd86 100644 --- a/obs-browser-source.cpp +++ b/obs-browser-source.cpp @@ -658,7 +658,7 @@ extern void ProcessCef(); void BrowserSource::Render() { bool flip = false; -#ifdef ENABLE_BROWSER_SHARED_TEXTURE +#if defined(ENABLE_BROWSER_SHARED_TEXTURE) && CHROME_VERSION_BUILD < 6367 flip = hwaccel; #endif