Merge ~b-stolk/chromium-browser/+git/snap-from-source:dynamic-nv12-test into ~chromium-team/chromium-browser/+git/snap-from-source:hwacc-dev

Proposed by Bram Stolk
Status: Merged
Merged at revision: 306f8cea55dd2cdf4bbcccb7357ecefb704c3b60
Proposed branch: ~b-stolk/chromium-browser/+git/snap-from-source:dynamic-nv12-test
Merge into: ~chromium-team/chromium-browser/+git/snap-from-source:hwacc-dev
Diff against target: 251 lines (+212/-5)
4 files modified
build/args.gn (+3/-2)
build/chromium-patches/af887ba.diff (+206/-0)
build/chromium-patches/series (+1/-0)
launcher/chromium.launcher (+2/-3)
Reviewer Review Type Date Requested Status
Nathan Teodosio Needs Fixing
Review via email: mp+436150@code.launchpad.net

Commit message

This is a patch that was sent to me by Intel to address the issue of webcams on non intel platforms and the use of the flag --video-capture-use-gpu-memory-buffer

It dynamically checks for nv12 support before using it.

Patch M107: https://chromium-review.googlesource.com/c/chromium/src/+/4179735
Patch main: https://chromium-review.googlesource.com/c/chromium/src/+/4167408

Description of the change

Addresses nv12 and non-intel platforms.

