cef/patch/patches/osr_win_remove_keyed_mutex_2575.patch
reito 260dd0ca24 osr: Implement shared texture support (fixes #1006, fixes #2575)
Adds support for the OnAcceleratedPaint callback. Verified to work
on macOS and Windows. Linux support is present but not implemented
for cefclient, so it is not verified to work.

To test:
Run `cefclient --off-screen-rendering-enabled --shared-texture-enabled`
2024-04-23 13:03:56 -04:00

72 lines
3.5 KiB
Diff

diff --git gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
index ecabd51db586d..a7ae5e101ca02 100644
--- gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
+++ gpu/ipc/service/gpu_memory_buffer_factory_dxgi.cc
@@ -174,7 +174,8 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer(
// so make sure that the usage is one that we support.
DCHECK(usage == gfx::BufferUsage::GPU_READ ||
usage == gfx::BufferUsage::SCANOUT ||
- usage == gfx::BufferUsage::SCANOUT_CPU_READ_WRITE)
+ usage == gfx::BufferUsage::SCANOUT_CPU_READ_WRITE ||
+ usage == gfx::BufferUsage::SCANOUT_VEA_CPU_READ)
<< "Incorrect usage, usage=" << gfx::BufferUsageToString(usage);
D3D11_TEXTURE2D_DESC desc = {
@@ -188,7 +189,9 @@ gfx::GpuMemoryBufferHandle GpuMemoryBufferFactoryDXGI::CreateGpuMemoryBuffer(
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET,
0,
D3D11_RESOURCE_MISC_SHARED_NTHANDLE |
- D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX};
+ static_cast<UINT>(usage == gfx::BufferUsage::SCANOUT_VEA_CPU_READ
+ ? D3D11_RESOURCE_MISC_SHARED
+ : D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)};
Microsoft::WRL::ComPtr<ID3D11Texture2D> d3d11_texture;
diff --git media/video/renderable_gpu_memory_buffer_video_frame_pool.cc media/video/renderable_gpu_memory_buffer_video_frame_pool.cc
index 15b1d849d27cd..4887e6482b0f6 100644
--- media/video/renderable_gpu_memory_buffer_video_frame_pool.cc
+++ media/video/renderable_gpu_memory_buffer_video_frame_pool.cc
@@ -205,7 +205,7 @@ gfx::Size GetBufferSizeInPixelsForVideoPixelFormat(
bool FrameResources::Initialize() {
auto* context = pool_->GetContext();
- constexpr gfx::BufferUsage kBufferUsage =
+ gfx::BufferUsage buffer_usage =
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
gfx::BufferUsage::SCANOUT_VEA_CPU_READ
#else
@@ -219,13 +219,30 @@ bool FrameResources::Initialize() {
const gfx::Size buffer_size_in_pixels =
GetBufferSizeInPixelsForVideoPixelFormat(format_, coded_size_);
+#if BUILDFLAG(IS_WIN)
+ // For CEF OSR feature, currently there's no other place in chromium use RGBA.
+ // If the format is RGBA, currently CEF do not write to the texture anymore
+ // once the GMB is returned from CopyRequest. So there will be no race
+ // condition on that texture. We can request a GMB without a keyed mutex to
+ // accelerate and probably prevent some driver deadlock.
+ if (format_ == PIXEL_FORMAT_ARGB) {
+ // This value is 'borrowed', SCANOUT_VEA_CPU_READ is probably invalid
+ // cause there's no real SCANOUT on Windows. We simply use this enum as a
+ // flag to disable mutex in the GMBFactoryDXGI because this enum is also
+ // used above in macOS and CrOS for similar usage (claim no other one will
+ // concurrently use the resource).
+ // https://chromium-review.googlesource.com/c/chromium/src/+/5302103
+ buffer_usage = gfx::BufferUsage::SCANOUT_VEA_CPU_READ;
+ }
+#endif
+
// Create the GpuMemoryBuffer.
gpu_memory_buffer_ = context->CreateGpuMemoryBuffer(
- buffer_size_in_pixels, buffer_format, kBufferUsage);
+ buffer_size_in_pixels, buffer_format, buffer_usage);
if (!gpu_memory_buffer_) {
DLOG(ERROR) << "Failed to allocate GpuMemoryBuffer for frame: coded_size="
<< coded_size_.ToString()
- << ", usage=" << static_cast<int>(kBufferUsage);
+ << ", usage=" << static_cast<int>(buffer_usage);
return false;
}