Jetson Linux API Reference

32.7.5 Release
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 
132  EGLDisplay getEGLDisplay() { return egl_display; }
133 
142  static int getDisplayResolution(uint32_t &width, uint32_t &height);
143 
153  int setOverlayText(char *str, uint32_t x, uint32_t y);
154 
155 private:
156  Display * x_display;
158  Window x_window;
161  EGLDisplay egl_display;
162  EGLContext egl_context;
163  EGLSurface egl_surface;
164  EGLConfig egl_config;
167  uint32_t texture_id;
168  GC gc;
169  XFontStruct *fontinfo;
170  char overlay_str[512];
177  int create_texture();
184  int InitializeShaders();
194  void CreateShader(GLuint program, GLenum type, const char *source,
195  int size);
196 
197  struct timespec last_render_time;
199  int render_fd;
201  bool stop_thread;
203  pthread_t render_thread;
204  pthread_mutex_t render_lock;
205  pthread_cond_t render_cond;
206  uint32_t overlay_str_x_offset;
207  uint32_t overlay_str_y_offset;
208  float fps;
209  uint64_t render_time_sec;
211  uint64_t render_time_nsec;
217  NvEglRenderer(const char *name, uint32_t width, uint32_t height,
218  uint32_t x_offset, uint32_t y_offset);
222  static int initEgl();
230  static void * renderThread(void *arg);
235  int renderInternal();
236 
240  static PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
241  static PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
242  static PFNEGLCREATESYNCKHRPROC eglCreateSyncKHR;
243  static PFNEGLDESTROYSYNCKHRPROC eglDestroySyncKHR;
244  static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR;
245  static PFNEGLGETSYNCATTRIBKHRPROC eglGetSyncAttribKHR;
246  static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
247 
248  static const NvElementProfiler::ProfilerField valid_fields =
252 };
254 #endif
NvEglRenderer::setOverlayText
int setOverlayText(char *str, uint32_t x, uint32_t y)
Sets the overlay string.
NvElementProfiler::PROFILER_FIELD_LATE_UNITS
static const ProfilerField PROFILER_FIELD_LATE_UNITS
Definition: NvElementProfiler.h:82
NvElementProfiler::ProfilerField
int ProfilerField
Definition: NvElementProfiler.h:79
NvEglRenderer::render
int render(int fd)
Renders a buffer.
NvEglRenderer::setFPS
int setFPS(float fps)
Sets the rendering rate in frames per second (fps).
NvEglRenderer::getEGLDisplay
EGLDisplay getEGLDisplay()
Gets underlying EGLDisplay.
Definition: NvEglRenderer.h:132
NvEglRenderer::createEglRenderer
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.
NvElementProfiler::PROFILER_FIELD_FPS
static const ProfilerField PROFILER_FIELD_FPS
Definition: NvElementProfiler.h:84
NvEglRenderer
NvEglRenderer is a helper class for rendering using EGL and OpenGL ES 2.0.
Definition: NvEglRenderer.h:74
NvElement
Every element has a unique name that can be used for identifying the element in debug logs.
Definition: NvElement.h:63
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS
static const ProfilerField PROFILER_FIELD_TOTAL_UNITS
Definition: NvElementProfiler.h:81
NvEglRenderer::getDisplayResolution
static int getDisplayResolution(uint32_t &width, uint32_t &height)
Gets the display resolution.
NvEglRenderer::~NvEglRenderer
~NvEglRenderer()
NvElement.h