blob: 1b464cfeec8c86fae433ef9a24917bed53303801 [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,
41 GRALLOC_MODULE_PERFORM_GET_DRM_MAGIC = 0x80000003,
42 GRALLOC_MODULE_PERFORM_AUTH_DRM_MAGIC = 0x80000004,
43 GRALLOC_MODULE_PERFORM_ENTER_VT = 0x80000005,
44 GRALLOC_MODULE_PERFORM_LEAVE_VT = 0x80000006,
45};
46
Chia-I Wu2ec32d42011-06-12 16:21:30 +080047struct gralloc_drm_t *gralloc_drm_create(void);
48void gralloc_drm_destroy(struct gralloc_drm_t *drm);
49
50int gralloc_drm_get_fd(struct gralloc_drm_t *drm);
51int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic);
52int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic);
53int gralloc_drm_set_master(struct gralloc_drm_t *drm);
54void gralloc_drm_drop_master(struct gralloc_drm_t *drm);
55
Chia-I Wu2ec32d42011-06-12 16:21:30 +080056static inline int gralloc_drm_get_bpp(int format)
57{
58 int bpp;
59
60 switch (format) {
61 case HAL_PIXEL_FORMAT_RGBA_8888:
62 case HAL_PIXEL_FORMAT_RGBX_8888:
63 case HAL_PIXEL_FORMAT_BGRA_8888:
64 bpp = 4;
65 break;
66 case HAL_PIXEL_FORMAT_RGB_888:
67 bpp = 3;
68 break;
69 case HAL_PIXEL_FORMAT_RGB_565:
Chia-I Wub65a3f82011-10-27 18:01:23 +080070 case HAL_PIXEL_FORMAT_YCbCr_422_I:
Chia-I Wu2ec32d42011-06-12 16:21:30 +080071 bpp = 2;
72 break;
Chia-I Wub65a3f82011-10-27 18:01:23 +080073 /* planar; only Y is considered */
74 case HAL_PIXEL_FORMAT_YV12:
75 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
76 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
77 bpp = 1;
78 break;
Chia-I Wu2ec32d42011-06-12 16:21:30 +080079 default:
80 bpp = 0;
81 break;
82 }
83
84 return bpp;
85}
86
Chia-I Wub65a3f82011-10-27 18:01:23 +080087static inline void gralloc_drm_align_geometry(int format, int *width, int *height)
88{
89 int align_w = 1, align_h = 1, extra_height_div = 0;
90
91 switch (format) {
92 case HAL_PIXEL_FORMAT_YV12:
93 align_w = 32;
94 align_h = 2;
95 extra_height_div = 2;
96 break;
97 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
98 align_w = 2;
99 extra_height_div = 1;
100 break;
101 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
102 align_w = 2;
103 align_h = 2;
104 extra_height_div = 2;
105 break;
106 case HAL_PIXEL_FORMAT_YCbCr_422_I:
107 align_w = 2;
108 break;
109 }
110
Tapani Pällidf57ea92013-04-22 08:20:39 +0300111 *width = ALIGN(*width, align_w);
112 *height = ALIGN(*height, align_h);
Chia-I Wub65a3f82011-10-27 18:01:23 +0800113
114 if (extra_height_div)
115 *height += *height / extra_height_div;
116}
117
Chia-I Wu8542de32011-07-31 16:35:21 +0900118int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm);
119int gralloc_drm_handle_unregister(buffer_handle_t handle);
120
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800121struct 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 +0300122void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800123
Chia-I Wu8542de32011-07-31 16:35:21 +0900124struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle);
125buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride);
Tapani Pälli421d4ec2013-01-15 13:58:57 +0200126int gralloc_drm_get_gem_handle(buffer_handle_t handle);
Tapani Pällia8f03342013-01-18 15:01:43 +0200127void 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 +0200128unsigned int planes_for_format(struct gralloc_drm_t *drm, int hal_format);
Chia-I Wu2fc5da42011-07-29 19:57:04 +0900129
Chia-I Wu25e04132011-07-29 20:43:12 +0900130int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr);
131void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo);
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800132
Chih-Wei Huang4b3db542013-04-11 10:41:50 +0300133#ifdef __cplusplus
134}
135#endif
Chia-I Wu2ec32d42011-06-12 16:21:30 +0800136#endif /* _GRALLOC_DRM_H_ */