use mesa to get the gpu vendor and device id and pass it to chromium because

we can't use libpci due to permission restrictions and use some more UI code
on BSD as well
This commit is contained in:
robert 2015-02-15 19:51:28 +00:00
parent b59c85629c
commit b3e9f10830
18 changed files with 371 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.200 2015/02/12 07:38:09 robert Exp $
# $OpenBSD: Makefile,v 1.201 2015/02/15 19:51:28 robert Exp $
ONLY_FOR_ARCHS= i386 amd64
DPB_PROPERTIES= parallel
@ -7,6 +7,7 @@ COMMENT= Chromium browser
V= 40.0.2214.114
DISTNAME= chromium-${V}
REVISION= 0
CATEGORIES= www
@ -157,10 +158,13 @@ do-configure:
do-build:
@cd ${WRKSRC} && env -i ${MAKE_ENV} ninja \
-j ${MAKE_JOBS} -C out/${BUILDTYPE} ${ALL_TARGET}
${CC} ${CLAGS} -o ${BUILDDIR}/gpuid -I${X11BASE}/include \
-L${X11BASE}/lib ${FILESDIR}/gpuid.c -lGL
do-install:
${INSTALL_DATA_DIR} ${PREFIX}/chrome
${INSTALL_PROGRAM} ${BUILDDIR}/chrome ${PREFIX}/chrome
${INSTALL_PROGRAM} ${BUILDDIR}/gpuid ${PREFIX}/chrome
${SUBST_PROGRAM} ${FILESDIR}/chrome ${PREFIX}/bin/chrome
${INSTALL_MAN} ${BUILDDIR}/chrome.1 ${PREFIX}/man/man1

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $OpenBSD: chrome,v 1.11 2014/07/20 17:23:34 robert Exp $
# $OpenBSD: chrome,v 1.12 2015/02/15 19:51:28 robert Exp $
DATASIZE="716800"
OPENFILES="400"
@ -40,4 +40,6 @@ fi
#
[ -z ${LANG} ] && _l=en_US.UTF-8 || _l=${LANG}
eval `/usr/local/chrome/gpuid`
LANG=${_l} exec "/usr/local/chrome/chrome" "${@}"

View File

