michael@0: // Copyright (c) 2009 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef CHROME_COMMON_X11_UTIL_H_ michael@0: #define CHROME_COMMON_X11_UTIL_H_ michael@0: michael@0: // This file declares utility functions for X11 (Linux only). michael@0: // michael@0: // These functions do not require the Xlib headers to be included (which is why michael@0: // we use a void* for Visual*). The Xlib headers are highly polluting so we try michael@0: // hard to limit their spread into the rest of the code. michael@0: michael@0: #if (MOZ_WIDGET_GTK == 2) michael@0: typedef struct _GdkDrawable GdkWindow; michael@0: #else michael@0: typedef struct _GdkWindow GdkWindow; michael@0: #endif michael@0: typedef struct _GtkWidget GtkWidget; michael@0: typedef unsigned long XID; michael@0: typedef struct _XDisplay Display; michael@0: michael@0: namespace base { michael@0: class Thread; michael@0: } michael@0: namespace x11_util { michael@0: michael@0: // These functions use the GDK default display and this /must/ be called from michael@0: // the UI thread. Thus, they don't support multiple displays. michael@0: michael@0: // These functions cache their results. michael@0: michael@0: // Return an X11 connection for the current, primary display. michael@0: Display* GetXDisplay(); michael@0: // Return true iff the connection supports X shared memory michael@0: bool QuerySharedMemorySupport(Display* dpy); michael@0: // Return true iff the display supports Xrender michael@0: bool QueryRenderSupport(Display* dpy); michael@0: // Return the default screen number for the display michael@0: int GetDefaultScreen(Display* display); michael@0: michael@0: // These functions do not cache their results michael@0: michael@0: // Get the X window id for the default root window michael@0: XID GetX11RootWindow(); michael@0: // Get the X window id for the given GTK widget. michael@0: XID GetX11WindowFromGtkWidget(GtkWidget*); michael@0: XID GetX11WindowFromGdkWindow(GdkWindow*); michael@0: // Get a Visual from the given widget. Since we don't include the Xlib michael@0: // headers, this is returned as a void*. michael@0: void* GetVisualFromGtkWidget(GtkWidget*); michael@0: // Return the number of bits-per-pixel for a pixmap of the given depth michael@0: int BitsPerPixelForPixmapDepth(Display*, int depth); michael@0: michael@0: // Return a handle to a server side pixmap. |shared_memory_key| is a SysV michael@0: // IPC key. The shared memory region must contain 32-bit pixels. michael@0: XID AttachSharedMemory(Display* display, int shared_memory_support); michael@0: void DetachSharedMemory(Display* display, XID shmseg); michael@0: michael@0: // Return a handle to an XRender picture where |pixmap| is a handle to a michael@0: // pixmap containing Skia ARGB data. michael@0: XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap); michael@0: michael@0: void FreePicture(Display* display, XID picture); michael@0: void FreePixmap(Display* display, XID pixmap); michael@0: michael@0: // These functions are for performing X opertions outside of the UI thread. michael@0: michael@0: // Return the Display for the secondary X connection. We keep a second michael@0: // connection around for making X requests outside of the UI thread. michael@0: // This function may only be called from the BACKGROUND_X11 thread. michael@0: Display* GetSecondaryDisplay(); michael@0: michael@0: // Since one cannot include both WebKit header and Xlib headers in the same michael@0: // file (due to collisions), we wrap all the Xlib functions that we need here. michael@0: // These functions must be called on the BACKGROUND_X11 thread since they michael@0: // reference GetSecondaryDisplay(). michael@0: michael@0: // Get the position of the given window in screen coordinates as well as its michael@0: // current size. michael@0: bool GetWindowGeometry(int* x, int* y, unsigned* width, unsigned* height, michael@0: XID window); michael@0: michael@0: // Find the immediate parent of an X window. michael@0: // michael@0: // parent_window: (output) the parent window of |window|, or 0. michael@0: // parent_is_root: (output) true iff the parent of |window| is the root window. michael@0: bool GetWindowParent(XID* parent_window, bool* parent_is_root, XID window); michael@0: michael@0: } // namespace x11_util michael@0: michael@0: #endif // CHROME_COMMON_X11_UTIL_H_