blob: 4d5afdc9b26ccb08a5eba60fd54035a5cf7eeb2b [file] [log] [blame]
Mathias Agopiana8a75162009-04-10 14:24:31 -07001/*
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
35inline size_t roundUpToPageSize(size_t x) {
36 return (x + (PAGESIZE-1)) & ~(PAGESIZE-1);
37}
38
39int mapFrameBufferLocked(struct private_module_t* module);
40
41/*****************************************************************************/
42
43struct private_handle_t;
44
45struct 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 Agopian988b8bd2009-05-04 14:26:56 -070061 // flag to indicate we'll post this buffer
Mathias Agopiana8a75162009-04-10 14:24:31 -070062 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
63 };
64};
65
66/*****************************************************************************/
67
68struct private_handle_t : public native_handle
69{
70 enum {
71 PRIV_FLAGS_FRAMEBUFFER = 0x00000001,
Mathias Agopian988b8bd2009-05-04 14:26:56 -070072 PRIV_FLAGS_USES_PMEM = 0x00000002,
Mathias Agopian51156652009-06-09 18:55:49 -070073 };
74
75 enum {
76 LOCK_STATE_WRITE = 1<<31,
77 LOCK_STATE_MAPPED = 1<<30,
78 LOCK_STATE_READ_MASK = 0x3FFFFFFF
Mathias Agopiana8a75162009-04-10 14:24:31 -070079 };
80
81 int fd;
82 int magic;
Mathias Agopiana8a75162009-04-10 14:24:31 -070083 int flags;
84 int size;
Mathias Agopian72c85082009-06-10 16:06:28 -070085 int offset; // used with copybit
Mathias Agopian485e6982009-05-05 20:21:57 -070086 // FIXME: the attributes below should be out-of-line
87 int base;
88 int lockState;
89 int writeOwner;
Mathias Agopiana8a75162009-04-10 14:24:31 -070090
Mathias Agopian72c85082009-06-10 16:06:28 -070091 static const int sNumInts = 7;
Mathias Agopiana8a75162009-04-10 14:24:31 -070092 static const int sNumFds = 1;
93 static const int sMagic = 0x3141592;
94
95 private_handle_t(int fd, int size, int flags) :
Mathias Agopian72c85082009-06-10 16:06:28 -070096 fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
97 base(0), lockState(0), writeOwner(0)
Mathias Agopian485e6982009-05-05 20:21:57 -070098 {
Mathias Agopiana8a75162009-04-10 14:24:31 -070099 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 Agopiana8a75162009-04-10 14:24:31 -0700131#endif /* GRALLOC_PRIV_H_ */