6#include <QAbstractEventDispatcher>
8#include <QGuiApplication>
11#include <qpa/qplatformnativeinterface.h>
13#include <QOpenGLContext>
14#include <QOpenGLFunctions>
34 bool initialize(screen_context_t screenContext);
40 bool grab(screen_window_t
window);
44 screen_pixmap_t m_pixmap;
45 screen_buffer_t m_pixmapBuffer;
48 unsigned char *m_bufferAddress;
59 m_eglImageSupported(
false),
73 s_eglCreateImageKHR =
reinterpret_cast<PFNEGLCREATEIMAGEKHRPROC
>(eglGetProcAddress(
"eglCreateImageKHR"));
74 s_eglDestroyImageKHR =
reinterpret_cast<PFNEGLDESTROYIMAGEKHRPROC
>(eglGetProcAddress(
"eglDestroyImageKHR"));
78 if (nativeInterface) {
79 m_screenContext =
static_cast<screen_context_t
>(
89 screen_create_window(&m_windowParent, m_screenContext);
90 screen_create_window_group(m_windowParent,
nullptr);
95 screen_destroy_window(m_windowParent);
106 m_windowId = windowId;
113 checkForEglImageExtension();
122 m_startPending =
true;
126 m_startPending =
false;
128 if (!m_screenContext)
129 screen_get_window_property_pv(m_window, SCREEN_PROPERTY_CONTEXT,
reinterpret_cast<void**
>(&m_screenContext));
173 if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
174 qWarning() <<
"QQnxWindowGrabber: Failed to query screen event type";
178 if (eventType != SCREEN_EVENT_CREATE)
181 screen_window_t
window = 0;
182 if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (
void**)&
window) != 0) {
183 qWarning() <<
"QQnxWindowGrabber: Failed to query window property";
187 const int maxIdStrLength = 128;
188 char idString[maxIdStrLength];
189 if (screen_get_window_property_cv(
window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
190 qWarning() <<
"QQnxWindowGrabber: Failed to query window ID string";
195 if (idString[0] !=
'\0' && m_windowId == idString) {
207 if (eventType ==
"screen_event_t") {
208 const screen_event_t
event =
static_cast<screen_event_t
>(
message);
218 memset(groupName, 0,
sizeof(groupName));
219 screen_get_window_property_cv(m_windowParent,
220 SCREEN_PROPERTY_GROUP,
221 sizeof(groupName) - 1,
228 return m_eglImageSupported;
231void QQnxWindowGrabber::checkForEglImageExtension()
233 m_eglImageSupported =
false;
238 const EGLDisplay defaultDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
240 const char *vendor = eglQueryString(defaultDisplay, EGL_VENDOR);
242 if (vendor && std::strstr(vendor,
"VMWare"))
245 const char *eglExtensions = eglQueryString(defaultDisplay, EGL_EXTENSIONS);
250 m_eglImageSupported = std::strstr(eglExtensions,
"EGL_KHR_image")
255void QQnxWindowGrabber::triggerUpdate()
257 int size[2] = { 0, 0 };
259 const int result = screen_get_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE,
size);
263 qWarning() <<
"QQnxWindowGrabber: cannot get window size:" << strerror(errno);
273bool QQnxWindowGrabber::selectBuffer()
278 std::swap(m_frontBuffer, m_backBuffer);
283 auto frontBuffer = std::make_unique<QQnxWindowGrabberImage>();
285 if (!frontBuffer->initialize(m_screenContext))
288 m_frontBuffer = std::move(frontBuffer);
298 return m_frontBuffer->getTexture(m_window, m_size);
306 return m_frontBuffer->getBuffer(m_window, m_size);
309void QQnxWindowGrabber::resetBuffers()
311 m_frontBuffer.reset();
312 m_backBuffer.reset();
328 glDeleteTextures(1, &m_glTexture);
332 screen_destroy_pixmap(m_pixmap);
337 if (screen_create_pixmap(&m_pixmap, screenContext) != 0) {
338 qWarning() <<
"QQnxWindowGrabber: cannot create pixmap:" << strerror(errno);
341 const int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
342 screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_USAGE, &
usage);
348 const int format = SCREEN_FORMAT_RGBX8888;
349 screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_FORMAT, &
format);
354bool QQnxWindowGrabberImage::resize(
const QSize &newSize)
356 if (m_pixmapBuffer) {
357 screen_destroy_pixmap_buffer(m_pixmap);
365 screen_set_pixmap_property_iv(m_pixmap, SCREEN_PROPERTY_BUFFER_SIZE,
size);
367 if (screen_create_pixmap_buffer(m_pixmap) == 0) {
368 screen_get_pixmap_property_pv(m_pixmap, SCREEN_PROPERTY_RENDER_BUFFERS,
369 reinterpret_cast<void**
>(&m_pixmapBuffer));
370 screen_get_buffer_property_pv(m_pixmapBuffer, SCREEN_PROPERTY_POINTER,
371 reinterpret_cast<void**
>(&m_bufferAddress));
372 screen_get_buffer_property_iv(m_pixmapBuffer, SCREEN_PROPERTY_STRIDE, &m_bufferStride);
382bool QQnxWindowGrabberImage::grab(screen_window_t
window)
385 return screen_read_window(
window, m_pixmapBuffer, 1,
rect, 0) == 0;
391 if (
size != m_size && !resize(
size))
394 if (!m_bufferAddress || !grab(
window))
399 .height = m_size.
height(),
400 .stride = m_bufferStride,
401 .data = m_bufferAddress
407 if (
size != m_size) {
411 glDeleteTextures(1, &m_glTexture);
412 glGenTextures(1, &m_glTexture);
414 glBindTexture(GL_TEXTURE_2D, m_glTexture);
416 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, 0);
423 EGL_NATIVE_PIXMAP_KHR, m_pixmap, 0);
424 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, m_eglImage);
427 if (!m_pixmap || !grab(
window))
435#include "moc_qqnxwindowgrabber_p.cpp"
void installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
\variable QAbstractEventDispatcher::TimerInfo::timerId
void removeNativeEventFilter(QAbstractNativeEventFilter *filterObj)
Removes the event filter filter from this object.
static QAbstractEventDispatcher * eventDispatcher()
Returns a pointer to the event dispatcher object for the main thread.
static QPlatformNativeInterface * platformNativeInterface()
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
~QQnxWindowGrabberImage()
bool initialize(screen_context_t screenContext)
GLuint getTexture(screen_window_t window, const QSize &size)
QQnxWindowGrabber::BufferView getBuffer(screen_window_t window, const QSize &size)
QQnxWindowGrabber(QObject *parent=0)
bool isEglImageSupported() const
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override
This method is called for every native event.
BufferView getNextBuffer()
void setWindowId(const QByteArray &windowId)
bool handleScreenEvent(screen_event_t event)
QByteArray windowGroupId() const
void updateScene(const QSize &size)
void setFrameRate(int frameRate)
Implementation backend() const
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
void start(int msec)
Starts or restarts the timer with a timeout interval of msec milliseconds.
void setInterval(int msec)
void stop()
Stops the timer.
void timeout(QPrivateSignal)
This signal is emitted when the timer times out.
Combined button and popup list for selecting options.
typedef EGLDisplay(EGLAPIENTRYP PFNEGLGETPLATFORMDISPLAYEXTPROC)(EGLenum platform
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum format
GLsizeiptr const void GLenum usage
static PFNEGLDESTROYIMAGEKHRPROC s_eglDestroyImageKHR
static QT_BEGIN_NAMESPACE PFNEGLCREATEIMAGEKHRPROC s_eglCreateImageKHR
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static int toInt(const QChar &qc, int R)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent