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_H_
25 #define _GRALLOC_DRM_H_
27 #include <hardware/gralloc.h>
28 #include "gralloc_drm_formats.h"
34 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
35 #define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
38 struct gralloc_drm_bo_t;
41 GRALLOC_MODULE_PERFORM_GET_DRM_FD = 0x40000002,
42 GRALLOC_MODULE_PERFORM_GET_DRM_MAGIC = 0x80000003,
43 GRALLOC_MODULE_PERFORM_AUTH_DRM_MAGIC = 0x80000004,
44 GRALLOC_MODULE_PERFORM_ENTER_VT = 0x80000005,
45 GRALLOC_MODULE_PERFORM_LEAVE_VT = 0x80000006,
48 struct gralloc_drm_t *gralloc_drm_create(void);
49 void gralloc_drm_destroy(struct gralloc_drm_t *drm);
51 int gralloc_drm_get_fd(struct gralloc_drm_t *drm);
52 int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic);
53 int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic);
54 int gralloc_drm_set_master(struct gralloc_drm_t *drm);
55 void gralloc_drm_drop_master(struct gralloc_drm_t *drm);
57 int gralloc_drm_init_kms(struct gralloc_drm_t *drm);
58 void gralloc_drm_fini_kms(struct gralloc_drm_t *drm);
59 int gralloc_drm_is_kms_initialized(struct gralloc_drm_t *drm);
61 void gralloc_drm_get_kms_info(struct gralloc_drm_t *drm, struct framebuffer_device_t *fb);
62 int gralloc_drm_is_kms_pipelined(struct gralloc_drm_t *drm);
64 static inline int gralloc_drm_get_bpp(int format)
69 case HAL_PIXEL_FORMAT_RGBA_8888:
70 case HAL_PIXEL_FORMAT_RGBX_8888:
71 case HAL_PIXEL_FORMAT_BGRA_8888:
74 case HAL_PIXEL_FORMAT_RGB_888:
77 case HAL_PIXEL_FORMAT_RGB_565:
78 case HAL_PIXEL_FORMAT_YCbCr_422_I:
81 /* planar; only Y is considered */
82 case HAL_PIXEL_FORMAT_YV12:
83 case HAL_PIXEL_FORMAT_DRM_NV12:
84 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
85 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
96 static inline void gralloc_drm_align_geometry(int format, int *width, int *height)
98 int align_w = 1, align_h = 1, extra_height_div = 0;
101 case HAL_PIXEL_FORMAT_DRM_NV12:
102 case HAL_PIXEL_FORMAT_YV12:
105 extra_height_div = 2;
107 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
109 extra_height_div = 1;
111 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
114 extra_height_div = 2;
116 case HAL_PIXEL_FORMAT_YCbCr_422_I:
121 *width = ALIGN(*width, align_w);
122 *height = ALIGN(*height, align_h);
124 if (extra_height_div)
125 *height += *height / extra_height_div;
128 int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm);
129 int gralloc_drm_handle_unregister(buffer_handle_t handle);
131 struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage);
132 void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo);
134 struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle);
135 buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);
136 int gralloc_drm_get_prime_fd(buffer_handle_t _handle);
137 int gralloc_drm_get_gem_handle(buffer_handle_t handle);
138 void gralloc_drm_resolve_format(buffer_handle_t _handle, uint32_t *pitches, uint32_t *offsets, uint32_t *handles);
139 unsigned int planes_for_format(struct gralloc_drm_t *drm, int hal_format);
141 int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr);
142 void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo);
144 int gralloc_drm_bo_need_fb(const struct gralloc_drm_bo_t *bo);
145 int gralloc_drm_bo_add_fb(struct gralloc_drm_bo_t *bo);
146 void gralloc_drm_bo_rm_fb(struct gralloc_drm_bo_t *bo);
147 int gralloc_drm_bo_post(struct gralloc_drm_bo_t *bo);
149 int gralloc_drm_reserve_plane(struct gralloc_drm_t *drm,
150 buffer_handle_t handle, uint32_t id,
151 uint32_t dst_x, uint32_t dst_y, uint32_t dst_w, uint32_t dst_h,
152 uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h);
153 void gralloc_drm_disable_planes(struct gralloc_drm_t *mod);
154 int gralloc_drm_set_plane_handle(struct gralloc_drm_t *drm,
155 uint32_t id, buffer_handle_t handle);
160 #endif /* _GRALLOC_DRM_H_ */