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