blob: b5430185fb84928143f8f12a81a6cf4ac59f8cd6 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -08002* Copyright (c) 2011-2013, 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.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * 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#ifndef OVERLAY_UTILS_H
31#define OVERLAY_UTILS_H
32
33#include <cutils/log.h> // ALOGE, etc
34#include <errno.h>
35#include <fcntl.h> // open, O_RDWR, etc
36#include <hardware/hardware.h>
37#include <hardware/gralloc.h> // buffer_handle_t
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038#include <linux/msm_mdp.h> // flags
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080039#include <linux/msm_rotator.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070048// Older platforms do not support Venus
49#ifndef VENUS_COLOR_FORMAT
Saurabh Shah5380a232013-04-10 17:13:11 -070050#define MDP_Y_CBCR_H2V2_VENUS MDP_IMGTYPE_LIMIT
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070051#endif
52
Naseer Ahmed29a26812012-06-14 00:56:20 -070053/*
54*
55* Collection of utilities functions/structs/enums etc...
56*
57* */
58
59// comment that out if you want to remove asserts
60// or put it as -D in Android.mk. your choice.
61#define OVERLAY_HAS_ASSERT
62
63#ifdef OVERLAY_HAS_ASSERT
64# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
65#else
66# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
67#endif // OVERLAY_HAS_ASSERT
68
69#define DEBUG_OVERLAY 0
70#define PROFILE_OVERLAY 0
71
Saurabh Shahcf053c62012-12-13 12:32:55 -080072#ifndef MDSS_MDP_RIGHT_MIXER
73#define MDSS_MDP_RIGHT_MIXER 0x100
74#endif
75
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080076#ifndef MDP_OV_PIPE_FORCE_DMA
77#define MDP_OV_PIPE_FORCE_DMA 0x4000
78#endif
79
Sushil Chauhan07a2c762013-03-06 15:36:49 -080080#define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u"
Sushil Chauhan07a2c762013-03-06 15:36:49 -080081
Naseer Ahmed29a26812012-06-14 00:56:20 -070082namespace overlay {
83
84// fwd
85class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070086class OvFD;
87
88/* helper function to open by using fbnum */
89bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
90 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070091
92namespace utils {
93struct Whf;
94struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
96inline uint32_t setBit(uint32_t x, uint32_t mask) {
97 return (x | mask);
98}
99
100inline uint32_t clrBit(uint32_t x, uint32_t mask) {
101 return (x & ~mask);
102}
103
104/* Utility class to help avoid copying instances by making the copy ctor
105* and assignment operator private
106*
107* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700108* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700109*/
110class NoCopy {
111protected:
112 NoCopy(){}
113 ~NoCopy() {}
114private:
115 NoCopy(const NoCopy&);
116 const NoCopy& operator=(const NoCopy&);
117};
118
Naseer Ahmed29a26812012-06-14 00:56:20 -0700119
120/* 3D related utils, defines etc...
121 * The compound format passed to the overlay is
122 * ABCCC where A is the input 3D format
123 * B is the output 3D format
124 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
125enum { SHIFT_OUT_3D = 12,
126 SHIFT_TOT_3D = 16 };
127enum { INPUT_3D_MASK = 0xFFFF0000,
128 OUTPUT_3D_MASK = 0x0000FFFF };
129enum { BARRIER_LAND = 1,
130 BARRIER_PORT = 2 };
131
132inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700133inline uint32_t format3DOutput(uint32_t x) {
134 return (x & 0xF000) >> SHIFT_OUT_3D; }
135inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136
137bool isHDMIConnected ();
138bool is3DTV();
139bool isPanel3D();
140bool usePanel3D();
141bool send3DInfoPacket (uint32_t fmt);
142bool enableBarrier (uint32_t orientation);
143uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800144bool isMdssRotator();
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700145void normalizeCrop(uint32_t& xy, uint32_t& wh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148bool getPositionS3D(const Whf& whf, Dim& out);
149
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700151bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
152
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155
156struct Dim {
157 Dim () : x(0), y(0),
158 w(0), h(0),
159 o(0) {}
160 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
161 x(_x), y(_y),
162 w(_w), h(_h) {}
163 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
164 x(_x), y(_y),
165 w(_w), h(_h),
166 o(_o) {}
167 bool check(uint32_t _w, uint32_t _h) const {
168 return (x+w <= _w && y+h <= _h);
169
170 }
171
172 bool operator==(const Dim& d) const {
173 return d.x == x && d.y == y &&
174 d.w == w && d.h == h &&
175 d.o == o;
176 }
177
178 bool operator!=(const Dim& d) const {
179 return !operator==(d);
180 }
181
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 void dump() const;
183 uint32_t x;
184 uint32_t y;
185 uint32_t w;
186 uint32_t h;
187 uint32_t o;
188};
189
190// TODO have Whfz
191
192struct Whf {
193 Whf() : w(0), h(0), format(0), size(0) {}
194 Whf(uint32_t wi, uint32_t he, uint32_t f) :
195 w(wi), h(he), format(f), size(0) {}
196 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
197 w(wi), h(he), format(f), size(s) {}
198 // FIXME not comparing size at the moment
199 bool operator==(const Whf& whf) const {
200 return whf.w == w && whf.h == h &&
201 whf.format == format;
202 }
203 bool operator!=(const Whf& whf) const {
204 return !operator==(whf);
205 }
206 void dump() const;
207 uint32_t w;
208 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 uint32_t format;
210 uint32_t size;
211};
212
213enum { MAX_PATH_LEN = 256 };
214
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215/**
216 * Rotator flags: not to be confused with orientation flags.
Saurabh Shahacf10202013-02-26 10:15:15 -0800217 * Usually, you want to open the rotator to make sure it is
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 * ready for business.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800220 enum eRotFlags {
221 ROT_FLAGS_NONE = 0,
222 //Use rotator for 0 rotation. It is used anyway for others.
223 ROT_0_ENABLED = 1 << 0,
224 //Enable rotator downscale optimization for hardware bugs not handled in
225 //driver. If downscale optimizatation is required,
226 //then rotator will be used even if its 0 rotation case.
227 ROT_DOWNSCALE_ENABLED = 1 << 1,
Saurabh Shahacf10202013-02-26 10:15:15 -0800228 ROT_PREROTATED = 1 << 2,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800229};
230
231enum eRotDownscale {
232 ROT_DS_NONE = 0,
233 ROT_DS_HALF = 1,
234 ROT_DS_FOURTH = 2,
235 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236};
237
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238/* The values for is_fg flag for control alpha and transp
239 * IS_FG_OFF means is_fg = 0
240 * IS_FG_SET means is_fg = 1
241 */
242enum eIsFg {
243 IS_FG_OFF = 0,
244 IS_FG_SET = 1
245};
246
247/*
248 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
249 * kernel/common/linux/msm_mdp.h
250 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
251 * */
252enum eMdpFlags {
253 OV_MDP_FLAGS_NONE = 0,
254 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800255 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700257 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
258 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
Saurabh Shah799a3972012-09-01 12:16:12 -0700259 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700260 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700261 OV_MDP_FLIP_H = MDP_FLIP_LR,
262 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800263 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Saurabh Shah5daeee52013-01-23 16:52:26 +0800264 OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN,
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800265 OV_MDSS_MDP_BWC_EN = MDP_BWC_EN,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266};
267
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800269 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 ZORDER_1,
271 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500272 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273 Z_SYSTEM_ALLOC = 0xFFFF
274};
275
276enum eMdpPipeType {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800277 OV_MDP_PIPE_RGB = 0,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500278 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800279 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500280 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700281};
282
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800283// Identify destination pipes
284// TODO Names useless, replace with int and change all interfaces
Naseer Ahmed29a26812012-06-14 00:56:20 -0700285enum eDest {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800286 OV_P0 = 0,
287 OV_P1,
288 OV_P2,
289 OV_P3,
290 OV_P4,
291 OV_P5,
292 OV_P6,
293 OV_P7,
294 OV_P8,
295 OV_P9,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500296 OV_INVALID,
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800297 OV_MAX = OV_INVALID,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500298};
299
300/* Used when a buffer is split over 2 pipes and sent to display */
301enum {
302 OV_LEFT_SPLIT = 0,
303 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304};
305
306/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
307enum eTransform {
308 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700309 OVERLAY_TRANSFORM_0 = 0x0,
310 /* flip source image horizontally 0x1 */
311 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
312 /* flip source image vertically 0x2 */
313 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700314 /* rotate source image 180 degrees
315 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700316 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
317 /* rotate source image 90 degrees 0x4 */
318 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
319 /* rotate source image 90 degrees and flip horizontally 0x5 */
320 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
321 HAL_TRANSFORM_FLIP_H,
322 /* rotate source image 90 degrees and flip vertically 0x6 */
323 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
324 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325 /* rotate source image 270 degrees
326 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700327 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700328 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700329 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330};
331
332// Used to consolidate pipe params
333struct PipeArgs {
334 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700335 zorder(Z_SYSTEM_ALLOC),
336 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800337 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700338 }
339
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700340 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341 eZorder z, eIsFg fg, eRotFlags r) :
342 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 zorder(z),
345 isFg(fg),
346 rotFlags(r) {
347 }
348
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700349 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700350 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351 eZorder zorder; // stage number
352 eIsFg isFg; // control alpha & transp
353 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354};
355
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800356// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
357// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
358enum { HW_OV_MAGNIFICATION_LIMIT = 20,
359 HW_OV_MINIFICATION_LIMIT = 8
360};
361
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
363 f = static_cast<eMdpFlags>(setBit(f, v));
364}
365
366inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
367 f = static_cast<eMdpFlags>(clrBit(f, v));
368}
369
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370enum { FB0, FB1, FB2 };
371
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372struct ScreenInfo {
373 ScreenInfo() : mFBWidth(0),
374 mFBHeight(0),
375 mFBbpp(0),
376 mFBystride(0) {}
377 void dump(const char* const s) const;
378 uint32_t mFBWidth;
379 uint32_t mFBHeight;
380 uint32_t mFBbpp;
381 uint32_t mFBystride;
382};
383
384int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800385int getHALFormat(int mdpFormat);
Saurabh Shahacf10202013-02-26 10:15:15 -0800386int getDownscaleFactor(const int& src_w, const int& src_h,
387 const int& dst_w, const int& dst_h);
Saurabh Shah1a03d482013-05-29 13:44:20 -0700388void getDecimationFactor(const int& src_w, const int& src_h,
389 const int& dst_w, const int& dst_h, float& horDscale,
390 float& verDscale);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800391
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392/* flip is upside down and such. V, H flip
393 * rotation is 90, 180 etc
394 * It returns MDP related enum/define that match rot+flip*/
395int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700396const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700397
Naseer Ahmed29a26812012-06-14 00:56:20 -0700398template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700399inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400
401template <class T> inline void swap ( T& a, T& b )
402{
403 T c(a); a=b; b=c;
404}
405
406inline int alignup(int value, int a) {
407 //if align = 0, return the value. Else, do alignment.
408 return a ? ((((value - 1) / a) + 1) * a) : value;
409}
410
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800411inline int aligndown(int value, int a) {
412 //if align = 0, return the value. Else, do alignment.
413 return a ? ((value) & ~(a-1)) : value;
414}
415
Naseer Ahmed29a26812012-06-14 00:56:20 -0700416// FIXME that align should replace the upper one.
417inline int align(int value, int a) {
418 //if align = 0, return the value. Else, do alignment.
419 return a ? ((value + (a-1)) & ~(a-1)) : value;
420}
421
Naseer Ahmed29a26812012-06-14 00:56:20 -0700422enum eRotOutFmt {
423 ROT_OUT_FMT_DEFAULT,
424 ROT_OUT_FMT_Y_CRCB_H2V2
425};
426
427template <int ROT_OUT_FMT> struct RotOutFmt;
428
429// FIXME, taken from gralloc_priv.h. Need to
430// put it back as soon as overlay takes place of the old one
431/* possible formats for 3D content*/
432enum {
433 HAL_NO_3D = 0x0000,
434 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
435 HAL_3D_IN_TOP_BOTTOM = 0x20000,
436 HAL_3D_IN_INTERLEAVE = 0x40000,
437 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
438 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
439 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
440 HAL_3D_OUT_INTERLEAVE = 0x4000,
441 HAL_3D_OUT_MONOSCOPIC = 0x8000
442};
443
444enum { HAL_3D_OUT_SBS_MASK =
445 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
446 HAL_3D_OUT_TOP_BOT_MASK =
447 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
448 HAL_3D_OUT_INTERL_MASK =
449 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
450 HAL_3D_OUT_MONOS_MASK =
451 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
452};
453
454
455inline bool isYuv(uint32_t format) {
456 switch(format){
457 case MDP_Y_CBCR_H2V1:
458 case MDP_Y_CBCR_H2V2:
459 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700460 case MDP_Y_CRCB_H1V1:
461 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700462 case MDP_Y_CRCB_H2V2_TILE:
463 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700464 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700465 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700466 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700467 return true;
468 default:
469 return false;
470 }
471 return false;
472}
473
474inline bool isRgb(uint32_t format) {
475 switch(format) {
476 case MDP_RGBA_8888:
477 case MDP_BGRA_8888:
478 case MDP_RGBX_8888:
479 case MDP_RGB_565:
480 return true;
481 default:
482 return false;
483 }
484 return false;
485}
486
Saurabh Shah9c876d92012-08-25 19:29:53 -0700487inline const char* getFormatString(int format){
Saurabh Shah5380a232013-04-10 17:13:11 -0700488 #define STR(f) #f;
489 static const char* formats[MDP_IMGTYPE_LIMIT + 1] = {0};
490 formats[MDP_RGB_565] = STR(MDP_RGB_565);
491 formats[MDP_XRGB_8888] = STR(MDP_XRGB_8888);
492 formats[MDP_Y_CBCR_H2V2] = STR(MDP_Y_CBCR_H2V2);
493 formats[MDP_Y_CBCR_H2V2_ADRENO] = STR(MDP_Y_CBCR_H2V2_ADRENO);
494 formats[MDP_ARGB_8888] = STR(MDP_ARGB_8888);
495 formats[MDP_RGB_888] = STR(MDP_RGB_888);
496 formats[MDP_Y_CRCB_H2V2] = STR(MDP_Y_CRCB_H2V2);
497 formats[MDP_YCRYCB_H2V1] = STR(MDP_YCRYCB_H2V1);
498 formats[MDP_CBYCRY_H2V1] = STR(MDP_CBYCRY_H2V1);
499 formats[MDP_Y_CRCB_H2V1] = STR(MDP_Y_CRCB_H2V1);
500 formats[MDP_Y_CBCR_H2V1] = STR(MDP_Y_CBCR_H2V1);
501 formats[MDP_Y_CRCB_H1V2] = STR(MDP_Y_CRCB_H1V2);
502 formats[MDP_Y_CBCR_H1V2] = STR(MDP_Y_CBCR_H1V2);
503 formats[MDP_RGBA_8888] = STR(MDP_RGBA_8888);
504 formats[MDP_BGRA_8888] = STR(MDP_BGRA_8888);
505 formats[MDP_RGBX_8888] = STR(MDP_RGBX_8888);
506 formats[MDP_Y_CRCB_H2V2_TILE] = STR(MDP_Y_CRCB_H2V2_TILE);
507 formats[MDP_Y_CBCR_H2V2_TILE] = STR(MDP_Y_CBCR_H2V2_TILE);
508 formats[MDP_Y_CR_CB_H2V2] = STR(MDP_Y_CR_CB_H2V2);
509 formats[MDP_Y_CR_CB_GH2V2] = STR(MDP_Y_CR_CB_GH2V2);
510 formats[MDP_Y_CB_CR_H2V2] = STR(MDP_Y_CB_CR_H2V2);
511 formats[MDP_Y_CRCB_H1V1] = STR(MDP_Y_CRCB_H1V1);
512 formats[MDP_Y_CBCR_H1V1] = STR(MDP_Y_CBCR_H1V1);
513 formats[MDP_YCRCB_H1V1] = STR(MDP_YCRCB_H1V1);
514 formats[MDP_YCBCR_H1V1] = STR(MDP_YCBCR_H1V1);
515 formats[MDP_BGR_565] = STR(MDP_BGR_565);
516 formats[MDP_BGR_888] = STR(MDP_BGR_888);
517 formats[MDP_Y_CBCR_H2V2_VENUS] = STR(MDP_Y_CBCR_H2V2_VENUS);
518 formats[MDP_BGRX_8888] = STR(MDP_BGRX_8888);
519 formats[MDP_IMGTYPE_LIMIT] = STR(MDP_IMGTYPE_LIMIT);
520
521 if(format < 0 || format >= MDP_IMGTYPE_LIMIT) {
Saurabh Shah9c876d92012-08-25 19:29:53 -0700522 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
523 return "Unsupported format";
524 }
Saurabh Shah5380a232013-04-10 17:13:11 -0700525 if(formats[format] == 0) {
526 ALOGE("%s: table missing format %d from header", __FUNCTION__, format);
527 return "";
528 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700529 return formats[format];
530}
531
Naseer Ahmed29a26812012-06-14 00:56:20 -0700532inline void Whf::dump() const {
533 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
534 w, h, format, size);
535}
536
537inline void Dim::dump() const {
538 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
539}
540
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541// FB0
542template <int CHAN>
543inline Dim getPositionS3DImpl(const Whf& whf)
544{
545 switch (whf.format & OUTPUT_3D_MASK)
546 {
547 case HAL_3D_OUT_SBS_MASK:
548 // x, y, w, h
549 return Dim(0, 0, whf.w/2, whf.h);
550 case HAL_3D_OUT_TOP_BOT_MASK:
551 return Dim(0, 0, whf.w, whf.h/2);
552 case HAL_3D_OUT_MONOS_MASK:
553 return Dim();
554 case HAL_3D_OUT_INTERL_MASK:
555 // FIXME error?
556 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
557 return Dim();
558 default:
559 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
560 whf.format);
561 }
562 return Dim();
563}
564
565template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500566inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700567{
568 switch (whf.format & OUTPUT_3D_MASK)
569 {
570 case HAL_3D_OUT_SBS_MASK:
571 return Dim(whf.w/2, 0, whf.w/2, whf.h);
572 case HAL_3D_OUT_TOP_BOT_MASK:
573 return Dim(0, whf.h/2, whf.w, whf.h/2);
574 case HAL_3D_OUT_MONOS_MASK:
575 return Dim(0, 0, whf.w, whf.h);
576 case HAL_3D_OUT_INTERL_MASK:
577 // FIXME error?
578 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
579 return Dim();
580 default:
581 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
582 whf.format);
583 }
584 return Dim();
585}
586
587template <int CHAN>
588inline bool getPositionS3D(const Whf& whf, Dim& out) {
589 out = getPositionS3DImpl<CHAN>(whf);
590 return (out != Dim());
591}
592
593template <int CHAN>
594inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
595 switch (fmt & INPUT_3D_MASK)
596 {
597 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
598 return Dim(0, 0, in.w/2, in.h);
599 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
600 return Dim(in.w/2, 0, in.w/2, in.h);
601 case HAL_3D_IN_TOP_BOTTOM:
602 return Dim(0, 0, in.w, in.h/2);
603 case HAL_3D_IN_INTERLEAVE:
604 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
605 break;
606 default:
607 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
608 break;
609 }
610 return Dim();
611}
612
613template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500614inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700615 switch (fmt & INPUT_3D_MASK)
616 {
617 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
618 return Dim(in.w/2, 0, in.w/2, in.h);
619 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
620 return Dim(0, 0, in.w/2, in.h);
621 case HAL_3D_IN_TOP_BOTTOM:
622 return Dim(0, in.h/2, in.w, in.h/2);
623 case HAL_3D_IN_INTERLEAVE:
624 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
625 break;
626 default:
627 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
628 break;
629 }
630 return Dim();
631}
632
633template <int CHAN>
634inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
635{
636 out = getCropS3DImpl<CHAN>(in, fmt);
637 return (out != Dim());
638}
639
640template <class Type>
641void swapWidthHeight(Type& width, Type& height) {
642 Type tmp = width;
643 width = height;
644 height = tmp;
645}
646
647inline void ScreenInfo::dump(const char* const s) const {
648 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
649 " bpp=%d stride=%d start/end ==",
650 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
651}
652
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700653inline bool openDev(OvFD& fd, int fbnum,
654 const char* const devpath, int flags) {
655 return overlay::open(fd, fbnum, devpath, flags);
656}
657
Saurabh Shahb121e142012-08-20 17:59:13 -0700658template <class T>
659inline void even_ceil(T& value) {
660 if(value & 1)
661 value++;
662}
663
664template <class T>
665inline void even_floor(T& value) {
666 if(value & 1)
667 value--;
668}
669
Saurabh Shah76fd6552013-03-14 14:45:38 -0700670void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800671void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
672void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
673void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
674void getDump(char *buf, size_t len, const char *prefix,
675 const msmfb_overlay_data& ov);
676void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
677void getDump(char *buf, size_t len, const char *prefix,
678 const msm_rotator_img_info& ov);
679void getDump(char *buf, size_t len, const char *prefix,
680 const msm_rotator_data_info& ov);
681
Naseer Ahmed29a26812012-06-14 00:56:20 -0700682} // namespace utils ends
683
684//--------------------Class Res stuff (namespace overlay only) -----------
685
686class Res {
687public:
688 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700689 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700690 // /dev/msm_rotator
691 static const char* const rotPath;
692 // /sys/class/graphics/fb1/format_3d
693 static const char* const format3DFile;
694 // /sys/class/graphics/fb1/3d_present
695 static const char* const edid3dInfoFile;
696 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
697 static const char* const barrierFile;
698};
699
700
701//--------------------Class OvFD stuff (namespace overlay only) -----------
702
Naseer Ahmed29a26812012-06-14 00:56:20 -0700703/*
704* Holds one FD
705* Dtor will NOT close the underlying FD.
706* That enables us to copy that object around
707* */
708class OvFD {
709public:
710 /* Ctor */
711 explicit OvFD();
712
713 /* dtor will NOT close the underlying FD */
714 ~OvFD();
715
716 /* Open fd using the path given by dev.
717 * return false in failure */
718 bool open(const char* const dev,
719 int flags = O_RDWR);
720
721 /* populate path */
722 void setPath(const char* const dev);
723
724 /* Close fd if we have a valid fd. */
725 bool close();
726
727 /* returns underlying fd.*/
728 int getFD() const;
729
730 /* returns true if fd is valid */
731 bool valid() const;
732
733 /* like operator= */
734 void copy(int fd);
735
736 /* dump the state of the instance */
737 void dump() const;
738private:
739 /* helper enum for determine valid/invalid fd */
740 enum { INVAL = -1 };
741
742 /* actual os fd */
743 int mFD;
744
745 /* path, for debugging */
746 char mPath[utils::MAX_PATH_LEN];
747};
748
749//-------------------Inlines--------------------------
750
751inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
752{
753 char dev_name[64] = {0};
754 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
755 return fd.open(dev_name, flags);
756}
757
758inline OvFD::OvFD() : mFD (INVAL) {
759 mPath[0] = 0;
760}
761
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700762inline OvFD::~OvFD() {
763 //no op since copy() can be used to share fd, in 3d cases.
764}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700765
766inline bool OvFD::open(const char* const dev, int flags)
767{
768 mFD = ::open(dev, flags, 0);
769 if (mFD < 0) {
770 // FIXME errno, strerror in bionic?
771 ALOGE("Cant open device %s err=%d", dev, errno);
772 return false;
773 }
774 setPath(dev);
775 return true;
776}
777
778inline void OvFD::setPath(const char* const dev)
779{
780 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
781}
782
783inline bool OvFD::close()
784{
785 int ret = 0;
786 if(valid()) {
787 ret = ::close(mFD);
788 mFD = INVAL;
789 }
790 return (ret == 0);
791}
792
793inline bool OvFD::valid() const
794{
795 return (mFD != INVAL);
796}
797
798inline int OvFD::getFD() const { return mFD; }
799
800inline void OvFD::copy(int fd) {
801 mFD = fd;
802}
803
804inline void OvFD::dump() const
805{
806 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
807 mFD, mPath);
808}
809
810//--------------- class OvFD stuff ends ---------------------
811
812} // overlay
813
814
815#endif // OVERLAY_UTILS_H