blob: 76d930b408753d7bf15fc3f51cc9ec19639a2a03 [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
Naseer Ahmed29a26812012-06-14 00:56:20 -070039#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -080047// Older platforms do not support Venus.
48#ifndef VENUS_COLOR_FORMAT
Sushil Chauhanc5e61482012-08-22 17:13:32 -070049#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
50#endif
51
Naseer Ahmed29a26812012-06-14 00:56:20 -070052/*
53*
54* Collection of utilities functions/structs/enums etc...
55*
56* */
57
58// comment that out if you want to remove asserts
59// or put it as -D in Android.mk. your choice.
60#define OVERLAY_HAS_ASSERT
61
62#ifdef OVERLAY_HAS_ASSERT
63# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
64#else
65# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
66#endif // OVERLAY_HAS_ASSERT
67
68#define DEBUG_OVERLAY 0
69#define PROFILE_OVERLAY 0
70
Saurabh Shahcf053c62012-12-13 12:32:55 -080071#ifndef MDSS_MDP_RIGHT_MIXER
72#define MDSS_MDP_RIGHT_MIXER 0x100
73#endif
74
Naseer Ahmed29a26812012-06-14 00:56:20 -070075namespace overlay {
76
77// fwd
78class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070079class OvFD;
80
81/* helper function to open by using fbnum */
82bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
83 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084
85namespace utils {
86struct Whf;
87struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088
89inline uint32_t setBit(uint32_t x, uint32_t mask) {
90 return (x | mask);
91}
92
93inline uint32_t clrBit(uint32_t x, uint32_t mask) {
94 return (x & ~mask);
95}
96
97/* Utility class to help avoid copying instances by making the copy ctor
98* and assignment operator private
99*
100* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102*/
103class NoCopy {
104protected:
105 NoCopy(){}
106 ~NoCopy() {}
107private:
108 NoCopy(const NoCopy&);
109 const NoCopy& operator=(const NoCopy&);
110};
111
112/*
113* Utility class to query the framebuffer info for primary display
114*
115* Usage:
116* Outside of functions:
117* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
118* Inside functions:
119* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
120*/
121class FrameBufferInfo {
122
123public:
124 /* ctor init */
125 explicit FrameBufferInfo();
126
127 /* Gets an instance if one does not already exist */
128 static FrameBufferInfo* getInstance();
129
130 /* Gets width of primary framebuffer */
131 int getWidth() const;
132
133 /* Gets height of primary framebuffer */
134 int getHeight() const;
135
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136private:
137 int mFBWidth;
138 int mFBHeight;
139 bool mBorderFillSupported;
140 static FrameBufferInfo *sFBInfoInstance;
141};
142
143/* 3D related utils, defines etc...
144 * The compound format passed to the overlay is
145 * ABCCC where A is the input 3D format
146 * B is the output 3D format
147 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
148enum { SHIFT_OUT_3D = 12,
149 SHIFT_TOT_3D = 16 };
150enum { INPUT_3D_MASK = 0xFFFF0000,
151 OUTPUT_3D_MASK = 0x0000FFFF };
152enum { BARRIER_LAND = 1,
153 BARRIER_PORT = 2 };
154
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700155/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
156 * close all the pipes if it is opened after reboot.
157 */
158int initOverlay(void);
159
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161inline uint32_t colorFormat(uint32_t fmt) {
162 /*TODO enable this block only if format has interlace / 3D info in top bits.
163 if(fmt & INTERLACE_MASK) {
164 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
165 }
166 fmt = fmt & 0xFFF;*/
167 return fmt;
168}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169inline uint32_t format3DOutput(uint32_t x) {
170 return (x & 0xF000) >> SHIFT_OUT_3D; }
171inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
172uint32_t getColorFormat(uint32_t format);
173
174bool isHDMIConnected ();
175bool is3DTV();
176bool isPanel3D();
177bool usePanel3D();
178bool send3DInfoPacket (uint32_t fmt);
179bool enableBarrier (uint32_t orientation);
180uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800181bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184bool getPositionS3D(const Whf& whf, Dim& out);
185
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
188
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191
192struct Dim {
193 Dim () : x(0), y(0),
194 w(0), h(0),
195 o(0) {}
196 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
197 x(_x), y(_y),
198 w(_w), h(_h) {}
199 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
200 x(_x), y(_y),
201 w(_w), h(_h),
202 o(_o) {}
203 bool check(uint32_t _w, uint32_t _h) const {
204 return (x+w <= _w && y+h <= _h);
205
206 }
207
208 bool operator==(const Dim& d) const {
209 return d.x == x && d.y == y &&
210 d.w == w && d.h == h &&
211 d.o == o;
212 }
213
214 bool operator!=(const Dim& d) const {
215 return !operator==(d);
216 }
217
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 void dump() const;
219 uint32_t x;
220 uint32_t y;
221 uint32_t w;
222 uint32_t h;
223 uint32_t o;
224};
225
226// TODO have Whfz
227
228struct Whf {
229 Whf() : w(0), h(0), format(0), size(0) {}
230 Whf(uint32_t wi, uint32_t he, uint32_t f) :
231 w(wi), h(he), format(f), size(0) {}
232 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
233 w(wi), h(he), format(f), size(s) {}
234 // FIXME not comparing size at the moment
235 bool operator==(const Whf& whf) const {
236 return whf.w == w && whf.h == h &&
237 whf.format == format;
238 }
239 bool operator!=(const Whf& whf) const {
240 return !operator==(whf);
241 }
242 void dump() const;
243 uint32_t w;
244 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245 uint32_t format;
246 uint32_t size;
247};
248
Saurabh Shah56f610d2012-08-07 15:27:06 -0700249class ActionSafe {
250private:
251 ActionSafe() : mWidth(0.0f), mHeight(0.0f) { };
252 float mWidth;
253 float mHeight;
254 static ActionSafe *sActionSafe;
255public:
256 ~ActionSafe() { };
257 static ActionSafe* getInstance() {
258 if(!sActionSafe) {
259 sActionSafe = new ActionSafe();
260 }
261 return sActionSafe;
262 }
263 void setDimension(int w, int h) {
264 mWidth = (float)w;
265 mHeight = (float)h;
266 }
267 float getWidth() { return mWidth; }
268 float getHeight() { return mHeight; }
269};
270
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271enum { MAX_PATH_LEN = 256 };
272
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273/**
274 * Rotator flags: not to be confused with orientation flags.
275 * Ususally, you want to open the rotator to make sure it is
276 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500277 * ROT_FLAG_DISABLED: Rotator not used unless required.
278 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800280 enum eRotFlags {
281 ROT_FLAGS_NONE = 0,
282 //Use rotator for 0 rotation. It is used anyway for others.
283 ROT_0_ENABLED = 1 << 0,
284 //Enable rotator downscale optimization for hardware bugs not handled in
285 //driver. If downscale optimizatation is required,
286 //then rotator will be used even if its 0 rotation case.
287 ROT_DOWNSCALE_ENABLED = 1 << 1,
288};
289
290enum eRotDownscale {
291 ROT_DS_NONE = 0,
292 ROT_DS_HALF = 1,
293 ROT_DS_FOURTH = 2,
294 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700295};
296
Naseer Ahmed29a26812012-06-14 00:56:20 -0700297/* The values for is_fg flag for control alpha and transp
298 * IS_FG_OFF means is_fg = 0
299 * IS_FG_SET means is_fg = 1
300 */
301enum eIsFg {
302 IS_FG_OFF = 0,
303 IS_FG_SET = 1
304};
305
306/*
307 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
308 * kernel/common/linux/msm_mdp.h
309 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
310 * */
311enum eMdpFlags {
312 OV_MDP_FLAGS_NONE = 0,
313 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
314 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700315 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
316 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
317 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700318 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700319 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700320 OV_MDP_FLIP_H = MDP_FLIP_LR,
321 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800322 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323};
324
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325enum eZorder {
326 ZORDER_0,
327 ZORDER_1,
328 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500329 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330 Z_SYSTEM_ALLOC = 0xFFFF
331};
332
333enum eMdpPipeType {
334 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500335 OV_MDP_PIPE_VG,
336 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700337};
338
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500339/* Used to identify destination pipes
340 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500342 OV_VG0 = 0,
343 OV_RGB0,
344 OV_VG1,
345 OV_RGB1,
346 OV_VG2,
347 OV_RGB2,
348 OV_INVALID,
349};
350
351/* Used when a buffer is split over 2 pipes and sent to display */
352enum {
353 OV_LEFT_SPLIT = 0,
354 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355};
356
357/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
358enum eTransform {
359 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700360 OVERLAY_TRANSFORM_0 = 0x0,
361 /* flip source image horizontally 0x1 */
362 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
363 /* flip source image vertically 0x2 */
364 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 /* rotate source image 180 degrees
366 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700367 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
368 /* rotate source image 90 degrees 0x4 */
369 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
370 /* rotate source image 90 degrees and flip horizontally 0x5 */
371 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
372 HAL_TRANSFORM_FLIP_H,
373 /* rotate source image 90 degrees and flip vertically 0x6 */
374 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
375 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376 /* rotate source image 270 degrees
377 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700379 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700380 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381};
382
383// Used to consolidate pipe params
384struct PipeArgs {
385 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386 zorder(Z_SYSTEM_ALLOC),
387 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800388 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389 }
390
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700391 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392 eZorder z, eIsFg fg, eRotFlags r) :
393 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700394 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700395 zorder(z),
396 isFg(fg),
397 rotFlags(r) {
398 }
399
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700400 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700401 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700402 eZorder zorder; // stage number
403 eIsFg isFg; // control alpha & transp
404 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700405};
406
Naseer Ahmed29a26812012-06-14 00:56:20 -0700407inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
408 f = static_cast<eMdpFlags>(setBit(f, v));
409}
410
411inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
412 f = static_cast<eMdpFlags>(clrBit(f, v));
413}
414
415// fb 0/1/2
416enum { FB0, FB1, FB2 };
417
418//Panels could be categorized as primary and external
419enum { PRIMARY, EXTERNAL };
420
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421// 2 for rgb0/1 double bufs
422enum { RGB_PIPE_NUM_BUFS = 2 };
423
424struct ScreenInfo {
425 ScreenInfo() : mFBWidth(0),
426 mFBHeight(0),
427 mFBbpp(0),
428 mFBystride(0) {}
429 void dump(const char* const s) const;
430 uint32_t mFBWidth;
431 uint32_t mFBHeight;
432 uint32_t mFBbpp;
433 uint32_t mFBystride;
434};
435
436int getMdpFormat(int format);
437int getRotOutFmt(uint32_t format);
438/* flip is upside down and such. V, H flip
439 * rotation is 90, 180 etc
440 * It returns MDP related enum/define that match rot+flip*/
441int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700442const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700443
Naseer Ahmed29a26812012-06-14 00:56:20 -0700444// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
445// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
446enum { HW_OV_MAGNIFICATION_LIMIT = 20,
447 HW_OV_MINIFICATION_LIMIT = 8
448};
449
Naseer Ahmed29a26812012-06-14 00:56:20 -0700450template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700451inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700452
453template <class T> inline void swap ( T& a, T& b )
454{
455 T c(a); a=b; b=c;
456}
457
458inline int alignup(int value, int a) {
459 //if align = 0, return the value. Else, do alignment.
460 return a ? ((((value - 1) / a) + 1) * a) : value;
461}
462
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800463inline int aligndown(int value, int a) {
464 //if align = 0, return the value. Else, do alignment.
465 return a ? ((value) & ~(a-1)) : value;
466}
467
Naseer Ahmed29a26812012-06-14 00:56:20 -0700468// FIXME that align should replace the upper one.
469inline int align(int value, int a) {
470 //if align = 0, return the value. Else, do alignment.
471 return a ? ((value + (a-1)) & ~(a-1)) : value;
472}
473
Naseer Ahmed29a26812012-06-14 00:56:20 -0700474enum eRotOutFmt {
475 ROT_OUT_FMT_DEFAULT,
476 ROT_OUT_FMT_Y_CRCB_H2V2
477};
478
479template <int ROT_OUT_FMT> struct RotOutFmt;
480
481// FIXME, taken from gralloc_priv.h. Need to
482// put it back as soon as overlay takes place of the old one
483/* possible formats for 3D content*/
484enum {
485 HAL_NO_3D = 0x0000,
486 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
487 HAL_3D_IN_TOP_BOTTOM = 0x20000,
488 HAL_3D_IN_INTERLEAVE = 0x40000,
489 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
490 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
491 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
492 HAL_3D_OUT_INTERLEAVE = 0x4000,
493 HAL_3D_OUT_MONOSCOPIC = 0x8000
494};
495
496enum { HAL_3D_OUT_SBS_MASK =
497 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
498 HAL_3D_OUT_TOP_BOT_MASK =
499 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
500 HAL_3D_OUT_INTERL_MASK =
501 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
502 HAL_3D_OUT_MONOS_MASK =
503 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
504};
505
506
507inline bool isYuv(uint32_t format) {
508 switch(format){
509 case MDP_Y_CBCR_H2V1:
510 case MDP_Y_CBCR_H2V2:
511 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700512 case MDP_Y_CRCB_H1V1:
513 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700514 case MDP_Y_CRCB_H2V2_TILE:
515 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700516 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700517 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700518 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700519 return true;
520 default:
521 return false;
522 }
523 return false;
524}
525
526inline bool isRgb(uint32_t format) {
527 switch(format) {
528 case MDP_RGBA_8888:
529 case MDP_BGRA_8888:
530 case MDP_RGBX_8888:
531 case MDP_RGB_565:
532 return true;
533 default:
534 return false;
535 }
536 return false;
537}
538
Saurabh Shah9c876d92012-08-25 19:29:53 -0700539inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700540 static const char* const formats[] = {
541 "MDP_RGB_565",
542 "MDP_XRGB_8888",
543 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700544 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545 "MDP_ARGB_8888",
546 "MDP_RGB_888",
547 "MDP_Y_CRCB_H2V2",
548 "MDP_YCRYCB_H2V1",
549 "MDP_Y_CRCB_H2V1",
550 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700551 "MDP_Y_CRCB_H1V2",
552 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700553 "MDP_RGBA_8888",
554 "MDP_BGRA_8888",
555 "MDP_RGBX_8888",
556 "MDP_Y_CRCB_H2V2_TILE",
557 "MDP_Y_CBCR_H2V2_TILE",
558 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700559 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700560 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700561 "MDP_Y_CRCB_H1V1",
562 "MDP_Y_CBCR_H1V1",
563 "MDP_YCRCB_H1V1",
564 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700565 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700566 "MDP_BGR_888",
567 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700568 "MDP_IMGTYPE_LIMIT",
569 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700570 "MDP_FB_FORMAT",
571 "MDP_IMGTYPE_LIMIT2"
572 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700573 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
574 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
575 return "Unsupported format";
576 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700577 return formats[format];
578}
579
Naseer Ahmed29a26812012-06-14 00:56:20 -0700580inline void Whf::dump() const {
581 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
582 w, h, format, size);
583}
584
585inline void Dim::dump() const {
586 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
587}
588
589inline int getMdpOrient(eTransform rotation) {
590 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700591 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700592 {
593 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700594 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
595 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
596 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700597 //getMdpOrient will switch the flips if the source is 90 rotated.
598 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700599 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700600 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700601 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
602 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700603 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
604 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700605 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700606 ALOGE("%s: invalid rotation value (value = 0x%x",
607 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700608 }
609 return -1;
610}
611
612inline int getRotOutFmt(uint32_t format) {
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800613
614 if (isMdssRotator())
615 return format;
616
Naseer Ahmed29a26812012-06-14 00:56:20 -0700617 switch (format) {
618 case MDP_Y_CRCB_H2V2_TILE:
619 return MDP_Y_CRCB_H2V2;
620 case MDP_Y_CBCR_H2V2_TILE:
621 return MDP_Y_CBCR_H2V2;
622 case MDP_Y_CB_CR_H2V2:
623 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700624 case MDP_Y_CR_CB_GH2V2:
625 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700626 default:
627 return format;
628 }
629 // not reached
630 OVASSERT(false, "%s not reached", __FUNCTION__);
631 return -1;
632}
633
Naseer Ahmed29a26812012-06-14 00:56:20 -0700634
635inline uint32_t getColorFormat(uint32_t format)
636{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700637 return (format == HAL_PIXEL_FORMAT_YV12) ?
638 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700639}
640
641// FB0
642template <int CHAN>
643inline Dim getPositionS3DImpl(const Whf& whf)
644{
645 switch (whf.format & OUTPUT_3D_MASK)
646 {
647 case HAL_3D_OUT_SBS_MASK:
648 // x, y, w, h
649 return Dim(0, 0, whf.w/2, whf.h);
650 case HAL_3D_OUT_TOP_BOT_MASK:
651 return Dim(0, 0, whf.w, whf.h/2);
652 case HAL_3D_OUT_MONOS_MASK:
653 return Dim();
654 case HAL_3D_OUT_INTERL_MASK:
655 // FIXME error?
656 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
657 return Dim();
658 default:
659 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
660 whf.format);
661 }
662 return Dim();
663}
664
665template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500666inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700667{
668 switch (whf.format & OUTPUT_3D_MASK)
669 {
670 case HAL_3D_OUT_SBS_MASK:
671 return Dim(whf.w/2, 0, whf.w/2, whf.h);
672 case HAL_3D_OUT_TOP_BOT_MASK:
673 return Dim(0, whf.h/2, whf.w, whf.h/2);
674 case HAL_3D_OUT_MONOS_MASK:
675 return Dim(0, 0, whf.w, whf.h);
676 case HAL_3D_OUT_INTERL_MASK:
677 // FIXME error?
678 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
679 return Dim();
680 default:
681 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
682 whf.format);
683 }
684 return Dim();
685}
686
687template <int CHAN>
688inline bool getPositionS3D(const Whf& whf, Dim& out) {
689 out = getPositionS3DImpl<CHAN>(whf);
690 return (out != Dim());
691}
692
693template <int CHAN>
694inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
695 switch (fmt & INPUT_3D_MASK)
696 {
697 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
698 return Dim(0, 0, in.w/2, in.h);
699 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
700 return Dim(in.w/2, 0, in.w/2, in.h);
701 case HAL_3D_IN_TOP_BOTTOM:
702 return Dim(0, 0, in.w, in.h/2);
703 case HAL_3D_IN_INTERLEAVE:
704 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
705 break;
706 default:
707 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
708 break;
709 }
710 return Dim();
711}
712
713template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500714inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700715 switch (fmt & INPUT_3D_MASK)
716 {
717 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
718 return Dim(in.w/2, 0, in.w/2, in.h);
719 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
720 return Dim(0, 0, in.w/2, in.h);
721 case HAL_3D_IN_TOP_BOTTOM:
722 return Dim(0, in.h/2, in.w, in.h/2);
723 case HAL_3D_IN_INTERLEAVE:
724 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
725 break;
726 default:
727 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
728 break;
729 }
730 return Dim();
731}
732
733template <int CHAN>
734inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
735{
736 out = getCropS3DImpl<CHAN>(in, fmt);
737 return (out != Dim());
738}
739
740template <class Type>
741void swapWidthHeight(Type& width, Type& height) {
742 Type tmp = width;
743 width = height;
744 height = tmp;
745}
746
747inline void ScreenInfo::dump(const char* const s) const {
748 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
749 " bpp=%d stride=%d start/end ==",
750 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
751}
752
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700753inline bool openDev(OvFD& fd, int fbnum,
754 const char* const devpath, int flags) {
755 return overlay::open(fd, fbnum, devpath, flags);
756}
757
Saurabh Shahb121e142012-08-20 17:59:13 -0700758template <class T>
759inline void even_ceil(T& value) {
760 if(value & 1)
761 value++;
762}
763
764template <class T>
765inline void even_floor(T& value) {
766 if(value & 1)
767 value--;
768}
769
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500770inline const char* getDestStr(eDest dest) {
771 switch(dest) {
772 case OV_VG0: return "VG0";
773 case OV_RGB0: return "RGB0";
774 case OV_VG1: return "VG1";
775 case OV_RGB1: return "RGB1";
776 case OV_VG2: return "VG2";
777 case OV_RGB2: return "RGB2";
778 default: return "Invalid";
779 }
780 return "Invalid";
781}
782
783inline eMdpPipeType getPipeType(eDest dest) {
784 switch(dest) {
785 case OV_VG0:
786 case OV_VG1:
787 case OV_VG2:
788 return OV_MDP_PIPE_VG;
789 case OV_RGB0:
790 case OV_RGB1:
791 case OV_RGB2:
792 return OV_MDP_PIPE_RGB;
793 default:
794 return OV_MDP_PIPE_ANY;
795 }
796 return OV_MDP_PIPE_ANY;
797}
798
Naseer Ahmed29a26812012-06-14 00:56:20 -0700799} // namespace utils ends
800
801//--------------------Class Res stuff (namespace overlay only) -----------
802
803class Res {
804public:
805 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700806 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700807 // /dev/msm_rotator
808 static const char* const rotPath;
809 // /sys/class/graphics/fb1/format_3d
810 static const char* const format3DFile;
811 // /sys/class/graphics/fb1/3d_present
812 static const char* const edid3dInfoFile;
813 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
814 static const char* const barrierFile;
815};
816
817
818//--------------------Class OvFD stuff (namespace overlay only) -----------
819
Naseer Ahmed29a26812012-06-14 00:56:20 -0700820/*
821* Holds one FD
822* Dtor will NOT close the underlying FD.
823* That enables us to copy that object around
824* */
825class OvFD {
826public:
827 /* Ctor */
828 explicit OvFD();
829
830 /* dtor will NOT close the underlying FD */
831 ~OvFD();
832
833 /* Open fd using the path given by dev.
834 * return false in failure */
835 bool open(const char* const dev,
836 int flags = O_RDWR);
837
838 /* populate path */
839 void setPath(const char* const dev);
840
841 /* Close fd if we have a valid fd. */
842 bool close();
843
844 /* returns underlying fd.*/
845 int getFD() const;
846
847 /* returns true if fd is valid */
848 bool valid() const;
849
850 /* like operator= */
851 void copy(int fd);
852
853 /* dump the state of the instance */
854 void dump() const;
855private:
856 /* helper enum for determine valid/invalid fd */
857 enum { INVAL = -1 };
858
859 /* actual os fd */
860 int mFD;
861
862 /* path, for debugging */
863 char mPath[utils::MAX_PATH_LEN];
864};
865
866//-------------------Inlines--------------------------
867
868inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
869{
870 char dev_name[64] = {0};
871 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
872 return fd.open(dev_name, flags);
873}
874
875inline OvFD::OvFD() : mFD (INVAL) {
876 mPath[0] = 0;
877}
878
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700879inline OvFD::~OvFD() {
880 //no op since copy() can be used to share fd, in 3d cases.
881}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700882
883inline bool OvFD::open(const char* const dev, int flags)
884{
885 mFD = ::open(dev, flags, 0);
886 if (mFD < 0) {
887 // FIXME errno, strerror in bionic?
888 ALOGE("Cant open device %s err=%d", dev, errno);
889 return false;
890 }
891 setPath(dev);
892 return true;
893}
894
895inline void OvFD::setPath(const char* const dev)
896{
897 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
898}
899
900inline bool OvFD::close()
901{
902 int ret = 0;
903 if(valid()) {
904 ret = ::close(mFD);
905 mFD = INVAL;
906 }
907 return (ret == 0);
908}
909
910inline bool OvFD::valid() const
911{
912 return (mFD != INVAL);
913}
914
915inline int OvFD::getFD() const { return mFD; }
916
917inline void OvFD::copy(int fd) {
918 mFD = fd;
919}
920
921inline void OvFD::dump() const
922{
923 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
924 mFD, mPath);
925}
926
927//--------------- class OvFD stuff ends ---------------------
928
929} // overlay
930
931
932#endif // OVERLAY_UTILS_H