Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 1 | /* |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef GRALLOC_PRIV_H_ |
| 18 | #define GRALLOC_PRIV_H_ |
| 19 | |
| 20 | #include <stdint.h> |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 21 | #include <limits.h> |
| 22 | #include <sys/cdefs.h> |
| 23 | #include <hardware/gralloc.h> |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 24 | #include <pthread.h> |
| 25 | #include <errno.h> |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 26 | #include <unistd.h> |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 27 | |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 28 | #include <cutils/native_handle.h> |
| 29 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 30 | #include <linux/fb.h> |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 31 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 32 | /*****************************************************************************/ |
Dima Zavin | a9301d1 | 2012-03-01 10:22:09 -0800 | [diff] [blame] | 33 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 34 | struct private_module_t; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 35 | struct private_handle_t; |
| 36 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 37 | struct private_module_t { |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 38 | gralloc_module_t base; |
| 39 | |
Greg Hackmann | 8c372e3 | 2013-01-15 09:29:40 -0800 | [diff] [blame] | 40 | struct private_handle_t* framebuffer; |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 41 | uint32_t flags; |
| 42 | uint32_t numBuffers; |
| 43 | uint32_t bufferMask; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 44 | pthread_mutex_t lock; |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 45 | buffer_handle_t currentBuffer; |
| 46 | int ionfd; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 47 | |
Greg Hackmann | d37bc2b | 2012-05-23 16:29:43 -0700 | [diff] [blame] | 48 | int xres; |
| 49 | int yres; |
| 50 | int line_length; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 51 | float xdpi; |
| 52 | float ydpi; |
| 53 | float fps; |
Greg Hackmann | dd55738 | 2012-05-03 14:51:28 -0700 | [diff] [blame] | 54 | void *queue; |
| 55 | pthread_mutex_t queue_lock; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 56 | |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 59 | /*****************************************************************************/ |
| 60 | |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 61 | #ifdef __cplusplus |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 62 | struct private_handle_t : public native_handle { |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 63 | #else |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 64 | struct private_handle_t { |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 65 | struct native_handle nativeHandle; |
| 66 | #endif |
| 67 | |
Alex Ray | 06f1fa7 | 2013-04-15 11:24:13 -0700 | [diff] [blame^] | 68 | // set if using video encoding colorspace |
| 69 | #define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0) |
| 70 | |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 71 | enum { |
| 72 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
| 73 | PRIV_FLAGS_USES_UMP = 0x00000002, |
Erik Gilling | 80b3e6c | 2012-04-05 15:34:47 -0700 | [diff] [blame] | 74 | PRIV_FLAGS_USES_ION = 0x00000020 |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 77 | // file-descriptors |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 78 | int fd; |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 79 | int fd1; |
| 80 | int fd2; |
| 81 | // ints |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 82 | int magic; |
| 83 | int flags; |
| 84 | int size; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 85 | int offset; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 86 | |
| 87 | int format; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 88 | int width; |
| 89 | int height; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 90 | int stride; |
Rebecca Schultz Zavin | 70212e5 | 2012-08-15 11:17:04 -0700 | [diff] [blame] | 91 | int vstride; |
Alex Ray | b528b80 | 2013-01-30 21:19:59 -0800 | [diff] [blame] | 92 | int gamut; |
Alex Ray | d09ee48 | 2013-03-05 12:47:50 -0800 | [diff] [blame] | 93 | int chroma; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 94 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 95 | // FIXME: the attributes below should be out-of-line |
| 96 | void *base; |
Rebecca Schultz Zavin | ec68ab2 | 2012-08-27 10:58:52 -0700 | [diff] [blame] | 97 | void *base1; |
| 98 | void *base2; |
| 99 | struct ion_handle *handle; |
| 100 | struct ion_handle *handle1; |
| 101 | struct ion_handle *handle2; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 102 | |
| 103 | #ifdef __cplusplus |
Rebecca Schultz Zavin | 471812b | 2012-05-15 16:49:56 -0700 | [diff] [blame] | 104 | static const int sNumFds = 3; |
Alex Ray | d09ee48 | 2013-03-05 12:47:50 -0800 | [diff] [blame] | 105 | static const int sNumInts = 17; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 106 | static const int sMagic = 0x3141592; |
Dima Zavin | 06062cd | 2012-04-03 00:10:57 -0700 | [diff] [blame] | 107 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 108 | |
| 109 | private_handle_t(int fd, int size, int flags, int w, |
Rebecca Schultz Zavin | 70212e5 | 2012-08-15 11:17:04 -0700 | [diff] [blame] | 110 | int h, int format, int stride, int vstride) : |
Rebecca Schultz Zavin | ec68ab2 | 2012-08-27 10:58:52 -0700 | [diff] [blame] | 111 | fd(fd), fd1(-1), fd2(-1), magic(sMagic), flags(flags), size(size), |
Rebecca Schultz Zavin | 70212e5 | 2012-08-15 11:17:04 -0700 | [diff] [blame] | 112 | offset(0), format(format), width(w), height(h), stride(stride), |
Alex Ray | d09ee48 | 2013-03-05 12:47:50 -0800 | [diff] [blame] | 113 | vstride(vstride), gamut(0), chroma(0), base(0), handle(0), handle1(0), |
| 114 | handle2(0) |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 115 | { |
| 116 | version = sizeof(native_handle); |
Rebecca Schultz Zavin | ec68ab2 | 2012-08-27 10:58:52 -0700 | [diff] [blame] | 117 | numInts = sNumInts + 2; |
| 118 | numFds = sNumFds - 2; |
| 119 | } |
| 120 | |
| 121 | private_handle_t(int fd, int fd1, int size, int flags, int w, |
| 122 | int h, int format, int stride, int vstride) : |
| 123 | fd(fd), fd1(fd1), fd2(-1), magic(sMagic), flags(flags), size(size), |
| 124 | offset(0), format(format), width(w), height(h), stride(stride), |
Alex Ray | d09ee48 | 2013-03-05 12:47:50 -0800 | [diff] [blame] | 125 | vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0), |
| 126 | handle(0), handle1(0), handle2(0) |
Rebecca Schultz Zavin | ec68ab2 | 2012-08-27 10:58:52 -0700 | [diff] [blame] | 127 | { |
| 128 | version = sizeof(native_handle); |
| 129 | numInts = sNumInts + 1; |
| 130 | numFds = sNumFds - 1; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 133 | private_handle_t(int fd, int fd1, int fd2, int size, int flags, int w, |
Rebecca Schultz Zavin | 70212e5 | 2012-08-15 11:17:04 -0700 | [diff] [blame] | 134 | int h, int format, int stride, int vstride) : |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 135 | fd(fd), fd1(fd1), fd2(fd2), magic(sMagic), flags(flags), size(size), |
Rebecca Schultz Zavin | 70212e5 | 2012-08-15 11:17:04 -0700 | [diff] [blame] | 136 | offset(0), format(format), width(w), height(h), stride(stride), |
Alex Ray | d09ee48 | 2013-03-05 12:47:50 -0800 | [diff] [blame] | 137 | vstride(vstride), gamut(0), chroma(0), base(0), base1(0), base2(0), |
| 138 | handle(0), handle1(0), handle2(0) |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 139 | { |
| 140 | version = sizeof(native_handle); |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 141 | numInts = sNumInts; |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 142 | numFds = sNumFds; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 143 | } |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 144 | ~private_handle_t() { |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 145 | magic = 0; |
| 146 | } |
| 147 | |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 148 | static int validate(const native_handle* h) { |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 149 | const private_handle_t* hnd = (const private_handle_t*)h; |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 150 | if (!h || h->version != sizeof(native_handle) || |
Rebecca Schultz Zavin | ec68ab2 | 2012-08-27 10:58:52 -0700 | [diff] [blame] | 151 | hnd->numInts + hnd->numFds != sNumInts + sNumFds || |
| 152 | hnd->magic != sMagic) |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 153 | { |
| 154 | ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle *>(h))); |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 155 | return -EINVAL; |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 156 | } |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | static private_handle_t* dynamicCast(const native_handle* in) |
| 161 | { |
| 162 | if (validate(in) == 0) |
| 163 | return (private_handle_t*) in; |
| 164 | |
| 165 | return NULL; |
| 166 | } |
Rebecca Schultz Zavin | a8b0b07 | 2012-06-26 12:50:15 -0700 | [diff] [blame] | 167 | |
Dima Zavin | 6198e54 | 2012-02-29 17:02:46 -0800 | [diff] [blame] | 168 | #endif |
| 169 | }; |
| 170 | |
| 171 | #endif /* GRALLOC_PRIV_H_ */ |