1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> 4 ** Copyright (C) 2017 The Qt Company Ltd. 5 ** Copyright (C) 2016 Pelagicore AG 6 ** Contact: https://www.qt.io/licensing/ 7 ** 8 ** This file is part of the plugins of the Qt Toolkit. 9 ** 10 ** $QT_BEGIN_LICENSE:LGPL$ 11 ** Commercial License Usage 12 ** Licensees holding valid commercial Qt licenses may use this file in 13 ** accordance with the commercial license agreement provided with the 14 ** Software or, alternatively, in accordance with the terms contained in 15 ** a written agreement between you and The Qt Company. For licensing terms 16 ** and conditions see https://www.qt.io/terms-conditions. For further 17 ** information use the contact form at https://www.qt.io/contact-us. 18 ** 19 ** GNU Lesser General Public License Usage 20 ** Alternatively, this file may be used under the terms of the GNU Lesser 21 ** General Public License version 3 as published by the Free Software 22 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 23 ** packaging of this file. Please review the following information to 24 ** ensure the GNU Lesser General Public License version 3 requirements 25 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 26 ** 27 ** GNU General Public License Usage 28 ** Alternatively, this file may be used under the terms of the GNU 29 ** General Public License version 2.0 or (at your option) the GNU General 30 ** Public license version 3 or any later version approved by the KDE Free 31 ** Qt Foundation. The licenses are as published by the Free Software 32 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 33 ** included in the packaging of this file. Please review the following 34 ** information to ensure the GNU General Public License requirements will 35 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 36 ** https://www.gnu.org/licenses/gpl-3.0.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef QEGLFSKMSVSP2SCREEN_H 43 #define QEGLFSKMSVSP2SCREEN_H 44 45 #include "qeglfskmsscreen.h" 46 #include "qvsp2blendingdevice.h" 47 #include <QtCore/QMutex> 48 49 #include <gbm.h> 50 51 QT_BEGIN_NAMESPACE 52 53 class QEglFSKmsVsp2Screen : public QEglFSKmsScreen 54 { 55 public: 56 QEglFSKmsVsp2Screen(QEglFSKmsDevice *device, const QKmsOutput &output); 57 58 gbm_surface *createSurface(); 59 void resetSurface(); 60 61 void initDumbFrameBuffers(); 62 void initVsp2(); 63 void initQtLayer(); 64 65 //TODO: use a fixed index API instead of auto increment? 66 int addLayer(int dmabufFd, const QSize &size, const QPoint &position, uint drmPixelFormat, uint bytesPerLine); 67 void setLayerBuffer(int id, int dmabufFd); 68 void setLayerPosition(int id, const QPoint &position); 69 void setLayerAlpha(int id, qreal alpha); 70 bool removeLayer(int id); 71 void addBlendListener(void (*callback)()); 72 73 void flip(); 74 void blendAndFlipDrm(); 75 76 private: 77 class Blender : public QObject // This is a workaround we really would want the screen to be a QObject 78 { 79 public: Blender(QEglFSKmsVsp2Screen * screen)80 Blender(QEglFSKmsVsp2Screen *screen) : m_screen(screen) {} ~Blender()81 ~Blender() override {} 82 bool event(QEvent *event) override; 83 QEglFSKmsVsp2Screen *m_screen = nullptr; 84 }; 85 QScopedArrayPointer<Blender> m_blender; 86 87 gbm_surface *m_gbmSurface = nullptr; 88 gbm_bo *m_currentGbmBo = nullptr; 89 gbm_bo *m_nextGbmBo = nullptr; 90 91 QScopedPointer<QVsp2BlendingDevice> m_blendDevice; 92 93 struct FrameBuffer { //these are for buffers that have been blended by the bru 94 uint32_t drmBufferId = 0; 95 int dmabufFd = -1; 96 }; 97 std::array<FrameBuffer, 2> m_frameBuffers; 98 uint m_backFb = 0; 99 void initDumbFrameBuffer(FrameBuffer &fb); 100 QVector<void (*)()> m_blendFinishedCallbacks; 101 102 struct DmaBuffer { //these are for qt buffers before blending with additional layers (gbm buffer data) 103 int dmabufFd = -1; 104 }; 105 static void dmaBufferDestroyedHandler(gbm_bo *gbmBo, void *data); 106 DmaBuffer *dmaBufferForGbmBuffer(gbm_bo *gbmBo); 107 108 void ensureModeSet(); 109 void doDrmFlip(); 110 111 bool m_blendScheduled = false; 112 int m_qtLayer = 0; //TODO: add API for changing this 113 }; 114 115 QT_END_NAMESPACE 116 117 #endif // QEGLFSKMSVSP2SCREEN_H 118