59 bool *swizzle,
bool *premultiplied,
62 if (graphicsBuffer->lock(QPlatformGraphicsBuffer::TextureAccess)) {
63 if (!graphicsBuffer->bindToTexture(rect)) {
64 qWarning(
"Failed to bind %sgraphicsbuffer to texture",
"");
70 *premultiplied =
false;
71 }
else if (graphicsBuffer->lock(QPlatformGraphicsBuffer::SWReadAccess)) {
72 if (!bindSWToTexture(graphicsBuffer, swizzle, premultiplied, rect)) {
73 qWarning(
"Failed to bind %sgraphicsbuffer to texture",
"SW ");
77 qWarning(
"Failed to lock");
108bool QPlatformGraphicsBufferHelper::
bindSWToTexture(
const QPlatformGraphicsBuffer *graphicsBuffer,
109 bool *swizzleRandB,
bool *premultipliedB,
110 const QRect &subRect)
113 QOpenGLContext *ctx = QOpenGLContext::currentContext();
117 if (!(graphicsBuffer->isLocked() & QPlatformGraphicsBuffer::SWReadAccess))
120 QSize size = graphicsBuffer->size();
122 Q_ASSERT(subRect.isEmpty() || QRect(QPoint(0,0), size).contains(subRect));
124 GLenum internalFormat = GL_RGBA;
125 GLuint pixelType = GL_UNSIGNED_BYTE;
127 bool needsConversion =
false;
128 bool swizzle =
false;
129 bool premultiplied =
false;
130 QImage::Format imageformat = QImage::toImageFormat(graphicsBuffer->format());
131 QImage image(graphicsBuffer->data(), size.width(), size.height(), graphicsBuffer->bytesPerLine(), imageformat);
132 switch (imageformat) {
133 case QImage::Format_ARGB32_Premultiplied:
134 premultiplied =
true;
136 case QImage::Format_RGB32:
137 case QImage::Format_ARGB32:
140 case QImage::Format_RGBA8888_Premultiplied:
141 premultiplied =
true;
143 case QImage::Format_RGBX8888:
144 case QImage::Format_RGBA8888:
146 case QImage::Format_BGR30:
147 case QImage::Format_A2BGR30_Premultiplied:
148 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
151 premultiplied =
true;
153 needsConversion =
true;
156 case QImage::Format_RGB30:
157 case QImage::Format_A2RGB30_Premultiplied:
158 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
161 premultiplied =
true;
164 needsConversion =
true;
168 needsConversion =
true;
171 if (!needsConversion && image.bytesPerLine() != (size.width() * 4) && ctx->isOpenGLES() && ctx->format().majorVersion() < 3)
172 needsConversion =
true;
174 image.convertTo(QImage::Format_RGBA8888);
176 bool needsRowLength = (image.bytesPerLine() != image.width() * 4);
177 QOpenGLFunctions *funcs = ctx->functions();
179 QRect rect = subRect;
180 if (rect.isNull() || rect == QRect(QPoint(0,0),size)) {
183 funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.height(), 0, GL_RGBA, pixelType, image.constBits());
187 if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) {
190 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
191 image.constScanLine(rect.y()) + rect.x() * 4);
197 if (rect.width() >= size.width() / 2) {
199 rect.setWidth(size.width());
205 if (rect.width() == image.bytesPerLine() / 4) {
206 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, 0, rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
207 image.constScanLine(rect.y()));
209 funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType,
210 image.copy(rect).constBits());
215 *swizzleRandB = swizzle;
217 *premultipliedB = premultiplied;
222 Q_UNUSED(graphicsBuffer);
223 Q_UNUSED(swizzleRandB);
224 Q_UNUSED(premultipliedB);