@ -0,0 +1,86 @@
#include <GL/glx.h>
#include <stdio.h>
#include <string.h>
int
main(int argc, char *argv[])
{
Display *dpy;
int scrnum = 0;
Window win;
XSetWindowAttributes attr;
Window root;
GLXContext ctx = NULL;
XVisualInfo *visinfo;
unsigned int vendor_id = 0x0000;
unsigned int device_id = 0x0000;
int attribSingle[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
None };
int attribDouble[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None };
dpy = XOpenDisplay(NULL);
if (!dpy)
goto exit;
root = RootWindow(dpy, scrnum);
visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
if (!visinfo)
visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
if (visinfo)
ctx = glXCreateContext(dpy, visinfo, NULL, False);
if (!ctx)
goto exit0;
attr.background_pixel = attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
win = XCreateWindow(dpy, root, 0, 0, 100, 100,
0, visinfo->depth, InputOutput,
visinfo->visual, CWBackPixel | CWBorderPixel | CWColormap | CWEventMask,
&attr);
if (glXMakeCurrent(dpy, win, ctx)) {
const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
unsigned int v [3];
PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC queryInteger;
queryInteger = (PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC)
glXGetProcAddressARB((const GLubyte *)
"glXQueryCurrentRendererIntegerMESA");
if (!glXQueryVersion(dpy, NULL, NULL)) {
goto exit1;
}
if (strstr(glxExtensions, "GLX_MESA_query_renderer")) {
queryInteger(GLX_RENDERER_VENDOR_ID_MESA, v);
vendor_id = *v;
queryInteger(GLX_RENDERER_DEVICE_ID_MESA, v);
device_id = *v;
}
}
exit1:
XDestroyWindow(dpy, win);
glXDestroyContext(dpy, ctx);
exit0:
XFree(visinfo);
XSync(dpy, 1);
exit:
printf("OPENBSD_GPU_VENDOR='0x%04x';\n", vendor_id);
printf("export OPENBSD_GPU_VENDOR;\n");
printf("OPENBSD_GPU_DEVICE='0x%04x';\n", device_id);
printf("export OPENBSD_GPU_DEVICE;\n");
XCloseDisplay(dpy);
return 0;
}

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-base_memory_ref_counted_h,v 1.1 2015/02/15 19:51:28 robert Exp $
--- base/memory/ref_counted.h.orig.port Sun Feb 15 19:32:22 2015
+++ base/memory/ref_counted.h Sun Feb 15 19:32:30 2015
@@ -17,7 +17,7 @@
#include "base/threading/thread_collision_warner.h"
#include "build/build_config.h"
-#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_ANDROID)
+#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_IOS) || defined(OS_ANDROID) || defined(OS_BSD)
#define DISABLE_SCOPED_REFPTR_CONVERSION_OPERATOR
#endif

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-base_message_loop_message_loop_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- base/message_loop/message_loop.cc.orig.port Sun Feb 15 19:35:19 2015
+++ base/message_loop/message_loop.cc Sun Feb 15 19:34:32 2015
@@ -222,7 +222,7 @@ scoped_ptr<MessagePump> MessageLoop::CreateMessagePump
// TODO(rvargas): Get rid of the OS guards.
#if defined(USE_GLIB) && !defined(OS_NACL)
typedef MessagePumpGlib MessagePumpForUI;
-#elif defined(OS_LINUX) && !defined(OS_NACL)
+#elif defined(OS_BSD) && !defined(OS_NACL)
typedef MessagePumpLibevent MessagePumpForUI;
#endif

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-cc_resources_raster_worker_pool_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- cc/resources/raster_worker_pool.cc.orig.port Sun Feb 15 20:21:13 2015
+++ cc/resources/raster_worker_pool.cc Sun Feb 15 20:21:24 2015
@@ -32,7 +32,7 @@ class RasterTaskGraphRunner : public TaskGraphRunner,
static_cast<unsigned>(workers_.size() + 1))
.c_str()));
worker->Start();
-#if defined(OS_ANDROID) || defined(OS_LINUX)
+#if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_BSD)
worker->SetThreadPriority(base::kThreadPriority_Background);
#endif
workers_.push_back(worker.Pass());

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-chrome_browser_download_chrome_download_manager_delegate_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- chrome/browser/download/chrome_download_manager_delegate.cc.orig.port Sun Feb 15 11:06:29 2015
+++ chrome/browser/download/chrome_download_manager_delegate.cc Sun Feb 15 11:06:44 2015
@@ -719,7 +719,7 @@ void ChromeDownloadManagerDelegate::OnDownloadTargetDe
bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile(
const base::FilePath& path) {
-#if defined(OS_WIN) || defined(OS_LINUX) || \
+#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_BSD) || \
(defined(OS_MACOSX) && !defined(OS_IOS))
if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) {
return !download_prefs_->ShouldOpenPdfInSystemReader();

View File

@ -1,6 +1,15 @@
$OpenBSD: patch-chrome_browser_ui_aura_chrome_browser_main_extra_parts_aura_cc,v 1.3 2014/11/19 21:27:32 robert Exp $
--- chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc.orig.port Wed Nov 19 06:13:08 2014
+++ chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc Wed Nov 19 08:38:25 2014
$OpenBSD: patch-chrome_browser_ui_aura_chrome_browser_main_extra_parts_aura_cc,v 1.4 2015/02/15 19:51:28 robert Exp $
--- chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc.orig.port Wed Feb 11 08:15:34 2015
+++ chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.cc Sun Feb 15 11:05:48 2015
@@ -68,7 +68,7 @@ chrome::HostDesktopType GetInitialDesktop() {
command_line->HasSwitch(switches::kViewerLaunchViaAppId)) {
return chrome::HOST_DESKTOP_TYPE_ASH;
}
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kOpenAsh))
return chrome::HOST_DESKTOP_TYPE_ASH;
@@ -128,7 +128,7 @@ void ChromeBrowserMainExtraPartsAura::PreCreateThreads
}

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-chrome_browser_ui_browser_cc,v 1.6 2015/02/15 19:51:28 robert Exp $
--- chrome/browser/ui/browser.cc.orig.port Sun Feb 15 11:09:25 2015
+++ chrome/browser/ui/browser.cc Sun Feb 15 11:09:31 2015
@@ -1258,7 +1258,7 @@ void Browser::OnWindowDidShow() {
window_has_shown_ = true;
// CurrentProcessInfo::CreationTime() is missing on some platforms.
-#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX)
+#if defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_LINUX) || defined(OS_BSD)
// Measure the latency from startup till the first browser window becomes
// visible.
static bool is_first_browser_window = true;

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-chrome_browser_ui_webui_chrome_web_ui_controller_factory_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc.orig.port Sun Feb 15 11:08:46 2015
+++ chrome/browser/ui/webui/chrome_web_ui_controller_factory.cc Sun Feb 15 11:08:59 2015
@@ -484,7 +484,7 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* we
#endif // defined(ENABLE_CONFIGURATION_POLICY)
-#if (defined(OS_LINUX) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA)
+#if ((defined(OS_LINUX) || defined(OS_BSD)) && defined(TOOLKIT_VIEWS)) || defined(USE_AURA)
if (url.host() == chrome::kChromeUITabModalConfirmDialogHost) {
return &NewWebUI<ConstrainedWebDialogUI>;
}

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-chrome_common_extensions_command_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- chrome/common/extensions/command.cc.orig.port Sun Feb 15 19:23:46 2015
+++ chrome/common/extensions/command.cc Sun Feb 15 19:25:17 2015
@@ -298,7 +298,7 @@ std::string Command::CommandPlatform() {
return values::kKeybindingPlatformMac;
#elif defined(OS_CHROMEOS)
return values::kKeybindingPlatformChromeOs;
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
return values::kKeybindingPlatformLinux;
#else
return "";

View File

@ -0,0 +1,30 @@
$OpenBSD: patch-content_browser_gpu_gpu_internals_ui_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- content/browser/gpu/gpu_internals_ui.cc.orig.port Sun Feb 15 10:56:09 2015
+++ content/browser/gpu/gpu_internals_ui.cc Sun Feb 15 10:56:33 2015
@@ -4,7 +4,7 @@
#include "content/browser/gpu/gpu_internals_ui.h"
-#if defined(OS_LINUX) && defined(USE_X11)
+#if (defined(OS_BSD) || defined(OS_LINUX)) && defined(USE_X11)
#include <X11/Xlib.h>
#endif
@@ -40,7 +40,7 @@
#include "ui/base/win/shell.h"
#endif
-#if defined(OS_LINUX) && defined(USE_X11)
+#if (defined(OS_BSD) || defined(OS_LINUX)) && defined(USE_X11)
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11_atom_cache.h"
#endif
@@ -172,7 +172,7 @@ base::DictionaryValue* GpuInfoAsDictionaryValue() {
gpu_info.gl_ws_version));
basic_info->Append(NewDescriptionValuePair("Window system binding extensions",
gpu_info.gl_ws_extensions));
-#if defined(OS_LINUX) && defined(USE_X11)
+#if (defined(OS_BSD) || defined(OS_LINUX)) && defined(USE_X11)
basic_info->Append(NewDescriptionValuePair("Window manager",
ui::GuessWindowManagerName()));
{

View File

@ -1,6 +1,6 @@
$OpenBSD: patch-content_browser_renderer_host_render_widget_host_view_aura_cc,v 1.5 2015/01/22 11:16:41 robert Exp $
--- content/browser/renderer_host/render_widget_host_view_aura.cc.orig.port Wed Jan 21 21:28:16 2015
+++ content/browser/renderer_host/render_widget_host_view_aura.cc Thu Jan 22 09:05:10 2015
$OpenBSD: patch-content_browser_renderer_host_render_widget_host_view_aura_cc,v 1.6 2015/02/15 19:51:28 robert Exp $
--- content/browser/renderer_host/render_widget_host_view_aura.cc.orig.port Wed Feb 11 08:15:35 2015
+++ content/browser/renderer_host/render_widget_host_view_aura.cc Sun Feb 15 11:04:07 2015
@@ -89,7 +89,7 @@
#include "ui/gfx/win/dpi.h"
#endif
@ -10,6 +10,15 @@ $OpenBSD: patch-content_browser_renderer_host_render_widget_host_view_aura_cc,v
#include "content/common/input_messages.h"
#include "ui/events/linux/text_edit_command_auralinux.h"
#include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
@@ -2326,7 +2326,7 @@ bool RenderWidgetHostViewAura::NeedsInputGrab() {
}
bool RenderWidgetHostViewAura::NeedsMouseCapture() {
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+#if (defined(OS_BSD) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
return NeedsInputGrab();
#endif
return false;
@@ -2542,7 +2542,7 @@ void RenderWidgetHostViewAura::DetachFromInputMethod()
void RenderWidgetHostViewAura::ForwardKeyboardEvent(

View File

@ -1,6 +1,15 @@
$OpenBSD: patch-content_gpu_gpu_main_cc,v 1.1 2015/01/22 11:16:41 robert Exp $
--- content/gpu/gpu_main.cc.orig.port Fri Dec 26 19:55:38 2014
+++ content/gpu/gpu_main.cc Fri Dec 26 19:59:25 2014
$OpenBSD: patch-content_gpu_gpu_main_cc,v 1.2 2015/02/15 19:51:28 robert Exp $
--- content/gpu/gpu_main.cc.orig.port Wed Feb 11 08:15:35 2015
+++ content/gpu/gpu_main.cc Sun Feb 15 10:55:08 2015
@@ -77,7 +77,7 @@ bool WarmUpSandbox(const CommandLine& command_line);
bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info);
#endif
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
#if !defined(OS_CHROMEOS)
bool CanAccessNvidiaDeviceFile();
#endif
@@ -162,13 +162,13 @@ int GpuMain(const MainFunctionParams& parameters) {
message_loop_type = base::MessageLoop::TYPE_UI;
}
@ -26,3 +35,50 @@ $OpenBSD: patch-content_gpu_gpu_main_cc,v 1.1 2015/01/22 11:16:41 robert Exp $
{
scoped_ptr<base::Environment> env(base::Environment::Create());
env->SetVar("LIBGL_DRI3_DISABLE", "1");
@@ -245,6 +245,10 @@ int GpuMain(const MainFunctionParams& parameters) {
initialized_sandbox = true;
}
#endif // defined(OS_LINUX)
+#if defined(OS_BSD)
+ bool initialized_gl_context = false;
+ bool should_initialize_gl_context = false;
+#endif
base::TimeTicks before_initialize_one_off = base::TimeTicks::Now();
@@ -292,7 +296,7 @@ int GpuMain(const MainFunctionParams& parameters) {
}
#endif
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
initialized_gl_context = true;
#if !defined(OS_CHROMEOS)
if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
@@ -327,14 +331,16 @@ int GpuMain(const MainFunctionParams& parameters) {
watchdog_thread = NULL;
}
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
should_initialize_gl_context = !initialized_gl_context &&
!dead_on_arrival;
+#if !defined(OS_BSD)
if (!initialized_sandbox) {
gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
should_initialize_gl_context);
}
+#endif
#elif defined(OS_WIN)
gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info);
#elif defined(OS_MACOSX)
@@ -435,7 +441,7 @@ bool CollectGraphicsInfo(gpu::GPUInfo& gpu_info) {
}
#endif
-#if defined(OS_LINUX)
+#if defined(OS_LINUX) || defined(OS_BSD)
#if !defined(OS_CHROMEOS)
bool CanAccessNvidiaDeviceFile() {
bool res = true;

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-content_renderer_webscrollbarbehavior_impl_gtkoraura_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- content/renderer/webscrollbarbehavior_impl_gtkoraura.cc.orig.port Sun Feb 15 11:01:57 2015
+++ content/renderer/webscrollbarbehavior_impl_gtkoraura.cc Sun Feb 15 11:05:12 2015
@@ -13,7 +13,7 @@ bool WebScrollbarBehaviorImpl::shouldCenterOnThumb(
blink::WebScrollbarBehavior::Button mouseButton,
bool shiftKeyPressed,
bool altKeyPressed) {
-#if (defined(OS_LINUX) && !defined(OS_CHROMEOS))
+#if (defined(OS_BSD) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
if (mouseButton == blink::WebScrollbarBehavior::ButtonMiddle)
return true;
#endif

View File

@ -0,0 +1,21 @@
$OpenBSD: patch-content_shell_browser_shell_browser_context_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- content/shell/browser/shell_browser_context.cc.orig.port Sun Feb 15 11:03:12 2015
+++ content/shell/browser/shell_browser_context.cc Sun Feb 15 11:03:24 2015
@@ -19,7 +19,7 @@
#if defined(OS_WIN)
#include "base/base_paths_win.h"
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
#include "base/nix/xdg_util.h"
#elif defined(OS_MACOSX)
#include "base/base_paths_mac.h"
@@ -74,7 +74,7 @@ void ShellBrowserContext::InitWhileIOAllowed() {
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"content_shell"));
-#elif defined(OS_LINUX)
+#elif defined(OS_LINUX) || defined(OS_BSD)
scoped_ptr<base::Environment> env(base::Environment::Create());
base::FilePath config_dir(
base::nix::GetXDGDirectory(env.get(),

View File

@ -0,0 +1,45 @@
$OpenBSD: patch-gpu_config_gpu_info_collector_linux_cc,v 1.1 2015/02/15 19:51:28 robert Exp $
--- gpu/config/gpu_info_collector_linux.cc.orig.port Sun Feb 15 15:25:13 2015
+++ gpu/config/gpu_info_collector_linux.cc Sun Feb 15 18:39:58 2015
@@ -31,6 +31,7 @@ namespace gpu {
namespace {
+#if !defined(OS_BSD)
// This checks if a system supports PCI bus.
// We check the existence of /sys/bus/pci or /sys/bug/pci_express.
bool IsPciSupported() {
@@ -39,6 +40,7 @@ bool IsPciSupported() {
return (base::PathExists(pci_path) ||
base::PathExists(pcie_path));
}
+#endif
// Scan /etc/ati/amdpcsdb.default for "ReleaseVersion".
// Return empty string on failing.
@@ -79,6 +81,7 @@ CollectInfoResult CollectPCIVideoCardInfo(GPUInfo* gpu
return kCollectInfoNonFatalFailure;
#else
+#if !defined(OS_BSD)
if (IsPciSupported() == false) {
VLOG(1) << "PCI bus scanning is not supported";
return kCollectInfoNonFatalFailure;
@@ -148,6 +151,17 @@ CollectInfoResult CollectPCIVideoCardInfo(GPUInfo* gpu
}
(libpci_loader.pci_cleanup)(access);
+#else
+ unsigned int vendor_id = 0x0000, device_id = 0x0000;
+ char *vid, *did;
+ if ((vid = getenv("OPENBSD_GPU_VENDOR")) != NULL)
+ vendor_id = strtol(vid, NULL, 16);
+ if ((did = getenv("OPENBSD_GPU_DEVICE")) != NULL)
+ device_id = strtol(did, NULL, 16);
+ bool primary_gpu_identified = true;
+ gpu_info->gpu.vendor_id = vendor_id;
+ gpu_info->gpu.device_id = device_id;
+#endif
if (!primary_gpu_identified)
return kCollectInfoNonFatalFailure;
return kCollectInfoSuccess;

View File

@ -1,10 +1,11 @@
@comment $OpenBSD: PLIST,v 1.44 2015/02/10 10:12:49 sthen Exp $
@comment $OpenBSD: PLIST,v 1.45 2015/02/15 19:51:28 robert Exp $
@pkgpath www/chromium,proprietary
bin/chrome
chrome/
@bin chrome/chrome
chrome/chrome_100_percent.pak
chrome/content_resources.pak
@bin chrome/gpuid
chrome/icudtl.dat
chrome/keyboard_resources.pak
chrome/libexif.so