1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QEGLFSCURSOR_H
41#define QEGLFSCURSOR_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include "qeglfsglobal_p.h"
55#include <qpa/qplatformcursor.h>
56#include <qpa/qplatformscreen.h>
57#include <QtGui/QMatrix4x4>
58#include <QtGui/QOpenGLFunctions>
59#include <QtGui/QOpenGLShaderProgram>
60#include <QtGui/private/qinputdevicemanager_p.h>
61
62#include <QtCore/qvector.h>
63
64QT_BEGIN_NAMESPACE
65
66class QOpenGLShaderProgram;
67class QEglFSCursor;
68class QEglFSScreen;
69
70class QEglFSCursorDeviceListener : public QObject
71{
72 Q_OBJECT
73
74public:
75 QEglFSCursorDeviceListener(QEglFSCursor *cursor) : m_cursor(cursor) { }
76 bool hasMouse() const;
77
78public slots:
79 void onDeviceListChanged(QInputDeviceManager::DeviceType type);
80
81private:
82 QEglFSCursor *m_cursor;
83};
84
85#if QT_CONFIG(opengl)
86
87struct QEglFSCursorData {
88 QScopedPointer<QOpenGLShaderProgram> program;
89 int textureEntry = 0;
90 int matEntry = 0;
91 uint customCursorTexture = 0;
92 uint atlasTexture = 0;
93 qint64 customCursorKey = 0;
94};
95
96class Q_EGLFS_EXPORT QEglFSCursor : public QPlatformCursor
97 , protected QOpenGLFunctions
98{
99 Q_OBJECT
100public:
101 QEglFSCursor(QPlatformScreen *screen);
102 ~QEglFSCursor();
103
104#ifndef QT_NO_CURSOR
105 void changeCursor(QCursor *cursor, QWindow *widget) override;
106#endif
107 void pointerEvent(const QMouseEvent &event) override;
108 QPoint pos() const override;
109 void setPos(const QPoint &pos) override;
110
111 QRect cursorRect() const;
112 void paintOnScreen();
113 void resetResources();
114
115 void updateMouseStatus();
116
117private:
118 bool event(QEvent *e) override;
119#ifndef QT_NO_CURSOR
120 bool setCurrentCursor(QCursor *cursor);
121#endif
122 void draw(const QRectF &rect);
123 void update(const QRect &rect, bool allScreens);
124 void createShaderPrograms();
125 void createCursorTexture(uint *texture, const QImage &image);
126 void initCursorAtlas();
127
128 // current cursor information
129 struct Cursor {
130 Cursor() : shape(Qt::BlankCursor), customCursorPending(false), customCursorKey(0), useCustomCursor(false) { }
131 Qt::CursorShape shape;
132 QRectF textureRect; // normalized rect inside texture
133 QSize size; // size of the cursor
134 QPoint hotSpot;
135 QImage customCursorImage;
136 QPoint pos; // current cursor position
137 bool customCursorPending;
138 qint64 customCursorKey;
139 bool useCustomCursor;
140 } m_cursor;
141
142 // cursor atlas information
143 struct CursorAtlas {
144 CursorAtlas() : cursorsPerRow(0), cursorWidth(0), cursorHeight(0) { }
145 int cursorsPerRow;
146 int width, height; // width and height of the atlas
147 int cursorWidth, cursorHeight; // width and height of cursors inside the atlas
148 QVector<QPoint> hotSpots;
149 QImage image; // valid until it's uploaded
150 } m_cursorAtlas;
151
152 bool m_visible;
153 QEglFSScreen *m_screen;
154 QPlatformScreen *m_activeScreen;
155 QEglFSCursorDeviceListener *m_deviceListener;
156 bool m_updateRequested;
157 QMatrix4x4 m_rotationMatrix;
158};
159#endif // QT_CONFIG(opengl)
160
161QT_END_NAMESPACE
162
163#endif // QEGLFSCURSOR_H
164

source code of qtbase/src/plugins/platforms/eglfs/api/qeglfscursor_p.h