Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qpaintengine_opengl.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtOpenGL module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
    4040****************************************************************************/
    4141
    42 #include <private/qtextengine_p.h>
    4342#include <qdebug.h>
    4443#include <private/qfontengine_p.h>
     
    5150#include "qgl.h"
    5251#include <private/qgl_p.h>
     52#include <private/qglpaintdevice_p.h>
    5353#include <private/qpainter_p.h>
    5454#include "qmap.h"
     
    5858#include "qvarlengtharray.h"
    5959#include <private/qpainter_p.h>
    60 #include <qglpixelbuffer.h>
    6160#include <private/qglpixelbuffer_p.h>
    6261#include <private/qbezier_p.h>
     
    6463
    6564#include "private/qtessellator_p.h"
    66 #include "private/qwindowsurface_gl_p.h"
    6765
    6866#include "util/fragmentprograms_p.h"
    6967
    7068#ifdef Q_WS_QWS
    71 #include "private/qglpaintdevice_qws_p.h"
    7269#include "private/qglwindowsurface_qws_p.h"
    7370#include "qwsmanager_qws.h"
     
    7976#endif
    8077
    81 #define QGL_FUNC_CONTEXT QGLContext *ctx = const_cast<QGLContext *>(drawable.context());
     78#define QGL_FUNC_CONTEXT QGLContext *ctx = const_cast<QGLContext *>(device->context());
    8279
    8380#include <stdlib.h>
     
    114111static inline void qt_glColor4ubv(unsigned char *col)
    115112{
    116 #ifdef QT_OPENGL_ES
    117         glColor4f(col[0]/255.0, col[1]/255.0, col[2]/255.0, col[3]/255.0);
    118 #else
    119         glColor4ubv(col);
    120 #endif
     113    glColor4f(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, col[3]/255.0f);
    121114}
    122115
     
    125118    qreal y;
    126119};
    127 
    128 void qt_add_rect_to_array(const QRectF &r, q_vertexType *array)
    129 {
    130     qreal left = r.left();
    131     qreal right = r.right();
    132     qreal top = r.top();
    133     qreal bottom = r.bottom();
    134 
    135     array[0] = f2vt(left);
    136     array[1] = f2vt(top);
    137     array[2] = f2vt(right);
    138     array[3] = f2vt(top);
    139     array[4] = f2vt(right);
    140     array[5] = f2vt(bottom);
    141     array[6] = f2vt(left);
    142     array[7] = f2vt(bottom);
    143 }
    144 
    145 void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array)
    146 {
    147     array[0] = f2vt(x1);
    148     array[1] = f2vt(y1);
    149     array[2] = f2vt(x2);
    150     array[3] = f2vt(y1);
    151     array[4] = f2vt(x2);
    152     array[5] = f2vt(y2);
    153     array[6] = f2vt(x1);
    154     array[7] = f2vt(y2);
    155 }
    156120
    157121struct QGLTrapezoid
     
    189153    trap.bottomRightX += delta.x();
    190154    return trap;
    191 }
    192 
    193 class QGLDrawable {
    194 public:
    195     QGLDrawable() : widget(0), buffer(0), fbo(0)
    196                   , wsurf(0)
    197         {}
    198     inline void setDevice(QPaintDevice *pdev);
    199     inline void swapBuffers();
    200     inline void makeCurrent();
    201     inline void doneCurrent();
    202     inline QSize size() const;
    203     inline QGLFormat format() const;
    204     inline GLuint bindTexture(const QImage &image, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
    205     inline GLuint bindTexture(const QPixmap &pixmap, GLenum target = GL_TEXTURE_2D, GLint format = GL_RGBA);
    206     inline QColor backgroundColor() const;
    207     inline QGLContext *context() const;
    208     inline bool autoFillBackground() const;
    209 
    210 private:
    211     bool wasBound;
    212     QGLWidget *widget;
    213     QGLPixelBuffer *buffer;
    214     QGLFramebufferObject *fbo;
    215 #ifdef Q_WS_QWS
    216     QWSGLWindowSurface *wsurf;
    217 #else
    218     QGLWindowSurface *wsurf;
    219 #endif
    220 };
    221 
    222 void QGLDrawable::setDevice(QPaintDevice *pdev)
    223 {
    224     wasBound = false;
    225     widget = 0;
    226     buffer = 0;
    227     fbo = 0;
    228 #ifdef Q_WS_QWS
    229     wsurf = 0;
    230 #endif
    231     if (pdev->devType() == QInternal::Widget)
    232         widget = static_cast<QGLWidget *>(pdev);
    233     else if (pdev->devType() == QInternal::Pbuffer)
    234         buffer = static_cast<QGLPixelBuffer *>(pdev);
    235     else if (pdev->devType() == QInternal::FramebufferObject)
    236         fbo = static_cast<QGLFramebufferObject *>(pdev);
    237     else if (pdev->devType() == QInternal::UnknownDevice)
    238 #ifdef Q_WS_QWS
    239         wsurf = static_cast<QWSGLPaintDevice*>(pdev)->windowSurface();
    240 #else
    241         wsurf = static_cast<QGLWindowSurface *>(pdev);
    242 #endif
    243 }
    244 
    245 inline void QGLDrawable::swapBuffers()
    246 {
    247     if (widget) {
    248         if (widget->autoBufferSwap())
    249             widget->swapBuffers();
    250     } else {
    251         glFlush();
    252     }
    253 }
    254 
    255 inline void QGLDrawable::makeCurrent()
    256 {
    257     if (widget)
    258         widget->makeCurrent();
    259     else if (buffer)
    260         buffer->makeCurrent();
    261     else if (wsurf)
    262         wsurf->context()->makeCurrent();
    263     else if (fbo) {
    264         wasBound = fbo->isBound();
    265         if (!wasBound)
    266             fbo->bind();
    267     }
    268 }
    269 
    270 inline void QGLDrawable::doneCurrent()
    271 {
    272     if (fbo && !wasBound)
    273         fbo->release();
    274 }
    275 
    276 inline QSize QGLDrawable::size() const
    277 {
    278     if (widget) {
    279         return QSize(widget->d_func()->glcx->device()->width(),
    280                      widget->d_func()->glcx->device()->height());
    281     } else if (buffer) {
    282         return buffer->size();
    283     } else if (fbo) {
    284         return fbo->size();
    285     } else if (wsurf) {
    286 #ifdef Q_WS_QWS
    287         return wsurf->window()->frameSize();
    288 #else
    289         return QSize(wsurf->width(), wsurf->height());
    290 #endif
    291     }
    292     return QSize();
    293 }
    294 
    295 inline QGLFormat QGLDrawable::format() const
    296 {
    297     if (widget)
    298         return widget->format();
    299     else if (buffer)
    300         return buffer->format();
    301     else if (wsurf)
    302         return wsurf->context()->format();
    303     else if (fbo && QGLContext::currentContext()) {
    304         QGLFormat fmt = QGLContext::currentContext()->format();
    305         fmt.setStencil(fbo->attachment() == QGLFramebufferObject::CombinedDepthStencil);
    306         fmt.setDepth(fbo->attachment() != QGLFramebufferObject::NoAttachment);
    307         return fmt;
    308     }
    309 
    310     return QGLFormat();
    311 }
    312 
    313 inline GLuint QGLDrawable::bindTexture(const QImage &image, GLenum target, GLint format)
    314 {
    315     if (widget)
    316         return widget->d_func()->glcx->d_func()->bindTexture(image, target, format, true);
    317     else if (buffer)
    318         return buffer->d_func()->qctx->d_func()->bindTexture(image, target, format, true);
    319     else if (fbo && QGLContext::currentContext())
    320         return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(image, target, format, true);
    321     else if (wsurf)
    322         return wsurf->context()->d_func()->bindTexture(image, target, format, true);
    323     return 0;
    324 }
    325 
    326 inline GLuint QGLDrawable::bindTexture(const QPixmap &pixmap, GLenum target, GLint format)
    327 {
    328     if (widget)
    329         return widget->d_func()->glcx->d_func()->bindTexture(pixmap, target, format, true);
    330     else if (buffer)
    331         return buffer->d_func()->qctx->d_func()->bindTexture(pixmap, target, format, true);
    332     else if (fbo && QGLContext::currentContext())
    333         return const_cast<QGLContext *>(QGLContext::currentContext())->d_func()->bindTexture(pixmap, target, format, true);
    334     else if (wsurf)
    335         return wsurf->context()->d_func()->bindTexture(pixmap, target, format, true);
    336     return 0;
    337 }
    338 
    339 inline QColor QGLDrawable::backgroundColor() const
    340 {
    341     if (widget)
    342         return widget->palette().brush(widget->backgroundRole()).color();
    343     return QApplication::palette().brush(QPalette::Background).color();
    344 }
    345 
    346 inline QGLContext *QGLDrawable::context() const
    347 {
    348     if (widget)
    349         return widget->d_func()->glcx;
    350     else if (buffer)
    351         return buffer->d_func()->qctx;
    352     else if (fbo)
    353         return const_cast<QGLContext *>(QGLContext::currentContext());
    354     else if (wsurf)
    355         return wsurf->context();
    356     return 0;
    357 }
    358 
    359 inline bool QGLDrawable::autoFillBackground() const
    360 {
    361     if (widget)
    362         return widget->autoFillBackground();
    363     else
    364         return false;
    365155}
    366156
     
    455245    {
    456246        connect(QGLSignalProxy::instance(),
    457                 SIGNAL(aboutToDestroyContext(const QGLContext *)),
    458                 SLOT(cleanupGLContextRefs(const QGLContext *)));
     247                SIGNAL(aboutToDestroyContext(const QGLContext*)),
     248                SLOT(cleanupGLContextRefs(const QGLContext*)));
    459249    }
    460250
     
    493283
    494284private:
    495     QGLDrawable drawable;
     285    QGLPaintDevice* device;
    496286
    497287    QGLFramebufferObject *offscreen;
     
    512302inline void QGLOffscreen::setDevice(QPaintDevice *pdev)
    513303{
    514     drawable.setDevice(pdev);
     304    if (pdev->devType() == QInternal::OpenGL)
     305        device = static_cast<QGLPaintDevice*>(pdev);
     306    else
     307        device = QGLPaintDevice::getDevice(pdev);
     308
     309    if (!device)
     310        return;
    515311
    516312    drawable_fbo = (pdev->devType() == QInternal::FramebufferObject);
     
    536332    initialized = true;
    537333
    538     int dim = qMax(2048, static_cast<int>(qt_next_power_of_two(qMax(drawable.size().width(), drawable.size().height()))));
    539 
    540     bool shared_context = qgl_share_reg()->checkSharing(drawable.context(), ctx);
     334    int dim = qMax(2048, static_cast<int>(qt_next_power_of_two(qMax(device->size().width(), device->size().height()))));
     335
     336    bool shared_context = QGLContext::areSharing(device->context(), ctx);
    541337    bool would_fail = last_failed_size.isValid() &&
    542                       (drawable.size().width() >= last_failed_size.width() ||
    543                        drawable.size().height() >= last_failed_size.height());
     338                      (device->size().width() >= last_failed_size.width() ||
     339                       device->size().height() >= last_failed_size.height());
    544340    bool needs_refresh = dim > mask_dim || !shared_context;
    545341
     
    555351            offscreen = 0;
    556352            mask_dim = 0;
    557             last_failed_size = drawable.size();
     353            last_failed_size = device->size();
    558354        }
    559355    }
    560356
    561357    qt_mask_texture_cache()->setOffscreenSize(offscreenSize());
    562     qt_mask_texture_cache()->setDrawableSize(drawable.size());
    563     ctx = drawable.context();
     358    qt_mask_texture_cache()->setDrawableSize(device->size());
     359    ctx = device->context();
    564360#endif
    565361}
     
    635431
    636432    if (drawable_fbo)
    637         drawable.makeCurrent();
     433        device->ensureActiveTarget(); //###
    638434    else
    639435        offscreen->release();
    640436
    641     QSize sz(drawable.size());
     437    QSize sz(device->size());
    642438    glViewport(0, 0, sz.width(), sz.height());
    643439
     
    662458inline QSize QGLOffscreen::drawableSize() const
    663459{
    664     return drawable.size();
     460    return device->size();
    665461}
    666462
     
    726522        // we have to know when a context is deleted so we can free
    727523        // any program handles it holds
    728         connect(QGLSignalProxy::instance(), SIGNAL(aboutToDestroyContext(const QGLContext *)),
    729                 SLOT(cleanupPrograms(const QGLContext *)));
     524        connect(QGLSignalProxy::instance(), SIGNAL(aboutToDestroyContext(const QGLContext*)),
     525                SLOT(cleanupPrograms(const QGLContext*)));
    730526
    731527    }
     
    755551        for (int i=0; i<contexts.size(); ++i) {
    756552            const QGLContext *cx = contexts.at(i);
    757             if (cx != ctx && qgl_share_reg()->checkSharing(cx, ctx)) {
     553            if (cx != ctx && QGLContext::areSharing(cx, ctx)) {
    758554                QList<GLProgram> progs = programs.values(cx);
    759555                for (int k=0; k<progs.size(); ++k) {
     
    840636    {
    841637        connect(QGLSignalProxy::instance(),
    842                 SIGNAL(aboutToDestroyContext(const QGLContext *)),
    843                 SLOT(cleanupGLContextRefs(const QGLContext *)));
     638                SIGNAL(aboutToDestroyContext(const QGLContext*)),
     639                SLOT(cleanupGLContextRefs(const QGLContext*)));
    844640    }
    845641
     
    869665        , inverseScale(1)
    870666        , moveToCount(0)
     667        , last_created_state(0)
    871668        , shader_ctx(0)
    872669        , grad_palette(0)
     
    946743    uint has_fast_pen : 1;
    947744    uint use_stencil_method : 1;
    948     uint dirty_stencil : 1;
    949745    uint dirty_drawable_texture : 1;
    950746    uint has_stencil_face_ext : 1;
     
    957753    uint use_emulation : 1;
    958754
     755    QRegion dirty_stencil;
     756
    959757    void updateUseEmulation();
    960758
     
    963761    GLubyte brush_color[4];
    964762    QTransform::TransformationType txop;
    965     QGLDrawable drawable;
     763    QGLPaintDevice* device;
    966764    QGLOffscreen offscreen;
    967765
     
    974772
    975773    void drawImageAsPath(const QRectF &r, const QImage &img, const QRectF &sr);
    976     void drawTiledImageAsPath(const QRectF &r, const QImage &img, qreal sx, qreal sy);
     774    void drawTiledImageAsPath(const QRectF &r, const QImage &img, qreal sx, qreal sy, const QPointF &offset);
    977775
    978776    void drawOffscreenPath(const QPainterPath &path);
     
    994792
    995793    void updateGLMatrix() const;
     794
     795    mutable QPainterState *last_created_state;
    996796
    997797    QGLContext *shader_ctx;
     
    12071007    {
    12081008        connect(QGLSignalProxy::instance(),
    1209                 SIGNAL(aboutToDestroyContext(const QGLContext *)),
    1210                 SLOT(cleanupGLContextRefs(const QGLContext *)));
     1009                SIGNAL(aboutToDestroyContext(const QGLContext*)),
     1010                SLOT(cleanupGLContextRefs(const QGLContext*)));
    12111011    }
    12121012
    12131013    inline GLuint getBuffer(const QGradient &gradient, qreal opacity, QGLContext *ctx) {
    1214         if (buffer_ctx && !qgl_share_reg()->checkSharing(buffer_ctx, ctx))
     1014        if (buffer_ctx && !QGLContext::areSharing(buffer_ctx, ctx))
    12151015            cleanCache();
    12161016
     
    12741074
    12751075    void cleanCache() {
     1076        QGLShareContextScope scope(buffer_ctx);
    12761077        QGLGradientColorTableHash::const_iterator it = cache.constBegin();
    12771078        for (; it != cache.constEnd(); ++it) {
     
    13711172    Q_UNUSED(g);
    13721173#else
    1373     GLuint texId = qt_opengl_gradient_cache()->getBuffer(g, opacity, drawable.context());
     1174    GLuint texId = qt_opengl_gradient_cache()->getBuffer(g, opacity, device->context());
    13741175    glBindTexture(GL_TEXTURE_1D, texId);
    13751176    grad_palette = texId;
     
    14181219            else if (current_style == Qt::SolidPattern)
    14191220                fragment_brush = FRAGMENT_PROGRAM_BRUSH_SOLID;
    1420             else if (current_style == Qt::TexturePattern)
     1221            else if (current_style == Qt::TexturePattern && !brush.texture().isQBitmap())
    14211222                fragment_brush = FRAGMENT_PROGRAM_BRUSH_TEXTURE;
    14221223            else
     
    14401241    Q_D(QOpenGLPaintEngine);
    14411242
    1442     d->drawable.setDevice(pdev);
     1243    if (pdev->devType() == QInternal::OpenGL)
     1244        d->device = static_cast<QGLPaintDevice*>(pdev);
     1245    else
     1246        d->device = QGLPaintDevice::getDevice(pdev);
     1247
     1248    if (!d->device)
     1249        return false;
     1250
    14431251    d->offscreen.setDevice(pdev);
    14441252    d->has_fast_pen = false;
    14451253    d->inverseScale = 1;
    14461254    d->opacity = 1;
    1447     d->drawable.makeCurrent();
     1255    d->device->beginPaint();
    14481256    d->matrix = QTransform();
    14491257    d->has_antialiasing = false;
    14501258    d->high_quality_antialiasing = false;
    1451     d->dirty_stencil = true;
     1259
     1260    QSize sz(d->device->size());
     1261    d->dirty_stencil = QRect(0, 0, sz.width(), sz.height());
    14521262
    14531263    d->use_emulation = false;
     
    14601270                            && (pdev->devType() != QInternal::Pixmap);
    14611271
    1462     QGLContext *ctx = const_cast<QGLContext *>(d->drawable.context());
     1272    QGLContext *ctx = const_cast<QGLContext *>(d->device->context());
    14631273    if (!ctx) {
    14641274        qWarning() << "QOpenGLPaintEngine: paint device doesn't have a valid GL context.";
     
    14691279        has_frag_program = qt_resolve_frag_program_extensions(ctx) && qt_resolve_version_1_3_functions(ctx);
    14701280
    1471     d->use_stencil_method = d->drawable.format().stencil()
     1281    d->use_stencil_method = d->device->format().stencil()
    14721282                            && (QGLExtensions::glExtensions & QGLExtensions::StencilWrap);
    1473     if (d->drawable.format().directRendering()
     1283    if (d->device->format().directRendering()
    14741284        && (d->use_stencil_method && QGLExtensions::glExtensions & QGLExtensions::StencilTwoSide))
    14751285        d->has_stencil_face_ext = qt_resolve_stencil_face_extension(ctx);
     
    15371347    d->offscreen.begin();
    15381348
    1539     const QColor &c = d->drawable.backgroundColor();
    1540     glClearColor(c.redF(), c.greenF(), c.blueF(), 1.0);
    1541     if (d->drawable.context()->d_func()->clear_on_painter_begin && d->drawable.autoFillBackground()) {
    1542         GLbitfield clearBits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
    1543 #ifndef QT_OPENGL_ES
    1544         clearBits |= GL_ACCUM_BUFFER_BIT;
    1545 #endif
    1546         glClear(clearBits);
    1547     }
    1548 
    1549     QSize sz(d->drawable.size());
    15501349    glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface...
    15511350    glMatrixMode(GL_PROJECTION);
     
    15641363    d->max_texture_size = ctx->d_func()->maxTextureSize();
    15651364#else
    1566     bool shared_ctx = qgl_share_reg()->checkSharing(d->drawable.context(), d->shader_ctx);
     1365    bool shared_ctx = QGLContext::areSharing(d->device->context(), d->shader_ctx);
    15671366
    15681367    if (shared_ctx) {
     
    15801379            ctx->makeCurrent();
    15811380        }
    1582         d->shader_ctx = d->drawable.context();
     1381        d->shader_ctx = d->device->context();
    15831382        glGenTextures(1, &d->grad_palette);
    15841383
     
    16151414    d->flushDrawQueue();
    16161415    d->offscreen.end();
    1617     QGLContext *ctx = const_cast<QGLContext *>(d->drawable.context());
     1416    QGLContext *ctx = const_cast<QGLContext *>(d->device->context());
    16181417    if (!ctx->d_ptr->internal_context) {
    16191418        glMatrixMode(GL_TEXTURE);
     
    16321431    }
    16331432#endif
    1634     d->drawable.swapBuffers();
    1635     d->drawable.doneCurrent();
     1433    d->device->endPaint();
    16361434    qt_mask_texture_cache()->maintainCache();
    16371435
     
    17961594            QTransform translate(1, 0, 0, 1, -realFocal.x(), -realFocal.y());
    17971595            QTransform gl_to_qt(1, 0, 0, -1, 0, pdev->height());
    1798             QTransform inv_matrix = gl_to_qt * matrix.inverted() * brush.transform().inverted() * translate;
     1596            QTransform m = QTransform(matrix).translate(brush_origin.x(), brush_origin.y());
     1597            QTransform inv_matrix = gl_to_qt * (brush.transform() * m).inverted() * translate;
    17991598
    18001599            setInvMatrixData(inv_matrix);
     
    18091608            QTransform translate(1, 0, 0, 1, -realCenter.x(), -realCenter.y());
    18101609            QTransform gl_to_qt(1, 0, 0, -1, 0, pdev->height());
    1811             QTransform inv_matrix = gl_to_qt * matrix.inverted() * brush.transform().inverted() * translate;
     1610            QTransform m = QTransform(matrix).translate(brush_origin.x(), brush_origin.y());
     1611            QTransform inv_matrix = gl_to_qt * (brush.transform() * m).inverted() * translate;
    18121612
    18131613            setInvMatrixData(inv_matrix);
     
    18211621            QTransform translate(1, 0, 0, 1, -realStart.x(), -realStart.y());
    18221622            QTransform gl_to_qt(1, 0, 0, -1, 0, pdev->height());
    1823 
    1824             QTransform inv_matrix = gl_to_qt * matrix.inverted() * brush.transform().inverted() * translate;
     1623            QTransform m = QTransform(matrix).translate(brush_origin.x(), brush_origin.y());
     1624            QTransform inv_matrix = gl_to_qt * (brush.transform() * m).inverted() * translate;
    18251625
    18261626            setInvMatrixData(inv_matrix);
     
    18331633            linear_data[2] = 1.0f / (l.x() * l.x() + l.y() * l.y());
    18341634        } else if (style != Qt::SolidPattern) {
    1835             QTransform translate(1, 0, 0, 1, brush_origin.x(), brush_origin.y());
    18361635            QTransform gl_to_qt(1, 0, 0, -1, 0, pdev->height());
    1837 
    1838             QTransform inv_matrix = gl_to_qt * matrix.inverted() * brush.transform().inverted() * translate;
     1636            QTransform m = QTransform(matrix).translate(brush_origin.x(), brush_origin.y());
     1637            QTransform inv_matrix = gl_to_qt * (brush.transform() * m).inverted();
    18391638
    18401639            setInvMatrixData(inv_matrix);
     
    19251724    qreal rightB = trap.bottomRightX + (trap.topRightX - trap.bottomRightX) * reciprocal;
    19261725
    1927     const bool topZero = qFuzzyCompare(topDist + 1, 1);
     1726    const bool topZero = qFuzzyIsNull(topDist);
    19281727
    19291728    reciprocal = topZero ? 1.0 / bottomDist : 1.0 / topDist;
     
    19321731    qreal rightA = topZero ? (trap.bottomRightX - rightB) * reciprocal : (trap.topRightX - rightB) * reciprocal;
    19331732
    1934     qreal invLeftA = qFuzzyCompare(leftA + 1, 1) ? 0.0 : 1.0 / leftA;
    1935     qreal invRightA = qFuzzyCompare(rightA + 1, 1) ? 0.0 : 1.0 / rightA;
     1733    qreal invLeftA = qFuzzyIsNull(leftA) ? 0.0 : 1.0 / leftA;
     1734    qreal invRightA = qFuzzyIsNull(rightA) ? 0.0 : 1.0 / rightA;
    19361735
    19371736    // fragment program needs the negative of invRightA as it mirrors the line
     
    19841783{
    19851784    // On OpenGL ES we convert the trap to 2 triangles
    1986 #ifndef QT_OPENGL_ES_1
     1785#ifndef QT_OPENGL_ES
    19871786    if (size > allocated - 8) {
    19881787#else
     
    19951794    QGLTrapezoid t = toGLTrapezoid(trap);
    19961795
    1997 #ifndef QT_OPENGL_ES_1
    1998     vertices[size++] = t.topLeftX;
    1999     vertices[size++] = t.top;
    2000     vertices[size++] = t.topRightX;
    2001     vertices[size++] = t.top;
    2002     vertices[size++] = t.bottomRightX;
    2003     vertices[size++] = t.bottom;
    2004     vertices[size++] = t.bottomLeftX;
    2005     vertices[size++] = t.bottom;
     1796#ifndef QT_OPENGL_ES
     1797    vertices[size++] = f2vt(t.topLeftX);
     1798    vertices[size++] = f2vt(t.top);
     1799    vertices[size++] = f2vt(t.topRightX);
     1800    vertices[size++] = f2vt(t.top);
     1801    vertices[size++] = f2vt(t.bottomRightX);
     1802    vertices[size++] = f2vt(t.bottom);
     1803    vertices[size++] = f2vt(t.bottomLeftX);
     1804    vertices[size++] = f2vt(t.bottom);
    20061805#else
    20071806    // First triangle
    2008     vertices[size++] = t.topLeftX;
    2009     vertices[size++] = t.top;
    2010     vertices[size++] = t.topRightX;
    2011     vertices[size++] = t.top;
    2012     vertices[size++] = t.bottomRightX;
    2013     vertices[size++] = t.bottom;
     1807    vertices[size++] = f2vt(t.topLeftX);
     1808    vertices[size++] = f2vt(t.top);
     1809    vertices[size++] = f2vt(t.topRightX);
     1810    vertices[size++] = f2vt(t.top);
     1811    vertices[size++] = f2vt(t.bottomRightX);
     1812    vertices[size++] = f2vt(t.bottom);
    20141813
    20151814    // Second triangle
    2016     vertices[size++] = t.bottomLeftX;
    2017     vertices[size++] = t.bottom;
    2018     vertices[size++] = t.topLeftX;
    2019     vertices[size++] = t.top;
    2020     vertices[size++] = t.bottomRightX;
    2021     vertices[size++] = t.bottom;
     1815    vertices[size++] = f2vt(t.bottomLeftX);
     1816    vertices[size++] = f2vt(t.bottom);
     1817    vertices[size++] = f2vt(t.topLeftX);
     1818    vertices[size++] = f2vt(t.top);
     1819    vertices[size++] = f2vt(t.bottomRightX);
     1820    vertices[size++] = f2vt(t.bottom);
    20221821#endif
    20231822}
     
    21491948    Q_Q(QOpenGLPaintEngine);
    21501949
    2151     if (dirty_stencil) {
     1950    QRect rect = dirty_stencil.boundingRect();
     1951
     1952    if (use_system_clip)
     1953        rect = q->systemClip().intersected(dirty_stencil).boundingRect();
     1954
     1955    glStencilMask(~0);
     1956
     1957    if (!rect.isEmpty()) {
    21521958        disableClipping();
    21531959
    2154         if (use_system_clip) {
    2155             glEnable(GL_SCISSOR_TEST);
    2156 
    2157             QRect rect = q->systemClip().boundingRect();
    2158 
    2159             const int left = rect.left();
    2160             const int width = rect.width();
    2161             const int bottom = drawable.size().height() - (rect.bottom() + 1);
    2162             const int height = rect.height();
    2163 
    2164             glScissor(left, bottom, width, height);
    2165         }
     1960        glEnable(GL_SCISSOR_TEST);
     1961
     1962        const int left = rect.left();
     1963        const int width = rect.width();
     1964        const int bottom = device->size().height() - (rect.bottom() + 1);
     1965        const int height = rect.height();
     1966
     1967        glScissor(left, bottom, width, height);
    21661968
    21671969        glClearStencil(0);
    21681970        glClear(GL_STENCIL_BUFFER_BIT);
    2169         dirty_stencil = false;
    2170 
    2171         if (use_system_clip)
    2172             glDisable(GL_SCISSOR_TEST);
     1971        dirty_stencil -= rect;
     1972
     1973        glDisable(GL_SCISSOR_TEST);
    21731974
    21741975        enableClipping();
    21751976    }
    2176 
    2177     glStencilMask(~0);
    21781977
    21791978    // Enable stencil.
     
    22342033    // Enable color writes.
    22352034    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    2236     glStencilMask(0);
     2035    glStencilMask(stencilMask);
    22372036
    22382037    setGradientOps(cbrush, QRectF(QPointF(min_x, min_y), QSizeF(max_x - min_x, max_y - min_y)));
     
    22462045        // Enable stencil func.
    22472046        glStencilFunc(GL_NOTEQUAL, 0, stencilMask);
     2047        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    22482048        composite(rect);
    22492049    } else {
     
    22522052        // Enable stencil func.
    22532053        glStencilFunc(GL_NOTEQUAL, 0, stencilMask);
     2054        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    22542055#ifndef QT_OPENGL_ES
    22552056        glBegin(GL_QUADS);
     
    22622063    }
    22632064
    2264     glStencilMask(~0);
    2265     glStencilFunc(GL_ALWAYS, 0, 0);
    2266     glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
    2267 
    2268     // clear all stencil values to 0
    2269     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    2270 
    2271 #ifndef QT_OPENGL_ES
    2272     glBegin(GL_QUADS);
    2273     glVertex2f(min_x, min_y);
    2274     glVertex2f(max_x, min_y);
    2275     glVertex2f(max_x, max_y);
    2276     glVertex2f(min_x, max_y);
    2277     glEnd();
    2278 #endif
    2279 
    2280     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    2281 
    22822065    // Disable stencil writes.
    22832066    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
     
    23322115    d->pen_brush_style = pen.brush().style();
    23332116    d->cpen = pen;
    2334     d->has_pen = (pen_style != Qt::NoPen);
     2117    d->has_pen = (pen_style != Qt::NoPen) && (d->pen_brush_style != Qt::NoBrush);
    23352118    d->updateUseEmulation();
    23362119
     
    24362219    Q_Q(QOpenGLPaintEngine);
    24372220
     2221    ++q->state()->depthClipId;
     2222
    24382223    glDisable(GL_DEPTH_TEST);
    24392224    glDisable(GL_SCISSOR_TEST);
     
    24542239        const int left = fastClip.left();
    24552240        const int width = fastClip.width();
    2456         const int bottom = drawable.size().height() - (fastClip.bottom() + 1);
     2241        const int bottom = device->size().height() - (fastClip.bottom() + 1);
    24572242        const int height = fastClip.height();
    24582243
     
    24612246    }
    24622247
    2463 #ifndef QT_OPENGL_ES
     2248#if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_2) || defined(QT_OPENGL_ES_1_CL)
     2249    glClearDepthf(0.0f);
     2250#else
    24642251    glClearDepth(0.0f);
    2465 #else
    2466     glClearDepthf(0.0f);
    24672252#endif
     2253
    24682254    glEnable(GL_DEPTH_TEST);
    24692255    glDepthMask(GL_TRUE);
     
    25242310{
    25252311    Q_Q(QOpenGLPaintEngine);
    2526     if (q->state()->hasClipping)
     2312    if (q->painter()->hasClipping())
    25272313        q->updateClipRegion(q->painter()->clipRegion(), Qt::ReplaceClip);
    25282314    else
     
    25362322    // clipping is only supported when a stencil or depth buffer is
    25372323    // available
    2538     if (!d->drawable.format().depth())
     2324    if (!d->device->format().depth())
    25392325        return;
    25402326
     
    25732359            path = d->matrix.map(path);
    25742360
    2575             if (path.contains(QRectF(QPointF(), d->drawable.size())))
     2361            if (path.contains(QRectF(QPointF(), d->device->size())))
    25762362                isScreenClip = true;
    25772363        }
     
    33013087}
    33023088
     3089extern void qt_add_rect_to_array(const QRectF &r, q_vertexType *array);
     3090extern void qt_add_texcoords_to_array(qreal x1, qreal y1, qreal x2, qreal y2, q_vertexType *array);
     3091
    33033092void QGLTrapezoidMaskGenerator::drawMask(const QRect &rect)
    33043093{
     
    34463235        qreal width = qAbs(delta.x()) + qAbs(delta.y());
    34473236
    3448         Q_ASSERT(qFuzzyCompare(delta.x() + 1, static_cast<qreal>(1))
    3449                  || qFuzzyCompare(delta.y() + 1, static_cast<qreal>(1)));
     3237        Q_ASSERT(qFuzzyIsNull(delta.x()) || qFuzzyIsNull(delta.y()));
    34503238
    34513239        tessellator.tessellateRect(first, last, width);
     
    35783366    disableClipping();
    35793367
    3580     GLuint program = qt_gl_program_cache()->getProgram(drawable.context(),
     3368    GLuint program = qt_gl_program_cache()->getProgram(device->context(),
    35813369                                                       FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true);
    35823370    QGLPathMaskGenerator maskGenerator(path, matrix, offscreen, program);
     
    37153503            if (d->has_brush) {
    37163504                d->disableClipping();
    3717                 GLuint program = qt_gl_program_cache()->getProgram(d->drawable.context(),
     3505                GLuint program = qt_gl_program_cache()->getProgram(d->device->context(),
    37183506                                                                   FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true);
    3719                 QGLRectMaskGenerator maskGenerator(path, d->matrix, d->offscreen, program);
    3720                 d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
     3507
     3508                if (d->matrix.type() >= QTransform::TxProject) {
     3509                    QGLPathMaskGenerator maskGenerator(path, d->matrix, d->offscreen, program);
     3510                    d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
     3511                } else {
     3512                    QGLRectMaskGenerator maskGenerator(path, d->matrix, d->offscreen, program);
     3513                    d->addItem(qt_mask_texture_cache()->getMask(maskGenerator, d));
     3514                }
    37213515
    37223516                d->enableClipping();
     
    38933687            // scale or 90 degree rotation?
    38943688            if (d->matrix.type() <= QTransform::TxTranslate
    3895                 || !d->cpen.isCosmetic()
    3896                    && (d->matrix.type() <= QTransform::TxScale
    3897                        || (d->matrix.type() == QTransform::TxRotate
    3898                            && d->matrix.m11() == 0 && d->matrix.m22() == 0))) {
     3689                || (!d->cpen.isCosmetic()
     3690                    && (d->matrix.type() <= QTransform::TxScale
     3691                        || (d->matrix.type() == QTransform::TxRotate
     3692                            && d->matrix.m11() == 0 && d->matrix.m22() == 0)))) {
    38993693                useRects = true;
    39003694                for (int i = 0; i < lineCount; ++i) {
     
    41193913    qreal penWidth = cpen.widthF();
    41203914
    4121     GLuint program = qt_gl_program_cache()->getProgram(drawable.context(),
     3915    GLuint program = qt_gl_program_cache()->getProgram(device->context(),
    41223916                                                       FRAGMENT_PROGRAM_MASK_TRAPEZOID_AA, 0, true);
    41233917    QGLLineMaskGenerator maskGenerator(path, matrix, penWidth == 0 ? 1.0 : penWidth,
     
    41663960        QPen pen = cpen;
    41673961        if (txscale != 1)
    4168             pen.setWidthF(pen.width() * txscale);
     3962            pen.setWidthF(pen.widthF() * txscale);
    41693963        if (use_cache)
    41703964            fillPath(qt_opengl_stroke_cache()->getStrokedPath(temp.map(path), pen));
     
    44094203    qreal scaleY = r.height() / sr.height();
    44104204
    4411     QTransform brush_matrix;
    4412     brush_matrix.translate(r.left(), r.top());
     4205    QTransform brush_matrix = QTransform::fromTranslate(r.left(), r.top());
    44134206    brush_matrix.scale(scaleX, scaleY);
    44144207    brush_matrix.translate(-sr.left(), -sr.top());
     
    44264219}
    44274220
    4428 void QOpenGLPaintEnginePrivate::drawTiledImageAsPath(const QRectF &r, const QImage &img, qreal sx, qreal sy)
     4221void QOpenGLPaintEnginePrivate::drawTiledImageAsPath(const QRectF &r, const QImage &img, qreal sx, qreal sy,
     4222                                                     const QPointF &offset)
    44294223{
    44304224    QBrush old_brush = cbrush;
    44314225    QPointF old_brush_origin = brush_origin;
    44324226
    4433     QTransform brush_matrix;
    4434     brush_matrix.translate(r.left(), r.top());
     4227    QTransform brush_matrix = QTransform::fromTranslate(r.left(), r.top());
    44354228    brush_matrix.scale(sx, sy);
     4229    brush_matrix.translate(-offset.x(), -offset.y());
    44364230
    44374231    cbrush = QBrush(img);
     
    45054299        GLenum target = qt_gl_preferredTextureTarget();
    45064300        d->flushDrawQueue();
    4507         d->drawable.bindTexture(pm, target);
    4508         drawTextureRect(pm.width(), pm.height(), r, sr, target);
    4509     }
    4510 }
    4511 
    4512 void QOpenGLPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &)
     4301        QGLTexture *tex =
     4302            d->device->context()->d_func()->bindTexture(pm, target, GL_RGBA,
     4303                                                        QGLContext::InternalBindOption);
     4304        drawTextureRect(pm.width(), pm.height(), r, sr, target, tex);
     4305    }
     4306}
     4307
     4308void QOpenGLPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pm, const QPointF &offset)
    45134309{
    45144310    Q_D(QOpenGLPaintEngine);
     4311    if (pm.depth() == 1) {
     4312        QPixmap tpx(pm.size());
     4313        tpx.fill(Qt::transparent);
     4314        QPainter p(&tpx);
     4315        p.setPen(d->cpen);
     4316        p.drawPixmap(0, 0, pm);
     4317        p.end();
     4318        drawTiledPixmap(r, tpx, offset);
     4319        return;
     4320    }
    45154321
    45164322    QImage scaled;
     
    45204326        int rh = qCeil(r.height());
    45214327        if (rw < pm.width() && rh < pm.height()) {
    4522             drawTiledPixmap(r, pm.copy(0, 0, rw, rh), QPointF());
     4328            drawTiledPixmap(r, pm.copy(0, 0, rw, rh), offset);
    45234329            return;
    45244330        }
     
    45294335    if (d->composition_mode > QPainter::CompositionMode_Plus || (d->high_quality_antialiasing && !d->isFastRect(r))) {
    45304336        if (scaled.isNull())
    4531             d->drawTiledImageAsPath(r, pm.toImage(), 1, 1);
     4337            d->drawTiledImageAsPath(r, pm.toImage(), 1, 1, offset);
    45324338        else {
    45334339            const qreal sx = pm.width() / qreal(scaled.width());
    45344340            const qreal sy = pm.height() / qreal(scaled.height());
    4535             d->drawTiledImageAsPath(r, scaled, sx, sy);
     4341            d->drawTiledImageAsPath(r, scaled, sx, sy, offset);
    45364342        }
    45374343    } else {
    45384344        d->flushDrawQueue();
    45394345
     4346        QGLTexture *tex;
    45404347        if (scaled.isNull())
    4541             d->drawable.bindTexture(pm);
     4348            tex = d->device->context()->d_func()->bindTexture(pm, GL_TEXTURE_2D, GL_RGBA,
     4349                                                              QGLContext::InternalBindOption);
    45424350        else
    4543             d->drawable.bindTexture(scaled);
     4351            tex = d->device->context()->d_func()->bindTexture(scaled, GL_TEXTURE_2D, GL_RGBA,
     4352                                                              QGLContext::InternalBindOption);
    45444353        updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, d->use_smooth_pixmap_transform);
    45454354
     
    45564365        // Rotate the texture so that it is aligned correctly and the
    45574366        // wrapping is done correctly
    4558         glMatrixMode(GL_TEXTURE);
    4559         glPushMatrix();
    4560         glRotatef(180.0, 0.0, 1.0, 0.0);
    4561         glRotatef(180.0, 0.0, 0.0, 1.0);
     4367        if (tex->options & QGLContext::InvertedYBindOption) {
     4368            glMatrixMode(GL_TEXTURE);
     4369            glPushMatrix();
     4370            glRotatef(180.0, 0.0, 1.0, 0.0);
     4371            glRotatef(180.0, 0.0, 0.0, 1.0);
     4372        }
    45624373
    45634374        q_vertexType vertexArray[4*2];
    45644375        q_vertexType texCoordArray[4*2];
    45654376
     4377        double offset_x = offset.x() / pm.width();
     4378        double offset_y = offset.y() / pm.height();
     4379
    45664380        qt_add_rect_to_array(r, vertexArray);
    4567         qt_add_texcoords_to_array(0, 0, tc_w, tc_h, texCoordArray);
     4381        qt_add_texcoords_to_array(offset_x, offset_y,
     4382                                  tc_w + offset_x, tc_h + offset_y, texCoordArray);
    45684383
    45694384        glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);
     
    45754390        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    45764391        glDisableClientState(GL_VERTEX_ARRAY);
    4577         glPopMatrix();
     4392        if (tex->options & QGLContext::InvertedYBindOption)
     4393            glPopMatrix();
    45784394
    45794395        glDisable(GL_TEXTURE_2D);
     
    46114427        GLenum target = qt_gl_preferredTextureTarget();
    46124428        d->flushDrawQueue();
    4613         d->drawable.bindTexture(image, target);
    4614         drawTextureRect(image.width(), image.height(), r, sr, target);
     4429        QGLTexture *tex =
     4430            d->device->context()->d_func()->bindTexture(image, target, GL_RGBA,
     4431                                                        QGLContext::InternalBindOption);
     4432        drawTextureRect(image.width(), image.height(), r, sr, target, tex);
    46154433    }
    46164434}
    46174435
    46184436void QOpenGLPaintEngine::drawTextureRect(int tx_width, int tx_height, const QRectF &r,
    4619                                          const QRectF &sr, GLenum target)
     4437                                         const QRectF &sr, GLenum target, QGLTexture *tex)
    46204438{
    46214439    Q_D(QOpenGLPaintEngine);
     
    46324450        x1 = sr.x() / tx_width;
    46334451        x2 = x1 + sr.width() / tx_width;
    4634         y1 = 1.0 - (sr.bottom() / tx_height);
    4635         y2 = 1.0 - (sr.y() / tx_height);
     4452        if (tex->options & QGLContext::InvertedYBindOption) {
     4453            y1 = 1 - (sr.bottom() / tx_height);
     4454            y2 = 1 - (sr.y() / tx_height);
     4455        } else {
     4456            y1 = sr.bottom() / tx_height;
     4457            y2 = sr.y() / tx_height;
     4458        }
    46364459    } else {
    46374460        x1 = sr.x();
    46384461        x2 = sr.right();
    4639         y1 = tx_height - sr.bottom();
    4640         y2 = tx_height - sr.y();
     4462        y1 = sr.bottom();
     4463        y2 = sr.y();
    46414464    }
    46424465
     
    47004523typedef QHash<const QGLContext*, QGLFontGlyphHash*> QGLContextHash;
    47014524
     4525static inline void qt_delete_glyph_hash(QGLGlyphHash *hash)
     4526{
     4527    qDeleteAll(*hash);
     4528    delete hash;
     4529}
     4530
    47024531class QGLGlyphCache : public QObject
    47034532{
     
    47404569            ctx = keys.at(i);
    47414570            QGLGlyphHash *cache = font_cache->take(fe);
    4742             delete cache;
     4571            qt_delete_glyph_hash(cache);
    47434572            break;
    47444573        }
     
    47774606        for (int i=0; i < keys.size(); ++i) {
    47784607            QFontEngine *fe = keys.at(i);
    4779             delete font_cache->take(fe);
     4608            qt_delete_glyph_hash(font_cache->take(fe));
    47804609            quint64 font_key = (reinterpret_cast<quint64>(ctx) << 32) | reinterpret_cast<quint64>(fe);
    47814610            QGLFontTexture *font_tex = qt_font_textures.take(font_key);
     
    48184647    for (int i=0; i < keys.size(); ++i) {
    48194648        QGLFontGlyphHash *font_cache = qt_context_cache.value(keys.at(i));
    4820         qDeleteAll(*font_cache);
     4649        QGLFontGlyphHash::Iterator it = font_cache->begin();
     4650        for (; it != font_cache->end(); ++it)
     4651            qt_delete_glyph_hash(it.value());
    48214652        font_cache->clear();
    48224653    }
     
    48694700        for (int i=0; i<contexts.size(); ++i) {
    48704701            const QGLContext *ctx = contexts.at(i);
    4871             if (ctx != context && qgl_share_reg()->checkSharing(context, ctx)) {
     4702            if (ctx != context && QGLContext::areSharing(context, ctx)) {
    48724703                context_key = ctx;
    48734704                dev_it = qt_context_cache.constFind(context_key);
     
    48864717            connect(widget, SIGNAL(destroyed(QObject*)), SLOT(widgetDestroyed(QObject*)));
    48874718            connect(QGLSignalProxy::instance(),
    4888                     SIGNAL(aboutToDestroyContext(const QGLContext *)),
    4889                     SLOT(cleanupContext(const QGLContext *)));
     4719                    SIGNAL(aboutToDestroyContext(const QGLContext*)),
     4720                    SLOT(cleanupContext(const QGLContext*)));
    48904721        }
    48914722    } else {
     
    49764807            }
    49774808
    4978             QImage glyph_im(ti.fontEngine->alphaMapForGlyph(glyphs[i]).convertToFormat(QImage::Format_Indexed8));
     4809            QImage glyph_im(ti.fontEngine->alphaMapForGlyph(glyphs[i]));
     4810            glyph_im = glyph_im.convertToFormat(QImage::Format_Indexed8);
    49794811            glyph_width = glyph_im.width();
    49804812            Q_ASSERT(glyph_width >= 0);
     
    50634895    // fall back to drawing a polygon if the scale factor is large, or
    50644896    // we use a gradient pen
    5065     if (ti.fontEngine->fontDef.pixelSize >= 64
    5066         || (d->matrix.det() > 1) || (d->pen_brush_style >= Qt::LinearGradientPattern
    5067                                      && d->pen_brush_style <= Qt::ConicalGradientPattern)) {
     4897    if ((d->matrix.det() > 1) || (d->pen_brush_style >= Qt::LinearGradientPattern
     4898                                  && d->pen_brush_style <= Qt::ConicalGradientPattern)) {
    50684899        QPaintEngine::drawTextItem(p, textItem);
    50694900        return;
     
    50754906    QVarLengthArray<QFixedPoint> positions;
    50764907    QVarLengthArray<glyph_t> glyphs;
    5077     QTransform matrix;
    5078     matrix.translate(qRound(p.x()), qRound(p.y()));
     4908    QTransform matrix = QTransform::fromTranslate(qRound(p.x()), qRound(p.y()));
    50794909    ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions);
    50804910
    50814911    // make sure the glyphs we want to draw are in the cache
    5082     qt_glyph_cache()->cacheGlyphs(d->drawable.context(), ti, glyphs);
     4912    qt_glyph_cache()->cacheGlyphs(d->device->context(), ti, glyphs);
    50834913
    50844914    d->setGradientOps(Qt::SolidPattern, QRectF()); // turns off gradient ops
     
    51584988            glLoadIdentity();
    51594989
    5160             GLuint program = qt_gl_program_cache()->getProgram(d->drawable.context(),
     4990            GLuint program = qt_gl_program_cache()->getProgram(d->device->context(),
    51614991                                                               FRAGMENT_PROGRAM_MASK_ELLIPSE_AA, 0, true);
    51624992            QGLEllipseMaskGenerator maskGenerator(rect,
     
    52935123
    52945124    int left = qMax(0, static_cast<int>(screen_rect.left()));
    5295     int width = qMin(drawable.size().width() - left, static_cast<int>(screen_rect.width()) + 1);
    5296 
    5297     int bottom = qMax(0, static_cast<int>(drawable.size().height() - screen_rect.bottom()));
    5298     int height = qMin(drawable.size().height() - bottom, static_cast<int>(screen_rect.height()) + 1);
     5125    int width = qMin(device->size().width() - left, static_cast<int>(screen_rect.width()) + 1);
     5126
     5127    int bottom = qMax(0, static_cast<int>(device->size().height() - screen_rect.bottom()));
     5128    int height = qMin(device->size().height() - bottom, static_cast<int>(screen_rect.height()) + 1);
    52995129
    53005130    glBindTexture(GL_TEXTURE_2D, drawable_texture);
     
    53905220
    53915221        if (current_style == Qt::TexturePattern)
    5392             drawable.bindTexture(cbrush.textureImage());
     5222            device->context()->d_func()->bindTexture(cbrush.textureImage(), GL_TEXTURE_2D, GL_RGBA,
     5223                                                     QGLContext::InternalBindOption);
    53935224        else
    5394             drawable.bindTexture(qt_imageForBrush(current_style, true));
     5225            device->context()->d_func()->bindTexture(qt_imageForBrush(current_style, false),
     5226                                                     GL_TEXTURE_2D, GL_RGBA,
     5227                                                     QGLContext::InternalBindOption);
    53955228
    53965229        updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, use_smooth_pixmap_transform);
     
    54005233    glVertexPointer(2, q_vertexTypeEnum, 0, vertexArray);
    54015234    glEnable(GL_FRAGMENT_PROGRAM_ARB);
    5402     GLuint program = qt_gl_program_cache()->getProgram(drawable.context(),
     5235    GLuint program = qt_gl_program_cache()->getProgram(device->context(),
    54035236                                                       fragment_brush,
    54045237                                                       fragment_composition_mode, false);
     
    54725305
    54735306    composite(item.location.screen_rect, item.location.rect.topLeft() - item.location.screen_rect.topLeft()
    5474                                          - QPoint(0, offscreen.offscreenSize().height() - drawable.size().height()));
     5307                                         - QPoint(0, offscreen.offscreenSize().height() - device->size().height()));
    54755308}
    54765309
     
    56215454        QBrush oldBrush = p->brush();
    56225455        p->setBrush(brush);
    5623         qt_draw_helper(p->d_ptr, painterPathFromVectorPath(path), QPainterPrivate::FillDraw);
     5456        qt_draw_helper(p->d_ptr.data(), painterPathFromVectorPath(path), QPainterPrivate::FillDraw);
    56245457        p->setBrush(oldBrush);
    56255458        return;
     
    57105543{
    57115544    Q_D(QOpenGLPaintEngine);
     5545    QOpenGLPaintEngineState *new_state = static_cast<QOpenGLPaintEngineState *>(s);
     5546    QOpenGLPaintEngineState *old_state = state();
     5547
    57125548    QPaintEngineEx::setState(s);
     5549
     5550    // are we in a save() ?
     5551    if (s == d->last_created_state) {
     5552        d->last_created_state = 0;
     5553        return;
     5554    }
     5555
    57135556    if (isActive()) {
    5714         d->updateDepthClip();
     5557        if (old_state->depthClipId != new_state->depthClipId)
     5558            d->updateDepthClip();
    57155559        penChanged();
    57165560        brushChanged();
     
    57245568QPainterState *QOpenGLPaintEngine::createState(QPainterState *orig) const
    57255569{
     5570    const Q_D(QOpenGLPaintEngine);
     5571
    57265572    QOpenGLPaintEngineState *s;
    57275573    if (!orig)
     
    57305576        s = new QOpenGLPaintEngineState(*static_cast<QOpenGLPaintEngineState *>(orig));
    57315577
     5578    d->last_created_state = s;
    57325579    return s;
    57335580}
     
    57435590    hasClipping = other.hasClipping;
    57445591    fastClip = other.fastClip;
     5592    depthClipId = other.depthClipId;
    57455593}
    57465594
     
    57485596{
    57495597    hasClipping = false;
     5598    depthClipId = 0;
    57505599}
    57515600
     
    57775626}
    57785627
    5779 QPixmapFilter *QOpenGLPaintEngine::createPixmapFilter(int type) const
    5780 {
    5781     if (QGLContext::currentContext())
    5782         return QGLContext::currentContext()->d_func()->createPixmapFilter(type);
    5783     else
    5784         return 0;
    5785 }
    5786 
    5787 
    57885628QT_END_NAMESPACE
    57895629
Note: See TracChangeset for help on using the changeset viewer.