Multimedia API Reference

November 16, 2016 | 24.2.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NvEglRenderer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
35 #ifndef __NV_EGL_RENDERER_H__
36 #define __NV_EGL_RENDERER_H__
37 
38 #include "NvElement.h"
39 
40 #include <EGL/egl.h>
41 #include <EGL/eglext.h>
42 #include <GLES2/gl2.h>
43 #include <GLES2/gl2ext.h>
44 
45 #include <X11/Xlib.h>
46 
75 {
76 public:
98  static NvEglRenderer *createEglRenderer(const char *name, uint32_t width,
99  uint32_t height, uint32_t x_offset,
100  uint32_t y_offset);
101  ~NvEglRenderer();
102 
115  int render(int fd);
116 
125  int setFPS(float fps);
126 
135  static int getDisplayResolution(uint32_t &width, uint32_t &height);
136 
146  int setOverlayText(char *str, uint32_t x, uint32_t y);
147 
148 private:
149  Display * x_display;
151  Window x_window;
154  EGLDisplay egl_display;
155  EGLContext egl_context;
156  EGLSurface egl_surface;
157  EGLConfig egl_config;
160  uint32_t texture_id;
161  GC gc;
162  XFontStruct *fontinfo;
163  char overlay_str[512];
170  int create_texture();
177  int InitializeShaders();
187  void CreateShader(GLuint program, GLenum type, const char *source,
188  int size);
189 
190  struct timespec last_render_time;
192  int render_fd;
194  bool stop_thread;
196  pthread_t render_thread;
197  pthread_mutex_t render_lock;
198  pthread_cond_t render_cond;
199  uint32_t overlay_str_x_offset;
200  uint32_t overlay_str_y_offset;
201  float fps;
202  uint64_t render_time_sec;
204  uint64_t render_time_nsec;
210  NvEglRenderer(const char *name, uint32_t width, uint32_t height,
211  uint32_t x_offset, uint32_t y_offset);
215  static int initEgl();
223  static void * renderThread(void *arg);
228  int renderInternal();
229 
233  static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
234  static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
235  static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR;
236  static PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR;
237  static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR;
238  static PFNEGLGETSYNCATTRIBKHRPROC eglGetSyncAttribKHR;
239  static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
240 
241  static const NvElementProfiler::ProfilerField valid_fields =
242  NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS |
243  NvElementProfiler::PROFILER_FIELD_FPS |
244  NvElementProfiler::PROFILER_FIELD_LATE_UNITS;
245 };
247 #endif
int setOverlayText(char *str, uint32_t x, uint32_t y)
Sets the overlay string.
NVIDIA Multimedia API: NvElement Base Class
Every element has a unique name that can be used for identifying the element in debug logs...
Definition: NvElement.h:63
static int getDisplayResolution(uint32_t &width, uint32_t &height)
Gets the display resolution.
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.
int setFPS(float fps)
Sets the rendering rate in frames per second (fps).
NvEglRenderer is a helper class for rendering using EGL and OpenGL ES 2.0.
Definition: NvEglRenderer.h:74
int render(int fd)
Renders a buffer.