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_HANDLE_H_ |
| 25 | #define _GRALLOC_DRM_HANDLE_H_ |
| 26 | |
Ben Chan | 31b96bf | 2017-03-03 17:47:26 -0800 | [diff] [blame] | 27 | #include <cutils/log.h> |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 28 | #include <cutils/native_handle.h> |
Sean V Kelley | 3e00d32 | 2013-05-01 15:02:39 -0700 | [diff] [blame] | 29 | #include <system/graphics.h> |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 30 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame] | 35 | struct gralloc_drm_bo_t; |
| 36 | |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 37 | struct gralloc_drm_handle_t { |
| 38 | native_handle_t base; |
| 39 | |
Sean Paul | 879cc4e | 2015-02-09 02:39:09 -0500 | [diff] [blame] | 40 | /* file descriptors */ |
| 41 | int prime_fd; |
| 42 | |
| 43 | /* integers */ |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 44 | int magic; |
| 45 | |
| 46 | int width; |
| 47 | int height; |
| 48 | int format; |
| 49 | int usage; |
| 50 | |
| 51 | int name; /* the name of the bo */ |
| 52 | int stride; /* the stride in bytes */ |
| 53 | |
Chih-Wei Huang | 68a74eb | 2014-12-01 01:46:20 +0800 | [diff] [blame] | 54 | struct gralloc_drm_bo_t *data; /* pointer to struct gralloc_drm_bo_t */ |
Sean Paul | 879cc4e | 2015-02-09 02:39:09 -0500 | [diff] [blame] | 55 | |
| 56 | // FIXME: the attributes below should be out-of-line |
| 57 | uint64_t unknown __attribute__((aligned(8))); |
| 58 | int data_owner; /* owner of data (for validation) */ |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 59 | }; |
Sean Paul | 879cc4e | 2015-02-09 02:39:09 -0500 | [diff] [blame] | 60 | #define GRALLOC_DRM_HANDLE_MAGIC 0x12345678 |
| 61 | #define GRALLOC_DRM_HANDLE_NUM_FDS 1 |
| 62 | #define GRALLOC_DRM_HANDLE_NUM_INTS ( \ |
| 63 | ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int)) \ |
| 64 | - GRALLOC_DRM_HANDLE_NUM_FDS) |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 65 | |
| 66 | static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle) |
| 67 | { |
| 68 | struct gralloc_drm_handle_t *handle = |
| 69 | (struct gralloc_drm_handle_t *) _handle; |
| 70 | |
Chia-I Wu | 75ee75c | 2011-07-30 15:43:48 +0900 | [diff] [blame] | 71 | if (handle && (handle->base.version != sizeof(handle->base) || |
| 72 | handle->base.numInts != GRALLOC_DRM_HANDLE_NUM_INTS || |
| 73 | handle->base.numFds != GRALLOC_DRM_HANDLE_NUM_FDS || |
Sean Paul | 879cc4e | 2015-02-09 02:39:09 -0500 | [diff] [blame] | 74 | handle->magic != GRALLOC_DRM_HANDLE_MAGIC)) { |
| 75 | ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x", |
| 76 | handle->base.version, handle->base.numInts, |
| 77 | handle->base.numFds, handle->magic); |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 78 | handle = NULL; |
Sean Paul | 879cc4e | 2015-02-09 02:39:09 -0500 | [diff] [blame] | 79 | } |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 80 | |
| 81 | return handle; |
| 82 | } |
| 83 | |
Garfield Tan | 5a1d7de | 2017-10-13 18:01:11 -0700 | [diff] [blame] | 84 | /* |
| 85 | * The functions supported by gralloc_drm's temporary private API are listed |
| 86 | * below. Use of these functions is highly discouraged and should only be |
| 87 | * reserved for cases where no alternative to get same information (such as |
| 88 | * querying ANativeWindow) exists. |
| 89 | */ |
| 90 | enum { |
| 91 | GRALLOC_DRM_GET_STRIDE, |
| 92 | GRALLOC_DRM_GET_FORMAT, |
| 93 | GRALLOC_DRM_GET_DIMENSIONS, |
| 94 | GRALLOC_DRM_GET_BACKING_STORE, |
| 95 | }; |
| 96 | |
Chih-Wei Huang | 4b3db54 | 2013-04-11 10:41:50 +0300 | [diff] [blame] | 97 | #ifdef __cplusplus |
| 98 | } |
| 99 | #endif |
Chia-I Wu | 2ec32d4 | 2011-06-12 16:21:30 +0800 | [diff] [blame] | 100 | #endif /* _GRALLOC_DRM_HANDLE_H_ */ |