| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/qglpaintdevice.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 16 | ** | - | ||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 29 | ** | - | ||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 31 | ** | - | ||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | #include <private/qglpaintdevice_p.h> | - | ||||||||||||
| 35 | #include <private/qgl_p.h> | - | ||||||||||||
| 36 | #include <private/qglpixelbuffer_p.h> | - | ||||||||||||
| 37 | #include <private/qglframebufferobject_p.h> | - | ||||||||||||
| 38 | #include <qopenglfunctions.h> | - | ||||||||||||
| 39 | #include <qwindow.h> | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | QGLPaintDevice::QGLPaintDevice() | - | ||||||||||||
| 44 | : m_thisFBO(0) | - | ||||||||||||
| 45 | { | - | ||||||||||||
| 46 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||
| 47 | - | |||||||||||||
| 48 | QGLPaintDevice::~QGLPaintDevice() | - | ||||||||||||
| 49 | { | - | ||||||||||||
| 50 | } | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | int QGLPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | switch(metric) { | - | ||||||||||||
| 55 | case PdmWidth: never executed: case PdmWidth: | 0 | ||||||||||||
| 56 | return size().width(); never executed: return size().width(); | 0 | ||||||||||||
| 57 | case PdmHeight: never executed: case PdmHeight: | 0 | ||||||||||||
| 58 | return size().height(); never executed: return size().height(); | 0 | ||||||||||||
| 59 | case PdmDepth: { never executed: case PdmDepth: | 0 | ||||||||||||
| 60 | const QGLFormat f = format(); | - | ||||||||||||
| 61 | return f.redBufferSize() + f.greenBufferSize() + f.blueBufferSize() + f.alphaBufferSize(); never executed: return f.redBufferSize() + f.greenBufferSize() + f.blueBufferSize() + f.alphaBufferSize(); | 0 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | case PdmDevicePixelRatio: never executed: case PdmDevicePixelRatio: | 0 | ||||||||||||
| 64 | return 1; never executed: return 1; | 0 | ||||||||||||
| 65 | case PdmDevicePixelRatioScaled: never executed: case PdmDevicePixelRatioScaled: | 0 | ||||||||||||
| 66 | return 1 * QPaintDevice::devicePixelRatioFScale(); never executed: return 1 * QPaintDevice::devicePixelRatioFScale(); | 0 | ||||||||||||
| 67 | default: never executed: default: | 0 | ||||||||||||
| 68 | qWarning("QGLPaintDevice::metric() - metric %d not known", metric); | - | ||||||||||||
| 69 | return 0; never executed: return 0; | 0 | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | void QGLPaintDevice::beginPaint() | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | // Make sure our context is the current one: | - | ||||||||||||
| 76 | QGLContext *ctx = context(); | - | ||||||||||||
| 77 | ctx->makeCurrent(); | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | ctx->d_func()->refreshCurrentFbo(); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | // Record the currently bound FBO so we can restore it again | - | ||||||||||||
| 82 | // in endPaint() and bind this device's FBO | - | ||||||||||||
| 83 | // | - | ||||||||||||
| 84 | // Note: m_thisFBO could be zero if the paint device is not | - | ||||||||||||
| 85 | // backed by an FBO (e.g. window back buffer). But there could | - | ||||||||||||
| 86 | // be a previous FBO bound to the context which we need to | - | ||||||||||||
| 87 | // explicitly unbind. Otherwise the painting will go into | - | ||||||||||||
| 88 | // the previous FBO instead of to the window. | - | ||||||||||||
| 89 | m_previousFBO = ctx->d_func()->current_fbo; | - | ||||||||||||
| 90 | - | |||||||||||||
| 91 | if (m_previousFBO != m_thisFBO) {
| 0-2 | ||||||||||||
| 92 | ctx->d_func()->setCurrentFbo(m_thisFBO); | - | ||||||||||||
| 93 | ctx->contextHandle()->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_thisFBO); | - | ||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | // Set the default fbo for the context to m_thisFBO so that | - | ||||||||||||
| 97 | // if some raw GL code between beginNativePainting() and | - | ||||||||||||
| 98 | // endNativePainting() calls QGLFramebufferObject::release(), | - | ||||||||||||
| 99 | // painting will revert to the window surface's fbo. | - | ||||||||||||
| 100 | ctx->d_ptr->default_fbo = m_thisFBO; | - | ||||||||||||
| 101 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | void QGLPaintDevice::ensureActiveTarget() | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | QGLContext* ctx = context(); | - | ||||||||||||
| 106 | if (ctx != QGLContext::currentContext())
| 0-28 | ||||||||||||
| 107 | ctx->makeCurrent(); never executed: ctx->makeCurrent(); | 0 | ||||||||||||
| 108 | - | |||||||||||||
| 109 | ctx->d_func()->refreshCurrentFbo(); | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | if (ctx->d_ptr->current_fbo != m_thisFBO) {
| 0-28 | ||||||||||||
| 112 | ctx->d_func()->setCurrentFbo(m_thisFBO); | - | ||||||||||||
| 113 | ctx->contextHandle()->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_thisFBO); | - | ||||||||||||
| 114 | } never executed: end of block | 0 | ||||||||||||
| 115 | - | |||||||||||||
| 116 | ctx->d_ptr->default_fbo = m_thisFBO; | - | ||||||||||||
| 117 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||
| 118 | - | |||||||||||||
| 119 | void QGLPaintDevice::endPaint() | - | ||||||||||||
| 120 | { | - | ||||||||||||
| 121 | // Make sure the FBO bound at beginPaint is re-bound again here: | - | ||||||||||||
| 122 | QGLContext *ctx = context(); | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | ctx->d_func()->refreshCurrentFbo(); | - | ||||||||||||
| 125 | - | |||||||||||||
| 126 | if (m_previousFBO != ctx->d_func()->current_fbo) {
| 0-2 | ||||||||||||
| 127 | ctx->d_func()->setCurrentFbo(m_previousFBO); | - | ||||||||||||
| 128 | ctx->contextHandle()->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_previousFBO); | - | ||||||||||||
| 129 | } never executed: end of block | 0 | ||||||||||||
| 130 | - | |||||||||||||
| 131 | ctx->d_ptr->default_fbo = 0; | - | ||||||||||||
| 132 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 133 | - | |||||||||||||
| 134 | QGLFormat QGLPaintDevice::format() const | - | ||||||||||||
| 135 | { | - | ||||||||||||
| 136 | return context()->format(); never executed: return context()->format(); | 0 | ||||||||||||
| 137 | } | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | bool QGLPaintDevice::alphaRequested() const | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | return context()->d_func()->reqFormat.alpha(); never executed: return context()->d_func()->reqFormat.alpha(); | 0 | ||||||||||||
| 142 | } | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | bool QGLPaintDevice::isFlipped() const | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 147 | } | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | ////////////////// QGLWidgetGLPaintDevice ////////////////// | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | } | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | return glWidget->paintEngine(); never executed: return glWidget->paintEngine(); | 0 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) | - | ||||||||||||
| 161 | { | - | ||||||||||||
| 162 | glWidget = w; | - | ||||||||||||
| 163 | } executed 12 times by 3 tests: end of blockExecuted by:
| 12 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | void QGLWidgetGLPaintDevice::beginPaint() | - | ||||||||||||
| 166 | { | - | ||||||||||||
| 167 | QGLPaintDevice::beginPaint(); | - | ||||||||||||
| 168 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||
| 169 | if (!glWidget->d_func()->disable_clear_on_painter_begin && glWidget->autoFillBackground()) {
| 0-2 | ||||||||||||
| 170 | if (glWidget->testAttribute(Qt::WA_TranslucentBackground))
| 0-2 | ||||||||||||
| 171 | funcs->glClearColor(0.0, 0.0, 0.0, 0.0); never executed: funcs->glClearColor(0.0, 0.0, 0.0, 0.0); | 0 | ||||||||||||
| 172 | else { | - | ||||||||||||
| 173 | const QColor &c = glWidget->palette().brush(glWidget->backgroundRole()).color(); | - | ||||||||||||
| 174 | float alpha = c.alphaF(); | - | ||||||||||||
| 175 | funcs->glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); | - | ||||||||||||
| 176 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 177 | if (context()->d_func()->workaround_needsFullClearOnEveryFrame)
| 0-2 | ||||||||||||
| 178 | funcs->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); never executed: funcs->glClear(0x00004000 | 0x00000100 | 0x00000400); | 0 | ||||||||||||
| 179 | else | - | ||||||||||||
| 180 | funcs->glClear(GL_COLOR_BUFFER_BIT); executed 2 times by 1 test: funcs->glClear(0x00004000);Executed by:
| 2 | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 183 | - | |||||||||||||
| 184 | void QGLWidgetGLPaintDevice::endPaint() | - | ||||||||||||
| 185 | { | - | ||||||||||||
| 186 | if (glWidget->autoBufferSwap())
| 0-2 | ||||||||||||
| 187 | glWidget->swapBuffers(); executed 2 times by 1 test: glWidget->swapBuffers();Executed by:
| 2 | ||||||||||||
| 188 | QGLPaintDevice::endPaint(); | - | ||||||||||||
| 189 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 190 | - | |||||||||||||
| 191 | - | |||||||||||||
| 192 | QSize QGLWidgetGLPaintDevice::size() const | - | ||||||||||||
| 193 | { | - | ||||||||||||
| 194 | #ifdef Q_OS_MAC | - | ||||||||||||
| 195 | return glWidget->size() * (glWidget->windowHandle() ? | - | ||||||||||||
| 196 | glWidget->windowHandle()->devicePixelRatio() : qApp->devicePixelRatio()); | - | ||||||||||||
| 197 | #else | - | ||||||||||||
| 198 | return glWidget->size(); executed 2 times by 1 test: return glWidget->size();Executed by:
| 2 | ||||||||||||
| 199 | #endif | - | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | QGLContext* QGLWidgetGLPaintDevice::context() const | - | ||||||||||||
| 203 | { | - | ||||||||||||
| 204 | return const_cast<QGLContext*>(glWidget->context()); executed 36 times by 1 test: return const_cast<QGLContext*>(glWidget->context());Executed by:
| 36 | ||||||||||||
| 205 | } | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | // returns the QGLPaintDevice for the given QPaintDevice | - | ||||||||||||
| 208 | QGLPaintDevice* QGLPaintDevice::getDevice(QPaintDevice* pd) | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | QGLPaintDevice* glpd = 0; | - | ||||||||||||
| 211 | - | |||||||||||||
| 212 | switch(pd->devType()) { | - | ||||||||||||
| 213 | case QInternal::Widget: executed 2 times by 1 test: case QInternal::Widget:Executed by:
| 2 | ||||||||||||
| 214 | // Should not be called on a non-gl widget: | - | ||||||||||||
| 215 | Q_ASSERT(qobject_cast<QGLWidget*>(static_cast<QWidget*>(pd))); | - | ||||||||||||
| 216 | glpd = &(static_cast<QGLWidget*>(pd)->d_func()->glDevice); | - | ||||||||||||
| 217 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||
| 218 | case QInternal::Pbuffer: never executed: case QInternal::Pbuffer: | 0 | ||||||||||||
| 219 | glpd = &(static_cast<QGLPixelBuffer*>(pd)->d_func()->glDevice); | - | ||||||||||||
| 220 | break; never executed: break; | 0 | ||||||||||||
| 221 | case QInternal::FramebufferObject: never executed: case QInternal::FramebufferObject: | 0 | ||||||||||||
| 222 | glpd = &(static_cast<QGLFramebufferObject*>(pd)->d_func()->glDevice); | - | ||||||||||||
| 223 | break; never executed: break; | 0 | ||||||||||||
| 224 | case QInternal::Pixmap: { never executed: case QInternal::Pixmap: | 0 | ||||||||||||
| 225 | qWarning("Pixmap type not supported for GL rendering"); | - | ||||||||||||
| 226 | break; never executed: break; | 0 | ||||||||||||
| 227 | } | - | ||||||||||||
| 228 | default: never executed: default: | 0 | ||||||||||||
| 229 | qWarning("QGLPaintDevice::getDevice() - Unknown device type %d", pd->devType()); | - | ||||||||||||
| 230 | break; never executed: break; | 0 | ||||||||||||
| 231 | } | - | ||||||||||||
| 232 | - | |||||||||||||
| 233 | return glpd; executed 2 times by 1 test: return glpd;Executed by:
| 2 | ||||||||||||
| 234 | } | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |