#pragma once #include #include #include #include #include #include class OSRThread; class Renderer : public QObject { Q_OBJECT Q_PROPERTY(QString id READ id CONSTANT) Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) Q_PROPERTY(int processInterval READ processInterval WRITE setProcessInterval NOTIFY processIntervalChanged) Q_PROPERTY(int renderInterval READ renderInterval WRITE setRenderInterval NOTIFY renderIntervalChanged) Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int height READ height NOTIFY heightChanged) public: Renderer(const QString renderId, qint64 friendProcessPid, int renderInterval); // Q_PROPERTY members start QString id() const; QUrl url() const; void setUrl(const QUrl &url); Q_SIGNAL void urlChanged(); int processInterval() const; void setProcessInterval(int processInterval); Q_SIGNAL void processIntervalChanged(); int renderInterval() const; void setRenderInterval(int renderInterval); Q_SIGNAL void renderIntervalChanged(); int width() const; Q_SIGNAL void widthChanged(); int height() const; Q_SIGNAL void heightChanged(); // Q_PROPERTY members end Q_SLOT void start(int initialWidth, int initialHeight, QUrl initialUrl); /** * Call to signal to the Renderer that it is no longer required and can * stop Rendering. * * Pass quit as true to also request that the QCoreApplication quits. **/ Q_SLOT void stop(bool quit); /** * Resizes the renderers offscreen window. **/ Q_SLOT void resize(int width, int height); /** * Send a QEvent to the renderer to be forwarded to the offscreen windows * content item. **/ Q_SLOT void sendMousePressEvent(QEvent::Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); /** * @brief exec: * Enters a QCoreApplication::processEvents while loop with a process * interval set by processInterval. **/ void exec(); /** * @brief getSharedTextureHandle: * Returns a valid handle to the underlying native texture for use * by the process with the provided pid. If the pid was not specified * as a friend process during startup (see -p cmd argument) or if an * error occured then -1 will be returned instead. It is up to the * underlying implementation to make sure the shared texture handles * can only be used by the associated process. It is the callers * responsibility to close the provided handle if valid. * * @param pid: * The process identifier for the process requesting the shared * handle. * * @return A texture handle for use with the requested process or -1. **/ Q_SLOT qint64 getSharedTextureHandle(qint64 pid) const; /** * Emitted any time the shared texture handle has changed (i.e. after * resizing the renderer). **/ Q_SIGNAL void sharedTextureHandleChanged(); protected: bool event(QEvent *e) override; private: Q_SLOT void handleRenderRequested(); Q_SLOT void handleSceneChanged(); Q_SLOT void handleAboutToQuit(); QString m_renderId; qint64 m_friendProcessPid; bool m_alive{true}; int m_processInterval{5}; OSRThread *m_osrThread; bool m_polishSyncRequired{false}; QTimer m_updateTimer; };