n jetson TX1 the tegra_multimedia_api / sample / 12_camera_v4l2_cuda program uses X-window to draw characters in the video display window. Draw the characters in the video display when the flashing phenomenon. When X-window draws a character, it causes the drawn character to blink.
int
NvEglRenderer::renderInternal()
{
EGLImageKHR hEglImage;
bool frame_is_late = false;
EGLSyncKHR egl_sync;
int iErr;
hEglImage = NvEGLImageFromFd(egl_display, render_fd);
if (!hEglImage)
{
COMP_ERROR_MSG("Could not get EglImage from fd. Not rendering");
return -1;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture_id);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, hEglImage);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
iErr = glGetError();
if (iErr != GL_NO_ERROR)
{
COMP_ERROR_MSG("glDrawArrays arrays failed:" << iErr);
return -1;
}
egl_sync = eglCreateSyncKHR(egl_display, EGL_SYNC_FENCE_KHR, NULL);
if (egl_sync == EGL_NO_SYNC_KHR)
{
COMP_ERROR_MSG("eglCreateSyncKHR() failed");
return -1;
}
if (last_render_time.tv_sec != 0)
{
pthread_mutex_lock(&render_lock);
last_render_time.tv_sec += render_time_sec;
last_render_time.tv_nsec += render_time_nsec;
last_render_time.tv_sec += last_render_time.tv_nsec / 1000000000UL;
last_render_time.tv_nsec %= 1000000000UL;
if (isProfilingEnabled())
{
struct timeval cur_time;
gettimeofday(&cur_time, NULL);
if ((cur_time.tv_sec * 1000000.0 + cur_time.tv_usec) >
(last_render_time.tv_sec * 1000000.0 +
last_render_time.tv_nsec / 1000.0))
{
frame_is_late = true;
}
}
pthread_cond_timedwait(&render_cond, &render_lock,
&last_render_time);
pthread_mutex_unlock(&render_lock);
}
else
{
struct timeval now;
gettimeofday(&now, NULL);
last_render_time.tv_sec = now.tv_sec;
last_render_time.tv_nsec = now.tv_usec * 1000L;
}
eglSwapBuffers(egl_display, egl_surface);
if (eglGetError() != EGL_SUCCESS)
{
COMP_ERROR_MSG("Got Error in eglSwapBuffers " << eglGetError());
return -1;
}
if (eglClientWaitSyncKHR (egl_display, egl_sync,
EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR) == EGL_FALSE)
{
COMP_ERROR_MSG("eglClientWaitSyncKHR failed!");
}
if (eglDestroySyncKHR(egl_display, egl_sync) != EGL_TRUE)
{
COMP_ERROR_MSG("eglDestroySyncKHR failed!");
}
NvDestroyEGLImage(egl_display, hEglImage);
if (strlen(overlay_str) != 0)
{
XSetForeground(x_display, gc,
BlackPixel(x_display, DefaultScreen(x_display)));
XSetFont(x_display, gc, fontinfo->fid);
XDrawString(x_display, x_window, gc, overlay_str_x_offset,
overlay_str_y_offset, overlay_str, strlen(overlay_str));
}
/*
XSetForeground(x_display, gc,
BlackPixel(x_display, DefaultScreen(x_display)));
XSetFont(x_display, gc, fontinfo->fid);
XDrawString(x_display, x_window, gc, 500,
500, “hello world!”, strlen(“hello world!”));
XDrawString(x_display, x_window, gc, 600,
500, “hello world!”, strlen(“hello world!”));
XDrawLine(x_display, x_window, gc, 600,
500, 800, 700);
*/
profiler.finishProcessing(0, frame_is_late);
return 0;
}