60 bool *swizzle,
bool *premultiplied,
63 if (graphicsBuffer->lock(QPlatformGraphicsBuffer::TextureAccess)) {
64 if (!graphicsBuffer->bindToTexture(rect)) {
65 qWarning(
"Failed to bind %sgraphicsbuffer to texture",
"");
71 *premultiplied =
false;
72 }
else if (graphicsBuffer->lock(QPlatformGraphicsBuffer::SWReadAccess)) {
73 if (!bindSWToTexture(graphicsBuffer, swizzle, premultiplied, rect)) {
74 qWarning(
"Failed to bind %sgraphicsbuffer to texture",
"SW ");
78 qWarning(
"Failed to lock");
109bool QPlatformGraphicsBufferHelper::
bindSWToTexture(
const QPlatformGraphicsBuffer *graphicsBuffer,
110 bool *swizzleRandB,
bool *premultipliedB,
111 const QRect &subRect)
114 QOpenGLContext *ctx = QOpenGLContext::currentContext();
118 if (!(graphicsBuffer->isLocked() & QPlatformGraphicsBuffer::SWReadAccess))
121 QSize size = graphicsBuffer->size();
123 Q_ASSERT(subRect.isEmpty() || QRect(QPoint(0,0), size).contains(subRect));
125 GLenum internalFormat = GL_RGBA;
126 GLuint pixelType = GL_UNSIGNED_BYTE;
128 bool needsConversion =
false;
129 bool swizzle =
false;
130 bool premultiplied =
false;
131 QImage::Format imageformat = QImage::toImageFormat(graphicsBuffer->format());
132 QImage image(graphicsBuffer->data(), size.width(), size.height(), graphicsBuffer->bytesPerLine(), imageformat);
133 switch (imageformat) {
134 case QImage::Format_ARGB32_Premultiplied:
135 premultiplied =
true;
137 case QImage::Format_RGB32:
138 case QImage::Format_ARGB32:
141 case QImage::Format_RGBA8888_Premultiplied:
142 premultiplied =
true;
144 case QImage::Format_RGBX8888:
145 case QImage::Format_RGBA8888:
147 case QImage::Format_BGR30:
148 case QImage::Format_A2BGR30_Premultiplied:
149 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
152 premultiplied =
true;
154 needsConversion =
true;
157 case QImage::Format_RGB30:
158 case QImage::Format_A2RGB30_Premultiplied:
159 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
162 premultiplied =
true;
165 needsConversion =
true;
169 needsConversion =
true;
172 if (!needsConversion && image.bytesPerLine() != (size.width() * 4) && ctx->isOpenGLES() && ctx->format().majorVersion() < 3)
173 needsConversion =
true;
175 image.convertTo(QImage::Format_RGBA8888);
177 bool needsRowLength = (image.bytesPerLine() != image.width() * 4);
178 QOpenGLFunctions *funcs = ctx->functions();
180 QRect rect = subRect;
181 if (rect.isNull() || rect == QRect(QPoint(0,0),size)) {
184 funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.height(), 0, GL_RGBA, pixelType, image.constBits());
188 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
191 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
192 image.constScanLine(rect.y()) + rect.x() * 4);
198 if (rect.width() >= size.width() / 2) {
200 rect.setWidth(size.width());
206 if (rect.width() == image.bytesPerLine() / 4) {
207 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
208 image.constScanLine(rect.y()));
210 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
211 image.copy(rect).constBits());
216 *swizzleRandB = swizzle;
218 *premultipliedB = premultiplied;
223 Q_UNUSED(graphicsBuffer);
224 Q_UNUSED(swizzleRandB);
225 Q_UNUSED(premultipliedB);