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: 108258icc-effect-5.14.5
parent
5f4935fc66
commit
b7f06b8708
|
@ -59,55 +59,55 @@ void ScreenShotEffect::postPaintScreen()
|
||||||
{
|
{
|
||||||
effects->postPaintScreen();
|
effects->postPaintScreen();
|
||||||
if (m_scheduledScreenshot) {
|
if (m_scheduledScreenshot) {
|
||||||
int w = displayWidth();
|
WindowPaintData d(m_scheduledScreenshot);
|
||||||
int h = displayHeight();
|
double left = 0;
|
||||||
bool validTarget = true;
|
double top = 0;
|
||||||
GLTexture* offscreenTexture = 0;
|
double right = m_scheduledScreenshot->width();
|
||||||
GLRenderTarget* target = 0;
|
double bottom = m_scheduledScreenshot->height();
|
||||||
if (effects->isOpenGLCompositing()) {
|
if (m_scheduledScreenshot->hasDecoration() && m_type & INCLUDE_DECORATION) {
|
||||||
if (!GLTexture::NPOTTextureSupported()) {
|
foreach (const WindowQuad & quad, d.quads) {
|
||||||
w = nearestPowerOfTwo(w);
|
// we need this loop to include the decoration padding
|
||||||
h = nearestPowerOfTwo(h);
|
left = qMin(left, quad.left());
|
||||||
|
top = qMin(top, quad.top());
|
||||||
|
right = qMax(right, quad.right());
|
||||||
|
bottom = qMax(bottom, quad.bottom());
|
||||||
}
|
}
|
||||||
offscreenTexture = new GLTexture(w, h);
|
} else if (m_scheduledScreenshot->hasDecoration()) {
|
||||||
offscreenTexture->setFilter(GL_LINEAR);
|
WindowQuadList newQuads;
|
||||||
offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
|
left = m_scheduledScreenshot->width();
|
||||||
target = new GLRenderTarget(*offscreenTexture);
|
top = m_scheduledScreenshot->height();
|
||||||
validTarget = target->valid();
|
right = 0;
|
||||||
}
|
bottom = 0;
|
||||||
if (validTarget) {
|
foreach (const WindowQuad & quad, d.quads) {
|
||||||
WindowPaintData d(m_scheduledScreenshot);
|
if (quad.type() == WindowQuadContents) {
|
||||||
double left = 0;
|
newQuads << quad;
|
||||||
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());
|
left = qMin(left, quad.left());
|
||||||
top = qMin(top, quad.top());
|
top = qMin(top, quad.top());
|
||||||
right = qMax(right, quad.right());
|
right = qMax(right, quad.right());
|
||||||
bottom = qMax(bottom, quad.bottom());
|
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;
|
d.quads = newQuads;
|
||||||
int height = bottom - top;
|
}
|
||||||
|
const int width = right - left;
|
||||||
|
const int height = bottom - top;
|
||||||
|
bool validTarget = true;
|
||||||
|
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.reset(new GLTexture(w, h));
|
||||||
|
offscreenTexture->setFilter(GL_LINEAR);
|
||||||
|
offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
|
||||||
|
target.reset(new GLRenderTarget(*offscreenTexture));
|
||||||
|
validTarget = target->valid();
|
||||||
|
}
|
||||||
|
if (validTarget) {
|
||||||
d.setXTranslation(-m_scheduledScreenshot->x() - left);
|
d.setXTranslation(-m_scheduledScreenshot->x() - left);
|
||||||
d.setYTranslation(-m_scheduledScreenshot->y() - top);
|
d.setYTranslation(-m_scheduledScreenshot->y() - top);
|
||||||
|
|
||||||
|
@ -115,14 +115,16 @@ void ScreenShotEffect::postPaintScreen()
|
||||||
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
|
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
|
||||||
QImage img;
|
QImage img;
|
||||||
if (effects->isOpenGLCompositing()) {
|
if (effects->isOpenGLCompositing()) {
|
||||||
GLRenderTarget::pushRenderTarget(target);
|
GLRenderTarget::pushRenderTarget(target.data());
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0);
|
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
|
// copy content from framebuffer into image
|
||||||
img = QImage(QSize(width, height), QImage::Format_ARGB32);
|
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();
|
GLRenderTarget::popRenderTarget();
|
||||||
ScreenShotEffect::convertFromGLImage(img, width, height);
|
ScreenShotEffect::convertFromGLImage(img, width, height);
|
||||||
}
|
}
|
||||||
|
@ -153,12 +155,54 @@ void ScreenShotEffect::postPaintScreen()
|
||||||
}
|
}
|
||||||
emit screenshotCreated(m_lastScreenshot.handle());
|
emit screenshotCreated(m_lastScreenshot.handle());
|
||||||
}
|
}
|
||||||
delete offscreenTexture;
|
|
||||||
delete target;
|
|
||||||
m_scheduledScreenshot = NULL;
|
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)
|
void ScreenShotEffect::screenshotWindowUnderCursor(int mask)
|
||||||
{
|
{
|
||||||
m_type = (ScreenShotType)mask;
|
m_type = (ScreenShotType)mask;
|
||||||
|
|
|
@ -80,6 +80,8 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
|
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
|
||||||
QString blitScreenshot(const QRect &geometry);
|
QString blitScreenshot(const QRect &geometry);
|
||||||
|
void setMatrix(int width, int height);
|
||||||
|
void restoreMatrix();
|
||||||
EffectWindow *m_scheduledScreenshot;
|
EffectWindow *m_scheduledScreenshot;
|
||||||
ScreenShotType m_type;
|
ScreenShotType m_type;
|
||||||
QPixmap m_lastScreenshot;
|
QPixmap m_lastScreenshot;
|
||||||
|
|
Loading…
Reference in New Issue