blob: c3655a506f0c518abe0fb75365c4d7cd93e43aa9 [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>
Mathias Agopiana8a75162009-04-10 14:24:31 -070021#include <limits.h>
22#include <sys/cdefs.h>
23#include <hardware/gralloc.h>
24#include <pthread.h>
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070025#include <errno.h>
26#include <unistd.h>
Mathias Agopiana8a75162009-04-10 14:24:31 -070027
28#include <cutils/native_handle.h>
29
Mathias Agopiana8a75162009-04-10 14:24:31 -070030#include <linux/fb.h>
Mathias Agopiana8a75162009-04-10 14:24:31 -070031
32/*****************************************************************************/
33
Mathias Agopian689fa732009-06-24 16:54:44 -070034struct private_module_t;
Mathias Agopianbd80b382009-07-07 17:53:43 -070035struct private_handle_t;
Mathias Agopian689fa732009-06-24 16:54:44 -070036
Mathias Agopiana8a75162009-04-10 14:24:31 -070037struct 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 Agopian8c4ab1f2009-06-11 16:32:05 -070046 int pmem_master;
47 void* pmem_master_base;
48
Mathias Agopiana8a75162009-04-10 14:24:31 -070049 struct fb_var_screeninfo info;
50 struct fb_fix_screeninfo finfo;
51 float xdpi;
52 float ydpi;
53 float fps;
54
55 enum {
Mathias Agopian988b8bd2009-05-04 14:26:56 -070056 // flag to indicate we'll post this buffer
Mathias Agopiana8a75162009-04-10 14:24:31 -070057 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000
58 };
59};
60
61/*****************************************************************************/
62
Mathias Agopianfc054132009-08-18 17:35:44 -070063#ifdef __cplusplus
64struct private_handle_t : public native_handle {
65#else
66struct private_handle_t {
67 struct native_handle nativeHandle;
68#endif
69
Mathias Agopiana8a75162009-04-10 14:24:31 -070070 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
Mathias Agopian876b4e82009-08-18 17:22:51 -070081 // file-descriptors
Mathias Agopiana8a75162009-04-10 14:24:31 -070082 int fd;
Mathias Agopian876b4e82009-08-18 17:22:51 -070083 // ints
Mathias Agopiana8a75162009-04-10 14:24:31 -070084 int magic;
Mathias Agopiana8a75162009-04-10 14:24:31 -070085 int flags;
86 int size;
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070087 int offset;
Mathias Agopian876b4e82009-08-18 17:22:51 -070088
Mathias Agopian485e6982009-05-05 20:21:57 -070089 // FIXME: the attributes below should be out-of-line
90 int base;
91 int lockState;
92 int writeOwner;
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070093 int pid;
Mathias Agopiana8a75162009-04-10 14:24:31 -070094
Mathias Agopianfc054132009-08-18 17:35:44 -070095#ifdef __cplusplus
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070096 static const int sNumInts = 8;
Mathias Agopiana8a75162009-04-10 14:24:31 -070097 static const int sNumFds = 1;
98 static const int sMagic = 0x3141592;
99
100 private_handle_t(int fd, int size, int flags) :
Mathias Agopian72c85082009-06-10 16:06:28 -0700101 fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -0700102 base(0), lockState(0), writeOwner(0), pid(getpid())
Mathias Agopian485e6982009-05-05 20:21:57 -0700103 {
Mathias Agopiana8a75162009-04-10 14:24:31 -0700104 version = sizeof(native_handle);
105 numInts = sNumInts;
106 numFds = sNumFds;
107 }
Mathias Agopiana8a75162009-04-10 14:24:31 -0700108 ~private_handle_t() {
109 magic = 0;
110 }
111
112 bool usesPhysicallyContiguousMemory() {
113 return (flags & PRIV_FLAGS_USES_PMEM) != 0;
114 }
115
116 static int validate(const native_handle* h) {
Mathias Agopian876b4e82009-08-18 17:22:51 -0700117 const private_handle_t* hnd = (const private_handle_t*)h;
Mathias Agopiana8a75162009-04-10 14:24:31 -0700118 if (!h || h->version != sizeof(native_handle) ||
Mathias Agopian876b4e82009-08-18 17:22:51 -0700119 h->numInts != sNumInts || h->numFds != sNumFds ||
120 hnd->magic != sMagic)
121 {
122 LOGE("invalid gralloc handle (at %p)", h);
Mathias Agopiana8a75162009-04-10 14:24:31 -0700123 return -EINVAL;
124 }
Mathias Agopiana8a75162009-04-10 14:24:31 -0700125 return 0;
126 }
127
128 static private_handle_t* dynamicCast(const native_handle* in) {
129 if (validate(in) == 0) {
130 return (private_handle_t*) in;
131 }
132 return NULL;
133 }
Mathias Agopianfc054132009-08-18 17:35:44 -0700134#endif
Mathias Agopiana8a75162009-04-10 14:24:31 -0700135};
136
Mathias Agopiana8a75162009-04-10 14:24:31 -0700137#endif /* GRALLOC_PRIV_H_ */