Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Unified Diff: ui/base/x/x11_util.cc

Issue 23460052: Move XID, XDisplay, GetXDisplay and a few other types to ui/gfx/x/x11_types.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/x/x11_util.cc
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index a51e6e54764fd7d96da2c10cfedefd939ad9f1ea..58c2c698a3cf825780d1c41ba5ce88bd7972b90c 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -72,11 +72,11 @@ namespace {
// Used to cache the XRenderPictFormat for a visual/display pair.
struct CachedPictFormat {
- bool equals(Display* display, Visual* visual) const {
+ bool equals(XDisplay* display, Visual* visual) const {
return display == this->display && visual == this->visual;
}
- Display* display;
+ XDisplay* display;
Visual* visual;
XRenderPictFormat* format;
};
@@ -94,7 +94,7 @@ CachedPictFormats* get_cached_pict_formats() {
// Maximum number of CachedPictFormats we keep around.
const size_t kMaxCacheSize = 5;
-int DefaultX11ErrorHandler(Display* d, XErrorEvent* e) {
+int DefaultX11ErrorHandler(XDisplay* d, XErrorEvent* e) {
if (base::MessageLoop::current()) {
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(&LogErrorEventDescription, d, *e));
@@ -109,7 +109,7 @@ int DefaultX11ErrorHandler(Display* d, XErrorEvent* e) {
return 0;
}
-int DefaultX11IOErrorHandler(Display* d) {
+int DefaultX11IOErrorHandler(XDisplay* d) {
// If there's an IO error it likely means the X server has gone away
LOG(ERROR) << "X IO error received (X server probably went away)";
_exit(1);
@@ -121,7 +121,7 @@ bool GetProperty(XID window, const std::string& property_name, long max_length,
unsigned char** property) {
Atom property_atom = GetAtom(property_name.c_str());
unsigned long remaining_bytes = 0;
- return XGetWindowProperty(GetXDisplay(),
+ return XGetWindowProperty(gfx::GetXDisplay(),
window,
property_atom,
0, // offset into property data to read
@@ -159,7 +159,7 @@ int XKeyEventType(ui::EventType type) {
// Converts KeyboardCode to XKeyEvent keycode.
unsigned int XKeyEventKeyCode(ui::KeyboardCode key_code,
int flags,
- Display* display) {
+ XDisplay* display) {
const int keysym = XKeysymForWindowsKeyCode(key_code,
flags & ui::EF_SHIFT_DOWN);
// Tests assume the keycode for XK_less is equal to the one of XK_comma,
@@ -182,14 +182,14 @@ class XCursorCache {
std::pair<std::map<int, ::Cursor>::iterator, bool> it = cache_.insert(
std::make_pair(cursor_shape, 0));
if (it.second) {
- Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
+ XDisplay* display = base::MessagePumpForUI::GetDefaultXDisplay();
it.first->second = XCreateFontCursor(display, cursor_shape);
}
return it.first->second;
}
void Clear() {
- Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
+ XDisplay* display = base::MessagePumpForUI::GetDefaultXDisplay();
for (std::map<int, ::Cursor>::iterator it =
cache_.begin(); it != cache_.end(); ++it) {
XFreeCursor(display, it->second);
@@ -243,12 +243,12 @@ class XCustomCursorCache {
XCustomCursor(XcursorImage* image)
: image_(image),
ref_(1) {
- cursor_ = XcursorImageLoadCursor(GetXDisplay(), image);
+ cursor_ = XcursorImageLoadCursor(gfx::GetXDisplay(), image);
}
~XCustomCursor() {
XcursorImageDestroy(image_);
- XFreeCursor(GetXDisplay(), cursor_);
+ XFreeCursor(gfx::GetXDisplay(), cursor_);
}
::Cursor cursor() const { return cursor_; }
@@ -292,7 +292,7 @@ class XButtonMap {
}
void UpdateMapping() {
- count_ = XGetPointerMapping(ui::GetXDisplay(), map_, arraysize(map_));
+ count_ = XGetPointerMapping(gfx::GetXDisplay(), map_, arraysize(map_));
}
int GetMappedButton(int button) {
@@ -317,7 +317,7 @@ class XButtonMap {
bool IsShapeAvailable() {
int dummy;
static bool is_shape_available =
- XShapeQueryExtension(ui::GetXDisplay(), &dummy, &dummy);
+ XShapeQueryExtension(gfx::GetXDisplay(), &dummy, &dummy);
return is_shape_available;
}
@@ -325,14 +325,10 @@ bool IsShapeAvailable() {
} // namespace
bool XDisplayExists() {
- return (GetXDisplay() != NULL);
+ return (gfx::GetXDisplay() != NULL);
}
-Display* GetXDisplay() {
- return base::MessagePumpForUI::GetDefaultXDisplay();
-}
-
-static SharedMemorySupport DoQuerySharedMemorySupport(Display* dpy) {
+static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) {
int dummy;
Bool pixmaps_supported;
// Query the server's support for XSHM.
@@ -389,7 +385,7 @@ static SharedMemorySupport DoQuerySharedMemorySupport(Display* dpy) {
return pixmaps_supported ? SHARED_MEMORY_PIXMAP : SHARED_MEMORY_PUTIMAGE;
}
-SharedMemorySupport QuerySharedMemorySupport(Display* dpy) {
+SharedMemorySupport QuerySharedMemorySupport(XDisplay* dpy) {
static SharedMemorySupport shared_memory_support = SHARED_MEMORY_NONE;
static bool shared_memory_support_cached = false;
@@ -402,7 +398,7 @@ SharedMemorySupport QuerySharedMemorySupport(Display* dpy) {
return shared_memory_support;
}
-bool QueryRenderSupport(Display* dpy) {
+bool QueryRenderSupport(XDisplay* dpy) {
static bool render_supported = false;
static bool render_supported_cached = false;
@@ -418,7 +414,7 @@ bool QueryRenderSupport(Display* dpy) {
return render_supported;
}
-int GetDefaultScreen(Display* display) {
+int GetDefaultScreen(XDisplay* display) {
return XDefaultScreen(display);
}
@@ -493,7 +489,7 @@ int CoalescePendingMotionEvents(const XEvent* xev,
XEvent* last_event) {
XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
int num_coalesced = 0;
- Display* display = xev->xany.display;
+ XDisplay* display = xev->xany.display;
int event_type = xev->xgeneric.evtype;
DCHECK_EQ(event_type, XI_Motion);
@@ -563,13 +559,13 @@ int CoalescePendingMotionEvents(const XEvent* xev,
void HideHostCursor() {
CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor,
- (CreateInvisibleCursor(), ui::GetXDisplay()));
- XDefineCursor(ui::GetXDisplay(), DefaultRootWindow(ui::GetXDisplay()),
+ (CreateInvisibleCursor(), gfx::GetXDisplay()));
+ XDefineCursor(gfx::GetXDisplay(), DefaultRootWindow(gfx::GetXDisplay()),
invisible_cursor.get());
}
::Cursor CreateInvisibleCursor() {
- Display* xdisplay = ui::GetXDisplay();
+ XDisplay* xdisplay = gfx::GetXDisplay();
::Cursor invisible_cursor;
char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
XColor black;
@@ -584,7 +580,7 @@ void HideHostCursor() {
}
XID GetX11RootWindow() {
- return DefaultRootWindow(GetXDisplay());
+ return DefaultRootWindow(gfx::GetXDisplay());
}
bool GetCurrentDesktop(int* desktop) {
@@ -621,7 +617,7 @@ void* GetVisualFromGtkWidget(GtkWidget* widget) {
void SetHideTitlebarWhenMaximizedProperty(XID window,
HideTitlebarWhenMaximized property) {
uint32 hide = property;
- XChangeProperty(GetXDisplay(),
+ XChangeProperty(gfx::GetXDisplay(),
window,
GetAtom("_GTK_HIDE_TITLEBAR_WHEN_MAXIMIZED"),
XA_CARDINAL,
@@ -632,7 +628,7 @@ void SetHideTitlebarWhenMaximizedProperty(XID window,
}
void ClearX11DefaultRootWindow() {
- Display* display = GetXDisplay();
+ XDisplay* display = gfx::GetXDisplay();
XID root_window = GetX11RootWindow();
gfx::Rect root_bounds;
if (!GetWindowRect(root_window, &root_bounds)) {
@@ -651,7 +647,7 @@ void ClearX11DefaultRootWindow() {
XFreeGC(display, gc);
}
-int BitsPerPixelForPixmapDepth(Display* dpy, int depth) {
+int BitsPerPixelForPixmapDepth(XDisplay* dpy, int depth) {
int count;
XPixmapFormatValues* formats = XListPixmapFormats(dpy, &count);
if (!formats)
@@ -671,7 +667,7 @@ int BitsPerPixelForPixmapDepth(Display* dpy, int depth) {
bool IsWindowVisible(XID window) {
XWindowAttributes win_attributes;
- if (!XGetWindowAttributes(GetXDisplay(), window, &win_attributes))
+ if (!XGetWindowAttributes(gfx::GetXDisplay(), window, &win_attributes))
return false;
if (win_attributes.map_state != IsViewable)
return false;
@@ -690,11 +686,11 @@ bool GetWindowRect(XID window, gfx::Rect* rect) {
unsigned int width, height;
unsigned int border_width, depth;
- if (!XGetGeometry(GetXDisplay(), window, &root, &x, &y,
+ if (!XGetGeometry(gfx::GetXDisplay(), window, &root, &x, &y,
&width, &height, &border_width, &depth))
return false;
- if (!XTranslateCoordinates(GetXDisplay(), window, root,
+ if (!XTranslateCoordinates(gfx::GetXDisplay(), window, root,
0, 0, &x, &y, &child))
return false;
@@ -723,7 +719,7 @@ bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
int dummy;
int input_rects_size = 0;
XRectangle* input_rects = XShapeGetRectangles(
- ui::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy);
+ gfx::GetXDisplay(), window, ShapeInput, &input_rects_size, &dummy);
if (!input_rects)
return true;
bool is_in_input_rects = false;
@@ -771,7 +767,7 @@ bool GetRawBytesOfProperty(XID window,
Atom prop_type = None;
int prop_format = 0;
unsigned char* property_data = NULL;
- if (XGetWindowProperty(GetXDisplay(), window, property,
+ if (XGetWindowProperty(gfx::GetXDisplay(), window, property,
0, 0x1FFFFFFF /* MAXINT32 / 4 */, False,
AnyPropertyType, &prop_type, &prop_format,
&nitems, &nbytes, &property_data) != Success) {
@@ -957,7 +953,7 @@ bool SetIntArrayProperty(XID window,
data[i] = value[i];
X11ErrorTracker err_tracker;
- XChangeProperty(ui::GetXDisplay(),
+ XChangeProperty(gfx::GetXDisplay(),
window,
name_atom,
type_atom,
@@ -982,7 +978,7 @@ bool SetAtomArrayProperty(XID window,
data[i] = value[i];
X11ErrorTracker err_tracker;
- XChangeProperty(ui::GetXDisplay(),
+ XChangeProperty(gfx::GetXDisplay(),
window,
name_atom,
type_atom,
@@ -999,11 +995,11 @@ Atom GetAtom(const char* name) {
gdk_display_get_default(), name);
#else
// TODO(derat): Cache atoms to avoid round-trips to the server.
- return XInternAtom(GetXDisplay(), name, false);
+ return XInternAtom(gfx::GetXDisplay(), name, false);
#endif
}
-void SetWindowClassHint(Display* display,
+void SetWindowClassHint(XDisplay* display,
XID window,
std::string res_name,
std::string res_class) {
@@ -1021,7 +1017,7 @@ XID GetParentWindow(XID window) {
XID parent = None;
XID* children = NULL;
unsigned int num_children = 0;
- XQueryTree(GetXDisplay(), window, &root, &parent, &children, &num_children);
+ XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children, &num_children);
if (children)
XFree(children);
return parent;
@@ -1042,7 +1038,7 @@ bool GetWindowDesktop(XID window, int* desktop) {
return GetIntProperty(window, "_NET_WM_DESKTOP", desktop);
}
-std::string GetX11ErrorString(Display* display, int err) {
+std::string GetX11ErrorString(XDisplay* display, int err) {
char buffer[256];
XGetErrorText(display, err, buffer, arraysize(buffer));
return buffer;
@@ -1051,7 +1047,7 @@ std::string GetX11ErrorString(Display* display, int err) {
// Returns true if |window| is a named window.
bool IsWindowNamed(XID window) {
XTextProperty prop;
- if (!XGetWMName(GetXDisplay(), window, &prop) || !prop.value)
+ if (!XGetWMName(gfx::GetXDisplay(), window, &prop) || !prop.value)
return false;
XFree(prop.value);
@@ -1065,7 +1061,7 @@ bool EnumerateChildren(EnumerateWindowsDelegate* delegate, XID window,
XID root, parent, *children;
unsigned int num_children;
- int status = XQueryTree(GetXDisplay(), window, &root, &parent, &children,
+ int status = XQueryTree(gfx::GetXDisplay(), window, &root, &parent, &children,
&num_children);
if (status == 0)
return false;
@@ -1157,10 +1153,10 @@ void RestackWindow(XID window, XID sibling, bool above) {
XWindowChanges changes;
changes.sibling = sibling;
changes.stack_mode = above ? Above : Below;
- XConfigureWindow(GetXDisplay(), window, CWSibling | CWStackMode, &changes);
+ XConfigureWindow(gfx::GetXDisplay(), window, CWSibling | CWStackMode, &changes);
}
-XSharedMemoryId AttachSharedMemory(Display* display, int shared_memory_key) {
+XSharedMemoryId AttachSharedMemory(XDisplay* display, int shared_memory_key) {
DCHECK(QuerySharedMemorySupport(display));
XShmSegmentInfo shminfo;
@@ -1181,7 +1177,7 @@ XSharedMemoryId AttachSharedMemory(Display* display, int shared_memory_key) {
return shminfo.shmseg;
}
-void DetachSharedMemory(Display* display, XSharedMemoryId shmseg) {
+void DetachSharedMemory(XDisplay* display, XSharedMemoryId shmseg) {
DCHECK(QuerySharedMemorySupport(display));
XShmSegmentInfo shminfo;
@@ -1197,7 +1193,7 @@ bool CopyAreaToCanvas(XID drawable,
gfx::Point dest_offset,
gfx::Canvas* canvas) {
ui::XScopedImage scoped_image(
- XGetImage(GetXDisplay(), drawable,
+ XGetImage(gfx::GetXDisplay(), drawable,
source_bounds.x(), source_bounds.y(),
source_bounds.width(), source_bounds.height(),
AllPlanes, ZPixmap));
@@ -1241,14 +1237,14 @@ bool CopyAreaToCanvas(XID drawable,
return true;
}
-XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap) {
+XID CreatePictureFromSkiaPixmap(XDisplay* display, XID pixmap) {
XID picture = XRenderCreatePicture(
display, pixmap, GetRenderARGB32Format(display), 0, NULL);
return picture;
}
-void PutARGBImage(Display* display,
+void PutARGBImage(XDisplay* display,
void* visual, int depth,
XID pixmap, void* pixmap_gc,
const uint8* data,
@@ -1262,7 +1258,7 @@ void PutARGBImage(Display* display,
width, height);
}
-void PutARGBImage(Display* display,
+void PutARGBImage(XDisplay* display,
void* visual, int depth,
XID pixmap, void* pixmap_gc,
const uint8* data,
@@ -1367,11 +1363,11 @@ void PutARGBImage(Display* display,
}
}
-void FreePicture(Display* display, XID picture) {
+void FreePicture(XDisplay* display, XID picture) {
XRenderFreePicture(display, picture);
}
-void FreePixmap(Display* display, XID pixmap) {
+void FreePixmap(XDisplay* display, XID pixmap) {
XFreePixmap(display, pixmap);
}
@@ -1457,7 +1453,7 @@ bool ChangeWindowDesktop(XID window, XID destination) {
event.xclient.data.l[0] = desktop;
event.xclient.data.l[1] = 1; // source indication
- int result = XSendEvent(GetXDisplay(), GetX11RootWindow(), False,
+ int result = XSendEvent(gfx::GetXDisplay(), GetX11RootWindow(), False,
SubstructureNotifyMask, &event);
return result == Success;
}
@@ -1508,7 +1504,7 @@ bool IsX11WindowFullScreen(XID window) {
//
// TODO(erg): Actually doing this correctly would require pulling out xrandr,
// which we don't even do in the desktop screen yet.
- ::Display* display = ui::GetXDisplay();
+ ::XDisplay* display = gfx::GetXDisplay();
::Screen* screen = DefaultScreenOfDisplay(display);
int width = WidthOfScreen(screen);
int height = HeightOfScreen(screen);
@@ -1536,7 +1532,7 @@ void InitXKeyEventForTesting(EventType type,
int flags,
XEvent* event) {
CHECK(event);
- Display* display = GetXDisplay();
+ XDisplay* display = gfx::GetXDisplay();
XKeyEvent key_event;
key_event.type = XKeyEventType(type);
CHECK_NE(0, key_event.type);
@@ -1586,7 +1582,7 @@ void XScopedImage::reset(XImage* image) {
image_ = image;
}
-XScopedCursor::XScopedCursor(::Cursor cursor, Display* display)
+XScopedCursor::XScopedCursor(::Cursor cursor, XDisplay* display)
: cursor_(cursor),
display_(display) {
}
@@ -1608,7 +1604,7 @@ void XScopedCursor::reset(::Cursor cursor) {
// ----------------------------------------------------------------------------
// These functions are declared in x11_util_internal.h because they require
// XLib.h to be included, and it conflicts with many other headers.
-XRenderPictFormat* GetRenderARGB32Format(Display* dpy) {
+XRenderPictFormat* GetRenderARGB32Format(XDisplay* dpy) {
static XRenderPictFormat* pictformat = NULL;
if (pictformat)
return pictformat;
@@ -1644,7 +1640,7 @@ XRenderPictFormat* GetRenderARGB32Format(Display* dpy) {
return pictformat;
}
-XRenderPictFormat* GetRenderVisualFormat(Display* dpy, Visual* visual) {
+XRenderPictFormat* GetRenderVisualFormat(XDisplay* dpy, Visual* visual) {
DCHECK(QueryRenderSupport(dpy));
CachedPictFormats* formats = get_cached_pict_formats();
@@ -1688,7 +1684,7 @@ void SetX11ErrorHandlers(XErrorHandler error_handler,
io_error_handler ? io_error_handler : DefaultX11IOErrorHandler);
}
-void LogErrorEventDescription(Display* dpy,
+void LogErrorEventDescription(XDisplay* dpy,
const XErrorEvent& error_event) {
char error_str[256];
char request_str[256];
« ui/base/x/x11_util.h ('K') | « ui/base/x/x11_util.h ('k') | ui/gfx/x/x11_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698