Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qpixmapdata_gl.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    368368
    369369void QGLPixmapData::fromImage(const QImage &image,
    370                               Qt::ImageConversionFlags /*flags*/)
     370                              Qt::ImageConversionFlags flags)
    371371{
    372372    if (image.size() == QSize(w, h))
     
    382382            format = QImage::Format_RGB16;
    383383
    384         if (image.hasAlphaChannel() && const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels())
     384        if (image.hasAlphaChannel()
     385            && ((flags & Qt::NoOpaqueDetection)
     386                || const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()))
    385387            format = QImage::Format_ARGB32_Premultiplied;;
    386388
     
    471473void QGLPixmapData::copy(const QPixmapData *data, const QRect &rect)
    472474{
    473     if (data->classId() != QPixmapData::OpenGLClass) {
     475    if (data->classId() != QPixmapData::OpenGLClass || !static_cast<const QGLPixmapData *>(data)->useFramebufferObjects()) {
    474476        QPixmapData::copy(data, rect);
    475477        return;
    476478    }
    477479
    478     // can be optimized to do a framebuffer blit or similar ...
    479     QPixmapData::copy(data, rect);
     480    const QGLPixmapData *other = static_cast<const QGLPixmapData *>(data);
     481    if (other->m_renderFbo) {
     482        QGLShareContextScope ctx(qt_gl_share_widget()->context());
     483
     484        resize(rect.width(), rect.height());
     485        m_hasAlpha = other->m_hasAlpha;
     486        ensureCreated();
     487
     488        if (!ctx->d_ptr->fbo)
     489            glGenFramebuffers(1, &ctx->d_ptr->fbo);
     490
     491        glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, ctx->d_ptr->fbo);
     492        glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
     493                GL_TEXTURE_2D, m_texture.id, 0);
     494
     495        if (!other->m_renderFbo->isBound())
     496            glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, other->m_renderFbo->handle());
     497
     498        glDisable(GL_SCISSOR_TEST);
     499        if (ctx->d_ptr->active_engine && ctx->d_ptr->active_engine->type() == QPaintEngine::OpenGL2)
     500            static_cast<QGL2PaintEngineEx *>(ctx->d_ptr->active_engine)->invalidateState();
     501
     502        glBlitFramebufferEXT(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(),
     503                0, 0, w, h,
     504                GL_COLOR_BUFFER_BIT,
     505                GL_NEAREST);
     506
     507        glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo);
     508    } else {
     509        QPixmapData::copy(data, rect);
     510    }
    480511}
    481512
     
    622653}
    623654
    624 bool QGLPixmapData::useFramebufferObjects()
     655bool QGLPixmapData::useFramebufferObjects() const
    625656{
    626657    return QGLFramebufferObject::hasOpenGLFramebufferObjects()
    627658           && QGLFramebufferObject::hasOpenGLFramebufferBlit()
    628            && qt_gl_preferGL2Engine();
     659           && qt_gl_preferGL2Engine()
     660           && (w * h > 32*32); // avoid overhead of FBOs for small pixmaps
    629661}
    630662
     
    708740}
    709741
    710 extern int qt_defaultDpiX();
    711 extern int qt_defaultDpiY();
     742Q_DECL_IMPORT extern int qt_defaultDpiX();
     743Q_DECL_IMPORT extern int qt_defaultDpiY();
    712744
    713745int QGLPixmapData::metric(QPaintDevice::PaintDeviceMetric metric) const
Note: See TracChangeset for help on using the changeset viewer.