blob: 677d1c1e67a88e8af57a888219dcb29203324674 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
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 FB_PRIV_H
19#define FB_PRIV_H
20#include <linux/fb.h>
21
22#define NUM_FRAMEBUFFERS_MIN 2
23//XXX: Enable triple framebuffers
24#define NUM_FRAMEBUFFERS_MAX 2
25
26#define NO_SURFACEFLINGER_SWAPINTERVAL
27#define COLOR_FORMAT(x) (x & 0xFFF) // Max range for colorFormats is 0 - FFF
28
29#ifdef __cplusplus
30template <class T>
31struct Node
32{
33 T data;
34 Node<T> *next;
35};
36
37template <class T>
38class Queue
39{
40 public:
41 Queue(): front(NULL), back(NULL), len(0) {dummy = new T;}
42 ~Queue()
43 {
44 clear();
45 delete dummy;
46 }
47 void push(const T& item) //add an item to the back of the queue
48 {
49 if(len != 0) { //if the queue is not empty
50 back->next = new Node<T>; //create a new node
51 back = back->next; //set the new node as the back node
52 back->data = item;
53 back->next = NULL;
54 } else {
55 back = new Node<T>;
56 back->data = item;
57 back->next = NULL;
58 front = back;
59 }
60 len++;
61 }
62 void pop() //remove the first item from the queue
63 {
64 if (isEmpty())
65 return; //if the queue is empty, no node to dequeue
66 T item = front->data;
67 Node<T> *tmp = front;
68 front = front->next;
69 delete tmp;
70 if(front == NULL) //if the queue is empty, update the back pointer
71 back = NULL;
72 len--;
73 return;
74 }
75 T& getHeadValue() const //return the value of the first item in the queue
76 { //without modification to the structure
77 if (isEmpty()) {
78 ALOGE("Error can't get head of empty queue");
79 return *dummy;
80 }
81 return front->data;
82 }
83
84 bool isEmpty() const //returns true if no elements are in the queue
85 {
86 return (front == NULL);
87 }
88
89 size_t size() const //returns the amount of elements in the queue
90 {
91 return len;
92 }
93
94 private:
95 Node<T> *front;
96 Node<T> *back;
97 size_t len;
98 void clear()
99 {
100 while (!isEmpty())
101 pop();
102 }
103 T *dummy;
104};
105#endif
106
107enum hdmi_mirroring_state {
108 HDMI_NO_MIRRORING,
109 HDMI_UI_MIRRORING,
110};
111
112struct private_handle_t;
113
114struct qbuf_t {
115 buffer_handle_t buf;
116 int idx;
117};
118
119enum buf_state {
120 SUB,
121 REF,
122 AVL
123};
124
125enum {
126 // flag to indicate we'll post this buffer
127 PRIV_USAGE_LOCKED_FOR_POST = 0x80000000,
128 PRIV_MIN_SWAP_INTERVAL = 0,
129 PRIV_MAX_SWAP_INTERVAL = 1,
130};
131
132
133struct avail_t {
134 pthread_mutex_t lock;
135 pthread_cond_t cond;
136 bool is_avail;
137 buf_state state;
138};
139
140struct private_module_t {
141 gralloc_module_t base;
142
143 struct private_handle_t* framebuffer;
144 uint32_t fbFormat;
145 uint32_t flags;
146 uint32_t numBuffers;
147 uint32_t bufferMask;
148 pthread_mutex_t lock;
149 buffer_handle_t currentBuffer;
150
151 struct fb_var_screeninfo info;
152 struct fb_fix_screeninfo finfo;
153 float xdpi;
154 float ydpi;
155 float fps;
156 uint32_t swapInterval;
157 Queue<struct qbuf_t> disp; // non-empty when buffer is ready for display
158 int currentIdx;
159 struct avail_t avail[NUM_FRAMEBUFFERS_MAX];
160 pthread_mutex_t qlock;
161 pthread_cond_t qpost;
162#if defined(__cplusplus) && defined(HDMI_DUAL_DISPLAY)
163 int orientation;
164 int videoOverlay; // VIDEO_OVERLAY - 2D or 3D
165 int secureVideoOverlay; // VideoOverlay is secure
166 uint32_t currentOffset;
167 int enableHDMIOutput; // holds the type of external display
168 bool trueMirrorSupport;
169 bool exitHDMIUILoop;
170 float actionsafeWidthRatio;
171 float actionsafeHeightRatio;
172 bool hdmiStateChanged;
173 hdmi_mirroring_state hdmiMirroringState;
174 pthread_mutex_t overlayLock;
175 pthread_cond_t overlayPost;
176#endif
177};
178
179
180
181#endif /* FB_PRIV_H */