Esempio n. 1
0
QSGNode *FilteredImage::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
    QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode*>(oldNode);
    QImage *image = !m_filteredImage.isNull() ? &m_filteredImage : &m_image;

    if(image->isNull())
    {
        delete node;
        return 0;
    }

    if (!node)
    {
        node = new QSGSimpleTextureNode();
    }

    if (m_imageChanged || !node->texture())
    {
        m_imageChanged = false;
        delete node->texture();

        node->setTexture(window()->createTextureFromImage(*image));

        node->setRect(0,0,implicitWidth(),implicitHeight());

        node->markDirty(QSGNode::DirtyMaterial | QSGNode::DirtyGeometry);
    }

    return node;
}
Esempio n. 2
0
QSGNode *ServerBufferItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
    updateTexture();
    QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode);

    if (!node) {
        node = new QSGSimpleTextureNode();
    }

    node->setTexture(m_provider->texture());

    if (isYInverted()) {
        node->setRect(0, height(), width(), -height());
    } else {
        node->setRect(0, 0, width(), height());
    }

    return node;
}
Esempio n. 3
0
QSGNode *VideoDisplay::updatePaintNode(QSGNode *oldNode,
                                       QQuickItem::UpdatePaintNodeData *updatePaintNodeData)
{
    Q_UNUSED(updatePaintNodeData)

    this->m_mutex.lock();
    this->m_videoFrame = this->m_packet;
    this->m_mutex.unlock();

    if (this->m_videoFrame.textureSize().isEmpty()) {
        if (oldNode)
            delete oldNode;

        return NULL;
    }

    QSGSimpleTextureNode *node = NULL;

    if (oldNode)
        node = dynamic_cast<QSGSimpleTextureNode *>(oldNode);
    else
        node = new QSGSimpleTextureNode();

    if (this->m_fillDisplay)
        node->setRect(this->boundingRect());
    else {
        QSizeF size(this->m_videoFrame.textureSize());
        size.scale(this->boundingRect().size(), Qt::KeepAspectRatio);
        QRectF rect(QPointF(), size);
        rect.moveCenter(this->boundingRect().center());

        node->setRect(rect);
    }

    node->setTexture(&this->m_videoFrame);

    return node;
}
static PyObject *meth_QSGSimpleTextureNode_setRect(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        const QRectF* a0;
        QSGSimpleTextureNode *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ9", &sipSelf, sipType_QSGSimpleTextureNode, &sipCpp, sipType_QRectF, &a0))
        {
            sipCpp->setRect(*a0);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    {
        qreal a0;
        qreal a1;
        qreal a2;
        qreal a3;
        QSGSimpleTextureNode *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "Bdddd", &sipSelf, sipType_QSGSimpleTextureNode, &sipCpp, &a0, &a1, &a2, &a3))
        {
            sipCpp->setRect(a0,a1,a2,a3);

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QSGSimpleTextureNode, sipName_setRect, doc_QSGSimpleTextureNode_setRect);

    return NULL;
}
QSGNode *CustomItem::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *updateData)
{
    Q_UNUSED(updateData);

    QSGSimpleTextureNode *textureNode = static_cast<QSGSimpleTextureNode *>(node);
    if (!textureNode) {
        textureNode = new QSGSimpleTextureNode();
        QImage image(":/images/lady.png");
        m_texture = window()->createTextureFromImage(image);
        textureNode->setTexture(m_texture);}
        textureNode->setRect(0, 0, width(), height());
        textureNode->setFiltering(QSGTexture::Linear);

    return textureNode;

}
Esempio n. 6
0
QSGNode* Texture::updateNode(QSGNode* node, QQuickItem* item, QPoint region)
{
	QSGSimpleTextureNode* n;

	// First update
	if (!node) {
		n = new QSGSimpleTextureNode;
		n->setRect(item->boundingRect());
	} else {
		n = static_cast<QSGSimpleTextureNode*>(node);
	}

	// Update the texture
	n->setTexture(
			// Ask the cache for the texture
			m_cacheIterator.value().get(item->window(),
			// Add the offset to the x axis
			{region.x() + 3*static_cast<int>(offset()), region.y()}) );
	return n;
}
Esempio n. 7
0
QSGNode *EmulatorItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
{
	QSGSimpleTextureNode *n = static_cast<QSGSimpleTextureNode *>(oldNode);
	if (!n) {
		m_gl = window()->openglContext()->functions();
		connect(window(), SIGNAL(frameFinished()), this, SLOT(onFrameFinished()));
		n = new QSGSimpleTextureNode();
		QImage img(GFX_WIDTH, GFX_HEIGHT, QImage::Format_RGBA8888);
		m_screen = new GLuint[GFX_WIDTH * GFX_HEIGHT];
		img.fill(Qt::green);
		m_texture = window()->createTextureFromImage(img);
		m_texture->setFiltering(QSGTexture::Linear);
		n->setTexture(m_texture);
		n->setRect(boundingRect());
	}

	m_texture->bind();
	m_gl->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GFX_WIDTH - 16, GFX_HEIGHT - 32, 0, GL_RGB, GL_UNSIGNED_BYTE, m_screen);

	return n;
}
Esempio n. 8
0
QSGNode *Renderer::paintNode(const QRectF& viewport) const {
  if (m_tiles.isEmpty()) {
    return 0;
  }

  QSGNode *parentNode = new QSGNode;

  for (const Tile& tile : m_tiles) {
    if (tile.visible) {
      QRectF rect = m_view->tileRect(tile);
      QSGSimpleTextureNode *node = new SimpleTextureNode;
      node->setFlag(QSGNode::OwnedByParent, true);
      node->setTexture(m_view->window()->createTextureFromImage(tile.image));
      node->setRect(rect);
      node->setFiltering(QSGTexture::Nearest);
      //      node->setOwnsTexture(true); // TODO: Qt 5.4

      qreal dx1 = rect.left() < viewport.left() ? viewport.left() - rect.left() : 0.0f;
      qreal dy1 = 0.0f;
      qreal dx2 = rect.right() > viewport.right() ? viewport.right() - rect.right() : 0.0f;
      qreal dy2 = rect.bottom() > viewport.bottom() ? viewport.bottom() - rect.bottom() : 0.0f;

      if (dx1 != 0.0f || dx2 != 0.0f || dy2 != 0.0f) {
	QSGClipNode *clip = new QSGClipNode;
	clip->setIsRectangular(true);
	clip->setClipRect(rect.adjusted(dx1, dy1, dx2, dy2));
	parentNode->appendChildNode(clip);
	clip->appendChildNode(node);
	//	qDebug() << "Clipping";
      } else {
	parentNode->appendChildNode(node);
      }
    }
  }

  return parentNode;
}
Esempio n. 9
0
QSGNode* QuickSubtitleItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data)
{
    Q_UNUSED(data);
    if (m_w_sub == 0 || m_h_sub == 0) {
        return node;
    }
    QSGSimpleTextureNode *stn = static_cast<QSGSimpleTextureNode*>(node);
    if (!node) {
        node = new QSGSimpleTextureNode();
        stn = static_cast<QSGSimpleTextureNode*>(node);
        stn->setFiltering(QSGTexture::Linear);
    }
    stn->setRect(mapSubRect(m_rect, m_w_sub, m_h_sub));
    if (m_texture)
        delete m_texture;
    {
        QMutexLocker lock(&m_mutex);
        Q_UNUSED(lock);
        m_texture = window()->createTextureFromImage(m_image);
    }
    stn->setTexture(m_texture);
    node->markDirty(QSGNode::DirtyGeometry);
    return node;
}
QSGNode* ARCameraQml::updatePaintNode(QSGNode* node, UpdatePaintNodeData* )
{
    using namespace QScrollEngine;
    _context->lock();
    QSGSimpleTextureNode* textureNode = dynamic_cast<QSGSimpleTextureNode*>(node);
    if (_context->openGLContext() != QOpenGLContext::currentContext()) {
        _clearFBOs();
        _context->setOpenGLContext(QOpenGLContext::currentContext());
        _context->setPostEffectUsed(false);
        _context->setEnableClearing(false);
        _surface.setQScrollEngineContext(_context);
        _arSystem.setContext(_context);
        if (textureNode == nullptr)
            textureNode = new QSGSimpleTextureNode();
        _context->unlock();
        _initialize(textureNode);
        _context->lock();
    } else if (textureNode == nullptr) {
        _context->unlock();
        textureNode = new QSGSimpleTextureNode();
        _initialize(textureNode);
        _context->lock();
    }
    GLint defaultFBO = 0;
    _context->glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
    AR::FrameProvider* frameProvider = _surface.frameProvider();
    if (frameProvider) {
        AR::IPoint resolution = frameProvider->originalTextureSize();
        if ((resolution != _currentResolution) || (_currentBoundingRect != boundingRect())) {
            _context->unlock();
            _initialize(textureNode);
            _context->lock();
        }
    }
    textureNode->markDirty(QSGNode::DirtyForceUpdate);
    _updateActions();
    if (_scene == nullptr) {
        _context->unlock();
        emit needToScene();
        return textureNode;
    }
    if (_arSystem.reconstructor3D()->isRunning()) {
        _context->unlock();
        _context->glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
        textureNode->setRect(_currentTextureRect);
        qDebug() << "Thread is running.";
        return textureNode;
    }
    _scene->setFrameProvider(nullptr);
    _scene->beginUpdate();
    _context->glEnable(GL_CULL_FACE);
    _context->glFrontFace(GL_CW);
    if (!_surface.isActive()) {
        _surface.scheduleOpenGLContextUpdate();
        QObject* glThreadCallback = (_surface.property("_q_GLThreadCallback")).value<QObject*>();
        if (glThreadCallback) {
            QEvent event(QEvent::User);
            glThreadCallback->event(&event);
        }
        if (!_context->postEffectUsed())
            _FBOs[0]->bind();
        _context->beginPaint();
    } else {
        bool frameAvailable = _surface.isFrameAvailable();
        _surface.provideFrame();
        if (frameProvider) {
            _scene->setFrameProvider(frameProvider);
            frameProvider->setUsedTransform(false);
            if (frameAvailable) {
                QTime timer;
                timer.start();
                _arSystem.tracking(frameProvider, _context, _FBOs[1], _FBOs[2]);
                int time = timer.elapsed();
                _textStatus = QString::number(frameProvider->timeProvideLuminanceFrame()) + "/" + QString::number(time);
                QMatrix4x4 matrix = _arSystem.matrixWorld();
                QQuaternion orientation;
                QOtherMathFunctions::matrixToQuaternion(matrix, orientation);
                QVector3D position(matrix(0, 3), matrix(1, 3), matrix(2, 3));
                _scene->position = position;
                _scene->orientation = orientation;
                emit textStatusChanged();
            }
            frameProvider->setUsedTransform(true);
            if (!_context->postEffectUsed())
                _FBOs[0]->bind();
            _context->beginPaint();
            _context->glDisable(GL_DEPTH_TEST);
            _context->glDepthMask(GL_FALSE);
            _context->glViewport(0, 0, _currentResolution.x, _currentResolution.y);
            frameProvider->bindColorShader(_context);
            _context->glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
            using namespace TMath;
            QMatrix2x2 transform;
            if (_mirrored) {
                QMatrix2x2 frameTransform = frameProvider->matrixTexture();
                transform(0, 0) = frameTransform(0, 0);
                transform(0, 1) = - frameTransform(0, 1);
                transform(1, 0) = - frameTransform(1, 0);
                transform(1, 1) = frameTransform(1, 1);
            } else {
                transform = frameProvider->matrixTexture();
            }
            _arSystem.drawResultOnGL(_context, transform);
        } else {
            if (!_context->postEffectUsed())
                _FBOs[0]->bind();
            _context->beginPaint();
        }
    }
    _context->unlock();
    _scene->endUpdate();
    State currentState = State(_arSystem.state());
    if (currentState != _currentState) {
        _currentState = currentState;
        emit arCameraStateChanged();
    }
    if ((currentState == TrackingNow) || (currentState == Reconstruction3D))
        _context->drawScenes();
    _context->endPaint(_FBOs[0]->handle());
    _context->glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
    textureNode->setRect(_currentTextureRect);
    return textureNode;
}
Esempio n. 11
0
QSGNode* HsQMLCanvas::updatePaintNode(
    QSGNode* oldNode, UpdatePaintNodeData* paintData)
{
    // Window always needs repainting
    mWindow->update();

    // Lazily create new callbacks
    if (!mGLCallbacks) {
        mGLCallbacks = mDelegate.value<HsQMLGLDelegate>().makeCallbacks();
        mLoadModel = true;
        mValidModel = false;

        // Display nothing without a valid delegate
        if (!mGLCallbacks) {
            setStatus(BadDelegate);
            delete oldNode;
            return NULL;
        }
    }

    // Process model update
    if (mLoadModel) {
        mValidModel = mGLCallbacks->mSyncCb(
            reinterpret_cast<HsQMLJValHandle*>(&mModel));
        mLoadModel = false;
    }

    // Display nothing if there's no valid model
    if (!mValidModel) {
        setStatus(BadModel);
        detachBackEnd();
        delete oldNode;
        return NULL;
    }

    // Create back-end on the rendering thread
    if (!mBackEnd) {
        mBackEnd = new HsQMLCanvasBackEnd(mWindow, mGLCallbacks, mDisplayMode);

        // Monitor back-end's status
        QObject::connect(
            mBackEnd, SIGNAL(statusChanged(HsQMLCanvas::Status)),
            this, SLOT(doBackEndStatusChanged(HsQMLCanvas::Status)));
        setStatus(mBackEnd->status(), true);
    }
    setStatus(Okay);

    // Save pointer to transform node
    mBackEnd->setTransformNode(
        Inline != mDisplayMode ? paintData->transformNode : NULL,
        width(), height());

    // Produce texture node if needed
    if (QSGTexture* texture =
            mBackEnd->updateFBO(mCanvasWidth, mCanvasHeight)) {
        QSGSimpleTextureNode* n = static_cast<QSGSimpleTextureNode*>(oldNode);
        if (!n) {
            n = new QSGSimpleTextureNode();
        }
        n->setTexture(texture);
        n->setRect(0, 0, width(), height());
        return n;
    }

    delete oldNode;
    return NULL;
}