OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/x/x11_types.h" | 5 #include "ui/gfx/x/x11_types.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "build/build_config.h" |
11 #include "ui/gfx/x/x11_switches.h" | 12 #include "ui/gfx/x/x11_switches.h" |
12 | 13 |
13 namespace gfx { | 14 namespace gfx { |
14 | 15 |
15 XDisplay* GetXDisplay() { | 16 XDisplay* GetXDisplay() { |
16 static XDisplay* display = NULL; | 17 static XDisplay* display = NULL; |
17 if (!display) | 18 if (!display) |
18 display = OpenNewXDisplay(); | 19 display = OpenNewXDisplay(); |
19 return display; | 20 return display; |
20 } | 21 } |
21 | 22 |
22 XDisplay* OpenNewXDisplay() { | 23 XDisplay* OpenNewXDisplay() { |
23 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
24 return XOpenDisplay(NULL); | 25 return XOpenDisplay(NULL); |
25 #else | 26 #else |
26 std::string display_str = base::CommandLine::ForCurrentProcess()-> | 27 std::string display_str = base::CommandLine::ForCurrentProcess()-> |
27 GetSwitchValueASCII(switches::kX11Display); | 28 GetSwitchValueASCII(switches::kX11Display); |
28 return XOpenDisplay(display_str.empty() ? NULL : display_str.c_str()); | 29 return XOpenDisplay(display_str.empty() ? NULL : display_str.c_str()); |
29 #endif | 30 #endif |
30 } | 31 } |
31 | 32 |
32 void PutARGBImage(XDisplay* display, | 33 void PutARGBImage(XDisplay* display, |
33 void* visual, int depth, | 34 void* visual, |
34 XID pixmap, void* pixmap_gc, | 35 int depth, |
35 const uint8* data, | 36 XID pixmap, |
36 int width, int height) { | 37 void* pixmap_gc, |
| 38 const uint8_t* data, |
| 39 int width, |
| 40 int height) { |
37 PutARGBImage(display, | 41 PutARGBImage(display, |
38 visual, depth, | 42 visual, depth, |
39 pixmap, pixmap_gc, | 43 pixmap, pixmap_gc, |
40 data, width, height, | 44 data, width, height, |
41 0, 0, // src_x, src_y | 45 0, 0, // src_x, src_y |
42 0, 0, // dst_x, dst_y | 46 0, 0, // dst_x, dst_y |
43 width, height); | 47 width, height); |
44 } | 48 } |
45 | 49 |
46 int BitsPerPixelForPixmapDepth(XDisplay* dpy, int depth) { | 50 int BitsPerPixelForPixmapDepth(XDisplay* dpy, int depth) { |
47 int count; | 51 int count; |
48 XScopedPtr<XPixmapFormatValues[]> formats(XListPixmapFormats(dpy, &count)); | 52 XScopedPtr<XPixmapFormatValues[]> formats(XListPixmapFormats(dpy, &count)); |
49 if (!formats) | 53 if (!formats) |
50 return -1; | 54 return -1; |
51 | 55 |
52 for (int i = 0; i < count; ++i) { | 56 for (int i = 0; i < count; ++i) { |
53 if (formats[i].depth == depth) | 57 if (formats[i].depth == depth) |
54 return formats[i].bits_per_pixel; | 58 return formats[i].bits_per_pixel; |
55 } | 59 } |
56 | 60 |
57 return -1; | 61 return -1; |
58 } | 62 } |
59 | 63 |
60 void PutARGBImage(XDisplay* display, | 64 void PutARGBImage(XDisplay* display, |
61 void* visual, int depth, | 65 void* visual, |
62 XID pixmap, void* pixmap_gc, | 66 int depth, |
63 const uint8* data, | 67 XID pixmap, |
64 int data_width, int data_height, | 68 void* pixmap_gc, |
65 int src_x, int src_y, | 69 const uint8_t* data, |
66 int dst_x, int dst_y, | 70 int data_width, |
67 int copy_width, int copy_height) { | 71 int data_height, |
| 72 int src_x, |
| 73 int src_y, |
| 74 int dst_x, |
| 75 int dst_y, |
| 76 int copy_width, |
| 77 int copy_height) { |
68 // TODO(scherkus): potential performance impact... consider passing in as a | 78 // TODO(scherkus): potential performance impact... consider passing in as a |
69 // parameter. | 79 // parameter. |
70 int pixmap_bpp = BitsPerPixelForPixmapDepth(display, depth); | 80 int pixmap_bpp = BitsPerPixelForPixmapDepth(display, depth); |
71 | 81 |
72 XImage image; | 82 XImage image; |
73 memset(&image, 0, sizeof(image)); | 83 memset(&image, 0, sizeof(image)); |
74 | 84 |
75 image.width = data_width; | 85 image.width = data_width; |
76 image.height = data_height; | 86 image.height = data_height; |
77 image.format = ZPixmap; | 87 image.format = ZPixmap; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 free(orig_bitmap16); | 167 free(orig_bitmap16); |
158 } else { | 168 } else { |
159 LOG(FATAL) << "Sorry, we don't support your visual depth without " | 169 LOG(FATAL) << "Sorry, we don't support your visual depth without " |
160 "Xrender support (depth:" << depth | 170 "Xrender support (depth:" << depth |
161 << " bpp:" << pixmap_bpp << ")"; | 171 << " bpp:" << pixmap_bpp << ")"; |
162 } | 172 } |
163 } | 173 } |
164 | 174 |
165 } // namespace gfx | 175 } // namespace gfx |
166 | 176 |
OLD | NEW |