Jetson Linux API Reference

32.7.4 Release
NvDrmRenderer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
3  * NVIDIA CORPORATION and its licensors retain all intellectual property
4  * and proprietary rights in and to this software, related documentation
5  * and any modifications thereto. Any use, reproduction, disclosure or
6  * distribution of this software and related documentation without an express
7  * license agreement from NVIDIA CORPORATION is strictly prohibited.
8  */
9 
17 #ifndef __NV_DRM_RENDERER_H__
18 #define __NV_DRM_RENDERER_H__
19 
20 #include "NvElement.h"
21 #include <stdint.h>
22 #include <pthread.h>
23 #include <queue>
24 #include <unordered_map>
25 
35 typedef struct _NvDrmBO {
36  uint32_t bo_handle;
37  int width;
38  int height;
39  int pitch;
40  uint8_t* data;
41 } NvDrmBO;
42 
44 typedef struct _NvDrmFB {
45  uint32_t fb_id;
46  int width;
47  int height;
48  int format;
51  NvDrmBO bo[4];
54 } NvDrmFB;
55 
56 
68 {
69 public:
86  static NvDrmRenderer *createDrmRenderer(const char *name, uint32_t width,
87  uint32_t height, uint32_t w_x, uint32_t w_y,
88  uint32_t connector, uint32_t crtc,
89  struct drm_tegra_hdr_metadata_smpte_2086 metadata,
90  bool streamHDR);
92 
104  int enqueBuffer(int fd);
105 
116  int dequeBuffer();
117 
126  int setFPS(float fps);
127 
135  bool enableUniversalPlanes(int enable);
136 
152  uint32_t createDumbFB(uint32_t width, uint32_t height, uint32_t drm_format, NvDrmFB *fb);
153 
161  int removeFB(uint32_t fb_id);
162 
163 
172  int drmUtilCloseGemBo(int fd, uint32_t bo_handle);
173 
202  int setPlane(uint32_t pl_index,
203  uint32_t fb_id,
204  uint32_t crtc_x,
205  uint32_t crtc_y,
206  uint32_t crtc_w,
207  uint32_t crtc_h,
208  uint32_t src_x,
209  uint32_t src_y,
210  uint32_t src_w,
211  uint32_t src_h);
212 
224  int getPlaneCount();
225 
239  int getPlaneIndex(uint32_t crtc_index,
240  int32_t* plane_index);
241 
247  int getCrtcCount();
248 
254  int getEncoderCount();
255 
261  bool hdrSupported();
262 
268  int setHDRMetadataSmpte2086(struct drm_tegra_hdr_metadata_smpte_2086);
269 
270 private:
271 
272  struct timespec last_render_time;
274  int drm_fd;
275  int conn, crtc;
276  uint32_t width, height;
277  uint32_t drm_conn_id;
278  uint32_t drm_enc_id;
279  uint32_t drm_crtc_id;
280  uint32_t last_fb;
281  int activeFd;
282  int flippedFd;
283  bool flipPending;
284  bool renderingStarted;
285  bool is_nvidia_drm;
286 
287  uint32_t hdrBlobId;
288  bool hdrBlobCreated;
289 
290  std::queue<int> freeBuffers;
291  std::queue<int> pendingBuffers;
292  std::unordered_map <int, int> map_list;
293 
294  bool stop_thread;
296  pthread_t render_thread;
298  pthread_mutex_t render_lock;
299  pthread_cond_t render_cond;
300  pthread_mutex_t enqueue_lock;
301  pthread_cond_t enqueue_cond;
302  pthread_mutex_t dequeue_lock;
303  pthread_cond_t dequeue_cond;
305  float fps;
306  uint64_t render_time_sec;
308  uint64_t render_time_nsec;
327  NvDrmRenderer(const char *name, uint32_t width, uint32_t height,
328  uint32_t w_x, uint32_t w_y, uint32_t connector, uint32_t crtc,
329  struct drm_tegra_hdr_metadata_smpte_2086 metadata, bool streamHDR);
330 
340  static void * renderThread(void *arg);
341  static void * renderThreadOrin(void *arg);
342 
347  static void page_flip_handler(int fd, unsigned int frame,
348  unsigned int sec, unsigned int usec, void *data);
349 
356  int renderInternal(int fd);
357 
358  /*
359  * Returns a DRM buffer_object handle.
360  *
361  * \param[in] w Width of the window in pixels.
362  * \param[in] h Height of the window in pixels.
363  * \param[in] bpp Bits per pixel in the window.
364  * \param[in] bo A pointer to a buffer object handle.
365  * \return An allocated DRM buffer_object handle of size (w,h)
366  */
367  int createDumbBO(int w, int h, int bpp, NvDrmBO *bo);
368 
369  static const NvElementProfiler::ProfilerField valid_fields =
373 };
374 
376 #endif
_NvDrmBO::width
int width
Holds width of the DRM buffer, in pixels.
Definition: NvDrmRenderer.h:37
NvElementProfiler::PROFILER_FIELD_LATE_UNITS
static const ProfilerField PROFILER_FIELD_LATE_UNITS
Definition: NvElementProfiler.h:82
NvDrmRenderer::hdrSupported
bool hdrSupported()
Checks whether the DRM renderer supports HDR mode.
_NvDrmBO::pitch
int pitch
Holds stride/pitch of the DRM buffer.
Definition: NvDrmRenderer.h:39
NvElementProfiler::ProfilerField
int ProfilerField
Definition: NvElementProfiler.h:79
NvDrmRenderer::dequeBuffer
int dequeBuffer()
Dequeues a previously rendered buffer.
_NvDrmFB::num_buffers
int num_buffers
Holds the number of DRM buffers, which depends on the buffer format.
Definition: NvDrmRenderer.h:52
_NvDrmFB::height
int height
Holds height of the frame, in pixels.
Definition: NvDrmRenderer.h:47
_NvDrmBO::data
uint8_t * data
Holds mapped CPU accessible address.
Definition: NvDrmRenderer.h:40
_NvDrmFB::width
int width
Holds width of the frame, in pixels.
Definition: NvDrmRenderer.h:46
NvDrmRenderer::enableUniversalPlanes
bool enableUniversalPlanes(int enable)
Enables/disables DRM universal planes client caps, such as DRM_CLIENT_CAP_UNIVERSAL_PLANES.
_NvDrmBO::height
int height
Holds height of the DRM buffer, in pixels.
Definition: NvDrmRenderer.h:38
NvDrmFB
struct _NvDrmFB NvDrmFB
Holds information about the frame.
_NvDrmFB::bo
NvDrmBO bo[4]
Holds DRM buffer handles.
Definition: NvDrmRenderer.h:51
NvDrmRenderer::setFPS
int setFPS(float fps)
Sets the rendering rate in terms of frames per second.
NvDrmRenderer::createDumbFB
uint32_t createDumbFB(uint32_t width, uint32_t height, uint32_t drm_format, NvDrmFB *fb)
Allocates a framebuffer of size (w, h).
_NvDrmFB::format
int format
Holds frame format, such as DRM_FORMAT_RGB332.
Definition: NvDrmRenderer.h:48
NvDrmRenderer::getPlaneCount
int getPlaneCount()
Gets total number of planes available.
NvDrmRenderer::getEncoderCount
int getEncoderCount()
Gets count of available encoders.
NvDrmRenderer::drmUtilCloseGemBo
int drmUtilCloseGemBo(int fd, uint32_t bo_handle)
Close GEM (Graphics Execution Manager) handles.
NvDrmRenderer::createDrmRenderer
static NvDrmRenderer * createDrmRenderer(const char *name, uint32_t width, uint32_t height, uint32_t w_x, uint32_t w_y, uint32_t connector, uint32_t crtc, struct drm_tegra_hdr_metadata_smpte_2086 metadata, bool streamHDR)
Creates a new DRM based renderer named name.
_NvDrmFB
Holds information about the frame.
Definition: NvDrmRenderer.h:44
_NvDrmBO
Holds a buffer object handle.
Definition: NvDrmRenderer.h:35
NvDrmRenderer::setHDRMetadataSmpte2086
int setHDRMetadataSmpte2086(struct drm_tegra_hdr_metadata_smpte_2086)
Sets the HDR metadata retrieved from the decoder.
NvElementProfiler::PROFILER_FIELD_FPS
static const ProfilerField PROFILER_FIELD_FPS
Definition: NvElementProfiler.h:84
NvDrmRenderer::setPlane
int setPlane(uint32_t pl_index, uint32_t fb_id, uint32_t crtc_x, uint32_t crtc_y, uint32_t crtc_w, uint32_t crtc_h, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h)
Changes a plane's framebuffer and position.
NvElement
Every element has a unique name that can be used for identifying the element in debug logs.
Definition: NvElement.h:63
NvDrmRenderer::~NvDrmRenderer
~NvDrmRenderer()
_NvDrmBO::bo_handle
uint32_t bo_handle
Holds DRM buffer index.
Definition: NvDrmRenderer.h:36
NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS
static const ProfilerField PROFILER_FIELD_TOTAL_UNITS
Definition: NvElementProfiler.h:81
NvDrmBO
struct _NvDrmBO NvDrmBO
Holds a buffer object handle.
NvDrmRenderer::removeFB
int removeFB(uint32_t fb_id)
Destroys (frees) a framebuffer previously allocated by createDumbFB().
NvElement.h
NvDrmRenderer::getPlaneIndex
int getPlaneIndex(uint32_t crtc_index, int32_t *plane_index)
Gets the plane indexes supported by the given crtc index.
NvDrmRenderer
Helper class for rendering using LibDRM.
Definition: NvDrmRenderer.h:67
_NvDrmFB::fb_id
uint32_t fb_id
Holds the frame ID.
Definition: NvDrmRenderer.h:45
NvDrmRenderer::enqueBuffer
int enqueBuffer(int fd)
Enqueues a buffer file descriptor for rendering.
NvDrmRenderer::getCrtcCount
int getCrtcCount()
Gets count of available CRTCs.