To post a comment you must log in.
Revision history for this message
Nathan Teodosio (nteodosio) :
review: Needs Fixing
Revision history for this message
Nathan Teodosio (nteodosio) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/build/args.gn b/build/args.gn
2index 06beeef..ae91a41 100644
3--- a/build/args.gn
4+++ b/build/args.gn
5@@ -34,6 +34,7 @@ target_os = "linux"
6 current_os = "linux"
7 proprietary_codecs = true
8 ffmpeg_branding = "Chrome"
9-use_system_minigbm = true
10-use_intel_minigbm = false
11+use_system_minigbm = false
12+use_intel_minigbm = true
13+use_amdgpu_minigbm = true
14 pkg_config = "/snap/gnome-3-38-2004/current/usr/bin/pkg-config"
15diff --git a/build/chromium-patches/af887ba.diff b/build/chromium-patches/af887ba.diff
16new file mode 100644
17index 0000000..8c74ace
18--- /dev/null
19+++ b/build/chromium-patches/af887ba.diff
20@@ -0,0 +1,206 @@
21+From af887ba502876aa590d1890b543ccebfa3db8566 Mon Sep 17 00:00:00 2001
22+From: Yaowei Zhou <yaowei.zhou@intel.com>
23+Date: Thu, 19 Jan 2023 16:30:25 +0800
24+Subject: [PATCH] Dynamic check NV12 format when enable the video capture use gpu memory ubffers
25+
26+Bug: N/A
27+Change-Id: I8ba75b3981ebb890662d2a3b3981c0578d0f6ec7
28+---
29+
30+diff --git a/content/browser/gpu/gpu_memory_buffer_manager_singleton.cc b/content/browser/gpu/gpu_memory_buffer_manager_singleton.cc
31+index 1899912..5a6a992 100644
32+--- a/content/browser/gpu/gpu_memory_buffer_manager_singleton.cc
33++++ b/content/browser/gpu/gpu_memory_buffer_manager_singleton.cc
34+@@ -22,6 +22,10 @@
35+ #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
36+ #endif
37+
38++#if BUILDFLAG(IS_LINUX)
39++#include "media/capture/capture_switches.h"
40++#endif
41++
42+ namespace content {
43+ namespace {
44+
45+@@ -53,6 +57,23 @@
46+ #endif
47+ }
48+
49++#if BUILDFLAG(IS_LINUX)
50++// Dynamic check NV12 format support as supported format inconsistent in
51++// system and chromium miniGBM
52++void DynamicUpdateVideoCaptureUseGpuMemoryBuffer(bool support_nv12) {
53++ if (base::CommandLine::ForCurrentProcess()->HasSwitch(
54++ switches::kDisableVideoCaptureUseGpuMemoryBuffer) ||
55++ !base::CommandLine::ForCurrentProcess()->HasSwitch(
56++ switches::kVideoCaptureUseGpuMemoryBuffer)) {
57++ return;
58++ }
59++
60++ if (!support_nv12) {
61++ base::CommandLine::ForCurrentProcess()->AppendSwitch(
62++ switches::kDisableVideoCaptureUseGpuMemoryBuffer);
63++ }
64++}
65++#endif // BUILDFLAG(IS_LINUX)
66+ } // namespace
67+
68+ GpuMemoryBufferManagerSingleton::GpuMemoryBufferManagerSingleton(int client_id)
69+@@ -80,6 +101,12 @@
70+ }
71+
72+ void GpuMemoryBufferManagerSingleton::OnGpuExtraInfoUpdate() {
73++#if BUILDFLAG(IS_LINUX) && \
74++ (BUILDFLAG(OZONE_PLATFORM_X11) || BUILDFLAG(OZONE_PLATFORM_WAYLAND))
75++ DynamicUpdateVideoCaptureUseGpuMemoryBuffer(
76++ gpu_data_manager_impl_->GetGpuExtraInfo().gpu_memory_buffer_support_NV12);
77++#endif
78++
79+ #if defined(USE_OZONE_PLATFORM_X11)
80+ // X11 fetches buffer formats on gpu and passes them via gpu extra info.
81+ if (!ShouldSetBufferFormatsFromGpuExtraInfo())
82+diff --git a/ui/gfx/gpu_extra_info.h b/ui/gfx/gpu_extra_info.h
83+index e8fa594..d1edbfea 100644
84+--- a/ui/gfx/gpu_extra_info.h
85++++ b/ui/gfx/gpu_extra_info.h
86+@@ -65,6 +65,10 @@
87+ #if defined(USE_OZONE_PLATFORM_X11)
88+ std::vector<gfx::BufferUsageAndFormat> gpu_memory_buffer_support_x11;
89+ #endif
90++#if BUILDFLAG(IS_LINUX) && \
91++ (BUILDFLAG(OZONE_PLATFORM_X11) || BUILDFLAG(OZONE_PLATFORM_WAYLAND))
92++ bool gpu_memory_buffer_support_NV12;
93++#endif
94+ };
95+
96+ } // namespace gfx
97+diff --git a/ui/gfx/mojom/BUILD.gn b/ui/gfx/mojom/BUILD.gn
98+index 37b984d..4921b84 100644
99+--- a/ui/gfx/mojom/BUILD.gn
100++++ b/ui/gfx/mojom/BUILD.gn
101+@@ -50,7 +50,9 @@
102+ if (ozone_platform_x11) {
103+ enabled_features += [ "enable_x11_params" ]
104+ }
105+-
106++ if (is_linux && (ozone_platform_x11 || ozone_platform_wayland)) {
107++ enabled_features += [ "enable_nv12_params" ]
108++ }
109+ shared_cpp_typemaps = [
110+ {
111+ types = [
112+diff --git a/ui/gfx/mojom/gpu_extra_info.mojom b/ui/gfx/mojom/gpu_extra_info.mojom
113+index 3de1c579..6d724c2b 100644
114+--- a/ui/gfx/mojom/gpu_extra_info.mojom
115++++ b/ui/gfx/mojom/gpu_extra_info.mojom
116+@@ -24,4 +24,7 @@
117+
118+ [EnableIf=enable_x11_params]
119+ array<gfx.mojom.BufferUsageAndFormat> gpu_memory_buffer_support_x11;
120++
121++ [EnableIf=enable_nv12_params]
122++ bool gpu_memory_buffer_support_NV12;
123+ };
124+diff --git a/ui/gfx/mojom/gpu_extra_info_mojom_traits.cc b/ui/gfx/mojom/gpu_extra_info_mojom_traits.cc
125+index 15c7340..9add661 100644
126+--- a/ui/gfx/mojom/gpu_extra_info_mojom_traits.cc
127++++ b/ui/gfx/mojom/gpu_extra_info_mojom_traits.cc
128+@@ -28,6 +28,10 @@
129+ if (!data.ReadGpuMemoryBufferSupportX11(&out->gpu_memory_buffer_support_x11))
130+ return false;
131+ #endif
132++#if BUILDFLAG(IS_LINUX) && \
133++ (BUILDFLAG(OZONE_PLATFORM_X11) || BUILDFLAG(OZONE_PLATFORM_WAYLAND))
134++ out->gpu_memory_buffer_support_NV12 = data.gpu_memory_buffer_support_NV12();
135++#endif
136+ return true;
137+ }
138+
139+diff --git a/ui/gfx/mojom/gpu_extra_info_mojom_traits.h b/ui/gfx/mojom/gpu_extra_info_mojom_traits.h
140+index 12b616f..7c908bf 100644
141+--- a/ui/gfx/mojom/gpu_extra_info_mojom_traits.h
142++++ b/ui/gfx/mojom/gpu_extra_info_mojom_traits.h
143+@@ -68,6 +68,12 @@
144+ return input.gpu_memory_buffer_support_x11;
145+ }
146+ #endif
147++#if BUILDFLAG(IS_LINUX) && \
148++ (BUILDFLAG(OZONE_PLATFORM_X11) || BUILDFLAG(OZONE_PLATFORM_WAYLAND))
149++ static bool gpu_memory_buffer_support_NV12(const gfx::GpuExtraInfo& input) {
150++ return input.gpu_memory_buffer_support_NV12;
151++ }
152++#endif
153+ };
154+
155+ } // namespace mojo
156+diff --git a/ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.cc b/ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.cc
157+index b3e92d8..ee165fe 100644
158+--- a/ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.cc
159++++ b/ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.cc
160+@@ -5,6 +5,11 @@
161+ #include "ui/ozone/platform/wayland/gpu/wayland_gl_egl_utility.h"
162+
163+ #include "base/containers/contains.h"
164++#if BUILDFLAG(IS_LINUX)
165++#include "ui/gfx/native_pixmap.h"
166++#include "ui/ozone/public/ozone_platform.h"
167++#include "ui/ozone/public/surface_factory_ozone.h"
168++#endif // BUILDFLAG(IS_LINUX)
169+
170+ // From ANGLE's egl/eglext.h. Follows the same approach as in
171+ // ui/gl/gl_surface_egl.cc
172+@@ -74,7 +79,23 @@
173+
174+ void WaylandGLEGLUtility::CollectGpuExtraInfo(
175+ bool enable_native_gpu_memory_buffers,
176+- gfx::GpuExtraInfo& gpu_extra_info) const {}
177++ gfx::GpuExtraInfo& gpu_extra_info) const {
178++#if BUILDFLAG(IS_LINUX)
179++ if (!enable_native_gpu_memory_buffers) {
180++ gpu_extra_info.gpu_memory_buffer_support_NV12 = false;
181++ return;
182++ }
183++ scoped_refptr<gfx::NativePixmap> pixmap;
184++ pixmap = ui::OzonePlatform::GetInstance()
185++ ->GetSurfaceFactoryOzone()
186++ ->CreateNativePixmap(gfx::kNullAcceleratedWidget, nullptr,
187++ gfx::Size(2, 2),
188++ gfx::BufferFormat::YUV_420_BIPLANAR,
189++ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE);
190++
191++ gpu_extra_info.gpu_memory_buffer_support_NV12 = !!pixmap;
192++#endif // BUILDFLAG(IS_LINUX)
193++}
194+
195+ bool WaylandGLEGLUtility::X11DoesVisualHaveAlphaForTest() const {
196+ return false;
197+diff --git a/ui/ozone/platform/x11/gl_egl_utility_x11.cc b/ui/ozone/platform/x11/gl_egl_utility_x11.cc
198+index 58c7fe6..0eb5608 100644
199+--- a/ui/ozone/platform/x11/gl_egl_utility_x11.cc
200++++ b/ui/ozone/platform/x11/gl_egl_utility_x11.cc
201+@@ -12,6 +12,10 @@
202+ #include "ui/gl/gl_implementation.h"
203+ #include "ui/gl/gl_utils.h"
204+
205++#if BUILDFLAG(IS_LINUX)
206++#include "base/ranges/algorithm.h"
207++#endif
208++
209+ namespace ui {
210+
211+ GLEGLUtilityX11::GLEGLUtilityX11() = default;
212+@@ -45,6 +49,14 @@
213+ // ANGLE does not yet support EGL_EXT_image_dma_buf_import[_modifiers].
214+ gpu_extra_info.gpu_memory_buffer_support_x11.clear();
215+ }
216++#if BUILDFLAG(IS_LINUX)
217++ gpu_extra_info.gpu_memory_buffer_support_NV12 = base::ranges::any_of(
218++ ui::GpuMemoryBufferSupportX11::GetInstance()->supported_configs(),
219++ [](gfx::BufferUsageAndFormat other) {
220++ return other.format == gfx::BufferFormat::YUV_420_BIPLANAR &&
221++ other.usage == gfx::BufferUsage::GPU_READ_CPU_READ_WRITE;
222++ });
223++#endif
224+ }
225+
226+ bool GLEGLUtilityX11::X11DoesVisualHaveAlphaForTest() const {
227diff --git a/build/chromium-patches/series b/build/chromium-patches/series
228index 373ea12..5517f2b 100644
229--- a/build/chromium-patches/series
230+++ b/build/chromium-patches/series
231@@ -31,3 +31,4 @@ dont-collect-motherboard-metrics.patch
232 4ed5da1.diff
233 40002f9.diff
234 linker-oom-armhf.patch
235+af887ba.diff
236diff --git a/launcher/chromium.launcher b/launcher/chromium.launcher
237index e366d6a..4c79460 100755
238--- a/launcher/chromium.launcher
239+++ b/launcher/chromium.launcher
240@@ -113,9 +113,8 @@ fi
241 # Add necessary flags for VAAPI video en/decoding
242 CHROMIUM_VAAPI_FLAGS='--enable-features=VaapiVideoDecoder,VaapiVideoEncoder --disable-features=UseChromeOSDirectVideoDecoder --use-gl=egl --video-capture-use-external-dma-buffer'
243
244-# The following flag should only be used on Intel GPUs, and when the binary was built with intel minigbm.
245-# Which means we have to leave it out for now.
246-#CHROMIUM_VAAPI_FLAGS="--video-capture-use-gpu-memory-buffer $CHROMIUM_VAAPI_FLAGS"
247+# With the patch for dynamic NV12 support detection, this should now be safe on non-Intel platforms.
248+CHROMIUM_VAAPI_FLAGS="--video-capture-use-gpu-memory-buffer $CHROMIUM_VAAPI_FLAGS"
249
250 if [ -n "$WAYLAND_DISPLAY" ]; then
251 CHROMIUM_VAAPI_FLAGS="--ozone-platform=wayland $CHROMIUM_VAAPI_FLAGS"

Subscribers

People subscribed via source and target branches

to status/vote changes: