Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 1 | /* |
| 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> |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 21 | #include <limits.h> |
| 22 | #include <sys/cdefs.h> |
| 23 | #include <hardware/gralloc.h> |
| 24 | #include <pthread.h> |
Mathias Agopian | 8c4ab1f | 2009-06-11 16:32:05 -0700 | [diff] [blame] | 25 | #include <errno.h> |
| 26 | #include <unistd.h> |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 27 | |
| 28 | #include <cutils/native_handle.h> |
| 29 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 30 | #include <linux/fb.h> |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 31 | |
| 32 | /*****************************************************************************/ |
| 33 | |
Mathias Agopian | 689fa73 | 2009-06-24 16:54:44 -0700 | [diff] [blame] | 34 | struct private_module_t; |
Mathias Agopian | bd80b38 | 2009-07-07 17:53:43 -0700 | [diff] [blame] | 35 | struct private_handle_t; |
Mathias Agopian | 689fa73 | 2009-06-24 16:54:44 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 37 | struct private_module_t { |
| 38 | gralloc_module_t base; |
| 39 | |
| 40 | private_handle_t* framebuffer; |
| 41 | uint32_t flags; |
| 42 | uint32_t numBuffers; |
| 43 | uint32_t bufferMask; |
| 44 | pthread_mutex_t lock; |
| 45 | buffer_handle_t currentBuffer; |
Mathias Agopian | 8c4ab1f | 2009-06-11 16:32:05 -0700 | [diff] [blame] | 46 | int pmem_master; |
| 47 | void* pmem_master_base; |
| 48 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 49 | struct fb_var_screeninfo info; |
| 50 | struct fb_fix_screeninfo finfo; |
| 51 | float xdpi; |
| 52 | float ydpi; |
| 53 | float fps; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /*****************************************************************************/ |
| 57 | |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | struct private_handle_t : public native_handle { |
| 60 | #else |
| 61 | struct private_handle_t { |
| 62 | struct native_handle nativeHandle; |
| 63 | #endif |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 64 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 65 | enum { |
Mathias Agopian | f96b206 | 2009-12-14 18:27:09 -0800 | [diff] [blame] | 66 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001 |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 69 | // file-descriptors |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 70 | int fd; |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 71 | // ints |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 72 | int magic; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 73 | int flags; |
| 74 | int size; |
Mathias Agopian | 8c4ab1f | 2009-06-11 16:32:05 -0700 | [diff] [blame] | 75 | int offset; |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 76 | |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 77 | // FIXME: the attributes below should be out-of-line |
Mathias Agopian | 485e698 | 2009-05-05 20:21:57 -0700 | [diff] [blame] | 78 | int base; |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 79 | int pid; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 80 | |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 81 | #ifdef __cplusplus |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 82 | static const int sNumInts = 6; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 83 | static const int sNumFds = 1; |
| 84 | static const int sMagic = 0x3141592; |
| 85 | |
| 86 | private_handle_t(int fd, int size, int flags) : |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 87 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), |
| 88 | base(0), pid(getpid()) |
Mathias Agopian | 485e698 | 2009-05-05 20:21:57 -0700 | [diff] [blame] | 89 | { |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 90 | version = sizeof(native_handle); |
| 91 | numInts = sNumInts; |
| 92 | numFds = sNumFds; |
| 93 | } |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 94 | ~private_handle_t() { |
| 95 | magic = 0; |
| 96 | } |
| 97 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 98 | static int validate(const native_handle* h) { |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 99 | const private_handle_t* hnd = (const private_handle_t*)h; |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 100 | if (!h || h->version != sizeof(native_handle) || |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 101 | h->numInts != sNumInts || h->numFds != sNumFds || |
Jesse Hall | 0d8f81a | 2013-03-28 16:51:25 -0700 | [diff] [blame^] | 102 | hnd->magic != sMagic) |
Mathias Agopian | 876b4e8 | 2009-08-18 17:22:51 -0700 | [diff] [blame] | 103 | { |
Steve Block | 60d056b | 2012-01-08 10:17:53 +0000 | [diff] [blame] | 104 | ALOGE("invalid gralloc handle (at %p)", h); |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 105 | return -EINVAL; |
| 106 | } |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 107 | return 0; |
| 108 | } |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 109 | #endif |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 110 | }; |
| 111 | |
Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 112 | #endif /* GRALLOC_PRIV_H_ */ |