blob: 0459ea4d33c1c284d0dbde9bc4d3671c4f76b0c9 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -08002* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef OVERLAY_UTILS_H
31#define OVERLAY_UTILS_H
32
33#include <cutils/log.h> // ALOGE, etc
34#include <errno.h>
35#include <fcntl.h> // open, O_RDWR, etc
36#include <hardware/hardware.h>
37#include <hardware/gralloc.h> // buffer_handle_t
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038#include <linux/msm_mdp.h> // flags
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080039#include <linux/msm_rotator.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070048// Older platforms do not support Venus
49#ifndef VENUS_COLOR_FORMAT
50#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
51#endif
52
Naseer Ahmed29a26812012-06-14 00:56:20 -070053/*
54*
55* Collection of utilities functions/structs/enums etc...
56*
57* */
58
59// comment that out if you want to remove asserts
60// or put it as -D in Android.mk. your choice.
61#define OVERLAY_HAS_ASSERT
62
63#ifdef OVERLAY_HAS_ASSERT
64# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
65#else
66# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
67#endif // OVERLAY_HAS_ASSERT
68
69#define DEBUG_OVERLAY 0
70#define PROFILE_OVERLAY 0
71
Saurabh Shahcf053c62012-12-13 12:32:55 -080072#ifndef MDSS_MDP_RIGHT_MIXER
73#define MDSS_MDP_RIGHT_MIXER 0x100
74#endif
75
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080076#ifndef MDP_OV_PIPE_FORCE_DMA
77#define MDP_OV_PIPE_FORCE_DMA 0x4000
78#endif
79
Naseer Ahmed29a26812012-06-14 00:56:20 -070080namespace overlay {
81
82// fwd
83class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070084class OvFD;
85
86/* helper function to open by using fbnum */
87bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
88 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070089
90namespace utils {
91struct Whf;
92struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070093
94inline uint32_t setBit(uint32_t x, uint32_t mask) {
95 return (x | mask);
96}
97
98inline uint32_t clrBit(uint32_t x, uint32_t mask) {
99 return (x & ~mask);
100}
101
102/* Utility class to help avoid copying instances by making the copy ctor
103* and assignment operator private
104*
105* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107*/
108class NoCopy {
109protected:
110 NoCopy(){}
111 ~NoCopy() {}
112private:
113 NoCopy(const NoCopy&);
114 const NoCopy& operator=(const NoCopy&);
115};
116
117/*
118* Utility class to query the framebuffer info for primary display
119*
120* Usage:
121* Outside of functions:
122* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
123* Inside functions:
124* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
125*/
126class FrameBufferInfo {
127
128public:
129 /* ctor init */
130 explicit FrameBufferInfo();
131
132 /* Gets an instance if one does not already exist */
133 static FrameBufferInfo* getInstance();
134
135 /* Gets width of primary framebuffer */
136 int getWidth() const;
137
138 /* Gets height of primary framebuffer */
139 int getHeight() const;
140
Naseer Ahmed29a26812012-06-14 00:56:20 -0700141private:
142 int mFBWidth;
143 int mFBHeight;
144 bool mBorderFillSupported;
145 static FrameBufferInfo *sFBInfoInstance;
146};
147
148/* 3D related utils, defines etc...
149 * The compound format passed to the overlay is
150 * ABCCC where A is the input 3D format
151 * B is the output 3D format
152 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
153enum { SHIFT_OUT_3D = 12,
154 SHIFT_TOT_3D = 16 };
155enum { INPUT_3D_MASK = 0xFFFF0000,
156 OUTPUT_3D_MASK = 0x0000FFFF };
157enum { BARRIER_LAND = 1,
158 BARRIER_PORT = 2 };
159
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700160/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
161 * close all the pipes if it is opened after reboot.
162 */
163int initOverlay(void);
164
Naseer Ahmed29a26812012-06-14 00:56:20 -0700165inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700166inline uint32_t colorFormat(uint32_t fmt) {
167 /*TODO enable this block only if format has interlace / 3D info in top bits.
168 if(fmt & INTERLACE_MASK) {
169 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
170 }
171 fmt = fmt & 0xFFF;*/
172 return fmt;
173}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700174inline uint32_t format3DOutput(uint32_t x) {
175 return (x & 0xF000) >> SHIFT_OUT_3D; }
176inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
177uint32_t getColorFormat(uint32_t format);
178
179bool isHDMIConnected ();
180bool is3DTV();
181bool isPanel3D();
182bool usePanel3D();
183bool send3DInfoPacket (uint32_t fmt);
184bool enableBarrier (uint32_t orientation);
185uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800186bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189bool getPositionS3D(const Whf& whf, Dim& out);
190
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700192bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
193
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700195void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700196
197struct Dim {
198 Dim () : x(0), y(0),
199 w(0), h(0),
200 o(0) {}
201 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
202 x(_x), y(_y),
203 w(_w), h(_h) {}
204 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
205 x(_x), y(_y),
206 w(_w), h(_h),
207 o(_o) {}
208 bool check(uint32_t _w, uint32_t _h) const {
209 return (x+w <= _w && y+h <= _h);
210
211 }
212
213 bool operator==(const Dim& d) const {
214 return d.x == x && d.y == y &&
215 d.w == w && d.h == h &&
216 d.o == o;
217 }
218
219 bool operator!=(const Dim& d) const {
220 return !operator==(d);
221 }
222
Naseer Ahmed29a26812012-06-14 00:56:20 -0700223 void dump() const;
224 uint32_t x;
225 uint32_t y;
226 uint32_t w;
227 uint32_t h;
228 uint32_t o;
229};
230
231// TODO have Whfz
232
233struct Whf {
234 Whf() : w(0), h(0), format(0), size(0) {}
235 Whf(uint32_t wi, uint32_t he, uint32_t f) :
236 w(wi), h(he), format(f), size(0) {}
237 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
238 w(wi), h(he), format(f), size(s) {}
239 // FIXME not comparing size at the moment
240 bool operator==(const Whf& whf) const {
241 return whf.w == w && whf.h == h &&
242 whf.format == format;
243 }
244 bool operator!=(const Whf& whf) const {
245 return !operator==(whf);
246 }
247 void dump() const;
248 uint32_t w;
249 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700250 uint32_t format;
251 uint32_t size;
252};
253
254enum { MAX_PATH_LEN = 256 };
255
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256/**
257 * Rotator flags: not to be confused with orientation flags.
258 * Ususally, you want to open the rotator to make sure it is
259 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500260 * ROT_FLAG_DISABLED: Rotator not used unless required.
261 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700262 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800263 enum eRotFlags {
264 ROT_FLAGS_NONE = 0,
265 //Use rotator for 0 rotation. It is used anyway for others.
266 ROT_0_ENABLED = 1 << 0,
267 //Enable rotator downscale optimization for hardware bugs not handled in
268 //driver. If downscale optimizatation is required,
269 //then rotator will be used even if its 0 rotation case.
270 ROT_DOWNSCALE_ENABLED = 1 << 1,
271};
272
273enum eRotDownscale {
274 ROT_DS_NONE = 0,
275 ROT_DS_HALF = 1,
276 ROT_DS_FOURTH = 2,
277 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278};
279
Naseer Ahmed29a26812012-06-14 00:56:20 -0700280/* The values for is_fg flag for control alpha and transp
281 * IS_FG_OFF means is_fg = 0
282 * IS_FG_SET means is_fg = 1
283 */
284enum eIsFg {
285 IS_FG_OFF = 0,
286 IS_FG_SET = 1
287};
288
289/*
290 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
291 * kernel/common/linux/msm_mdp.h
292 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
293 * */
294enum eMdpFlags {
295 OV_MDP_FLAGS_NONE = 0,
296 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800297 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700298 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700299 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
300 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
301 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700302 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700303 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700304 OV_MDP_FLIP_H = MDP_FLIP_LR,
305 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800306 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700307};
308
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309enum eZorder {
310 ZORDER_0,
311 ZORDER_1,
312 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700314 Z_SYSTEM_ALLOC = 0xFFFF
315};
316
317enum eMdpPipeType {
318 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500319 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800320 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500321 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322};
323
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500324/* Used to identify destination pipes
325 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500327 OV_VG0 = 0,
328 OV_RGB0,
329 OV_VG1,
330 OV_RGB1,
331 OV_VG2,
332 OV_RGB2,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800333 OV_DMA0,
334 OV_DMA1,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500335 OV_INVALID,
336};
337
338/* Used when a buffer is split over 2 pipes and sent to display */
339enum {
340 OV_LEFT_SPLIT = 0,
341 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342};
343
344/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
345enum eTransform {
346 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700347 OVERLAY_TRANSFORM_0 = 0x0,
348 /* flip source image horizontally 0x1 */
349 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
350 /* flip source image vertically 0x2 */
351 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700352 /* rotate source image 180 degrees
353 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700354 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
355 /* rotate source image 90 degrees 0x4 */
356 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
357 /* rotate source image 90 degrees and flip horizontally 0x5 */
358 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
359 HAL_TRANSFORM_FLIP_H,
360 /* rotate source image 90 degrees and flip vertically 0x6 */
361 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
362 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363 /* rotate source image 270 degrees
364 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700365 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700366 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700367 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368};
369
370// Used to consolidate pipe params
371struct PipeArgs {
372 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 zorder(Z_SYSTEM_ALLOC),
374 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800375 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376 }
377
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700379 eZorder z, eIsFg fg, eRotFlags r) :
380 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700382 zorder(z),
383 isFg(fg),
384 rotFlags(r) {
385 }
386
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700387 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389 eZorder zorder; // stage number
390 eIsFg isFg; // control alpha & transp
391 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392};
393
Naseer Ahmed29a26812012-06-14 00:56:20 -0700394inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
395 f = static_cast<eMdpFlags>(setBit(f, v));
396}
397
398inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
399 f = static_cast<eMdpFlags>(clrBit(f, v));
400}
401
402// fb 0/1/2
403enum { FB0, FB1, FB2 };
404
405//Panels could be categorized as primary and external
406enum { PRIMARY, EXTERNAL };
407
Naseer Ahmed29a26812012-06-14 00:56:20 -0700408// 2 for rgb0/1 double bufs
409enum { RGB_PIPE_NUM_BUFS = 2 };
410
411struct ScreenInfo {
412 ScreenInfo() : mFBWidth(0),
413 mFBHeight(0),
414 mFBbpp(0),
415 mFBystride(0) {}
416 void dump(const char* const s) const;
417 uint32_t mFBWidth;
418 uint32_t mFBHeight;
419 uint32_t mFBbpp;
420 uint32_t mFBystride;
421};
422
423int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800424int getHALFormat(int mdpFormat);
425
Naseer Ahmed29a26812012-06-14 00:56:20 -0700426/* flip is upside down and such. V, H flip
427 * rotation is 90, 180 etc
428 * It returns MDP related enum/define that match rot+flip*/
429int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700430const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700431
Naseer Ahmed29a26812012-06-14 00:56:20 -0700432// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
433// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
434enum { HW_OV_MAGNIFICATION_LIMIT = 20,
435 HW_OV_MINIFICATION_LIMIT = 8
436};
437
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700439inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700440
441template <class T> inline void swap ( T& a, T& b )
442{
443 T c(a); a=b; b=c;
444}
445
446inline int alignup(int value, int a) {
447 //if align = 0, return the value. Else, do alignment.
448 return a ? ((((value - 1) / a) + 1) * a) : value;
449}
450
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800451inline int aligndown(int value, int a) {
452 //if align = 0, return the value. Else, do alignment.
453 return a ? ((value) & ~(a-1)) : value;
454}
455
Naseer Ahmed29a26812012-06-14 00:56:20 -0700456// FIXME that align should replace the upper one.
457inline int align(int value, int a) {
458 //if align = 0, return the value. Else, do alignment.
459 return a ? ((value + (a-1)) & ~(a-1)) : value;
460}
461
Naseer Ahmed29a26812012-06-14 00:56:20 -0700462enum eRotOutFmt {
463 ROT_OUT_FMT_DEFAULT,
464 ROT_OUT_FMT_Y_CRCB_H2V2
465};
466
467template <int ROT_OUT_FMT> struct RotOutFmt;
468
469// FIXME, taken from gralloc_priv.h. Need to
470// put it back as soon as overlay takes place of the old one
471/* possible formats for 3D content*/
472enum {
473 HAL_NO_3D = 0x0000,
474 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
475 HAL_3D_IN_TOP_BOTTOM = 0x20000,
476 HAL_3D_IN_INTERLEAVE = 0x40000,
477 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
478 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
479 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
480 HAL_3D_OUT_INTERLEAVE = 0x4000,
481 HAL_3D_OUT_MONOSCOPIC = 0x8000
482};
483
484enum { HAL_3D_OUT_SBS_MASK =
485 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
486 HAL_3D_OUT_TOP_BOT_MASK =
487 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
488 HAL_3D_OUT_INTERL_MASK =
489 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
490 HAL_3D_OUT_MONOS_MASK =
491 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
492};
493
494
495inline bool isYuv(uint32_t format) {
496 switch(format){
497 case MDP_Y_CBCR_H2V1:
498 case MDP_Y_CBCR_H2V2:
499 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700500 case MDP_Y_CRCB_H1V1:
501 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700502 case MDP_Y_CRCB_H2V2_TILE:
503 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700504 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700505 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700506 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700507 return true;
508 default:
509 return false;
510 }
511 return false;
512}
513
514inline bool isRgb(uint32_t format) {
515 switch(format) {
516 case MDP_RGBA_8888:
517 case MDP_BGRA_8888:
518 case MDP_RGBX_8888:
519 case MDP_RGB_565:
520 return true;
521 default:
522 return false;
523 }
524 return false;
525}
526
Saurabh Shah9c876d92012-08-25 19:29:53 -0700527inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700528 static const char* const formats[] = {
529 "MDP_RGB_565",
530 "MDP_XRGB_8888",
531 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700532 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700533 "MDP_ARGB_8888",
534 "MDP_RGB_888",
535 "MDP_Y_CRCB_H2V2",
536 "MDP_YCRYCB_H2V1",
537 "MDP_Y_CRCB_H2V1",
538 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700539 "MDP_Y_CRCB_H1V2",
540 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541 "MDP_RGBA_8888",
542 "MDP_BGRA_8888",
543 "MDP_RGBX_8888",
544 "MDP_Y_CRCB_H2V2_TILE",
545 "MDP_Y_CBCR_H2V2_TILE",
546 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700547 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700548 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700549 "MDP_Y_CRCB_H1V1",
550 "MDP_Y_CBCR_H1V1",
551 "MDP_YCRCB_H1V1",
552 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700553 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700554 "MDP_BGR_888",
555 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700556 "MDP_IMGTYPE_LIMIT",
557 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558 "MDP_FB_FORMAT",
559 "MDP_IMGTYPE_LIMIT2"
560 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700561 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
562 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
563 return "Unsupported format";
564 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700565 return formats[format];
566}
567
Naseer Ahmed29a26812012-06-14 00:56:20 -0700568inline void Whf::dump() const {
569 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
570 w, h, format, size);
571}
572
573inline void Dim::dump() const {
574 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
575}
576
577inline int getMdpOrient(eTransform rotation) {
578 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700579 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700580 {
581 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700582 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
583 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
584 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700585 //getMdpOrient will switch the flips if the source is 90 rotated.
586 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700587 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700588 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700589 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
590 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700591 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
592 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700593 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700594 ALOGE("%s: invalid rotation value (value = 0x%x",
595 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700596 }
597 return -1;
598}
599
Naseer Ahmed29a26812012-06-14 00:56:20 -0700600inline uint32_t getColorFormat(uint32_t format)
601{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700602 return (format == HAL_PIXEL_FORMAT_YV12) ?
603 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700604}
605
606// FB0
607template <int CHAN>
608inline Dim getPositionS3DImpl(const Whf& whf)
609{
610 switch (whf.format & OUTPUT_3D_MASK)
611 {
612 case HAL_3D_OUT_SBS_MASK:
613 // x, y, w, h
614 return Dim(0, 0, whf.w/2, whf.h);
615 case HAL_3D_OUT_TOP_BOT_MASK:
616 return Dim(0, 0, whf.w, whf.h/2);
617 case HAL_3D_OUT_MONOS_MASK:
618 return Dim();
619 case HAL_3D_OUT_INTERL_MASK:
620 // FIXME error?
621 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
622 return Dim();
623 default:
624 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
625 whf.format);
626 }
627 return Dim();
628}
629
630template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500631inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700632{
633 switch (whf.format & OUTPUT_3D_MASK)
634 {
635 case HAL_3D_OUT_SBS_MASK:
636 return Dim(whf.w/2, 0, whf.w/2, whf.h);
637 case HAL_3D_OUT_TOP_BOT_MASK:
638 return Dim(0, whf.h/2, whf.w, whf.h/2);
639 case HAL_3D_OUT_MONOS_MASK:
640 return Dim(0, 0, whf.w, whf.h);
641 case HAL_3D_OUT_INTERL_MASK:
642 // FIXME error?
643 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
644 return Dim();
645 default:
646 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
647 whf.format);
648 }
649 return Dim();
650}
651
652template <int CHAN>
653inline bool getPositionS3D(const Whf& whf, Dim& out) {
654 out = getPositionS3DImpl<CHAN>(whf);
655 return (out != Dim());
656}
657
658template <int CHAN>
659inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
660 switch (fmt & INPUT_3D_MASK)
661 {
662 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
663 return Dim(0, 0, in.w/2, in.h);
664 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
665 return Dim(in.w/2, 0, in.w/2, in.h);
666 case HAL_3D_IN_TOP_BOTTOM:
667 return Dim(0, 0, in.w, in.h/2);
668 case HAL_3D_IN_INTERLEAVE:
669 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
670 break;
671 default:
672 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
673 break;
674 }
675 return Dim();
676}
677
678template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500679inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700680 switch (fmt & INPUT_3D_MASK)
681 {
682 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
683 return Dim(in.w/2, 0, in.w/2, in.h);
684 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
685 return Dim(0, 0, in.w/2, in.h);
686 case HAL_3D_IN_TOP_BOTTOM:
687 return Dim(0, in.h/2, in.w, in.h/2);
688 case HAL_3D_IN_INTERLEAVE:
689 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
690 break;
691 default:
692 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
693 break;
694 }
695 return Dim();
696}
697
698template <int CHAN>
699inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
700{
701 out = getCropS3DImpl<CHAN>(in, fmt);
702 return (out != Dim());
703}
704
705template <class Type>
706void swapWidthHeight(Type& width, Type& height) {
707 Type tmp = width;
708 width = height;
709 height = tmp;
710}
711
712inline void ScreenInfo::dump(const char* const s) const {
713 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
714 " bpp=%d stride=%d start/end ==",
715 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
716}
717
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700718inline bool openDev(OvFD& fd, int fbnum,
719 const char* const devpath, int flags) {
720 return overlay::open(fd, fbnum, devpath, flags);
721}
722
Saurabh Shahb121e142012-08-20 17:59:13 -0700723template <class T>
724inline void even_ceil(T& value) {
725 if(value & 1)
726 value++;
727}
728
729template <class T>
730inline void even_floor(T& value) {
731 if(value & 1)
732 value--;
733}
734
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500735inline const char* getDestStr(eDest dest) {
736 switch(dest) {
737 case OV_VG0: return "VG0";
738 case OV_RGB0: return "RGB0";
739 case OV_VG1: return "VG1";
740 case OV_RGB1: return "RGB1";
741 case OV_VG2: return "VG2";
742 case OV_RGB2: return "RGB2";
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800743 case OV_DMA0: return "DMA0";
744 case OV_DMA1: return "DMA1";
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500745 default: return "Invalid";
746 }
747 return "Invalid";
748}
749
750inline eMdpPipeType getPipeType(eDest dest) {
751 switch(dest) {
752 case OV_VG0:
753 case OV_VG1:
754 case OV_VG2:
755 return OV_MDP_PIPE_VG;
756 case OV_RGB0:
757 case OV_RGB1:
758 case OV_RGB2:
759 return OV_MDP_PIPE_RGB;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800760 case OV_DMA0:
761 case OV_DMA1:
762 return OV_MDP_PIPE_DMA;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500763 default:
764 return OV_MDP_PIPE_ANY;
765 }
766 return OV_MDP_PIPE_ANY;
767}
768
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800769void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
770void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
771void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
772void getDump(char *buf, size_t len, const char *prefix,
773 const msmfb_overlay_data& ov);
774void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
775void getDump(char *buf, size_t len, const char *prefix,
776 const msm_rotator_img_info& ov);
777void getDump(char *buf, size_t len, const char *prefix,
778 const msm_rotator_data_info& ov);
779
Naseer Ahmed29a26812012-06-14 00:56:20 -0700780} // namespace utils ends
781
782//--------------------Class Res stuff (namespace overlay only) -----------
783
784class Res {
785public:
786 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700787 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700788 // /dev/msm_rotator
789 static const char* const rotPath;
790 // /sys/class/graphics/fb1/format_3d
791 static const char* const format3DFile;
792 // /sys/class/graphics/fb1/3d_present
793 static const char* const edid3dInfoFile;
794 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
795 static const char* const barrierFile;
796};
797
798
799//--------------------Class OvFD stuff (namespace overlay only) -----------
800
Naseer Ahmed29a26812012-06-14 00:56:20 -0700801/*
802* Holds one FD
803* Dtor will NOT close the underlying FD.
804* That enables us to copy that object around
805* */
806class OvFD {
807public:
808 /* Ctor */
809 explicit OvFD();
810
811 /* dtor will NOT close the underlying FD */
812 ~OvFD();
813
814 /* Open fd using the path given by dev.
815 * return false in failure */
816 bool open(const char* const dev,
817 int flags = O_RDWR);
818
819 /* populate path */
820 void setPath(const char* const dev);
821
822 /* Close fd if we have a valid fd. */
823 bool close();
824
825 /* returns underlying fd.*/
826 int getFD() const;
827
828 /* returns true if fd is valid */
829 bool valid() const;
830
831 /* like operator= */
832 void copy(int fd);
833
834 /* dump the state of the instance */
835 void dump() const;
836private:
837 /* helper enum for determine valid/invalid fd */
838 enum { INVAL = -1 };
839
840 /* actual os fd */
841 int mFD;
842
843 /* path, for debugging */
844 char mPath[utils::MAX_PATH_LEN];
845};
846
847//-------------------Inlines--------------------------
848
849inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
850{
851 char dev_name[64] = {0};
852 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
853 return fd.open(dev_name, flags);
854}
855
856inline OvFD::OvFD() : mFD (INVAL) {
857 mPath[0] = 0;
858}
859
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700860inline OvFD::~OvFD() {
861 //no op since copy() can be used to share fd, in 3d cases.
862}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700863
864inline bool OvFD::open(const char* const dev, int flags)
865{
866 mFD = ::open(dev, flags, 0);
867 if (mFD < 0) {
868 // FIXME errno, strerror in bionic?
869 ALOGE("Cant open device %s err=%d", dev, errno);
870 return false;
871 }
872 setPath(dev);
873 return true;
874}
875
876inline void OvFD::setPath(const char* const dev)
877{
878 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
879}
880
881inline bool OvFD::close()
882{
883 int ret = 0;
884 if(valid()) {
885 ret = ::close(mFD);
886 mFD = INVAL;
887 }
888 return (ret == 0);
889}
890
891inline bool OvFD::valid() const
892{
893 return (mFD != INVAL);
894}
895
896inline int OvFD::getFD() const { return mFD; }
897
898inline void OvFD::copy(int fd) {
899 mFD = fd;
900}
901
902inline void OvFD::dump() const
903{
904 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
905 mFD, mPath);
906}
907
908//--------------- class OvFD stuff ends ---------------------
909
910} // overlay
911
912
913#endif // OVERLAY_UTILS_H