From 5d29307f58ca30dca5f66ff9b71819ea60f7e7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Tue, 15 Feb 2011 18:10:54 +0100 Subject: [PATCH] kwin: Refactor the window transformation code Move the code that computes the transformation matrix into its own method, and rewrite it to improve readability. --- scene_opengl.cpp | 79 +++++++++++++++++++++++++----------------------- scene_opengl.h | 2 ++ 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 92a6c2ead6..6e38adf00f 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -417,6 +417,38 @@ void SceneOpenGL::Window::pixmapDiscarded() texture.release(); } +QMatrix4x4 SceneOpenGL::Window::transformation(int mask, const WindowPaintData &data) const +{ + QMatrix4x4 matrix; + matrix.translate(x(), y()); + + if (!(mask & PAINT_WINDOW_TRANSFORMED)) + return matrix; + + matrix.translate(data.xTranslate, data.yTranslate, data.zTranslate); + matrix.scale(data.xScale, data.yScale, data.zScale); + + if (!data.rotation) + return matrix; + + // Apply the rotation + const qreal xAxis = (data.rotation->axis == RotationData::XAxis ? 1.0 : 0.0); + const qreal yAxis = (data.rotation->axis == RotationData::YAxis ? 1.0 : 0.0); + const qreal zAxis = (data.rotation->axis == RotationData::ZAxis ? 1.0 : 0.0); + + matrix.translate(data.rotation->xRotationPoint, + data.rotation->yRotationPoint, + data.rotation->zRotationPoint); + + matrix.rotate(data.rotation->angle, xAxis, yAxis, zAxis); + + matrix.translate(-data.rotation->xRotationPoint, + -data.rotation->yRotationPoint, + -data.rotation->zRotationPoint); + + return matrix; +} + // paint the window void SceneOpenGL::Window::performPaint(int mask, QRegion region, WindowPaintData data) { @@ -448,11 +480,6 @@ void SceneOpenGL::Window::performPaint(int mask, QRegion region, WindowPaintData texture.setFilter(filter == ImageFilterGood ? GL_LINEAR : GL_NEAREST); - // do required transformations - int x = toplevel->x(); - int y = toplevel->y(); - double z = 0.0; - bool sceneShader = false; if (!data.shader && ShaderManager::instance()->isValid()) { @@ -461,43 +488,19 @@ void SceneOpenGL::Window::performPaint(int mask, QRegion region, WindowPaintData data.shader = ShaderManager::instance()->pushShader(ShaderManager::GenericShader); } else { data.shader = ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); - data.shader->setUniform(GLShader::Offset, QVector2D(x, y)); + data.shader->setUniform(GLShader::Offset, QVector2D(x(), y())); } sceneShader = true; } - QMatrix4x4 windowTransformation; - windowTransformation.translate(x, y); - if ((mask & PAINT_WINDOW_TRANSFORMED) || (mask & PAINT_SCREEN_TRANSFORMED)) { - windowTransformation.translate(data.xTranslate, data.yTranslate, data.zTranslate); - if ((mask & PAINT_WINDOW_TRANSFORMED) && (data.xScale != 1 || data.yScale != 1 || data.zScale != 1)) { - windowTransformation.scale(data.xScale, data.yScale, data.zScale); - } - if ((mask & PAINT_WINDOW_TRANSFORMED) && data.rotation) { - windowTransformation.translate(data.rotation->xRotationPoint, data.rotation->yRotationPoint, data.rotation->zRotationPoint); - qreal xAxis = 0.0; - qreal yAxis = 0.0; - qreal zAxis = 0.0; - switch(data.rotation->axis) { - case RotationData::XAxis: - xAxis = 1.0; - break; - case RotationData::YAxis: - yAxis = 1.0; - break; - case RotationData::ZAxis: - zAxis = 1.0; - break; - } - windowTransformation.rotate(data.rotation->angle, xAxis, yAxis, zAxis); - windowTransformation.translate(-data.rotation->xRotationPoint, -data.rotation->yRotationPoint, -data.rotation->zRotationPoint); - } - if (data.shader) { - data.shader->setUniform(GLShader::WindowTransformation, windowTransformation); - } - } - if (!sceneShader) { + + const QMatrix4x4 windowTransformation = transformation(mask, data); + + if (data.shader) + data.shader->setUniform(GLShader::WindowTransformation, windowTransformation); + + if (!sceneShader) pushMatrix(windowTransformation); - } + region.translate(toplevel->x(), toplevel->y()); // Back to screen coords WindowQuadList decoration = data.quads.select(WindowQuadDecoration); diff --git a/scene_opengl.h b/scene_opengl.h index f708edd9a6..9775acf286 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -155,6 +155,8 @@ protected: DecorationRight, DecorationBottom }; + + QMatrix4x4 transformation(int mask, const WindowPaintData &data) const; void paintDecoration(const QPixmap* decoration, TextureType decorationType, const QRegion& region, const QRect& rect, const WindowPaintData& data, const WindowQuadList& quads, bool updateDeco); void makeDecorationArrays(const WindowQuadList& quads, const QRect& rect) const; void renderQuads(int mask, const QRegion& region, const WindowQuadList& quads);