| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qplatformbackingstore.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | class QPlatformBackingStorePrivate | - | ||||||||||||
| 7 | { | - | ||||||||||||
| 8 | public: | - | ||||||||||||
| 9 | QPlatformBackingStorePrivate(QWindow *w) | - | ||||||||||||
| 10 | : window(w) | - | ||||||||||||
| 11 | - | |||||||||||||
| 12 | , textureId(0) | - | ||||||||||||
| 13 | , blitter(0) | - | ||||||||||||
| 14 | - | |||||||||||||
| 15 | { | - | ||||||||||||
| 16 | } | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | ~QPlatformBackingStorePrivate() | - | ||||||||||||
| 19 | { | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 22 | if (ctx) { | - | ||||||||||||
| 23 | if (textureId) | - | ||||||||||||
| 24 | ctx->functions()->glDeleteTextures(1, &textureId); | - | ||||||||||||
| 25 | if (blitter) | - | ||||||||||||
| 26 | blitter->destroy(); | - | ||||||||||||
| 27 | } else if (textureId || blitter) { | - | ||||||||||||
| 28 | QMessageLogger(__FILE__, 9197, __PRETTY_FUNCTION__).warning("No context current during QPlatformBackingStore destruction, OpenGL resources not released"); | - | ||||||||||||
| 29 | } | - | ||||||||||||
| 30 | delete blitter; | - | ||||||||||||
| 31 | - | |||||||||||||
| 32 | } | - | ||||||||||||
| 33 | QWindow *window; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | mutable GLuint textureId; | - | ||||||||||||
| 36 | mutable QSize textureSize; | - | ||||||||||||
| 37 | mutable bool needsSwizzle; | - | ||||||||||||
| 38 | mutable bool premultiplied; | - | ||||||||||||
| 39 | QOpenGLTextureBlitter *blitter; | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | }; | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | - | |||||||||||||
| 44 | - | |||||||||||||
| 45 | struct QBackingstoreTextureInfo | - | ||||||||||||
| 46 | { | - | ||||||||||||
| 47 | void *source; | - | ||||||||||||
| 48 | GLuint textureId; | - | ||||||||||||
| 49 | QRect rect; | - | ||||||||||||
| 50 | QRect clipRect; | - | ||||||||||||
| 51 | QPlatformTextureList::Flags flags; | - | ||||||||||||
| 52 | }; | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | template<> class QTypeInfo<QBackingstoreTextureInfo > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QBackingstoreTextureInfo)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QBackingstoreTextureInfo >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QBackingstoreTextureInfo) }; static inline const char *name() { return "QBackingstoreTextureInfo"; } }; | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | class QPlatformTextureListPrivate : public QObjectPrivate | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | public: | - | ||||||||||||
| 59 | QPlatformTextureListPrivate() | - | ||||||||||||
| 60 | : locked(false) | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | QVector<QBackingstoreTextureInfo> textures; | - | ||||||||||||
| 65 | bool locked; | - | ||||||||||||
| 66 | }; | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | QPlatformTextureList::QPlatformTextureList(QObject *parent) | - | ||||||||||||
| 69 | : QObject(*new QPlatformTextureListPrivate, parent) | - | ||||||||||||
| 70 | { | - | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | QPlatformTextureList::~QPlatformTextureList() | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | } | - | ||||||||||||
| 76 | - | |||||||||||||
| 77 | int QPlatformTextureList::count() const | - | ||||||||||||
| 78 | { | - | ||||||||||||
| 79 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 80 | return d->textures.count(); | - | ||||||||||||
| 81 | } | - | ||||||||||||
| 82 | - | |||||||||||||
| 83 | GLuint QPlatformTextureList::textureId(int index) const | - | ||||||||||||
| 84 | { | - | ||||||||||||
| 85 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 86 | return d->textures.at(index).textureId; | - | ||||||||||||
| 87 | } | - | ||||||||||||
| 88 | - | |||||||||||||
| 89 | void *QPlatformTextureList::source(int index) | - | ||||||||||||
| 90 | { | - | ||||||||||||
| 91 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 92 | return d->textures.at(index).source; | - | ||||||||||||
| 93 | } | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | QPlatformTextureList::Flags QPlatformTextureList::flags(int index) const | - | ||||||||||||
| 96 | { | - | ||||||||||||
| 97 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 98 | return d->textures.at(index).flags; | - | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | QRect QPlatformTextureList::geometry(int index) const | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 104 | return d->textures.at(index).rect; | - | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | QRect QPlatformTextureList::clipRect(int index) const | - | ||||||||||||
| 108 | { | - | ||||||||||||
| 109 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 110 | return d->textures.at(index).clipRect; | - | ||||||||||||
| 111 | } | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | void QPlatformTextureList::lock(bool on) | - | ||||||||||||
| 114 | { | - | ||||||||||||
| 115 | QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 116 | if (on != d->locked) { | - | ||||||||||||
| 117 | d->locked = on; | - | ||||||||||||
| 118 | locked(on); | - | ||||||||||||
| 119 | } | - | ||||||||||||
| 120 | } | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | bool QPlatformTextureList::isLocked() const | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | const QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 125 | return d->locked; | - | ||||||||||||
| 126 | } | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | void QPlatformTextureList::appendTexture(void *source, GLuint textureId, const QRect &geometry, | - | ||||||||||||
| 129 | const QRect &clipRect, Flags flags) | - | ||||||||||||
| 130 | { | - | ||||||||||||
| 131 | QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 132 | QBackingstoreTextureInfo bi; | - | ||||||||||||
| 133 | bi.source = source; | - | ||||||||||||
| 134 | bi.textureId = textureId; | - | ||||||||||||
| 135 | bi.rect = geometry; | - | ||||||||||||
| 136 | bi.clipRect = clipRect; | - | ||||||||||||
| 137 | bi.flags = flags; | - | ||||||||||||
| 138 | d->textures.append(bi); | - | ||||||||||||
| 139 | } | - | ||||||||||||
| 140 | - | |||||||||||||
| 141 | void QPlatformTextureList::clear() | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | QPlatformTextureListPrivate * const d = d_func(); | - | ||||||||||||
| 144 | d->textures.clear(); | - | ||||||||||||
| 145 | } | - | ||||||||||||
| 146 | static inline QRect deviceRect(const QRect &rect, QWindow *window) | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | QRect deviceRect(rect.topLeft() * window->devicePixelRatio(), | - | ||||||||||||
| 149 | rect.size() * window->devicePixelRatio()); | - | ||||||||||||
| 150 | return deviceRect; | - | ||||||||||||
| } | ||||||||||||||
| static inline QPoint deviceOffset(const QPoint &pt, QWindow *window) | ||||||||||||||
| { | ||||||||||||||
| return pt * window->devicePixelRatio();} | ||||||||||||||
| 152 | - | |||||||||||||
| 153 | static QRegion deviceRegion(const QRegion ®ion, QWindow *window, const QPoint &offset) | - | ||||||||||||
| 154 | { | - | ||||||||||||
| 155 |     if (offset.isNull()
 
  | 0 | ||||||||||||
| 156 |         return never executed:   region;return region;never executed:  return region; | 0 | ||||||||||||
| 157 | - | |||||||||||||
| 158 | QVector<QRect> rects; | - | ||||||||||||
| 159 | const QVector<QRect> regionRects = region.rects(); | - | ||||||||||||
| 160 | rects.reserve(regionRects.count()); | - | ||||||||||||
| 161 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(regionRects)>::type> _container_((regionRects)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QRect &rect = *_container_.i; _container_.control; _container_.control = 0: regionRects) | - | ||||||||||||
| 162 |         rects.append(deviceRect(rect.translated(offset), window)); never executed:  rects.append(deviceRect(rect.translated(offset), window)); | 0 | ||||||||||||
| 163 | - | |||||||||||||
| 164 | QRegion deviceRegion; | - | ||||||||||||
| 165 | deviceRegion.setRects(rects.constData(), rects.count()); | - | ||||||||||||
| 166 |     return never executed:   deviceRegion;return deviceRegion;never executed:  return deviceRegion; | 0 | ||||||||||||
| 167 | } | - | ||||||||||||
| 168 | - | |||||||||||||
| 169 | static inline QRect toBottomLeftRect(const QRect &topLeftRect, int windowHeight) | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | return QRect(topLeftRect.x(), windowHeight - topLeftRect.bottomRight().y() - 1, | - | ||||||||||||
| 172 | topLeftRect.width(), topLeftRect.height()); | - | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | static void blitTextureForWidget(const QPlatformTextureList *textures, int idx, QWindow *window, const QRect &deviceWindowRect, | - | ||||||||||||
| 176 | QOpenGLTextureBlitter *blitter, const QPoint &offset) | - | ||||||||||||
| 177 | { | - | ||||||||||||
| 178 | const QRect clipRect = textures->clipRect(idx); | - | ||||||||||||
| 179 | if (clipRect.isEmpty()) | - | ||||||||||||
| 180 | return; | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | QRect rectInWindow = textures->geometry(idx); | - | ||||||||||||
| 183 | - | |||||||||||||
| 184 | rectInWindow.translate(-offset); | - | ||||||||||||
| 185 | - | |||||||||||||
| 186 | const QRect clippedRectInWindow = rectInWindow & clipRect.translated(rectInWindow.topLeft()); | - | ||||||||||||
| 187 | const QRect srcRect = toBottomLeftRect(clipRect, rectInWindow.height()); | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(deviceRect(clippedRectInWindow, window), | - | ||||||||||||
| 190 | deviceWindowRect); | - | ||||||||||||
| 191 | - | |||||||||||||
| 192 | const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(deviceRect(srcRect, window), | - | ||||||||||||
| 193 | deviceRect(rectInWindow, window).size(), | - | ||||||||||||
| 194 | QOpenGLTextureBlitter::OriginBottomLeft); | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | blitter->blit(textures->textureId(idx), target, source); | - | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®ion, | - | ||||||||||||
| 199 | const QPoint &offset, | - | ||||||||||||
| 200 | QPlatformTextureList *textures, QOpenGLContext *context, | - | ||||||||||||
| 201 | bool translucentBackground) | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 |     if (!qt_window_private(window)->receivedExpose
  | 0 | ||||||||||||
| 204 |         return; never executed:  return; | 0 | ||||||||||||
| 205 | - | |||||||||||||
| 206 |     if (!context->makeCurrent(window)
  | 0 | ||||||||||||
| 207 | QMessageLogger(__FILE__, 315316, __PRETTY_FUNCTION__).warning("composeAndFlush: makeCurrent() failed"); | - | ||||||||||||
| 208 |         return; never executed:  return; | 0 | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | QWindowPrivate::get(window)->lastComposeTime.start(); | - | ||||||||||||
| 212 | - | |||||||||||||
| 213 | QOpenGLFunctions *funcs = context->functions(); | - | ||||||||||||
| 214 | funcs->glViewport(0, 0, window->width() * window->devicePixelRatio(), window->height() * window->devicePixelRatio()); | - | ||||||||||||
| 215 | funcs->glClearColor(0, 0, 0, translucentBackground ? 0 : 1); | - | ||||||||||||
| 216 | funcs->glClear(0x00004000); | - | ||||||||||||
| 217 | - | |||||||||||||
| 218 |     if (!d_ptr->blitter
  | 0 | ||||||||||||
| 219 | d_ptr->blitter = new QOpenGLTextureBlitter; | - | ||||||||||||
| 220 | d_ptr->blitter->create(); | - | ||||||||||||
| 221 |     } never executed:  end of block | 0 | ||||||||||||
| 222 | - | |||||||||||||
| 223 | d_ptr->blitter->bind(); | - | ||||||||||||
| 224 | - | |||||||||||||
| 225 | const QRect deviceWindowRect = deviceRect(QRect(QPoint(), window->size()), window); | - | ||||||||||||
| const QPoint deviceWindowOffset = deviceOffset(offset,window); | ||||||||||||||
| 226 | - | |||||||||||||
| 227 | - | |||||||||||||
| 228 |     for (int i = 0; i < textures->count()
  | 0 | ||||||||||||
| 229 |         if (!textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)
  | 0 | ||||||||||||
| 230 |             blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset); never executed:  blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset); | 0 | ||||||||||||
| 231 |     } never executed:  end of block | 0 | ||||||||||||
| 232 | - | |||||||||||||
| 233 | - | |||||||||||||
| 234 | GLuint textureId = 0; | - | ||||||||||||
| 235 | QOpenGLTextureBlitter::Origin origin = QOpenGLTextureBlitter::OriginTopLeft; | - | ||||||||||||
| 236 |     if (QPlatformGraphicsBuffer *graphicsBuffer = this->graphicsBuffer()
  | 0 | ||||||||||||
| 237 |         if (graphicsBuffer->size() != d_ptr->textureSize
  | 0 | ||||||||||||
| 238 |             if (d_ptr->textureId
  | 0 | ||||||||||||
| 239 |                 funcs->glDeleteTextures(1, &d_ptr->textureId); never executed:  funcs->glDeleteTextures(1, &d_ptr->textureId); | 0 | ||||||||||||
| 240 | funcs->glGenTextures(1, &d_ptr->textureId); | - | ||||||||||||
| 241 | funcs->glBindTexture(0x0DE1, d_ptr->textureId); | - | ||||||||||||
| 242 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 243 |             if (!ctx->isOpenGLES()
 
  | 0 | ||||||||||||
| 244 | funcs->glTexParameteri(0x0DE1, 0x813C, 0); | - | ||||||||||||
| 245 | funcs->glTexParameteri(0x0DE1, 0x813D, 0); | - | ||||||||||||
| 246 |             } never executed:  end of block | 0 | ||||||||||||
| 247 | funcs->glTexParameterf(0x0DE1, 0x2801, 0x2600); | - | ||||||||||||
| 248 | funcs->glTexParameterf(0x0DE1, 0x2800, 0x2600); | - | ||||||||||||
| 249 | funcs->glTexParameterf(0x0DE1, 0x2802, 0x812F); | - | ||||||||||||
| 250 | funcs->glTexParameterf(0x0DE1, 0x2803, 0x812F); | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 |             if (QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &d_ptr->needsSwizzle, &d_ptr->premultiplied)
  | 0 | ||||||||||||
| 253 | d_ptr->textureSize = graphicsBuffer->size(); | - | ||||||||||||
| 254 |             } never executed:   else {end of block | 0 | ||||||||||||
| 255 | d_ptr->textureSize = QSize(0,0); | - | ||||||||||||
| 256 |             } never executed:  end of block | 0 | ||||||||||||
| 257 | - | |||||||||||||
| 258 | graphicsBuffer->unlock(); | - | ||||||||||||
| 259 |         } never executed:   else if (!region.isEmpty()end of block
  | 0 | ||||||||||||
| 260 | funcs->glBindTexture(0x0DE1, d_ptr->textureId); | - | ||||||||||||
| 261 | QPlatformGraphicsBufferHelper::lockAndBindToTexture(graphicsBuffer, &d_ptr->needsSwizzle, &d_ptr->premultiplied); | - | ||||||||||||
| 262 |         } never executed:  end of block | 0 | ||||||||||||
| 263 | - | |||||||||||||
| 264 |         if (graphicsBuffer->origin() == QPlatformGraphicsBuffer::OriginBottomLeft
  | 0 | ||||||||||||
| 265 |             origin = QOpenGLTextureBlitter::OriginBottomLeft; never executed:  origin = QOpenGLTextureBlitter::OriginBottomLeft; | 0 | ||||||||||||
| 266 | textureId = d_ptr->textureId; | - | ||||||||||||
| 267 |     } never executed:   else {end of block | 0 | ||||||||||||
| 268 | TextureFlags flags = 0; | - | ||||||||||||
| 269 | textureId = toTexture(deviceRegion(region, window, offset), &d_ptr->textureSize, &flags); | - | ||||||||||||
| 270 | d_ptr->needsSwizzle = (flags & TextureSwizzle) != 0; | - | ||||||||||||
| 271 | d_ptr->premultiplied = (flags & TexturePremultiplied) != 0; | - | ||||||||||||
| 272 |         if (flags & TextureFlip
  | 0 | ||||||||||||
| 273 |             origin = QOpenGLTextureBlitter::OriginBottomLeft; never executed:  origin = QOpenGLTextureBlitter::OriginBottomLeft; | 0 | ||||||||||||
| 274 |     } never executed:  end of block | 0 | ||||||||||||
| 275 | - | |||||||||||||
| 276 | funcs->glEnable(0x0BE2); | - | ||||||||||||
| 277 |     if (d_ptr->premultiplied
  | 0 | ||||||||||||
| 278 |         funcs->glBlendFuncSeparate(1, 0x0303, 1, 1); never executed:  funcs->glBlendFuncSeparate(1, 0x0303, 1, 1); | 0 | ||||||||||||
| 279 | else | - | ||||||||||||
| 280 |         funcs->glBlendFuncSeparate(0x0302, 0x0303, 1, 1); never executed:  funcs->glBlendFuncSeparate(0x0302, 0x0303, 1, 1); | 0 | ||||||||||||
| 281 | - | |||||||||||||
| 282 |     if (textureId
  | 0 | ||||||||||||
| 283 |         if (d_ptr->needsSwizzle
  | 0 | ||||||||||||
| 284 |             d_ptr->blitter->setSwizzleRB(true); never executed:  d_ptr->blitter->setSwizzleRB(true); | 0 | ||||||||||||
| 285 | - | |||||||||||||
| 286 | - | |||||||||||||
| 287 | const QRect srcRect = toBottomLeftRect(deviceWindowRect.translated(deviceWindowOffsetoffset), d_ptr->textureSize.height()); | - | ||||||||||||
| 288 | const QMatrix3x3 source = QOpenGLTextureBlitter::sourceTransform(srcRect, | - | ||||||||||||
| 289 | d_ptr->textureSize, | - | ||||||||||||
| 290 | origin); | - | ||||||||||||
| 291 | d_ptr->blitter->blit(textureId, QMatrix4x4(), source); | - | ||||||||||||
| 292 |         if (d_ptr->needsSwizzle
  | 0 | ||||||||||||
| 293 |             d_ptr->blitter->setSwizzleRB(false); never executed:  d_ptr->blitter->setSwizzleRB(false); | 0 | ||||||||||||
| 294 |     } never executed:  end of block | 0 | ||||||||||||
| 295 | - | |||||||||||||
| 296 | - | |||||||||||||
| 297 |     for (int i = 0; i < textures->count()
  | 0 | ||||||||||||
| 298 |         if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)
  | 0 | ||||||||||||
| 299 |             blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset); never executed:  blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset); | 0 | ||||||||||||
| 300 |     } never executed:  end of block | 0 | ||||||||||||
| 301 | - | |||||||||||||
| 302 | funcs->glDisable(0x0BE2); | - | ||||||||||||
| 303 | d_ptr->blitter->release(); | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | context->swapBuffers(window); | - | ||||||||||||
| 306 | } never executed:  end of block | 0 | ||||||||||||
| 307 | QImage QPlatformBackingStore::toImage() const | - | ||||||||||||
| 308 | { | - | ||||||||||||
| 309 | return QImage(); | - | ||||||||||||
| 310 | } | - | ||||||||||||
| 311 | GLuint QPlatformBackingStore::toTexture(const QRegion &dirtyRegion, QSize *textureSize, TextureFlags *flags) const | - | ||||||||||||
| 312 | { | - | ||||||||||||
| 313 | ((!(textureSize)) ? qt_assert("textureSize",__FILE__,460) : qt_noop()); | - | ||||||||||||
| 314 | ((!(flags)) ? qt_assert("flags",__FILE__,461) : qt_noop()); | - | ||||||||||||
| 315 | - | |||||||||||||
| 316 | QImage image = toImage(); | - | ||||||||||||
| 317 | QSize imageSize = image.size(); | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
| 320 | GLenum internalFormat = 0x1908; | - | ||||||||||||
| 321 | GLuint pixelType = 0x1401; | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | bool needsConversion = false; | - | ||||||||||||
| 324 | *flags = 0; | - | ||||||||||||
| 325 | switch (image.format()) { | - | ||||||||||||
| 326 | case QImage::Format_ARGB32_Premultiplied: | - | ||||||||||||
| 327 | *flags |= TexturePremultiplied; | - | ||||||||||||
| 328 | - | |||||||||||||
| 329 | case QImage::Format_RGB32: | - | ||||||||||||
| 330 | case QImage::Format_ARGB32: | - | ||||||||||||
| 331 | *flags |= TextureSwizzle; | - | ||||||||||||
| 332 | break; | - | ||||||||||||
| 333 | case QImage::Format_RGBA8888_Premultiplied: | - | ||||||||||||
| 334 | *flags |= TexturePremultiplied; | - | ||||||||||||
| 335 | - | |||||||||||||
| 336 | case QImage::Format_RGBX8888: | - | ||||||||||||
| 337 | case QImage::Format_RGBA8888: | - | ||||||||||||
| 338 | break; | - | ||||||||||||
| 339 | case QImage::Format_BGR30: | - | ||||||||||||
| 340 | case QImage::Format_A2BGR30_Premultiplied: | - | ||||||||||||
| 341 | if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { | - | ||||||||||||
| 342 | pixelType = 0x8368; | - | ||||||||||||
| 343 | internalFormat = 0x8059; | - | ||||||||||||
| 344 | *flags |= TexturePremultiplied; | - | ||||||||||||
| 345 | } else { | - | ||||||||||||
| 346 | needsConversion = true; | - | ||||||||||||
| 347 | } | - | ||||||||||||
| 348 | break; | - | ||||||||||||
| 349 | case QImage::Format_RGB30: | - | ||||||||||||
| 350 | case QImage::Format_A2RGB30_Premultiplied: | - | ||||||||||||
| 351 | if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { | - | ||||||||||||
| 352 | pixelType = 0x8368; | - | ||||||||||||
| 353 | internalFormat = 0x8059; | - | ||||||||||||
| 354 | *flags |= TextureSwizzle | TexturePremultiplied; | - | ||||||||||||
| 355 | } else { | - | ||||||||||||
| 356 | needsConversion = true; | - | ||||||||||||
| 357 | } | - | ||||||||||||
| 358 | break; | - | ||||||||||||
| 359 | default: | - | ||||||||||||
| 360 | needsConversion = true; | - | ||||||||||||
| 361 | break; | - | ||||||||||||
| 362 | } | - | ||||||||||||
| 363 | if (imageSize.isEmpty()) { | - | ||||||||||||
| 364 | *textureSize = imageSize; | - | ||||||||||||
| 365 | return 0; | - | ||||||||||||
| 366 | } | - | ||||||||||||
| 367 | - | |||||||||||||
| 368 | - | |||||||||||||
| 369 | - | |||||||||||||
| 370 | bool resized = *textureSize != imageSize; | - | ||||||||||||
| 371 | if (dirtyRegion.isEmpty() && !resized) | - | ||||||||||||
| 372 | return d_ptr->textureId; | - | ||||||||||||
| 373 | - | |||||||||||||
| 374 | *textureSize = imageSize; | - | ||||||||||||
| 375 | - | |||||||||||||
| 376 | if (needsConversion) | - | ||||||||||||
| 377 | image = image.convertToFormat(QImage::Format_RGBA8888); | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | - | |||||||||||||
| 380 | - | |||||||||||||
| 381 | static const int bytesPerPixel = 4; | - | ||||||||||||
| 382 | const int strideInPixels = image.bytesPerLine() / bytesPerPixel; | - | ||||||||||||
| 383 | const bool hasUnpackRowLength = !ctx->isOpenGLES() || ctx->format().majorVersion() >= 3; | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | QOpenGLFunctions *funcs = ctx->functions(); | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | if (hasUnpackRowLength) { | - | ||||||||||||
| 388 | funcs->glPixelStorei(0x0CF2, strideInPixels); | - | ||||||||||||
| 389 | } else if (strideInPixels != image.width()) { | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | - | |||||||||||||
| 392 | - | |||||||||||||
| 393 | image = image.copy(); | - | ||||||||||||
| 394 | } | - | ||||||||||||
| 395 | - | |||||||||||||
| 396 | if (resized) { | - | ||||||||||||
| 397 | if (d_ptr->textureId) | - | ||||||||||||
| 398 | funcs->glDeleteTextures(1, &d_ptr->textureId); | - | ||||||||||||
| 399 | funcs->glGenTextures(1, &d_ptr->textureId); | - | ||||||||||||
| 400 | funcs->glBindTexture(0x0DE1, d_ptr->textureId); | - | ||||||||||||
| 401 | if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { | - | ||||||||||||
| 402 | funcs->glTexParameteri(0x0DE1, 0x813C, 0); | - | ||||||||||||
| 403 | funcs->glTexParameteri(0x0DE1, 0x813D, 0); | - | ||||||||||||
| 404 | } | - | ||||||||||||
| 405 | funcs->glTexParameterf(0x0DE1, 0x2801, 0x2600); | - | ||||||||||||
| 406 | funcs->glTexParameterf(0x0DE1, 0x2800, 0x2600); | - | ||||||||||||
| 407 | funcs->glTexParameterf(0x0DE1, 0x2802, 0x812F); | - | ||||||||||||
| 408 | funcs->glTexParameterf(0x0DE1, 0x2803, 0x812F); | - | ||||||||||||
| 409 | - | |||||||||||||
| 410 | funcs->glTexImage2D(0x0DE1, 0, internalFormat, imageSize.width(), imageSize.height(), 0, 0x1908, pixelType, | - | ||||||||||||
| 411 | const_cast<uchar*>(image.constBits())); | - | ||||||||||||
| 412 | } else { | - | ||||||||||||
| 413 | funcs->glBindTexture(0x0DE1, d_ptr->textureId); | - | ||||||||||||
| 414 | QRect imageRect = image.rect(); | - | ||||||||||||
| 415 | QRect rect = dirtyRegion.boundingRect() & imageRect; | - | ||||||||||||
| 416 | - | |||||||||||||
| 417 | if (hasUnpackRowLength) { | - | ||||||||||||
| 418 | funcs->glTexSubImage2D(0x0DE1, 0, rect.x(), rect.y(), rect.width(), rect.height(), 0x1908, pixelType, | - | ||||||||||||
| 419 | image.constScanLine(rect.y()) + rect.x() * bytesPerPixel); | - | ||||||||||||
| 420 | } else { | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | - | |||||||||||||
| 423 | if (rect.width() >= imageRect.width() / 2) { | - | ||||||||||||
| 424 | rect.setX(0); | - | ||||||||||||
| 425 | rect.setWidth(imageRect.width()); | - | ||||||||||||
| 426 | } | - | ||||||||||||
| 427 | - | |||||||||||||
| 428 | - | |||||||||||||
| 429 | - | |||||||||||||
| 430 | - | |||||||||||||
| 431 | if (rect.width() == imageRect.width()) { | - | ||||||||||||
| 432 | funcs->glTexSubImage2D(0x0DE1, 0, 0, rect.y(), rect.width(), rect.height(), 0x1908, pixelType, | - | ||||||||||||
| 433 | image.constScanLine(rect.y())); | - | ||||||||||||
| 434 | } else { | - | ||||||||||||
| 435 | funcs->glTexSubImage2D(0x0DE1, 0, rect.x(), rect.y(), rect.width(), rect.height(), 0x1908, pixelType, | - | ||||||||||||
| 436 | image.copy(rect).constBits()); | - | ||||||||||||
| 437 | } | - | ||||||||||||
| 438 | } | - | ||||||||||||
| 439 | } | - | ||||||||||||
| 440 | - | |||||||||||||
| 441 | if (hasUnpackRowLength) | - | ||||||||||||
| 442 | funcs->glPixelStorei(0x0CF2, 0); | - | ||||||||||||
| 443 | - | |||||||||||||
| 444 | return d_ptr->textureId; | - | ||||||||||||
| 445 | } | - | ||||||||||||
| 446 | QPlatformBackingStore::QPlatformBackingStore(QWindow *window) | - | ||||||||||||
| 447 | : d_ptr(new QPlatformBackingStorePrivate(window)) | - | ||||||||||||
| 448 | { | - | ||||||||||||
| 449 | } | - | ||||||||||||
| 450 | - | |||||||||||||
| 451 | - | |||||||||||||
| 452 | - | |||||||||||||
| 453 | - | |||||||||||||
| 454 | QPlatformBackingStore::~QPlatformBackingStore() | - | ||||||||||||
| 455 | { | - | ||||||||||||
| 456 | delete d_ptr; | - | ||||||||||||
| 457 | } | - | ||||||||||||
| 458 | - | |||||||||||||
| 459 | - | |||||||||||||
| 460 | - | |||||||||||||
| 461 | - | |||||||||||||
| 462 | - | |||||||||||||
| 463 | QWindow* QPlatformBackingStore::window() const | - | ||||||||||||
| 464 | { | - | ||||||||||||
| 465 | return d_ptr->window; | - | ||||||||||||
| 466 | } | - | ||||||||||||
| 467 | void QPlatformBackingStore::beginPaint(const QRegion &) | - | ||||||||||||
| 468 | { | - | ||||||||||||
| 469 | } | - | ||||||||||||
| 470 | - | |||||||||||||
| 471 | - | |||||||||||||
| 472 | - | |||||||||||||
| 473 | - | |||||||||||||
| 474 | - | |||||||||||||
| 475 | - | |||||||||||||
| 476 | - | |||||||||||||
| 477 | void QPlatformBackingStore::endPaint() | - | ||||||||||||
| 478 | { | - | ||||||||||||
| 479 | } | - | ||||||||||||
| 480 | - | |||||||||||||
| 481 | - | |||||||||||||
| 482 | - | |||||||||||||
| 483 | - | |||||||||||||
| 484 | QPlatformGraphicsBuffer *QPlatformBackingStore::graphicsBuffer() const | - | ||||||||||||
| 485 | { | - | ||||||||||||
| 486 | return nullptr; | - | ||||||||||||
| 487 | } | - | ||||||||||||
| 488 | - | |||||||||||||
| 489 | - | |||||||||||||
| 490 | - | |||||||||||||
| 491 | - | |||||||||||||
| 492 | - | |||||||||||||
| 493 | - | |||||||||||||
| 494 | - | |||||||||||||
| 495 | bool QPlatformBackingStore::scroll(const QRegion &area, int dx, int dy) | - | ||||||||||||
| 496 | { | - | ||||||||||||
| 497 | (void)area;; | - | ||||||||||||
| 498 | (void)dx;; | - | ||||||||||||
| 499 | (void)dy;; | - | ||||||||||||
| 500 | - | |||||||||||||
| 501 | return false; | - | ||||||||||||
| 502 | } | - | ||||||||||||
| 503 | - | |||||||||||||
| 504 | - | |||||||||||||
| Switch to Source code | Preprocessed file |