NvEglRenderer
is a helper class for rendering using EGL and OpenGL ES 2.0.
More...
#include <NvEglRenderer.h>
Public Member Functions | |
~NvEglRenderer () | |
int | render (int fd) |
Renders a buffer. | |
int | setFPS (float fps) |
Sets the rendering rate in frames per second (fps). | |
EGLDisplay | getEGLDisplay () |
Get underlying EGLDisplay. | |
int | setOverlayText (char *str, uint32_t x, uint32_t y) |
Set Overlay string. | |
Static Public Member Functions | |
static NvEglRenderer * | createEglRenderer (const char *name, uint32_t width, uint32_t height, uint32_t x_offset, uint32_t y_offset) |
Creates a new EGL-based renderer named name. | |
static int | getDisplayResolution (uint32_t &width, uint32_t &height) |
Get Display's resolution. | |
Private Member Functions | |
int | create_texture () |
Creates a GL texture used for rendering. | |
int | InitializeShaders () |
Initializes shaders with shader programs required for drawing a buffer. | |
void | CreateShader (GLuint program, GLenum type, const char *source, int size) |
Creates, compiles and attaches a shader to the program. | |
NvEglRenderer (const char *name, uint32_t width, uint32_t height, uint32_t x_offset, uint32_t y_offset) | |
Constructor called by the wrapper createEglRenderer. | |
int | renderInternal () |
This method contains the actual logic of rendering a buffer and waiting until the buffer render time. | |
Static Private Member Functions | |
static int | initEgl () |
Gets the pointers to the required EGL methods. | |
static void * | renderThread (void *arg) |
Method executed by the renderThread. | |
Private Attributes | |
Display * | x_display |
Connection to the X server created using XOpenDisplay(). | |
Window | x_window |
Holds the window to be used for rendering created using XCreateWindow(). | |
EGLDisplay | egl_display |
Holds the EGL Display connection. | |
EGLContext | egl_context |
Holds the EGL rendering context. | |
EGLSurface | egl_surface |
Holds the EGL Window render surface. | |
EGLConfig | egl_config |
Holds the EGL frame buffer configuration to be usedfor rendering. | |
uint32_t | texture_id |
Holds the GL Texture ID used for rendering. | |
GC | gc |
Graphic Context. | |
XFontStruct * | fontinfo |
Brush's font info. | |
char | overlay_str [512] |
Overlay's text. | |
struct timespec | last_render_time |
Rendering time for the last buffer. | |
int | render_fd |
File descriptor (FD) of the next buffer to render. | |
bool | stop_thread |
Boolean variable used to signal rendering thread to stop. | |
pthread_t | render_thread |
The pthread id of the rendering thread. | |
pthread_mutex_t | render_lock |
Used for synchronization. | |
pthread_cond_t | render_cond |
Used for synchronization. | |
uint32_t | overlay_str_x_offset |
overlay text's position in horizontal direction. | |
uint32_t | overlay_str_y_offset |
overlay text's position in vertical direction. | |
float | fps |
The render rate in frames per second. | |
uint64_t | render_time_sec |
Seconds component of the time for which a frame should be displayed. | |
uint64_t | render_time_nsec |
Nanoseconds component of the time for which a frame should be displayed. | |
Static Private Attributes | |
static PFNEGLCREATEIMAGEKHRPROC | eglCreateImageKHR |
These EGL function pointers are required by the renderer. | |
static PFNEGLDESTROYIMAGEKHRPROC | eglDestroyImageKHR |
static PFNEGLCREATESYNCKHRPROC | eglCreateSyncKHR |
static PFNEGLDESTROYSYNCKHRPROC | eglDestroySyncKHR |
static PFNEGLCLIENTWAITSYNCKHRPROC | eglClientWaitSyncKHR |
static PFNEGLGETSYNCATTRIBKHRPROC | eglGetSyncAttribKHR |
static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC | glEGLImageTargetTexture2DOES |
static const NvElementProfiler::ProfilerField | valid_fields |
NvEglRenderer
is a helper class for rendering using EGL and OpenGL ES 2.0.
The renderer requires the file descriptor (FD) of a buffer as an input. The rendering rate, in frames per second (fps), is configurable.
The renderer creates an X Window of its own. The width, height, horizontal offset, and vertical offset of the window are configurable.
All EGL calls must be made through one thread only. This class internally creates a thread which performs all EGL/GL initializations, gets EGLImage
objects from FD, renders the EGLImage
objects, and then deinitializes all the EGL/GL structures.
Definition at line 73 of file NvEglRenderer.h.
NvEglRenderer::~NvEglRenderer | ( | ) |
Definition at line 323 of file NvEglRenderer.cpp.
NvEglRenderer::NvEglRenderer | ( | const char * | name, | |
uint32_t | width, | |||
uint32_t | height, | |||
uint32_t | x_offset, | |||
uint32_t | y_offset | |||
) | [private] |
Constructor called by the wrapper createEglRenderer.
Definition at line 56 of file NvEglRenderer.cpp.
int NvEglRenderer::create_texture | ( | ) | [private] |
Creates a GL texture used for rendering.
Definition at line 672 of file NvEglRenderer.cpp.
NvEglRenderer * NvEglRenderer::createEglRenderer | ( | const char * | name, | |
uint32_t | width, | |||
uint32_t | height, | |||
uint32_t | x_offset, | |||
uint32_t | y_offset | |||
) | [static] |
Creates a new EGL-based renderer named name.
This method creates a new X window for rendering, of size width and height, that is offset by x_offset and y_offset. If width or height is zero, a full screen window is created with x_offset and y_offset set to zero.
It internally initializes EGL, creates an eglContext
, an eglSurface
, a GL texture, and shaders for rendering.
[in] | name | Specifies a pointer to a unique name to identity the element instance. |
[in] | width | Specifies the width of the window in pixels. |
[in] | height | Specifies the height of the window in pixels. |
[in] | x_offset | Specifies the horizontal offset of the window in pixels. |
[in] | y_offset | Specifies the vertical offset of the window in pixels. |
NULL
in case of failure during initialization. Definition at line 500 of file NvEglRenderer.cpp.
void NvEglRenderer::CreateShader | ( | GLuint | program, | |
GLenum | type, | |||
const char * | source, | |||
int | size | |||
) | [private] |
Creates, compiles and attaches a shader to the program.
[in] | program | Specifies the GL Program ID. |
[in] | type | Specifies the type of the vertex shader. Must be either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER . |
[in] | source | Specifies the source code of the shader in form of a string. |
[in] | size | Specifies the character length of source. |
Definition at line 560 of file NvEglRenderer.cpp.
int NvEglRenderer::getDisplayResolution | ( | uint32_t & | width, | |
uint32_t & | height | |||
) | [static] |
Get Display's resolution.
[out] | Full | screen width, in pixel |
[out] | Full | screen height, in pixel |
Definition at line 157 of file NvEglRenderer.cpp.
EGLDisplay NvEglRenderer::getEGLDisplay | ( | ) | [inline] |
Get underlying EGLDisplay.
Definition at line 131 of file NvEglRenderer.h.
int NvEglRenderer::initEgl | ( | ) | [static, private] |
int NvEglRenderer::InitializeShaders | ( | void | ) | [private] |
Initializes shaders with shader programs required for drawing a buffer.
Definition at line 586 of file NvEglRenderer.cpp.
int NvEglRenderer::render | ( | int | fd | ) |
Renders a buffer.
This method waits until the rendering time of the next buffer, caluclated from the rendering time of the last buffer and the render rate in frames per second (fps). This is a blocking call.
[in] | fd | Specifies the file descriptor (FD) of the exported buffer to render. |
Definition at line 359 of file NvEglRenderer.cpp.
int NvEglRenderer::renderInternal | ( | ) | [private] |
This method contains the actual logic of rendering a buffer and waiting until the buffer render time.
Definition at line 371 of file NvEglRenderer.cpp.
void * NvEglRenderer::renderThread | ( | void * | arg | ) | [static, private] |
Method executed by the renderThread.
This method continues to execute infinitely until signalled to stop with the stop_thread
variable. This method contains a while loop that calls NvEglRenderer::renderInternal().
Definition at line 177 of file NvEglRenderer.cpp.
int NvEglRenderer::setFPS | ( | float | fps | ) |
Sets the rendering rate in frames per second (fps).
[in] | fps | Specifies the render rate in fps. |
Definition at line 480 of file NvEglRenderer.cpp.
int NvEglRenderer::setOverlayText | ( | char * | str, | |
uint32_t | x, | |||
uint32_t | y | |||
) |
Set Overlay string.
[in] | str | Overlay Text |
[in] | Horizontal | offset, in pixel |
[in] | Vertical | offset, in pixel |
Definition at line 468 of file NvEglRenderer.cpp.
EGLConfig NvEglRenderer::egl_config [private] |
Holds the EGL frame buffer configuration to be usedfor rendering.
Definition at line 163 of file NvEglRenderer.h.
EGLContext NvEglRenderer::egl_context [private] |
EGLDisplay NvEglRenderer::egl_display [private] |
EGLSurface NvEglRenderer::egl_surface [private] |
PFNEGLCLIENTWAITSYNCKHRPROC NvEglRenderer::eglClientWaitSyncKHR [static, private] |
Definition at line 243 of file NvEglRenderer.h.
PFNEGLCREATEIMAGEKHRPROC NvEglRenderer::eglCreateImageKHR [static, private] |
These EGL function pointers are required by the renderer.
Definition at line 239 of file NvEglRenderer.h.
PFNEGLCREATESYNCKHRPROC NvEglRenderer::eglCreateSyncKHR [static, private] |
Definition at line 241 of file NvEglRenderer.h.
PFNEGLDESTROYIMAGEKHRPROC NvEglRenderer::eglDestroyImageKHR [static, private] |
Definition at line 240 of file NvEglRenderer.h.
PFNEGLDESTROYSYNCKHRPROC NvEglRenderer::eglDestroySyncKHR [static, private] |
Definition at line 242 of file NvEglRenderer.h.
PFNEGLGETSYNCATTRIBKHRPROC NvEglRenderer::eglGetSyncAttribKHR [static, private] |
Definition at line 244 of file NvEglRenderer.h.
XFontStruct* NvEglRenderer::fontinfo [private] |
float NvEglRenderer::fps [private] |
GC NvEglRenderer::gc [private] |
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC NvEglRenderer::glEGLImageTargetTexture2DOES [static, private] |
Definition at line 245 of file NvEglRenderer.h.
struct timespec NvEglRenderer::last_render_time [read, private] |
char NvEglRenderer::overlay_str[512] [private] |
uint32_t NvEglRenderer::overlay_str_x_offset [private] |
uint32_t NvEglRenderer::overlay_str_y_offset [private] |
pthread_cond_t NvEglRenderer::render_cond [private] |
int NvEglRenderer::render_fd [private] |
pthread_mutex_t NvEglRenderer::render_lock [private] |
pthread_t NvEglRenderer::render_thread [private] |
uint64_t NvEglRenderer::render_time_nsec [private] |
Nanoseconds component of the time for which a frame should be displayed.
Definition at line 210 of file NvEglRenderer.h.
uint64_t NvEglRenderer::render_time_sec [private] |
Seconds component of the time for which a frame should be displayed.
Definition at line 208 of file NvEglRenderer.h.
bool NvEglRenderer::stop_thread [private] |
Boolean variable used to signal rendering thread to stop.
Definition at line 200 of file NvEglRenderer.h.
uint32_t NvEglRenderer::texture_id [private] |
const NvElementProfiler::ProfilerField NvEglRenderer::valid_fields [static, private] |
Initial value:
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS | NvElementProfiler::PROFILER_FIELD_FPS | NvElementProfiler::PROFILER_FIELD_LATE_UNITS
Definition at line 247 of file NvEglRenderer.h.
Display* NvEglRenderer::x_display [private] |
Connection to the X server created using XOpenDisplay().
Definition at line 155 of file NvEglRenderer.h.
Window NvEglRenderer::x_window [private] |
Holds the window to be used for rendering created using XCreateWindow().
Definition at line 157 of file NvEglRenderer.h.