1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_X_X11_UTIL_H_
6 #define UI_GFX_X_X11_UTIL_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/gfx/gfx_export.h"
12 typedef unsigned long XAtom
;
13 typedef unsigned long XID
;
14 typedef struct _XImage XImage
;
15 typedef struct _XGC
*GC
;
16 typedef struct _XDisplay XDisplay
;
24 template <class T
, class R
, R (*F
)(T
*)>
25 struct XObjectDeleter
{
26 inline void operator()(void* ptr
) const { F(static_cast<T
*>(ptr
)); }
29 template <class T
, class D
= XObjectDeleter
<void, int, XFree
>>
30 using XScopedPtr
= scoped_ptr
<T
, D
>;
32 // TODO(oshima|evan): This assume there is one display and doesn't work
33 // undef multiple displays/monitor environment. Remove this and change the
34 // chrome codebase to get the display from window.
35 GFX_EXPORT XDisplay
* GetXDisplay();
37 // This opens a new X11 XDisplay*, taking command line arguments into account.
38 GFX_EXPORT XDisplay
* OpenNewXDisplay();
40 // Return the number of bits-per-pixel for a pixmap of the given depth
41 GFX_EXPORT
int BitsPerPixelForPixmapDepth(XDisplay
* display
, int depth
);
43 // Draws ARGB data on the given pixmap using the given GC, converting to the
44 // server side visual depth as needed. Destination is assumed to be the same
45 // dimensions as |data| or larger. |data| is also assumed to be in row order
46 // with each line being exactly |width| * 4 bytes long.
47 GFX_EXPORT
void PutARGBImage(XDisplay
* display
,
48 void* visual
, int depth
,
49 XID pixmap
, void* pixmap_gc
,
51 int width
, int height
);
53 // Same as above only more general:
54 // - |data_width| and |data_height| refer to the data image
55 // - |src_x|, |src_y|, |copy_width| and |copy_height| define source region
56 // - |dst_x|, |dst_y|, |copy_width| and |copy_height| define destination region
57 GFX_EXPORT
void PutARGBImage(XDisplay
* display
,
58 void* visual
, int depth
,
59 XID pixmap
, void* pixmap_gc
,
61 int data_width
, int data_height
,
64 int copy_width
, int copy_height
);
68 #endif // UI_GFX_X_X11_UTIL_H_