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