qxcbimage.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/plugins/platforms/xcb/qxcbimage.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the plugins of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 2.1 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
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// 'template' is used as a function argument name in xcb_renderutil.h-
41#define template template_param-
42// extern "C" is missing too-
43extern "C" {-
44#include <xcb/xcb_renderutil.h>-
45}-
46#undef template-
47#endif-
48-
49QT_BEGIN_NAMESPACE-
50-
51QImage::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)
!visualDescription
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
!formatDescription
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated 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 == 0xff0000
depth == 32Description
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
format->bits_per_pixel == 32Description
TRUEnever evaluated
FALSEnever evaluated
visual->red_mask == 0xff0000Description
TRUEnever evaluated
FALSEnever evaluated
0-22
60 && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)
visual->green_mask == 0xff00Description
TRUEnever evaluated
FALSEnever evaluated
visual->blue_mask == 0xffDescription
TRUEnever evaluated
FALSEnever 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 == 0x3ff
depth == 30Description
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
format->bits_per_pixel == 32Description
TRUEnever evaluated
FALSEnever evaluated
visual->red_mask == 0x3ffDescription
TRUEnever evaluated
FALSEnever evaluated
0-22
64 && visual->green_mask == 0x0ffc00 && visual->blue_mask == 0x3ff00000)
visual->green_mask == 0x0ffc00Description
TRUEnever evaluated
FALSEnever evaluated
visual->blue_m... == 0x3ff00000Description
TRUEnever evaluated
FALSEnever 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 == 0x3ff
depth == 30Description
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
format->bits_per_pixel == 32Description
TRUEnever evaluated
FALSEnever evaluated
visual->blue_mask == 0x3ffDescription
TRUEnever evaluated
FALSEnever evaluated
0-22
68 && visual->green_mask == 0x0ffc00 && visual->red_mask == 0x3ff00000)
visual->green_mask == 0x0ffc00Description
TRUEnever evaluated
FALSEnever evaluated
visual->red_mask == 0x3ff00000Description
TRUEnever evaluated
FALSEnever 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 == 0xff0000
depth == 24Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
format->bits_per_pixel == 32Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
visual->red_mask == 0xff0000Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
0-22
72 && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)
visual->green_mask == 0xff00Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
visual->blue_mask == 0xffDescription
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever 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 == 0xf800
depth == 16Description
TRUEnever evaluated
FALSEnever evaluated
format->bits_per_pixel == 16Description
TRUEnever evaluated
FALSEnever evaluated
visual->red_mask == 0xf800Description
TRUEnever evaluated
FALSEnever evaluated
0
76 && visual->green_mask == 0x7e0 && visual->blue_mask == 0x1f)
visual->green_mask == 0x7e0Description
TRUEnever evaluated
FALSEnever evaluated
visual->blue_mask == 0x1fDescription
TRUEnever evaluated
FALSEnever 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-
82QPixmap 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) {
!image_replyDescription
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated 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) {
format != QIma...Format_InvalidDescription
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever 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 // we may have to swap the byte order-
111 if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && image_byte_order == XCB_IMAGE_ORDER_MSB_FIRST)
QSysInfo::Byte...::LittleEndianDescription
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
image_byte_ord...RDER_MSB_FIRSTDescription
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
0-22
112 || (QSysInfo::ByteOrder == QSysInfo::BigEndian && image_byte_order == XCB_IMAGE_ORDER_LSB_FIRST))
QSysInfo::Byte...nfo::BigEndianDescription
TRUEnever evaluated
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
image_byte_ord...RDER_LSB_FIRSTDescription
TRUEnever evaluated
FALSEnever evaluated
0-22
113 {-
114 for (int i=0; i < image.height(); i++) {
i < image.height()Description
TRUEnever evaluated
FALSEnever 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) {
p < endDescription
TRUEnever evaluated
FALSEnever 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: // fall-through
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) {
p < endDescription
TRUEnever evaluated
FALSEnever 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 // fix-up alpha channel-
143 if (format == QImage::Format_RGB32) {
format == QImage::Format_RGB32Description
TRUEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEnever evaluated
0-22
144 QRgb *p = (QRgb *)image.bits();-
145 for (int y = 0; y < height; ++y) {
y < heightDescription
TRUEevaluated 1856 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEevaluated 22 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
22-1856
146 for (int x = 0; x < width; ++x)
x < widthDescription
TRUEevaluated 487578 times by 3 tests
Evaluated by:
  • tst_QOpenGLWidget
  • tst_QToolTip
  • tst_QWidget
FALSEevaluated 1856 times by 3 tests
Evaluated 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
format == QImage::Format_BGR30Description
TRUEnever evaluated
FALSEnever evaluated
format == QImage::Format_RGB30Description
TRUEnever evaluated
FALSEnever evaluated
0-22
151 QRgb *p = (QRgb *)image.bits();-
152 for (int y = 0; y < height; ++y) {
y < heightDescription
TRUEnever evaluated
FALSEnever evaluated
0
153 for (int x = 0; x < width; ++x)
x < widthDescription
TRUEnever evaluated
FALSEnever 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-
166xcb_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) {
bitmap.color(0) == c0Description
TRUEnever evaluated
FALSEnever evaluated
bitmap.color(1) == c1Description
TRUEnever evaluated
FALSEnever 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)
width % 8Description
TRUEnever evaluated
FALSEnever 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++)
i < heightDescription
TRUEnever evaluated
FALSEnever 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-
193xcb_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) {
!formatsReplyDescription
TRUEnever evaluated
FALSEnever evaluated
errorDescription
TRUEnever evaluated
FALSEnever 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) {
!fmtDescription
TRUEnever evaluated
FALSEnever 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) {
!xiDescription
TRUEnever evaluated
FALSEnever 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) {
!xi->dataDescription
TRUEnever evaluated
FALSEnever 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-
268QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9