summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-12 12:43:15 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-12 12:43:15 (GMT)
commit5038fe5d545292c58f0e06b1b6a34115ef8d357a (patch)
tree87a5ed53c8be616d5437fa0877ec2ea98de5c614
parentc53414e11b3f980f81a4470b3fb52f9d1aa80d56 (diff)
parentd834d94bde645d43dd981154bd0ba99d8e81f040 (diff)
downloadQt-5038fe5d545292c58f0e06b1b6a34115ef8d357a.zip
Qt-5038fe5d545292c58f0e06b1b6a34115ef8d357a.tar.gz
Qt-5038fe5d545292c58f0e06b1b6a34115ef8d357a.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
-rw-r--r--doc/src/qtnetwork.qdoc66
-rw-r--r--doc/src/snippets/qprocess-environment/main.cpp2
-rw-r--r--src/corelib/codecs/qtextcodec.cpp4
-rw-r--r--src/gui/painting/qbrush.cpp2
-rw-r--r--src/gui/painting/qdrawutil.h16
-rw-r--r--src/gui/widgets/qbuttongroup.cpp9
-rw-r--r--src/network/access/qhttp.cpp8
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager.cpp11
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadermanager_p.h8
-rw-r--r--src/opengl/gl2paintengineex/qglengineshadersource_p.h17
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp26
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h2
-rw-r--r--src/opengl/qpixmapdata_gl.cpp67
-rw-r--r--src/opengl/qpixmapdata_gl_p.h4
-rw-r--r--src/opengl/qwindowsurface_gl.cpp20
-rw-r--r--src/opengl/qwindowsurface_gl_p.h6
-rw-r--r--src/testlib/qtestelementattribute.cpp60
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp105
18 files changed, 323 insertions, 110 deletions
diff --git a/doc/src/qtnetwork.qdoc b/doc/src/qtnetwork.qdoc
index 2be7457..3773c81 100644
--- a/doc/src/qtnetwork.qdoc
+++ b/doc/src/qtnetwork.qdoc
@@ -51,7 +51,7 @@
write TCP/IP clients and servers.
The network module provides classes to make network programming
- easier and portable. It offers classes such as QHttp and QFtp that
+ easier and portable. It offers classes such as QFtp that
implement specific application-level protocols, lower-level classes
such as QTcpSocket, QTcpServer and QUdpSocket that represent low
level network concepts, and high level classes such as QNetworkRequest,
@@ -81,7 +81,7 @@
\snippet doc/src/snippets/code/doc_src_qtnetwork.qdoc 1
- \section1 High Level Network Operations
+ \section1 High Level Network Operations for HTTP and FTP
The Network Access API is a collection of classes for performing
common network operations. The API provides an abstraction layer
@@ -94,6 +94,8 @@
with a request, such as any header information and the encryption
used. The URL specified when a request object is constructed
determines the protocol used for a request.
+ Currently HTTP, FTP and local file URLs are supported for uploading
+ and downloading.
The coordination of network operations is performed by the
QNetworkAccessManager class. Once a request has been created,
@@ -113,65 +115,50 @@
Each application or library can create one or more instances of
QNetworkAccessManager to handle network communication.
+
+ \section1 Writing FTP Clients with QFtp
- \section1 Writing HTTP and FTP Clients with QHttp and QFtp
+ FTP (File Transfer Protocol) is a protocol used almost exclusively
+ for browsing remote directories and for transferring files.
- HTTP (Hypertext Transfer Protocol) is an application-level
- network protocol used mainly for downloading HTML and XML files,
- but it is also used as a high-level transport protocol for many
- other types of data, from images and movies to purchase orders
- and banking transactions. In contrast, FTP (File Transfer
- Protocol) is a protocol used almost exclusively for browsing
- remote directories and for transferring files.
+ \image httpstack.png FTP Client and Server
- \image httpstack.png HTTP Client and Server
-
- HTTP is a simpler protocol than FTP in many ways. It uses only
- one network connection, while FTP uses two (one for sending
- commands, and one for transferring data). HTTP is a stateless
- protocol; requests and responses are always self-contained. The
+ FTP uses two network connections, one for sending
+ commands and one for transferring data. The
FTP protocol has a state and requires the client to send several
commands before a file transfer takes place.
+ FTP clients establish a connection
+ and keeps it open throughout the session. In each session, multiple
+ transfers can occur.
- In practice, HTTP clients often use separate connections for
- separate requests, whereas FTP clients establish one connection
- and keep it open throughout the session.
-
- The QHttp and QFtp classes provide client-side support for HTTP
- and FTP. Since the two protocols are used to solve the same
- problems, the QHttp and QFtp classes have many features in
- common:
-
+ The QFtp class provides client-side support for FTP.
+ It has the following characteristics:
\list
- \o \e{Non-blocking behavior.} QHttp and QFtp are asynchronous.
- You can schedule a series of commands (also called "requests" for
- HTTP). The commands are executed later, when control returns to
- Qt's event loop.
+ \o \e{Non-blocking behavior.} QFtp is asynchronous.
+ You can schedule a series of commands which are executed later,
+ when control returns to Qt's event loop.
\o \e{Command IDs.} Each command has a unique ID number that you
can use to follow the execution of the command. For example, QFtp
emits the \l{QFtp::commandStarted()}{commandStarted()} and
\l{QFtp::commandFinished()}{commandFinished()} signal with the
- command ID for each command that is executed. QHttp has a
- \l{QHttp::requestStarted()}{requestStarted()} and a
- \l{QHttp::requestFinished()}{requestFinished()} signal that work
- the same way.
+ command ID for each command that is executed.
- \o \e{Data transfer progress indicators.} QHttp and QFtp emit
+ \o \e{Data transfer progress indicators.} QFtp emits
signals whenever data is transferred
(QFtp::dataTransferProgress(), QHttp::dataReadProgress(), and
QHttp::dataSendProgress()). You could connect these signals to
QProgressBar::setProgress() or QProgressDialog::setProgress(),
for example.
- \o \e{QIODevice support.} Both classes support convenient
+ \o \e{QIODevice support.} The class supports convenient
uploading from and downloading to \l{QIODevice}s, in addition to a
QByteArray-based API.
\endlist
- There are two main ways of using QHttp and QFtp. The most common
+ There are two main ways of using QFtp. The most common
approach is to keep track of the command IDs and follow the
execution of every command by connecting to the appropriate
signals. The other approach is to schedule all commands at once
@@ -182,10 +169,9 @@
commands based on the result of a previous command. It also
enables you to provide detailed feedback to the user.
- The \l{network/http}{HTTP} and \l{network/ftp}{FTP} examples
- illustrate how to write an HTTP and an FTP client.
-
- Writing your own HTTP or FTP server is possible using the
+ The \l{network/ftp}{FTP} example
+ illustrates how to write an FTP client.
+ Writing your own FTP (or HTTP) server is possible using the
lower-level classes QTcpSocket and QTcpServer.
\section1 Using TCP with QTcpSocket and QTcpServer
diff --git a/doc/src/snippets/qprocess-environment/main.cpp b/doc/src/snippets/qprocess-environment/main.cpp
index 148518b..c8681e7 100644
--- a/doc/src/snippets/qprocess-environment/main.cpp
+++ b/doc/src/snippets/qprocess-environment/main.cpp
@@ -62,7 +62,7 @@ env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
env["PATH"] += ";C:\\Bin";
process.setEnvironment(env);
process.start("myapp");
-//! [0]
+//! [1]
}
}
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp
index 050c997..2aec40f 100644
--- a/src/corelib/codecs/qtextcodec.cpp
+++ b/src/corelib/codecs/qtextcodec.cpp
@@ -1510,7 +1510,7 @@ QString QTextDecoder::toUnicode(const QByteArray &ba)
cannot be detected from the content provided, \a defaultCodec is
returned.
- \sa codecForUtfText
+ \sa codecForUtfText()
*/
QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec)
{
@@ -1556,7 +1556,7 @@ QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba)
cannot be detected from the content provided, \a defaultCodec is
returned.
- \sa codecForHtml
+ \sa codecForHtml()
*/
QTextCodec *QTextCodec::codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec)
{
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index 854d0aa..ea93764 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -217,7 +217,7 @@ struct QTexturedBrushData : public QBrushData
// returns true if the brush has a pixmap (or bitmap) set as the
// brush texture, false otherwise
-bool qHasPixmapTexture(const QBrush& brush)
+bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush)
{
if (brush.style() != Qt::TexturePattern)
return false;
diff --git a/src/gui/painting/qdrawutil.h b/src/gui/painting/qdrawutil.h
index 38d9ec0..306f4e2 100644
--- a/src/gui/painting/qdrawutil.h
+++ b/src/gui/painting/qdrawutil.h
@@ -161,10 +161,18 @@ struct Q_GUI_EXPORT QTileRules
Qt::TileRule vertical;
};
-Q_GUI_EXPORT void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, const QPixmap &pixmap,
- const QRect &sourceRect, const QMargins &sourceMargins, const QTileRules &rules = QTileRules());
-
-Q_GUI_EXPORT inline void qDrawBorderPixmap(QPainter *painter, const QRect &target, const QMargins &margins, const QPixmap &pixmap)
+Q_GUI_EXPORT void qDrawBorderPixmap(QPainter *painter,
+ const QRect &targetRect,
+ const QMargins &targetMargins,
+ const QPixmap &pixmap,
+ const QRect &sourceRect,
+ const QMargins &sourceMargins,
+ const QTileRules &rules = QTileRules());
+
+Q_GUI_EXPORT inline void qDrawBorderPixmap(QPainter *painter,
+ const QRect &target,
+ const QMargins &margins,
+ const QPixmap &pixmap)
{
qDrawBorderPixmap(painter, target, margins, pixmap, pixmap.rect(), margins);
}
diff --git a/src/gui/widgets/qbuttongroup.cpp b/src/gui/widgets/qbuttongroup.cpp
index ebfafe3..1003523 100644
--- a/src/gui/widgets/qbuttongroup.cpp
+++ b/src/gui/widgets/qbuttongroup.cpp
@@ -178,10 +178,11 @@
/*!
\fn void QButtonGroup::addButton(QAbstractButton *button);
- Adds the given \a button to the end of the group's internal list of buttons.
- An \a id will be assigned to the button by this QButtonGroup. Automatically
- assigned ids are guaranteed to be negative, starting with -2. If you are also
- assigning your own ids, use positive values to avoid conflicts.
+ Adds the given \a button to the end of the group's internal list
+ of buttons. An id will be assigned to the button by this
+ QButtonGroup. Automatically assigned ids are guaranteed to be
+ negative, starting with -2. If you are also assigning your own
+ ids, use positive values to avoid conflicts.
\sa removeButton() buttons()
*/
diff --git a/src/network/access/qhttp.cpp b/src/network/access/qhttp.cpp
index 49ce5a3..711de24 100644
--- a/src/network/access/qhttp.cpp
+++ b/src/network/access/qhttp.cpp
@@ -1413,6 +1413,7 @@ QString QHttpRequestHeader::toString() const
****************************************************/
/*!
\class QHttp
+ \obsolete
\reentrant
\brief The QHttp class provides an implementation of the HTTP protocol.
@@ -1422,10 +1423,11 @@ QString QHttpRequestHeader::toString() const
\mainclass
This class provides a direct interface to HTTP that allows you to
- have more control over the requests and that allows you to access
- the response header fields. However, for new applications, it is
+ download and upload data with the HTTP protocol.
+ However, for new applications, it is
recommended to use QNetworkAccessManager and QNetworkReply, as
- those classes possess a simpler, yet more powerful API.
+ those classes possess a simpler, yet more powerful API
+ and a more modern protocol implementation.
The class works asynchronously, so there are no blocking
functions. If an operation cannot be executed immediately, the
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
index 5c541d0..b71c4c1 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager.cpp
@@ -107,9 +107,11 @@ QGLEngineShaderManager::QGLEngineShaderManager(QGLContext* context)
code[MainFragmentShader] = qglslMainFragmentShader;
code[ImageSrcFragmentShader] = qglslImageSrcFragmentShader;
+ code[ImageSrcWithPatternFragmentShader] = qglslImageSrcWithPatternFragmentShader;
code[NonPremultipliedImageSrcFragmentShader] = qglslNonPremultipliedImageSrcFragmentShader;
code[SolidBrushSrcFragmentShader] = qglslSolidBrushSrcFragmentShader;
code[TextureBrushSrcFragmentShader] = qglslTextureBrushSrcFragmentShader;
+ code[TextureBrushSrcWithPatternFragmentShader] = qglslTextureBrushSrcWithPatternFragmentShader;
code[PatternBrushSrcFragmentShader] = qglslPatternBrushSrcFragmentShader;
code[LinearGradientBrushSrcFragmentShader] = qglslLinearGradientBrushSrcFragmentShader;
code[RadialGradientBrushSrcFragmentShader] = qglslRadialGradientBrushSrcFragmentShader;
@@ -296,6 +298,15 @@ bool QGLEngineShaderManager::useCorrectShaderProg()
srcPixelFragShaderName = ImageSrcFragmentShader;
positionVertexShaderName = PositionOnlyVertexShader;
break;
+ case QGLEngineShaderManager::PatternSrc:
+ srcPixelFragShaderName = ImageSrcWithPatternFragmentShader;
+ positionVertexShaderName = PositionOnlyVertexShader;
+ break;
+ case QGLEngineShaderManager::TextureSrcWithPattern:
+ srcPixelFragShaderName = TextureBrushSrcWithPatternFragmentShader;
+ positionVertexShaderName = isAffine ? AffinePositionWithTextureBrushVertexShader
+ : PositionWithTextureBrushVertexShader;
+ break;
case QGLEngineShaderManager::NonPremultipliedImageSrc:
srcPixelFragShaderName = NonPremultipliedImageSrcFragmentShader;
positionVertexShaderName = PositionOnlyVertexShader;
diff --git a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
index afbc918..4a55eca 100644
--- a/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadermanager_p.h
@@ -129,9 +129,11 @@
Brushes & image drawing are implementations of "qcolorp vec4 srcPixel()":
qglslImageSrcFragShader
+ qglslImageSrcWithPatternFragShader
qglslNonPremultipliedImageSrcFragShader
qglslSolidBrushSrcFragShader
qglslTextureBrushSrcFragShader
+ qglslTextureBrushWithPatternFragShader
qglslPatternBrushSrcFragShader
qglslLinearGradientBrushSrcFragShader
qglslRadialGradientBrushSrcFragShader
@@ -265,7 +267,9 @@ public:
enum MaskType {NoMask, PixelMask, SubPixelMask, SubPixelWithGammaMask};
enum PixelSrcType {
ImageSrc = Qt::TexturePattern+1,
- NonPremultipliedImageSrc = Qt::TexturePattern+2
+ NonPremultipliedImageSrc = Qt::TexturePattern+2,
+ PatternSrc = Qt::TexturePattern+3,
+ TextureSrcWithPattern = Qt::TexturePattern+4
};
// There are optimisations we can do, depending on the brush transform:
@@ -313,9 +317,11 @@ public:
MainFragmentShader,
ImageSrcFragmentShader,
+ ImageSrcWithPatternFragmentShader,
NonPremultipliedImageSrcFragmentShader,
SolidBrushSrcFragmentShader,
TextureBrushSrcFragmentShader,
+ TextureBrushSrcWithPatternFragmentShader,
PatternBrushSrcFragmentShader,
LinearGradientBrushSrcFragmentShader,
RadialGradientBrushSrcFragmentShader,
diff --git a/src/opengl/gl2paintengineex/qglengineshadersource_p.h b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
index 70cc67e..61cc63e 100644
--- a/src/opengl/gl2paintengineex/qglengineshadersource_p.h
+++ b/src/opengl/gl2paintengineex/qglengineshadersource_p.h
@@ -130,7 +130,7 @@ static const char* const qglslPatternBrushSrcFragmentShader = "\
uniform lowp vec4 patternColor; \
varying mediump vec2 patternTexCoords;\
lowp vec4 srcPixel() { \
- return patternColor * texture2D(brushTexture, patternTexCoords).r; \
+ return patternColor * (1.0 - texture2D(brushTexture, patternTexCoords).r); \
}\n";
@@ -278,6 +278,13 @@ static const char* const qglslTextureBrushSrcFragmentShader = "\
return texture2D(brushTexture, brushTextureCoords); \
}";
+static const char* const qglslTextureBrushSrcWithPatternFragmentShader = "\
+ varying mediump vec2 brushTextureCoords; \
+ uniform lowp vec4 patternColor; \
+ uniform sampler2D brushTexture; \
+ lowp vec4 srcPixel() { \
+ return patternColor * (1.0 - texture2D(brushTexture, brushTextureCoords).r); \
+ }";
// Solid Fill Brush
static const char* const qglslSolidBrushSrcFragmentShader = "\
@@ -293,6 +300,14 @@ static const char* const qglslImageSrcFragmentShader = "\
return texture2D(imageTexture, textureCoords); \
}";
+static const char* const qglslImageSrcWithPatternFragmentShader = "\
+ varying highp vec2 textureCoords; \
+ uniform lowp vec4 patternColor; \
+ uniform sampler2D imageTexture; \
+ lowp vec4 srcPixel() { \
+ return patternColor * (1.0 - texture2D(imageTexture, textureCoords).r); \
+ }\n";
+
static const char* const qglslNonPremultipliedImageSrcFragmentShader = "\
varying highp vec2 textureCoords; \
uniform sampler2D imageTexture; \
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index bdea187..d1c6e9f 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -279,7 +279,13 @@ void QGL2PaintEngineExPrivate::setBrush(const QBrush* brush)
currentBrush = brush;
brushTextureDirty = true;
brushUniformsDirty = true;
- shaderManager->setSrcPixelType(currentBrush->style());
+ if (currentBrush->style() == Qt::TexturePattern
+ && qHasPixmapTexture(*brush) && brush->texture().isQBitmap())
+ {
+ shaderManager->setSrcPixelType(QGLEngineShaderManager::TextureSrcWithPattern);
+ } else {
+ shaderManager->setSrcPixelType(currentBrush->style());
+ }
shaderManager->optimiseForBrushTransform(currentBrush->transform());
}
@@ -314,7 +320,7 @@ void QGL2PaintEngineExPrivate::updateBrushTexture()
if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) {
// Get the image data for the pattern
- QImage texImage = qt_imageForBrush(style, true);
+ QImage texImage = qt_imageForBrush(style, false);
glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT);
ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, true);
@@ -432,6 +438,11 @@ void QGL2PaintEngineExPrivate::updateBrushUniforms()
const QPixmap& texPixmap = currentBrush->texture();
+ if (qHasPixmapTexture(*currentBrush) && currentBrush->texture().isQBitmap()) {
+ QColor col = premultiplyColor(currentBrush->color(), (GLfloat)q->state()->opacity);
+ shaderManager->currentProgram()->setUniformValue("patternColor", col);
+ }
+
QSizeF invertedTextureSize( 1.0 / texPixmap.width(), 1.0 / texPixmap.height() );
shaderManager->currentProgram()->setUniformValue("invertedTextureSize", invertedTextureSize);
@@ -578,17 +589,22 @@ static inline void setCoords(GLfloat *coords, const QGLRect &rect)
coords[7] = rect.bottom;
}
-void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque)
+void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern)
{
transferMode(ImageDrawingMode);
updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform);
// Setup for texture drawing
- shaderManager->setSrcPixelType(QGLEngineShaderManager::ImageSrc);
+ shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc);
shaderManager->setTextureCoordsEnabled(true);
prepareForDraw(opaque);
+ if (pattern) {
+ QColor col = premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity);
+ shaderManager->currentProgram()->setUniformValue("patternColor", col);
+ }
+
shaderManager->currentProgram()->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT);
GLfloat dx = 1.0 / textureSize.width();
@@ -987,7 +1003,7 @@ void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, c
ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, true);
//FIXME: we should use hasAlpha() instead, but that's SLOW at the moment
- d->drawTexture(dest, src, pixmap.size(), !pixmap.hasAlphaChannel());
+ d->drawTexture(dest, src, pixmap.size(), !pixmap.hasAlphaChannel(), pixmap.depth() == 1);
}
void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src,
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index db39ced..8a50096 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -165,7 +165,7 @@ public:
// fill, drawOutline, drawTexture & drawCachedGlyphs are the rendering entry points:
void fill(const QVectorPath &path);
void drawOutline(const QVectorPath& path);
- void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque);
+ void drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false);
void drawCachedGlyphs(const QPointF &p, const QTextItemInt &ti);
void drawVertexArrays(QGL2PEXVertexArray& vertexArray, GLenum primitive);
diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp
index 98c406b..4c53c46 100644
--- a/src/opengl/qpixmapdata_gl.cpp
+++ b/src/opengl/qpixmapdata_gl.cpp
@@ -104,6 +104,7 @@ QGLPixmapData::QGLPixmapData(PixelType type)
, m_ctx(0)
, m_dirty(false)
, m_hasFillColor(false)
+ , m_hasAlpha(false)
{
setSerialNumber(++qt_gl_pixmap_serial);
}
@@ -136,6 +137,11 @@ void QGLPixmapData::resize(int width, int height)
if (width == m_width && height == m_height)
return;
+ if (width <= 0 || height <= 0) {
+ width = 0;
+ height = 0;
+ }
+
m_width = width;
m_height = height;
@@ -166,7 +172,8 @@ void QGLPixmapData::ensureCreated() const
if (!m_textureId) {
glGenTextures(1, &m_textureId);
glBindTexture(target, m_textureId);
- glTexImage2D(target, 0, GL_RGBA, m_width, m_height, 0,
+ GLenum format = m_hasAlpha ? GL_RGBA : GL_RGB;
+ glTexImage2D(target, 0, format, m_width, m_height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -195,10 +202,20 @@ void QGLPixmapData::fromImage(const QImage &image,
if (image.size() == QSize(m_width, m_height))
setSerialNumber(++qt_gl_pixmap_serial);
resize(image.width(), image.height());
- m_source = image;
+
+ if (pixelType() == BitmapType) {
+ m_source = image.convertToFormat(QImage::Format_MonoLSB);
+ } else {
+ m_source = image.hasAlphaChannel()
+ ? image.convertToFormat(QImage::Format_ARGB32_Premultiplied)
+ : image.convertToFormat(QImage::Format_RGB32);
+ }
+
m_dirty = true;
m_hasFillColor = false;
+ m_hasAlpha = image.hasAlphaChannel();
+
if (m_textureId) {
QGLShareContextScope ctx(qt_gl_share_widget()->context());
glDeleteTextures(1, &m_textureId);
@@ -230,24 +247,46 @@ void QGLPixmapData::fill(const QColor &color)
if (!isValid())
return;
+ if (!m_textureId)
+ m_hasAlpha = color.alpha() != 255;
+
if (useFramebufferObjects()) {
m_source = QImage();
m_hasFillColor = true;
m_fillColor = color;
- } else if (!m_source.isNull()) {
- m_source.fill(PREMUL(color.rgba()));
} else {
- // ## TODO: improve performance here
- QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
- img.fill(PREMUL(color.rgba()));
-
- fromImage(img, 0);
+ QImage image = fillImage(color);
+ fromImage(image, 0);
}
}
bool QGLPixmapData::hasAlphaChannel() const
{
- return true;
+ return pixelType() == BitmapType || m_hasAlpha;
+}
+
+QImage QGLPixmapData::fillImage(const QColor &color) const
+{
+ QImage img;
+ if (pixelType() == BitmapType) {
+ img = QImage(m_width, m_height, QImage::Format_MonoLSB);
+ img.setNumColors(2);
+ img.setColor(0, QColor(Qt::color0).rgba());
+ img.setColor(1, QColor(Qt::color1).rgba());
+
+ int gray = qGray(color.rgba());
+ if (qAbs(255 - gray) < gray)
+ img.fill(0);
+ else
+ img.fill(1);
+ } else {
+ img = QImage(m_width, m_height,
+ m_hasAlpha
+ ? QImage::Format_ARGB32_Premultiplied
+ : QImage::Format_RGB32);
+ img.fill(PREMUL(color.rgba()));
+ }
+ return img;
}
QImage QGLPixmapData::toImage() const
@@ -260,10 +299,7 @@ QImage QGLPixmapData::toImage() const
} else if (!m_source.isNull()) {
return m_source;
} else if (m_dirty || m_hasFillColor) {
- QImage img(m_width, m_height, QImage::Format_ARGB32_Premultiplied);
- if (m_hasFillColor)
- img.fill(PREMUL(m_fillColor.rgba()));
- return img;
+ return fillImage(m_fillColor);
} else {
ensureCreated();
}
@@ -453,6 +489,9 @@ extern int qt_defaultDpiY();
int QGLPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
{
+ if (m_width == 0)
+ return 0;
+
switch (metric) {
case QPaintDevice::PdmWidth:
return m_width;
diff --git a/src/opengl/qpixmapdata_gl_p.h b/src/opengl/qpixmapdata_gl_p.h
index 1b6b7ae..af10f2c 100644
--- a/src/opengl/qpixmapdata_gl_p.h
+++ b/src/opengl/qpixmapdata_gl_p.h
@@ -115,6 +115,8 @@ private:
static bool useFramebufferObjects();
+ QImage fillImage(const QColor &color) const;
+
int m_width;
int m_height;
@@ -131,6 +133,8 @@ private:
// represented by a single fill color
mutable QColor m_fillColor;
mutable bool m_hasFillColor;
+
+ mutable bool m_hasAlpha;
};
QT_END_NAMESPACE
diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp
index 965c7a5..01974a2 100644
--- a/src/opengl/qwindowsurface_gl.cpp
+++ b/src/opengl/qwindowsurface_gl.cpp
@@ -272,6 +272,24 @@ QGLWindowSurface::~QGLWindowSurface()
delete d_ptr;
}
+void QGLWindowSurface::deleted(QObject *object)
+{
+ QWidget *widget = qobject_cast<QWidget *>(object);
+ if (widget) {
+ QWidgetPrivate *widgetPrivate = widget->d_func();
+ if (widgetPrivate->extraData()) {
+ union { QGLContext **ctxPtr; void **voidPtr; };
+ voidPtr = &widgetPrivate->extraData()->glContext;
+ int index = d_ptr->contexts.indexOf(ctxPtr);
+ if (index != -1) {
+ delete *ctxPtr;
+ *ctxPtr = 0;
+ d_ptr->contexts.removeAt(index);
+ }
+ }
+ }
+}
+
void QGLWindowSurface::hijackWindow(QWidget *widget)
{
QWidgetPrivate *widgetPrivate = widget->d_func();
@@ -288,6 +306,8 @@ void QGLWindowSurface::hijackWindow(QWidget *widget)
union { QGLContext **ctxPtr; void **voidPtr; };
+ connect(widget, SIGNAL(destroyed(QObject *)), this, SLOT(deleted(QObject *)));
+
voidPtr = &widgetPrivate->extraData()->glContext;
d_ptr->contexts << ctxPtr;
qDebug() << "hijackWindow() context created for" << widget << d_ptr->contexts.size();
diff --git a/src/opengl/qwindowsurface_gl_p.h b/src/opengl/qwindowsurface_gl_p.h
index d47e3e3..9efd1ae 100644
--- a/src/opengl/qwindowsurface_gl_p.h
+++ b/src/opengl/qwindowsurface_gl_p.h
@@ -65,8 +65,9 @@ class QRegion;
class QWidget;
struct QGLWindowSurfacePrivate;
-class QGLWindowSurface : public QWindowSurface, public QPaintDevice
+class QGLWindowSurface : public QObject, public QWindowSurface, public QPaintDevice
{
+ Q_OBJECT
public:
QGLWindowSurface(QWidget *window);
~QGLWindowSurface();
@@ -91,6 +92,9 @@ public:
protected:
int metric(PaintDeviceMetric metric) const;
+private slots:
+ void deleted(QObject *object);
+
private:
void hijackWindow(QWidget *widget);
diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp
index 540389b..783b83d 100644
--- a/src/testlib/qtestelementattribute.cpp
+++ b/src/testlib/qtestelementattribute.cpp
@@ -46,6 +46,66 @@
QT_BEGIN_NAMESPACE
+/*! \enum QTest::AttributeIndex
+ This enum numbers the different tests.
+
+ \value AI_Undefined
+
+ \value AI_Name
+
+ \value AI_Result
+
+ \value AI_Tests
+
+ \value AI_Failures
+
+ \value AI_Errors
+
+ \value AI_Type
+
+ \value AI_Description
+
+ \value AI_PropertyValue
+
+ \value AI_QTestVersion
+
+ \value AI_QtVersion
+
+ \value AI_File
+
+ \value AI_Line
+
+ \value AI_Metric
+
+ \value AI_Tag
+
+ \value AI_Value
+
+ \value AI_Iterations
+*/
+
+/*! \enum QTest::LogElementType
+ The enum specifies the kinds of test log messages.
+
+ \value LET_Undefined
+
+ \value LET_Property
+
+ \value LET_Properties
+
+ \value LET_Failure
+
+ \value LET_Error
+
+ \value LET_TestCase
+
+ \value LET_TestSuite
+
+ \value LET_Benchmark
+
+ \value LET_SystemError
+*/
+
QTestElementAttribute::QTestElementAttribute()
:attributeValue(0),
attributeIndex(QTest::AI_Undefined)
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 058c3c6..06e50d7 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -48,6 +48,8 @@
#include <qdesktopwidget.h>
#include <qpaintengine.h>
+#include <private/qpixmapdata_p.h>
+
#include <QSet>
#ifdef Q_WS_WIN
@@ -140,6 +142,38 @@ private slots:
void fromData();
};
+static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
+{
+ QImage expectedImage = expected.toImage().convertToFormat(QImage::Format_RGB32);
+ QImage actualImage = actual.toImage().convertToFormat(QImage::Format_RGB32);
+
+ if (expectedImage.size() != actualImage.size())
+ return false;
+
+ int size = actual.width() * actual.height();
+
+ QRgb *a = (QRgb *)actualImage.bits();
+ QRgb *e = (QRgb *)expectedImage.bits();
+ for (int i = 0; i < size; ++i) {
+ QColor ca(a[i]);
+ QColor ce(e[i]);
+
+ bool result = true;
+
+ if (qAbs(ca.red() - ce.red()) > 2)
+ result = false;
+ if (qAbs(ca.green() - ce.green()) > 2)
+ result = false;
+ if (qAbs(ca.blue() - ce.blue()) > 2)
+ result = false;
+
+ if (!result)
+ return false;
+ }
+
+ return true;
+}
+
Q_DECLARE_METATYPE(QImage)
Q_DECLARE_METATYPE(QPixmap)
Q_DECLARE_METATYPE(QMatrix)
@@ -202,7 +236,7 @@ void tst_QPixmap::setAlphaChannel()
pixmap.setAlphaChannel(alphaChannel);
#ifdef Q_WS_X11
- if (!pixmap.x11PictureHandle())
+ if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle())
QSKIP("Requires XRender support", SkipAll);
#endif
@@ -261,7 +295,7 @@ void tst_QPixmap::fromImage()
const QPixmap pixmap = QPixmap::fromImage(image);
#ifdef Q_WS_X11
- if (!pixmap.x11PictureHandle())
+ if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle())
QSKIP("Requires XRender support", SkipAll);
#endif
const QImage result = pixmap.toImage();
@@ -392,9 +426,9 @@ void tst_QPixmap::scroll()
#else
QString fileName = QString(":/images/%1.png").arg(QTest::currentDataTag());
#endif
- QImage output(fileName);
+ QPixmap output(fileName);
QVERIFY(input.isNull() == output.isNull());
- QCOMPARE(pixmap.toImage(), output);
+ QVERIFY(lenientCompare(pixmap, output));
QCOMPARE(exp, exposed);
}
@@ -463,7 +497,7 @@ void tst_QPixmap::fill()
pm = QPixmap(400, 400);
#if defined(Q_WS_X11)
- if (!bitmap && !pm.x11PictureHandle())
+ if (!bitmap && pm.pixmapData()->classId() == QPixmapData::X11Class && !pm.x11PictureHandle())
QSKIP("Requires XRender support", SkipSingle);
#endif
@@ -475,7 +509,7 @@ void tst_QPixmap::fill()
QImage image = pm.toImage();
if (bitmap && syscolor) {
int pixelindex = (pixel == Qt::color0) ? 0 : 1;
- QVERIFY(image.pixelIndex(0,0) == pixelindex);
+ QCOMPARE(image.pixelIndex(0,0), pixelindex);
}
QImage::Format format = compareColor.alpha() != 255
? QImage::Format_ARGB32
@@ -493,7 +527,7 @@ void tst_QPixmap::fill_transparent()
{
QPixmap pixmap(10, 10);
#ifdef Q_WS_X11
- if (!pixmap.x11PictureHandle())
+ if (pixmap.pixmapData()->classId() == QPixmapData::X11Class && !pixmap.x11PictureHandle())
QSKIP("Requires XRender support", SkipAll);
#endif
pixmap.fill(Qt::transparent);
@@ -613,7 +647,7 @@ void tst_QPixmap::testMetrics()
QCOMPARE(pixmap.width(), 100);
QCOMPARE(pixmap.height(), 100);
- QCOMPARE(pixmap.depth(), QPixmap::defaultDepth());
+ QVERIFY(pixmap.depth() >= QPixmap::defaultDepth());
QBitmap bitmap(100, 100);
@@ -675,7 +709,11 @@ void tst_QPixmap::drawBitmap()
painter2.setPen(Qt::red);
painter2.drawPixmap(0,0,10,10, bitmap);
painter2.end();
- QCOMPARE(pixmap.toImage().pixel(5,5), QColor(Qt::red).rgb());
+
+ QPixmap expected(10, 10);
+ expected.fill(Qt::red);
+
+ QVERIFY(lenientCompare(pixmap, expected));
}
void tst_QPixmap::grabWidget()
@@ -688,8 +726,7 @@ void tst_QPixmap::grabWidget()
expected.fill(Qt::green);
QPixmap actual = QPixmap::grabWidget(&widget, QRect(64, 64, 64, 64));
-
- QCOMPARE(actual, expected);
+ QVERIFY(lenientCompare(actual, expected));
}
void tst_QPixmap::grabWindow()
@@ -720,7 +757,7 @@ void tst_QPixmap::grabWindow()
QPixmap grabWindowPixmap = QPixmap::grabWindow(child.winId());
QPixmap grabWidgetPixmap = QPixmap::grabWidget(&child);
- QCOMPARE(grabWindowPixmap, grabWidgetPixmap);
+ lenientCompare(grabWindowPixmap, grabWidgetPixmap);
}
void tst_QPixmap::isNull()
@@ -960,10 +997,10 @@ void tst_QPixmap::copy()
}
QPixmap dest = src.copy(10, 10, 10, 10);
- QImage result = dest.toImage().convertToFormat(QImage::Format_RGB32);
- QImage expected(10, 10, QImage::Format_RGB32);
- expected.fill(0xff0000ff);
- QCOMPARE(result, expected);
+
+ QPixmap expected(10, 10);
+ expected.fill(Qt::blue);
+ QVERIFY(lenientCompare(dest, expected));
}
#ifdef QT3_SUPPORT
@@ -1031,27 +1068,33 @@ void tst_QPixmap::transformed()
}
QPixmap p2(10, 20);
- p2.fill(Qt::red);
{
QPainter p(&p2);
- p.drawRect(0, 0, p2.width() - 1, p2.height() - 1);
+ p.rotate(90);
+ p.drawPixmap(0, -p1.height(), p1);
+ }
+
+ QPixmap p3(20, 10);
+ {
+ QPainter p(&p3);
+ p.rotate(180);
+ p.drawPixmap(-p1.width(), -p1.height(), p1);
+ }
+
+ QPixmap p4(10, 20);
+ {
+ QPainter p(&p4);
+ p.rotate(270);
+ p.drawPixmap(-p1.width(), 0, p1);
}
QPixmap p1_90 = p1.transformed(QTransform().rotate(90));
QPixmap p1_180 = p1.transformed(QTransform().rotate(180));
QPixmap p1_270 = p1.transformed(QTransform().rotate(270));
- QCOMPARE(p1_90.size(), p2.size());
- QCOMPARE(p1_90.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied),
- p2.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied));
-
- QCOMPARE(p1_180.size(), p1.size());
- QCOMPARE(p1_180.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied),
- p1.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied));
-
- QCOMPARE(p1_270.size(), p2.size());
- QCOMPARE(p1_270.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied),
- p2.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied));
+ QVERIFY(lenientCompare(p1_90, p2));
+ QVERIFY(lenientCompare(p1_180, p3));
+ QVERIFY(lenientCompare(p1_270, p4));
}
void tst_QPixmap::transformed2()
@@ -1079,9 +1122,7 @@ void tst_QPixmap::transformed2()
p.drawRect(3, 6, 3, 3);
p.end();
- QCOMPARE(actual.size(), expected.size());
- QCOMPARE(actual.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied),
- expected.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied));
+ QVERIFY(lenientCompare(actual, expected));
}
void tst_QPixmap::fromImage_crash()