| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengl2pexvertexarray.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 QtGui 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 "qopengl2pexvertexarray_p.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include <private/qbezier_p.h> | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | void QOpenGL2PEXVertexArray::clear() | - | ||||||||||||||||||
| 41 | { | - | ||||||||||||||||||
| 42 | vertexArray.reset(); | - | ||||||||||||||||||
| 43 | vertexArrayStops.reset(); | - | ||||||||||||||||||
| 44 | boundingRectDirty = true; | - | ||||||||||||||||||
| 45 | } never executed:  end of block | 0 | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | QOpenGLRect QOpenGL2PEXVertexArray::boundingRect() const | - | ||||||||||||||||||
| 49 | { | - | ||||||||||||||||||
| 50 |     if (boundingRectDirty)
  | 0 | ||||||||||||||||||
| 51 |         return QOpenGLRect(0.0, 0.0, 0.0, 0.0); never executed:  return QOpenGLRect(0.0, 0.0, 0.0, 0.0); | 0 | ||||||||||||||||||
| 52 | else | - | ||||||||||||||||||
| 53 |         return QOpenGLRect(minX, minY, maxX, maxY); never executed:  return QOpenGLRect(minX, minY, maxX, maxY); | 0 | ||||||||||||||||||
| 54 | } | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | void QOpenGL2PEXVertexArray::addClosingLine(int index) | - | ||||||||||||||||||
| 57 | { | - | ||||||||||||||||||
| 58 | QPointF point(vertexArray.at(index)); | - | ||||||||||||||||||
| 59 |     if (point != QPointF(vertexArray.last()))
  | 0 | ||||||||||||||||||
| 60 |         vertexArray.add(point); never executed:  vertexArray.add(point); | 0 | ||||||||||||||||||
| 61 | } never executed:  end of block | 0 | ||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | void QOpenGL2PEXVertexArray::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 | ||||||||||||||||||
| 72 | sum += points[i]; | - | ||||||||||||||||||
| 73 | ++count; | - | ||||||||||||||||||
| 74 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | const QPointF centroid = sum / qreal(count); | - | ||||||||||||||||||
| 77 | vertexArray.add(centroid); | - | ||||||||||||||||||
| 78 | } never executed:  end of block | 0 | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | void QOpenGL2PEXVertexArray::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 | ||||||||||||||||||
| 86 | minX = maxX = points[0].x(); | - | ||||||||||||||||||
| 87 | minY = maxY = points[0].y(); | - | ||||||||||||||||||
| 88 | boundingRectDirty = false; | - | ||||||||||||||||||
| 89 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 |     if (!outline && !path.isConvex())
 
  | 0 | ||||||||||||||||||
| 92 |         addCentroid(path, 0); never executed:  addCentroid(path, 0); | 0 | ||||||||||||||||||
| 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 | ||||||||||||||||||
| 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) {
  | 0 | ||||||||||||||||||
| 110 | switch (elements[i]) { | - | ||||||||||||||||||
| 111 |             case QPainterPath::MoveToElement: never executed:  case QPainterPath::MoveToElement: | 0 | ||||||||||||||||||
| 112 |                 if (!outline)
  | 0 | ||||||||||||||||||
| 113 |                     addClosingLine(lastMoveTo); never executed:  addClosingLine(lastMoveTo); | 0 | ||||||||||||||||||
| 114 | // qDebug("element[%d] is a MoveToElement", i); | - | ||||||||||||||||||
| 115 | vertexArrayStops.add(vertexArray.size()); | - | ||||||||||||||||||
| 116 |                 if (!outline) {
  | 0 | ||||||||||||||||||
| 117 |                     if (!path.isConvex()) addCentroid(path, i); never executed:  addCentroid(path, i);
  | 0 | ||||||||||||||||||
| 118 | lastMoveTo = vertexArray.size(); | - | ||||||||||||||||||
| 119 |                 } never executed:  end of block | 0 | ||||||||||||||||||
| 120 | lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex | - | ||||||||||||||||||
| 121 |                 break; never executed:  break; | 0 | ||||||||||||||||||
| 122 |             case QPainterPath::LineToElement: never executed:  case QPainterPath::LineToElement: | 0 | ||||||||||||||||||
| 123 | // qDebug("element[%d] is a LineToElement", i); | - | ||||||||||||||||||
| 124 | lineToArray(points[i].x(), points[i].y()); | - | ||||||||||||||||||
| 125 |                 break; never executed:  break; | 0 | ||||||||||||||||||
| 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 | ||||||||||||||||||
| 149 |         addClosingLine(lastMoveTo); never executed:  addClosingLine(lastMoveTo); | 0 | ||||||||||||||||||
| 150 | vertexArrayStops.add(vertexArray.size()); | - | ||||||||||||||||||
| 151 | } never executed:  end of block | 0 | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | void QOpenGL2PEXVertexArray::lineToArray(const GLfloat x, const GLfloat y) | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | vertexArray.add(QOpenGLPoint(x, y)); | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 |     if (x > maxX)
  | 0 | ||||||||||||||||||
| 158 |         maxX = x; never executed:  maxX = x; | 0 | ||||||||||||||||||
| 159 |     else if (x < minX)
  | 0 | ||||||||||||||||||
| 160 |         minX = x; never executed:  minX = x; | 0 | ||||||||||||||||||
| 161 |     if (y > maxY)
  | 0 | ||||||||||||||||||
| 162 |         maxY = y; never executed:  maxY = y; | 0 | ||||||||||||||||||
| 163 |     else if (y < minY)
  | 0 | ||||||||||||||||||
| 164 |         minY = y; never executed:  minY = y; | 0 | ||||||||||||||||||
| 165 | } never executed:  end of block | 0 | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |