codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 ARM Limited. All rights reserved. |
| 3 | * |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 4 | * Portions of this code have been modified from the original. |
| 5 | * These modifications are: |
| 6 | * * includes |
| 7 | * * struct private_handle_t |
| 8 | * * usesPhysicallyContiguousMemory() |
| 9 | * * validate() |
| 10 | * * dynamicCast() |
| 11 | * |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 12 | * Copyright (C) 2008 The Android Open Source Project |
| 13 | * |
| 14 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 | * you may not use this file except in compliance with the License. |
| 16 | * You may obtain a copy of the License at |
| 17 | * |
| 18 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | * |
| 20 | * Unless required by applicable law or agreed to in writing, software |
| 21 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 | * See the License for the specific language governing permissions and |
| 24 | * limitations under the License. |
| 25 | */ |
| 26 | |
| 27 | #ifndef GRALLOC_PRIV_H_ |
| 28 | #define GRALLOC_PRIV_H_ |
| 29 | |
| 30 | #include <stdint.h> |
| 31 | #include <pthread.h> |
| 32 | #include <errno.h> |
| 33 | #include <linux/fb.h> |
| 34 | |
| 35 | #include <hardware/gralloc.h> |
| 36 | #include <cutils/native_handle.h> |
| 37 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 38 | /*#include <ump/ump.h>*/ |
| 39 | #include "ump.h" |
| 40 | |
| 41 | /* |
| 42 | * HWC_HWOVERLAY is flag for location of glReadPixels(). |
| 43 | * Enable this define if you want that glReadPixesl() is in HWComposer. |
| 44 | * If you disable this define, glReadPixesl() is called in threadloop(). |
| 45 | */ |
| 46 | #define HWC_HWOVERLAY 1 |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 47 | |
| 48 | #define GRALLOC_ARM_UMP_MODULE 1 |
| 49 | |
codeworkx | 23280fc | 2012-07-03 19:22:20 +0200 | [diff] [blame^] | 50 | enum { |
| 51 | /* SEC Private usage , for HWC to set HDMI S3D format */ |
| 52 | /* HDMI should display this buffer as S3D SBS LR/RL*/ |
| 53 | GRALLOC_USAGE_PRIVATE_SBS_LR = 0x00400000, |
| 54 | GRALLOC_USAGE_PRIVATE_SBS_RL = 0x00200000, |
| 55 | |
| 56 | /* HDMI should display this buffer as 3D TB LR/RL*/ |
| 57 | GRALLOC_USAGE_PRIVATE_TB_LR = 0x00100000, |
| 58 | GRALLOC_USAGE_PRIVATE_TB_RL = 0x00080000, |
| 59 | }; |
| 60 | |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 61 | struct private_handle_t; |
| 62 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 63 | struct private_module_t { |
| 64 | gralloc_module_t base; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 65 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 66 | private_handle_t* framebuffer; |
| 67 | uint32_t flags; |
| 68 | uint32_t numBuffers; |
| 69 | uint32_t bufferMask; |
| 70 | pthread_mutex_t lock; |
| 71 | buffer_handle_t currentBuffer; |
| 72 | int ion_client; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 73 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 74 | struct fb_var_screeninfo info; |
| 75 | struct fb_fix_screeninfo finfo; |
| 76 | float xdpi; |
| 77 | float ydpi; |
| 78 | float fps; |
| 79 | int enableVSync; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 80 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 81 | enum { |
| 82 | PRIV_USAGE_LOCKED_FOR_POST = 0x80000000 |
| 83 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 86 | #ifdef USE_PARTIAL_FLUSH |
| 87 | struct private_handle_rect { |
| 88 | int handle; |
| 89 | int stride; |
| 90 | int l; |
| 91 | int t; |
| 92 | int w; |
| 93 | int h; |
| 94 | int locked; |
| 95 | struct private_handle_rect *next; |
| 96 | }; |
| 97 | #endif |
| 98 | |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 99 | #ifdef __cplusplus |
| 100 | struct private_handle_t : public native_handle |
| 101 | { |
| 102 | #else |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 103 | struct private_handle_t { |
| 104 | struct native_handle nativeHandle; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 105 | #endif |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 106 | enum { |
| 107 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
| 108 | PRIV_FLAGS_USES_UMP = 0x00000002, |
| 109 | PRIV_FLAGS_USES_PMEM = 0x00000004, |
| 110 | PRIV_FLAGS_USES_IOCTL = 0x00000008, |
| 111 | PRIV_FLAGS_USES_HDMI = 0x00000010, |
| 112 | PRIV_FLAGS_USES_ION = 0x00000020, |
| 113 | PRIV_FLAGS_NONE_CACHED = 0x00000040, |
| 114 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 115 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 116 | enum { |
| 117 | LOCK_STATE_WRITE = 1<<31, |
| 118 | LOCK_STATE_MAPPED = 1<<30, |
| 119 | LOCK_STATE_READ_MASK = 0x3FFFFFFF |
| 120 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 121 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 122 | int fd; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 123 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 124 | int magic; |
| 125 | int flags; |
| 126 | int size; |
| 127 | int base; |
| 128 | int lockState; |
| 129 | int writeOwner; |
| 130 | int pid; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 131 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 132 | /* Following members are for UMP memory only */ |
| 133 | int ump_id; |
| 134 | int ump_mem_handle; |
| 135 | int offset; |
| 136 | int paddr; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 137 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 138 | int format; |
| 139 | int usage; |
| 140 | int width; |
| 141 | int height; |
| 142 | int bpp; |
| 143 | int stride; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 144 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 145 | /* Following members are for ION memory only */ |
| 146 | int ion_client; |
| 147 | |
| 148 | /* Following members ard for YUV information */ |
| 149 | unsigned int yaddr; |
| 150 | unsigned int uoffset; |
| 151 | unsigned int voffset; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 152 | |
| 153 | #ifdef __cplusplus |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 154 | static const int sNumInts = 21; |
| 155 | static const int sNumFds = 1; |
| 156 | static const int sMagic = 0x3141592; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 157 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 158 | private_handle_t(int flags, int size, int base, int lock_state, ump_secure_id secure_id, ump_handle handle,int fd_val, int offset_val, int paddr_val): |
| 159 | fd(fd_val), |
| 160 | magic(sMagic), |
| 161 | flags(flags), |
| 162 | size(size), |
| 163 | base(base), |
| 164 | lockState(lock_state), |
| 165 | writeOwner(0), |
| 166 | pid(getpid()), |
| 167 | ump_id((int)secure_id), |
| 168 | ump_mem_handle((int)handle), |
| 169 | offset(offset_val), |
| 170 | paddr(paddr_val), |
| 171 | format(0), |
| 172 | usage(0), |
| 173 | width(0), |
| 174 | height(0), |
| 175 | bpp(0), |
| 176 | stride(0), |
| 177 | ion_client(0), |
| 178 | yaddr(0), |
| 179 | uoffset(0), |
| 180 | voffset(0) |
| 181 | { |
| 182 | version = sizeof(native_handle); |
| 183 | numFds = sNumFds; |
| 184 | numInts = sNumInts; |
| 185 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 186 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 187 | private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset): |
| 188 | fd(fb_file), |
| 189 | magic(sMagic), |
| 190 | flags(flags), |
| 191 | size(size), |
| 192 | base(base), |
| 193 | lockState(lock_state), |
| 194 | writeOwner(0), |
| 195 | pid(getpid()), |
| 196 | ump_id((int)UMP_INVALID_SECURE_ID), |
| 197 | ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE), |
| 198 | offset(fb_offset), |
| 199 | paddr(0), |
| 200 | format(0), |
| 201 | usage(0), |
| 202 | width(0), |
| 203 | height(0), |
| 204 | bpp(0), |
| 205 | stride(0), |
| 206 | ion_client(0), |
| 207 | yaddr(0), |
| 208 | uoffset(0), |
| 209 | voffset(0) |
| 210 | { |
| 211 | version = sizeof(native_handle); |
| 212 | numFds = sNumFds; |
| 213 | numInts = sNumInts; |
| 214 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 215 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 216 | ~private_handle_t() |
| 217 | { |
| 218 | magic = 0; |
| 219 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 220 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 221 | bool usesPhysicallyContiguousMemory() |
| 222 | { |
| 223 | return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false; |
| 224 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 225 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 226 | static int validate(const native_handle* h) |
| 227 | { |
| 228 | const private_handle_t* hnd = (const private_handle_t*)h; |
| 229 | if (!h || h->version != sizeof(native_handle) || |
| 230 | h->numInts != sNumInts || |
| 231 | h->numFds != sNumFds || |
| 232 | hnd->magic != sMagic) |
| 233 | return -EINVAL; |
| 234 | return 0; |
| 235 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 236 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 237 | static private_handle_t* dynamicCast(const native_handle* in) |
| 238 | { |
| 239 | if (validate(in) == 0) |
| 240 | return (private_handle_t*) in; |
| 241 | return NULL; |
| 242 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 243 | #endif |
| 244 | }; |
| 245 | |
| 246 | #endif /* GRALLOC_PRIV_H_ */ |