Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 1 | /* |
| 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 GR_H_ |
| 18 | #define GR_H_ |
| 19 | |
| 20 | #include <stdint.h> |
Elliott Hughes | 6caa78d | 2014-02-24 15:50:34 -0800 | [diff] [blame] | 21 | #include <sys/user.h> |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 22 | #include <limits.h> |
| 23 | #include <sys/cdefs.h> |
| 24 | #include <hardware/gralloc.h> |
| 25 | #include <pthread.h> |
| 26 | #include <errno.h> |
Juan Yescas | cf51f70 | 2023-08-18 16:04:03 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 28 | |
| 29 | #include <cutils/native_handle.h> |
| 30 | |
| 31 | /*****************************************************************************/ |
| 32 | |
| 33 | struct private_module_t; |
| 34 | struct private_handle_t; |
| 35 | |
Juan Yescas | cf51f70 | 2023-08-18 16:04:03 +0000 | [diff] [blame] | 36 | static const size_t kPageSize = getpagesize(); |
| 37 | |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 38 | inline size_t roundUpToPageSize(size_t x) { |
Juan Yescas | cf51f70 | 2023-08-18 16:04:03 +0000 | [diff] [blame] | 39 | return (x + (kPageSize-1)) & ~(kPageSize-1); |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Peter Collingbourne | f2ed293 | 2019-10-15 17:29:20 -0700 | [diff] [blame] | 42 | int mapFrameBufferLocked(struct private_module_t* module, int format); |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 43 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); |
Mathias Agopian | f96b206 | 2009-12-14 18:27:09 -0800 | [diff] [blame] | 44 | int mapBuffer(gralloc_module_t const* module, private_handle_t* hnd); |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 45 | |
| 46 | /*****************************************************************************/ |
| 47 | |
| 48 | class Locker { |
| 49 | pthread_mutex_t mutex; |
| 50 | public: |
| 51 | class Autolock { |
| 52 | Locker& locker; |
| 53 | public: |
Chih-Hung Hsieh | 928e679 | 2016-06-30 14:17:31 -0700 | [diff] [blame] | 54 | inline explicit Autolock(Locker& locker) : locker(locker) { locker.lock(); } |
Mathias Agopian | fc05413 | 2009-08-18 17:35:44 -0700 | [diff] [blame] | 55 | inline ~Autolock() { locker.unlock(); } |
| 56 | }; |
| 57 | inline Locker() { pthread_mutex_init(&mutex, 0); } |
| 58 | inline ~Locker() { pthread_mutex_destroy(&mutex); } |
| 59 | inline void lock() { pthread_mutex_lock(&mutex); } |
| 60 | inline void unlock() { pthread_mutex_unlock(&mutex); } |
| 61 | }; |
| 62 | |
| 63 | #endif /* GR_H_ */ |