| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 |
|
| 4 |
#ifndef QEGLFSCURSOR_H |
| 5 |
#define QEGLFSCURSOR_H |
| 6 |
|
| 7 |
// |
| 8 |
// W A R N I N G |
| 9 |
// ------------- |
| 10 |
// |
| 11 |
// This file is not part of the Qt API. It exists purely as an |
| 12 |
// implementation detail. This header file may change from version to |
| 13 |
// version without notice, or even be removed. |
| 14 |
// |
| 15 |
// We mean it. |
| 16 |
// |
| 17 |
|
| 18 |
#include "qeglfsglobal_p.h" |
| 19 |
#include <qpa/qplatformcursor.h> |
| 20 |
#include <qpa/qplatformscreen.h> |
| 21 |
#include <QtOpenGL/QOpenGLShaderProgram> |
| 22 |
#include <QtGui/QMatrix4x4> |
| 23 |
#include <QtGui/private/qinputdevicemanager_p.h> |
| 24 |
|
| 25 |
#include <QtCore/qlist.h> |
| 26 |
|
| 27 |
QT_BEGIN_NAMESPACE |
| 28 |
|
| 29 |
class QOpenGLShaderProgram; |
| 30 |
class QEglFSCursor; |
| 31 |
class QEglFSScreen; |
| 32 |
|
| 33 |
class QEglFSCursorDeviceListener : public QObject |
| 34 |
{ |
| 35 |
Q_OBJECT |
| 36 |
|
| 37 |
public: |
| 38 |
QEglFSCursorDeviceListener(QEglFSCursor *cursor) : m_cursor(cursor) { } |
| 39 |
bool hasMouse() const; |
| 40 |
|
| 41 |
public slots: |
| 42 |
void onDeviceListChanged(QInputDeviceManager::DeviceType type); |
| 43 |
|
| 44 |
private: |
| 45 |
QEglFSCursor *m_cursor; |
| 46 |
}; |
| 47 |
|
| 48 |
#if QT_CONFIG(opengl) |
| 49 |
|
| 50 |
struct QEglFSCursorData { |
| 51 |
QScopedPointer<QOpenGLShaderProgram> program; |
| 52 |
int textureEntry = 0; |
| 53 |
int matEntry = 0; |
| 54 |
uint customCursorTexture = 0; |
| 55 |
uint atlasTexture = 0; |
| 56 |
qint64 customCursorKey = 0; |
| 57 |
}; |
| 58 |
|
| 59 |
class Q_EGLFS_EXPORT QEglFSCursor : public QPlatformCursor |
| 60 |
{ |
| 61 |
Q_OBJECT |
| 62 |
public: |
| 63 |
QEglFSCursor(QPlatformScreen *screen); |
| 64 |
~QEglFSCursor(); |
| 65 |
|
| 66 |
#ifndef QT_NO_CURSOR |
| 67 |
void changeCursor(QCursor *cursor, QWindow *widget) override; |
| 68 |
#endif |
| 69 |
void pointerEvent(const QMouseEvent &event) override; |
| 70 |
QPoint pos() const override; |
| 71 |
void setPos(const QPoint &pos) override; |
| 72 |
|
| 73 |
QRect cursorRect() const; |
| 74 |
void paintOnScreen(); |
| 75 |
void resetResources(); |
| 76 |
|
| 77 |
void updateMouseStatus(); |
| 78 |
|
| 79 |
private: |
| 80 |
bool event(QEvent *e) override; |
| 81 |
#ifndef QT_NO_CURSOR |
| 82 |
bool setCurrentCursor(QCursor *cursor); |
| 83 |
#endif |
| 84 |
void draw(const QRectF &rect); |
| 85 |
void update(const QRect &rect, bool allScreens); |
| 86 |
void createShaderPrograms(); |
| 87 |
void createCursorTexture(uint *texture, const QImage &image); |
| 88 |
void initCursorAtlas(); |
| 89 |
|
| 90 |
// current cursor information |
| 91 |
struct Cursor { |
| 92 |
Cursor() : shape(Qt::BlankCursor), customCursorPending(false), customCursorKey(0), useCustomCursor(false) { } |
| 93 |
Qt::CursorShape shape; |
| 94 |
QRectF textureRect; // normalized rect inside texture |
| 95 |
QSize size; // size of the cursor |
| 96 |
QPoint hotSpot; |
| 97 |
QImage customCursorImage; |
| 98 |
QPoint pos; // current cursor position |
| 99 |
bool customCursorPending; |
| 100 |
qint64 customCursorKey; |
| 101 |
bool useCustomCursor; |
| 102 |
} m_cursor; |
| 103 |
|
| 104 |
// cursor atlas information |
| 105 |
struct CursorAtlas { |
| 106 |
CursorAtlas() : cursorsPerRow(0), cursorWidth(0), cursorHeight(0) { } |
| 107 |
int cursorsPerRow; |
| 108 |
int width, height; // width and height of the atlas |
| 109 |
int cursorWidth, cursorHeight; // width and height of cursors inside the atlas |
| 110 |
QList<QPoint> hotSpots; |
| 111 |
QImage image; // valid until it's uploaded |
| 112 |
} m_cursorAtlas; |
| 113 |
|
| 114 |
bool m_visible; |
| 115 |
QEglFSScreen *m_screen; |
| 116 |
QPlatformScreen *m_activeScreen; |
| 117 |
QEglFSCursorDeviceListener *m_deviceListener; |
| 118 |
bool m_updateRequested; |
| 119 |
QMatrix4x4 m_rotationMatrix; |
| 120 |
}; |
| 121 |
#endif // QT_CONFIG(opengl) |
| 122 |
|
| 123 |
QT_END_NAMESPACE |
| 124 |
|
| 125 |
#endif // QEGLFSCURSOR_H |