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 | |
| 50 | struct private_handle_t; |
| 51 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 52 | struct private_module_t { |
| 53 | gralloc_module_t base; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 54 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 55 | private_handle_t* framebuffer; |
| 56 | uint32_t flags; |
| 57 | uint32_t numBuffers; |
| 58 | uint32_t bufferMask; |
| 59 | pthread_mutex_t lock; |
| 60 | buffer_handle_t currentBuffer; |
| 61 | int ion_client; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 62 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 63 | struct fb_var_screeninfo info; |
| 64 | struct fb_fix_screeninfo finfo; |
| 65 | float xdpi; |
| 66 | float ydpi; |
| 67 | float fps; |
| 68 | int enableVSync; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 69 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 70 | enum { |
| 71 | PRIV_USAGE_LOCKED_FOR_POST = 0x80000000 |
| 72 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 73 | }; |
| 74 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 75 | #ifdef USE_PARTIAL_FLUSH |
| 76 | struct private_handle_rect { |
| 77 | int handle; |
| 78 | int stride; |
| 79 | int l; |
| 80 | int t; |
| 81 | int w; |
| 82 | int h; |
| 83 | int locked; |
| 84 | struct private_handle_rect *next; |
| 85 | }; |
| 86 | #endif |
| 87 | |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 88 | #ifdef __cplusplus |
| 89 | struct private_handle_t : public native_handle |
| 90 | { |
| 91 | #else |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 92 | struct private_handle_t { |
| 93 | struct native_handle nativeHandle; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 94 | #endif |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 95 | enum { |
| 96 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
| 97 | PRIV_FLAGS_USES_UMP = 0x00000002, |
| 98 | PRIV_FLAGS_USES_PMEM = 0x00000004, |
| 99 | PRIV_FLAGS_USES_IOCTL = 0x00000008, |
| 100 | PRIV_FLAGS_USES_HDMI = 0x00000010, |
| 101 | PRIV_FLAGS_USES_ION = 0x00000020, |
| 102 | PRIV_FLAGS_NONE_CACHED = 0x00000040, |
| 103 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 104 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 105 | enum { |
| 106 | LOCK_STATE_WRITE = 1<<31, |
| 107 | LOCK_STATE_MAPPED = 1<<30, |
| 108 | LOCK_STATE_READ_MASK = 0x3FFFFFFF |
| 109 | }; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 110 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 111 | int fd; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 112 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 113 | int magic; |
| 114 | int flags; |
| 115 | int size; |
| 116 | int base; |
| 117 | int lockState; |
| 118 | int writeOwner; |
| 119 | int pid; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 120 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 121 | /* Following members are for UMP memory only */ |
| 122 | int ump_id; |
| 123 | int ump_mem_handle; |
| 124 | int offset; |
| 125 | int paddr; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 126 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 127 | int format; |
| 128 | int usage; |
| 129 | int width; |
| 130 | int height; |
| 131 | int bpp; |
| 132 | int stride; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 133 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 134 | /* Following members are for ION memory only */ |
| 135 | int ion_client; |
| 136 | |
| 137 | /* Following members ard for YUV information */ |
| 138 | unsigned int yaddr; |
| 139 | unsigned int uoffset; |
| 140 | unsigned int voffset; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 141 | |
| 142 | #ifdef __cplusplus |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 143 | static const int sNumInts = 21; |
| 144 | static const int sNumFds = 1; |
| 145 | static const int sMagic = 0x3141592; |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 146 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 147 | 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): |
| 148 | fd(fd_val), |
| 149 | magic(sMagic), |
| 150 | flags(flags), |
| 151 | size(size), |
| 152 | base(base), |
| 153 | lockState(lock_state), |
| 154 | writeOwner(0), |
| 155 | pid(getpid()), |
| 156 | ump_id((int)secure_id), |
| 157 | ump_mem_handle((int)handle), |
| 158 | offset(offset_val), |
| 159 | paddr(paddr_val), |
| 160 | format(0), |
| 161 | usage(0), |
| 162 | width(0), |
| 163 | height(0), |
| 164 | bpp(0), |
| 165 | stride(0), |
| 166 | ion_client(0), |
| 167 | yaddr(0), |
| 168 | uoffset(0), |
| 169 | voffset(0) |
| 170 | { |
| 171 | version = sizeof(native_handle); |
| 172 | numFds = sNumFds; |
| 173 | numInts = sNumInts; |
| 174 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 175 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 176 | private_handle_t(int flags, int size, int base, int lock_state, int fb_file, int fb_offset): |
| 177 | fd(fb_file), |
| 178 | magic(sMagic), |
| 179 | flags(flags), |
| 180 | size(size), |
| 181 | base(base), |
| 182 | lockState(lock_state), |
| 183 | writeOwner(0), |
| 184 | pid(getpid()), |
| 185 | ump_id((int)UMP_INVALID_SECURE_ID), |
| 186 | ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE), |
| 187 | offset(fb_offset), |
| 188 | paddr(0), |
| 189 | format(0), |
| 190 | usage(0), |
| 191 | width(0), |
| 192 | height(0), |
| 193 | bpp(0), |
| 194 | stride(0), |
| 195 | ion_client(0), |
| 196 | yaddr(0), |
| 197 | uoffset(0), |
| 198 | voffset(0) |
| 199 | { |
| 200 | version = sizeof(native_handle); |
| 201 | numFds = sNumFds; |
| 202 | numInts = sNumInts; |
| 203 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 204 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 205 | ~private_handle_t() |
| 206 | { |
| 207 | magic = 0; |
| 208 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 209 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 210 | bool usesPhysicallyContiguousMemory() |
| 211 | { |
| 212 | return (flags & PRIV_FLAGS_FRAMEBUFFER) ? true : false; |
| 213 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 214 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 215 | static int validate(const native_handle* h) |
| 216 | { |
| 217 | const private_handle_t* hnd = (const private_handle_t*)h; |
| 218 | if (!h || h->version != sizeof(native_handle) || |
| 219 | h->numInts != sNumInts || |
| 220 | h->numFds != sNumFds || |
| 221 | hnd->magic != sMagic) |
| 222 | return -EINVAL; |
| 223 | return 0; |
| 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 private_handle_t* dynamicCast(const native_handle* in) |
| 227 | { |
| 228 | if (validate(in) == 0) |
| 229 | return (private_handle_t*) in; |
| 230 | return NULL; |
| 231 | } |
codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 232 | #endif |
| 233 | }; |
| 234 | |
| 235 | #endif /* GRALLOC_PRIV_H_ */ |