1fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian/*
2fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * Copyright (C) 2008 The Android Open Source Project
3fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian *
4fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * you may not use this file except in compliance with the License.
6fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * You may obtain a copy of the License at
7fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian *
8fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian *
10fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * Unless required by applicable law or agreed to in writing, software
11fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * See the License for the specific language governing permissions and
14fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian * limitations under the License.
15fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian */
16fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
17fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#ifndef GR_H_
18fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#define GR_H_
19fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
20fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <stdint.h>
216caa78dc37e58b951d37ec51682acab713b344c3Elliott Hughes#include <sys/user.h>
22fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <limits.h>
23fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <sys/cdefs.h>
24fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <hardware/gralloc.h>
25fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <pthread.h>
26fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <errno.h>
27fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
28fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#include <cutils/native_handle.h>
29fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
30fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian/*****************************************************************************/
31fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
32fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianstruct private_module_t;
33fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianstruct private_handle_t;
34fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
35fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianinline size_t roundUpToPageSize(size_t x) {
36fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
37fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian}
38fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
39fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianint mapFrameBufferLocked(struct private_module_t* module);
40fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianint terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
41f96b2064d7753af7ab75f05eff9559f401e1a4adMathias Agopianint mapBuffer(gralloc_module_t const* module, private_handle_t* hnd);
42fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
43fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian/*****************************************************************************/
44fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
45fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianclass Locker {
46fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    pthread_mutex_t mutex;
47fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopianpublic:
48fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    class Autolock {
49fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian        Locker& locker;
50fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    public:
51fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian        inline Autolock(Locker& locker) : locker(locker) {  locker.lock(); }
52fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian        inline ~Autolock() { locker.unlock(); }
53fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    };
54fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    inline Locker()        { pthread_mutex_init(&mutex, 0); }
55fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    inline ~Locker()       { pthread_mutex_destroy(&mutex); }
56fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    inline void lock()     { pthread_mutex_lock(&mutex); }
57fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian    inline void unlock()   { pthread_mutex_unlock(&mutex); }
58fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian};
59fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian
60fc0541328190d60b3cf6beb72b630e115dc7a2beMathias Agopian#endif /* GR_H_ */
61