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

[XProto] Remove usage of XCreateWindow/XDestroyWindow

BUG=1066670
R=sky

Change-Id: I143ec40265e7b9787c948be67f3695fce79634d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412472
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807606}
parent f5fefca2
...@@ -24,6 +24,7 @@ if ((is_linux || is_chromeos) && use_x11 && current_cpu != "arm") { ...@@ -24,6 +24,7 @@ if ((is_linux || is_chromeos) && use_x11 && current_cpu != "arm") {
deps = [ deps = [
"//base", "//base",
"//ui/base/x",
"//ui/gfx/x", "//ui/gfx/x",
"//ui/gl", "//ui/gl",
"//ui/gl/init", "//ui/gl/init",
......
include_rules = [
"+ui/base/x",
]
...@@ -34,15 +34,16 @@ ...@@ -34,15 +34,16 @@
#include "gpu/tools/compositor_model_bench/render_model_utils.h" #include "gpu/tools/compositor_model_bench/render_model_utils.h"
#include "gpu/tools/compositor_model_bench/render_models.h" #include "gpu/tools/compositor_model_bench/render_models.h"
#include "gpu/tools/compositor_model_bench/render_tree.h" #include "gpu/tools/compositor_model_bench/render_tree.h"
#include "ui/base/x/x11_util.h"
#include "ui/gfx/x/connection.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/gfx/x/xproto_util.h" #include "ui/gfx/x/xproto_util.h"
#include "ui/gl/init/gl_factory.h" #include "ui/gl/init/gl_factory.h"
using base::TimeTicks;
using base::DirectoryExists; using base::DirectoryExists;
using base::PathExists; using base::PathExists;
using base::TimeTicks;
using std::string; using std::string;
struct SimulationSpecification { struct SimulationSpecification {
...@@ -64,7 +65,6 @@ class Simulator { ...@@ -64,7 +65,6 @@ class Simulator {
: output_path_(output_path), : output_path_(output_path),
seconds_per_test_(seconds_per_test), seconds_per_test_(seconds_per_test),
display_(nullptr), display_(nullptr),
window_(0),
gl_context_(nullptr), gl_context_(nullptr),
window_width_(WINDOW_WIDTH), window_width_(WINDOW_WIDTH),
window_height_(WINDOW_HEIGHT) {} window_height_(WINDOW_HEIGHT) {}
...@@ -75,7 +75,7 @@ class Simulator { ...@@ -75,7 +75,7 @@ class Simulator {
glXDestroyContext(display_, gl_context_); glXDestroyContext(display_, gl_context_);
// Destroy window and display. // Destroy window and display.
XDestroyWindow(display_, window_); connection_->DestroyWindow({window_});
XCloseDisplay(display_); XCloseDisplay(display_);
} }
...@@ -87,8 +87,9 @@ class Simulator { ...@@ -87,8 +87,9 @@ class Simulator {
// name, but that's not really harmful (we'll still warn about it though.) // name, but that's not really harmful (we'll still warn about it though.)
spec.simulation_name = path.BaseName().RemoveExtension().MaybeAsASCII(); spec.simulation_name = path.BaseName().RemoveExtension().MaybeAsASCII();
if (spec.simulation_name.empty()) { if (spec.simulation_name.empty()) {
LOG(WARNING) << "Simulation for path " << path.LossyDisplayName() << LOG(WARNING) << "Simulation for path " << path.LossyDisplayName()
" will have a blank simulation name, since the file name isn't ASCII"; << " will have a blank simulation name, since the file name "
"isn't ASCII";
} }
spec.input_path = path; spec.input_path = path;
spec.model_under_test = ForwardRenderModel; spec.model_under_test = ForwardRenderModel;
...@@ -155,21 +156,31 @@ class Simulator { ...@@ -155,21 +156,31 @@ class Simulator {
return false; return false;
} }
// Get properties of the screen.
int screen = XDefaultScreen(display_);
int root_window = XDefaultRootWindow(display_);
// Creates the window. // Creates the window.
window_ = XCreateSimpleWindow( auto black_pixel = connection_->default_screen().black_pixel;
display_, root_window, 1, 1, window_width_, window_height_, 0, window_ = connection_->GenerateId<x11::Window>();
XBlackPixel(display_, screen), XBlackPixel(display_, screen)); connection_->CreateWindow({
XStoreName(display_, window_, "Compositor Model Bench"); .wid = window_,
.parent = connection_->default_root(),
XSelectInput(display_, window_, .x = 1,
ExposureMask | KeyPressMask | StructureNotifyMask); .y = 1,
XMapWindow(display_, window_); .width = window_width_,
.height = window_height_,
XResizeWindow(display_, window_, WINDOW_WIDTH, WINDOW_HEIGHT); .background_pixel = black_pixel,
.border_pixel = black_pixel,
.event_mask = x11::EventMask::Exposure | x11::EventMask::KeyPress |
x11::EventMask::StructureNotify,
});
ui::SetStringProperty(window_, x11::Atom::WM_NAME, x11::Atom::STRING,
"Compositor Model Bench");
connection_->MapWindow({window_});
connection_->ConfigureWindow({
.window = window_,
.width = WINDOW_WIDTH,
.height = WINDOW_HEIGHT,
});
return true; return true;
} }
...@@ -181,10 +192,9 @@ class Simulator { ...@@ -181,10 +192,9 @@ class Simulator {
return false; return false;
} }
XWindowAttributes attributes;
XGetWindowAttributes(display_, window_, &attributes);
XVisualInfo visual_info_template; XVisualInfo visual_info_template;
visual_info_template.visualid = XVisualIDFromVisual(attributes.visual); if (auto reply = connection_->GetWindowAttributes({window_}).Sync())
visual_info_template.visualid = static_cast<uint32_t>(reply->visual);
int visual_info_count = 0; int visual_info_count = 0;
constexpr int kVisualIdMask = 1; constexpr int kVisualIdMask = 1;
XVisualInfo* visual_info_list = XGetVisualInfo( XVisualInfo* visual_info_list = XGetVisualInfo(
...@@ -200,7 +210,8 @@ class Simulator { ...@@ -200,7 +210,8 @@ class Simulator {
return false; return false;
} }
if (!glXMakeCurrent(display_, window_, gl_context_)) { if (!glXMakeCurrent(display_, static_cast<uint32_t>(window_),
gl_context_)) {
glXDestroyContext(display_, gl_context_); glXDestroyContext(display_, gl_context_);
gl_context_ = nullptr; gl_context_ = nullptr;
return false; return false;
...@@ -239,7 +250,7 @@ class Simulator { ...@@ -239,7 +250,7 @@ class Simulator {
if (current_sim_) if (current_sim_)
current_sim_->Update(); current_sim_->Update();
glXSwapBuffers(display_, window_); glXSwapBuffers(display_, static_cast<uint32_t>(window_));
auto window = static_cast<x11::Window>(window_); auto window = static_cast<x11::Window>(window_);
x11::ExposeEvent ev{ x11::ExposeEvent ev{
...@@ -276,8 +287,7 @@ class Simulator { ...@@ -276,8 +287,7 @@ class Simulator {
"\t\t\t\"render_model\":\"%s\",\n" "\t\t\t\"render_model\":\"%s\",\n"
"\t\t\t\"frames_drawn\":%d\n" "\t\t\t\"frames_drawn\":%d\n"
"\t\t},\n", "\t\t},\n",
i.simulation_name.c_str(), i.simulation_name.c_str(), ModelToString(i.model_under_test),
ModelToString(i.model_under_test),
i.frames_rendered); i.frames_rendered);
sims_completed_.pop(); sims_completed_.pop();
} }
...@@ -334,7 +344,7 @@ class Simulator { ...@@ -334,7 +344,7 @@ class Simulator {
// GUI data // GUI data
std::unique_ptr<x11::Connection> connection_; std::unique_ptr<x11::Connection> connection_;
Display* display_; Display* display_;
Window window_; x11::Window window_ = x11::Window::None;
GLXContext gl_context_; GLXContext gl_context_;
int window_width_; int window_width_;
int window_height_; int window_height_;
...@@ -346,9 +356,10 @@ int main(int argc, char* argv[]) { ...@@ -346,9 +356,10 @@ int main(int argc, char* argv[]) {
const base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); const base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
if (argc != 3 && argc != 4) { if (argc != 3 && argc != 4) {
LOG(INFO) << "Usage: \n" << LOG(INFO)
cl->GetProgram().BaseName().LossyDisplayName() << << "Usage: \n"
"--in=[input path] --out=[output path] (duration=[seconds])\n" << cl->GetProgram().BaseName().LossyDisplayName()
<< "--in=[input path] --out=[output path] (duration=[seconds])\n"
"The input path specifies either a JSON configuration file or\n" "The input path specifies either a JSON configuration file or\n"
"a directory containing only these files\n" "a directory containing only these files\n"
"(if a directory is specified, simulations will be run for\n" "(if a directory is specified, simulations will be run for\n"
......
...@@ -47,38 +47,40 @@ class VulkanSurfaceX11::ExposeEventForwarder : public ui::XEventDispatcher { ...@@ -47,38 +47,40 @@ class VulkanSurfaceX11::ExposeEventForwarder : public ui::XEventDispatcher {
std::unique_ptr<VulkanSurfaceX11> VulkanSurfaceX11::Create( std::unique_ptr<VulkanSurfaceX11> VulkanSurfaceX11::Create(
VkInstance vk_instance, VkInstance vk_instance,
x11::Window parent_window) { x11::Window parent_window) {
XDisplay* display = gfx::GetXDisplay(); auto* connection = x11::Connection::Get();
XWindowAttributes attributes; auto geometry = connection->GetGeometry({parent_window}).Sync();
if (!XGetWindowAttributes(display, static_cast<uint32_t>(parent_window), if (!geometry) {
&attributes)) { LOG(ERROR) << "GetGeometry failed for window "
LOG(ERROR) << "XGetWindowAttributes failed for window "
<< static_cast<uint32_t>(parent_window) << "."; << static_cast<uint32_t>(parent_window) << ".";
return nullptr; return nullptr;
} }
Window window = XCreateWindow(
display, static_cast<uint32_t>(parent_window), 0, 0, attributes.width, auto window = connection->GenerateId<x11::Window>();
attributes.height, 0, static_cast<int>(x11::WindowClass::CopyFromParent), connection->CreateWindow({
static_cast<int>(x11::WindowClass::InputOutput), nullptr, 0, nullptr); .wid = window,
if (!window) { .parent = parent_window,
LOG(ERROR) << "XCreateWindow failed."; .width = geometry->width,
.height = geometry->height,
.c_class = x11::WindowClass::InputOutput,
});
if (connection->MapWindow({window}).Sync().error) {
LOG(ERROR) << "Failed to create or map window.";
return nullptr; return nullptr;
} }
XMapWindow(display, window);
XFlush(display);
VkSurfaceKHR vk_surface; VkSurfaceKHR vk_surface;
VkXlibSurfaceCreateInfoKHR surface_create_info = { VkXlibSurfaceCreateInfoKHR surface_create_info = {
VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR}; VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
surface_create_info.dpy = display; surface_create_info.dpy = connection->display();
surface_create_info.window = window; surface_create_info.window = static_cast<uint32_t>(window);
VkResult result = vkCreateXlibSurfaceKHR(vk_instance, &surface_create_info, VkResult result = vkCreateXlibSurfaceKHR(vk_instance, &surface_create_info,
nullptr, &vk_surface); nullptr, &vk_surface);
if (VK_SUCCESS != result) { if (VK_SUCCESS != result) {
DLOG(ERROR) << "vkCreateXlibSurfaceKHR() failed: " << result; DLOG(ERROR) << "vkCreateXlibSurfaceKHR() failed: " << result;
return nullptr; return nullptr;
} }
return std::make_unique<VulkanSurfaceX11>( return std::make_unique<VulkanSurfaceX11>(vk_instance, vk_surface,
vk_instance, vk_surface, parent_window, static_cast<x11::Window>(window)); parent_window, window);
} }
VulkanSurfaceX11::VulkanSurfaceX11(VkInstance vk_instance, VulkanSurfaceX11::VulkanSurfaceX11(VkInstance vk_instance,
...@@ -99,10 +101,10 @@ void VulkanSurfaceX11::Destroy() { ...@@ -99,10 +101,10 @@ void VulkanSurfaceX11::Destroy() {
VulkanSurface::Destroy(); VulkanSurface::Destroy();
expose_event_forwarder_.reset(); expose_event_forwarder_.reset();
if (window_ != x11::Window::None) { if (window_ != x11::Window::None) {
Display* display = gfx::GetXDisplay(); auto* connection = x11::Connection::Get();
XDestroyWindow(display, static_cast<uint32_t>(window_)); connection->DestroyWindow({window_});
window_ = x11::Window::None; window_ = x11::Window::None;
XFlush(display); connection->Flush();
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/events/x/x11_window_event_manager.h" #include "ui/events/x/x11_window_event_manager.h"
#include "ui/gfx/x/xproto.h"
namespace ui { namespace ui {
...@@ -26,23 +27,24 @@ TestCompositorHostX11::TestCompositorHostX11( ...@@ -26,23 +27,24 @@ TestCompositorHostX11::TestCompositorHostX11(
TestCompositorHostX11::~TestCompositorHostX11() = default; TestCompositorHostX11::~TestCompositorHostX11() = default;
void TestCompositorHostX11::Show() { void TestCompositorHostX11::Show() {
XDisplay* display = gfx::GetXDisplay(); auto* connection = x11::Connection::Get();
XSetWindowAttributes swa; window_ = connection->GenerateId<x11::Window>();
swa.override_redirect = true; connection->CreateWindow({
window_ = static_cast<x11::Window>(XCreateWindow( .wid = window_,
display, XDefaultRootWindow(display), // parent .parent = connection->default_root(),
bounds_.x(), bounds_.y(), bounds_.width(), bounds_.height(), .x = bounds_.x(),
0, // border width .y = bounds_.y(),
static_cast<int>(x11::WindowClass::CopyFromParent), // depth .width = bounds_.width(),
static_cast<int>(x11::WindowClass::InputOutput), .height = bounds_.height(),
nullptr, // visual .c_class = x11::WindowClass::InputOutput,
CWOverrideRedirect, &swa)); .override_redirect = x11::Bool32(true),
});
window_events_ = window_events_ =
std::make_unique<XScopedEventSelector>(window_, ExposureMask); std::make_unique<XScopedEventSelector>(window_, ExposureMask);
XMapWindow(display, static_cast<uint32_t>(window_)); connection->MapWindow({window_});
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete. // to ensure the map is complete.
XSync(display, false); connection->Sync();
allocator_.GenerateId(); allocator_.GenerateId();
compositor_.SetAcceleratedWidget( compositor_.SetAcceleratedWidget(
static_cast<gfx::AcceleratedWidget>(window_)); static_cast<gfx::AcceleratedWidget>(window_));
......
...@@ -297,28 +297,6 @@ int XGrabKey(Display*, int, unsigned int, Window, Bool, int, int); ...@@ -297,28 +297,6 @@ int XGrabKey(Display*, int, unsigned int, Window, Bool, int, int);
int XUngrabKey(Display*, int, unsigned int, Window); int XUngrabKey(Display*, int, unsigned int, Window);
int XSelectInput(Display*, Window, long); int XSelectInput(Display*, Window, long);
int XSetWindowBackgroundPixmap(Display*, Window, Pixmap); int XSetWindowBackgroundPixmap(Display*, Window, Pixmap);
Window XCreateWindow(Display*,
Window,
int,
int,
unsigned int,
unsigned int,
unsigned int,
int,
unsigned int,
Visual*,
unsigned long,
XSetWindowAttributes*);
Window XCreateSimpleWindow(Display*,
Window,
int,
int,
unsigned int,
unsigned int,
unsigned int,
unsigned long,
unsigned long);
int XDestroyWindow(Display*, Window);
Status XGetWindowAttributes(Display*, Window, XWindowAttributes*); Status XGetWindowAttributes(Display*, Window, XWindowAttributes*);
VisualID XVisualIDFromVisual(Visual*); VisualID XVisualIDFromVisual(Visual*);
int XResizeWindow(Display*, Window, unsigned int, unsigned int); int XResizeWindow(Display*, Window, unsigned int, unsigned int);
......
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_error_tracker.h" #include "ui/gfx/x/x11_error_tracker.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface_glx_x11.h" #include "ui/gl/gl_surface_glx_x11.h"
#include "ui/gl/init/gl_factory.h" #include "ui/gl/init/gl_factory.h"
...@@ -26,28 +28,26 @@ namespace gl { ...@@ -26,28 +28,26 @@ namespace gl {
#endif #endif
TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) { TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
auto* xdisplay = gfx::GetXDisplay(); auto* connection = x11::Connection::Get();
ASSERT_TRUE(xdisplay); ASSERT_TRUE(connection && connection->Ready());
gfx::X11ErrorTracker error_tracker; gfx::X11ErrorTracker error_tracker;
XSetWindowAttributes swa; auto xwindow = connection->GenerateId<x11::Window>();
memset(&swa, 0, sizeof(swa)); connection->CreateWindow({
swa.background_pixmap = 0; .wid = xwindow,
swa.override_redirect = true; .parent = connection->default_root(),
auto xwindow = static_cast<x11::Window>(XCreateWindow( .width = 10,
xdisplay, XDefaultRootWindow(xdisplay), 0, 0, 10, .height = 10,
10, // x, y, width, height .c_class = x11::WindowClass::InputOutput,
0, // border width .background_pixmap = x11::Pixmap::None,
static_cast<int>(x11::WindowClass::CopyFromParent), // depth .override_redirect = x11::Bool32(true),
static_cast<int>(x11::WindowClass::InputOutput), });
nullptr, // visual
CWBackPixmap | CWOverrideRedirect, &swa));
XMapWindow(xdisplay, static_cast<uint32_t>(xwindow)); connection->MapWindow({xwindow});
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the map is complete. // to ensure the map is complete.
XSync(xdisplay, false); connection->Sync();
GLImageTestSupport::InitializeGL(base::nullopt); GLImageTestSupport::InitializeGL(base::nullopt);
auto surface = gl::InitializeGLSurface(base::MakeRefCounted<GLSurfaceGLXX11>( auto surface = gl::InitializeGLSurface(base::MakeRefCounted<GLSurfaceGLXX11>(
...@@ -61,10 +61,10 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) { ...@@ -61,10 +61,10 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
EXPECT_TRUE(context->GetHandle()); EXPECT_TRUE(context->GetHandle());
context->ReleaseCurrent(surface.get()); context->ReleaseCurrent(surface.get());
XDestroyWindow(xdisplay, static_cast<uint32_t>(xwindow)); connection->DestroyWindow({xwindow});
// Since this window is override-redirect, syncing is sufficient // Since this window is override-redirect, syncing is sufficient
// to ensure the window is destroyed and unmapped. // to ensure the window is destroyed and unmapped.
XSync(xdisplay, false); connection->Sync();
ASSERT_FALSE(error_tracker.FoundNewError()); ASSERT_FALSE(error_tracker.FoundNewError());
if (context->MakeCurrent(surface.get())) { if (context->MakeCurrent(surface.get())) {
...@@ -83,7 +83,8 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) { ...@@ -83,7 +83,8 @@ TEST(GLContextGLXTest, MAYBE_DoNotDestroyOnFailedMakeCurrent) {
// not destroyed. // not destroyed.
ASSERT_TRUE(context->GetHandle()); ASSERT_TRUE(context->GetHandle());
surface = nullptr; surface = nullptr;
XSync(xdisplay, true); connection->Sync();
connection->events().clear();
} }
} // namespace gl } // namespace gl
...@@ -19,7 +19,7 @@ namespace { ...@@ -19,7 +19,7 @@ namespace {
class XrandrIntervalOnlyVSyncProvider : public gfx::VSyncProvider { class XrandrIntervalOnlyVSyncProvider : public gfx::VSyncProvider {
public: public:
explicit XrandrIntervalOnlyVSyncProvider(Display* display) explicit XrandrIntervalOnlyVSyncProvider()
: interval_(base::TimeDelta::FromSeconds(1 / 60.)) {} : interval_(base::TimeDelta::FromSeconds(1 / 60.)) {}
void GetVSyncParameters(UpdateVSyncCallback callback) override { void GetVSyncParameters(UpdateVSyncCallback callback) override {
...@@ -86,8 +86,9 @@ gfx::SwapResult NativeViewGLSurfaceEGLX11::SwapBuffers( ...@@ -86,8 +86,9 @@ gfx::SwapResult NativeViewGLSurfaceEGLX11::SwapBuffers(
// views::DesktopWindowTreeHostX11::InitX11Window back to None for the // views::DesktopWindowTreeHostX11::InitX11Window back to None for the
// XWindow associated to this surface after the first SwapBuffers has // XWindow associated to this surface after the first SwapBuffers has
// happened, to avoid showing a weird white background while resizing. // happened, to avoid showing a weird white background while resizing.
if (GetXNativeDisplay() && !has_swapped_buffers_) { if (GetXNativeConnection()->display() && !has_swapped_buffers_) {
XSetWindowBackgroundPixmap(GetXNativeDisplay(), window_, 0); XSetWindowBackgroundPixmap(GetXNativeConnection()->display(), window_, 0);
GetXNativeConnection()->Flush();
has_swapped_buffers_ = true; has_swapped_buffers_ = true;
} }
return result; return result;
...@@ -97,13 +98,13 @@ NativeViewGLSurfaceEGLX11::~NativeViewGLSurfaceEGLX11() { ...@@ -97,13 +98,13 @@ NativeViewGLSurfaceEGLX11::~NativeViewGLSurfaceEGLX11() {
Destroy(); Destroy();
} }
Display* NativeViewGLSurfaceEGLX11::GetXNativeDisplay() const { x11::Connection* NativeViewGLSurfaceEGLX11::GetXNativeConnection() const {
return reinterpret_cast<Display*>(GetNativeDisplay()); return x11::Connection::Get();
} }
std::unique_ptr<gfx::VSyncProvider> std::unique_ptr<gfx::VSyncProvider>
NativeViewGLSurfaceEGLX11::CreateVsyncProviderInternal() { NativeViewGLSurfaceEGLX11::CreateVsyncProviderInternal() {
return std::make_unique<XrandrIntervalOnlyVSyncProvider>(GetXNativeDisplay()); return std::make_unique<XrandrIntervalOnlyVSyncProvider>();
} }
bool NativeViewGLSurfaceEGLX11::DispatchXEvent(x11::Event* x11_event) { bool NativeViewGLSurfaceEGLX11::DispatchXEvent(x11::Event* x11_event) {
......
...@@ -35,7 +35,7 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11 : public NativeViewGLSurfaceEGL, ...@@ -35,7 +35,7 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11 : public NativeViewGLSurfaceEGL,
protected: protected:
~NativeViewGLSurfaceEGLX11() override; ~NativeViewGLSurfaceEGLX11() override;
Display* GetXNativeDisplay() const; x11::Connection* GetXNativeConnection() const;
private: private:
// NativeViewGLSurfaceEGL overrides: // NativeViewGLSurfaceEGL overrides:
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/xproto.h"
#include "ui/gfx/x/xproto_util.h" #include "ui/gfx/x/xproto_util.h"
#include "ui/gl/egl_util.h" #include "ui/gl/egl_util.h"
...@@ -19,33 +20,33 @@ NativeViewGLSurfaceEGLX11GLES2::NativeViewGLSurfaceEGLX11GLES2( ...@@ -19,33 +20,33 @@ NativeViewGLSurfaceEGLX11GLES2::NativeViewGLSurfaceEGLX11GLES2(
: NativeViewGLSurfaceEGLX11(x11::Window::None), parent_window_(window) {} : NativeViewGLSurfaceEGLX11(x11::Window::None), parent_window_(window) {}
bool NativeViewGLSurfaceEGLX11GLES2::InitializeNativeWindow() { bool NativeViewGLSurfaceEGLX11GLES2::InitializeNativeWindow() {
Display* x11_display = GetXNativeDisplay(); auto* connection = GetXNativeConnection();
XWindowAttributes attributes; auto geometry = connection->GetGeometry({parent_window_}).Sync();
if (!XGetWindowAttributes(x11_display, static_cast<uint32_t>(parent_window_), if (!geometry) {
&attributes)) { LOG(ERROR) << "GetGeometry failed for window "
LOG(ERROR) << "XGetWindowAttributes failed for window "
<< static_cast<uint32_t>(parent_window_) << "."; << static_cast<uint32_t>(parent_window_) << ".";
return false; return false;
} }
size_ = gfx::Size(attributes.width, attributes.height); size_ = gfx::Size(geometry->width, geometry->height);
// Create a child window, with a CopyFromParent visual (to avoid inducing // Create a child window, with a CopyFromParent visual (to avoid inducing
// extra blits in the driver), that we can resize exactly in Resize(), // extra blits in the driver), that we can resize exactly in Resize(),
// correctly ordered with GL, so that we don't have invalid transient states. // correctly ordered with GL, so that we don't have invalid transient states.
// See https://crbug.com/326995. // See https://crbug.com/326995.
XSetWindowAttributes swa; set_window(connection->GenerateId<x11::Window>());
memset(&swa, 0, sizeof(swa)); connection->CreateWindow({
swa.background_pixmap = 0; .wid = window(),
swa.bit_gravity = NorthWestGravity; .parent = parent_window_,
window_ = XCreateWindow(x11_display, static_cast<uint32_t>(parent_window_), 0, .width = size_.width(),
0, size_.width(), size_.height(), 0, .height = size_.height(),
static_cast<int>(x11::WindowClass::CopyFromParent), .c_class = x11::WindowClass::InputOutput,
static_cast<int>(x11::WindowClass::InputOutput), .background_pixmap = x11::Pixmap::None,
nullptr, CWBackPixmap | CWBitGravity, &swa); .bit_gravity = x11::Gravity::NorthWest,
XMapWindow(x11_display, window_); .event_mask = x11::EventMask::Exposure,
XSelectInput(x11_display, window_, ExposureMask); });
XFlush(x11_display); connection->MapWindow({window()});
connection->Flush();
return true; return true;
} }
...@@ -54,10 +55,10 @@ void NativeViewGLSurfaceEGLX11GLES2::Destroy() { ...@@ -54,10 +55,10 @@ void NativeViewGLSurfaceEGLX11GLES2::Destroy() {
NativeViewGLSurfaceEGLX11::Destroy(); NativeViewGLSurfaceEGLX11::Destroy();
if (window_) { if (window_) {
Display* x11_display = GetXNativeDisplay(); auto* connection = GetXNativeConnection();
XDestroyWindow(x11_display, window_); connection->DestroyWindow({window()});
window_ = 0; window_ = 0;
XFlush(x11_display); connection->Flush();
} }
} }
...@@ -65,10 +66,10 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() { ...@@ -65,10 +66,10 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
if (!config_) { if (!config_) {
// Get a config compatible with the window // Get a config compatible with the window
DCHECK(window_); DCHECK(window_);
XWindowAttributes win_attribs; auto* connection = GetXNativeConnection();
if (!XGetWindowAttributes(GetXNativeDisplay(), window_, &win_attribs)) { auto geometry = connection->GetGeometry({window()}).Sync();
if (!geometry)
return nullptr; return nullptr;
}
// Try matching the window depth with an alpha channel, // Try matching the window depth with an alpha channel,
// because we're worried the destination alpha width could // because we're worried the destination alpha width could
...@@ -90,7 +91,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() { ...@@ -90,7 +91,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
EGL_SURFACE_TYPE, EGL_SURFACE_TYPE,
EGL_WINDOW_BIT | EGL_PBUFFER_BIT, EGL_WINDOW_BIT | EGL_PBUFFER_BIT,
EGL_NONE}; EGL_NONE};
config_attribs[kBufferSizeOffset] = win_attribs.depth; config_attribs[kBufferSizeOffset] = geometry->depth;
EGLDisplay display = GetHardwareDisplay(); EGLDisplay display = GetHardwareDisplay();
EGLint num_configs; EGLint num_configs;
...@@ -109,7 +110,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() { ...@@ -109,7 +110,7 @@ EGLConfig NativeViewGLSurfaceEGLX11GLES2::GetConfig() {
return nullptr; return nullptr;
} }
if (config_depth == win_attribs.depth) { if (config_depth == geometry->depth) {
return config_; return config_;
} }
} }
...@@ -140,7 +141,13 @@ bool NativeViewGLSurfaceEGLX11GLES2::Resize(const gfx::Size& size, ...@@ -140,7 +141,13 @@ bool NativeViewGLSurfaceEGLX11GLES2::Resize(const gfx::Size& size,
size_ = size; size_ = size;
eglWaitGL(); eglWaitGL();
XResizeWindow(GetXNativeDisplay(), window_, size.width(), size.height()); auto* connection = GetXNativeConnection();
connection->ConfigureWindow({
.window = window(),
.width = size.width(),
.height = size.height(),
});
connection->Flush();
eglWaitNative(EGL_CORE_NATIVE_ENGINE); eglWaitNative(EGL_CORE_NATIVE_ENGINE);
return true; return true;
......
...@@ -34,6 +34,11 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11GLES2 ...@@ -34,6 +34,11 @@ class GL_EXPORT NativeViewGLSurfaceEGLX11GLES2
protected: protected:
~NativeViewGLSurfaceEGLX11GLES2() override; ~NativeViewGLSurfaceEGLX11GLES2() override;
x11::Window window() const { return static_cast<x11::Window>(window_); }
void set_window(x11::Window window) {
window_ = static_cast<uint32_t>(window);
}
private: private:
// XEventDispatcher: // XEventDispatcher:
bool DispatchXEvent(x11::Event* xev) override; bool DispatchXEvent(x11::Event* xev) override;
......
This diff is collapsed.
...@@ -106,7 +106,9 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX { ...@@ -106,7 +106,9 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX {
// Checks if event is Expose for child window. // Checks if event is Expose for child window.
bool CanHandleEvent(x11::Event* xevent); bool CanHandleEvent(x11::Event* xevent);
gfx::AcceleratedWidget window() const { return window_; } gfx::AcceleratedWidget window() const {
return static_cast<gfx::AcceleratedWidget>(window_);
}
private: private:
// The handle for the drawable to make current or swap. // The handle for the drawable to make current or swap.
...@@ -116,7 +118,7 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX { ...@@ -116,7 +118,7 @@ class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX {
gfx::AcceleratedWidget parent_window_; gfx::AcceleratedWidget parent_window_;
// Child window, used to control resizes so that they're in-order with GL. // Child window, used to control resizes so that they're in-order with GL.
gfx::AcceleratedWidget window_; x11::Window window_;
// GLXDrawable for the window. // GLXDrawable for the window.
GLXWindow glx_window_; GLXWindow glx_window_;
...@@ -155,7 +157,7 @@ class GL_EXPORT UnmappedNativeViewGLSurfaceGLX : public GLSurfaceGLX { ...@@ -155,7 +157,7 @@ class GL_EXPORT UnmappedNativeViewGLSurfaceGLX : public GLSurfaceGLX {
gfx::Size size_; gfx::Size size_;
GLXFBConfig config_; GLXFBConfig config_;
// Unmapped dummy window, used to provide a compatible surface. // Unmapped dummy window, used to provide a compatible surface.
gfx::AcceleratedWidget window_; x11::Window window_;
// GLXDrawable for the window. // GLXDrawable for the window.
GLXWindow glx_window_; GLXWindow glx_window_;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_path.h" #include "ui/gfx/x/x11_path.h"
#include "ui/gfx/x/xproto.h"
#include "ui/views/test/widget_test.h" #include "ui/views/test/widget_test.h"
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
...@@ -144,11 +145,13 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive { ...@@ -144,11 +145,13 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive {
// Creates and shows an X window with |bounds|. // Creates and shows an X window with |bounds|.
x11::Window CreateAndShowXWindow(const gfx::Rect& bounds) { x11::Window CreateAndShowXWindow(const gfx::Rect& bounds) {
x11::Window root = ui::GetX11RootWindow(); x11::Window root = ui::GetX11RootWindow();
x11::Window window = static_cast<x11::Window>( auto window = connection()->GenerateId<x11::Window>();
XCreateSimpleWindow(xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1, connection()->CreateWindow({
0, // border_width .wid = window,
0, // border .parent = root,
0)); // background .width = 1,
.height = 1,
});
ui::SetUseOSWindowFrame(window, false); ui::SetUseOSWindowFrame(window, false);
ShowAndSetXWindowBounds(window, bounds); ShowAndSetXWindowBounds(window, bounds);
...@@ -168,6 +171,7 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive { ...@@ -168,6 +171,7 @@ class X11TopmostWindowFinderTest : public test::DesktopWidgetTestInteractive {
CWX | CWY | CWWidth | CWHeight, &changes); CWX | CWY | CWWidth | CWHeight, &changes);
} }
x11::Connection* connection() { return x11::Connection::Get(); }
Display* xdisplay() { return gfx::GetXDisplay(); } Display* xdisplay() { return gfx::GetXDisplay(); }
// Returns the topmost X window at the passed in screen position. // Returns the topmost X window at the passed in screen position.
...@@ -261,7 +265,7 @@ TEST_F(X11TopmostWindowFinderTest, Basic) { ...@@ -261,7 +265,7 @@ TEST_F(X11TopmostWindowFinderTest, Basic) {
EXPECT_EQ(window1, EXPECT_EQ(window1,
FindTopmostLocalProcessWindowWithIgnore(150, 195, window3)); FindTopmostLocalProcessWindowWithIgnore(150, 195, window3));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(x11_window2)); connection()->DestroyWindow({x11_window2});
} }
// Test that the minimized state is properly handled. // Test that the minimized state is properly handled.
...@@ -298,7 +302,7 @@ TEST_F(X11TopmostWindowFinderTest, Minimized) { ...@@ -298,7 +302,7 @@ TEST_F(X11TopmostWindowFinderTest, Minimized) {
EXPECT_NE(x11_window1, FindTopmostXWindowAt(350, 150)); EXPECT_NE(x11_window1, FindTopmostXWindowAt(350, 150));
EXPECT_NE(x11_window2, FindTopmostXWindowAt(350, 150)); EXPECT_NE(x11_window2, FindTopmostXWindowAt(350, 150));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(x11_window2)); connection()->DestroyWindow({x11_window2});
} }
// Test that non-rectangular windows are properly handled. // Test that non-rectangular windows are properly handled.
...@@ -342,7 +346,7 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangular) { ...@@ -342,7 +346,7 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangular) {
EXPECT_NE(window1, FindTopmostXWindowAt(305, 105)); EXPECT_NE(window1, FindTopmostXWindowAt(305, 105));
EXPECT_NE(window2, FindTopmostXWindowAt(305, 105)); EXPECT_NE(window2, FindTopmostXWindowAt(305, 105));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(window2)); connection()->DestroyWindow({window2});
} }
// Test that a window with an empty shape are properly handled. // Test that a window with an empty shape are properly handled.
...@@ -399,19 +403,19 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) { ...@@ -399,19 +403,19 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) {
x11::Window window = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100)); x11::Window window = CreateAndShowXWindow(gfx::Rect(100, 100, 100, 100));
x11::Window root = ui::GetX11RootWindow(); x11::Window root = ui::GetX11RootWindow();
XSetWindowAttributes swa; auto menu_window = connection()->GenerateId<x11::Window>();
swa.override_redirect = true; connection()->CreateWindow({
x11::Window menu_window = static_cast<x11::Window>(XCreateWindow( .wid = menu_window,
xdisplay(), static_cast<uint32_t>(root), 0, 0, 1, 1, .parent = root,
0, // border width .width = 1,
static_cast<int>(x11::WindowClass::CopyFromParent), // depth .height = 1,
static_cast<int>(x11::WindowClass::InputOutput), .c_class = x11::WindowClass::CopyFromParent,
nullptr, // visual .override_redirect = x11::Bool32(true),
CWOverrideRedirect, &swa)); });
{
ui::SetAtomProperty(menu_window, "_NET_WM_WINDOW_TYPE", "ATOM", ui::SetAtomProperty(menu_window, "_NET_WM_WINDOW_TYPE", "ATOM",
gfx::GetAtom("_NET_WM_WINDOW_TYPE_MENU")); gfx::GetAtom("_NET_WM_WINDOW_TYPE_MENU"));
}
ui::SetUseOSWindowFrame(menu_window, false); ui::SetUseOSWindowFrame(menu_window, false);
ShowAndSetXWindowBounds(menu_window, gfx::Rect(140, 110, 100, 100)); ShowAndSetXWindowBounds(menu_window, gfx::Rect(140, 110, 100, 100));
ui::X11EventSource::GetInstance()->DispatchXEvents(); ui::X11EventSource::GetInstance()->DispatchXEvents();
...@@ -425,8 +429,8 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) { ...@@ -425,8 +429,8 @@ TEST_F(X11TopmostWindowFinderTest, DISABLED_Menu) {
EXPECT_EQ(menu_window, FindTopmostXWindowAt(150, 120)); EXPECT_EQ(menu_window, FindTopmostXWindowAt(150, 120));
EXPECT_EQ(menu_window, FindTopmostXWindowAt(210, 120)); EXPECT_EQ(menu_window, FindTopmostXWindowAt(210, 120));
XDestroyWindow(xdisplay(), static_cast<uint32_t>(window)); connection()->DestroyWindow({window});
XDestroyWindow(xdisplay(), static_cast<uint32_t>(menu_window)); connection()->DestroyWindow({menu_window});
} }
} // namespace views } // namespace views
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