| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/gl2paintengineex/qgl2pexvertexarray.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 "qgl2pexvertexarray_p.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include <private/qbezier_p.h> | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | void QGL2PEXVertexArray::clear() | - | ||||||||||||||||||
| 41 | { | - | ||||||||||||||||||
| 42 | vertexArray.reset(); | - | ||||||||||||||||||
| 43 | vertexArrayStops.reset(); | - | ||||||||||||||||||
| 44 | boundingRectDirty = true; | - | ||||||||||||||||||
| 45 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | QGLRect QGL2PEXVertexArray::boundingRect() const | - | ||||||||||||||||||
| 49 | { | - | ||||||||||||||||||
| 50 | if (boundingRectDirty)
| 0-4 | ||||||||||||||||||
| 51 | return QGLRect(0.0, 0.0, 0.0, 0.0); never executed: return QGLRect(0.0, 0.0, 0.0, 0.0); | 0 | ||||||||||||||||||
| 52 | else | - | ||||||||||||||||||
| 53 | return QGLRect(minX, minY, maxX, maxY); executed 4 times by 1 test: return QGLRect(minX, minY, maxX, maxY);Executed by:
| 4 | ||||||||||||||||||
| 54 | } | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | void QGL2PEXVertexArray::addClosingLine(int index) | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 | QPointF point(vertexArray.at(index)); | - | ||||||||||||||||||
| 59 | if (point != QPointF(vertexArray.last()))
| 0-28 | ||||||||||||||||||
| 60 | vertexArray.add(point); never executed: vertexArray.add(point); | 0 | ||||||||||||||||||
| 61 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | void QGL2PEXVertexArray::addCentroid(const QVectorPath &path, int subPathIndex) | - | ||||||||||||||||||
| 64 | { | - | ||||||||||||||||||
| 65 | const QPointF *const points = reinterpret_cast<const QPointF *>(path.points()); | - | ||||||||||||||||||
| 66 | const QPainterPath::ElementType *const elements = path.elements(); | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | QPointF sum = points[subPathIndex]; | - | ||||||||||||||||||
| 69 | int count = 1; | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | for (int i = subPathIndex + 1; i < path.elementCount() && (!elements || elements[i] != QPainterPath::MoveToElement); ++i) {
| 0-138 | ||||||||||||||||||
| 72 | sum += points[i]; | - | ||||||||||||||||||
| 73 | ++count; | - | ||||||||||||||||||
| 74 | } executed 112 times by 1 test: end of blockExecuted by:
| 112 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | const QPointF centroid = sum / qreal(count); | - | ||||||||||||||||||
| 77 | vertexArray.add(centroid); | - | ||||||||||||||||||
| 78 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | void QGL2PEXVertexArray::addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline) | - | ||||||||||||||||||
| 81 | { | - | ||||||||||||||||||
| 82 | const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); | - | ||||||||||||||||||
| 83 | const QPainterPath::ElementType* const elements = path.elements(); | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | if (boundingRectDirty) {
| 0-2 | ||||||||||||||||||
| 86 | minX = maxX = points[0].x(); | - | ||||||||||||||||||
| 87 | minY = maxY = points[0].y(); | - | ||||||||||||||||||
| 88 | boundingRectDirty = false; | - | ||||||||||||||||||
| 89 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | if (!outline && !path.isConvex())
| 0-2 | ||||||||||||||||||
| 92 | addCentroid(path, 0); executed 2 times by 1 test: addCentroid(path, 0);Executed by:
| 2 | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | int lastMoveTo = vertexArray.size(); | - | ||||||||||||||||||
| 95 | vertexArray.add(points[0]); // The first element is always a moveTo | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | do { | - | ||||||||||||||||||
| 98 | if (!elements) {
| 0-2 | ||||||||||||||||||
| 99 | // qDebug("QVectorPath has no elements"); | - | ||||||||||||||||||
| 100 | // If the path has a null elements pointer, the elements implicitly | - | ||||||||||||||||||
| 101 | // start with a moveTo (already added) and continue with lineTos: | - | ||||||||||||||||||
| 102 | for (int i=1; i<path.elementCount(); ++i)
| 0 | ||||||||||||||||||
| 103 | lineToArray(points[i].x(), points[i].y()); never executed: lineToArray(points[i].x(), points[i].y()); | 0 | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | break; never executed: break; | 0 | ||||||||||||||||||
| 106 | } | - | ||||||||||||||||||
| 107 | // qDebug("QVectorPath has element types"); | - | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | for (int i=1; i<path.elementCount(); ++i) {
| 2-138 | ||||||||||||||||||
| 110 | switch (elements[i]) { | - | ||||||||||||||||||
| 111 | case QPainterPath::MoveToElement: executed 26 times by 1 test: case QPainterPath::MoveToElement:Executed by:
| 26 | ||||||||||||||||||
| 112 | if (!outline)
| 0-26 | ||||||||||||||||||
| 113 | addClosingLine(lastMoveTo); executed 26 times by 1 test: addClosingLine(lastMoveTo);Executed by:
| 26 | ||||||||||||||||||
| 114 | // qDebug("element[%d] is a MoveToElement", i); | - | ||||||||||||||||||
| 115 | vertexArrayStops.add(vertexArray.size()); | - | ||||||||||||||||||
| 116 | if (!outline) {
| 0-26 | ||||||||||||||||||
| 117 | if (!path.isConvex()) addCentroid(path, i); executed 26 times by 1 test: addCentroid(path, i);Executed by:
| 0-26 | ||||||||||||||||||
| 118 | lastMoveTo = vertexArray.size(); | - | ||||||||||||||||||
| 119 | } executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 120 | lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex | - | ||||||||||||||||||
| 121 | break; executed 26 times by 1 test: break;Executed by:
| 26 | ||||||||||||||||||
| 122 | case QPainterPath::LineToElement: executed 112 times by 1 test: case QPainterPath::LineToElement:Executed by:
| 112 | ||||||||||||||||||
| 123 | // qDebug("element[%d] is a LineToElement", i); | - | ||||||||||||||||||
| 124 | lineToArray(points[i].x(), points[i].y()); | - | ||||||||||||||||||
| 125 | break; executed 112 times by 1 test: break;Executed by:
| 112 | ||||||||||||||||||
| 126 | case QPainterPath::CurveToElement: { never executed: case QPainterPath::CurveToElement: | 0 | ||||||||||||||||||
| 127 | QBezier b = QBezier::fromPoints(*(((const QPointF *) points) + i - 1), | - | ||||||||||||||||||
| 128 | points[i], | - | ||||||||||||||||||
| 129 | points[i+1], | - | ||||||||||||||||||
| 130 | points[i+2]); | - | ||||||||||||||||||
| 131 | QRectF bounds = b.bounds(); | - | ||||||||||||||||||
| 132 | // threshold based on same algorithm as in qtriangulatingstroker.cpp | - | ||||||||||||||||||
| 133 | int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14f / (curveInverseScale * 6)); | - | ||||||||||||||||||
| 134 | if (threshold < 3) threshold = 3; never executed: threshold = 3;
| 0 | ||||||||||||||||||
| 135 | qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1); | - | ||||||||||||||||||
| 136 | for (int t=0; t<threshold; ++t) {
| 0 | ||||||||||||||||||
| 137 | QPointF pt = b.pointAt(t * one_over_threshold_minus_1); | - | ||||||||||||||||||
| 138 | lineToArray(pt.x(), pt.y()); | - | ||||||||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||||||||
| 140 | i += 2; | - | ||||||||||||||||||
| 141 | break; } never executed: break; | 0 | ||||||||||||||||||
| 142 | default: never executed: default: | 0 | ||||||||||||||||||
| 143 | break; never executed: break; | 0 | ||||||||||||||||||
| 144 | } | - | ||||||||||||||||||
| 145 | } | - | ||||||||||||||||||
| 146 | } while (0); | - | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | if (!outline)
| 0-2 | ||||||||||||||||||
| 149 | addClosingLine(lastMoveTo); executed 2 times by 1 test: addClosingLine(lastMoveTo);Executed by:
| 2 | ||||||||||||||||||
| 150 | vertexArrayStops.add(vertexArray.size()); | - | ||||||||||||||||||
| 151 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | void QGL2PEXVertexArray::lineToArray(const GLfloat x, const GLfloat y) | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | vertexArray.add(QGLPoint(x, y)); | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | if (x > maxX)
| 10-128 | ||||||||||||||||||
| 158 | maxX = x; executed 10 times by 1 test: maxX = x;Executed by:
| 10 | ||||||||||||||||||
| 159 | else if (x < minX)
| 0-128 | ||||||||||||||||||
| 160 | minX = x; never executed: minX = x; | 0 | ||||||||||||||||||
| 161 | if (y > maxY)
| 12-126 | ||||||||||||||||||
| 162 | maxY = y; executed 12 times by 1 test: maxY = y;Executed by:
| 12 | ||||||||||||||||||
| 163 | else if (y < minY)
| 0-126 | ||||||||||||||||||
| 164 | minY = y; never executed: minY = y; | 0 | ||||||||||||||||||
| 165 | } executed 138 times by 1 test: end of blockExecuted by:
| 138 | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |