blob: 28d2b673e9f28820bd961ac1523250a2ddc38b18 [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
Saurabh Shahcf053c62012-12-13 12:32:55 -080070#ifndef MDSS_MDP_RIGHT_MIXER
71#define MDSS_MDP_RIGHT_MIXER 0x100
72#endif
73
Naseer Ahmed29a26812012-06-14 00:56:20 -070074namespace overlay {
75
76// fwd
77class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070078class OvFD;
79
80/* helper function to open by using fbnum */
81bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
82 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070083
84namespace utils {
85struct Whf;
86struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070087
88inline uint32_t setBit(uint32_t x, uint32_t mask) {
89 return (x | mask);
90}
91
92inline uint32_t clrBit(uint32_t x, uint32_t mask) {
93 return (x & ~mask);
94}
95
96/* Utility class to help avoid copying instances by making the copy ctor
97* and assignment operator private
98*
99* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700100* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700101*/
102class NoCopy {
103protected:
104 NoCopy(){}
105 ~NoCopy() {}
106private:
107 NoCopy(const NoCopy&);
108 const NoCopy& operator=(const NoCopy&);
109};
110
111/*
112* Utility class to query the framebuffer info for primary display
113*
114* Usage:
115* Outside of functions:
116* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
117* Inside functions:
118* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
119*/
120class FrameBufferInfo {
121
122public:
123 /* ctor init */
124 explicit FrameBufferInfo();
125
126 /* Gets an instance if one does not already exist */
127 static FrameBufferInfo* getInstance();
128
129 /* Gets width of primary framebuffer */
130 int getWidth() const;
131
132 /* Gets height of primary framebuffer */
133 int getHeight() const;
134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135private:
136 int mFBWidth;
137 int mFBHeight;
138 bool mBorderFillSupported;
139 static FrameBufferInfo *sFBInfoInstance;
140};
141
142/* 3D related utils, defines etc...
143 * The compound format passed to the overlay is
144 * ABCCC where A is the input 3D format
145 * B is the output 3D format
146 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
147enum { SHIFT_OUT_3D = 12,
148 SHIFT_TOT_3D = 16 };
149enum { INPUT_3D_MASK = 0xFFFF0000,
150 OUTPUT_3D_MASK = 0x0000FFFF };
151enum { BARRIER_LAND = 1,
152 BARRIER_PORT = 2 };
153
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700154/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
155 * close all the pipes if it is opened after reboot.
156 */
157int initOverlay(void);
158
Naseer Ahmed29a26812012-06-14 00:56:20 -0700159inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700160inline uint32_t colorFormat(uint32_t fmt) {
161 /*TODO enable this block only if format has interlace / 3D info in top bits.
162 if(fmt & INTERLACE_MASK) {
163 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
164 }
165 fmt = fmt & 0xFFF;*/
166 return fmt;
167}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700168inline uint32_t format3DOutput(uint32_t x) {
169 return (x & 0xF000) >> SHIFT_OUT_3D; }
170inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
171uint32_t getColorFormat(uint32_t format);
172
173bool isHDMIConnected ();
174bool is3DTV();
175bool isPanel3D();
176bool usePanel3D();
177bool send3DInfoPacket (uint32_t fmt);
178bool enableBarrier (uint32_t orientation);
179uint32_t getS3DFormat(uint32_t fmt);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700180
Naseer Ahmed29a26812012-06-14 00:56:20 -0700181template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182bool getPositionS3D(const Whf& whf, Dim& out);
183
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
186
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189
190struct Dim {
191 Dim () : x(0), y(0),
192 w(0), h(0),
193 o(0) {}
194 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
195 x(_x), y(_y),
196 w(_w), h(_h) {}
197 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
198 x(_x), y(_y),
199 w(_w), h(_h),
200 o(_o) {}
201 bool check(uint32_t _w, uint32_t _h) const {
202 return (x+w <= _w && y+h <= _h);
203
204 }
205
206 bool operator==(const Dim& d) const {
207 return d.x == x && d.y == y &&
208 d.w == w && d.h == h &&
209 d.o == o;
210 }
211
212 bool operator!=(const Dim& d) const {
213 return !operator==(d);
214 }
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216 void dump() const;
217 uint32_t x;
218 uint32_t y;
219 uint32_t w;
220 uint32_t h;
221 uint32_t o;
222};
223
224// TODO have Whfz
225
226struct Whf {
227 Whf() : w(0), h(0), format(0), size(0) {}
228 Whf(uint32_t wi, uint32_t he, uint32_t f) :
229 w(wi), h(he), format(f), size(0) {}
230 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
231 w(wi), h(he), format(f), size(s) {}
232 // FIXME not comparing size at the moment
233 bool operator==(const Whf& whf) const {
234 return whf.w == w && whf.h == h &&
235 whf.format == format;
236 }
237 bool operator!=(const Whf& whf) const {
238 return !operator==(whf);
239 }
240 void dump() const;
241 uint32_t w;
242 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700243 uint32_t format;
244 uint32_t size;
245};
246
Saurabh Shah56f610d2012-08-07 15:27:06 -0700247class ActionSafe {
248private:
249 ActionSafe() : mWidth(0.0f), mHeight(0.0f) { };
250 float mWidth;
251 float mHeight;
252 static ActionSafe *sActionSafe;
253public:
254 ~ActionSafe() { };
255 static ActionSafe* getInstance() {
256 if(!sActionSafe) {
257 sActionSafe = new ActionSafe();
258 }
259 return sActionSafe;
260 }
261 void setDimension(int w, int h) {
262 mWidth = (float)w;
263 mHeight = (float)h;
264 }
265 float getWidth() { return mWidth; }
266 float getHeight() { return mHeight; }
267};
268
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269enum { MAX_PATH_LEN = 256 };
270
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271/**
272 * Rotator flags: not to be confused with orientation flags.
273 * Ususally, you want to open the rotator to make sure it is
274 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500275 * ROT_FLAG_DISABLED: Rotator not used unless required.
276 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700277 * */
278enum eRotFlags {
279 ROT_FLAG_DISABLED = 0,
280 ROT_FLAG_ENABLED = 1 // needed in rot
281};
282
Naseer Ahmed29a26812012-06-14 00:56:20 -0700283/* The values for is_fg flag for control alpha and transp
284 * IS_FG_OFF means is_fg = 0
285 * IS_FG_SET means is_fg = 1
286 */
287enum eIsFg {
288 IS_FG_OFF = 0,
289 IS_FG_SET = 1
290};
291
292/*
293 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
294 * kernel/common/linux/msm_mdp.h
295 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
296 * */
297enum eMdpFlags {
298 OV_MDP_FLAGS_NONE = 0,
299 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
300 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700301 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
302 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
303 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700304 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700305 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700306 OV_MDP_FLIP_H = MDP_FLIP_LR,
307 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800308 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309};
310
Naseer Ahmed29a26812012-06-14 00:56:20 -0700311enum eZorder {
312 ZORDER_0,
313 ZORDER_1,
314 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500315 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316 Z_SYSTEM_ALLOC = 0xFFFF
317};
318
319enum eMdpPipeType {
320 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500321 OV_MDP_PIPE_VG,
322 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323};
324
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500325/* Used to identify destination pipes
326 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700327enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500328 OV_VG0 = 0,
329 OV_RGB0,
330 OV_VG1,
331 OV_RGB1,
332 OV_VG2,
333 OV_RGB2,
334 OV_INVALID,
335};
336
337/* Used when a buffer is split over 2 pipes and sent to display */
338enum {
339 OV_LEFT_SPLIT = 0,
340 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341};
342
343/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
344enum eTransform {
345 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700346 OVERLAY_TRANSFORM_0 = 0x0,
347 /* flip source image horizontally 0x1 */
348 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
349 /* flip source image vertically 0x2 */
350 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351 /* rotate source image 180 degrees
352 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700353 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
354 /* rotate source image 90 degrees 0x4 */
355 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
356 /* rotate source image 90 degrees and flip horizontally 0x5 */
357 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
358 HAL_TRANSFORM_FLIP_H,
359 /* rotate source image 90 degrees and flip vertically 0x6 */
360 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
361 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700362 /* rotate source image 270 degrees
363 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700364 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700366 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367};
368
369// Used to consolidate pipe params
370struct PipeArgs {
371 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372 zorder(Z_SYSTEM_ALLOC),
373 isFg(IS_FG_OFF),
374 rotFlags(ROT_FLAG_DISABLED){
375 }
376
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700377 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378 eZorder z, eIsFg fg, eRotFlags r) :
379 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 zorder(z),
382 isFg(fg),
383 rotFlags(r) {
384 }
385
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700386 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 eZorder zorder; // stage number
389 eIsFg isFg; // control alpha & transp
390 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700391};
392
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393inline 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
Naseer Ahmed29a26812012-06-14 00:56:20 -0700407// 2 for rgb0/1 double bufs
408enum { RGB_PIPE_NUM_BUFS = 2 };
409
410struct ScreenInfo {
411 ScreenInfo() : mFBWidth(0),
412 mFBHeight(0),
413 mFBbpp(0),
414 mFBystride(0) {}
415 void dump(const char* const s) const;
416 uint32_t mFBWidth;
417 uint32_t mFBHeight;
418 uint32_t mFBbpp;
419 uint32_t mFBystride;
420};
421
422int getMdpFormat(int format);
423int getRotOutFmt(uint32_t format);
424/* flip is upside down and such. V, H flip
425 * rotation is 90, 180 etc
426 * It returns MDP related enum/define that match rot+flip*/
427int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700428const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700429
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
431// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
432enum { HW_OV_MAGNIFICATION_LIMIT = 20,
433 HW_OV_MINIFICATION_LIMIT = 8
434};
435
Naseer Ahmed29a26812012-06-14 00:56:20 -0700436template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700437inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438
439template <class T> inline void swap ( T& a, T& b )
440{
441 T c(a); a=b; b=c;
442}
443
444inline int alignup(int value, int a) {
445 //if align = 0, return the value. Else, do alignment.
446 return a ? ((((value - 1) / a) + 1) * a) : value;
447}
448
449// FIXME that align should replace the upper one.
450inline int align(int value, int a) {
451 //if align = 0, return the value. Else, do alignment.
452 return a ? ((value + (a-1)) & ~(a-1)) : value;
453}
454
Naseer Ahmed29a26812012-06-14 00:56:20 -0700455enum eRotOutFmt {
456 ROT_OUT_FMT_DEFAULT,
457 ROT_OUT_FMT_Y_CRCB_H2V2
458};
459
460template <int ROT_OUT_FMT> struct RotOutFmt;
461
462// FIXME, taken from gralloc_priv.h. Need to
463// put it back as soon as overlay takes place of the old one
464/* possible formats for 3D content*/
465enum {
466 HAL_NO_3D = 0x0000,
467 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
468 HAL_3D_IN_TOP_BOTTOM = 0x20000,
469 HAL_3D_IN_INTERLEAVE = 0x40000,
470 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
471 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
472 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
473 HAL_3D_OUT_INTERLEAVE = 0x4000,
474 HAL_3D_OUT_MONOSCOPIC = 0x8000
475};
476
477enum { HAL_3D_OUT_SBS_MASK =
478 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
479 HAL_3D_OUT_TOP_BOT_MASK =
480 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
481 HAL_3D_OUT_INTERL_MASK =
482 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
483 HAL_3D_OUT_MONOS_MASK =
484 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
485};
486
487
488inline bool isYuv(uint32_t format) {
489 switch(format){
490 case MDP_Y_CBCR_H2V1:
491 case MDP_Y_CBCR_H2V2:
492 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700493 case MDP_Y_CRCB_H1V1:
494 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495 case MDP_Y_CRCB_H2V2_TILE:
496 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700497 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700498 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700499 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700500 return true;
501 default:
502 return false;
503 }
504 return false;
505}
506
507inline bool isRgb(uint32_t format) {
508 switch(format) {
509 case MDP_RGBA_8888:
510 case MDP_BGRA_8888:
511 case MDP_RGBX_8888:
512 case MDP_RGB_565:
513 return true;
514 default:
515 return false;
516 }
517 return false;
518}
519
Saurabh Shah9c876d92012-08-25 19:29:53 -0700520inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700521 static const char* const formats[] = {
522 "MDP_RGB_565",
523 "MDP_XRGB_8888",
524 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700525 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700526 "MDP_ARGB_8888",
527 "MDP_RGB_888",
528 "MDP_Y_CRCB_H2V2",
529 "MDP_YCRYCB_H2V1",
530 "MDP_Y_CRCB_H2V1",
531 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700532 "MDP_Y_CRCB_H1V2",
533 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700534 "MDP_RGBA_8888",
535 "MDP_BGRA_8888",
536 "MDP_RGBX_8888",
537 "MDP_Y_CRCB_H2V2_TILE",
538 "MDP_Y_CBCR_H2V2_TILE",
539 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700540 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700542 "MDP_Y_CRCB_H1V1",
543 "MDP_Y_CBCR_H1V1",
544 "MDP_YCRCB_H1V1",
545 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700546 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700547 "MDP_BGR_888",
548 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700549 "MDP_IMGTYPE_LIMIT",
550 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700551 "MDP_FB_FORMAT",
552 "MDP_IMGTYPE_LIMIT2"
553 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700554 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
555 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
556 return "Unsupported format";
557 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558 return formats[format];
559}
560
Naseer Ahmed29a26812012-06-14 00:56:20 -0700561inline void Whf::dump() const {
562 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
563 w, h, format, size);
564}
565
566inline void Dim::dump() const {
567 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
568}
569
570inline int getMdpOrient(eTransform rotation) {
571 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700572 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700573 {
574 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700575 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
576 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
577 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700578 //getMdpOrient will switch the flips if the source is 90 rotated.
579 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700580 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700581 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700582 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
583 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700584 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
585 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700586 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700587 ALOGE("%s: invalid rotation value (value = 0x%x",
588 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700589 }
590 return -1;
591}
592
593inline int getRotOutFmt(uint32_t format) {
594 switch (format) {
595 case MDP_Y_CRCB_H2V2_TILE:
596 return MDP_Y_CRCB_H2V2;
597 case MDP_Y_CBCR_H2V2_TILE:
598 return MDP_Y_CBCR_H2V2;
599 case MDP_Y_CB_CR_H2V2:
600 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700601 case MDP_Y_CR_CB_GH2V2:
602 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700603 default:
604 return format;
605 }
606 // not reached
607 OVASSERT(false, "%s not reached", __FUNCTION__);
608 return -1;
609}
610
Naseer Ahmed29a26812012-06-14 00:56:20 -0700611
612inline uint32_t getColorFormat(uint32_t format)
613{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700614 return (format == HAL_PIXEL_FORMAT_YV12) ?
615 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700616}
617
618// FB0
619template <int CHAN>
620inline Dim getPositionS3DImpl(const Whf& whf)
621{
622 switch (whf.format & OUTPUT_3D_MASK)
623 {
624 case HAL_3D_OUT_SBS_MASK:
625 // x, y, w, h
626 return Dim(0, 0, whf.w/2, whf.h);
627 case HAL_3D_OUT_TOP_BOT_MASK:
628 return Dim(0, 0, whf.w, whf.h/2);
629 case HAL_3D_OUT_MONOS_MASK:
630 return Dim();
631 case HAL_3D_OUT_INTERL_MASK:
632 // FIXME error?
633 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
634 return Dim();
635 default:
636 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
637 whf.format);
638 }
639 return Dim();
640}
641
642template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500643inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700644{
645 switch (whf.format & OUTPUT_3D_MASK)
646 {
647 case HAL_3D_OUT_SBS_MASK:
648 return Dim(whf.w/2, 0, whf.w/2, whf.h);
649 case HAL_3D_OUT_TOP_BOT_MASK:
650 return Dim(0, whf.h/2, whf.w, whf.h/2);
651 case HAL_3D_OUT_MONOS_MASK:
652 return Dim(0, 0, whf.w, whf.h);
653 case HAL_3D_OUT_INTERL_MASK:
654 // FIXME error?
655 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
656 return Dim();
657 default:
658 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
659 whf.format);
660 }
661 return Dim();
662}
663
664template <int CHAN>
665inline bool getPositionS3D(const Whf& whf, Dim& out) {
666 out = getPositionS3DImpl<CHAN>(whf);
667 return (out != Dim());
668}
669
670template <int CHAN>
671inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
672 switch (fmt & INPUT_3D_MASK)
673 {
674 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
675 return Dim(0, 0, in.w/2, in.h);
676 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
677 return Dim(in.w/2, 0, in.w/2, in.h);
678 case HAL_3D_IN_TOP_BOTTOM:
679 return Dim(0, 0, in.w, in.h/2);
680 case HAL_3D_IN_INTERLEAVE:
681 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
682 break;
683 default:
684 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
685 break;
686 }
687 return Dim();
688}
689
690template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500691inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700692 switch (fmt & INPUT_3D_MASK)
693 {
694 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
695 return Dim(in.w/2, 0, in.w/2, in.h);
696 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
697 return Dim(0, 0, in.w/2, in.h);
698 case HAL_3D_IN_TOP_BOTTOM:
699 return Dim(0, in.h/2, in.w, in.h/2);
700 case HAL_3D_IN_INTERLEAVE:
701 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
702 break;
703 default:
704 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
705 break;
706 }
707 return Dim();
708}
709
710template <int CHAN>
711inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
712{
713 out = getCropS3DImpl<CHAN>(in, fmt);
714 return (out != Dim());
715}
716
717template <class Type>
718void swapWidthHeight(Type& width, Type& height) {
719 Type tmp = width;
720 width = height;
721 height = tmp;
722}
723
724inline void ScreenInfo::dump(const char* const s) const {
725 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
726 " bpp=%d stride=%d start/end ==",
727 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
728}
729
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700730inline bool openDev(OvFD& fd, int fbnum,
731 const char* const devpath, int flags) {
732 return overlay::open(fd, fbnum, devpath, flags);
733}
734
Saurabh Shahb121e142012-08-20 17:59:13 -0700735template <class T>
736inline void even_ceil(T& value) {
737 if(value & 1)
738 value++;
739}
740
741template <class T>
742inline void even_floor(T& value) {
743 if(value & 1)
744 value--;
745}
746
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500747inline const char* getDestStr(eDest dest) {
748 switch(dest) {
749 case OV_VG0: return "VG0";
750 case OV_RGB0: return "RGB0";
751 case OV_VG1: return "VG1";
752 case OV_RGB1: return "RGB1";
753 case OV_VG2: return "VG2";
754 case OV_RGB2: return "RGB2";
755 default: return "Invalid";
756 }
757 return "Invalid";
758}
759
760inline eMdpPipeType getPipeType(eDest dest) {
761 switch(dest) {
762 case OV_VG0:
763 case OV_VG1:
764 case OV_VG2:
765 return OV_MDP_PIPE_VG;
766 case OV_RGB0:
767 case OV_RGB1:
768 case OV_RGB2:
769 return OV_MDP_PIPE_RGB;
770 default:
771 return OV_MDP_PIPE_ANY;
772 }
773 return OV_MDP_PIPE_ANY;
774}
775
Naseer Ahmed29a26812012-06-14 00:56:20 -0700776} // namespace utils ends
777
778//--------------------Class Res stuff (namespace overlay only) -----------
779
780class Res {
781public:
782 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700783 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700784 // /dev/msm_rotator
785 static const char* const rotPath;
786 // /sys/class/graphics/fb1/format_3d
787 static const char* const format3DFile;
788 // /sys/class/graphics/fb1/3d_present
789 static const char* const edid3dInfoFile;
790 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
791 static const char* const barrierFile;
792};
793
794
795//--------------------Class OvFD stuff (namespace overlay only) -----------
796
Naseer Ahmed29a26812012-06-14 00:56:20 -0700797/*
798* Holds one FD
799* Dtor will NOT close the underlying FD.
800* That enables us to copy that object around
801* */
802class OvFD {
803public:
804 /* Ctor */
805 explicit OvFD();
806
807 /* dtor will NOT close the underlying FD */
808 ~OvFD();
809
810 /* Open fd using the path given by dev.
811 * return false in failure */
812 bool open(const char* const dev,
813 int flags = O_RDWR);
814
815 /* populate path */
816 void setPath(const char* const dev);
817
818 /* Close fd if we have a valid fd. */
819 bool close();
820
821 /* returns underlying fd.*/
822 int getFD() const;
823
824 /* returns true if fd is valid */
825 bool valid() const;
826
827 /* like operator= */
828 void copy(int fd);
829
830 /* dump the state of the instance */
831 void dump() const;
832private:
833 /* helper enum for determine valid/invalid fd */
834 enum { INVAL = -1 };
835
836 /* actual os fd */
837 int mFD;
838
839 /* path, for debugging */
840 char mPath[utils::MAX_PATH_LEN];
841};
842
843//-------------------Inlines--------------------------
844
845inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
846{
847 char dev_name[64] = {0};
848 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
849 return fd.open(dev_name, flags);
850}
851
852inline OvFD::OvFD() : mFD (INVAL) {
853 mPath[0] = 0;
854}
855
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700856inline OvFD::~OvFD() {
857 //no op since copy() can be used to share fd, in 3d cases.
858}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700859
860inline bool OvFD::open(const char* const dev, int flags)
861{
862 mFD = ::open(dev, flags, 0);
863 if (mFD < 0) {
864 // FIXME errno, strerror in bionic?
865 ALOGE("Cant open device %s err=%d", dev, errno);
866 return false;
867 }
868 setPath(dev);
869 return true;
870}
871
872inline void OvFD::setPath(const char* const dev)
873{
874 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
875}
876
877inline bool OvFD::close()
878{
879 int ret = 0;
880 if(valid()) {
881 ret = ::close(mFD);
882 mFD = INVAL;
883 }
884 return (ret == 0);
885}
886
887inline bool OvFD::valid() const
888{
889 return (mFD != INVAL);
890}
891
892inline int OvFD::getFD() const { return mFD; }
893
894inline void OvFD::copy(int fd) {
895 mFD = fd;
896}
897
898inline void OvFD::dump() const
899{
900 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
901 mFD, mPath);
902}
903
904//--------------- class OvFD stuff ends ---------------------
905
906} // overlay
907
908
909#endif // OVERLAY_UTILS_H