blob: 2cd1007235a698161a79cf3573d58d0cb34a8dc0 [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
Jesse Hall0d8f81a2013-03-28 16:51:25 -070064
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
Jesse Hall0d8f81a2013-03-28 16:51:25 -070077 // FIXME: the attributes below should be out-of-line
Greg Hackmannf5811ba2014-03-03 13:10:15 -080078 uint64_t base __attribute__((aligned(8)));
Jesse Hall0d8f81a2013-03-28 16:51:25 -070079 int pid;
Mathias Agopiana8a75162009-04-10 14:24:31 -070080
Mathias Agopianfc054132009-08-18 17:35:44 -070081#ifdef __cplusplus
Ashok Bhatd2be74a2014-02-06 14:11:08 +000082 static inline int sNumInts() {
83 return (((sizeof(private_handle_t) - sizeof(native_handle_t))/sizeof(int)) - sNumFds);
84 }
Mathias Agopiana8a75162009-04-10 14:24:31 -070085 static const int sNumFds = 1;
86 static const int sMagic = 0x3141592;
87
88 private_handle_t(int fd, int size, int flags) :
Jesse Hall0d8f81a2013-03-28 16:51:25 -070089 fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
90 base(0), pid(getpid())
Mathias Agopian485e6982009-05-05 20:21:57 -070091 {
Mathias Agopiana8a75162009-04-10 14:24:31 -070092 version = sizeof(native_handle);
Ashok Bhatd2be74a2014-02-06 14:11:08 +000093 numInts = sNumInts();
Mathias Agopiana8a75162009-04-10 14:24:31 -070094 numFds = sNumFds;
95 }
Mathias Agopiana8a75162009-04-10 14:24:31 -070096 ~private_handle_t() {
97 magic = 0;
98 }
99
Mathias Agopiana8a75162009-04-10 14:24:31 -0700100 static int validate(const native_handle* h) {
Mathias Agopian876b4e82009-08-18 17:22:51 -0700101 const private_handle_t* hnd = (const private_handle_t*)h;
Mathias Agopiana8a75162009-04-10 14:24:31 -0700102 if (!h || h->version != sizeof(native_handle) ||
Ashok Bhatd2be74a2014-02-06 14:11:08 +0000103 h->numInts != sNumInts() || h->numFds != sNumFds ||
Jesse Hall0d8f81a2013-03-28 16:51:25 -0700104 hnd->magic != sMagic)
Mathias Agopian876b4e82009-08-18 17:22:51 -0700105 {
Steve Block60d056b2012-01-08 10:17:53 +0000106 ALOGE("invalid gralloc handle (at %p)", h);
Mathias Agopiana8a75162009-04-10 14:24:31 -0700107 return -EINVAL;
108 }
Mathias Agopiana8a75162009-04-10 14:24:31 -0700109 return 0;
110 }
Mathias Agopianfc054132009-08-18 17:35:44 -0700111#endif
Mathias Agopiana8a75162009-04-10 14:24:31 -0700112};
113
Mathias Agopiana8a75162009-04-10 14:24:31 -0700114#endif /* GRALLOC_PRIV_H_ */