$OpenBSD: patch-src_3rdparty_chromium_content_gpu_gpu_main_cc,v 1.2 2021/01/19 06:16:34 rsadowski Exp $

Index: src/3rdparty/chromium/content/gpu/gpu_main.cc
--- src/3rdparty/chromium/content/gpu/gpu_main.cc.orig
+++ src/3rdparty/chromium/content/gpu/gpu_main.cc
@@ -84,7 +84,7 @@
 #include "ui/gfx/x/x11_switches.h"                       // nogncheck
 #endif
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
 #include "content/gpu/gpu_sandbox_hook_linux.h"
 #include "content/public/common/sandbox_init.h"
 #include "services/service_manager/sandbox/linux/sandbox_linux.h"
@@ -109,7 +109,7 @@ namespace content {
 
 namespace {
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
 bool StartSandboxLinux(gpu::GpuWatchdogThread*,
                        const gpu::GPUInfo*,
                        const gpu::GpuPreferences&);
@@ -162,7 +162,7 @@ class ContentSandboxHelper : public gpu::GpuSandboxHel
   bool EnsureSandboxInitialized(gpu::GpuWatchdogThread* watchdog_thread,
                                 const gpu::GPUInfo* gpu_info,
                                 const gpu::GpuPreferences& gpu_prefs) override {
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
     return StartSandboxLinux(watchdog_thread, gpu_info, gpu_prefs);
 #elif defined(OS_WIN)
     return StartSandboxWindows(sandbox_info_);
@@ -312,7 +312,7 @@ int GpuMain(const MainFunctionParams& parameters) {
 
   base::PlatformThread::SetName("CrGpuMain");
 
-#if !defined(OS_MACOSX)
+#if !defined(OS_MACOSX) && !defined(OS_BSD)
   if (base::FeatureList::IsEnabled(features::kGpuUseDisplayThreadPriority)) {
     // Set thread priority before sandbox initialization.
     base::PlatformThread::SetCurrentThreadPriority(
@@ -332,6 +332,11 @@ int GpuMain(const MainFunctionParams& parameters) {
   // before it.
   InitializeSkia();
 
+  // pledge(2)
+ //#if defined(OS_BSD)
+ //  ui::GpuMemoryBufferSupportX11::GetInstance();
+ //#endif
+
   // Gpu initialization may fail for various reasons, in which case we will need
   // to tear down this process. However, we can not do so safely until the IPC
   // channel is set up, because the detection of early return of a child process
@@ -361,7 +366,9 @@ int GpuMain(const MainFunctionParams& parameters) {
   GpuProcess gpu_process(io_thread_priority);
 #endif
 
-#if defined(USE_X11)
+  // ^^^^^^^^^^^^^^^^^^^^^^
+  // moved up due to pledge(2)
+#if defined(USE_X11) && !defined(OS_BSD)
   // ui::GbmDevice() takes >50ms with amdgpu, so kick off
   // GpuMemoryBufferSupportX11 creation on another thread now.
   base::PostTask(
@@ -436,17 +443,19 @@ int GpuMain(const MainFunctionParams& parameters) {
 
 namespace {
 
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
 bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdog_thread,
                        const gpu::GPUInfo* gpu_info,
                        const gpu::GpuPreferences& gpu_prefs) {
   TRACE_EVENT0("gpu,startup", "Initialize sandbox");
 
+#if !defined(OS_BSD)
   if (watchdog_thread) {
     // SandboxLinux needs to be able to ensure that the thread
     // has really been stopped.
     service_manager::SandboxLinux::GetInstance()->StopThread(watchdog_thread);
   }
+#endif
 
   // SandboxLinux::InitializeSandbox() must always be called
   // with only one thread.
@@ -465,11 +474,13 @@ bool StartSandboxLinux(gpu::GpuWatchdogThread* watchdo
           *base::CommandLine::ForCurrentProcess()),
       base::BindOnce(GpuProcessPreSandboxHook), sandbox_options);
 
+#if !defined(OS_BSD)
   if (watchdog_thread) {
     base::Thread::Options thread_options;
     thread_options.timer_slack = base::TIMER_SLACK_MAXIMUM;
     watchdog_thread->StartWithOptions(thread_options);
   }
+#endif
 
   return res;
 }
