| 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> | 
|  | 21 | #include <asm/page.h> | 
|  | 22 | #include <limits.h> | 
|  | 23 | #include <sys/cdefs.h> | 
|  | 24 | #include <hardware/gralloc.h> | 
|  | 25 | #include <pthread.h> | 
|  | 26 |  | 
|  | 27 | #include <cutils/native_handle.h> | 
|  | 28 |  | 
|  | 29 | #if HAVE_ANDROID_OS | 
|  | 30 | #include <linux/fb.h> | 
|  | 31 | #endif | 
|  | 32 |  | 
|  | 33 | /*****************************************************************************/ | 
|  | 34 |  | 
|  | 35 | inline size_t roundUpToPageSize(size_t x) { | 
|  | 36 | return (x + (PAGESIZE-1)) & ~(PAGESIZE-1); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | int mapFrameBufferLocked(struct private_module_t* module); | 
|  | 40 |  | 
|  | 41 | /*****************************************************************************/ | 
|  | 42 |  | 
|  | 43 | struct private_handle_t; | 
|  | 44 |  | 
|  | 45 | struct private_module_t { | 
|  | 46 | gralloc_module_t base; | 
|  | 47 |  | 
|  | 48 | private_handle_t* framebuffer; | 
|  | 49 | uint32_t flags; | 
|  | 50 | uint32_t numBuffers; | 
|  | 51 | uint32_t bufferMask; | 
|  | 52 | pthread_mutex_t lock; | 
|  | 53 | buffer_handle_t currentBuffer; | 
|  | 54 | struct fb_var_screeninfo info; | 
|  | 55 | struct fb_fix_screeninfo finfo; | 
|  | 56 | float xdpi; | 
|  | 57 | float ydpi; | 
|  | 58 | float fps; | 
|  | 59 |  | 
|  | 60 | enum { | 
| Mathias Agopian | 988b8bd | 2009-05-04 14:26:56 -0700 | [diff] [blame] | 61 | // flag to indicate we'll post this buffer | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 62 | PRIV_USAGE_LOCKED_FOR_POST = 0x80000000 | 
|  | 63 | }; | 
|  | 64 | }; | 
|  | 65 |  | 
|  | 66 | /*****************************************************************************/ | 
|  | 67 |  | 
|  | 68 | struct private_handle_t : public native_handle | 
|  | 69 | { | 
|  | 70 | enum { | 
|  | 71 | PRIV_FLAGS_FRAMEBUFFER = 0x00000001, | 
| Mathias Agopian | 988b8bd | 2009-05-04 14:26:56 -0700 | [diff] [blame] | 72 | PRIV_FLAGS_USES_PMEM   = 0x00000002, | 
| Mathias Agopian | 5115665 | 2009-06-09 18:55:49 -0700 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
|  | 75 | enum { | 
|  | 76 | LOCK_STATE_WRITE     =   1<<31, | 
|  | 77 | LOCK_STATE_MAPPED    =   1<<30, | 
|  | 78 | LOCK_STATE_READ_MASK =   0x3FFFFFFF | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 79 | }; | 
|  | 80 |  | 
|  | 81 | int     fd; | 
|  | 82 | int     magic; | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 83 | int     flags; | 
|  | 84 | int     size; | 
| Mathias Agopian | 72c8508 | 2009-06-10 16:06:28 -0700 | [diff] [blame^] | 85 | int     offset; // used with copybit | 
| Mathias Agopian | 485e698 | 2009-05-05 20:21:57 -0700 | [diff] [blame] | 86 | // FIXME: the attributes below should be out-of-line | 
|  | 87 | int     base; | 
|  | 88 | int     lockState; | 
|  | 89 | int     writeOwner; | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 90 |  | 
| Mathias Agopian | 72c8508 | 2009-06-10 16:06:28 -0700 | [diff] [blame^] | 91 | static const int sNumInts = 7; | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 92 | static const int sNumFds = 1; | 
|  | 93 | static const int sMagic = 0x3141592; | 
|  | 94 |  | 
|  | 95 | private_handle_t(int fd, int size, int flags) : | 
| Mathias Agopian | 72c8508 | 2009-06-10 16:06:28 -0700 | [diff] [blame^] | 96 | fd(fd), magic(sMagic), flags(flags), size(size), offset(0), | 
|  | 97 | base(0), lockState(0), writeOwner(0) | 
| Mathias Agopian | 485e698 | 2009-05-05 20:21:57 -0700 | [diff] [blame] | 98 | { | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 99 | version = sizeof(native_handle); | 
|  | 100 | numInts = sNumInts; | 
|  | 101 | numFds = sNumFds; | 
|  | 102 | } | 
|  | 103 |  | 
|  | 104 | ~private_handle_t() { | 
|  | 105 | magic = 0; | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | bool usesPhysicallyContiguousMemory() { | 
|  | 109 | return (flags & PRIV_FLAGS_USES_PMEM) != 0; | 
|  | 110 | } | 
|  | 111 |  | 
|  | 112 | static int validate(const native_handle* h) { | 
|  | 113 | if (!h || h->version != sizeof(native_handle) || | 
|  | 114 | h->numInts!=sNumInts || h->numFds!=sNumFds) { | 
|  | 115 | return -EINVAL; | 
|  | 116 | } | 
|  | 117 | const private_handle_t* hnd = (const private_handle_t*)h; | 
|  | 118 | if (hnd->magic != sMagic) | 
|  | 119 | return -EINVAL; | 
|  | 120 | return 0; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | static private_handle_t* dynamicCast(const native_handle* in) { | 
|  | 124 | if (validate(in) == 0) { | 
|  | 125 | return (private_handle_t*) in; | 
|  | 126 | } | 
|  | 127 | return NULL; | 
|  | 128 | } | 
|  | 129 | }; | 
|  | 130 |  | 
| Mathias Agopian | a8a7516 | 2009-04-10 14:24:31 -0700 | [diff] [blame] | 131 | #endif /* GRALLOC_PRIV_H_ */ |