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