From 9a786cd8bf032a461216ce6080c22f209cb7f6e9 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 1 Mar 2021 14:19:11 +0200 Subject: [PATCH] effects/screenshot: Minor style fixes We prefer pragma once and put braces on the same line as the if statement. --- src/effects/screenshot/screenshot.cpp | 77 ++++++++++++++------------- src/effects/screenshot/screenshot.h | 18 ++++--- 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/effects/screenshot/screenshot.cpp b/src/effects/screenshot/screenshot.cpp index ddcf05500e..1c715f8917 100644 --- a/src/effects/screenshot/screenshot.cpp +++ b/src/effects/screenshot/screenshot.cpp @@ -13,11 +13,13 @@ #include #include -#include #include +#if defined(KWIN_HAVE_XRENDER_COMPOSITING) +#include #include +#endif namespace KWin { @@ -76,7 +78,7 @@ static void convertFromGLImage(QImage &img, int w, int h) img = img.mirrored(); } -#ifdef KWIN_HAVE_XRENDER_COMPOSITING +#if defined(KWIN_HAVE_XRENDER_COMPOSITING) static void xImageCleanup(void *data) { xcb_image_destroy(static_cast(data)); @@ -103,8 +105,8 @@ static QImage xPictureToImage(xcb_render_picture_t srcPic, const QRect &geometry bool ScreenShotEffect::supported() { - return effects->compositingType() == XRenderCompositing || - (effects->isOpenGLCompositing() && GLRenderTarget::supported()); + return effects->compositingType() == XRenderCompositing || + (effects->isOpenGLCompositing() && GLRenderTarget::supported()); } ScreenShotEffect::ScreenShotEffect() @@ -241,9 +243,9 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot) if (window->hasDecoration() && (screenshot->flags & ScreenShotIncludeDecoration)) { for (const WindowQuad &quad : qAsConst(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()); + left = qMin(left, quad.left()); + top = qMin(top, quad.top()); + right = qMax(right, quad.right()); bottom = qMax(bottom, quad.bottom()); } } else if (window->hasDecoration()) { @@ -255,9 +257,9 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot) for (const WindowQuad &quad : qAsConst(d.quads)) { if (quad.type() == WindowQuadContents) { newQuads << quad; - left = qMin(left, quad.left()); - top = qMin(top, quad.top()); - right = qMax(right, quad.right()); + left = qMin(left, quad.left()); + top = qMin(top, quad.top()); + right = qMax(right, quad.right()); bottom = qMax(bottom, quad.bottom()); } } @@ -296,11 +298,12 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot) // copy content from framebuffer into image img = QImage(QSize(width, height), QImage::Format_ARGB32); - glReadnPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, img.sizeInBytes(), (GLvoid*)img.bits()); + glReadnPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, img.sizeInBytes(), + static_cast(img.bits())); GLRenderTarget::popRenderTarget(); convertFromGLImage(img, width, height); } -#ifdef KWIN_HAVE_XRENDER_COMPOSITING +#if defined(KWIN_HAVE_XRENDER_COMPOSITING) if (effects->compositingType() == XRenderCompositing) { setXRenderOffscreen(true); effects->drawWindow(window, mask, QRegion(0, 0, width, height), d); @@ -409,48 +412,50 @@ void ScreenShotEffect::postPaintScreen() } } -QImage ScreenShotEffect::blitScreenshot(const QRect &geometry, const qreal scale) +QImage ScreenShotEffect::blitScreenshot(const QRect &geometry, qreal devicePixelRatio) const { - QImage img; - if (effects->isOpenGLCompositing()) - { - const QSize nativeSize = geometry.size() * scale; + QImage image; + + if (effects->isOpenGLCompositing()) { + const QSize nativeSize = geometry.size() * devicePixelRatio; if (GLRenderTarget::blitSupported() && !GLPlatform::instance()->isGLES()) { - - img = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32); - GLTexture tex(GL_RGBA8, nativeSize.width(), nativeSize.height()); - GLRenderTarget target(tex); + image = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32); + GLTexture texture(GL_RGBA8, nativeSize.width(), nativeSize.height()); + GLRenderTarget target(texture); target.blitFromFramebuffer(geometry); // copy content from framebuffer into image - tex.bind(); - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast(img.bits())); - tex.unbind(); + texture.bind(); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, + static_cast(image.bits())); + texture.unbind(); } else { - img = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32); - glReadPixels(0, 0, nativeSize.width(), nativeSize.height(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits()); + image = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32); + glReadPixels(0, 0, nativeSize.width(), nativeSize.height(), GL_RGBA, + GL_UNSIGNED_BYTE, static_cast(image.bits())); } - convertFromGLImage(img, nativeSize.width(), nativeSize.height()); + convertFromGLImage(image, nativeSize.width(), nativeSize.height()); } -#ifdef KWIN_HAVE_XRENDER_COMPOSITING +#if defined(KWIN_HAVE_XRENDER_COMPOSITING) if (effects->compositingType() == XRenderCompositing) { - img = xPictureToImage(effects->xrenderBufferPicture(), geometry); + image = xPictureToImage(effects->xrenderBufferPicture(), geometry); } #endif - img.setDevicePixelRatio(scale); - return img; + image.setDevicePixelRatio(devicePixelRatio); + return image; } -void ScreenShotEffect::grabPointerImage(QImage& snapshot, int offsetx, int offsety) +void ScreenShotEffect::grabPointerImage(QImage &snapshot, int xOffset, int yOffset) const { - const auto cursor = effects->cursorImage(); - if (cursor.image().isNull()) + const PlatformCursorImage cursor = effects->cursorImage(); + if (cursor.image().isNull()) { return; + } QPainter painter(&snapshot); - painter.drawImage(effects->cursorPos() - cursor.hotSpot() - QPoint(offsetx, offsety), cursor.image()); + painter.drawImage(effects->cursorPos() - cursor.hotSpot() - QPoint(xOffset, yOffset), cursor.image()); } bool ScreenShotEffect::isActive() const @@ -491,4 +496,4 @@ void ScreenShotEffect::handleWindowClosed(EffectWindow *window) } } -} // namespace +} // namespace KWin diff --git a/src/effects/screenshot/screenshot.h b/src/effects/screenshot/screenshot.h index 40b4bdbe1f..454efc35de 100644 --- a/src/effects/screenshot/screenshot.h +++ b/src/effects/screenshot/screenshot.h @@ -8,8 +8,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef KWIN_SCREENSHOT_H -#define KWIN_SCREENSHOT_H +#pragma once #include @@ -37,7 +36,12 @@ struct ScreenShotAreaData; struct ScreenShotScreenData; /** - * The screenshot effet allows to takes screenshot, by window, area, screen, etc... + * The ScreenShotEffect provides a convenient way to capture the contents of a given window, + * screen or an area in the global coordinates. + * + * Use the QFutureWatcher class to get notified when the requested screenshot is ready. Note + * that the screenshot QFuture object can get cancelled if the captured window or the screen is + * removed. */ class ScreenShotEffect : public Effect { @@ -88,8 +92,8 @@ private: void cancelAreaScreenShots(); void cancelScreenScreenShots(); - void grabPointerImage(QImage& snapshot, int offsetx, int offsety); - QImage blitScreenshot(const QRect &geometry, const qreal scale = 1.0); + void grabPointerImage(QImage &snapshot, int xOffset, int yOffset) const; + QImage blitScreenshot(const QRect &geometry, qreal devicePixelRatio = 1.0) const; QVector m_windowScreenShots; QVector m_areaScreenShots; @@ -99,8 +103,6 @@ private: EffectScreen *m_paintedScreen = nullptr; }; -} // namespace +} // namespace KWin Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScreenShotFlags) - -#endif // KWIN_SCREENSHOT_H