2020-04-13 08:40:28 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "renderer.h"
|
|
|
|
|
2020-05-16 02:28:36 +00:00
|
|
|
#include <SDL_opengles2.h>
|
|
|
|
#include <SDL_opengles2_gl2ext.h>
|
|
|
|
|
2020-04-13 08:40:28 +00:00
|
|
|
class EGLRenderer : public IFFmpegRenderer {
|
|
|
|
public:
|
|
|
|
EGLRenderer(IFFmpegRenderer *backendRenderer);
|
|
|
|
virtual ~EGLRenderer() override;
|
|
|
|
virtual bool initialize(PDECODER_PARAMETERS params) override;
|
|
|
|
virtual bool prepareDecoderContext(AVCodecContext* context, AVDictionary** options) override;
|
2022-04-08 02:30:20 +00:00
|
|
|
virtual void cleanupRenderContext() override;
|
2022-04-09 00:28:22 +00:00
|
|
|
virtual void waitToRender() override;
|
2020-04-13 08:40:28 +00:00
|
|
|
virtual void renderFrame(AVFrame* frame) override;
|
2021-03-23 03:51:29 +00:00
|
|
|
virtual bool testRenderFrame(AVFrame* frame) override;
|
2020-04-13 08:40:28 +00:00
|
|
|
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
|
|
|
|
virtual bool isPixelFormatSupported(int videoFormat, enum AVPixelFormat pixelFormat) override;
|
2021-02-05 01:39:18 +00:00
|
|
|
virtual AVPixelFormat getPreferredPixelFormat(int videoFormat) override;
|
2020-04-13 08:40:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2020-12-17 04:09:00 +00:00
|
|
|
void renderOverlay(Overlay::OverlayType type);
|
|
|
|
unsigned compileShader(const char* vertexShaderSrc, const char* fragmentShaderSrc);
|
|
|
|
bool compileShaders();
|
2020-04-13 08:40:28 +00:00
|
|
|
bool specialize();
|
2021-11-19 06:54:59 +00:00
|
|
|
const float *getColorOffsets(const AVFrame* frame);
|
|
|
|
const float *getColorMatrix(const AVFrame* frame);
|
2020-04-13 08:40:28 +00:00
|
|
|
static int loadAndBuildShader(int shaderType, const char *filename);
|
2020-05-16 19:13:00 +00:00
|
|
|
bool openDisplay(unsigned int platform, void* nativeDisplay);
|
2020-04-13 08:40:28 +00:00
|
|
|
|
2020-12-17 04:09:00 +00:00
|
|
|
int m_ViewportWidth;
|
|
|
|
int m_ViewportHeight;
|
|
|
|
|
2021-02-05 01:39:18 +00:00
|
|
|
AVPixelFormat m_EGLImagePixelFormat;
|
2020-04-13 08:40:28 +00:00
|
|
|
void *m_EGLDisplay;
|
|
|
|
unsigned m_Textures[EGL_MAX_PLANES];
|
2020-12-17 04:09:00 +00:00
|
|
|
unsigned m_OverlayTextures[Overlay::OverlayMax];
|
|
|
|
unsigned m_OverlayVbos[Overlay::OverlayMax];
|
|
|
|
SDL_atomic_t m_OverlayHasValidData[Overlay::OverlayMax];
|
2020-04-13 08:40:28 +00:00
|
|
|
unsigned m_ShaderProgram;
|
2020-12-17 04:09:00 +00:00
|
|
|
unsigned m_OverlayShaderProgram;
|
2020-04-13 08:40:28 +00:00
|
|
|
SDL_GLContext m_Context;
|
|
|
|
SDL_Window *m_Window;
|
|
|
|
IFFmpegRenderer *m_Backend;
|
|
|
|
unsigned int m_VAO;
|
2020-05-16 23:25:13 +00:00
|
|
|
bool m_BlockingSwapBuffers;
|
2022-04-09 00:28:22 +00:00
|
|
|
EGLSync m_LastRenderSync;
|
2021-03-07 18:00:44 +00:00
|
|
|
AVFrame* m_LastFrame;
|
2020-05-16 02:28:36 +00:00
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC m_glEGLImageTargetTexture2DOES;
|
|
|
|
PFNGLGENVERTEXARRAYSOESPROC m_glGenVertexArraysOES;
|
|
|
|
PFNGLBINDVERTEXARRAYOESPROC m_glBindVertexArrayOES;
|
|
|
|
PFNGLDELETEVERTEXARRAYSOESPROC m_glDeleteVertexArraysOES;
|
2022-04-09 00:28:22 +00:00
|
|
|
PFNEGLCREATESYNCPROC m_eglCreateSync;
|
|
|
|
PFNEGLCREATESYNCKHRPROC m_eglCreateSyncKHR;
|
|
|
|
PFNEGLDESTROYSYNCPROC m_eglDestroySync;
|
|
|
|
PFNEGLCLIENTWAITSYNCPROC m_eglClientWaitSync;
|
2022-01-21 00:02:44 +00:00
|
|
|
int m_GlesMajorVersion;
|
|
|
|
int m_GlesMinorVersion;
|
|
|
|
bool m_HasExtUnpackSubimage;
|
2020-05-16 02:28:36 +00:00
|
|
|
|
2021-03-22 02:43:57 +00:00
|
|
|
#define NV12_PARAM_YUVMAT 0
|
|
|
|
#define NV12_PARAM_OFFSET 1
|
|
|
|
#define NV12_PARAM_PLANE1 2
|
|
|
|
#define NV12_PARAM_PLANE2 3
|
2021-03-22 04:23:12 +00:00
|
|
|
#define OPAQUE_PARAM_TEXTURE 0
|
2020-12-17 04:09:00 +00:00
|
|
|
int m_ShaderProgramParams[4];
|
|
|
|
|
2021-03-22 02:43:57 +00:00
|
|
|
#define OVERLAY_PARAM_TEXTURE 0
|
2020-12-17 04:09:00 +00:00
|
|
|
int m_OverlayShaderProgramParams[1];
|
|
|
|
|
2022-03-19 19:50:38 +00:00
|
|
|
int m_OldContextProfileMask;
|
|
|
|
int m_OldContextMajorVersion;
|
|
|
|
int m_OldContextMinorVersion;
|
|
|
|
|
2020-04-13 08:40:28 +00:00
|
|
|
SDL_Renderer *m_DummyRenderer;
|
2020-09-08 06:53:29 +00:00
|
|
|
|
|
|
|
// HACK: Work around bug where renderer will repeatedly fail with:
|
|
|
|
// SDL_CreateRenderer() failed: Could not create GLES window surface
|
|
|
|
static SDL_Window* s_LastFailedWindow;
|
2022-01-29 07:12:38 +00:00
|
|
|
static int s_LastFailedVideoFormat;
|
2020-04-13 08:40:28 +00:00
|
|
|
};
|