Browse Source

qt: add property `isValid` to `TextureProviderObserver`

This is to see if the source texture provider actually
provides a texture, and especially useful if it is
important to know when the texture would be available.

One particular use case for this is with static effects,
such that it makes it possible to apply the effect once
the source provider starts providing the texture.

`Image` as texture provider has `Image.Ready` status,
but it seems that it is not really the best reflection
for whether the texture is ready or not. My understanding
is that it is rather for when the image is loaded, and
not necessarily the texture.
pull/188/head
Fatih Uzunoglu 7 months ago
committed by Steve Lhomme
parent
commit
aa2b1ec673
  1. 14
      modules/gui/qt/util/textureproviderobserver.cpp
  2. 4
      modules/gui/qt/util/textureproviderobserver.hpp

14
modules/gui/qt/util/textureproviderobserver.cpp

@ -125,6 +125,14 @@ bool TextureProviderObserver::isAtlasTexture() const
return m_isAtlasTexture.load(std::memory_order_acquire);
}
bool TextureProviderObserver::isValid() const
{
// This is likely called in the QML/GUI thread.
// QML/GUI thread can freely block the rendering thread to the extent the time is reasonable and a
// fraction of `1/FPS`, because it is already throttled by v-sync (so it would just throttle less).
return m_isValid.load(std::memory_order_acquire);
}
void TextureProviderObserver::updateProperties()
{
// This is likely called in the rendering thread.
@ -191,6 +199,9 @@ void TextureProviderObserver::updateProperties()
emit isAtlasTextureChanged(isAtlasTexture);
}
if (!m_isValid.exchange(true, memoryOrder))
emit isValidChanged(true);
return;
}
}
@ -205,4 +216,7 @@ void TextureProviderObserver::updateProperties()
if (m_isAtlasTexture.exchange(false, memoryOrder))
emit isAtlasTextureChanged(false);
if (m_isValid.exchange(false, memoryOrder))
emit isValidChanged(false);
}

4
modules/gui/qt/util/textureproviderobserver.hpp

@ -61,6 +61,7 @@ class TextureProviderObserver : public QObject
Q_PROPERTY(bool hasAlphaChannel READ hasAlphaChannel NOTIFY hasAlphaChannelChanged FINAL)
Q_PROPERTY(bool hasMipmaps READ hasMipmaps NOTIFY hasMipmapsChanged FINAL)
Q_PROPERTY(bool isAtlasTexture READ isAtlasTexture NOTIFY isAtlasTextureChanged FINAL)
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL) // whether a texture is provided or not
public:
explicit TextureProviderObserver(QObject *parent = nullptr);
@ -71,12 +72,14 @@ public:
bool hasAlphaChannel() const;
bool hasMipmaps() const;
bool isAtlasTexture() const;
bool isValid() const;
signals:
void sourceChanged();
void hasAlphaChannelChanged(bool);
void hasMipmapsChanged(bool);
void isAtlasTextureChanged(bool);
void isValidChanged(bool);
private slots:
void updateProperties();
@ -100,6 +103,7 @@ private:
std::atomic<bool> m_hasAlphaChannel = false;
std::atomic<bool> m_hasMipmaps = false;
std::atomic<bool> m_isAtlasTexture = false;
std::atomic<bool> m_isValid = false;
};
#endif // TEXTUREPROVIDEROBSERVER_HPP

Loading…
Cancel
Save