Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 1 | /* |
| 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> |
Tapani Pälli | 45a9451 | 2012-12-14 10:43:39 +0200 | [diff] [blame] | 28 | #include "gralloc_drm_formats.h" |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 29 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame^] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 34 | struct gralloc_drm_t; |
| 35 | struct gralloc_drm_bo_t; |
| 36 | |
| 37 | struct gralloc_drm_t *gralloc_drm_create(void); |
| 38 | void gralloc_drm_destroy(struct gralloc_drm_t *drm); |
| 39 | |
| 40 | int gralloc_drm_get_fd(struct gralloc_drm_t *drm); |
| 41 | int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic); |
| 42 | int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic); |
| 43 | int gralloc_drm_set_master(struct gralloc_drm_t *drm); |
| 44 | void gralloc_drm_drop_master(struct gralloc_drm_t *drm); |
| 45 | |
| 46 | int gralloc_drm_init_kms(struct gralloc_drm_t *drm); |
Chia-I Wu | d5c39c9 | 2011-07-31 17:09:11 +0900 | [diff] [blame] | 47 | void gralloc_drm_fini_kms(struct gralloc_drm_t *drm); |
| 48 | int gralloc_drm_is_kms_initialized(struct gralloc_drm_t *drm); |
| 49 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 50 | void gralloc_drm_get_kms_info(struct gralloc_drm_t *drm, struct framebuffer_device_t *fb); |
| 51 | int gralloc_drm_is_kms_pipelined(struct gralloc_drm_t *drm); |
| 52 | |
| 53 | static inline int gralloc_drm_get_bpp(int format) |
| 54 | { |
| 55 | int bpp; |
| 56 | |
| 57 | switch (format) { |
| 58 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 59 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 60 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 61 | bpp = 4; |
| 62 | break; |
| 63 | case HAL_PIXEL_FORMAT_RGB_888: |
| 64 | bpp = 3; |
| 65 | break; |
| 66 | case HAL_PIXEL_FORMAT_RGB_565: |
| 67 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 68 | case HAL_PIXEL_FORMAT_RGBA_4444: |
Chia-I Wu | b65a3f8 | 2011-10-27 18:01:23 +0800 | [diff] [blame] | 69 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 70 | bpp = 2; |
| 71 | break; |
Chia-I Wu | b65a3f8 | 2011-10-27 18:01:23 +0800 | [diff] [blame] | 72 | /* planar; only Y is considered */ |
| 73 | case HAL_PIXEL_FORMAT_YV12: |
Tapani Pälli | 45a9451 | 2012-12-14 10:43:39 +0200 | [diff] [blame] | 74 | case HAL_PIXEL_FORMAT_DRM_NV12: |
Chia-I Wu | b65a3f8 | 2011-10-27 18:01:23 +0800 | [diff] [blame] | 75 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 76 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 77 | bpp = 1; |
| 78 | break; |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 79 | default: |
| 80 | bpp = 0; |
| 81 | break; |
| 82 | } |
| 83 | |
| 84 | return bpp; |
| 85 | } |
| 86 | |
Chia-I Wu | b65a3f8 | 2011-10-27 18:01:23 +0800 | [diff] [blame] | 87 | static 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) { |
Tapani Pälli | 45a9451 | 2012-12-14 10:43:39 +0200 | [diff] [blame] | 92 | case HAL_PIXEL_FORMAT_DRM_NV12: |
Chia-I Wu | b65a3f8 | 2011-10-27 18:01:23 +0800 | [diff] [blame] | 93 | case HAL_PIXEL_FORMAT_YV12: |
| 94 | align_w = 32; |
| 95 | align_h = 2; |
| 96 | extra_height_div = 2; |
| 97 | break; |
| 98 | case HAL_PIXEL_FORMAT_YCbCr_422_SP: |
| 99 | align_w = 2; |
| 100 | extra_height_div = 1; |
| 101 | break; |
| 102 | case HAL_PIXEL_FORMAT_YCrCb_420_SP: |
| 103 | align_w = 2; |
| 104 | align_h = 2; |
| 105 | extra_height_div = 2; |
| 106 | break; |
| 107 | case HAL_PIXEL_FORMAT_YCbCr_422_I: |
| 108 | align_w = 2; |
| 109 | break; |
| 110 | } |
| 111 | |
| 112 | *width = (*width + align_w - 1) & ~(align_w - 1); |
| 113 | *height = (*height + align_h - 1) & ~(align_h - 1); |
| 114 | |
| 115 | if (extra_height_div) |
| 116 | *height += *height / extra_height_div; |
| 117 | } |
| 118 | |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 119 | int gralloc_drm_handle_register(buffer_handle_t handle, struct gralloc_drm_t *drm); |
| 120 | int gralloc_drm_handle_unregister(buffer_handle_t handle); |
| 121 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 122 | struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage); |
Tapani Pälli | a86ecd9 | 2012-08-01 16:06:00 +0300 | [diff] [blame] | 123 | void gralloc_drm_bo_decref(struct gralloc_drm_bo_t *bo); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 124 | |
Chia-I Wu | 8542de3 | 2011-07-31 16:35:21 +0900 | [diff] [blame] | 125 | struct gralloc_drm_bo_t *gralloc_drm_bo_from_handle(buffer_handle_t handle); |
| 126 | buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride); |
Tapani Pälli | 421d4ec | 2013-01-15 13:58:57 +0200 | [diff] [blame] | 127 | int gralloc_drm_get_gem_handle(buffer_handle_t handle); |
Tapani Pälli | a8f0334 | 2013-01-18 15:01:43 +0200 | [diff] [blame] | 128 | void gralloc_drm_resolve_format(buffer_handle_t _handle, uint32_t *pitches, uint32_t *offsets, uint32_t *handles); |
Tapani Pälli | 73e275e | 2013-01-21 14:58:33 +0200 | [diff] [blame] | 129 | unsigned int planes_for_format(struct gralloc_drm_t *drm, int hal_format); |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 130 | |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame] | 131 | int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr); |
| 132 | void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 133 | |
| 134 | int gralloc_drm_bo_need_fb(const struct gralloc_drm_bo_t *bo); |
| 135 | int gralloc_drm_bo_add_fb(struct gralloc_drm_bo_t *bo); |
| 136 | void gralloc_drm_bo_rm_fb(struct gralloc_drm_bo_t *bo); |
| 137 | int gralloc_drm_bo_post(struct gralloc_drm_bo_t *bo); |
| 138 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame^] | 139 | #ifdef __cplusplus |
| 140 | } |
| 141 | #endif |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 142 | #endif /* _GRALLOC_DRM_H_ */ |