blob: d0f945733ee7e084451f4a0d8ede7653ff568142 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Naseer Ahmed758bfc52012-11-28 17:02:08 -05002* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
Naseer Ahmed758bfc52012-11-28 17:02:08 -050013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#include <stdlib.h>
31#include <utils/Log.h>
32#include <linux/msm_mdp.h>
33#include <cutils/properties.h>
34#include "gralloc_priv.h"
35#include "fb_priv.h"
36#include "overlayUtils.h"
37#include "mdpWrapper.h"
Saurabh Shah94822ee2012-08-17 16:48:43 -070038#include "mdp_version.h"
Naseer Ahmed29a26812012-06-14 00:56:20 -070039
40// just a helper static thingy
41namespace {
42struct IOFile {
43 IOFile(const char* s, const char* mode) : fp(0) {
44 fp = ::fopen(s, mode);
45 if(!fp) {
46 ALOGE("Failed open %s", s);
47 }
48 }
49 template <class T>
50 size_t read(T& r, size_t elem) {
51 if(fp) {
52 return ::fread(&r, sizeof(T), elem, fp);
53 }
54 return 0;
55 }
56 size_t write(const char* s, uint32_t val) {
57 if(fp) {
58 return ::fprintf(fp, s, val);
59 }
60 return 0;
61 }
62 bool valid() const { return fp != 0; }
63 ~IOFile() {
64 if(fp) ::fclose(fp);
65 fp=0;
66 }
67 FILE* fp;
68};
69}
70
71namespace overlay {
72
73//----------From class Res ------------------------------
Naseer Ahmedf48aef62012-07-20 09:05:53 -070074const char* const Res::fbPath = "/dev/graphics/fb%u";
Naseer Ahmed29a26812012-06-14 00:56:20 -070075const char* const Res::rotPath = "/dev/msm_rotator";
76const char* const Res::format3DFile =
77 "/sys/class/graphics/fb1/format_3d";
78const char* const Res::edid3dInfoFile =
79 "/sys/class/graphics/fb1/3d_present";
80const char* const Res::barrierFile =
81 "/sys/devices/platform/mipi_novatek.0/enable_3d_barrier";
82//--------------------------------------------------------
83
84
85
86namespace utils {
Ajay Dudanicb3da0a2012-09-07 13:37:49 -070087//------------------ defines -----------------------------
88#define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u"
89#define NUM_FB_DEVICES 3
90
Naseer Ahmed29a26812012-06-14 00:56:20 -070091//--------------------------------------------------------
92FrameBufferInfo::FrameBufferInfo() {
93 mFBWidth = 0;
94 mFBHeight = 0;
95 mBorderFillSupported = false;
96
97 OvFD mFd;
98
99 // Use open defined in overlayFD file to open fd for fb0
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100 if(!overlay::open(mFd, 0, Res::fbPath)) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101 ALOGE("FrameBufferInfo: failed to open fd");
102 return;
103 }
104
105 if (!mFd.valid()) {
106 ALOGE("FrameBufferInfo: FD not valid");
107 return;
108 }
109
110 fb_var_screeninfo vinfo;
111 if (!mdp_wrapper::getVScreenInfo(mFd.getFD(), vinfo)) {
112 ALOGE("FrameBufferInfo: failed getVScreenInfo on fb0");
113 mFd.close();
114 return;
115 }
116
Saurabh Shah94822ee2012-08-17 16:48:43 -0700117 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
118 if (mdpVersion < qdutils::MDSS_V5) {
119 mdp_overlay ov;
120 memset(&ov, 0, sizeof(ov));
121 ov.id = 1;
122 if (!mdp_wrapper::getOverlay(mFd.getFD(), ov)) {
123 ALOGE("FrameBufferInfo: failed getOverlay on fb0");
124 mFd.close();
125 return;
126 }
127 mBorderFillSupported = (ov.flags & MDP_BORDERFILL_SUPPORTED) ?
128 true : false;
129 } else {
130 // badger always support border fill
131 mBorderFillSupported = true;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700132 }
133
134 mFd.close();
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135 mFBWidth = vinfo.xres;
136 mFBHeight = vinfo.yres;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137}
138
139FrameBufferInfo* FrameBufferInfo::getInstance() {
140 if (!sFBInfoInstance) {
141 sFBInfoInstance = new FrameBufferInfo;
142 }
143 return sFBInfoInstance;
144}
145
146int FrameBufferInfo::getWidth() const {
147 return mFBWidth;
148}
149
150int FrameBufferInfo::getHeight() const {
151 return mFBHeight;
152}
153
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700154/* clears any VG pipes allocated to the fb devices */
155int initOverlay() {
Naseer Ahmedff5c5302012-12-03 16:00:13 -0500156 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
157 if (mdpVersion < qdutils::MDSS_V5) {
158 msmfb_mixer_info_req req;
159 mdp_mixer_info *minfo = NULL;
160 char name[64];
161 int fd = -1;
162 for(int i = 0; i < NUM_FB_DEVICES; i++) {
163 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
164 ALOGD("initoverlay:: opening the device:: %s", name);
165 fd = ::open(name, O_RDWR, 0);
166 if(fd < 0) {
167 ALOGE("cannot open framebuffer(%d)", i);
168 return -1;
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700169 }
Naseer Ahmedff5c5302012-12-03 16:00:13 -0500170 //Get the mixer configuration */
171 req.mixer_num = i;
172 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
173 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
174 close(fd);
175 return -1;
176 }
177 minfo = req.info;
178 for (int j = 0; j < req.cnt; j++) {
179 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
180 minfo->z_order);
181 // except the RGB base layer with z_order of -1, clear any
182 // other pipes connected to mixer.
183 if((minfo->z_order) != -1) {
184 int index = minfo->pndx;
185 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
186 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
187 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
188 close(fd);
189 return -1;
190 }
191 }
192 minfo++;
193 }
194 close(fd);
195 fd = -1;
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700196 }
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700197 }
198 return 0;
199}
200
Naseer Ahmed29a26812012-06-14 00:56:20 -0700201//--------------------------------------------------------
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700202//Refer to graphics.h, gralloc_priv.h, msm_mdp.h
Naseer Ahmed29a26812012-06-14 00:56:20 -0700203int getMdpFormat(int format) {
204 switch (format) {
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700205 //From graphics.h
Naseer Ahmed29a26812012-06-14 00:56:20 -0700206 case HAL_PIXEL_FORMAT_RGBA_8888 :
207 return MDP_RGBA_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700208 case HAL_PIXEL_FORMAT_RGBX_8888:
209 return MDP_RGBX_8888;
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700210 case HAL_PIXEL_FORMAT_RGB_888:
211 return MDP_RGB_888;
212 case HAL_PIXEL_FORMAT_RGB_565:
213 return MDP_RGB_565;
214 case HAL_PIXEL_FORMAT_BGRA_8888:
215 return MDP_BGRA_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 case HAL_PIXEL_FORMAT_YV12:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700217 return MDP_Y_CR_CB_GH2V2;
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700218 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
219 return MDP_Y_CBCR_H2V1;
220 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
221 return MDP_Y_CRCB_H2V2;
222
223 //From gralloc_priv.h
224 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
225 return MDP_Y_CBCR_H2V2_TILE;
226 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
227 return MDP_Y_CBCR_H2V2;
228 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
229 return MDP_Y_CRCB_H2V1;
230 case HAL_PIXEL_FORMAT_YCbCr_444_SP:
231 return MDP_Y_CBCR_H1V1;
232 case HAL_PIXEL_FORMAT_YCrCb_444_SP:
233 return MDP_Y_CRCB_H1V1;
234
Naseer Ahmed29a26812012-06-14 00:56:20 -0700235 default:
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700236 //Unsupported by MDP
237 //---graphics.h--------
238 //HAL_PIXEL_FORMAT_RGBA_5551
239 //HAL_PIXEL_FORMAT_RGBA_4444
240 //HAL_PIXEL_FORMAT_YCbCr_422_I
241 //---gralloc_priv.h-----
242 //HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01
243 //HAL_PIXEL_FORMAT_R_8 = 0x10D
244 //HAL_PIXEL_FORMAT_RG_88 = 0x10E
245 ALOGE("%s: Unsupported format = 0x%x", __func__, format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246 return -1;
247 }
248 // not reached
249 return -1;
250}
251
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252bool is3DTV() {
253 char is3DTV = '0';
254 IOFile fp(Res::edid3dInfoFile, "r");
255 (void)fp.read(is3DTV, 1);
256 ALOGI("3DTV EDID flag: %d", is3DTV);
257 return (is3DTV == '0') ? false : true;
258}
259
260bool isPanel3D() {
261 OvFD fd;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700262 if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263 ALOGE("isPanel3D Can't open framebuffer 0");
264 return false;
265 }
266 fb_fix_screeninfo finfo;
267 if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) {
268 ALOGE("isPanel3D read fb0 failed");
269 }
270 fd.close();
271 return (FB_TYPE_3D_PANEL == finfo.type) ? true : false;
272}
273
274bool usePanel3D() {
275 if(!isPanel3D())
276 return false;
277 char value[PROPERTY_VALUE_MAX];
278 property_get("persist.user.panel3D", value, "0");
279 int usePanel3D = atoi(value);
280 return usePanel3D ? true : false;
281}
282
283bool send3DInfoPacket (uint32_t format3D) {
284 IOFile fp(Res::format3DFile, "wb");
285 (void)fp.write("%d", format3D);
286 if(!fp.valid()) {
287 ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode");
288 return false;
289 }
290 return true;
291}
292
293bool enableBarrier (uint32_t orientation) {
294 IOFile fp(Res::barrierFile, "wb");
295 (void)fp.write("%d", orientation);
296 if(!fp.valid()) {
297 ALOGE("enableBarrier no sysfs entry for "
298 "enabling barriers on 3D panel");
299 return false;
300 }
301 return true;
302}
303
304uint32_t getS3DFormat(uint32_t fmt) {
305 // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add
306 // an explicit check for the format
307 if (fmt == HAL_PIXEL_FORMAT_YV12) {
308 return 0;
309 }
310 uint32_t fmt3D = format3D(fmt);
311 uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp
312 uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out
313 fmt3D = fIn3D | fOut3D;
314 if (!fIn3D) {
315 fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format
316 }
317 if (!fOut3D) {
318 switch (fIn3D) {
319 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
320 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
321 // For all side by side formats, set the output
322 // format as Side-by-Side i.e 0x1
323 fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D;
324 break;
325 default:
326 fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format
327 }
328 }
329 return fmt3D;
330}
331
Naseer Ahmed29a26812012-06-14 00:56:20 -0700332} // utils
333
334} // overlay