From 5b445b17061d67d5bd532bc0293acc7f7b574095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=B6glund?= Date: Sat, 16 Mar 2013 12:21:59 +0100 Subject: [PATCH] kwin: Set the texcoords in the decoration quads This way we don't have to compute them in makeDecorationArrays(). --- scene.cpp | 47 +++++++++++++++++++++++++++++++++++++++-------- scene.h | 1 + scene_opengl.cpp | 19 +++++++++---------- scene_opengl.h | 4 ++-- 4 files changed, 51 insertions(+), 20 deletions(-) diff --git a/scene.cpp b/scene.cpp index 64cb507d2e..b1142d089e 100644 --- a/scene.cpp +++ b/scene.cpp @@ -717,16 +717,16 @@ WindowQuadList Scene::Window::buildQuads(bool force) const QRegion decoration = (client && decorationPlugin()->hasAlpha() ? QRegion(client->decorationRect()) : shape()) - center; ret = makeQuads(WindowQuadContents, contents); + + QRect rects[4]; + client->layoutDecorationRects(rects[0], rects[1], rects[2], rects[3], Client::WindowRelative); + if (!client || !(center.isEmpty() || client->isShade())) - ret += makeQuads(WindowQuadDecoration, decoration); + ret += makeDecorationQuads(rects, decoration); else { - // this is a shaded client, we have to create four decoartion quads - QRect left, top, right, bottom; - client->layoutDecorationRects(left, top, right, bottom, Client::WindowRelative); - ret += makeQuads(WindowQuadDecoration, top); - ret += makeQuads(WindowQuadDecoration, bottom); - ret += makeQuads(WindowQuadDecoration, left); - ret += makeQuads(WindowQuadDecoration, right); + // this is a shaded client, we have to create four decoration quads + const QRect bounding = rects[0] | rects[1] | rects[2] | rects[3]; + ret += makeDecorationQuads(rects, bounding); } } if (m_shadow) { @@ -737,6 +737,37 @@ WindowQuadList Scene::Window::buildQuads(bool force) const return ret; } +WindowQuadList Scene::Window::makeDecorationQuads(const QRect *rects, const QRegion ®ion) const +{ + WindowQuadList list; + + for (int i = 0; i < 4; i++) { + foreach (const QRect &r, (region & rects[i]).rects()) { + if (!r.isValid()) + continue; + + const int x0 = r.x(); + const int y0 = r.y(); + const int x1 = r.x() + r.width(); + const int y1 = r.y() + r.height(); + + const int u0 = x0 - rects[i].x(); + const int v0 = y0 - rects[i].y(); + const int u1 = x1 - rects[i].x(); + const int v1 = y1 - rects[i].y(); + + WindowQuad quad(WindowQuadDecoration); + quad[0] = WindowVertex(x0, y0, u0, v0); // Top-left + quad[1] = WindowVertex(x1, y0, u1, v0); // Top-right + quad[2] = WindowVertex(x1, y1, u1, v1); // Bottom-right + quad[3] = WindowVertex(x0, y1, u0, v1); // Bottom-left + list.append(quad); + } + } + + return list; +} + WindowQuadList Scene::Window::makeQuads(WindowQuadType type, const QRegion& reg) const { WindowQuadList ret; diff --git a/scene.h b/scene.h index 254d6f92f1..c96065d605 100644 --- a/scene.h +++ b/scene.h @@ -233,6 +233,7 @@ public: Shadow* shadow(); protected: WindowQuadList makeQuads(WindowQuadType type, const QRegion& reg) const; + WindowQuadList makeDecorationQuads(const QRect *rects, const QRegion ®ion) const; Toplevel* toplevel; ImageFilterType filter; Shadow *m_shadow; diff --git a/scene_opengl.cpp b/scene_opengl.cpp index 967743b67d..2a58c0832e 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -1181,15 +1181,15 @@ void SceneOpenGL::Window::paintDecorations(const WindowPaintData &data, const QR TextureType type[] = { DecorationLeft, DecorationTop, DecorationRight, DecorationBottom }; for (int i = 0; i < 4; i++) - paintDecoration(textures[i], type[i], region, rect[i], data, quads[i], hardwareClipping); + paintDecoration(textures[i], type[i], region, data, quads[i], hardwareClipping); redirector->markAsRepainted(); } -void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType decorationType, - const QRegion& region, const QRect& rect, const WindowPaintData& data, - const WindowQuadList& quads, bool hardwareClipping) +void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType type, + const QRegion ®ion, const WindowPaintData &data, + const WindowQuadList &quads, bool hardwareClipping) { if (!texture || quads.isEmpty()) return; @@ -1202,10 +1202,10 @@ void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType decora texture->setWrapMode(GL_CLAMP_TO_EDGE); texture->bind(); - prepareStates(decorationType, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation(), data.screen()); - makeDecorationArrays(quads, rect, texture); + prepareStates(type, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation(), data.screen()); + makeDecorationArrays(quads, texture); GLVertexBuffer::streamingBuffer()->render(region, GL_TRIANGLES, hardwareClipping); - restoreStates(decorationType, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation()); + restoreStates(type, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation()); texture->unbind(); @@ -1266,10 +1266,9 @@ void SceneOpenGL::Window::paintShadow(const QRegion ®ion, const WindowPaintDa #endif } -void SceneOpenGL::Window::makeDecorationArrays(const WindowQuadList &quads, const QRect &rect, GLTexture *texture) const +void SceneOpenGL::Window::makeDecorationArrays(const WindowQuadList &quads, GLTexture *texture) const { - QMatrix4x4 matrix = texture->matrix(UnnormalizedCoordinates); - matrix.translate(-rect.x(), -rect.y()); + const QMatrix4x4 matrix = texture->matrix(UnnormalizedCoordinates); // Since we know that the texture matrix just scales and translates // we can use this information to optimize the transformation diff --git a/scene_opengl.h b/scene_opengl.h index b8a998358b..54d16924ed 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -233,9 +233,9 @@ protected: }; QMatrix4x4 transformation(int mask, const WindowPaintData &data) const; - void paintDecoration(GLTexture *decorationTexture, TextureType decorationType, const QRegion& region, const QRect& rect, const WindowPaintData& data, const WindowQuadList& quads, bool hardwareClipping); + void paintDecoration(GLTexture *texture, TextureType type, const QRegion ®ion, const WindowPaintData &data, const WindowQuadList &quads, bool hardwareClipping); void paintShadow(const QRegion ®ion, const WindowPaintData &data, bool hardwareClipping); - void makeDecorationArrays(const WindowQuadList& quads, const QRect &rect, GLTexture *tex) const; + void makeDecorationArrays(const WindowQuadList& quads, GLTexture *tex) const; void renderQuads(int, const QRegion& region, const WindowQuadList& quads, GLTexture* tex, bool normalized, bool hardwareClipping); /** * @brief Called from performPaint once it is determined whether the window will be painted.