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 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 QPAINTERVIDEOSURFACE_P_H
41#define QPAINTERVIDEOSURFACE_P_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 <qtmultimediawidgetdefs.h>
55#include <QtCore/qsize.h>
56#include <QtGui/qimage.h>
57#include <QtGui/qmatrix4x4.h>
58#include <QtGui/qpaintengine.h>
59#include <qabstractvideosurface.h>
60#include <qvideoframe.h>
61
62QT_USE_NAMESPACE
63
64QT_BEGIN_NAMESPACE
65
66class Q_AUTOTEST_EXPORT QVideoSurfacePainter
67{
68public:
69 virtual ~QVideoSurfacePainter();
70
71 virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats(
72 QAbstractVideoBuffer::HandleType handleType) const = 0;
73
74 virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const = 0;
75
76 virtual QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) = 0;
77 virtual void stop() = 0;
78
79 virtual QAbstractVideoSurface::Error setCurrentFrame(const QVideoFrame &frame) = 0;
80
81 virtual QAbstractVideoSurface::Error paint(
82 const QRectF &target, QPainter *painter, const QRectF &source) = 0;
83
84 virtual void updateColors(int brightness, int contrast, int hue, int saturation) = 0;
85 virtual void viewportDestroyed() {}
86};
87
88class QOpenGLContext;
89class Q_AUTOTEST_EXPORT QPainterVideoSurface : public QAbstractVideoSurface
90{
91 Q_OBJECT
92public:
93 explicit QPainterVideoSurface(QObject *parent = 0);
94 ~QPainterVideoSurface();
95
96 QList<QVideoFrame::PixelFormat> supportedPixelFormats(
97 QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const override;
98
99 bool isFormatSupported(const QVideoSurfaceFormat &format) const override;
100
101 bool start(const QVideoSurfaceFormat &format) override;
102 void stop() override;
103
104 bool present(const QVideoFrame &frame) override;
105
106 int brightness() const;
107 void setBrightness(int brightness);
108
109 int contrast() const;
110 void setContrast(int contrast);
111
112 int hue() const;
113 void setHue(int hue);
114
115 int saturation() const;
116 void setSaturation(int saturation);
117
118 bool isReady() const;
119 void setReady(bool ready);
120
121 void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1));
122
123#if QT_CONFIG(opengl)
124 const QOpenGLContext *glContext() const;
125 void updateGLContext();
126
127 enum ShaderType
128 {
129 NoShaders = 0x00,
130 FragmentProgramShader = 0x01,
131 GlslShader = 0x02
132 };
133
134 Q_DECLARE_FLAGS(ShaderTypes, ShaderType)
135
136 ShaderTypes supportedShaderTypes() const;
137
138 ShaderType shaderType() const;
139 void setShaderType(ShaderType type);
140#endif
141
142public Q_SLOTS:
143 void viewportDestroyed();
144
145Q_SIGNALS:
146 void frameChanged();
147
148private:
149 void createPainter();
150
151 QVideoSurfacePainter *m_painter;
152#if QT_CONFIG(opengl)
153 QOpenGLContext *m_glContext;
154 ShaderTypes m_shaderTypes;
155 ShaderType m_shaderType;
156#endif
157 int m_brightness;
158 int m_contrast;
159 int m_hue;
160 int m_saturation;
161
162 QVideoFrame::PixelFormat m_pixelFormat;
163 QSize m_frameSize;
164 QRect m_sourceRect;
165 bool m_colorsDirty;
166 bool m_ready;
167};
168
169#if QT_CONFIG(opengl)
170Q_DECLARE_OPERATORS_FOR_FLAGS(QPainterVideoSurface::ShaderTypes)
171#endif
172
173QT_END_NAMESPACE
174
175
176#endif
177

source code of qtmultimedia/src/multimediawidgets/qpaintervideosurface_p.h