Commit 29e91f90 authored by Martin Flöser's avatar Martin Flöser

Support for fullscreen, screen and region screenshot

Just to have something which uses the blitFramebuffer functionality.
parent 225c362a
......@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "screenshot.h"
#include <kwinglutils.h>
#include <KDE/KDebug>
#include <KDE/KTemporaryFile>
#include <QtDBus/QDBusConnection>
#include <QtCore/QVarLengthArray>
#include <QtGui/QPainter>
......@@ -146,6 +147,63 @@ void ScreenShotEffect::screenshotWindowUnderCursor(int mask)
}
}
QString ScreenShotEffect::screenshotFullscreen()
{
if (!GLRenderTarget::blitSupported()) {
kDebug(1212) << "Framebuffer Blit not supported";
return QString();
}
return blitScreenshot(QRect(0, 0, displayWidth(), displayHeight()));
}
QString ScreenShotEffect::screenshotScreen(int screen)
{
if (!GLRenderTarget::blitSupported()) {
kDebug(1212) << "Framebuffer Blit not supported";
return QString();
}
return blitScreenshot(effects->clientArea(FullScreenArea, screen, 0));
}
QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height)
{
if (!GLRenderTarget::blitSupported()) {
kDebug(1212) << "Framebuffer Blit not supported";
return QString();
}
return blitScreenshot(QRect(x, y, width, height));
}
QString ScreenShotEffect::blitScreenshot(const QRect &geometry)
{
#ifdef KWIN_HAVE_OPENGLES
Q_UNUSED(geometry)
return QString();
#else
GLTexture tex(geometry.width(), geometry.height());
GLRenderTarget target(&tex);
target.blitFromFramebuffer(geometry);
// copy content from framebuffer into image
tex.bind();
QImage img(geometry.size(), QImage::Format_ARGB32);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
tex.unbind();
ScreenShotEffect::convertFromGLImage(img, geometry.width(), geometry.height());
KTemporaryFile temp;
temp.setSuffix(".png");
temp.setAutoRemove(false);
if (!temp.open()) {
return QString();
}
img.save(&temp);
temp.close();
return temp.fileName();
#endif
}
void ScreenShotEffect::grabPointerImage(QImage& snapshot, int offsetx, int offsety)
// Uses the X11_EXTENSIONS_XFIXES_H extension to grab the pointer image, and overlays it onto the snapshot.
{
......
......@@ -45,12 +45,36 @@ public:
static void convertFromGLImage(QImage &img, int w, int h);
public Q_SLOTS:
Q_SCRIPTABLE void screenshotWindowUnderCursor(int mask = 0);
/**
* Saves a screenshot of all screen into a file and returns the path to the file.
* Functionality requires hardware support, if not available a null string is returned.
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotFullscreen();
/**
* Saves a screenshot of the screen identified by @p screen into a file and returns the path to the file.
* Functionality requires hardware support, if not available a null string is returned.
* @param screen Number of screen as numbered by kephal
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotScreen(int screen);
/**
* Saves a screenshot of the selected geometry into a file and returns the path to the file.
* Functionality requires hardware support, if not available a null string is returned.
* @param x Left upper x coord of region
* @param y Left upper y coord of region
* @param width Width of the region to screenshot
* @param height Height of the region to screenshot
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotArea(int x, int y, int width, int height);
Q_SIGNALS:
Q_SCRIPTABLE void screenshotCreated(qulonglong handle);
private:
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
QString blitScreenshot(const QRect &geometry);
EffectWindow *m_scheduledScreenshot;
ScreenShotType m_type;
QPixmap m_lastScreenshot;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment