summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gräßlin <mgraesslin@kde.org>2013-01-08 09:46:10 (GMT)
committerMartin Gräßlin <mgraesslin@kde.org>2013-01-15 14:05:43 (GMT)
commite15aaaef060ee823d143831766961fc3589cb65c (patch)
tree6a6390018d2e573188640d074b4b8b1cf96d2e9f
parent5a8bb2f46e5c19f121dab1a8a70dd04b56e7ab2e (diff)
Use window size for offscreen texture size in screenshot effect
Effect used the display size which caused windows being larger than either width or height not to be captured correctly. Now it uses the window size for the offscreen texture which also requires to adjust the modelviewprojection matrix. As an unrelated change the pointer to GLRenderTarget and GLTexture are changed to a QScopedPointer and some variables which got moved around are consted. BUG: 312851 FIXED-IN: 4.11 REVIEW: 108258
-rw-r--r--kwin/effects/screenshot/screenshot.cpp130
-rw-r--r--kwin/effects/screenshot/screenshot.h2
2 files changed, 89 insertions, 43 deletions
diff --git a/kwin/effects/screenshot/screenshot.cpp b/kwin/effects/screenshot/screenshot.cpp
index b231292..dfbb2c7 100644
--- a/kwin/effects/screenshot/screenshot.cpp
+++ b/kwin/effects/screenshot/screenshot.cpp
@@ -59,55 +59,55 @@ void ScreenShotEffect::postPaintScreen()
{
effects->postPaintScreen();
if (m_scheduledScreenshot) {
- int w = displayWidth();
- int h = displayHeight();
+ WindowPaintData d(m_scheduledScreenshot);
+ double left = 0;
+ double top = 0;
+ double right = m_scheduledScreenshot->width();
+ double bottom = m_scheduledScreenshot->height();
+ if (m_scheduledScreenshot->hasDecoration() && m_type & INCLUDE_DECORATION) {
+ foreach (const WindowQuad & quad, d.quads) {
+ // we need this loop to include the decoration padding
+ left = qMin(left, quad.left());
+ top = qMin(top, quad.top());
+ right = qMax(right, quad.right());
+ bottom = qMax(bottom, quad.bottom());
+ }
+ } else if (m_scheduledScreenshot->hasDecoration()) {
+ WindowQuadList newQuads;
+ left = m_scheduledScreenshot->width();
+ top = m_scheduledScreenshot->height();
+ right = 0;
+ bottom = 0;
+ foreach (const WindowQuad & quad, d.quads) {
+ if (quad.type() == WindowQuadContents) {
+ newQuads << quad;
+ left = qMin(left, quad.left());
+ top = qMin(top, quad.top());
+ right = qMax(right, quad.right());
+ bottom = qMax(bottom, quad.bottom());
+ }
+ }
+ d.quads = newQuads;
+ }
+ const int width = right - left;
+ const int height = bottom - top;
bool validTarget = true;
- GLTexture* offscreenTexture = 0;
- GLRenderTarget* target = 0;
+ QScopedPointer<GLTexture> offscreenTexture;
+ QScopedPointer<GLRenderTarget> target;
if (effects->isOpenGLCompositing()) {
+ int w = width;
+ int h = height;
if (!GLTexture::NPOTTextureSupported()) {
w = nearestPowerOfTwo(w);
h = nearestPowerOfTwo(h);
}
- offscreenTexture = new GLTexture(w, h);
+ offscreenTexture.reset(new GLTexture(w, h));
offscreenTexture->setFilter(GL_LINEAR);
offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
- target = new GLRenderTarget(*offscreenTexture);
+ target.reset(new GLRenderTarget(*offscreenTexture));
validTarget = target->valid();
}
if (validTarget) {
- WindowPaintData d(m_scheduledScreenshot);
- double left = 0;
- double top = 0;
- double right = m_scheduledScreenshot->width();
- double bottom = m_scheduledScreenshot->height();
- if (m_scheduledScreenshot->hasDecoration() && m_type & INCLUDE_DECORATION) {
- foreach (const WindowQuad & quad, d.quads) {
- // we need this loop to include the decoration padding
- left = qMin(left, quad.left());
- top = qMin(top, quad.top());
- right = qMax(right, quad.right());
- bottom = qMax(bottom, quad.bottom());
- }
- } else if (m_scheduledScreenshot->hasDecoration()) {
- WindowQuadList newQuads;
- left = m_scheduledScreenshot->width();
- top = m_scheduledScreenshot->height();
- right = 0;
- bottom = 0;
- foreach (const WindowQuad & quad, d.quads) {
- if (quad.type() == WindowQuadContents) {
- newQuads << quad;
- left = qMin(left, quad.left());
- top = qMin(top, quad.top());
- right = qMax(right, quad.right());
- bottom = qMax(bottom, quad.bottom());
- }
- }
- d.quads = newQuads;
- }
- int width = right - left;
- int height = bottom - top;
d.setXTranslation(-m_scheduledScreenshot->x() - left);
d.setYTranslation(-m_scheduledScreenshot->y() - top);
@@ -115,14 +115,16 @@ void ScreenShotEffect::postPaintScreen()
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
QImage img;
if (effects->isOpenGLCompositing()) {
- GLRenderTarget::pushRenderTarget(target);
+ GLRenderTarget::pushRenderTarget(target.data());
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
- effects->drawWindow(m_scheduledScreenshot, mask, QRegion(0, 0, width, height), d);
+ setMatrix(offscreenTexture->width(), offscreenTexture->height());
+ effects->drawWindow(m_scheduledScreenshot, mask, infiniteRegion(), d);
+ restoreMatrix();
// copy content from framebuffer into image
img = QImage(QSize(width, height), QImage::Format_ARGB32);
- glReadPixels(0, offscreenTexture->height() - height, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
+ glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
GLRenderTarget::popRenderTarget();
ScreenShotEffect::convertFromGLImage(img, width, height);
}
@@ -153,12 +155,54 @@ void ScreenShotEffect::postPaintScreen()
}
emit screenshotCreated(m_lastScreenshot.handle());
}
- delete offscreenTexture;
- delete target;
m_scheduledScreenshot = NULL;
}
}
+static QMatrix4x4 s_origProjection;
+static QMatrix4x4 s_origModelview;
+
+void ScreenShotEffect::setMatrix(int width, int height)
+{
+ QMatrix4x4 projection;
+ QMatrix4x4 identity;
+ projection.ortho(QRect(0, 0, width, height));
+ if (effects->compositingType() == OpenGL2Compositing) {
+ ShaderBinder binder(ShaderManager::GenericShader);
+ GLShader *shader = binder.shader();
+ s_origProjection = shader->getUniformMatrix4x4("projection");
+ s_origModelview = shader->getUniformMatrix4x4("modelview");
+ shader->setUniform(GLShader::ProjectionMatrix, projection);
+ shader->setUniform(GLShader::ModelViewMatrix, identity);
+ } else if (effects->compositingType() == OpenGL1Compositing) {
+#ifdef KWIN_HAVE_OPENGL_1
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ loadMatrix(projection);
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+#endif
+ }
+}
+
+void ScreenShotEffect::restoreMatrix()
+{
+ if (effects->compositingType() == OpenGL2Compositing) {
+ ShaderBinder binder(ShaderManager::GenericShader);
+ GLShader *shader = binder.shader();
+ shader->setUniform(GLShader::ProjectionMatrix, s_origProjection);
+ shader->setUniform(GLShader::ModelViewMatrix, s_origModelview);
+ } else if (effects->compositingType() == OpenGL1Compositing) {
+#ifdef KWIN_HAVE_OPENGL_1
+ glMatrixMode(GL_PROJECTION);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+#endif
+ }
+}
+
void ScreenShotEffect::screenshotWindowUnderCursor(int mask)
{
m_type = (ScreenShotType)mask;
diff --git a/kwin/effects/screenshot/screenshot.h b/kwin/effects/screenshot/screenshot.h
index 0dcfa58..18b5002 100644
--- a/kwin/effects/screenshot/screenshot.h
+++ b/kwin/effects/screenshot/screenshot.h
@@ -80,6 +80,8 @@ private slots:
private:
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
QString blitScreenshot(const QRect &geometry);
+ void setMatrix(int width, int height);
+ void restoreMatrix();
EffectWindow *m_scheduledScreenshot;
ScreenShotType m_type;
QPixmap m_lastScreenshot;