kwin: Set the texcoords in the decoration quads

This way we don't have to compute them in makeDecorationArrays().
This commit is contained in:
Fredrik Höglund 2013-03-16 12:21:59 +01:00
parent 49e78a3507
commit 5b445b1706
4 changed files with 51 additions and 20 deletions

View file

@ -717,16 +717,16 @@ WindowQuadList Scene::Window::buildQuads(bool force) const
QRegion decoration = (client && decorationPlugin()->hasAlpha() ? QRegion decoration = (client && decorationPlugin()->hasAlpha() ?
QRegion(client->decorationRect()) : shape()) - center; QRegion(client->decorationRect()) : shape()) - center;
ret = makeQuads(WindowQuadContents, contents); 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())) if (!client || !(center.isEmpty() || client->isShade()))
ret += makeQuads(WindowQuadDecoration, decoration); ret += makeDecorationQuads(rects, decoration);
else { else {
// this is a shaded client, we have to create four decoartion quads // this is a shaded client, we have to create four decoration quads
QRect left, top, right, bottom; const QRect bounding = rects[0] | rects[1] | rects[2] | rects[3];
client->layoutDecorationRects(left, top, right, bottom, Client::WindowRelative); ret += makeDecorationQuads(rects, bounding);
ret += makeQuads(WindowQuadDecoration, top);
ret += makeQuads(WindowQuadDecoration, bottom);
ret += makeQuads(WindowQuadDecoration, left);
ret += makeQuads(WindowQuadDecoration, right);
} }
} }
if (m_shadow) { if (m_shadow) {
@ -737,6 +737,37 @@ WindowQuadList Scene::Window::buildQuads(bool force) const
return ret; return ret;
} }
WindowQuadList Scene::Window::makeDecorationQuads(const QRect *rects, const QRegion &region) 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 Scene::Window::makeQuads(WindowQuadType type, const QRegion& reg) const
{ {
WindowQuadList ret; WindowQuadList ret;

View file

@ -233,6 +233,7 @@ public:
Shadow* shadow(); Shadow* shadow();
protected: protected:
WindowQuadList makeQuads(WindowQuadType type, const QRegion& reg) const; WindowQuadList makeQuads(WindowQuadType type, const QRegion& reg) const;
WindowQuadList makeDecorationQuads(const QRect *rects, const QRegion &region) const;
Toplevel* toplevel; Toplevel* toplevel;
ImageFilterType filter; ImageFilterType filter;
Shadow *m_shadow; Shadow *m_shadow;

View file

@ -1181,15 +1181,15 @@ void SceneOpenGL::Window::paintDecorations(const WindowPaintData &data, const QR
TextureType type[] = { DecorationLeft, DecorationTop, DecorationRight, DecorationBottom }; TextureType type[] = { DecorationLeft, DecorationTop, DecorationRight, DecorationBottom };
for (int i = 0; i < 4; i++) 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(); redirector->markAsRepainted();
} }
void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType decorationType, void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType type,
const QRegion& region, const QRect& rect, const WindowPaintData& data, const QRegion &region, const WindowPaintData &data,
const WindowQuadList& quads, bool hardwareClipping) const WindowQuadList &quads, bool hardwareClipping)
{ {
if (!texture || quads.isEmpty()) if (!texture || quads.isEmpty())
return; return;
@ -1202,10 +1202,10 @@ void SceneOpenGL::Window::paintDecoration(GLTexture *texture, TextureType decora
texture->setWrapMode(GL_CLAMP_TO_EDGE); texture->setWrapMode(GL_CLAMP_TO_EDGE);
texture->bind(); texture->bind();
prepareStates(decorationType, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation(), data.screen()); prepareStates(type, data.opacity() * data.decorationOpacity(), data.brightness(), data.saturation(), data.screen());
makeDecorationArrays(quads, rect, texture); makeDecorationArrays(quads, texture);
GLVertexBuffer::streamingBuffer()->render(region, GL_TRIANGLES, hardwareClipping); 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(); texture->unbind();
@ -1266,10 +1266,9 @@ void SceneOpenGL::Window::paintShadow(const QRegion &region, const WindowPaintDa
#endif #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); const QMatrix4x4 matrix = texture->matrix(UnnormalizedCoordinates);
matrix.translate(-rect.x(), -rect.y());
// Since we know that the texture matrix just scales and translates // Since we know that the texture matrix just scales and translates
// we can use this information to optimize the transformation // we can use this information to optimize the transformation

View file

@ -233,9 +233,9 @@ protected:
}; };
QMatrix4x4 transformation(int mask, const WindowPaintData &data) const; 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 &region, const WindowPaintData &data, const WindowQuadList &quads, bool hardwareClipping);
void paintShadow(const QRegion &region, const WindowPaintData &data, bool hardwareClipping); void paintShadow(const QRegion &region, 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); 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. * @brief Called from performPaint once it is determined whether the window will be painted.