| 1 |
// Copyright (C) 2015 Pier Luigi Fiorini <[email protected]> |
| 2 |
// Copyright (C) 2017 The Qt Company Ltd. |
| 3 |
// Copyright (C) 2016 Pelagicore AG |
| 4 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 5 |
|
| 6 |
#ifndef QEGLFSKMSVSP2SCREEN_H |
| 7 |
#define QEGLFSKMSVSP2SCREEN_H |
| 8 |
|
| 9 |
#include "qeglfskmsscreen_p.h" |
| 10 |
#include "qvsp2blendingdevice.h" |
| 11 |
#include <QtCore/QMutex> |
| 12 |
|
| 13 |
#include <qpa/qplatformscreen_p.h> |
| 14 |
|
| 15 |
#include <gbm.h> |
| 16 |
|
| 17 |
QT_BEGIN_NAMESPACE |
| 18 |
|
| 19 |
class QEglFSKmsVsp2Screen : public QEglFSKmsScreen |
| 20 |
, public QNativeInterface::Private::QVsp2Screen |
| 21 |
{ |
| 22 |
public: |
| 23 |
QEglFSKmsVsp2Screen(QEglFSKmsDevice *device, const QKmsOutput &output); |
| 24 |
|
| 25 |
gbm_surface *createSurface(); |
| 26 |
void resetSurface(); |
| 27 |
|
| 28 |
void initDumbFrameBuffers(); |
| 29 |
void initVsp2(); |
| 30 |
void initQtLayer(); |
| 31 |
|
| 32 |
//TODO: use a fixed index API instead of auto increment? |
| 33 |
int addLayer(int dmabufFd, const QSize &size, const QPoint &position, uint drmPixelFormat, uint bytesPerLine) override; |
| 34 |
void setLayerBuffer(int id, int dmabufFd) override; |
| 35 |
void setLayerPosition(int id, const QPoint &position) override; |
| 36 |
void setLayerAlpha(int id, qreal alpha) override; |
| 37 |
bool removeLayer(int id) override; |
| 38 |
void addBlendListener(void (*callback)()) override; |
| 39 |
|
| 40 |
void flip(); |
| 41 |
void blendAndFlipDrm(); |
| 42 |
|
| 43 |
private: |
| 44 |
class Blender : public QObject // This is a workaround we really would want the screen to be a QObject |
| 45 |
{ |
| 46 |
public: |
| 47 |
Blender(QEglFSKmsVsp2Screen *screen) : m_screen(screen) {} |
| 48 |
~Blender() override {} |
| 49 |
bool event(QEvent *event) override; |
| 50 |
QEglFSKmsVsp2Screen *m_screen = nullptr; |
| 51 |
}; |
| 52 |
QScopedArrayPointer<Blender> m_blender; |
| 53 |
|
| 54 |
gbm_surface *m_gbmSurface = nullptr; |
| 55 |
gbm_bo *m_currentGbmBo = nullptr; |
| 56 |
gbm_bo *m_nextGbmBo = nullptr; |
| 57 |
|
| 58 |
QScopedPointer<QVsp2BlendingDevice> m_blendDevice; |
| 59 |
|
| 60 |
struct FrameBuffer { //these are for buffers that have been blended by the bru |
| 61 |
uint32_t drmBufferId = 0; |
| 62 |
int dmabufFd = -1; |
| 63 |
}; |
| 64 |
std::array<FrameBuffer, 2> m_frameBuffers; |
| 65 |
uint m_backFb = 0; |
| 66 |
void initDumbFrameBuffer(FrameBuffer &fb); |
| 67 |
QList<void (*)()> m_blendFinishedCallbacks; |
| 68 |
|
| 69 |
struct DmaBuffer { //these are for qt buffers before blending with additional layers (gbm buffer data) |
| 70 |
int dmabufFd = -1; |
| 71 |
}; |
| 72 |
static void dmaBufferDestroyedHandler(gbm_bo *gbmBo, void *data); |
| 73 |
DmaBuffer *dmaBufferForGbmBuffer(gbm_bo *gbmBo); |
| 74 |
|
| 75 |
void ensureModeSet(); |
| 76 |
void doDrmFlip(); |
| 77 |
|
| 78 |
bool m_blendScheduled = false; |
| 79 |
int m_qtLayer = 0; //TODO: add API for changing this |
| 80 |
}; |
| 81 |
|
| 82 |
QT_END_NAMESPACE |
| 83 |
|
| 84 |
#endif // QEGLFSKMSVSP2SCREEN_H |