xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkisp_demo/demo/rkdrm_display.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2020 Rockchip Electronics Co., Ltd.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL), available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 #ifndef _RKDRM_DISPLAY_H_
33 #define _RKDRM_DISPLAY_H_
34 
35 #include <assert.h>
36 #include <errno.h>
37 #include <getopt.h>
38 #include <inttypes.h>
39 #include <math.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 #include <drm_fourcc.h>
45 #include <sys/mman.h>
46 #include <xf86drm.h>
47 #include <xf86drmMode.h>
48 
49 struct drm_buf {
50   int fb_id;
51   uint32_t handle;
52   uint32_t size;
53   uint32_t pitch;
54   char *map;
55   int dmabuf_fd;
56 };
57 
58 struct plane_prop {
59   int crtc_id;
60   int fb_id;
61 
62   int src_x;
63   int src_y;
64   int src_w;
65   int src_h;
66 
67   int crtc_x;
68   int crtc_y;
69   int crtc_w;
70   int crtc_h;
71 
72   int zpos;
73 };
74 
75 struct drm_dev_plane {
76   drmModePlanePtr p;
77   int zpos_max;
78   struct plane_prop plane_prop;
79 };
80 
81 struct drm_dev {
82   int drm_fd;
83   int crtc_index;
84   drmModeCrtcPtr crtc;
85   drmModeConnectorPtr connector;
86   drmModePropertyPtr dpms_prop;
87 
88   struct drm_dev_plane plane_primary;
89   struct drm_dev_plane plane_overlay;
90 };
91 
92 int drmGetBuffer(int fd, int width, int height, int format,
93                  struct drm_buf *buffer);
94 int drmPutBuffer(int fd, struct drm_buf *buffer);
95 int drmInit(struct drm_dev *dev);
96 int drmDeinit(struct drm_dev *dev);
97 int drmCommit(struct drm_buf *buffer, int width, int height, int x_off,
98               int y_off, struct drm_dev *dev, int plane_type);
99 int drmSetDpmsMode(uint32_t dpms_mode, struct drm_dev *dev);
100 
101 #endif
102