blob: ce63d423a365a164819f6c0efd60136fbfe86215 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Duy Truong73d36df2013-02-09 20:33:23 -08003 * Copyright (c) 2011-2012, The Linux Foundation. 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>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070022#include <limits.h>
23#include <sys/cdefs.h>
24#include <hardware/gralloc.h>
25#include <pthread.h>
26#include <errno.h>
27
28#include <cutils/native_handle.h>
Naomi Luisa44100c2013-02-08 12:42:03 -080029#include <utils/Singleton.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070030
31/*****************************************************************************/
32
33struct private_module_t;
34struct private_handle_t;
35
36inline size_t roundUpToPageSize(size_t x) {
37 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
38}
39
40inline size_t ALIGN(size_t x, size_t align) {
41 return (x + align-1) & ~(align-1);
42}
43
44#define FALSE 0
45#define TRUE 1
46
47int mapFrameBufferLocked(struct private_module_t* module);
48int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
49size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -070050 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051
52int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 int hasBlitEngine, int *needConversion,
54 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055
56// Allocate buffer from width, height, format into a private_handle_t
57// It is the responsibility of the caller to free the buffer
58int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
59void free_buffer(private_handle_t *hnd);
Naseer Ahmed57b52452014-04-08 20:23:47 -040060int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070061
62/*****************************************************************************/
63
64class Locker {
65 pthread_mutex_t mutex;
Raj kamal9af062e2014-04-01 16:52:19 +053066 pthread_cond_t cond;
Naseer Ahmed29a26812012-06-14 00:56:20 -070067 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070068 class Autolock {
69 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070071 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
72 inline ~Autolock() { locker.unlock(); }
73 };
Raj kamal9af062e2014-04-01 16:52:19 +053074 inline Locker() {
75 pthread_mutex_init(&mutex, 0);
76 pthread_cond_init(&cond, 0);
77 }
78 inline ~Locker() {
79 pthread_mutex_destroy(&mutex);
80 pthread_cond_destroy(&cond);
81 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070082 inline void lock() { pthread_mutex_lock(&mutex); }
Raj kamal9af062e2014-04-01 16:52:19 +053083 inline void wait() { pthread_cond_wait(&cond, &mutex); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070084 inline void unlock() { pthread_mutex_unlock(&mutex); }
Raj kamal9af062e2014-04-01 16:52:19 +053085 inline void signal() { pthread_cond_signal(&cond); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070086};
87
Naomi Luisa44100c2013-02-08 12:42:03 -080088
89class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
90{
91 public:
Naomi Luis01f5c8e2013-02-11 12:46:24 -080092 AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -080093
Naomi Luis01f5c8e2013-02-11 12:46:24 -080094 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -080095
Naomi Luis01f5c8e2013-02-11 12:46:24 -080096 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -080097 * Function to compute the adreno aligned width and aligned height
98 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -080099 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800100 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800101 */
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800102 void getAlignedWidthAndHeight(int width, int height, int format,
103 int& alignedw, int &alignedh);
Naomi Luisa44100c2013-02-08 12:42:03 -0800104 private:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800105 // Pointer to the padding library.
106 void *libadreno_utils;
107
108 // link to the surface padding library.
109 int (*LINK_adreno_compute_padding) (int width, int bpp,
110 int surface_tile_height,
111 int screen_tile_height,
112 int padding_threshold);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800113 // link to the surface padding library.
114 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
115 int height,
116 int bpp,
117 int tile_mode,
118 int raster_mode,
119 int padding_threshold,
120 int *aligned_w,
121 int *aligned_h);
122
Naomi Luisa44100c2013-02-08 12:42:03 -0800123};
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700124#endif /* GR_H_ */