Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | #include "qxcbimage.h" | - |
35 | #include <QtGui/QColor> | - |
36 | #include <QtGui/private/qimage_p.h> | - |
37 | #include <QtGui/private/qdrawhelper_p.h> | - |
38 | #ifdef XCB_USE_RENDER | - |
39 | #include <xcb/render.h> | - |
40 | | - |
41 | #define template template_param | - |
42 | | - |
43 | extern "C" { | - |
44 | #include <xcb/xcb_renderutil.h> | - |
45 | } | - |
46 | #undef template | - |
47 | #endif | - |
48 | | - |
49 | QT_BEGIN_NAMESPACE | - |
50 | | - |
51 | QImage::Format qt_xcb_imageFormatForVisual(QXcbConnection *connection, uint8_t depth, | - |
52 | const xcb_visualtype_t *visual) | - |
53 | { | - |
54 | const xcb_format_t *format = connection->formatForDepth(depth); | - |
55 | | - |
56 | if (!visual || !format)TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
| 0-22 |
57 | return QImage::Format_Invalid; never executed: return QImage::Format_Invalid; | 0 |
58 | | - |
59 | if (depth == 32 && format->bits_per_pixel == 32 && visual->red_mask == 0xff0000TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-22 |
60 | && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
61 | return QImage::Format_ARGB32_Premultiplied; never executed: return QImage::Format_ARGB32_Premultiplied; | 0 |
62 | | - |
63 | if (depth == 30 && format->bits_per_pixel == 32 && visual->red_mask == 0x3ffTRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-22 |
64 | && visual->green_mask == 0x0ffc00 && visual->blue_mask == 0x3ff00000)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
65 | return QImage::Format_BGR30; never executed: return QImage::Format_BGR30; | 0 |
66 | | - |
67 | if (depth == 30 && format->bits_per_pixel == 32 && visual->blue_mask == 0x3ffTRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-22 |
68 | && visual->green_mask == 0x0ffc00 && visual->red_mask == 0x3ff00000)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
69 | return QImage::Format_RGB30; never executed: return QImage::Format_RGB30; | 0 |
70 | | - |
71 | if (depth == 24 && format->bits_per_pixel == 32 && visual->red_mask == 0xff0000TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
| 0-22 |
72 | && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
| 0-22 |
73 | return QImage::Format_RGB32;executed 22 times by 3 tests: return QImage::Format_RGB32; Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| 22 |
74 | | - |
75 | if (depth == 16 && format->bits_per_pixel == 16 && visual->red_mask == 0xf800TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
76 | && visual->green_mask == 0x7e0 && visual->blue_mask == 0x1f)TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
77 | return QImage::Format_RGB16; never executed: return QImage::Format_RGB16; | 0 |
78 | | - |
79 | return QImage::Format_Invalid; never executed: return QImage::Format_Invalid; | 0 |
80 | } | - |
81 | | - |
82 | QPixmap qt_xcb_pixmapFromXPixmap(QXcbConnection *connection, xcb_pixmap_t pixmap, | - |
83 | int width, int height, int depth, | - |
84 | const xcb_visualtype_t *visual) | - |
85 | { | - |
86 | xcb_connection_t *conn = connection->xcb_connection(); | - |
87 | | - |
88 | xcb_get_image_cookie_t get_image_cookie = | - |
89 | xcb_get_image_unchecked(conn, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, | - |
90 | 0, 0, width, height, 0xffffffff); | - |
91 | | - |
92 | xcb_get_image_reply_t *image_reply = | - |
93 | xcb_get_image_reply(conn, get_image_cookie, NULL); | - |
94 | | - |
95 | if (!image_reply) {TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
| 0-22 |
96 | return QPixmap(); never executed: return QPixmap(); | 0 |
97 | } | - |
98 | | - |
99 | uint8_t *data = xcb_get_image_data(image_reply); | - |
100 | uint32_t length = xcb_get_image_data_length(image_reply); | - |
101 | | - |
102 | QPixmap result; | - |
103 | | - |
104 | QImage::Format format = qt_xcb_imageFormatForVisual(connection, depth, visual); | - |
105 | if (format != QImage::Format_Invalid) {TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
| 0-22 |
106 | uint32_t bytes_per_line = length / height; | - |
107 | QImage image(const_cast<uint8_t *>(data), width, height, bytes_per_line, format); | - |
108 | uint8_t image_byte_order = connection->setup()->image_byte_order; | - |
109 | | - |
110 | | - |
111 | if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && image_byte_order == XCB_IMAGE_ORDER_MSB_FIRST)TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
| 0-22 |
112 | || (QSysInfo::ByteOrder == QSysInfo::BigEndian && image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST))TRUE | never evaluated | FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
TRUE | never evaluated | FALSE | never evaluated |
| 0-22 |
113 | { | - |
114 | for (int i=0; i < image.height(); i++) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
115 | switch (format) { | - |
116 | case QImage::Format_RGB16: { never executed: case QImage::Format_RGB16: | 0 |
117 | ushort *p = (ushort*)image.scanLine(i); | - |
118 | ushort *end = p + image.width(); | - |
119 | while (p < end) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
120 | *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff); | - |
121 | p++; | - |
122 | } never executed: end of block | 0 |
123 | break; never executed: break; | 0 |
124 | } | - |
125 | case QImage::Format_RGB32: never executed: case QImage::Format_RGB32: | 0 |
126 | case QImage::Format_ARGB32_Premultiplied: { never executed: case QImage::Format_ARGB32_Premultiplied: | 0 |
127 | uint *p = (uint*)image.scanLine(i); | - |
128 | uint *end = p + image.width(); | - |
129 | while (p < end) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
130 | *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000) | - |
131 | | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff); | - |
132 | p++; | - |
133 | } never executed: end of block | 0 |
134 | break; never executed: break; | 0 |
135 | } | - |
136 | default: never executed: default: | 0 |
137 | Q_ASSERT(false); | - |
138 | } never executed: end of block | 0 |
139 | } | - |
140 | } never executed: end of block | 0 |
141 | | - |
142 | | - |
143 | if (format == QImage::Format_RGB32) {TRUE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | never evaluated |
| 0-22 |
144 | QRgb *p = (QRgb *)image.bits(); | - |
145 | for (int y = 0; y < height; ++y) {TRUE | evaluated 1856 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | evaluated 22 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
| 22-1856 |
146 | for (int x = 0; x < width; ++x)TRUE | evaluated 487578 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| FALSE | evaluated 1856 times by 3 testsEvaluated by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
|
| 1856-487578 |
147 | p[x] |= 0xff000000;executed 487578 times by 3 tests: p[x] |= 0xff000000; Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| 487578 |
148 | p += bytes_per_line / 4; | - |
149 | }executed 1856 times by 3 tests: end of block Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| 1856 |
150 | } else if (format == QImage::Format_BGR30 || format == QImage::Format_RGB30) {executed 22 times by 3 tests: end of block Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0-22 |
151 | QRgb *p = (QRgb *)image.bits(); | - |
152 | for (int y = 0; y < height; ++y) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
153 | for (int x = 0; x < width; ++x)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
154 | p[x] |= 0xc0000000; never executed: p[x] |= 0xc0000000; | 0 |
155 | p += bytes_per_line / 4; | - |
156 | } never executed: end of block | 0 |
157 | } never executed: end of block | 0 |
158 | | - |
159 | result = QPixmap::fromImage(image.copy()); | - |
160 | }executed 22 times by 3 tests: end of block Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| 22 |
161 | | - |
162 | free(image_reply); | - |
163 | return result;executed 22 times by 3 tests: return result; Executed by:- tst_QOpenGLWidget
- tst_QToolTip
- tst_QWidget
| 22 |
164 | } | - |
165 | | - |
166 | xcb_pixmap_t qt_xcb_XPixmapFromBitmap(QXcbScreen *screen, const QImage &image) | - |
167 | { | - |
168 | xcb_connection_t *conn = screen->xcb_connection(); | - |
169 | QImage bitmap = image.convertToFormat(QImage::Format_MonoLSB); | - |
170 | const QRgb c0 = QColor(Qt::black).rgb(); | - |
171 | const QRgb c1 = QColor(Qt::white).rgb(); | - |
172 | if (bitmap.color(0) == c0 && bitmap.color(1) == c1) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
173 | bitmap.invertPixels(); | - |
174 | bitmap.setColor(0, c1); | - |
175 | bitmap.setColor(1, c0); | - |
176 | } never executed: end of block | 0 |
177 | const int width = bitmap.width(); | - |
178 | const int height = bitmap.height(); | - |
179 | const int bytesPerLine = bitmap.bytesPerLine(); | - |
180 | int destLineSize = width / 8; | - |
181 | if (width % 8)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
182 | ++destLineSize; never executed: ++destLineSize; | 0 |
183 | const uchar *map = bitmap.bits(); | - |
184 | uint8_t *buf = new uint8_t[height * destLineSize]; | - |
185 | for (int i = 0; i < height; i++)TRUE | never evaluated | FALSE | never evaluated |
| 0 |
186 | memcpy(buf + (destLineSize * i), map + (bytesPerLine * i), destLineSize); never executed: memcpy(buf + (destLineSize * i), map + (bytesPerLine * i), destLineSize); | 0 |
187 | xcb_pixmap_t pm = xcb_create_pixmap_from_bitmap_data(conn, screen->root(), buf, | - |
188 | width, height, 1, 0, 0, 0); | - |
189 | delete[] buf; | - |
190 | return pm; never executed: return pm; | 0 |
191 | } | - |
192 | | - |
193 | xcb_cursor_t qt_xcb_createCursorXRender(QXcbScreen *screen, const QImage &image, | - |
194 | const QPoint &spot) | - |
195 | { | - |
196 | #ifdef XCB_USE_RENDER | - |
197 | xcb_connection_t *conn = screen->xcb_connection(); | - |
198 | const int w = image.width(); | - |
199 | const int h = image.height(); | - |
200 | xcb_generic_error_t *error = 0; | - |
201 | xcb_render_query_pict_formats_cookie_t formatsCookie = xcb_render_query_pict_formats(conn); | - |
202 | xcb_render_query_pict_formats_reply_t *formatsReply = xcb_render_query_pict_formats_reply(conn, | - |
203 | formatsCookie, | - |
204 | &error); | - |
205 | if (!formatsReply || error) {TRUE | never evaluated | FALSE | never evaluated |
TRUE | never evaluated | FALSE | never evaluated |
| 0 |
206 | qWarning("qt_xcb_createCursorXRender: query_pict_formats failed"); | - |
207 | free(formatsReply); | - |
208 | free(error); | - |
209 | return XCB_NONE; never executed: return 0L; | 0 |
210 | } | - |
211 | xcb_render_pictforminfo_t *fmt = xcb_render_util_find_standard_format(formatsReply, | - |
212 | XCB_PICT_STANDARD_ARGB_32); | - |
213 | if (!fmt) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
214 | qWarning("qt_xcb_createCursorXRender: Failed to find format PICT_STANDARD_ARGB_32"); | - |
215 | free(formatsReply); | - |
216 | return XCB_NONE; never executed: return 0L; | 0 |
217 | } | - |
218 | | - |
219 | QImage img = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - |
220 | xcb_image_t *xi = xcb_image_create(w, h, XCB_IMAGE_FORMAT_Z_PIXMAP, | - |
221 | 32, 32, 32, 32, | - |
222 | QSysInfo::ByteOrder == QSysInfo::BigEndian ? XCB_IMAGE_ORDER_MSB_FIRST : XCB_IMAGE_ORDER_LSB_FIRST, | - |
223 | XCB_IMAGE_ORDER_MSB_FIRST, | - |
224 | 0, 0, 0); | - |
225 | if (!xi) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
226 | qWarning("qt_xcb_createCursorXRender: xcb_image_create failed"); | - |
227 | free(formatsReply); | - |
228 | return XCB_NONE; never executed: return 0L; | 0 |
229 | } | - |
230 | xi->data = (uint8_t *) malloc(xi->stride * h); | - |
231 | if (!xi->data) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
232 | qWarning("qt_xcb_createCursorXRender: Failed to malloc() image data"); | - |
233 | xcb_image_destroy(xi); | - |
234 | free(formatsReply); | - |
235 | return XCB_NONE; never executed: return 0L; | 0 |
236 | } | - |
237 | memcpy(xi->data, img.constBits(), img.byteCount()); | - |
238 | | - |
239 | xcb_pixmap_t pix = xcb_generate_id(conn); | - |
240 | xcb_create_pixmap(conn, 32, pix, screen->root(), w, h); | - |
241 | | - |
242 | xcb_render_picture_t pic = xcb_generate_id(conn); | - |
243 | xcb_render_create_picture(conn, pic, pix, fmt->id, 0, 0); | - |
244 | | - |
245 | xcb_gcontext_t gc = xcb_generate_id(conn); | - |
246 | xcb_create_gc(conn, gc, pix, 0, 0); | - |
247 | xcb_image_put(conn, pix, gc, xi, 0, 0, 0); | - |
248 | xcb_free_gc(conn, gc); | - |
249 | | - |
250 | xcb_cursor_t cursor = xcb_generate_id(conn); | - |
251 | xcb_render_create_cursor(conn, cursor, pic, spot.x(), spot.y()); | - |
252 | | - |
253 | free(xi->data); | - |
254 | xcb_image_destroy(xi); | - |
255 | xcb_render_free_picture(conn, pic); | - |
256 | xcb_free_pixmap(conn, pix); | - |
257 | free(formatsReply); | - |
258 | return cursor; never executed: return cursor; | 0 |
259 | | - |
260 | #else | - |
261 | Q_UNUSED(screen); | - |
262 | Q_UNUSED(image); | - |
263 | Q_UNUSED(spot); | - |
264 | return XCB_NONE; | - |
265 | #endif | - |
266 | } | - |
267 | | - |
268 | QT_END_NAMESPACE | - |
| | |