]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sitara-linux/video-graphics-test.git/blob - disp_obj.cpp
7bbc3dcbfcb9c4299381c2e7344aafe845df9d81
[sitara-linux/video-graphics-test.git] / disp_obj.cpp
1 /*
2  * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
3  * 
4  * 
5  *  Redistribution and use in source and binary forms, with or without 
6  *  modification, are permitted provided that the following conditions 
7  *  are met:
8  *
9  *    Redistributions of source code must retain the above copyright 
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  *    Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the 
14  *    documentation and/or other materials provided with the   
15  *    distribution.
16  *
17  *    Neither the name of Texas Instruments Incorporated nor the names of
18  *    its contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
25  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
26  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
27  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
30  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
31  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33 */
35 /* This file defines the functions to deal with the DSS engine via QT eglfs_kms QPA 
36 *  It secures the hardware plane for overlay need, set one time the display proerpties 
37 *  of the overlay plane, also sets the primary plane properties for alphablending, 
38 *  exports user allocated video buffers to the DRM, queue and dequeue the video buffers
39 *  submitted to the QPA 
40 */
42 #include <sys/types.h>
43 #include <stdint.h>
44 #include <xf86drmMode.h>
45 #include <unistd.h>
46 #include "disp_obj.h"
47 #include "error.h"
48 #include <sys/time.h>
50 static void page_flip_handler(void *data){
51     bool *page_flipped = (bool *)data; 
52         //MSG("received notification from QPA\n");
53     *page_flipped = true;
54 }
56 DispObj::DispObj(QpaCtlObj *qpa_ctl, void *screen, uint32_t x, 
57                  uint32_t y, uint32_t w, uint32_t h, uint32_t num_planes) {
58     m_screen =  screen;
59     m_crtc_x = x;
60     m_crtc_y = y;
61     m_crtc_w = w;
62     m_crtc_h = h;
63     m_num_planes = num_planes;
64     m_page_flipped = false;
66     m_qpa_ctl = qpa_ctl;
68     //If display is not connected, don't create overlay planes
69     if(screen != NULL){
71         //Secure DSS hardware planes for overlay from QT QPA
72         for(uint32_t i = 0; i < m_num_planes; i++){
73             m_plane_id[i] = m_qpa_ctl->m_create_plane(m_screen);
74         }
75     
76         /* Pass callback function pointer to the QT eglfs_kms QPA. The QPA will
77          call this function to notify display completion of the overlay buffer */
78         m_qpa_ctl->m_set_user_call_back(m_screen, &page_flip_handler, &m_page_flipped);
79     }
80 }
82 DispObj::~DispObj(){
83     for(uint32_t i = 0; i < m_num_planes; i++){
84         m_qpa_ctl->m_distroy_plane(m_screen, m_plane_id[i]);
85     }
86 }
88 /*
89 * Set up the DSS for scaling of video planes and blending it with graphics planes
90 */
91 int DispObj::set_properties(uint32_t src_w, uint32_t src_h, 
92     uint32_t fb_id, uint32_t plane_idx){
94     char trans_key_mode = 2;
95     char *propname[11];
96     unsigned int propval[11];
97     int i;
99     for(i = 0; i < 11; i++)
100     {
101         propname[i]= (char *) malloc(sizeof(char)*128);
102     }
104     /*set primary/graphics plane property for alpha blending*/
105     strcpy(propname[0],"trans-key-mode");
106     strcpy(propname[1],"alpha_blender");
107     strcpy(propname[2],"zorder");
109     propval[0] = trans_key_mode;
110     propval[1] = 1;
111     propval[2] = 1;
113     m_qpa_ctl->m_set_plane_properties(m_screen, DRM_PLANE_TYPE_PRIMARY, 0, 
114         3, (const char**)propname, propval);
116     /* Set overlay plane properties for input and output resolution (scaling) */
117     /* CRTC properties below are the DSS processed/displayed output proerties */
118     /* and SRC is for input */
119     strcpy(propname[0], "CRTC_X"); //output offset X to be displayed from
120     propval[0] = m_crtc_x;
121     strcpy(propname[1], "CRTC_Y"); //output offset Y to be displayed from
122     propval[1] = m_crtc_y;
123     strcpy(propname[2], "CRTC_W"); //output width, set to screen width in this example
124     propval[2] = m_crtc_w;
125     strcpy(propname[3], "CRTC_H"); //output width, set to screen height in this example
126     propval[3] = m_crtc_h;
127     strcpy(propname[4], "SRC_X"); //input buffer offset X to be processed from
128     propval[4] = 0;
129     strcpy(propname[5], "SRC_Y"); //input buffer offset Y to be processed from
130     propval[5] = 0;
131     strcpy(propname[6], "SRC_W"); //input buffer width
132     propval[6] = src_w << 16 ;
133     strcpy(propname[7], "SRC_H"); //input buffer height
134     propval[7] = src_h << 16;
135     strcpy(propname[8], "zorder"); //order of the video plane when laying on top/below other planes
136     propval[8] = 2;                // higher the value, higher in order the plane reside. Max value is 3
137     strcpy(propname[9], "FB_ID");
138     propval[9] = fb_id;            //frame buffer id
139     strcpy(propname[10], "global_alpha");
140     propval[10] = 150;             //Alpha value for blending
142     /* Set the plane properties once. After that only set those properties that changes each time a frame is 
143     displayed - like fb_id. */
144     m_qpa_ctl->m_set_plane_properties(m_screen, DRM_PLANE_TYPE_OVERLAY, m_plane_id[plane_idx], 
145         11, (const char**)propname, propval);
147     for (i = 0; i < 11; i++){
148         free(propname[i]);
149     }
151     return 0;
154 /* Export user allocated buffer to the QT QPA/DRM device */
155 int DispObj::export_buf2_qpa(uint32_t w, uint32_t h, uint32_t pix_fmt, 
156         uint32_t *pitches, uint32_t *offset, uint32_t fd, uint32_t *fb_id){
157     return m_qpa_ctl->m_export_buffer(m_screen, w, h, pix_fmt, pitches, offset, fd, fb_id);
160 /* Queue the video buffer to be overlayed to QPA */
161 int DispObj::queue_buf(uint32_t plane_idx, uint32_t fb_id){
162     m_qpa_ctl->m_queue_buffer(m_screen, plane_idx, fb_id);
163     return 0;
166 // Single wait for all the planes submitted to one display as they all get displayed together  
167 int DispObj::dequeue_bufs(int wait_time){
168     struct timeval start, now;
169     gettimeofday(&start, NULL);
171     if(!wait_time){
172         wait_time = 60; //by default, wait for 60 ms
173     }
174         //MSG("before m_page_flipped = %d", m_page_flipped);
175         do{
176                 if (m_page_flipped == false){
177                         usleep(500);
178                 }
179                 else{
180                         m_page_flipped = false;
181                         return 0;
182                 }
183                 gettimeofday(&now, NULL);
184         }while(((now.tv_usec - start.tv_usec)/1000) < wait_time);
185         //MSG("after m_page_flipped = %d", m_page_flipped);
186     MSG("Waited for %d msec. Overlay buffer wasn't freed\n", wait_time);
187     return -1;
190 int DispObj::start_disp(){
191     return(m_qpa_ctl->m_start_disp_plane(m_screen));