effects/screenshot: Minor style fixes
We prefer pragma once and put braces on the same line as the if statement.
This commit is contained in:
parent
1fb44b5bd5
commit
9a786cd8bf
2 changed files with 51 additions and 44 deletions
|
@ -13,11 +13,13 @@
|
||||||
|
|
||||||
#include <kwinglplatform.h>
|
#include <kwinglplatform.h>
|
||||||
#include <kwinglutils.h>
|
#include <kwinglutils.h>
|
||||||
#include <kwinxrenderutils.h>
|
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
|
#if defined(KWIN_HAVE_XRENDER_COMPOSITING)
|
||||||
|
#include <kwinxrenderutils.h>
|
||||||
#include <xcb/xcb_image.h>
|
#include <xcb/xcb_image.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace KWin
|
namespace KWin
|
||||||
{
|
{
|
||||||
|
@ -76,7 +78,7 @@ static void convertFromGLImage(QImage &img, int w, int h)
|
||||||
img = img.mirrored();
|
img = img.mirrored();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
#if defined(KWIN_HAVE_XRENDER_COMPOSITING)
|
||||||
static void xImageCleanup(void *data)
|
static void xImageCleanup(void *data)
|
||||||
{
|
{
|
||||||
xcb_image_destroy(static_cast<xcb_image_t *>(data));
|
xcb_image_destroy(static_cast<xcb_image_t *>(data));
|
||||||
|
@ -103,8 +105,8 @@ static QImage xPictureToImage(xcb_render_picture_t srcPic, const QRect &geometry
|
||||||
|
|
||||||
bool ScreenShotEffect::supported()
|
bool ScreenShotEffect::supported()
|
||||||
{
|
{
|
||||||
return effects->compositingType() == XRenderCompositing ||
|
return effects->compositingType() == XRenderCompositing ||
|
||||||
(effects->isOpenGLCompositing() && GLRenderTarget::supported());
|
(effects->isOpenGLCompositing() && GLRenderTarget::supported());
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreenShotEffect::ScreenShotEffect()
|
ScreenShotEffect::ScreenShotEffect()
|
||||||
|
@ -241,9 +243,9 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
|
||||||
if (window->hasDecoration() && (screenshot->flags & ScreenShotIncludeDecoration)) {
|
if (window->hasDecoration() && (screenshot->flags & ScreenShotIncludeDecoration)) {
|
||||||
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
||||||
// we need this loop to include the decoration padding
|
// 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 (window->hasDecoration()) {
|
} else if (window->hasDecoration()) {
|
||||||
|
@ -255,9 +257,9 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
|
||||||
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
||||||
if (quad.type() == WindowQuadContents) {
|
if (quad.type() == WindowQuadContents) {
|
||||||
newQuads << quad;
|
newQuads << quad;
|
||||||
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -296,11 +298,12 @@ void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot)
|
||||||
|
|
||||||
// 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);
|
||||||
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<GLvoid *>(img.bits()));
|
||||||
GLRenderTarget::popRenderTarget();
|
GLRenderTarget::popRenderTarget();
|
||||||
convertFromGLImage(img, width, height);
|
convertFromGLImage(img, width, height);
|
||||||
}
|
}
|
||||||
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
#if defined(KWIN_HAVE_XRENDER_COMPOSITING)
|
||||||
if (effects->compositingType() == XRenderCompositing) {
|
if (effects->compositingType() == XRenderCompositing) {
|
||||||
setXRenderOffscreen(true);
|
setXRenderOffscreen(true);
|
||||||
effects->drawWindow(window, mask, QRegion(0, 0, width, height), d);
|
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;
|
QImage image;
|
||||||
if (effects->isOpenGLCompositing())
|
|
||||||
{
|
if (effects->isOpenGLCompositing()) {
|
||||||
const QSize nativeSize = geometry.size() * scale;
|
const QSize nativeSize = geometry.size() * devicePixelRatio;
|
||||||
|
|
||||||
if (GLRenderTarget::blitSupported() && !GLPlatform::instance()->isGLES()) {
|
if (GLRenderTarget::blitSupported() && !GLPlatform::instance()->isGLES()) {
|
||||||
|
image = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32);
|
||||||
img = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32);
|
GLTexture texture(GL_RGBA8, nativeSize.width(), nativeSize.height());
|
||||||
GLTexture tex(GL_RGBA8, nativeSize.width(), nativeSize.height());
|
GLRenderTarget target(texture);
|
||||||
GLRenderTarget target(tex);
|
|
||||||
target.blitFromFramebuffer(geometry);
|
target.blitFromFramebuffer(geometry);
|
||||||
// copy content from framebuffer into image
|
// copy content from framebuffer into image
|
||||||
tex.bind();
|
texture.bind();
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(img.bits()));
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||||
tex.unbind();
|
static_cast<GLvoid *>(image.bits()));
|
||||||
|
texture.unbind();
|
||||||
} else {
|
} else {
|
||||||
img = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32);
|
image = QImage(nativeSize.width(), nativeSize.height(), QImage::Format_ARGB32);
|
||||||
glReadPixels(0, 0, nativeSize.width(), nativeSize.height(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
|
glReadPixels(0, 0, nativeSize.width(), nativeSize.height(), GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE, static_cast<GLvoid *>(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) {
|
if (effects->compositingType() == XRenderCompositing) {
|
||||||
img = xPictureToImage(effects->xrenderBufferPicture(), geometry);
|
image = xPictureToImage(effects->xrenderBufferPicture(), geometry);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
img.setDevicePixelRatio(scale);
|
image.setDevicePixelRatio(devicePixelRatio);
|
||||||
return img;
|
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();
|
const PlatformCursorImage cursor = effects->cursorImage();
|
||||||
if (cursor.image().isNull())
|
if (cursor.image().isNull()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QPainter painter(&snapshot);
|
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
|
bool ScreenShotEffect::isActive() const
|
||||||
|
@ -491,4 +496,4 @@ void ScreenShotEffect::handleWindowClosed(EffectWindow *window)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace KWin
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later
|
SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef KWIN_SCREENSHOT_H
|
#pragma once
|
||||||
#define KWIN_SCREENSHOT_H
|
|
||||||
|
|
||||||
#include <kwineffects.h>
|
#include <kwineffects.h>
|
||||||
|
|
||||||
|
@ -37,7 +36,12 @@ struct ScreenShotAreaData;
|
||||||
struct ScreenShotScreenData;
|
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
|
class ScreenShotEffect : public Effect
|
||||||
{
|
{
|
||||||
|
@ -88,8 +92,8 @@ private:
|
||||||
void cancelAreaScreenShots();
|
void cancelAreaScreenShots();
|
||||||
void cancelScreenScreenShots();
|
void cancelScreenScreenShots();
|
||||||
|
|
||||||
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
|
void grabPointerImage(QImage &snapshot, int xOffset, int yOffset) const;
|
||||||
QImage blitScreenshot(const QRect &geometry, const qreal scale = 1.0);
|
QImage blitScreenshot(const QRect &geometry, qreal devicePixelRatio = 1.0) const;
|
||||||
|
|
||||||
QVector<ScreenShotWindowData> m_windowScreenShots;
|
QVector<ScreenShotWindowData> m_windowScreenShots;
|
||||||
QVector<ScreenShotAreaData> m_areaScreenShots;
|
QVector<ScreenShotAreaData> m_areaScreenShots;
|
||||||
|
@ -99,8 +103,6 @@ private:
|
||||||
EffectScreen *m_paintedScreen = nullptr;
|
EffectScreen *m_paintedScreen = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace KWin
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScreenShotFlags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScreenShotFlags)
|
||||||
|
|
||||||
#endif // KWIN_SCREENSHOT_H
|
|
||||||
|
|
Loading…
Reference in a new issue