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