2017-08-04 23:08:15 +02:00
|
|
|
#pragma once
|
2020-07-12 09:23:13 +02:00
|
|
|
#include <QAbstractEventDispatcher>
|
|
|
|
#include <QAbstractNativeEventFilter>
|
|
|
|
#include <QCoreApplication>
|
2017-08-04 23:08:15 +02:00
|
|
|
#include <QObject>
|
2014-01-30 13:35:29 +01:00
|
|
|
|
|
|
|
// Hyperion-utils includes
|
|
|
|
#include <utils/ColorRgb.h>
|
2017-08-04 23:08:15 +02:00
|
|
|
#include <hyperion/Grabber.h>
|
|
|
|
|
2014-01-30 13:35:29 +01:00
|
|
|
// X11 includes
|
|
|
|
#include <X11/Xlib.h>
|
2020-07-12 09:23:13 +02:00
|
|
|
#include <X11/extensions/Xrandr.h>
|
2016-01-21 16:39:52 +01:00
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#include <X11/extensions/XShm.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
|
2020-07-12 09:23:13 +02:00
|
|
|
class X11Grabber : public Grabber , public QAbstractNativeEventFilter
|
2014-01-30 13:35:29 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
X11Grabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation);
|
2014-01-30 13:35:29 +01:00
|
|
|
|
2020-07-12 09:19:59 +02:00
|
|
|
~X11Grabber() override;
|
2014-01-30 13:35:29 +01:00
|
|
|
|
2016-01-21 16:39:52 +01:00
|
|
|
bool Setup();
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-07-24 15:18:34 +02:00
|
|
|
///
|
|
|
|
/// Captures a single snapshot of the display and writes the data to the given image. The
|
|
|
|
/// provided image should have the same dimensions as the configured values (_width and
|
|
|
|
/// _height)
|
|
|
|
///
|
|
|
|
/// @param[out] image The snapped screenshot (should be initialized with correct width and
|
|
|
|
/// height)
|
|
|
|
///
|
2017-08-12 07:55:32 +02:00
|
|
|
virtual int grabFrame(Image<ColorRgb> & image, bool forceUpdate=false);
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-07-24 15:18:34 +02:00
|
|
|
///
|
|
|
|
/// update dimension according current screen
|
2017-08-12 07:55:32 +02:00
|
|
|
int updateScreenDimensions(bool force=false);
|
|
|
|
|
|
|
|
virtual void setVideoMode(VideoMode mode);
|
2016-07-24 15:18:34 +02:00
|
|
|
|
2018-12-27 23:11:32 +01:00
|
|
|
///
|
|
|
|
/// @brief Apply new width/height values, overwrite Grabber.h implementation as X11 doesn't use width/height, just pixelDecimation to calc dimensions
|
|
|
|
///
|
2018-12-28 18:12:45 +01:00
|
|
|
virtual bool setWidthHeight(int width, int height) { return true; };
|
2018-12-27 23:11:32 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Apply new pixelDecimation
|
|
|
|
///
|
|
|
|
virtual void setPixelDecimation(int pixelDecimation);
|
|
|
|
|
|
|
|
///
|
|
|
|
/// Set the crop values
|
|
|
|
/// @param cropLeft Left pixel crop
|
|
|
|
/// @param cropRight Right pixel crop
|
|
|
|
/// @param cropTop Top pixel crop
|
|
|
|
/// @param cropBottom Bottom pixel crop
|
|
|
|
///
|
|
|
|
virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom);
|
|
|
|
|
2020-07-12 09:23:13 +02:00
|
|
|
protected:
|
|
|
|
bool nativeEventFilter(const QByteArray & eventType, void * message, long int * result) override;
|
|
|
|
|
2014-01-30 13:35:29 +01:00
|
|
|
private:
|
2020-07-12 09:23:13 +02:00
|
|
|
bool _XShmAvailable, _XShmPixmapAvailable, _XRenderAvailable, _XRandRAvailable;
|
2017-08-04 23:08:15 +02:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
XImage* _xImage;
|
|
|
|
XShmSegmentInfo _shminfo;
|
2014-01-30 13:35:29 +01:00
|
|
|
|
|
|
|
/// Reference to the X11 display (nullptr if not opened)
|
2016-01-21 16:39:52 +01:00
|
|
|
Display* _x11Display;
|
|
|
|
Window _window;
|
|
|
|
XWindowAttributes _windowAttr;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-05-24 19:55:50 +02:00
|
|
|
Pixmap _pixmap;
|
|
|
|
XRenderPictFormat* _srcFormat;
|
|
|
|
XRenderPictFormat* _dstFormat;
|
|
|
|
XRenderPictureAttributes _pictAttr;
|
|
|
|
Picture _srcPicture;
|
|
|
|
Picture _dstPicture;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2020-07-12 09:23:13 +02:00
|
|
|
int _XRandREventBase;
|
|
|
|
|
2016-08-22 11:59:07 +02:00
|
|
|
XTransform _transform;
|
2018-12-27 23:11:32 +01:00
|
|
|
int _pixelDecimation;
|
2014-01-30 13:35:29 +01:00
|
|
|
|
|
|
|
unsigned _screenWidth;
|
|
|
|
unsigned _screenHeight;
|
2017-08-12 07:55:32 +02:00
|
|
|
unsigned _src_x;
|
|
|
|
unsigned _src_y;
|
2014-01-30 13:35:29 +01:00
|
|
|
|
|
|
|
Image<ColorRgb> _image;
|
2018-12-27 23:11:32 +01:00
|
|
|
|
2016-01-21 16:39:52 +01:00
|
|
|
void freeResources();
|
|
|
|
void setupResources();
|
2014-01-30 13:35:29 +01:00
|
|
|
};
|