blob: cf2d71ceb1f82b24a4a8d686df000f1da0dded77 [file] [log] [blame]
Chia-I Wu2ec32d42011-06-12 16:21:30 +08001/*
2 * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
3 * Copyright (C) 2010-2011 LunarG Inc.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
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.
22 */
23
24#ifndef _GRALLOC_DRM_H_
25#define _GRALLOC_DRM_H_
26
27#include <hardware/gralloc.h>
28
29struct gralloc_drm_t;
30struct gralloc_drm_bo_t;
31
32struct gralloc_drm_t *gralloc_drm_create(void);
33void gralloc_drm_destroy(struct gralloc_drm_t *drm);
34
35int gralloc_drm_get_fd(struct gralloc_drm_t *drm);
36int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic);
37int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic);
38int gralloc_drm_set_master(struct gralloc_drm_t *drm);
39void gralloc_drm_drop_master(struct gralloc_drm_t *drm);
40
41int gralloc_drm_init_kms(struct gralloc_drm_t *drm);
Chia-I Wud5c39c92011-07-31 17:09:11 +090042void gralloc_drm_fini_kms(struct gralloc_drm_t *drm);
43int gralloc_drm_is_kms_initialized(struct gralloc_drm_t *drm);
44
Chia-I Wu2ec32d42011-06-12 16:21:30 +080045void gralloc_drm_get_kms_info(struct gralloc_drm_t *drm, struct framebuffer_device_t *fb);
46int gralloc_drm_is_kms_pipelined(struct gralloc_drm_t *drm);
47
48static inline int gralloc_drm_get_bpp(int format)
49{
50 int bpp;
51
52 switch (format) {
53 case HAL_PIXEL_FORMAT_RGBA_8888:
54 case HAL_PIXEL_FORMAT_RGBX_8888:
55 case HAL_PIXEL_FORMAT_BGRA_8888:
56 bpp = 4;
57 break;
58 case HAL_PIXEL_FORMAT_RGB_888:
59 bpp = 3;
60 break;
61 case HAL_PIXEL_FORMAT_RGB_565:
62 case HAL_PIXEL_FORMAT_RGBA_5551:
63 case HAL_PIXEL_FORMAT_RGBA_4444:
Chia-I Wub65a3f82011-10-27 18:01:23 +080064 case HAL_PIXEL_FORMAT_YCbCr_422_I:
Chia-I Wu2ec32d42011-06-12 16:21:30 +080065 bpp = 2;
66 break;
Chia-I Wub65a3f82011-10-27 18:01:23 +080067 /* planar; only Y is considered */
68 case HAL_PIXEL_FORMAT_YV12:
69 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
70 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
71 bpp = 1;
72 break;
Chia-I Wu2ec32d42011-06-12 16:21:30 +080073 default:
74 bpp = 0;
75 break;
76 }
77
78 return bpp;
79}
80
Chia-I Wub65a3f82011-10-27 18:01:23 +080081static inline void gralloc_drm_align_geometry(int format, int *width, int *height)
82{
83 int align_w = 1, align_h = 1, extra_height_div = 0;
84
85 switch (format) {
86 case HAL_PIXEL_FORMAT_YV12:
87 align_w = 32;
88 align_h = 2;
89 extra_height_div = 2;
90 break;
91 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
92 align_w = 2;
93 extra_height_div = 1;
94 break;
95 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
96 align_w = 2;
97 align_h = 2;
98 extra_height_div = 2;
99 break;
100 case HAL_PIXEL_FORMAT_YCbCr_422_I:
101 align_w = 2;
102 break;
103 }
104
105 *width = (*width + align_w - 1) & ~(align_w - 1);
106 *height = (*height + align_h - 1) & ~(align_h - 1);
107
108 if (extra_height_div)
109 *height += *height / extra_height_div;
110}
111
Chia-I Wu8542de32011-07-31 16:35:21 +0900112int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm);
113int gralloc_drm_handle_unregister(buffer_handle_t handle);
114
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800115struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage);
Tapani Pällia86ecd92012-08-01 16:06:00 +0300116void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800117
Chia-I Wu8542de32011-07-31 16:35:21 +0900118struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle);
119buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);
Chia-I Wu2fc5da42011-07-29 19:57:04 +0900120
Chia-I Wu25e04132011-07-29 20:43:12 +0900121int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr);
122void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800123
124int gralloc_drm_bo_need_fb(const struct gralloc_drm_bo_t *bo);
125int gralloc_drm_bo_add_fb(struct gralloc_drm_bo_t *bo);
126void gralloc_drm_bo_rm_fb(struct gralloc_drm_bo_t *bo);
127int gralloc_drm_bo_post(struct gralloc_drm_bo_t *bo);
128
129#endif /* _GRALLOC_DRM_H_ */