2 * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3 * Copyright (C) 2010-2011 LunarG Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #ifndef _GRALLOC_DRM_PRIV_H_
25 #define _GRALLOC_DRM_PRIV_H_
29 #include <xf86drmMode.h>
31 #include "gralloc_drm_handle.h"
37 /* how a bo is posted */
45 enum hdmi_output_mode {
50 struct gralloc_drm_plane_t {
51 drmModePlane *drm_plane;
53 /* plane has been set to display a layer */
56 /* handle to display */
57 buffer_handle_t handle;
59 /* identifier set by hwc */
62 /* position, crop and scale */
72 /* previous buffer, for refcounting */
73 struct gralloc_drm_bo_t *prev;
76 struct gralloc_drm_output
79 uint32_t connector_id;
87 /* 'private fb' for this output */
88 struct gralloc_drm_bo_t *bo;
91 struct gralloc_drm_t {
92 /* initialized by gralloc_drm_create */
94 struct gralloc_drm_drv_t *drv;
96 /* initialized by gralloc_drm_init_kms */
97 drmModeResPtr resources;
98 struct gralloc_drm_output primary;
99 struct gralloc_drm_output hdmi;
100 enum hdmi_output_mode hdmi_mode;
103 pthread_mutex_t hdmi_mutex;
104 pthread_t hdmi_hotplug_thread;
106 #ifdef DRM_MODE_FEATURE_DIRTYFB
110 /* initialized by drv->init_kms_features */
111 enum drm_swap_mode swap_mode;
113 int mode_quirk_vmwgfx;
114 int mode_sync_flip; /* page flip should block */
115 int vblank_secondary;
117 drmEventContext evctx;
120 struct gralloc_drm_bo_t *current_front, *next_front;
122 unsigned int last_swap;
125 drmModePlaneResPtr plane_resources;
126 struct gralloc_drm_plane_t *planes;
129 struct drm_module_t {
130 gralloc_module_t base;
133 int (*hwc_reserve_plane) (struct gralloc_drm_t *mod,
134 buffer_handle_t handle, uint32_t id,
135 uint32_t dst_x, uint32_t dst_y, uint32_t dst_w, uint32_t dst_h,
136 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h);
137 void (*hwc_disable_planes) (struct gralloc_drm_t *mod);
138 int (*hwc_set_plane_handle) (struct gralloc_drm_t *mod,
139 uint32_t id, buffer_handle_t handle);
141 pthread_mutex_t mutex;
142 struct gralloc_drm_t *drm;
145 struct gralloc_drm_drv_t {
146 /* destroy the driver */
147 void (*destroy)(struct gralloc_drm_drv_t *drv);
149 /* initialize KMS features */
150 void (*init_kms_features)(struct gralloc_drm_drv_t *drv,
151 struct gralloc_drm_t *drm);
153 /* allocate or import a bo */
154 struct gralloc_drm_bo_t *(*alloc)(struct gralloc_drm_drv_t *drv,
155 struct gralloc_drm_handle_t *handle);
158 void (*free)(struct gralloc_drm_drv_t *drv,
159 struct gralloc_drm_bo_t *bo);
161 /* map a bo for CPU access */
162 int (*map)(struct gralloc_drm_drv_t *drv,
163 struct gralloc_drm_bo_t *bo,
164 int x, int y, int w, int h, int enable_write, void **addr);
167 void (*unmap)(struct gralloc_drm_drv_t *drv,
168 struct gralloc_drm_bo_t *bo);
170 /* blit between two bo's, used for DRM_SWAP_COPY and general blitting */
171 void (*blit)(struct gralloc_drm_drv_t *drv,
172 struct gralloc_drm_bo_t *dst,
173 struct gralloc_drm_bo_t *src,
174 uint16_t dst_x1, uint16_t dst_y1,
175 uint16_t dst_x2, uint16_t dst_y2,
176 uint16_t src_x1, uint16_t src_y1,
177 uint16_t src_x2, uint16_t src_y2);
179 /* query component offsets, strides and handles for a format */
180 void (*resolve_format)(struct gralloc_drm_drv_t *drv,
181 struct gralloc_drm_bo_t *bo,
182 uint32_t *pitches, uint32_t *offsets, uint32_t *handles);
185 struct gralloc_drm_bo_t {
186 struct gralloc_drm_t *drm;
187 struct gralloc_drm_handle_t *handle;
189 int imported; /* the handle is from a remote proces when true */
190 int fb_handle; /* the GEM handle of the bo */
191 int fb_id; /* the fb id */
196 unsigned int refcount;
199 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name);
200 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_intel(int fd);
201 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_radeon(int fd);
202 struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_nouveau(int fd);
207 #endif /* _GRALLOC_DRM_PRIV_H_ */