Commit 4ee7c239 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Introduce x11::Connection to replace XDisplay

x11::Connection::Get() should replace gfx::GetXDisplay().

R=sky
CC=​msisov,nickdiego
BUG=1066670

Change-Id: I5a2020c10f158f98697074fb9fec19c13ff6e644
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2168927
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763465}
parent a124a2e4
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/events/x/x11_window_event_manager.h" #include "ui/events/x/x11_window_event_manager.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto.h"
...@@ -14,9 +15,10 @@ namespace ui { ...@@ -14,9 +15,10 @@ namespace ui {
namespace { namespace {
x11::Future<x11::XProto::GetPropertyReply> GetWorkspace(XDisplay* display) { x11::Future<x11::XProto::GetPropertyReply> GetWorkspace() {
return x11::XProto{display}.GetProperty({ auto* connection = x11::Connection::Get();
.window = XDefaultRootWindow(display), return connection->GetProperty({
.window = XDefaultRootWindow(connection->display()),
.property = gfx::GetAtom("_NET_CURRENT_DESKTOP"), .property = gfx::GetAtom("_NET_CURRENT_DESKTOP"),
.type = gfx::GetAtom("CARDINAL"), .type = gfx::GetAtom("CARDINAL"),
.long_length = 1, .long_length = 1,
...@@ -44,7 +46,7 @@ X11WorkspaceHandler::~X11WorkspaceHandler() { ...@@ -44,7 +46,7 @@ X11WorkspaceHandler::~X11WorkspaceHandler() {
std::string X11WorkspaceHandler::GetCurrentWorkspace() { std::string X11WorkspaceHandler::GetCurrentWorkspace() {
if (workspace_.empty()) if (workspace_.empty())
OnWorkspaceResponse(GetWorkspace(xdisplay_).Sync()); OnWorkspaceResponse(GetWorkspace().Sync());
return workspace_; return workspace_;
} }
...@@ -56,7 +58,7 @@ bool X11WorkspaceHandler::DispatchXEvent(XEvent* event) { ...@@ -56,7 +58,7 @@ bool X11WorkspaceHandler::DispatchXEvent(XEvent* event) {
switch (event->type) { switch (event->type) {
case PropertyNotify: { case PropertyNotify: {
if (event->xproperty.atom == gfx::GetAtom("_NET_CURRENT_DESKTOP")) { if (event->xproperty.atom == gfx::GetAtom("_NET_CURRENT_DESKTOP")) {
GetWorkspace(xdisplay_).OnResponse( GetWorkspace().OnResponse(
base::BindOnce(&X11WorkspaceHandler::OnWorkspaceResponse, base::BindOnce(&X11WorkspaceHandler::OnWorkspaceResponse,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -93,6 +93,10 @@ component("xprotos") { ...@@ -93,6 +93,10 @@ component("xprotos") {
"request_queue.cc", "request_queue.cc",
"xproto_util.h", "xproto_util.h",
"xproto_util.cc", "xproto_util.cc",
"connection.h",
"connection.cc",
"x11_switches.cc",
"x11_switches.h",
] ]
configs += [ configs += [
":x11_private_config", ":x11_private_config",
...@@ -112,8 +116,6 @@ jumbo_component("x") { ...@@ -112,8 +116,6 @@ jumbo_component("x") {
"x11_error_tracker.h", "x11_error_tracker.h",
"x11_path.cc", "x11_path.cc",
"x11_path.h", "x11_path.h",
"x11_switches.cc",
"x11_switches.h",
"x11_types.cc", "x11_types.cc",
"x11_types.h", "x11_types.h",
] ]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/x/connection.h"
#include "base/command_line.h"
#include "ui/gfx/x/x11_switches.h"
namespace x11 {
namespace {
XDisplay* OpenNewXDisplay() {
if (!XInitThreads())
return nullptr;
std::string display_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kX11Display);
return XOpenDisplay(display_str.empty() ? nullptr : display_str.c_str());
}
} // namespace
Connection* Connection::Get() {
static Connection* instance = new Connection(OpenNewXDisplay());
return instance;
}
Connection::Connection(XDisplay* display) : XProto(display) {}
} // namespace x11
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GFX_X_CONNECTION_H_
#define UI_GFX_X_CONNECTION_H_
#include "base/component_export.h"
#include "ui/gfx/x/xproto.h"
namespace x11 {
// Represents a socket to the X11 server.
class COMPONENT_EXPORT(X11) Connection : public XProto {
public:
// Gets or creates the singeton connection.
static Connection* Get();
Connection(const Connection&) = delete;
Connection(Connection&&) = delete;
private:
explicit Connection(XDisplay* display);
};
} // namespace x11
#endif // UI_GFX_X_CONNECTION_H_
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
# public: # public:
# explicit XProto(XDisplay* display); # explicit XProto(XDisplay* display);
# #
# XDisplay* display() { return display_; }
#
# struct RGB { # struct RGB {
# uint16_t red{}; # uint16_t red{};
# uint16_t green{}; # uint16_t green{};
...@@ -682,6 +684,8 @@ class GenXproto: ...@@ -682,6 +684,8 @@ class GenXproto:
self.write('public:') self.write('public:')
self.write('explicit %s(XDisplay* display);' % name) self.write('explicit %s(XDisplay* display);' % name)
self.write() self.write()
self.write('XDisplay* display() { return display_; }')
self.write()
for (name, item) in self.module.all: for (name, item) in self.module.all:
self.declare_type(item, name) self.declare_type(item, name)
self.write('private:') self.write('private:')
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "build/build_config.h"
#include "ui/gfx/x/x11_switches.h" #include "ui/gfx/x/x11_switches.h"
namespace switches { namespace switches {
......
...@@ -5,14 +5,13 @@ ...@@ -5,14 +5,13 @@
#ifndef UI_GFX_X_X11_SWITCHES_H_ #ifndef UI_GFX_X_X11_SWITCHES_H_
#define UI_GFX_X_X11_SWITCHES_H_ #define UI_GFX_X_X11_SWITCHES_H_
#include "build/build_config.h" #include "base/component_export.h"
#include "ui/gfx/gfx_export.h"
namespace switches { namespace switches {
GFX_EXPORT extern const char kX11Display[]; COMPONENT_EXPORT(X11) extern const char kX11Display[];
GFX_EXPORT extern const char kNoXshm[]; COMPONENT_EXPORT(X11) extern const char kNoXshm[];
} // namespace switches } // namespace switches
......
...@@ -10,26 +10,13 @@ ...@@ -10,26 +10,13 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11_switches.h" #include "ui/gfx/x/x11_switches.h"
namespace gfx { namespace gfx {
namespace {
XDisplay* OpenNewXDisplay() {
if (!XInitThreads())
return nullptr;
std::string display_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kX11Display);
return XOpenDisplay(display_str.empty() ? nullptr : display_str.c_str());
}
} // namespace
XDisplay* GetXDisplay() { XDisplay* GetXDisplay() {
static XDisplay* display = OpenNewXDisplay(); return x11::Connection::Get()->display();
return display;
} }
XDisplay* CloneXDisplay(XDisplay* display) { XDisplay* CloneXDisplay(XDisplay* display) {
...@@ -90,10 +77,10 @@ void PutARGBImage(XDisplay* display, ...@@ -90,10 +77,10 @@ void PutARGBImage(XDisplay* display,
image.width = data_width; image.width = data_width;
image.height = data_height; image.height = data_height;
image.format = ZPixmap; image.format = static_cast<int>(x11::XProto::ImageFormat::ZPixmap);
image.byte_order = LSBFirst; image.byte_order = static_cast<int>(x11::XProto::ImageOrder::LSBFirst);
image.bitmap_unit = 8; image.bitmap_unit = 8;
image.bitmap_bit_order = LSBFirst; image.bitmap_bit_order = static_cast<int>(x11::XProto::ImageOrder::LSBFirst);
image.depth = depth; image.depth = depth;
image.bits_per_pixel = pixmap_bpp; image.bits_per_pixel = pixmap_bpp;
image.bytes_per_line = data_width * pixmap_bpp / 8; image.bytes_per_line = data_width * pixmap_bpp / 8;
......
...@@ -17,10 +17,10 @@ typedef unsigned long VisualID; ...@@ -17,10 +17,10 @@ typedef unsigned long VisualID;
typedef struct _XcursorImage XcursorImage; typedef struct _XcursorImage XcursorImage;
typedef union _XEvent XEvent; typedef union _XEvent XEvent;
typedef struct _XImage XImage; typedef struct _XImage XImage;
typedef struct _XGC *GC; typedef struct _XGC* GC;
typedef struct _XDisplay XDisplay; typedef struct _XDisplay XDisplay;
typedef struct _XRegion XRegion; typedef struct _XRegion XRegion;
typedef struct __GLXFBConfigRec *GLXFBConfig; typedef struct __GLXFBConfigRec* GLXFBConfig;
typedef XID GLXWindow; typedef XID GLXWindow;
typedef XID GLXDrawable; typedef XID GLXDrawable;
...@@ -38,9 +38,7 @@ struct XObjectDeleter { ...@@ -38,9 +38,7 @@ struct XObjectDeleter {
template <class T, class D = XObjectDeleter<void, int, XFree>> template <class T, class D = XObjectDeleter<void, int, XFree>>
using XScopedPtr = std::unique_ptr<T, D>; using XScopedPtr = std::unique_ptr<T, D>;
// TODO(oshima|evan): This assume there is one display and doesn't work // Get the XDisplay singleton. Prefer x11::Connection::Get() instead.
// under multiple displays/monitor environment. Remove this and change the
// chrome codebase to get the display from window.
GFX_EXPORT XDisplay* GetXDisplay(); GFX_EXPORT XDisplay* GetXDisplay();
// Given a connection to an X server, opens a new parallel connection to the // Given a connection to an X server, opens a new parallel connection to the
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "ui/base/x/x11_display_util.h" #include "ui/base/x/x11_display_util.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xproto.h" #include "ui/gfx/x/xproto.h"
#include "ui/gl/egl_util.h" #include "ui/gl/egl_util.h"
...@@ -55,8 +56,7 @@ bool NativeViewGLSurfaceEGLX11::Initialize(GLSurfaceFormat format) { ...@@ -55,8 +56,7 @@ bool NativeViewGLSurfaceEGLX11::Initialize(GLSurfaceFormat format) {
// Query all child windows and store them. ANGLE creates a child window when // Query all child windows and store them. ANGLE creates a child window when
// eglCreateWidnowSurface is called on X11 and expose events from this window // eglCreateWidnowSurface is called on X11 and expose events from this window
// need to be received by this class. // need to be received by this class.
x11::XProto conn{GetXNativeDisplay()}; if (auto reply = x11::Connection::Get()->QueryTree({window_}).Sync())
if (auto reply = conn.QueryTree({window_}).Sync())
children_ = std::move(reply->children); children_ = std::move(reply->children);
if (ui::X11EventSource::HasInstance()) { if (ui::X11EventSource::HasInstance()) {
......
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