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