blob: f82fb88b3b00aff1c8ce9e8861b6a408b11696f4 [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#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 Ahmed29a26812012-06-14 00:56:20 -070046/*
47*
48* Collection of utilities functions/structs/enums etc...
49*
50* */
51
52// comment that out if you want to remove asserts
53// or put it as -D in Android.mk. your choice.
54#define OVERLAY_HAS_ASSERT
55
56#ifdef OVERLAY_HAS_ASSERT
57# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
58#else
59# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
60#endif // OVERLAY_HAS_ASSERT
61
62#define DEBUG_OVERLAY 0
63#define PROFILE_OVERLAY 0
64
65namespace overlay {
66
67// fwd
68class Overlay;
69
70namespace utils {
71struct Whf;
72struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070073
74inline uint32_t setBit(uint32_t x, uint32_t mask) {
75 return (x | mask);
76}
77
78inline uint32_t clrBit(uint32_t x, uint32_t mask) {
79 return (x & ~mask);
80}
81
82/* Utility class to help avoid copying instances by making the copy ctor
83* and assignment operator private
84*
85* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -070086* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -070087*/
88class NoCopy {
89protected:
90 NoCopy(){}
91 ~NoCopy() {}
92private:
93 NoCopy(const NoCopy&);
94 const NoCopy& operator=(const NoCopy&);
95};
96
97/*
98* Utility class to query the framebuffer info for primary display
99*
100* Usage:
101* Outside of functions:
102* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
103* Inside functions:
104* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
105*/
106class FrameBufferInfo {
107
108public:
109 /* ctor init */
110 explicit FrameBufferInfo();
111
112 /* Gets an instance if one does not already exist */
113 static FrameBufferInfo* getInstance();
114
115 /* Gets width of primary framebuffer */
116 int getWidth() const;
117
118 /* Gets height of primary framebuffer */
119 int getHeight() const;
120
121 /* Indicates whether true mirroring is supported */
122 bool supportTrueMirroring() const;
123
124private:
125 int mFBWidth;
126 int mFBHeight;
127 bool mBorderFillSupported;
128 static FrameBufferInfo *sFBInfoInstance;
129};
130
131/* 3D related utils, defines etc...
132 * The compound format passed to the overlay is
133 * ABCCC where A is the input 3D format
134 * B is the output 3D format
135 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
136enum { SHIFT_OUT_3D = 12,
137 SHIFT_TOT_3D = 16 };
138enum { INPUT_3D_MASK = 0xFFFF0000,
139 OUTPUT_3D_MASK = 0x0000FFFF };
140enum { BARRIER_LAND = 1,
141 BARRIER_PORT = 2 };
142
143inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700144inline uint32_t colorFormat(uint32_t fmt) {
145 /*TODO enable this block only if format has interlace / 3D info in top bits.
146 if(fmt & INTERLACE_MASK) {
147 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
148 }
149 fmt = fmt & 0xFFF;*/
150 return fmt;
151}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700152inline uint32_t format3DOutput(uint32_t x) {
153 return (x & 0xF000) >> SHIFT_OUT_3D; }
154inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
155uint32_t getColorFormat(uint32_t format);
156
157bool isHDMIConnected ();
158bool is3DTV();
159bool isPanel3D();
160bool usePanel3D();
161bool send3DInfoPacket (uint32_t fmt);
162bool enableBarrier (uint32_t orientation);
163uint32_t getS3DFormat(uint32_t fmt);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700164
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166bool getPositionS3D(const Whf& whf, Dim& out);
167
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700169bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
170
Naseer Ahmed29a26812012-06-14 00:56:20 -0700171template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700172void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700173
174struct Dim {
175 Dim () : x(0), y(0),
176 w(0), h(0),
177 o(0) {}
178 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
179 x(_x), y(_y),
180 w(_w), h(_h) {}
181 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
182 x(_x), y(_y),
183 w(_w), h(_h),
184 o(_o) {}
185 bool check(uint32_t _w, uint32_t _h) const {
186 return (x+w <= _w && y+h <= _h);
187
188 }
189
190 bool operator==(const Dim& d) const {
191 return d.x == x && d.y == y &&
192 d.w == w && d.h == h &&
193 d.o == o;
194 }
195
196 bool operator!=(const Dim& d) const {
197 return !operator==(d);
198 }
199
Naseer Ahmed29a26812012-06-14 00:56:20 -0700200 void dump() const;
201 uint32_t x;
202 uint32_t y;
203 uint32_t w;
204 uint32_t h;
205 uint32_t o;
206};
207
208// TODO have Whfz
209
210struct Whf {
211 Whf() : w(0), h(0), format(0), size(0) {}
212 Whf(uint32_t wi, uint32_t he, uint32_t f) :
213 w(wi), h(he), format(f), size(0) {}
214 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
215 w(wi), h(he), format(f), size(s) {}
216 // FIXME not comparing size at the moment
217 bool operator==(const Whf& whf) const {
218 return whf.w == w && whf.h == h &&
219 whf.format == format;
220 }
221 bool operator!=(const Whf& whf) const {
222 return !operator==(whf);
223 }
224 void dump() const;
225 uint32_t w;
226 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700227 uint32_t format;
228 uint32_t size;
229};
230
231enum { MAX_PATH_LEN = 256 };
232
Naseer Ahmed29a26812012-06-14 00:56:20 -0700233/**
234 * Rotator flags: not to be confused with orientation flags.
235 * Ususally, you want to open the rotator to make sure it is
236 * ready for business.
237 * ROT_FLAG_DISABLED: Rotator would not kick in. (ioctl will emit errors).
238 * ROT_FLAG_ENABLED: and when rotation is needed.
239 * (prim video playback)
240 * (UI mirroring on HDMI w/ 0 degree rotator. - just memcpy)
241 * In HDMI UI mirroring, rotator is always used.
242 * Even when w/o orienation change on primary,
243 * we do 0 rotation on HDMI and using rotator buffers.
244 * That is because we might see tearing otherwise. so
245 * we use another buffer (rotator).
246 * When a simple video playback on HDMI, no rotator is being used.(null r).
247 * */
248enum eRotFlags {
249 ROT_FLAG_DISABLED = 0,
250 ROT_FLAG_ENABLED = 1 // needed in rot
251};
252
Naseer Ahmed29a26812012-06-14 00:56:20 -0700253/* The values for is_fg flag for control alpha and transp
254 * IS_FG_OFF means is_fg = 0
255 * IS_FG_SET means is_fg = 1
256 */
257enum eIsFg {
258 IS_FG_OFF = 0,
259 IS_FG_SET = 1
260};
261
262/*
263 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
264 * kernel/common/linux/msm_mdp.h
265 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
266 * */
267enum eMdpFlags {
268 OV_MDP_FLAGS_NONE = 0,
269 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
270 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700271 OV_MDP_PLAY_NOWAIT = MDP_OV_PLAY_NOWAIT, //deprecated
272 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
273 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
274 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700275};
276
277enum eOverlayPipeType {
278 OV_PIPE_TYPE_NULL,
279 OV_PIPE_TYPE_BYPASS,
280 OV_PIPE_TYPE_GENERIC,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700281 OV_PIPE_TYPE_VIDEO_EXT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700282 OV_PIPE_TYPE_M3D_EXTERNAL,
283 OV_PIPE_TYPE_M3D_PRIMARY,
284 OV_PIPE_TYPE_RGB,
285 OV_PIPE_TYPE_S3D_EXTERNAL,
286 OV_PIPE_TYPE_S3D_PRIMARY,
287 OV_PIPE_TYPE_UI_MIRROR
288};
289
290enum eZorder {
291 ZORDER_0,
292 ZORDER_1,
293 ZORDER_2,
294 Z_SYSTEM_ALLOC = 0xFFFF
295};
296
297enum eMdpPipeType {
298 OV_MDP_PIPE_RGB,
299 OV_MDP_PIPE_VG
300};
301
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302// Max pipes via overlay (VG0, VG1, RGB1)
303enum { MAX_PIPES = 3 };
304
305/* Used to identify destination channels and
306 * also 3D channels e.g. when in 3D mode with 2
307 * pipes opened and it is used in get crop/pos 3D
Naseer Ahmed29a26812012-06-14 00:56:20 -0700308 * */
309enum eDest {
310 OV_PIPE0 = 1 << 0,
311 OV_PIPE1 = 1 << 1,
312 OV_PIPE2 = 1 << 2,
313 OV_PIPE_ALL = (OV_PIPE0 | OV_PIPE1 | OV_PIPE2)
314};
315
316/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
317enum eTransform {
318 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700319 OVERLAY_TRANSFORM_0 = 0x0,
320 /* flip source image horizontally 0x1 */
321 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
322 /* flip source image vertically 0x2 */
323 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324 /* rotate source image 180 degrees
325 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700326 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
327 /* rotate source image 90 degrees 0x4 */
328 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
329 /* rotate source image 90 degrees and flip horizontally 0x5 */
330 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
331 HAL_TRANSFORM_FLIP_H,
332 /* rotate source image 90 degrees and flip vertically 0x6 */
333 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
334 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700335 /* rotate source image 270 degrees
336 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700337 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700338 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700339 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340};
341
342// Used to consolidate pipe params
343struct PipeArgs {
344 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700345 zorder(Z_SYSTEM_ALLOC),
346 isFg(IS_FG_OFF),
347 rotFlags(ROT_FLAG_DISABLED){
348 }
349
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700350 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351 eZorder z, eIsFg fg, eRotFlags r) :
352 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354 zorder(z),
355 isFg(fg),
356 rotFlags(r) {
357 }
358
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700359 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700361 eZorder zorder; // stage number
362 eIsFg isFg; // control alpha & transp
363 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364};
365
366enum eOverlayState{
367 /* No pipes from overlay open */
368 OV_CLOSED = 0,
369
370 /* 2D Video */
371 OV_2D_VIDEO_ON_PANEL,
372 OV_2D_VIDEO_ON_PANEL_TV,
373
374 /* 3D Video on one display (panel or TV) */
375 OV_3D_VIDEO_ON_2D_PANEL,
376 OV_3D_VIDEO_ON_3D_PANEL,
377 OV_3D_VIDEO_ON_3D_TV,
378
379 /* 3D Video on two displays (panel and TV) */
380 OV_3D_VIDEO_ON_2D_PANEL_2D_TV,
381
382 /* UI Mirroring */
383 OV_UI_MIRROR,
384 OV_2D_TRUE_UI_MIRROR,
385 OV_M3D_TRUE_UI_MIRROR, // Not yet supported
386
387 /* Composition Bypass */
388 OV_BYPASS_1_LAYER,
389 OV_BYPASS_2_LAYER,
390 OV_BYPASS_3_LAYER,
391};
392
393inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
394 f = static_cast<eMdpFlags>(setBit(f, v));
395}
396
397inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
398 f = static_cast<eMdpFlags>(clrBit(f, v));
399}
400
401// fb 0/1/2
402enum { FB0, FB1, FB2 };
403
404//Panels could be categorized as primary and external
405enum { PRIMARY, EXTERNAL };
406
407//External Panels could use HDMI or WFD
408enum {
409 HDMI = 1,
410 WFD = 2
411};
412
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700413//TODO Make this a part of some appropriate class
Naseer Ahmed29a26812012-06-14 00:56:20 -0700414static int sExtType = HDMI; //HDMI or WFD
Naseer Ahmed29a26812012-06-14 00:56:20 -0700415//Set by client as HDMI/WFD
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700416void setExtType(const int& type);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700417//Return External panel type set by client.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700418int getExtType();
419
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420
421//Gets the FB number for the external type.
422//As of now, HDMI always has fb1, WFD could use fb1 or fb2
423//Assumes Ext type set by setExtType() from client.
424static int getFBForPanel(int panel) { // PRIMARY OR EXTERNAL
425 switch(panel) {
426 case PRIMARY: return FB0;
427 break;
428 case EXTERNAL:
429 switch(getExtType()) {
430 case HDMI: return FB1;
431 break;
432 case WFD: return FB2;//Hardcoding fb2 for wfd. Will change.
433 break;
434 }
435 break;
436 default:
437 ALOGE("%s: Unrecognized PANEL category %d", __func__, panel);
438 break;
439 }
440 return -1;
441}
442
443// number of rgb pipes bufs (max)
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700444
Naseer Ahmed29a26812012-06-14 00:56:20 -0700445// 2 for rgb0/1 double bufs
446enum { RGB_PIPE_NUM_BUFS = 2 };
447
448struct ScreenInfo {
449 ScreenInfo() : mFBWidth(0),
450 mFBHeight(0),
451 mFBbpp(0),
452 mFBystride(0) {}
453 void dump(const char* const s) const;
454 uint32_t mFBWidth;
455 uint32_t mFBHeight;
456 uint32_t mFBbpp;
457 uint32_t mFBystride;
458};
459
460int getMdpFormat(int format);
461int getRotOutFmt(uint32_t format);
462/* flip is upside down and such. V, H flip
463 * rotation is 90, 180 etc
464 * It returns MDP related enum/define that match rot+flip*/
465int getMdpOrient(eTransform rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700466const char* getFormatString(uint32_t format);
467const char* getStateString(eOverlayState state);
468
Naseer Ahmed29a26812012-06-14 00:56:20 -0700469// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
470// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
471enum { HW_OV_MAGNIFICATION_LIMIT = 20,
472 HW_OV_MINIFICATION_LIMIT = 8
473};
474
Naseer Ahmed29a26812012-06-14 00:56:20 -0700475template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700476inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700477
478template <class T> inline void swap ( T& a, T& b )
479{
480 T c(a); a=b; b=c;
481}
482
483inline int alignup(int value, int a) {
484 //if align = 0, return the value. Else, do alignment.
485 return a ? ((((value - 1) / a) + 1) * a) : value;
486}
487
488// FIXME that align should replace the upper one.
489inline int align(int value, int a) {
490 //if align = 0, return the value. Else, do alignment.
491 return a ? ((value + (a-1)) & ~(a-1)) : value;
492}
493
Naseer Ahmed29a26812012-06-14 00:56:20 -0700494enum eRotOutFmt {
495 ROT_OUT_FMT_DEFAULT,
496 ROT_OUT_FMT_Y_CRCB_H2V2
497};
498
499template <int ROT_OUT_FMT> struct RotOutFmt;
500
501// FIXME, taken from gralloc_priv.h. Need to
502// put it back as soon as overlay takes place of the old one
503/* possible formats for 3D content*/
504enum {
505 HAL_NO_3D = 0x0000,
506 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
507 HAL_3D_IN_TOP_BOTTOM = 0x20000,
508 HAL_3D_IN_INTERLEAVE = 0x40000,
509 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
510 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
511 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
512 HAL_3D_OUT_INTERLEAVE = 0x4000,
513 HAL_3D_OUT_MONOSCOPIC = 0x8000
514};
515
516enum { HAL_3D_OUT_SBS_MASK =
517 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
518 HAL_3D_OUT_TOP_BOT_MASK =
519 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
520 HAL_3D_OUT_INTERL_MASK =
521 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
522 HAL_3D_OUT_MONOS_MASK =
523 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
524};
525
526
527inline bool isYuv(uint32_t format) {
528 switch(format){
529 case MDP_Y_CBCR_H2V1:
530 case MDP_Y_CBCR_H2V2:
531 case MDP_Y_CRCB_H2V2:
532 case MDP_Y_CRCB_H2V2_TILE:
533 case MDP_Y_CBCR_H2V2_TILE:
534 return true;
535 default:
536 return false;
537 }
538 return false;
539}
540
541inline bool isRgb(uint32_t format) {
542 switch(format) {
543 case MDP_RGBA_8888:
544 case MDP_BGRA_8888:
545 case MDP_RGBX_8888:
546 case MDP_RGB_565:
547 return true;
548 default:
549 return false;
550 }
551 return false;
552}
553
554inline bool isValidDest(eDest dest)
555{
556 if ((OV_PIPE0 & dest) ||
557 (OV_PIPE1 & dest) ||
558 (OV_PIPE2 & dest)) {
559 return true;
560 }
561 return false;
562}
563
564inline const char* getFormatString(uint32_t format){
565 static const char* const formats[] = {
566 "MDP_RGB_565",
567 "MDP_XRGB_8888",
568 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700569 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700570 "MDP_ARGB_8888",
571 "MDP_RGB_888",
572 "MDP_Y_CRCB_H2V2",
573 "MDP_YCRYCB_H2V1",
574 "MDP_Y_CRCB_H2V1",
575 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700576 "MDP_Y_CRCB_H1V2",
577 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700578 "MDP_RGBA_8888",
579 "MDP_BGRA_8888",
580 "MDP_RGBX_8888",
581 "MDP_Y_CRCB_H2V2_TILE",
582 "MDP_Y_CBCR_H2V2_TILE",
583 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700584 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700585 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700586 "MDP_Y_CRCB_H1V1",
587 "MDP_Y_CBCR_H1V1",
588 "MDP_YCRCB_H1V1",
589 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700590 "MDP_BGR_565",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700591 "MDP_IMGTYPE_LIMIT",
592 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700593 "MDP_FB_FORMAT",
594 "MDP_IMGTYPE_LIMIT2"
595 };
596 OVASSERT(format < sizeof(formats) / sizeof(formats[0]),
597 "getFormatString wrong fmt %d", format);
598 return formats[format];
599}
600
601inline const char* getStateString(eOverlayState state){
602 switch (state) {
603 case OV_CLOSED:
604 return "OV_CLOSED";
605 case OV_2D_VIDEO_ON_PANEL:
606 return "OV_2D_VIDEO_ON_PANEL";
607 case OV_2D_VIDEO_ON_PANEL_TV:
608 return "OV_2D_VIDEO_ON_PANEL_TV";
609 case OV_3D_VIDEO_ON_2D_PANEL:
610 return "OV_3D_VIDEO_ON_2D_PANEL";
611 case OV_3D_VIDEO_ON_3D_PANEL:
612 return "OV_3D_VIDEO_ON_3D_PANEL";
613 case OV_3D_VIDEO_ON_3D_TV:
614 return "OV_3D_VIDEO_ON_3D_TV";
615 case OV_3D_VIDEO_ON_2D_PANEL_2D_TV:
616 return "OV_3D_VIDEO_ON_2D_PANEL_2D_TV";
617 case OV_UI_MIRROR:
618 return "OV_UI_MIRROR";
619 case OV_2D_TRUE_UI_MIRROR:
620 return "OV_2D_TRUE_UI_MIRROR";
621 case OV_BYPASS_1_LAYER:
622 return "OV_BYPASS_1_LAYER";
623 case OV_BYPASS_2_LAYER:
624 return "OV_BYPASS_2_LAYER";
625 case OV_BYPASS_3_LAYER:
626 return "OV_BYPASS_3_LAYER";
627 default:
628 return "UNKNOWN_STATE";
629 }
630 return "BAD_STATE";
631}
632
Naseer Ahmed29a26812012-06-14 00:56:20 -0700633inline void Whf::dump() const {
634 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
635 w, h, format, size);
636}
637
638inline void Dim::dump() const {
639 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
640}
641
642inline int getMdpOrient(eTransform rotation) {
643 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700644 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700645 {
646 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700647 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
648 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
649 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
650 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
651 return MDP_ROT_90 | MDP_FLIP_UD;
652 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
653 return MDP_ROT_90 | MDP_FLIP_LR;
654 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
655 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700656 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700657 ALOGE("%s: invalid rotation value (value = 0x%x",
658 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700659 }
660 return -1;
661}
662
663inline int getRotOutFmt(uint32_t format) {
664 switch (format) {
665 case MDP_Y_CRCB_H2V2_TILE:
666 return MDP_Y_CRCB_H2V2;
667 case MDP_Y_CBCR_H2V2_TILE:
668 return MDP_Y_CBCR_H2V2;
669 case MDP_Y_CB_CR_H2V2:
670 return MDP_Y_CBCR_H2V2;
671 default:
672 return format;
673 }
674 // not reached
675 OVASSERT(false, "%s not reached", __FUNCTION__);
676 return -1;
677}
678
Naseer Ahmed29a26812012-06-14 00:56:20 -0700679
680inline uint32_t getColorFormat(uint32_t format)
681{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700682 return (format == HAL_PIXEL_FORMAT_YV12) ?
683 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700684}
685
686// FB0
687template <int CHAN>
688inline Dim getPositionS3DImpl(const Whf& whf)
689{
690 switch (whf.format & OUTPUT_3D_MASK)
691 {
692 case HAL_3D_OUT_SBS_MASK:
693 // x, y, w, h
694 return Dim(0, 0, whf.w/2, whf.h);
695 case HAL_3D_OUT_TOP_BOT_MASK:
696 return Dim(0, 0, whf.w, whf.h/2);
697 case HAL_3D_OUT_MONOS_MASK:
698 return Dim();
699 case HAL_3D_OUT_INTERL_MASK:
700 // FIXME error?
701 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
702 return Dim();
703 default:
704 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
705 whf.format);
706 }
707 return Dim();
708}
709
710template <>
711inline Dim getPositionS3DImpl<utils::OV_PIPE1>(const Whf& whf)
712{
713 switch (whf.format & OUTPUT_3D_MASK)
714 {
715 case HAL_3D_OUT_SBS_MASK:
716 return Dim(whf.w/2, 0, whf.w/2, whf.h);
717 case HAL_3D_OUT_TOP_BOT_MASK:
718 return Dim(0, whf.h/2, whf.w, whf.h/2);
719 case HAL_3D_OUT_MONOS_MASK:
720 return Dim(0, 0, whf.w, whf.h);
721 case HAL_3D_OUT_INTERL_MASK:
722 // FIXME error?
723 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
724 return Dim();
725 default:
726 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
727 whf.format);
728 }
729 return Dim();
730}
731
732template <int CHAN>
733inline bool getPositionS3D(const Whf& whf, Dim& out) {
734 out = getPositionS3DImpl<CHAN>(whf);
735 return (out != Dim());
736}
737
738template <int CHAN>
739inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
740 switch (fmt & INPUT_3D_MASK)
741 {
742 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
743 return Dim(0, 0, in.w/2, in.h);
744 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
745 return Dim(in.w/2, 0, in.w/2, in.h);
746 case HAL_3D_IN_TOP_BOTTOM:
747 return Dim(0, 0, in.w, in.h/2);
748 case HAL_3D_IN_INTERLEAVE:
749 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
750 break;
751 default:
752 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
753 break;
754 }
755 return Dim();
756}
757
758template <>
759inline Dim getCropS3DImpl<utils::OV_PIPE1>(const Dim& in, uint32_t fmt) {
760 switch (fmt & INPUT_3D_MASK)
761 {
762 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
763 return Dim(in.w/2, 0, in.w/2, in.h);
764 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
765 return Dim(0, 0, in.w/2, in.h);
766 case HAL_3D_IN_TOP_BOTTOM:
767 return Dim(0, in.h/2, in.w, in.h/2);
768 case HAL_3D_IN_INTERLEAVE:
769 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
770 break;
771 default:
772 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
773 break;
774 }
775 return Dim();
776}
777
778template <int CHAN>
779inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
780{
781 out = getCropS3DImpl<CHAN>(in, fmt);
782 return (out != Dim());
783}
784
785template <class Type>
786void swapWidthHeight(Type& width, Type& height) {
787 Type tmp = width;
788 width = height;
789 height = tmp;
790}
791
792inline void ScreenInfo::dump(const char* const s) const {
793 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
794 " bpp=%d stride=%d start/end ==",
795 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
796}
797
Naseer Ahmed29a26812012-06-14 00:56:20 -0700798} // namespace utils ends
799
800//--------------------Class Res stuff (namespace overlay only) -----------
801
802class Res {
803public:
804 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700805 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700806 // /dev/msm_rotator
807 static const char* const rotPath;
808 // /sys/class/graphics/fb1/format_3d
809 static const char* const format3DFile;
810 // /sys/class/graphics/fb1/3d_present
811 static const char* const edid3dInfoFile;
812 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
813 static const char* const barrierFile;
814};
815
816
817//--------------------Class OvFD stuff (namespace overlay only) -----------
818
819class OvFD;
820
821/* helper function to open by using fbnum */
822bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
823 int flags = O_RDWR);
824
825/*
826* Holds one FD
827* Dtor will NOT close the underlying FD.
828* That enables us to copy that object around
829* */
830class OvFD {
831public:
832 /* Ctor */
833 explicit OvFD();
834
835 /* dtor will NOT close the underlying FD */
836 ~OvFD();
837
838 /* Open fd using the path given by dev.
839 * return false in failure */
840 bool open(const char* const dev,
841 int flags = O_RDWR);
842
843 /* populate path */
844 void setPath(const char* const dev);
845
846 /* Close fd if we have a valid fd. */
847 bool close();
848
849 /* returns underlying fd.*/
850 int getFD() const;
851
852 /* returns true if fd is valid */
853 bool valid() const;
854
855 /* like operator= */
856 void copy(int fd);
857
858 /* dump the state of the instance */
859 void dump() const;
860private:
861 /* helper enum for determine valid/invalid fd */
862 enum { INVAL = -1 };
863
864 /* actual os fd */
865 int mFD;
866
867 /* path, for debugging */
868 char mPath[utils::MAX_PATH_LEN];
869};
870
871//-------------------Inlines--------------------------
872
873inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
874{
875 char dev_name[64] = {0};
876 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
877 return fd.open(dev_name, flags);
878}
879
880inline OvFD::OvFD() : mFD (INVAL) {
881 mPath[0] = 0;
882}
883
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700884inline OvFD::~OvFD() {
885 //no op since copy() can be used to share fd, in 3d cases.
886}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700887
888inline bool OvFD::open(const char* const dev, int flags)
889{
890 mFD = ::open(dev, flags, 0);
891 if (mFD < 0) {
892 // FIXME errno, strerror in bionic?
893 ALOGE("Cant open device %s err=%d", dev, errno);
894 return false;
895 }
896 setPath(dev);
897 return true;
898}
899
900inline void OvFD::setPath(const char* const dev)
901{
902 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
903}
904
905inline bool OvFD::close()
906{
907 int ret = 0;
908 if(valid()) {
909 ret = ::close(mFD);
910 mFD = INVAL;
911 }
912 return (ret == 0);
913}
914
915inline bool OvFD::valid() const
916{
917 return (mFD != INVAL);
918}
919
920inline int OvFD::getFD() const { return mFD; }
921
922inline void OvFD::copy(int fd) {
923 mFD = fd;
924}
925
926inline void OvFD::dump() const
927{
928 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
929 mFD, mPath);
930}
931
932//--------------- class OvFD stuff ends ---------------------
933
934} // overlay
935
936
937#endif // OVERLAY_UTILS_H