blob: 975b7b1a349e36031dd77cbfb10cf0740876cb69 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Saurabh Shah56f610d2012-08-07 15:27:06 -07002* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
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 Ahmed758bfc52012-11-28 17:02:08 -050046
Sushil Chauhanc5e61482012-08-22 17:13:32 -070047#ifndef MDP_Y_CBCR_H2V2_VENUS
48#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
49#endif
50
Naseer Ahmed29a26812012-06-14 00:56:20 -070051/*
52*
53* Collection of utilities functions/structs/enums etc...
54*
55* */
56
57// comment that out if you want to remove asserts
58// or put it as -D in Android.mk. your choice.
59#define OVERLAY_HAS_ASSERT
60
61#ifdef OVERLAY_HAS_ASSERT
62# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
63#else
64# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
65#endif // OVERLAY_HAS_ASSERT
66
67#define DEBUG_OVERLAY 0
68#define PROFILE_OVERLAY 0
69
70namespace overlay {
71
72// fwd
73class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070074class OvFD;
75
76/* helper function to open by using fbnum */
77bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
78 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070079
80namespace utils {
81struct Whf;
82struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070083
84inline uint32_t setBit(uint32_t x, uint32_t mask) {
85 return (x | mask);
86}
87
88inline uint32_t clrBit(uint32_t x, uint32_t mask) {
89 return (x & ~mask);
90}
91
92/* Utility class to help avoid copying instances by making the copy ctor
93* and assignment operator private
94*
95* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -070096* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -070097*/
98class NoCopy {
99protected:
100 NoCopy(){}
101 ~NoCopy() {}
102private:
103 NoCopy(const NoCopy&);
104 const NoCopy& operator=(const NoCopy&);
105};
106
107/*
108* Utility class to query the framebuffer info for primary display
109*
110* Usage:
111* Outside of functions:
112* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
113* Inside functions:
114* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
115*/
116class FrameBufferInfo {
117
118public:
119 /* ctor init */
120 explicit FrameBufferInfo();
121
122 /* Gets an instance if one does not already exist */
123 static FrameBufferInfo* getInstance();
124
125 /* Gets width of primary framebuffer */
126 int getWidth() const;
127
128 /* Gets height of primary framebuffer */
129 int getHeight() const;
130
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131private:
132 int mFBWidth;
133 int mFBHeight;
134 bool mBorderFillSupported;
135 static FrameBufferInfo *sFBInfoInstance;
136};
137
138/* 3D related utils, defines etc...
139 * The compound format passed to the overlay is
140 * ABCCC where A is the input 3D format
141 * B is the output 3D format
142 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
143enum { SHIFT_OUT_3D = 12,
144 SHIFT_TOT_3D = 16 };
145enum { INPUT_3D_MASK = 0xFFFF0000,
146 OUTPUT_3D_MASK = 0x0000FFFF };
147enum { BARRIER_LAND = 1,
148 BARRIER_PORT = 2 };
149
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700150/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
151 * close all the pipes if it is opened after reboot.
152 */
153int initOverlay(void);
154
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156inline uint32_t colorFormat(uint32_t fmt) {
157 /*TODO enable this block only if format has interlace / 3D info in top bits.
158 if(fmt & INTERLACE_MASK) {
159 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
160 }
161 fmt = fmt & 0xFFF;*/
162 return fmt;
163}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700164inline uint32_t format3DOutput(uint32_t x) {
165 return (x & 0xF000) >> SHIFT_OUT_3D; }
166inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
167uint32_t getColorFormat(uint32_t format);
168
169bool isHDMIConnected ();
170bool is3DTV();
171bool isPanel3D();
172bool usePanel3D();
173bool send3DInfoPacket (uint32_t fmt);
174bool enableBarrier (uint32_t orientation);
175uint32_t getS3DFormat(uint32_t fmt);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700176
Naseer Ahmed29a26812012-06-14 00:56:20 -0700177template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700178bool getPositionS3D(const Whf& whf, Dim& out);
179
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185
186struct Dim {
187 Dim () : x(0), y(0),
188 w(0), h(0),
189 o(0) {}
190 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
191 x(_x), y(_y),
192 w(_w), h(_h) {}
193 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
194 x(_x), y(_y),
195 w(_w), h(_h),
196 o(_o) {}
197 bool check(uint32_t _w, uint32_t _h) const {
198 return (x+w <= _w && y+h <= _h);
199
200 }
201
202 bool operator==(const Dim& d) const {
203 return d.x == x && d.y == y &&
204 d.w == w && d.h == h &&
205 d.o == o;
206 }
207
208 bool operator!=(const Dim& d) const {
209 return !operator==(d);
210 }
211
Naseer Ahmed29a26812012-06-14 00:56:20 -0700212 void dump() const;
213 uint32_t x;
214 uint32_t y;
215 uint32_t w;
216 uint32_t h;
217 uint32_t o;
218};
219
220// TODO have Whfz
221
222struct Whf {
223 Whf() : w(0), h(0), format(0), size(0) {}
224 Whf(uint32_t wi, uint32_t he, uint32_t f) :
225 w(wi), h(he), format(f), size(0) {}
226 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
227 w(wi), h(he), format(f), size(s) {}
228 // FIXME not comparing size at the moment
229 bool operator==(const Whf& whf) const {
230 return whf.w == w && whf.h == h &&
231 whf.format == format;
232 }
233 bool operator!=(const Whf& whf) const {
234 return !operator==(whf);
235 }
236 void dump() const;
237 uint32_t w;
238 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239 uint32_t format;
240 uint32_t size;
241};
242
Saurabh Shah56f610d2012-08-07 15:27:06 -0700243class ActionSafe {
244private:
245 ActionSafe() : mWidth(0.0f), mHeight(0.0f) { };
246 float mWidth;
247 float mHeight;
248 static ActionSafe *sActionSafe;
249public:
250 ~ActionSafe() { };
251 static ActionSafe* getInstance() {
252 if(!sActionSafe) {
253 sActionSafe = new ActionSafe();
254 }
255 return sActionSafe;
256 }
257 void setDimension(int w, int h) {
258 mWidth = (float)w;
259 mHeight = (float)h;
260 }
261 float getWidth() { return mWidth; }
262 float getHeight() { return mHeight; }
263};
264
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265enum { MAX_PATH_LEN = 256 };
266
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267/**
268 * Rotator flags: not to be confused with orientation flags.
269 * Ususally, you want to open the rotator to make sure it is
270 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500271 * ROT_FLAG_DISABLED: Rotator not used unless required.
272 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273 * */
274enum eRotFlags {
275 ROT_FLAG_DISABLED = 0,
276 ROT_FLAG_ENABLED = 1 // needed in rot
277};
278
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279/* The values for is_fg flag for control alpha and transp
280 * IS_FG_OFF means is_fg = 0
281 * IS_FG_SET means is_fg = 1
282 */
283enum eIsFg {
284 IS_FG_OFF = 0,
285 IS_FG_SET = 1
286};
287
288/*
289 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
290 * kernel/common/linux/msm_mdp.h
291 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
292 * */
293enum eMdpFlags {
294 OV_MDP_FLAGS_NONE = 0,
295 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
296 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700297 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
298 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
299 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700300 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700301 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700302 OV_MDP_FLIP_H = MDP_FLIP_LR,
303 OV_MDP_FLIP_V = MDP_FLIP_UD,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304};
305
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306enum eZorder {
307 ZORDER_0,
308 ZORDER_1,
309 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500310 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700311 Z_SYSTEM_ALLOC = 0xFFFF
312};
313
314enum eMdpPipeType {
315 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500316 OV_MDP_PIPE_VG,
317 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700318};
319
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500320/* Used to identify destination pipes
321 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500323 OV_VG0 = 0,
324 OV_RGB0,
325 OV_VG1,
326 OV_RGB1,
327 OV_VG2,
328 OV_RGB2,
329 OV_INVALID,
330};
331
332/* Used when a buffer is split over 2 pipes and sent to display */
333enum {
334 OV_LEFT_SPLIT = 0,
335 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336};
337
338/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
339enum eTransform {
340 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700341 OVERLAY_TRANSFORM_0 = 0x0,
342 /* flip source image horizontally 0x1 */
343 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
344 /* flip source image vertically 0x2 */
345 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700346 /* rotate source image 180 degrees
347 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700348 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
349 /* rotate source image 90 degrees 0x4 */
350 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
351 /* rotate source image 90 degrees and flip horizontally 0x5 */
352 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
353 HAL_TRANSFORM_FLIP_H,
354 /* rotate source image 90 degrees and flip vertically 0x6 */
355 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
356 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700357 /* rotate source image 270 degrees
358 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700359 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700361 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362};
363
364// Used to consolidate pipe params
365struct PipeArgs {
366 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367 zorder(Z_SYSTEM_ALLOC),
368 isFg(IS_FG_OFF),
369 rotFlags(ROT_FLAG_DISABLED){
370 }
371
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700372 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 eZorder z, eIsFg fg, eRotFlags r) :
374 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376 zorder(z),
377 isFg(fg),
378 rotFlags(r) {
379 }
380
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700381 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700382 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700383 eZorder zorder; // stage number
384 eIsFg isFg; // control alpha & transp
385 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386};
387
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
389 f = static_cast<eMdpFlags>(setBit(f, v));
390}
391
392inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
393 f = static_cast<eMdpFlags>(clrBit(f, v));
394}
395
396// fb 0/1/2
397enum { FB0, FB1, FB2 };
398
399//Panels could be categorized as primary and external
400enum { PRIMARY, EXTERNAL };
401
Naseer Ahmed29a26812012-06-14 00:56:20 -0700402// 2 for rgb0/1 double bufs
403enum { RGB_PIPE_NUM_BUFS = 2 };
404
405struct ScreenInfo {
406 ScreenInfo() : mFBWidth(0),
407 mFBHeight(0),
408 mFBbpp(0),
409 mFBystride(0) {}
410 void dump(const char* const s) const;
411 uint32_t mFBWidth;
412 uint32_t mFBHeight;
413 uint32_t mFBbpp;
414 uint32_t mFBystride;
415};
416
417int getMdpFormat(int format);
418int getRotOutFmt(uint32_t format);
419/* flip is upside down and such. V, H flip
420 * rotation is 90, 180 etc
421 * It returns MDP related enum/define that match rot+flip*/
422int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700423const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424
Naseer Ahmed29a26812012-06-14 00:56:20 -0700425// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
426// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
427enum { HW_OV_MAGNIFICATION_LIMIT = 20,
428 HW_OV_MINIFICATION_LIMIT = 8
429};
430
Naseer Ahmed29a26812012-06-14 00:56:20 -0700431template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700432inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700433
434template <class T> inline void swap ( T& a, T& b )
435{
436 T c(a); a=b; b=c;
437}
438
439inline int alignup(int value, int a) {
440 //if align = 0, return the value. Else, do alignment.
441 return a ? ((((value - 1) / a) + 1) * a) : value;
442}
443
444// FIXME that align should replace the upper one.
445inline int align(int value, int a) {
446 //if align = 0, return the value. Else, do alignment.
447 return a ? ((value + (a-1)) & ~(a-1)) : value;
448}
449
Naseer Ahmed29a26812012-06-14 00:56:20 -0700450enum eRotOutFmt {
451 ROT_OUT_FMT_DEFAULT,
452 ROT_OUT_FMT_Y_CRCB_H2V2
453};
454
455template <int ROT_OUT_FMT> struct RotOutFmt;
456
457// FIXME, taken from gralloc_priv.h. Need to
458// put it back as soon as overlay takes place of the old one
459/* possible formats for 3D content*/
460enum {
461 HAL_NO_3D = 0x0000,
462 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
463 HAL_3D_IN_TOP_BOTTOM = 0x20000,
464 HAL_3D_IN_INTERLEAVE = 0x40000,
465 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
466 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
467 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
468 HAL_3D_OUT_INTERLEAVE = 0x4000,
469 HAL_3D_OUT_MONOSCOPIC = 0x8000
470};
471
472enum { HAL_3D_OUT_SBS_MASK =
473 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
474 HAL_3D_OUT_TOP_BOT_MASK =
475 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
476 HAL_3D_OUT_INTERL_MASK =
477 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
478 HAL_3D_OUT_MONOS_MASK =
479 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
480};
481
482
483inline bool isYuv(uint32_t format) {
484 switch(format){
485 case MDP_Y_CBCR_H2V1:
486 case MDP_Y_CBCR_H2V2:
487 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700488 case MDP_Y_CRCB_H1V1:
489 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700490 case MDP_Y_CRCB_H2V2_TILE:
491 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700492 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700493 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700494 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495 return true;
496 default:
497 return false;
498 }
499 return false;
500}
501
502inline bool isRgb(uint32_t format) {
503 switch(format) {
504 case MDP_RGBA_8888:
505 case MDP_BGRA_8888:
506 case MDP_RGBX_8888:
507 case MDP_RGB_565:
508 return true;
509 default:
510 return false;
511 }
512 return false;
513}
514
Saurabh Shah9c876d92012-08-25 19:29:53 -0700515inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700516 static const char* const formats[] = {
517 "MDP_RGB_565",
518 "MDP_XRGB_8888",
519 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700520 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700521 "MDP_ARGB_8888",
522 "MDP_RGB_888",
523 "MDP_Y_CRCB_H2V2",
524 "MDP_YCRYCB_H2V1",
525 "MDP_Y_CRCB_H2V1",
526 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700527 "MDP_Y_CRCB_H1V2",
528 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700529 "MDP_RGBA_8888",
530 "MDP_BGRA_8888",
531 "MDP_RGBX_8888",
532 "MDP_Y_CRCB_H2V2_TILE",
533 "MDP_Y_CBCR_H2V2_TILE",
534 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700535 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700536 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700537 "MDP_Y_CRCB_H1V1",
538 "MDP_Y_CBCR_H1V1",
539 "MDP_YCRCB_H1V1",
540 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700542 "MDP_BGR_888",
543 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700544 "MDP_IMGTYPE_LIMIT",
545 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700546 "MDP_FB_FORMAT",
547 "MDP_IMGTYPE_LIMIT2"
548 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700549 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
550 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
551 return "Unsupported format";
552 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700553 return formats[format];
554}
555
Naseer Ahmed29a26812012-06-14 00:56:20 -0700556inline void Whf::dump() const {
557 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
558 w, h, format, size);
559}
560
561inline void Dim::dump() const {
562 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
563}
564
565inline int getMdpOrient(eTransform rotation) {
566 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700567 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700568 {
569 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700570 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
571 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
572 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700573 //getMdpOrient will switch the flips if the source is 90 rotated.
574 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700575 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700576 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700577 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
578 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700579 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
580 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700581 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700582 ALOGE("%s: invalid rotation value (value = 0x%x",
583 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700584 }
585 return -1;
586}
587
588inline int getRotOutFmt(uint32_t format) {
589 switch (format) {
590 case MDP_Y_CRCB_H2V2_TILE:
591 return MDP_Y_CRCB_H2V2;
592 case MDP_Y_CBCR_H2V2_TILE:
593 return MDP_Y_CBCR_H2V2;
594 case MDP_Y_CB_CR_H2V2:
595 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700596 case MDP_Y_CR_CB_GH2V2:
597 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700598 default:
599 return format;
600 }
601 // not reached
602 OVASSERT(false, "%s not reached", __FUNCTION__);
603 return -1;
604}
605
Naseer Ahmed29a26812012-06-14 00:56:20 -0700606
607inline uint32_t getColorFormat(uint32_t format)
608{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700609 return (format == HAL_PIXEL_FORMAT_YV12) ?
610 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700611}
612
613// FB0
614template <int CHAN>
615inline Dim getPositionS3DImpl(const Whf& whf)
616{
617 switch (whf.format & OUTPUT_3D_MASK)
618 {
619 case HAL_3D_OUT_SBS_MASK:
620 // x, y, w, h
621 return Dim(0, 0, whf.w/2, whf.h);
622 case HAL_3D_OUT_TOP_BOT_MASK:
623 return Dim(0, 0, whf.w, whf.h/2);
624 case HAL_3D_OUT_MONOS_MASK:
625 return Dim();
626 case HAL_3D_OUT_INTERL_MASK:
627 // FIXME error?
628 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
629 return Dim();
630 default:
631 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
632 whf.format);
633 }
634 return Dim();
635}
636
637template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500638inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700639{
640 switch (whf.format & OUTPUT_3D_MASK)
641 {
642 case HAL_3D_OUT_SBS_MASK:
643 return Dim(whf.w/2, 0, whf.w/2, whf.h);
644 case HAL_3D_OUT_TOP_BOT_MASK:
645 return Dim(0, whf.h/2, whf.w, whf.h/2);
646 case HAL_3D_OUT_MONOS_MASK:
647 return Dim(0, 0, whf.w, whf.h);
648 case HAL_3D_OUT_INTERL_MASK:
649 // FIXME error?
650 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
651 return Dim();
652 default:
653 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
654 whf.format);
655 }
656 return Dim();
657}
658
659template <int CHAN>
660inline bool getPositionS3D(const Whf& whf, Dim& out) {
661 out = getPositionS3DImpl<CHAN>(whf);
662 return (out != Dim());
663}
664
665template <int CHAN>
666inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
667 switch (fmt & INPUT_3D_MASK)
668 {
669 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
670 return Dim(0, 0, in.w/2, in.h);
671 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
672 return Dim(in.w/2, 0, in.w/2, in.h);
673 case HAL_3D_IN_TOP_BOTTOM:
674 return Dim(0, 0, in.w, in.h/2);
675 case HAL_3D_IN_INTERLEAVE:
676 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
677 break;
678 default:
679 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
680 break;
681 }
682 return Dim();
683}
684
685template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500686inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700687 switch (fmt & INPUT_3D_MASK)
688 {
689 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
690 return Dim(in.w/2, 0, in.w/2, in.h);
691 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
692 return Dim(0, 0, in.w/2, in.h);
693 case HAL_3D_IN_TOP_BOTTOM:
694 return Dim(0, in.h/2, in.w, in.h/2);
695 case HAL_3D_IN_INTERLEAVE:
696 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
697 break;
698 default:
699 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
700 break;
701 }
702 return Dim();
703}
704
705template <int CHAN>
706inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
707{
708 out = getCropS3DImpl<CHAN>(in, fmt);
709 return (out != Dim());
710}
711
712template <class Type>
713void swapWidthHeight(Type& width, Type& height) {
714 Type tmp = width;
715 width = height;
716 height = tmp;
717}
718
719inline void ScreenInfo::dump(const char* const s) const {
720 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
721 " bpp=%d stride=%d start/end ==",
722 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
723}
724
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700725inline bool openDev(OvFD& fd, int fbnum,
726 const char* const devpath, int flags) {
727 return overlay::open(fd, fbnum, devpath, flags);
728}
729
Saurabh Shahb121e142012-08-20 17:59:13 -0700730template <class T>
731inline void even_ceil(T& value) {
732 if(value & 1)
733 value++;
734}
735
736template <class T>
737inline void even_floor(T& value) {
738 if(value & 1)
739 value--;
740}
741
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500742inline const char* getDestStr(eDest dest) {
743 switch(dest) {
744 case OV_VG0: return "VG0";
745 case OV_RGB0: return "RGB0";
746 case OV_VG1: return "VG1";
747 case OV_RGB1: return "RGB1";
748 case OV_VG2: return "VG2";
749 case OV_RGB2: return "RGB2";
750 default: return "Invalid";
751 }
752 return "Invalid";
753}
754
755inline eMdpPipeType getPipeType(eDest dest) {
756 switch(dest) {
757 case OV_VG0:
758 case OV_VG1:
759 case OV_VG2:
760 return OV_MDP_PIPE_VG;
761 case OV_RGB0:
762 case OV_RGB1:
763 case OV_RGB2:
764 return OV_MDP_PIPE_RGB;
765 default:
766 return OV_MDP_PIPE_ANY;
767 }
768 return OV_MDP_PIPE_ANY;
769}
770
Naseer Ahmed29a26812012-06-14 00:56:20 -0700771} // namespace utils ends
772
773//--------------------Class Res stuff (namespace overlay only) -----------
774
775class Res {
776public:
777 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700778 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700779 // /dev/msm_rotator
780 static const char* const rotPath;
781 // /sys/class/graphics/fb1/format_3d
782 static const char* const format3DFile;
783 // /sys/class/graphics/fb1/3d_present
784 static const char* const edid3dInfoFile;
785 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
786 static const char* const barrierFile;
787};
788
789
790//--------------------Class OvFD stuff (namespace overlay only) -----------
791
Naseer Ahmed29a26812012-06-14 00:56:20 -0700792/*
793* Holds one FD
794* Dtor will NOT close the underlying FD.
795* That enables us to copy that object around
796* */
797class OvFD {
798public:
799 /* Ctor */
800 explicit OvFD();
801
802 /* dtor will NOT close the underlying FD */
803 ~OvFD();
804
805 /* Open fd using the path given by dev.
806 * return false in failure */
807 bool open(const char* const dev,
808 int flags = O_RDWR);
809
810 /* populate path */
811 void setPath(const char* const dev);
812
813 /* Close fd if we have a valid fd. */
814 bool close();
815
816 /* returns underlying fd.*/
817 int getFD() const;
818
819 /* returns true if fd is valid */
820 bool valid() const;
821
822 /* like operator= */
823 void copy(int fd);
824
825 /* dump the state of the instance */
826 void dump() const;
827private:
828 /* helper enum for determine valid/invalid fd */
829 enum { INVAL = -1 };
830
831 /* actual os fd */
832 int mFD;
833
834 /* path, for debugging */
835 char mPath[utils::MAX_PATH_LEN];
836};
837
838//-------------------Inlines--------------------------
839
840inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
841{
842 char dev_name[64] = {0};
843 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
844 return fd.open(dev_name, flags);
845}
846
847inline OvFD::OvFD() : mFD (INVAL) {
848 mPath[0] = 0;
849}
850
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700851inline OvFD::~OvFD() {
852 //no op since copy() can be used to share fd, in 3d cases.
853}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700854
855inline bool OvFD::open(const char* const dev, int flags)
856{
857 mFD = ::open(dev, flags, 0);
858 if (mFD < 0) {
859 // FIXME errno, strerror in bionic?
860 ALOGE("Cant open device %s err=%d", dev, errno);
861 return false;
862 }
863 setPath(dev);
864 return true;
865}
866
867inline void OvFD::setPath(const char* const dev)
868{
869 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
870}
871
872inline bool OvFD::close()
873{
874 int ret = 0;
875 if(valid()) {
876 ret = ::close(mFD);
877 mFD = INVAL;
878 }
879 return (ret == 0);
880}
881
882inline bool OvFD::valid() const
883{
884 return (mFD != INVAL);
885}
886
887inline int OvFD::getFD() const { return mFD; }
888
889inline void OvFD::copy(int fd) {
890 mFD = fd;
891}
892
893inline void OvFD::dump() const
894{
895 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
896 mFD, mPath);
897}
898
899//--------------- class OvFD stuff ends ---------------------
900
901} // overlay
902
903
904#endif // OVERLAY_UTILS_H