Exemplo n.º 1
0
void QDocumentBuffer::insertLines(int after, const QVector<QDocumentLineHandle*>& l)
{
	int index = after + 1;
	int blockIndex = blockForLine(index);
	
	if ( blockIndex == -1 )
	{
		qWarning("cannot insert line at pos %i", index);
		return;
	}
	
	int n = l.count();
	Block *b = m_blocks.at(blockIndex);
	
	if ( (b->size() + 1) >= m_forkThresold )
	{
		// split block
		int bounds = b->start + m_optimalSize;
		
		Block *nb = new Block(bounds);
		nb->insert(bounds, b->lines.constData() + m_optimalSize, b->size() - m_optimalSize);
		nb->append(l.constData(), n);
		nb->end = bounds + nb->size();
		m_blocks.insert(blockIndex + 1, nb);
		
		b->lines.resize(m_optimalSize);
		b->end = bounds;
		
		blockIndex += 2;
	} else {
		b->insert(index, l.constData(), n);
	}
	
	// update block boundaries
	while ( blockIndex < m_blocks.count() )
	{
		b = m_blocks.at(blockIndex);
		b->start += n;
		b->end += n;
	}
}
Exemplo n.º 2
0
bool OctreePacketData::appendValue(const QVector<float>& value) {
    uint16_t qVecSize = value.size();
    bool success = appendValue(qVecSize);
    if (success) {
        success = append((const unsigned char*)value.constData(), qVecSize * sizeof(float));
        if (success) {
            _bytesOfValues += qVecSize * sizeof(float);
            _totalBytesOfValues += qVecSize * sizeof(float);
        }
    }
    return success;
}
Exemplo n.º 3
0
void AM3DAdditionAB::computeCachedValues() const
{
	AMnDIndex start = AMnDIndex();
	AMnDIndex end = AMnDIndex();

	if (dirtyIndices_.isEmpty()){

		start = AMnDIndex(rank(), AMnDIndex::DoInit);
		end = size()-1;
	}

	else {

		start = dirtyIndices_.first();
		end = dirtyIndices_.last();
		end[rank()-1] = size(rank()-1);
	}

	int totalSize = start.totalPointsTo(end);
	int flatStartIndex = start.flatIndexInArrayOfSize(size());
	QVector<double> data = QVector<double>(totalSize);
	sources_.at(0)->values(start, end, data.data());

	// Do the first data source separately to initialize the values.
	memcpy(cachedData_.data()+flatStartIndex, data.constData(), totalSize*sizeof(double));
	cachedData_ = data;

	// Iterate through the rest of the sources.
	for (int i = 1, count = sources_.size(); i < count; i++){

		sources_.at(i)->values(start, end, data.data());

		for (int j = 0; j < totalSize; j++)
			cachedData_[flatStartIndex+j] += data.at(j);
	}

	if (dirtyIndices_.isEmpty())
		cachedDataRange_ = AMUtility::rangeFinder(cachedData_);

	else{
		AMRange cachedRange = AMUtility::rangeFinder(cachedData_.mid(flatStartIndex, totalSize));

		if (cachedDataRange_.minimum() > cachedRange.minimum())
			cachedDataRange_.setMinimum(cachedRange.minimum());

		if (cachedDataRange_.maximum() < cachedRange.maximum())
			cachedDataRange_.setMaximum(cachedRange.maximum());
	}

	cacheUpdateRequired_ = false;
	dirtyIndices_.clear();
}
Exemplo n.º 4
0
/*!
    Converts the variant map \a map to a QJsonObject.

    The keys in \a map will be used as the keys in the JSON object,
    and the QVariant values will be converted to JSON values.

    \sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()
 */
QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)
{
    QJsonObject object;
    if (map.isEmpty())
        return object;

    object.detach2(1024);

    QVector<QJsonPrivate::offset> offsets;
    QJsonPrivate::offset currentOffset;
    currentOffset = sizeof(QJsonPrivate::Base);

    // the map is already sorted, so we can simply append one entry after the other and
    // write the offset table at the end
    for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) {
        QString key = it.key();
        QJsonValue val = QJsonValue::fromVariant(it.value());

        bool latinOrIntValue;
        int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);

        bool latinKey = QJsonPrivate::useCompressed(key);
        int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey);
        int requiredSize = valueOffset + valueSize;

        if (!object.detach2(requiredSize + sizeof(QJsonPrivate::offset))) // offset for the new index entry
            return QJsonObject();

        QJsonPrivate::Entry *e = reinterpret_cast<QJsonPrivate::Entry *>(reinterpret_cast<char *>(object.o) + currentOffset);
        e->value.type = val.t;
        e->value.latinKey = latinKey;
        e->value.latinOrIntValue = latinOrIntValue;
        e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)object.o + valueOffset);
        QJsonPrivate::copyString((char *)(e + 1), key, latinKey);
        if (valueSize)
            QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);

        offsets << currentOffset;
        currentOffset += requiredSize;
        object.o->size = currentOffset;
    }

    // write table
    object.o->tableOffset = currentOffset;
    if (!object.detach2(sizeof(QJsonPrivate::offset)*offsets.size()))
        return QJsonObject();
    memcpy(object.o->table(), offsets.constData(), offsets.size()*sizeof(uint));
    object.o->length = offsets.size();
    object.o->size = currentOffset + sizeof(QJsonPrivate::offset)*offsets.size();

    return object;
}
Exemplo n.º 5
0
void tst_QRegion::operator_intersect_data()
{
    QTest::addColumn<QRegion>("r1");
    QTest::addColumn<QRegion>("r2");
    QTest::addColumn<QRegion>("expected");

    QTest::newRow("empty 0") << QRegion() << QRegion() << QRegion();
    QTest::newRow("empty 1") << QRegion() << QRegion(QRect(10, 10, 10, 10))
                             << QRegion();
    QTest::newRow("empty 2") << QRegion(QRect(10, 10, 10, 10)) << QRegion()
                             << QRegion();

    QRegion dest;
    QVector<QRect> rects;
    rects << QRect(10, 10, 10, 10) << QRect(22, 10, 10, 10);
    dest.setRects(rects.constData(), rects.size());
    QTest::newRow("simple 1") << dest
                              << QRegion(22, 10, 10, 10)
                              << QRegion(22, 10, 10, 10);
    QTest::newRow("simple 2") << dest
                              << QRegion(10, 10, 10, 10)
                              << QRegion(10, 10, 10, 10);

    rects.clear();
    rects << QRect(10, 10, 10, 10) << QRect(10, 20, 15, 10);
    dest.setRects(rects.constData(), rects.size());
    QTest::newRow("merge 1") << dest
                             << QRegion(10, 10, 10, 20)
                             << QRegion(10, 10, 10, 20);

    rects.clear();
    rects << QRect(11, 11, 218, 117) << QRect(11, 128, 218, 27)
          << QRect(264, 128, 122, 27) << QRect(11, 155, 218, 43)
          << QRect(11, 198, 218, 27) << QRect(264, 198, 122, 27)
          << QRect(11, 225, 218, 221);
    dest.setRects(rects.constData(), rects.size());
    QTest::newRow("merge 2") << dest << QRegion(11, 11, 218, 458)
                             << QRegion(11, 11, 218, 435);

    rects.clear();
    rects << QRect(0, 0, 10, 10) << QRect(20, 0, 10, 10);
    dest.setRects(rects.constData(), rects.size());
    QTest::newRow("empty 3") << dest << QRegion(11, 0, 5, 5) << QRegion();

    QTest::newRow("extents check") << dest << QRegion(0, 0, 15, 15)
                                   << QRegion(0, 0, 10, 10);

    rects.clear();
    rects << QRect(10, 10, 10, 10) << QRect(10, 20, 10, 10)
          << QRect(30, 20, 10, 10) << QRect(10, 30, 10, 10);
    dest.setRects(rects.constData(), rects.size());
    rects.clear();
    rects << QRect(10, 10, 10, 10) << QRect(10, 20, 10, 10)
          << QRect(30, 20, 10, 10);
    QRegion expected;
    expected.setRects(rects.constData(), rects.size());
    QTest::newRow("dont merge") << dest << QRegion(0, 0, 100, 30)
                                << expected;
}
Exemplo n.º 6
0
void Grid::create()
{
    // Allocate some storage to hold per-vertex data
    QVector<float> v;         // Vertices
    QVector<unsigned int> el; // Element indices

    // Generate the vertex data
    generateVertexData( v, el );

    // Create and populate the buffer objects
    m_positionBuffer.create();
    m_positionBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw );
    m_positionBuffer.bind();
    m_positionBuffer.allocate( v.constData(), v.size() * sizeof( float ) );

