blob: b330da9852fc497fdacff2c5ebd8ef1d4bb0ebed [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Naseer Ahmed29a26812012-06-14 00:56:20 -07003 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef GR_H_
19#define GR_H_
20
21#include <stdint.h>
22#ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define
23# include <asm/page.h>
24#else
25# include <sys/user.h>
26#endif
27#include <limits.h>
28#include <sys/cdefs.h>
29#include <hardware/gralloc.h>
30#include <pthread.h>
31#include <errno.h>
32
33#include <cutils/native_handle.h>
34
35/*****************************************************************************/
36
37struct private_module_t;
38struct private_handle_t;
39
40inline size_t roundUpToPageSize(size_t x) {
41 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
42}
43
44inline size_t ALIGN(size_t x, size_t align) {
45 return (x + align-1) & ~(align-1);
46}
47
48#define FALSE 0
49#define TRUE 1
50
51int mapFrameBufferLocked(struct private_module_t* module);
52int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
53size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -070054 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055
56int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 int hasBlitEngine, int *needConversion,
58 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070059
60// Allocate buffer from width, height, format into a private_handle_t
61// It is the responsibility of the caller to free the buffer
62int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
63void free_buffer(private_handle_t *hnd);
64
65/*****************************************************************************/
66
67class Locker {
68 pthread_mutex_t mutex;
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070070 class Autolock {
71 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070072 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070073 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
74 inline ~Autolock() { locker.unlock(); }
75 };
76 inline Locker() { pthread_mutex_init(&mutex, 0); }
77 inline ~Locker() { pthread_mutex_destroy(&mutex); }
78 inline void lock() { pthread_mutex_lock(&mutex); }
79 inline void unlock() { pthread_mutex_unlock(&mutex); }
80};
81
82#endif /* GR_H_ */