• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4  */
5 
6 #ifndef CAPTURE_WIN_GL_H
7 #define CAPTURE_WIN_GL_H
8 
9 #ifdef HAVE_QTGL
10 #define GL_GLEXT_PROTOTYPES
11 #define QT_NO_OPENGL_ES_2
12 
13 #include <QtCore>
14 #if QT_VERSION < 0x060000
15 #include <QGLWidget>
16 #include <QGLShader>
17 #include <QGLShaderProgram>
18 #include <QGLFunctions>
19 #else
20 #include <QOpenGLWidget>
21 #include <QOpenGLFunctions>
22 #include <QOpenGLShaderProgram>
23 #endif
24 #endif
25 
26 #include "qv4l2.h"
27 #include "capture-win.h"
28 
29 #include <QResizeEvent>
30 
31 #ifdef HAVE_QTGL
32 
33 // This must be equal to the max number of textures that any shader uses
34 #define MAX_TEXTURES_NEEDED 3
35 
36 #if QT_VERSION < 0x060000
37 class CaptureWinGLEngine : public QGLWidget
38 #else
39 class CaptureWinGLEngine : public QOpenGLWidget, protected QOpenGLFunctions
40 #endif
41 {
42 public:
43 	CaptureWinGLEngine();
44 	~CaptureWinGLEngine();
45 
46 	void stop();
47 	void setFrame(int width, int height, int cropWidth, int cropHeight,
48 		      __u32 format, unsigned char *data, unsigned char *data2,
49 		      unsigned char *data3);
50 	bool hasNativeFormat(__u32 format);
51 	void lockSize(QSize size);
52 	void setColorspace(unsigned colorspace, unsigned xfer_func,
53 			unsigned ycbcr_enc, unsigned quantization, bool is_sdtv);
54 	void setField(unsigned field);
setBlending(bool enable)55 	void setBlending(bool enable) { m_blending = enable; }
56 	void setLinearFilter(bool enable);
57 
58 protected:
59 	void paintGL();
60 	void initializeGL();
61 	void resizeGL(int width, int height);
62 
63 private:
64 	// Colorspace conversion shaders
65 	void shader_YUV(__u32 format);
66 	QString shader_NV12_invariant(__u32 format);
67 	void shader_NV12(__u32 format);
68 	void shader_NV16(__u32 format);
69 	QString shader_NV16_invariant(__u32 format);
70 	void shader_NV24(__u32 format);
71 	QString shader_NV24_invariant(__u32 format);
72 	void shader_RGB(__u32 format);
73 	void shader_Bayer(__u32 format);
74 	void shader_YUV_packed(__u32 format);
75 	void shader_YUY2(__u32 format);
76 	QString shader_YUY2_invariant(__u32 format);
77 	QString codeYUVNormalize();
78 	QString codeRGBNormalize();
79 	QString codeYUV2RGB();
80 	QString codeTransformToLinear();
81 	QString codeColorspaceConversion();
82 	QString codeTransformToNonLinear();
83 
84 	// Colorspace conversion render
85 	void render_RGB(__u32 format);
86 	void render_Bayer(__u32 format);
87 	void render_YUY2(__u32 format);
88 	void render_YUV(__u32 format);
89 	void render_YUV_packed(__u32 format);
90 	void render_NV12(__u32 format);
91 	void render_NV16(__u32 format);
92 	void render_NV24(__u32 format);
93 
94 	void clearShader();
95 	void changeShader();
96 	void paintFrame();
97 	void paintSquare();
98 	void configureTexture(size_t idx);
99 	void checkError(const char *msg);
100 
101 	int m_frameWidth;
102 	int m_frameHeight;
103 	int m_WCrop;
104 	int m_HCrop;
105 	unsigned m_colorspace;
106 	unsigned m_xfer_func;
107 	unsigned m_ycbcr_enc;
108 	unsigned m_quantization;
109 	bool m_is_sdtv;
110 	bool m_is_rgb;
111 	unsigned m_field;
112 	int m_screenTextureCount;
113 	bool m_formatChange;
114 	__u32 m_frameFormat;
115 	GLuint m_screenTexture[MAX_TEXTURES_NEEDED];
116 #if QT_VERSION < 0x060000
117 	QGLFunctions m_glfunction;
118 #endif
119 	unsigned char *m_frameData;
120 	unsigned char *m_frameData2;
121 	unsigned char *m_frameData3;
122 #if QT_VERSION < 0x060000
123 	QGLShaderProgram m_shaderProgram;
124 #else
125 	QOpenGLShaderProgram m_shaderProgram;
126 #endif
127 	bool m_haveFramebufferSRGB;
128 	bool m_hasGLRed;
129 	unsigned m_glRed;
130 	unsigned m_glRed16;
131 	unsigned m_glRedGreen;
132 	bool m_blending;
133 	GLint m_mag_filter;
134 	GLint m_min_filter;
135 };
136 
137 #endif
138 
139 class CaptureWinGL : public CaptureWin
140 {
141 public:
142 	CaptureWinGL(ApplicationWindow *aw);
143 	~CaptureWinGL();
144 
145 	void stop();
146 	bool hasNativeFormat(__u32 format);
147 	static bool isSupported();
148 	void setColorspace(unsigned colorspace, unsigned xfer_func,
149 			unsigned ycbcr_enc, unsigned quantization, bool is_sdtv);
150 	void setField(unsigned field);
151 	void setBlending(bool enable);
152 	void setLinearFilter(bool enable);
153 
154 protected:
155 	void resizeEvent(QResizeEvent *event);
156 	void setRenderFrame();
157 	void closeEvent(QCloseEvent *event);
158 
159 private:
160 #ifdef HAVE_QTGL
161 	CaptureWinGLEngine m_videoSurface;
162 #endif
163 };
164 
165 #endif
166