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> |
| 28 | |
| 29 | struct gralloc_drm_t; |
| 30 | struct gralloc_drm_bo_t; |
| 31 | |
| 32 | struct gralloc_drm_t *gralloc_drm_create(void); |
| 33 | void gralloc_drm_destroy(struct gralloc_drm_t *drm); |
| 34 | |
| 35 | int gralloc_drm_get_fd(struct gralloc_drm_t *drm); |
| 36 | int gralloc_drm_get_magic(struct gralloc_drm_t *drm, int32_t *magic); |
| 37 | int gralloc_drm_auth_magic(struct gralloc_drm_t *drm, int32_t magic); |
| 38 | int gralloc_drm_set_master(struct gralloc_drm_t *drm); |
| 39 | void gralloc_drm_drop_master(struct gralloc_drm_t *drm); |
| 40 | |
| 41 | int gralloc_drm_init_kms(struct gralloc_drm_t *drm); |
| 42 | void gralloc_drm_get_kms_info(struct gralloc_drm_t *drm, struct framebuffer_device_t *fb); |
| 43 | int gralloc_drm_is_kms_pipelined(struct gralloc_drm_t *drm); |
| 44 | |
| 45 | static inline int gralloc_drm_get_bpp(int format) |
| 46 | { |
| 47 | int bpp; |
| 48 | |
| 49 | switch (format) { |
| 50 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 51 | case HAL_PIXEL_FORMAT_RGBX_8888: |
| 52 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 53 | bpp = 4; |
| 54 | break; |
| 55 | case HAL_PIXEL_FORMAT_RGB_888: |
| 56 | bpp = 3; |
| 57 | break; |
| 58 | case HAL_PIXEL_FORMAT_RGB_565: |
| 59 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 60 | case HAL_PIXEL_FORMAT_RGBA_4444: |
| 61 | bpp = 2; |
| 62 | break; |
| 63 | default: |
| 64 | bpp = 0; |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | return bpp; |
| 69 | } |
| 70 | |
| 71 | struct gralloc_drm_bo_t *gralloc_drm_bo_create(struct gralloc_drm_t *drm, int width, int height, int format, int usage); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 72 | void gralloc_drm_bo_destroy(struct gralloc_drm_bo_t *bo); |
| 73 | |
Chia-I Wu | 2fc5da4 | 2011-07-29 19:57:04 +0900 | [diff] [blame] | 74 | struct gralloc_drm_bo_t *gralloc_drm_bo_register(struct gralloc_drm_t *drm, buffer_handle_t handle, int create); |
| 75 | void gralloc_drm_bo_unregister(struct gralloc_drm_bo_t *bo); |
| 76 | |
| 77 | static inline struct gralloc_drm_bo_t *gralloc_drm_bo_validate(struct gralloc_drm_t *drm, buffer_handle_t handle) |
| 78 | { |
| 79 | return gralloc_drm_bo_register(drm, handle, 0); |
| 80 | } |
| 81 | |
Chia-I Wu | 25e0413 | 2011-07-29 20:43:12 +0900 | [diff] [blame^] | 82 | int gralloc_drm_bo_lock(struct gralloc_drm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr); |
| 83 | void gralloc_drm_bo_unlock(struct gralloc_drm_bo_t *bo); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 84 | buffer_handle_t gralloc_drm_bo_get_handle(struct gralloc_drm_bo_t *bo, int *stride); |
| 85 | |
| 86 | int gralloc_drm_bo_need_fb(const struct gralloc_drm_bo_t *bo); |
| 87 | int gralloc_drm_bo_add_fb(struct gralloc_drm_bo_t *bo); |
| 88 | void gralloc_drm_bo_rm_fb(struct gralloc_drm_bo_t *bo); |
| 89 | int gralloc_drm_bo_post(struct gralloc_drm_bo_t *bo); |
| 90 | |
| 91 | #endif /* _GRALLOC_DRM_H_ */ |