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