blob: 5d7db26ae39a9bf01b7caf50460a4c30fb95b2e6 [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;
Mathias Agopiana8a75162009-04-10 14:24:31 -070054};
55
56/*****************************************************************************/
57
Mathias Agopianfc054132009-08-18 17:35:44 -070058#ifdef __cplusplus
59struct private_handle_t : public native_handle {
60#else
61struct private_handle_t {
62 struct native_handle nativeHandle;
63#endif
64
Mathias Agopiana8a75162009-04-10 14:24:31 -070065 enum {
Mathias Agopianf96b2062009-12-14 18:27:09 -080066 PRIV_FLAGS_FRAMEBUFFER = 0x00000001
Mathias Agopiana8a75162009-04-10 14:24:31 -070067 };
68
Mathias Agopian876b4e82009-08-18 17:22:51 -070069 // file-descriptors
Mathias Agopiana8a75162009-04-10 14:24:31 -070070 int fd;
Mathias Agopian876b4e82009-08-18 17:22:51 -070071 // ints
Mathias Agopiana8a75162009-04-10 14:24:31 -070072 int magic;
Mathias Agopiana8a75162009-04-10 14:24:31 -070073 int flags;
74 int size;
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070075 int offset;
Mathias Agopian876b4e82009-08-18 17:22:51 -070076
Mathias Agopian485e6982009-05-05 20:21:57 -070077 // FIXME: the attributes below should be out-of-line
78 int base;
Mathias Agopian8c4ab1f2009-06-11 16:32:05 -070079 int pid;
Mathias Agopiana8a75162009-04-10 14:24:31 -070080
Mathias Agopianfc054132009-08-18 17:35:44 -070081#ifdef __cplusplus
Mathias Agopianf96b2062009-12-14 18:27:09 -080082 static const int sNumInts = 6;
Mathias Agopiana8a75162009-04-10 14:24:31 -070083 static const int sNumFds = 1;
84 static const int sMagic = 0x3141592;
85
86 private_handle_t(int fd, int size, int flags) :
Mathias Agopian72c85082009-06-10 16:06:28 -070087 fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
Mathias Agopianf96b2062009-12-14 18:27:09 -080088 base(0), pid(getpid())
Mathias Agopian485e6982009-05-05 20:21:57 -070089 {
Mathias Agopiana8a75162009-04-10 14:24:31 -070090 version = sizeof(native_handle);
91 numInts = sNumInts;
92 numFds = sNumFds;
93 }
Mathias Agopiana8a75162009-04-10 14:24:31 -070094 ~private_handle_t() {
95 magic = 0;
96 }
97
98 bool usesPhysicallyContiguousMemory() {
Mathias Agopianf96b2062009-12-14 18:27:09 -080099 return false;
Mathias Agopiana8a75162009-04-10 14:24:31 -0700100 }
101
102 static int validate(const native_handle* h) {
Mathias Agopian876b4e82009-08-18 17:22:51 -0700103 const private_handle_t* hnd = (const private_handle_t*)h;
Mathias Agopiana8a75162009-04-10 14:24:31 -0700104 if (!h || h->version != sizeof(native_handle) ||
Mathias Agopian876b4e82009-08-18 17:22:51 -0700105 h->numInts != sNumInts || h->numFds != sNumFds ||
106 hnd->magic != sMagic)
107 {
108 LOGE("invalid gralloc handle (at %p)", h);
Mathias Agopiana8a75162009-04-10 14:24:31 -0700109 return -EINVAL;
110 }
Mathias Agopiana8a75162009-04-10 14:24:31 -0700111 return 0;
112 }
113
114 static private_handle_t* dynamicCast(const native_handle* in) {
115 if (validate(in) == 0) {
116 return (private_handle_t*) in;
117 }
118 return NULL;
119 }
Mathias Agopianfc054132009-08-18 17:35:44 -0700120#endif
Mathias Agopiana8a75162009-04-10 14:24:31 -0700121};
122
Mathias Agopiana8a75162009-04-10 14:24:31 -0700123#endif /* GRALLOC_PRIV_H_ */