Commit 6f691398 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Avoid using X11 SHM for remote connections

This is a reland of [1], which was accidentally removed by [2].  The
only difference is the gethostname() check is removed to address [3].

> For remote connections, SHM doesn't work, but the MIT-SHM extension
> may still be available, so we need to do an explicit check before
> trying to use SHM.

[1] https://chromium.googlesource.com/chromium/src/+/633c011511bae4ff193ac007e3e8ba64287c1d89
[2] https://chromium.googlesource.com/chromium/src/+/12a86d61adf2520c177ed51aec6583f490e29f7d
[3] https://bugs.chromium.org/p/chromium/issues/detail?id=1035803#c12

R=nickdiego
BUG=1035803

Change-Id: I5b707de48a8c2991aaf73c347b29ef813a9c28b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062900
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarNick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#742312}
parent 6951f72d
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "net/base/url_util.h"
#include "ui/events/platform/platform_event_dispatcher.h" #include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -55,7 +56,30 @@ std::size_t MaxShmSegmentSize() { ...@@ -55,7 +56,30 @@ std::size_t MaxShmSegmentSize() {
} }
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
bool ShouldUseMitShm() { bool IsRemoteHost(const std::string& name) {
if (name.empty())
return false;
return !net::HostStringIsLocalhost(name);
}
bool ShouldUseMitShm(XDisplay* display) {
// MIT-SHM may be available on remote connetions, but it will be unusable. Do
// a best-effort check to see if the host is remote to disable the SHM
// codepath. It may be possible in contrived cases for there to be a
// false-positive, but in that case we'll just fallback to the non-SHM
// codepath.
char* display_string = DisplayString(display);
char* host = nullptr;
int display_id = 0;
int screen = 0;
if (xcb_parse_display(display_string, &host, &display_id, &screen)) {
std::string name = host;
free(host);
if (IsRemoteHost(name))
return false;
}
std::unique_ptr<base::Environment> env = base::Environment::Create(); std::unique_ptr<base::Environment> env = base::Environment::Create();
// Used by QT. // Used by QT.
...@@ -120,7 +144,7 @@ bool XShmImagePool::Resize(const gfx::Size& pixel_size) { ...@@ -120,7 +144,7 @@ bool XShmImagePool::Resize(const gfx::Size& pixel_size) {
return false; return false;
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
if (!ShouldUseMitShm()) if (!ShouldUseMitShm(display_))
return false; return false;
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment