#ifndef MEDIA_GPU_ANDROID_VIDEO_FRAME_GL_SURFACE_RENDERER_H_
#define MEDIA_GPU_ANDROID_VIDEO_FRAME_GL_SURFACE_RENDERER_H_
#include <android/native_window.h>
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "media/base/encoder_status.h"
#include "media/base/video_frame.h"
#include "media/gpu/media_gpu_export.h"
#include "ui/gl/android/scoped_a_native_window.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/gl/scoped_gl_texture.h"
namespace gpu {
class SharedImageManager;
}
namespace media {
class MEDIA_GPU_EXPORT VideoFrameGLSurfaceRenderer {
public:
explicit VideoFrameGLSurfaceRenderer(gl::ScopedANativeWindow window);
~VideoFrameGLSurfaceRenderer();
EncoderStatus Initialize();
EncoderStatus RenderVideoFrame(scoped_refptr<VideoFrame> frame,
base::TimeTicks presentation_timestamp);
void SetSharedImageManager(gpu::SharedImageManager* shared_image_manager);
private:
EncoderStatus RenderYUVVideoFrame(scoped_refptr<VideoFrame> frame);
EncoderStatus RenderRGBVideoFrame(scoped_refptr<VideoFrame> frame);
EncoderStatus RenderSharedImageVideoFrame(scoped_refptr<VideoFrame> frame);
void UpdateTextures(const VideoFrame& frame);
void DrawQuad();
void InitializeGL();
void DestroyGL();
SEQUENCE_CHECKER(sequence_checker_);
gl::ScopedANativeWindow window_;
scoped_refptr<gl::NativeViewGLSurfaceEGL> gl_surface_;
scoped_refptr<gl::GLContext> gl_context_;
GLuint gl_program_yuv_ = 0;
GLuint gl_vertex_shader_ = 0;
GLuint gl_fragment_shader_yuv_ = 0;
GLuint gl_program_rgb_ = 0;
GLuint gl_fragment_shader_rgb_ = 0;
GLuint gl_program_ahb_ = 0;
GLuint gl_fragment_shader_ahb_ = 0;
GLuint gl_vbo_ = 0;
GLint gl_pos_location_ = GL_INVALID_INDEX;
GLint gl_tc_location_ = GL_INVALID_INDEX;
std::array<GLint, 3> gl_yuv_tex_locations_{{-1, -1, -1}};
GLint gl_rgb_tex_location_ = GL_INVALID_INDEX;
GLint gl_ahb_tex_location_ = GL_INVALID_INDEX;
GLint gl_yuv_to_rgb_matrix_location_ = GL_INVALID_INDEX;
GLint gl_yuv_to_rgb_translation_location_ = GL_INVALID_INDEX;
GLint gl_is_nv12_location_ = GL_INVALID_INDEX;
std::vector<gl::ScopedGLTexture> cached_textures_;
bool cached_textures_for_shared_image_ = false;
VideoPixelFormat cached_frame_format_ = PIXEL_FORMAT_UNKNOWN;
gfx::Size cached_frame_size_;
gpu::MemoryTypeTracker memory_type_tracker_{nullptr};
raw_ptr<gpu::SharedImageManager> shared_image_manager_;
};
}
#endif