|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <QObject> |
| 4 | + |
| 5 | +// DirectX 9 header |
| 6 | +#include <d3d9.h> |
| 7 | +#include <d3dx9.h> |
| 8 | + |
| 9 | +// Hyperion-utils includes |
| 10 | +#include <utils/ColorRgb.h> |
| 11 | +#include <hyperion/Grabber.h> |
| 12 | + |
| 13 | +/// |
| 14 | +/// @brief The DirectX9 capture implementation |
| 15 | +/// |
| 16 | +class DirectXGrabber : public Grabber |
| 17 | +{ |
| 18 | +public: |
| 19 | + |
| 20 | + DirectXGrabber(int cropLeft, int cropRight, int cropTop, int cropBottom, int pixelDecimation, int display); |
| 21 | + |
| 22 | + virtual ~DirectXGrabber(); |
| 23 | + |
| 24 | + /// |
| 25 | + /// Captures a single snapshot of the display and writes the data to the given image. The |
| 26 | + /// provided image should have the same dimensions as the configured values (_width and |
| 27 | + /// _height) |
| 28 | + /// |
| 29 | + /// @param[out] image The snapped screenshot |
| 30 | + /// |
| 31 | + virtual int grabFrame(Image<ColorRgb> & image); |
| 32 | + |
| 33 | + /// |
| 34 | + /// @brief Set a new video mode |
| 35 | + /// |
| 36 | + virtual void setVideoMode(VideoMode mode); |
| 37 | + |
| 38 | + /// |
| 39 | + /// @brief Apply new width/height values, overwrite Grabber.h implementation |
| 40 | + /// |
| 41 | + virtual bool setWidthHeight(int width, int height) { return true; }; |
| 42 | + |
| 43 | + /// |
| 44 | + /// @brief Apply new pixelDecimation |
| 45 | + /// |
| 46 | + virtual void setPixelDecimation(int pixelDecimation); |
| 47 | + |
| 48 | + /// |
| 49 | + /// Set the crop values |
| 50 | + /// @param cropLeft Left pixel crop |
| 51 | + /// @param cropRight Right pixel crop |
| 52 | + /// @param cropTop Top pixel crop |
| 53 | + /// @param cropBottom Bottom pixel crop |
| 54 | + /// |
| 55 | + virtual void setCropping(unsigned cropLeft, unsigned cropRight, unsigned cropTop, unsigned cropBottom); |
| 56 | + |
| 57 | +private: |
| 58 | + /// |
| 59 | + /// @brief Setup a new capture display, will free the previous one |
| 60 | + /// @return True on success, false if no display is found |
| 61 | + /// |
| 62 | + bool setupDisplay(); |
| 63 | + |
| 64 | + /// |
| 65 | + /// @brief free the _screen pointer |
| 66 | + /// |
| 67 | + void freeResources(); |
| 68 | + |
| 69 | +private: |
| 70 | + int _pixelDecimation; |
| 71 | + unsigned _displayWidth; |
| 72 | + unsigned _displayHeight; |
| 73 | + RECT* _srcRect; |
| 74 | + |
| 75 | + IDirect3D9* _d3d9; |
| 76 | + IDirect3DDevice9* _device; |
| 77 | + IDirect3DSurface9* _surface; |
| 78 | + IDirect3DSurface9* _surfaceDest; |
| 79 | +}; |
0 commit comments