Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replaced grab() with scheduleUpdate().
Replaced the synchronous function grab() with an asynchronous
function scheduleUpdate() in QShaderEffectSource because
synchronous grabbing doesn't work with threaded rendering.
  • Loading branch information
Kim Motoyoshi Kalland committed May 10, 2011
1 parent 79f6db4 commit 67d5026
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
38 changes: 24 additions & 14 deletions src/declarative/items/qsgshadereffectsource.cpp
Expand Up @@ -82,6 +82,7 @@ QSGShaderEffectTexture::QSGShaderEffectTexture(QSGItem *shaderSource)
, m_dirtyTexture(true)
, m_multisamplingSupportChecked(false)
, m_multisampling(false)
, m_grab(false)
{
}

Expand Down Expand Up @@ -124,8 +125,9 @@ void QSGShaderEffectTexture::bind()

bool QSGShaderEffectTexture::updateTexture()
{
if (m_dirtyTexture) {
if ((m_live || m_grab) && m_dirtyTexture) {
grab();
m_grab = false;
return true;
}
return false;
Expand Down Expand Up @@ -181,17 +183,25 @@ void QSGShaderEffectTexture::setLive(bool live)
markDirtyTexture();
}

void QSGShaderEffectTexture::scheduleUpdate()
{
if (m_grab)
return;
m_grab = true;
if (m_dirtyTexture)
emit textureChanged();
}

void QSGShaderEffectTexture::setRecursive(bool recursive)
{
m_recursive = recursive;
}

void QSGShaderEffectTexture::markDirtyTexture()
{
if (m_live) {
m_dirtyTexture = true;
m_dirtyTexture = true;
if (m_live || m_grab)
emit textureChanged();
}
}

void QSGShaderEffectTexture::grab()
Expand Down Expand Up @@ -360,6 +370,7 @@ QSGShaderEffectSource::QSGShaderEffectSource(QSGItem *parent)
, m_hideSource(false)
, m_mipmap(false)
, m_recursive(false)
, m_grab(true)
{
setFlag(ItemHasContents);
m_texture = new QSGShaderEffectTexture(this);
Expand Down Expand Up @@ -516,17 +527,12 @@ void QSGShaderEffectSource::setRecursive(bool enabled)
emit recursiveChanged();
}

void QSGShaderEffectSource::grab()
void QSGShaderEffectSource::scheduleUpdate()
{
if (!m_sourceItem)
if (m_grab)
return;
QSGCanvas *canvas = m_sourceItem->canvas();
if (!canvas)
return;
QSGCanvasPrivate::get(canvas)->updateDirtyNodes();
QGLContext *glctx = const_cast<QGLContext *>(canvas->context());
glctx->makeCurrent();
qobject_cast<QSGShaderEffectTexture *>(m_texture)->grab();
m_grab = true;
update();
}

static void get_wrap_mode(QSGShaderEffectSource::WrapMode mode, QSGTexture::WrapMode *hWrap, QSGTexture::WrapMode *vWrap)
Expand Down Expand Up @@ -582,6 +588,7 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod

QSGShaderEffectTexture *tex = qobject_cast<QSGShaderEffectTexture *>(m_texture);

tex->setLive(m_live);
tex->setItem(QSGItemPrivate::get(m_sourceItem)->itemNode());
QRectF sourceRect = m_sourceRect.isNull()
? QRectF(0, 0, m_sourceItem->width(), m_sourceItem->height())
Expand All @@ -591,11 +598,14 @@ QSGNode *QSGShaderEffectSource::updatePaintNode(QSGNode *oldNode, UpdatePaintNod
? QSize(qCeil(qAbs(sourceRect.width())), qCeil(qAbs(sourceRect.height())))
: m_textureSize;
tex->setSize(textureSize);
tex->setLive(m_live);
tex->setRecursive(m_recursive);
tex->setFormat(GLenum(m_format));
tex->setHasMipmaps(m_mipmap);

if (m_grab)
tex->scheduleUpdate();
m_grab = false;

QSGTexture::Filtering filtering = QSGItemPrivate::get(this)->smooth
? QSGTexture::Linear
: QSGTexture::Nearest;
Expand Down
8 changes: 6 additions & 2 deletions src/declarative/items/qsgshadereffectsource_p.h
Expand Up @@ -112,7 +112,7 @@ class QSGShaderEffectTexture : public QSGDynamicTexture
bool recursive() const { return bool(m_recursive); }
void setRecursive(bool recursive);

void grab();
void scheduleUpdate();

Q_SIGNALS:
void textureChanged();
Expand All @@ -121,6 +121,8 @@ public Q_SLOTS:
void markDirtyTexture();

private:
void grab();

QSGNode *m_item;
QRectF m_rect;
QSize m_size;
Expand All @@ -141,6 +143,7 @@ public Q_SLOTS:
uint m_dirtyTexture : 1;
uint m_multisamplingSupportChecked : 1;
uint m_multisampling : 1;
uint m_grab : 1;
};

class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider
Expand Down Expand Up @@ -204,7 +207,7 @@ class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider
QSGTexture *texture() const;
const char *textureChangedSignal() const { return SIGNAL(textureChanged()); }

Q_INVOKABLE void grab();
Q_INVOKABLE void scheduleUpdate();

Q_SIGNALS:
void wrapModeChanged();
Expand Down Expand Up @@ -233,6 +236,7 @@ class QSGShaderEffectSource : public QSGItem, public QSGTextureProvider
uint m_hideSource : 1;
uint m_mipmap : 1;
uint m_recursive : 1;
uint m_grab : 1;
};

QT_END_NAMESPACE
Expand Down

0 comments on commit 67d5026

Please sign in to comment.