#if 0
    m_indexBuffer.create();
    m_indexBuffer.setUsagePattern( QOpenGLBuffer::StaticDraw );
    m_indexBuffer.bind();
    m_indexBuffer.allocate( el.constData(), el.size() * sizeof( unsigned int ) );
#endif
    updateVertexArrayObject();
}
Exemplo n.º 7
0
void QXcbNativeBackingStore::beginPaint(const QRegion &region)
{
#if QT_CONFIG(xrender)
    if (m_translucentBackground) {
        const QVector<XRectangle> xrects = qt_region_to_xrectangles(region);
        const XRenderColor color = { 0, 0, 0, 0 };
        XRenderFillRectangles(display(), PictOpSrc,
                              qt_x11PictureHandle(m_pixmap), &color,
                              xrects.constData(), xrects.size());
    }
#else
    Q_UNUSED(region);
#endif
}
Exemplo n.º 8
0
bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *member)
{
    receiver = target;
    metaTypes.clear();
    methodIdx = -1;
    if (!target)
        return true;;           // unsetting

    if (!member || !*member) {
        // would not be able to deliver a reply
        qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)",
                 target ? target->metaObject()->className() : "(null)",
                 member ? member + 1 : "(null)",
                 target ? qPrintable(target->objectName()) : "no name");
        return false;
    }

    methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes);
    if (methodIdx == -1) {
        QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1);
        methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes);
    }
    if (methodIdx == -1) {
        // would not be able to deliver a reply
        qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)",
                 target->metaObject()->className(),
                 member + 1, qPrintable(target->objectName()));
        return false;
    }

    // success
    // construct the expected signature
    int count = metaTypes.count() - 1;
    if (count == 1 && metaTypes.at(1) == QDBusMetaTypeId::message) {
        // wildcard slot, can receive anything, so don't set the signature
        return true;
    }

    if (metaTypes.at(count) == QDBusMetaTypeId::message)
        --count;

    if (count == 0) {
        setMetaTypes(count, 0);
    } else {
        QVector<int> types = QVector<int>::fromList(metaTypes);
        setMetaTypes(count, types.constData() + 1);
    }
    return true;
}
Exemplo n.º 9
0
void MonoFaceShader::renderMesh(QColor meshColor,
                                QVector<QVector3D>& vertices,
                                QVector<QVector3D>& normals)
{
    if (vertices.size() != normals.size())
        throw runtime_error("vertex and normal array not same size MonoFaceShader::renderMesh");

    _program->setUniformValue(_uniforms["sourceColor"],
                  meshColor.redF(),
                  meshColor.greenF(),
                  meshColor.blueF(),
                  1.0f);

    GLuint normalAttr = _attributes["normal"];
    GLuint vertexAttr = _attributes["vertex"];

    _program->setAttributeArray(vertexAttr, vertices.constData());
    _program->setAttributeArray(normalAttr, normals.constData());
    _program->enableAttributeArray(normalAttr);
    _program->enableAttributeArray(vertexAttr);
    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
    _program->disableAttributeArray(normalAttr);
    _program->disableAttributeArray(vertexAttr);
}
Exemplo n.º 10
0
void LineShader::renderPoints(QVector<QVector3D>& points, QColor color)
{
    _program->setUniformValue(_uniforms["sourceColor"],
                  color.redF(),
                  color.greenF(),
                  color.blueF(),
                  1.0f);

    GLuint posAttr = _attributes["posAttr"];

    _program->setAttributeArray(posAttr, points.constData());
    _program->enableAttributeArray(posAttr);
    glDrawArrays(GL_POINTS, 0, points.size());
    _program->disableAttributeArray(posAttr);
}
Exemplo n.º 11
0
void XCompositeEglClientBufferIntegration::bindTextureToBuffer(struct ::wl_resource *buffer)
{
    XCompositeBuffer *compositorBuffer = XCompositeBuffer::fromResource(buffer);
    Pixmap pixmap = XCompositeNameWindowPixmap(mDisplay, compositorBuffer->window());

    QVector<EGLint> eglConfigSpec = eglbuildSpec();

    EGLint matching = 0;
    EGLConfig config;
    bool matched = eglChooseConfig(mEglDisplay,eglConfigSpec.constData(),&config,1,&matching);
    if (!matched || !matching) {
        qWarning("Could not retrieve a suitable EGL config");
        return;
    }

    QVector<EGLint> attribList;

    attribList.append(EGL_TEXTURE_FORMAT);
    attribList.append(EGL_TEXTURE_RGBA);
    attribList.append(EGL_TEXTURE_TARGET);
    attribList.append(EGL_TEXTURE_2D);
    attribList.append(EGL_NONE);

    EGLSurface surface = eglCreatePixmapSurface(mEglDisplay,config,pixmap,attribList.constData());
    if (surface == EGL_NO_SURFACE) {
        qDebug() << "Failed to create eglsurface" << pixmap << compositorBuffer->window();
    }

    compositorBuffer->setInvertedY(true);

    if (!eglBindTexImage(mEglDisplay,surface,EGL_BACK_BUFFER)) {
        qDebug() << "Failed to bind";
    }

    //    eglDestroySurface(mEglDisplay,surface);
}
Exemplo n.º 12
0
MetaType * MetaType::find( int id )
{
  int n = gMetaTypes.count();
  MetaType * const * d = gMetaTypes.constData();

  int i;
  for(i = 0; i < n; ++i)
  {
      if((*d)->mId == id)
        return *d;
      ++d;
  }

  return 0;
}
Exemplo n.º 13
0
void LineShader::renderLines(QVector<QVector3D>& vertices, QColor lineColor)
{
    _program->setUniformValue(_uniforms["sourceColor"],
                  lineColor.redF(),
                  lineColor.greenF(),
                  lineColor.blueF(),
                  1.0f);

    GLuint posAttr = _attributes["posAttr"];

    _program->setAttributeArray(posAttr, vertices.constData());
    _program->enableAttributeArray(posAttr);
    glDrawArrays(GL_LINES, 0, vertices.size());
    _program->disableAttributeArray(posAttr);
}
Exemplo n.º 14
0
void tst_QRegion::rectCount_data()
{
    QTest::addColumn<QRegion>("region");
    QTest::addColumn<int>("expected");

    QTest::newRow("empty") << QRegion() << 0;
    QTest::newRow("rect") << QRegion(10, 10, 10, 10) << 1;

    QRegion dest;
    QVector<QRect> rects;
    rects << QRect(10, 10, 10, 10) << QRect(22, 10, 10, 10);
    dest.setRects(rects.constData(), rects.size());

    QTest::newRow("2 rects") << dest << rects.size();
}
Exemplo n.º 15
0
void IdTreeDB::put(quint64 docId, const QVector<quint64> subDocIds)
{
    Q_ASSERT(!subDocIds.isEmpty());
    Q_ASSERT(!subDocIds.contains(0));

    MDB_val key;
    key.mv_size = sizeof(quint64);
    key.mv_data = static_cast<void*>(&docId);

    MDB_val val;
    val.mv_size = subDocIds.size() * sizeof(quint64);
    val.mv_data = static_cast<void*>(const_cast<quint64*>(subDocIds.constData()));

    int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
    Q_ASSERT_X(rc == 0, "IdTreeDB::put", mdb_strerror(rc));
}
Exemplo n.º 16
0
GLXFBConfig qglx_findConfig(Display *display, int screen , const QSurfaceFormat &format, int drawableBit)
{
    bool reduced = true;
    GLXFBConfig chosenConfig = 0;
    QSurfaceFormat reducedFormat = format;
    while (!chosenConfig && reduced) {
        QVector<int> spec = qglx_buildSpec(reducedFormat, drawableBit);
        int confcount = 0;
        GLXFBConfig *configs;
        configs = glXChooseFBConfig(display, screen,spec.constData(),&confcount);
        if (confcount)
        {
            for (int i = 0; i < confcount; i++) {
                chosenConfig = configs[i];
                // Make sure we try to get an ARGB visual if the format asked for an alpha:
                if (reducedFormat.hasAlpha()) {
                    int alphaSize;
                    glXGetFBConfigAttrib(display,configs[i],GLX_ALPHA_SIZE,&alphaSize);
                    if (alphaSize > 0) {
                        XVisualInfo *visual = glXGetVisualFromFBConfig(display, chosenConfig);
                        bool hasAlpha = false;

#if !defined(QT_NO_XRENDER)
                        XRenderPictFormat *pictFormat = XRenderFindVisualFormat(display, visual->visual);
                        hasAlpha = pictFormat->direct.alphaMask > 0;
#else
                        hasAlpha = visual->depth == 32;
#endif

                        XFree(visual);

                        if (hasAlpha)
                            break;
                    }
                } else {
                    break; // Just choose the first in the list if there's no alpha requested
                }
            }

            XFree(configs);
        }
        if (!chosenConfig)
            reducedFormat = qglx_reduceSurfaceFormat(reducedFormat,&reduced);
    }

    return chosenConfig;
}
Exemplo n.º 17
0
QWaylandBrcmGLContext::QWaylandBrcmGLContext(EGLDisplay eglDisplay, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
    : QPlatformOpenGLContext()
    , m_eglDisplay(eglDisplay)
    , m_config(q_configFromGLFormat(m_eglDisplay, brcmFixFormat(format), true))
    , m_format(q_glFormatFromConfig(m_eglDisplay, m_config))
{
    EGLContext shareEGLContext = share ? static_cast<QWaylandBrcmGLContext *>(share)->eglContext() : EGL_NO_CONTEXT;

    eglBindAPI(EGL_OPENGL_ES_API);

    QVector<EGLint> eglContextAttrs;
    eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
    eglContextAttrs.append(format.majorVersion() == 1 ? 1 : 2);
    eglContextAttrs.append(EGL_NONE);

    m_context = eglCreateContext(m_eglDisplay, m_config, shareEGLContext, eglContextAttrs.constData());
}
Exemplo n.º 18
0
QPolygonF QwtSplineC1::polygonX( int numPoints, const QPolygonF &points ) const
{
    if ( points.size() <= 2 )
        return points;

    QPolygonF fittedPoints;

    const QVector<double> m = slopesX( points );
    if ( m.size() != points.size() )
        return fittedPoints;

    const QPointF *p = points.constData();
    const double *s = m.constData();

    const double x1 = points.first().x();
    const double x2 = points.last().x();

    const double delta = ( x2 - x1 ) / ( numPoints - 1 );

    double x0, y0;
    QwtSplinePolynom polynom;

    for ( int i = 0, j = 0; i < numPoints; i++ )
    {
        double x = x1 + i * delta;
        if ( x > x2 )
            x = x2;

        if ( i == 0 || x > p[j + 1].x() )
        {
            while ( x > p[j + 1].x() )
                j++;

            polynom = QwtSplinePolynom::fromSlopes( p[j], s[j], p[j + 1], s[j + 1] );

            x0 = p[j].x();
            y0 = p[j].y();
        }

        const double y = y0 + polynom.value( x - x0 );
        fittedPoints += QPointF( x, y );
    }

    return fittedPoints;
}   
Exemplo n.º 19
0
void FilterOp::filterVertically(QVector<QRgb>& src, QVector<QRgb>& trg)
{
    const QRgb *inPixels = src.constData();

    for (int x = 0; x < dstWidth; ++x)
    {
        for (int y = dstHeight - 1; y >= 0 ; --y)
        {
            int yTimesNumContributors = y * verticalSubsamplingData.matrixWidth;
            int max = verticalSubsamplingData.numberOfSamples[y];
            int ofsY = dstWidth * y;
            float red = 0;
            float green = 0;
            float blue = 0;
            float alpha = 0;

            int index = yTimesNumContributors;
            for (int j = max - 1; j >= 0 ; --j)
            {
                int color = inPixels[x + (dstWidth * verticalSubsamplingData.pixelPositions[index])];
                float w = verticalSubsamplingData.weights[index];
                alpha += qAlpha(color) * w;
                red += qRed(color) * w;
                green += qGreen(color) * w;
                blue += qBlue(color) * w;
                index++;
            }

            int ri = std::max((int)red, 0);
            ri = std::min(ri, 255);

            int gi = std::max((int)green, 0);
            gi = std::min(gi, 255);

            int bi = std::max((int)blue, 0);
            bi = std::min(bi, 255);

            int ai = std::max((int)alpha, 0);
            ai = std::min(ai, 255);

            trg[x + ofsY] = qRgba(ri, gi, bi, ai);
        }
    }
}
static SplineStore qwtSplinePathG1( 
    const QwtSplineCardinalG1 *spline, const QPolygonF &points ) 
{
    const int size = points.size();
    const int numTensions = spline->isClosing() ? size : size - 1;

    const QVector<QwtSplineCardinalG1::Tension> tensions2 = spline->tensions( points );
    if ( tensions2.size() != numTensions )
        return SplineStore();

    const QPointF *p = points.constData();
    const QwtSplineCardinalG1::Tension *t = tensions2.constData();

    SplineStore store;
    store.init( numTensions );
    store.start( p[0] );
    
    const QPointF &p0 = spline->isClosing() ? p[size-1] : p[0];
    QPointF vec1 = ( p[1] - p0 ) * 0.5;

    for ( int i = 0; i < size - 2; i++ )
    {
        const QPointF vec2 = ( p[i+2] - p[i] ) * 0.5;
        store.addCubic( p[i] + vec1 * t[i].t1, 
            p[i+1] - vec2 * t[i].t2, p[i+1] );
        
        vec1 = vec2;
    }   
    
    const QPointF &pn = spline->isClosing() ? p[0] : p[size-1];
    const QPointF vec2 = 0.5 * ( pn - p[size - 2] );

    store.addCubic( p[size - 2] + vec1 * t[size-2].t1,
        p[size - 1] - vec2 * t[size-2].t2, p[size - 1] );

    if ( spline->isClosing() )
    {
        const QPointF vec3 = 0.5 * ( p[1] - p[size-1] );
        store.addCubic( p[size-1] + vec2 * t[size-1].t1, 
            p[0] - vec3 * t[size-1].t2, p[0] );
    }

    return store;
}
Exemplo n.º 21
0
/*!
   \brief Append paint commands

   \param commands Paint commands
   \sa commands()
 */
void QwtGraphic::setCommands( QVector< QwtPainterCommand > &commands )
{
    reset();

    const int numCommands = commands.size();
    if ( numCommands <= 0 )
        return;

    // to calculate a proper bounding rectangle we don't simply copy 
    // the commands. 

    const QwtPainterCommand *cmds = commands.constData();

    QPainter painter( this );
    for ( int i = 0; i < numCommands; i++ )
        qwtExecCommand( &painter, cmds[i], RenderHints(), QTransform() );

    painter.end();
}
Exemplo n.º 22
0
QWaylandXCompositeEGLContext::QWaylandXCompositeEGLContext(QWaylandXCompositeEGLIntegration *glxIntegration, QWaylandXCompositeEGLWindow *window)
    : QPlatformGLContext()
    , mEglIntegration(glxIntegration)
    , mWindow(window)
    , mBuffer(0)
    , mXWindow(0)
    , mConfig(q_configFromQPlatformWindowFormat(glxIntegration->eglDisplay(),window->widget()->platformWindowFormat(),true,EGL_WINDOW_BIT))
    , mWaitingForSync(false)
{
    QVector<EGLint> eglContextAttrs;
    eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION); eglContextAttrs.append(2);
    eglContextAttrs.append(EGL_NONE);

    mContext = eglCreateContext(glxIntegration->eglDisplay(),mConfig,EGL_NO_CONTEXT,eglContextAttrs.constData());
    if (mContext == EGL_NO_CONTEXT) {
        qFatal("failed to find context");
    }

    geometryChanged();
}
Exemplo n.º 23
0
static bool kde4EnableBlurBehindWindow(WId window, bool enable, const QRegion &region = QRegion())
{
    Display *dpy = QX11Info::display();
    Atom atom = XInternAtom(dpy, "_KDE_NET_WM_BLUR_BEHIND_REGION", False);

    if (enable) {
        QVector<QRect> rects = region.rects();
        QVector<quint32> data;
        for (int i = 0; i < rects.count(); i++) {
            const QRect r = rects[i];
            data << r.x() << r.y() << r.width() << r.height();
        }

        XChangeProperty(dpy, window, atom, XA_CARDINAL, 32, PropModeReplace,
                        reinterpret_cast<const unsigned char *>(data.constData()), data.size());
    } else {
        XDeleteProperty(dpy, window, atom);
    }
    return true;
}
Exemplo n.º 24
0
void tst_QRegion::operator_xor_data()
{
    QTest::addColumn<QRegion>("dest");
    QTest::addColumn<QRegion>("arg");
    QTest::addColumn<QRegion>("expected");

    QTest::newRow("empty 0") << QRegion() << QRegion() << QRegion();
    QTest::newRow("empty 1") << QRegion() << QRegion(QRect(10, 10, 10, 10))
                             << QRegion(QRect(10, 10, 10, 10));
    QTest::newRow("empty 2") << QRegion(QRect(10, 10, 10, 10)) << QRegion()
                             << QRegion(QRect(10, 10, 10, 10));

    QRegion dest;
    QVector<QRect> rects;
    rects << QRect(10, 10, 10, 10) << QRect(22, 10, 10, 10);
    dest.setRects(rects.constData(), rects.size());
    QTest::newRow("simple 1") << dest
                              << QRegion(22, 10, 10, 10)
                              << QRegion(10, 10, 10, 10);
    QTest::newRow("simple 2") << dest
                              << QRegion(10, 10, 10, 10)
                              << QRegion(22, 10, 10, 10);
    QTest::newRow("simple 3") << dest << dest << QRegion();
    QTest::newRow("simple 4") << QRegion(10, 10, 10, 10)
                              << QRegion(10, 10, 5, 10)
                              << QRegion(15, 10, 5, 10);
    QTest::newRow("simple 5") << QRegion(10, 10, 10, 10)
                              << QRegion(10, 10, 10, 5)
                              << QRegion(10, 15, 10, 5);

    const QRegion rgnA(0, 0, 100, 100);
    const QRegion rgnB(0, 0, 10, 10);

    QTest::newRow("simple 6") << rgnA
                              << rgnA - rgnB
                              << rgnB;

    QTest::newRow("simple 7") << rgnB
                              << rgnA
                              << rgnA - rgnB;
}
Exemplo n.º 25
0
void MetaModelPayload::setBlendedVertices(int blendNumber, const QVector<BlendshapeOffset>& blendshapeOffsets, const QVector<int>& blendedMeshSizes, const render::ItemIDs& subRenderItems) {
    PROFILE_RANGE(render, __FUNCTION__);
    if (blendNumber < _appliedBlendNumber) {
        return;
    }
    _appliedBlendNumber = blendNumber;

    // We have fewer meshes than before.  Invalidate everything
    if (blendedMeshSizes.length() < (int)_blendshapeBuffers.size()) {
        _blendshapeBuffers.clear();
    }

    int index = 0;
    for (int i = 0; i < blendedMeshSizes.size(); i++) {
        int numVertices = blendedMeshSizes.at(i);

        // This mesh isn't blendshaped
        if (numVertices == 0) {
            _blendshapeBuffers.erase(i);
            continue;
        }

        const auto& buffer = _blendshapeBuffers.find(i);
        const auto blendShapeBufferSize = numVertices * sizeof(BlendshapeOffset);
        if (buffer == _blendshapeBuffers.end()) {
            _blendshapeBuffers[i] = std::make_shared<gpu::Buffer>(blendShapeBufferSize, (gpu::Byte*) blendshapeOffsets.constData() + index * sizeof(BlendshapeOffset), blendShapeBufferSize);
        } else {
            buffer->second->setData(blendShapeBufferSize, (gpu::Byte*) blendshapeOffsets.constData() + index * sizeof(BlendshapeOffset));
        }

        index += numVertices;
    }

    render::Transaction transaction;
    for (auto& id : subRenderItems) {
        transaction.updateItem<ModelMeshPartPayload>(id, [this, blendedMeshSizes](ModelMeshPartPayload& data) {
            data.setBlendshapeBuffer(_blendshapeBuffers, blendedMeshSizes);
        });
    }
    AbstractViewStateInterface::instance()->getMain3DScene()->enqueueTransaction(transaction);
}
Exemplo n.º 26
0
Cube::Cube(const QGLContext *context) :
    GLShape(context)
{
    if (!vbo.create() || !vbo.bind())
        qDebug() << "VBO error";

    QVector<QVector3D> vertices;
    for (int i = 0; i < 8; ++i)
        vertices << QVector3D((i & 1) ? -1.0 : 1.0,
                              (i & 2) ? -1.0 : 1.0,
                              (i & 4) ? -1.0 : 1.0);
    /*
      front (z = 1)
        1     0

        3     2

      back (z = -1)
        5     4

        7     6

      */

    vbo.allocate(vertices.constData(), vertices.size() * sizeof (GLfloat) * 3);
    vbo.release();

    if (!ibo.create() || !ibo.bind())
        qDebug() << "IBO error";

    const GLubyte indices[] = {
        3, 2, 0, 1,
        2, 6, 4, 0,
        6, 7, 5, 4,
        5, 7, 3, 1,
        1, 0, 4, 5,
        2, 3, 7, 6
    };
    ibo.allocate(indices, 4 * 6 * sizeof (GLubyte));
    ibo.release();
}
Exemplo n.º 27
0
bool OsmAnd::Frustum2D31::test(const QVector<PointI>& path) const
{
    if (path.isEmpty())
        return false;

    const auto pathSize = path.size();
    if (pathSize == 1)
        return test(path.first());
    if (pathSize == 2)
        return test(path.first(), path.last());

    auto pPoint = path.constData();
    auto pPrevPoint = pPoint++;
    for (auto idx = 1; idx < pathSize; idx++)
    {
        if (test(*(pPrevPoint++), *(pPoint++)))
            return true;
    }

    return false;
}
Exemplo n.º 28
0
void updateSubImage(GLuint texture, const QImage &image, const QRect &rect, bool mipmaps)
{
    mipmaps = mipmaps && canUseMipmaps(image.size());

    QVector<uchar> data;
    for (int i = rect.y(); i <= rect.bottom(); ++i) {
        QRgb *p = (QRgb *)image.scanLine(i);
        for (int j = rect.x(); j <= rect.right(); ++j) {
            data << qRed(p[j]);
            data << qGreen(p[j]);
            data << qBlue(p[j]);
            data << qAlpha(p[j]);
        }
    }

    glBindTexture(GL_TEXTURE_2D, texture);
    glTexSubImage2D(GL_TEXTURE_2D,  0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA,
                    GL_UNSIGNED_BYTE, data.constData());

    if (mipmaps)
        QOpenGLFunctions(QOpenGLContext::currentContext()).glGenerateMipmap(GL_TEXTURE_2D);
}
Exemplo n.º 29
0
QPainterPath QwtSpline::pathP( const QPolygonF &points ) const
{
    const int n = points.size();

    QPainterPath path;
    if ( n == 0 )
        return path;

    if ( n == 1 )
    {
        path.moveTo( points[0] );
        return path;
    }

    if ( n == 2 )
    {
        path.addPolygon( points );
        return path;
    }

    const QVector<QLineF> controlPoints = bezierControlPointsP( points );
    if ( controlPoints.size() < n - 1 )
        return path;

    const QPointF *p = points.constData();
    const QLineF *l = controlPoints.constData();

    path.moveTo( p[0] );
    for ( int i = 0; i < n - 1; i++ )
        path.cubicTo( l[i].p1(), l[i].p2(), p[i+1] );

    if ( controlPoints.size() >= n )
    {
        path.cubicTo( l[n-1].p1(), l[n-1].p2(), p[0] );
        path.closeSubpath();
    }

    return path;
}
Exemplo n.º 30
0
    /** Load the state from an array - the array must have size
        MTRand::N + 1 (625)

        \throw SireError::incompatible_error
    */
    void loadState(const QVector<quint32> &state)
    {
        int state_size = MTRand::N + 1;
    
        //check that the array is of the right size...
        if (state.count() != state_size)
            throw SireError::incompatible_error( QObject::tr(
                "Can only restore the state from an array of size %1, "
                "while you have provided an array of size %2.")
                    .arg(state_size).arg(state.count()), CODELOC );

        //convert the array to the right type...
        boost::scoped_array<MTUInt32> array( new MTUInt32[state_size] );

        const quint32 *state_array = state.constData();

        for (int i=0; i<state_size; ++i)
            array[i] = state_array[i];

        QMutexLocker lkr(&mutex);

        mersenne_generator.load(array.get());
    }