blob: 3ad818f8c9c89429fbae43b21fcb3d3d1a490b02 [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>
Sean V Kelley3e00d322013-05-01 15:02:39 -070028#include <system/graphics.h>
Chia-I Wu2ec32d42011-06-12 16:21:30 +080029
Chih-Wei Huang4b3db542013-04-11 10:41:50 +030030#ifdef __cplusplus
31extern "C" {
32#endif
33
Tapani Pällidf57ea92013-04-22 08:20:39 +030034#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
35
Chia-I Wu2ec32d42011-06-12 16:21:30 +080036struct gralloc_drm_t;
37struct gralloc_drm_bo_t;
38
Sean Paul9b27aa82015-02-09 02:27:39 -050039enum {
40 GRALLOC_MODULE_PERFORM_GET_DRM_FD = 0x80000002,
Sean Paul9b27aa82015-02-09 02:27:39 -050041};
42
Chia-I Wu2ec32d42011-06-12 16:21:30 +080043struct gralloc_drm_t *gralloc_drm_create(void);
44void gralloc_drm_destroy(struct gralloc_drm_t *drm);
45
46int gralloc_drm_get_fd(struct gralloc_drm_t *drm);
Chia-I Wu2ec32d42011-06-12 16:21:30 +080047
Chia-I Wu2ec32d42011-06-12 16:21:30 +080048static 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:
Chia-I Wub65a3f82011-10-27 18:01:23 +080062 case HAL_PIXEL_FORMAT_YCbCr_422_I:
Chia-I Wu2ec32d42011-06-12 16:21:30 +080063 bpp = 2;
64 break;
Chia-I Wub65a3f82011-10-27 18:01:23 +080065 /* planar; only Y is considered */
66 case HAL_PIXEL_FORMAT_YV12:
67 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
68 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
69 bpp = 1;
70 break;
Chia-I Wu2ec32d42011-06-12 16:21:30 +080071 default:
72 bpp = 0;
73 break;
74 }
75
76 return bpp;
77}
78
Chia-I Wub65a3f82011-10-27 18:01:23 +080079static inline void gralloc_drm_align_geometry(int format, int *width, int *height)
80{
81 int align_w = 1, align_h = 1, extra_height_div = 0;
82
83 switch (format) {
84 case HAL_PIXEL_FORMAT_YV12:
85 align_w = 32;
86 align_h = 2;
87 extra_height_div = 2;
88 break;
89 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
90 align_w = 2;
91 extra_height_div = 1;
92 break;
93 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
94 align_w = 2;
95 align_h = 2;
96 extra_height_div = 2;
97 break;
98 case HAL_PIXEL_FORMAT_YCbCr_422_I:
99 align_w = 2;
100 break;
101 }
102
Tapani Pällidf57ea92013-04-22 08:20:39 +0300103 *width = ALIGN(*width, align_w);
104 *height = ALIGN(*height, align_h);
Chia-I Wub65a3f82011-10-27 18:01:23 +0800105
106 if (extra_height_div)
107 *height += *height / extra_height_div;
108}
109
Chia-I Wu8542de32011-07-31 16:35:21 +0900110int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm);
111int gralloc_drm_handle_unregister(buffer_handle_t handle);
112
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800113struct 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 +0300114void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800115
Chia-I Wu8542de32011-07-31 16:35:21 +0900116struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle);
117buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);
Tapani Pälli421d4ec2013-01-15 13:58:57 +0200118int gralloc_drm_get_gem_handle(buffer_handle_t handle);
Tapani Pällia8f03342013-01-18 15:01:43 +0200119void gralloc_drm_resolve_format(buffer_handle_t _handle, uint32_t *pitches, uint32_t *offsets, uint32_t *handles);
Tapani Pälli73e275e2013-01-21 14:58:33 +0200120unsigned int planes_for_format(struct gralloc_drm_t *drm, int hal_format);
Chia-I Wu2fc5da42011-07-29 19:57:04 +0900121
Chia-I Wu25e04132011-07-29 20:43:12 +0900122int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr);
123void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800124
Chih-Wei Huang4b3db542013-04-11 10:41:50 +0300125#ifdef __cplusplus
126}
127#endif
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800128#endif /* _GRALLOC_DRM_H_ */