blob: 1c9c72b3f6fd58f751c8b172afeba7c002864d16 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
3*
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.
13* * Neither the name of Code Aurora Forum, Inc. nor the names of its
14* 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
154bool FrameBufferInfo::supportTrueMirroring() const {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700155 char value[PROPERTY_VALUE_MAX] = {0};
156 property_get("hw.trueMirrorSupported", value, "0");
157 int trueMirroringSupported = atoi(value);
158 return (trueMirroringSupported && mBorderFillSupported);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159}
160
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700161/* clears any VG pipes allocated to the fb devices */
162int initOverlay() {
163 msmfb_mixer_info_req req;
164 mdp_mixer_info *minfo = NULL;
165 char name[64];
166 int fd = -1;
167 for(int i = 0; i < NUM_FB_DEVICES; i++) {
168 snprintf(name, 64, FB_DEVICE_TEMPLATE, i);
169 ALOGD("initoverlay:: opening the device:: %s", name);
170 fd = ::open(name, O_RDWR, 0);
171 if(fd < 0) {
172 ALOGE("cannot open framebuffer(%d)", i);
173 return -1;
174 }
175 //Get the mixer configuration */
176 req.mixer_num = i;
177 if (ioctl(fd, MSMFB_MIXER_INFO, &req) == -1) {
178 ALOGE("ERROR: MSMFB_MIXER_INFO ioctl failed");
179 close(fd);
180 return -1;
181 }
182 minfo = req.info;
183 for (int j = 0; j < req.cnt; j++) {
184 ALOGD("ndx=%d num=%d z_order=%d", minfo->pndx, minfo->pnum,
185 minfo->z_order);
186 // except the RGB base layer with z_order of -1, clear any
187 // other pipes connected to mixer.
188 if((minfo->z_order) != -1) {
189 int index = minfo->pndx;
190 ALOGD("Unset overlay with index: %d at mixer %d", index, i);
191 if(ioctl(fd, MSMFB_OVERLAY_UNSET, &index) == -1) {
192 ALOGE("ERROR: MSMFB_OVERLAY_UNSET failed");
193 close(fd);
194 return -1;
195 }
196 }
197 minfo++;
198 }
199 close(fd);
200 fd = -1;
201 }
202 return 0;
203}
204
Naseer Ahmed29a26812012-06-14 00:56:20 -0700205//--------------------------------------------------------
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700206//Refer to graphics.h, gralloc_priv.h, msm_mdp.h
Naseer Ahmed29a26812012-06-14 00:56:20 -0700207int getMdpFormat(int format) {
208 switch (format) {
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700209 //From graphics.h
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 case HAL_PIXEL_FORMAT_RGBA_8888 :
211 return MDP_RGBA_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 case HAL_PIXEL_FORMAT_RGBX_8888:
213 return MDP_RGBX_8888;
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700214 case HAL_PIXEL_FORMAT_RGB_888:
215 return MDP_RGB_888;
216 case HAL_PIXEL_FORMAT_RGB_565:
217 return MDP_RGB_565;
218 case HAL_PIXEL_FORMAT_BGRA_8888:
219 return MDP_BGRA_8888;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220 case HAL_PIXEL_FORMAT_YV12:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700221 return MDP_Y_CR_CB_GH2V2;
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700222 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
223 return MDP_Y_CBCR_H2V1;
224 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
225 return MDP_Y_CRCB_H2V2;
226
227 //From gralloc_priv.h
228 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
229 return MDP_Y_CBCR_H2V2_TILE;
230 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
231 return MDP_Y_CBCR_H2V2;
232 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
233 return MDP_Y_CRCB_H2V1;
234 case HAL_PIXEL_FORMAT_YCbCr_444_SP:
235 return MDP_Y_CBCR_H1V1;
236 case HAL_PIXEL_FORMAT_YCrCb_444_SP:
237 return MDP_Y_CRCB_H1V1;
238
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 default:
Naseer Ahmedaf49e212012-07-31 19:13:41 -0700240 //Unsupported by MDP
241 //---graphics.h--------
242 //HAL_PIXEL_FORMAT_RGBA_5551
243 //HAL_PIXEL_FORMAT_RGBA_4444
244 //HAL_PIXEL_FORMAT_YCbCr_422_I
245 //---gralloc_priv.h-----
246 //HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO = 0x7FA30C01
247 //HAL_PIXEL_FORMAT_R_8 = 0x10D
248 //HAL_PIXEL_FORMAT_RG_88 = 0x10E
249 ALOGE("%s: Unsupported format = 0x%x", __func__, format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250 return -1;
251 }
252 // not reached
253 return -1;
254}
255
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700256//Set by client as HDMI/WFD
257void setExtType(const int& type) {
258 if(type != HDMI && type != WFD) {
259 ALOGE("%s: Unrecognized type %d", __func__, type);
260 return;
261 }
262 sExtType = type;
263}
264
265//Return External panel type set by client.
266int getExtType() {
267 return sExtType;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268}
269
270bool is3DTV() {
271 char is3DTV = '0';
272 IOFile fp(Res::edid3dInfoFile, "r");
273 (void)fp.read(is3DTV, 1);
274 ALOGI("3DTV EDID flag: %d", is3DTV);
275 return (is3DTV == '0') ? false : true;
276}
277
278bool isPanel3D() {
279 OvFD fd;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700280 if(!overlay::open(fd, 0 /*fb*/, Res::fbPath)){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700281 ALOGE("isPanel3D Can't open framebuffer 0");
282 return false;
283 }
284 fb_fix_screeninfo finfo;
285 if(!mdp_wrapper::getFScreenInfo(fd.getFD(), finfo)) {
286 ALOGE("isPanel3D read fb0 failed");
287 }
288 fd.close();
289 return (FB_TYPE_3D_PANEL == finfo.type) ? true : false;
290}
291
292bool usePanel3D() {
293 if(!isPanel3D())
294 return false;
295 char value[PROPERTY_VALUE_MAX];
296 property_get("persist.user.panel3D", value, "0");
297 int usePanel3D = atoi(value);
298 return usePanel3D ? true : false;
299}
300
301bool send3DInfoPacket (uint32_t format3D) {
302 IOFile fp(Res::format3DFile, "wb");
303 (void)fp.write("%d", format3D);
304 if(!fp.valid()) {
305 ALOGE("send3DInfoPacket: no sysfs entry for setting 3d mode");
306 return false;
307 }
308 return true;
309}
310
311bool enableBarrier (uint32_t orientation) {
312 IOFile fp(Res::barrierFile, "wb");
313 (void)fp.write("%d", orientation);
314 if(!fp.valid()) {
315 ALOGE("enableBarrier no sysfs entry for "
316 "enabling barriers on 3D panel");
317 return false;
318 }
319 return true;
320}
321
322uint32_t getS3DFormat(uint32_t fmt) {
323 // The S3D is part of the HAL_PIXEL_FORMAT_YV12 value. Add
324 // an explicit check for the format
325 if (fmt == HAL_PIXEL_FORMAT_YV12) {
326 return 0;
327 }
328 uint32_t fmt3D = format3D(fmt);
329 uint32_t fIn3D = format3DInput(fmt3D); // MSB 2 bytes - inp
330 uint32_t fOut3D = format3DOutput(fmt3D); // LSB 2 bytes - out
331 fmt3D = fIn3D | fOut3D;
332 if (!fIn3D) {
333 fmt3D |= fOut3D << SHIFT_TOT_3D; //Set the input format
334 }
335 if (!fOut3D) {
336 switch (fIn3D) {
337 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
338 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
339 // For all side by side formats, set the output
340 // format as Side-by-Side i.e 0x1
341 fmt3D |= HAL_3D_IN_SIDE_BY_SIDE_L_R >> SHIFT_TOT_3D;
342 break;
343 default:
344 fmt3D |= fIn3D >> SHIFT_TOT_3D; //Set the output format
345 }
346 }
347 return fmt3D;
348}
349
Naseer Ahmed29a26812012-06-14 00:56:20 -0700350} // utils
351
352} // overlay