Move loading of Cube textures into thread
Cube effect loads 0 to 2 textures which has been performed during configuration. This change delays loading the textures till cube is activated for the first time and the loading from file is moved into a thread. This means that for a very short time the texture is not yet visible, but this is not a problem as the cube animates from fully opaque starting state. So during the loading the texture would not be visible anyway. REVIEW: 104807icc-effect-5.14.5
parent
a569b5c785
commit
8489ede9aa
|
@ -33,7 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QColor>
|
||||
#include <QRect>
|
||||
#include <QEvent>
|
||||
#include <QFutureWatcher>
|
||||
#include <QKeyEvent>
|
||||
#include <QtConcurrentRun>
|
||||
#include <QVector2D>
|
||||
|
||||
#include <math.h>
|
||||
|
@ -177,31 +179,11 @@ void CubeEffect::loadConfig(QString config)
|
|||
invertMouse = conf.readEntry("InvertMouse", false);
|
||||
capDeformationFactor = conf.readEntry("CapDeformation", 0) / 100.0f;
|
||||
useZOrdering = conf.readEntry("ZOrdering", false);
|
||||
QString file = conf.readEntry("Wallpaper", QString(""));
|
||||
if (wallpaper)
|
||||
wallpaper->discard();
|
||||
delete wallpaper;
|
||||
wallpaper = NULL;
|
||||
if (!file.isEmpty()) {
|
||||
QImage img = QImage(file);
|
||||
if (!img.isNull()) {
|
||||
wallpaper = new GLTexture(img);
|
||||
}
|
||||
}
|
||||
delete capTexture;
|
||||
capTexture = NULL;
|
||||
texturedCaps = conf.readEntry("TexturedCaps", true);
|
||||
if (texturedCaps) {
|
||||
QString capPath = conf.readEntry("CapPath", KGlobal::dirs()->findResource("appdata", "cubecap.png"));
|
||||
QImage img = QImage(capPath);
|
||||
if (!img.isNull()) {
|
||||
capTexture = new GLTexture(img);
|
||||
capTexture->setFilter(GL_LINEAR);
|
||||
#ifndef KWIN_HAVE_OPENGLES
|
||||
capTexture->setWrapMode(GL_CLAMP_TO_BORDER);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
timeLine.setCurveShape(QTimeLine::EaseInOutCurve);
|
||||
timeLine.setDuration(rotationDuration);
|
||||
|
@ -262,6 +244,56 @@ CubeEffect::~CubeEffect()
|
|||
delete m_cubeCapBuffer;
|
||||
}
|
||||
|
||||
QImage CubeEffect::loadCubeCap(const QString &capPath)
|
||||
{
|
||||
if (!texturedCaps) {
|
||||
return QImage();
|
||||
}
|
||||
return QImage(capPath);
|
||||
}
|
||||
|
||||
void CubeEffect::slotCubeCapLoaded()
|
||||
{
|
||||
QFutureWatcher<QImage> *watcher = dynamic_cast<QFutureWatcher<QImage>*>(sender());
|
||||
if (!watcher) {
|
||||
// not invoked from future watcher
|
||||
return;
|
||||
}
|
||||
QImage img = watcher->result();
|
||||
if (!img.isNull()) {
|
||||
capTexture = new GLTexture(img);
|
||||
capTexture->setFilter(GL_LINEAR);
|
||||
#ifndef KWIN_HAVE_OPENGLES
|
||||
capTexture->setWrapMode(GL_CLAMP_TO_BORDER);
|
||||
#endif
|
||||
// need to recreate the VBO for the cube cap
|
||||
delete m_cubeCapBuffer;
|
||||
m_cubeCapBuffer = NULL;
|
||||
effects->addRepaintFull();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
}
|
||||
|
||||
QImage CubeEffect::loadWallPaper(const QString &file)
|
||||
{
|
||||
return QImage(file);
|
||||
}
|
||||
|
||||
void CubeEffect::slotWallPaperLoaded()
|
||||
{
|
||||
QFutureWatcher<QImage> *watcher = dynamic_cast<QFutureWatcher<QImage>*>(sender());
|
||||
if (!watcher) {
|
||||
// not invoked from future watcher
|
||||
return;
|
||||
}
|
||||
QImage img = watcher->result();
|
||||
if (!img.isNull()) {
|
||||
wallpaper = new GLTexture(img);
|
||||
effects->addRepaintFull();
|
||||
}
|
||||
watcher->deleteLater();
|
||||
}
|
||||
|
||||
bool CubeEffect::loadShader()
|
||||
{
|
||||
if (!(GLPlatform::instance()->supports(GLSL) &&
|
||||
|
@ -1865,6 +1897,19 @@ void CubeEffect::setActive(bool active)
|
|||
inside->setActive(true);
|
||||
}
|
||||
if (active) {
|
||||
KConfigGroup conf = effects->effectConfig("Cube");
|
||||
QString capPath = conf.readEntry("CapPath", KGlobal::dirs()->findResource("appdata", "cubecap.png"));
|
||||
if (texturedCaps && !capTexture && !capPath.isEmpty()) {
|
||||
QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>(this);
|
||||
connect(watcher, SIGNAL(finished()), SLOT(slotCubeCapLoaded()));
|
||||
watcher->setFuture(QtConcurrent::run(this, &CubeEffect::loadCubeCap, capPath));
|
||||
}
|
||||
QString wallpaperPath = conf.readEntry("Wallpaper", QString(""));
|
||||
if (!wallpaper && !wallpaperPath.isEmpty()) {
|
||||
QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>(this);
|
||||
connect(watcher, SIGNAL(finished()), SLOT(slotWallPaperLoaded()));
|
||||
watcher->setFuture(QtConcurrent::run(this, &CubeEffect::loadWallPaper, wallpaperPath));
|
||||
}
|
||||
if (!mousePolling) {
|
||||
effects->startMousePolling();
|
||||
mousePolling = true;
|
||||
|
|
|
@ -72,6 +72,8 @@ private slots:
|
|||
void slotTabBoxClosed();
|
||||
void slotMouseChanged(const QPoint& pos, const QPoint& oldpos, Qt::MouseButtons buttons,
|
||||
Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
|
||||
void slotCubeCapLoaded();
|
||||
void slotWallPaperLoaded();
|
||||
private:
|
||||
enum RotationDirection {
|
||||
Left,
|
||||
|
@ -100,6 +102,8 @@ private:
|
|||
void rotateCube();
|
||||
void rotateToDesktop(int desktop);
|
||||
void setActive(bool active);
|
||||
QImage loadCubeCap(const QString &capPath);
|
||||
QImage loadWallPaper(const QString &file);
|
||||
bool activated;
|
||||
bool mousePolling;
|
||||
bool cube_painting;
|
||||
|
|
Loading…
Reference in New Issue