Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Duy Truong | 73d36df | 2013-02-09 20:33:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 4 | * |
| 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> |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 34 | #include <utils/Singleton.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 35 | |
| 36 | /*****************************************************************************/ |
| 37 | |
| 38 | struct private_module_t; |
| 39 | struct private_handle_t; |
| 40 | |
| 41 | inline size_t roundUpToPageSize(size_t x) { |
| 42 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); |
| 43 | } |
| 44 | |
| 45 | inline size_t ALIGN(size_t x, size_t align) { |
| 46 | return (x + align-1) & ~(align-1); |
| 47 | } |
| 48 | |
| 49 | #define FALSE 0 |
| 50 | #define TRUE 1 |
| 51 | |
| 52 | int mapFrameBufferLocked(struct private_module_t* module); |
| 53 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); |
| 54 | size_t getBufferSizeAndDimensions(int width, int height, int format, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 55 | int& alignedw, int &alignedh); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 56 | |
| 57 | int decideBufferHandlingMechanism(int format, const char *compositionUsed, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | int hasBlitEngine, int *needConversion, |
| 59 | int *useBufferDirectly); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 60 | |
| 61 | // Allocate buffer from width, height, format into a private_handle_t |
| 62 | // It is the responsibility of the caller to free the buffer |
| 63 | int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage); |
| 64 | void free_buffer(private_handle_t *hnd); |
| 65 | |
| 66 | /*****************************************************************************/ |
| 67 | |
| 68 | class Locker { |
| 69 | pthread_mutex_t mutex; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 70 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 71 | class Autolock { |
| 72 | Locker& locker; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 73 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 74 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } |
| 75 | inline ~Autolock() { locker.unlock(); } |
| 76 | }; |
| 77 | inline Locker() { pthread_mutex_init(&mutex, 0); } |
| 78 | inline ~Locker() { pthread_mutex_destroy(&mutex); } |
| 79 | inline void lock() { pthread_mutex_lock(&mutex); } |
| 80 | inline void unlock() { pthread_mutex_unlock(&mutex); } |
| 81 | }; |
| 82 | |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 83 | |
| 84 | class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo> |
| 85 | { |
| 86 | public: |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 87 | AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 88 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 89 | ~AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 90 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 91 | /* |
| 92 | * Function to compute the adreno stride based on the width and format. |
| 93 | * |
| 94 | * @return stride. |
| 95 | */ |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 96 | int getStride(int width, int format); |
| 97 | |
| 98 | private: |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 99 | // Pointer to the padding library. |
| 100 | void *libadreno_utils; |
| 101 | |
| 102 | // link to the surface padding library. |
| 103 | int (*LINK_adreno_compute_padding) (int width, int bpp, |
| 104 | int surface_tile_height, |
| 105 | int screen_tile_height, |
| 106 | int padding_threshold); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 107 | }; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 108 | #endif /* GR_H_ */ |