OSDN Git Service

621f500f2c7aeddee3a88745aefcaf2b0d4fff4d
[android-x86/external-drm_gralloc.git] / gralloc_drm_handle.h
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
27 #include <cutils/native_handle.h>
28 #include "gralloc_drm_formats.h"
29
30 struct gralloc_drm_handle_t {
31         native_handle_t base;
32
33 #define GRALLOC_DRM_HANDLE_MAGIC 0x12345678
34 #define GRALLOC_DRM_HANDLE_NUM_INTS 9
35 #define GRALLOC_DRM_HANDLE_NUM_FDS 0
36         int magic;
37
38         int width;
39         int height;
40         int format;
41         int usage;
42
43         int name;   /* the name of the bo */
44         int stride; /* the stride in bytes */
45
46         int data_owner; /* owner of data (for validation) */
47         int data;       /* pointer to struct gralloc_drm_bo_t */
48 };
49
50 static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle)
51 {
52         struct gralloc_drm_handle_t *handle =
53                 (struct gralloc_drm_handle_t *) _handle;
54
55         if (handle && (handle->base.version != sizeof(handle->base) ||
56                        handle->base.numInts != GRALLOC_DRM_HANDLE_NUM_INTS ||
57                        handle->base.numFds != GRALLOC_DRM_HANDLE_NUM_FDS ||
58                        handle->magic != GRALLOC_DRM_HANDLE_MAGIC))
59                 handle = NULL;
60
61         return handle;
62 }
63
64 static inline void gralloc_drm_yuv_offsets(buffer_handle_t _handle,
65         int *y, int *u, int *v)
66 {
67         struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle);
68         if (handle && *y && *u && *v) {
69                 *y = 0;
70                 switch (handle->format) {
71                         case HAL_PIXEL_FORMAT_YV12:
72                                 *v = handle->stride * handle->height;
73                                 *u = *v + handle->height/2;
74                                 break;
75                         case HAL_PIXEL_FORMAT_DRM_NV12:
76                                 *u = *v = handle->stride * handle->height;
77                                 break;
78                 }
79         }
80 }
81
82 #endif /* _GRALLOC_DRM_HANDLE_H_ */