diff --git a/effects/screenshot/screenshot.cpp b/effects/screenshot/screenshot.cpp index e1704b48ef..d12d77df96 100644 --- a/effects/screenshot/screenshot.cpp +++ b/effects/screenshot/screenshot.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include "screenshot.h" #include #include +#include #include #include #include @@ -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. { diff --git a/effects/screenshot/screenshot.h b/effects/screenshot/screenshot.h index 83b29a8449..040ef61a70 100644 --- a/effects/screenshot/screenshot.h +++ b/effects/screenshot/screenshot.h @@ -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;