summaryrefslogtreecommitdiffstats
path: root/src/plugins/multimedia/qnx/common/qqnxwindowgrabber_p.h
blob: 1ffd96b634095c50ab6990f0a7ecaabc0be8b2da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (C) 2016 Research In Motion
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQnxWindowGrabber_H
#define QQnxWindowGrabber_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#define EGL_EGLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/eglext.h>
#include <QAbstractNativeEventFilter>
#include <QObject>
#include <QSize>
#include <QTimer>

#include <memory>

#include <screen/screen.h>

QT_BEGIN_NAMESPACE

class QRhi;
class QQnxWindowGrabberImage;

class QQnxWindowGrabber : public QObject, public QAbstractNativeEventFilter
{
    Q_OBJECT

public:
    struct BufferView
    {
        int width = -1;
        int height = -1;
        int stride = -1;

        unsigned char *data = nullptr;

        static constexpr int pixelSize = 4; // BGRX8888;
    };

    explicit QQnxWindowGrabber(QObject *parent = 0);
    ~QQnxWindowGrabber();

    void setFrameRate(int frameRate);

    void setWindowId(const QByteArray &windowId);

    void setRhi(QRhi *rhi);

    void start();
    void stop();

    void pause();
    void resume();

    void forceUpdate();

    bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;

    bool handleScreenEvent(screen_event_t event);

    QByteArray windowGroupId() const;

    bool isEglImageSupported() const;

    int getNextTextureId();
    BufferView getNextBuffer();

signals:
    void updateScene(const QSize &size);

private slots:
    void triggerUpdate();

private:
    bool selectBuffer();
    void resetBuffers();
    void checkForEglImageExtension();

    QTimer m_timer;

    QByteArray m_windowId;

    screen_window_t m_windowParent;
    screen_window_t m_window;
    screen_context_t m_screenContext;

    std::unique_ptr<QQnxWindowGrabberImage> m_frontBuffer;
    std::unique_ptr<QQnxWindowGrabberImage> m_backBuffer;

    QSize m_size;

    QRhi *m_rhi;

    bool m_active;
    bool m_eglImageSupported;
    bool m_startPending;
};

QT_END_NAMESPACE

#endif