blob: 2f833740b50d721497a7fd67079db0936286900f [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -08002* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef OVERLAY_UTILS_H
31#define OVERLAY_UTILS_H
32
33#include <cutils/log.h> // ALOGE, etc
34#include <errno.h>
35#include <fcntl.h> // open, O_RDWR, etc
36#include <hardware/hardware.h>
37#include <hardware/gralloc.h> // buffer_handle_t
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038#include <linux/msm_mdp.h> // flags
Naseer Ahmed29a26812012-06-14 00:56:20 -070039#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -080047// Older platforms do not support Venus.
48#ifndef VENUS_COLOR_FORMAT
Sushil Chauhanc5e61482012-08-22 17:13:32 -070049#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
50#endif
51
Naseer Ahmed29a26812012-06-14 00:56:20 -070052/*
53*
54* Collection of utilities functions/structs/enums etc...
55*
56* */
57
58// comment that out if you want to remove asserts
59// or put it as -D in Android.mk. your choice.
60#define OVERLAY_HAS_ASSERT
61
62#ifdef OVERLAY_HAS_ASSERT
63# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
64#else
65# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
66#endif // OVERLAY_HAS_ASSERT
67
68#define DEBUG_OVERLAY 0
69#define PROFILE_OVERLAY 0
70
Saurabh Shahcf053c62012-12-13 12:32:55 -080071#ifndef MDSS_MDP_RIGHT_MIXER
72#define MDSS_MDP_RIGHT_MIXER 0x100
73#endif
74
Naseer Ahmed29a26812012-06-14 00:56:20 -070075namespace overlay {
76
77// fwd
78class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070079class OvFD;
80
81/* helper function to open by using fbnum */
82bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
83 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084
85namespace utils {
86struct Whf;
87struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088
89inline uint32_t setBit(uint32_t x, uint32_t mask) {
90 return (x | mask);
91}
92
93inline uint32_t clrBit(uint32_t x, uint32_t mask) {
94 return (x & ~mask);
95}
96
97/* Utility class to help avoid copying instances by making the copy ctor
98* and assignment operator private
99*
100* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102*/
103class NoCopy {
104protected:
105 NoCopy(){}
106 ~NoCopy() {}
107private:
108 NoCopy(const NoCopy&);
109 const NoCopy& operator=(const NoCopy&);
110};
111
112/*
113* Utility class to query the framebuffer info for primary display
114*
115* Usage:
116* Outside of functions:
117* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
118* Inside functions:
119* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
120*/
121class FrameBufferInfo {
122
123public:
124 /* ctor init */
125 explicit FrameBufferInfo();
126
127 /* Gets an instance if one does not already exist */
128 static FrameBufferInfo* getInstance();
129
130 /* Gets width of primary framebuffer */
131 int getWidth() const;
132
133 /* Gets height of primary framebuffer */
134 int getHeight() const;
135
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136private:
137 int mFBWidth;
138 int mFBHeight;
139 bool mBorderFillSupported;
140 static FrameBufferInfo *sFBInfoInstance;
141};
142
143/* 3D related utils, defines etc...
144 * The compound format passed to the overlay is
145 * ABCCC where A is the input 3D format
146 * B is the output 3D format
147 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
148enum { SHIFT_OUT_3D = 12,
149 SHIFT_TOT_3D = 16 };
150enum { INPUT_3D_MASK = 0xFFFF0000,
151 OUTPUT_3D_MASK = 0x0000FFFF };
152enum { BARRIER_LAND = 1,
153 BARRIER_PORT = 2 };
154
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700155/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
156 * close all the pipes if it is opened after reboot.
157 */
158int initOverlay(void);
159
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161inline uint32_t colorFormat(uint32_t fmt) {
162 /*TODO enable this block only if format has interlace / 3D info in top bits.
163 if(fmt & INTERLACE_MASK) {
164 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
165 }
166 fmt = fmt & 0xFFF;*/
167 return fmt;
168}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169inline uint32_t format3DOutput(uint32_t x) {
170 return (x & 0xF000) >> SHIFT_OUT_3D; }
171inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
172uint32_t getColorFormat(uint32_t format);
173
174bool isHDMIConnected ();
175bool is3DTV();
176bool isPanel3D();
177bool usePanel3D();
178bool send3DInfoPacket (uint32_t fmt);
179bool enableBarrier (uint32_t orientation);
180uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800181bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184bool getPositionS3D(const Whf& whf, Dim& out);
185
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
188
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191
192struct Dim {
193 Dim () : x(0), y(0),
194 w(0), h(0),
195 o(0) {}
196 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
197 x(_x), y(_y),
198 w(_w), h(_h) {}
199 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
200 x(_x), y(_y),
201 w(_w), h(_h),
202 o(_o) {}
203 bool check(uint32_t _w, uint32_t _h) const {
204 return (x+w <= _w && y+h <= _h);
205
206 }
207
208 bool operator==(const Dim& d) const {
209 return d.x == x && d.y == y &&
210 d.w == w && d.h == h &&
211 d.o == o;
212 }
213
214 bool operator!=(const Dim& d) const {
215 return !operator==(d);
216 }
217
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 void dump() const;
219 uint32_t x;
220 uint32_t y;
221 uint32_t w;
222 uint32_t h;
223 uint32_t o;
224};
225
226// TODO have Whfz
227
228struct Whf {
229 Whf() : w(0), h(0), format(0), size(0) {}
230 Whf(uint32_t wi, uint32_t he, uint32_t f) :
231 w(wi), h(he), format(f), size(0) {}
232 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
233 w(wi), h(he), format(f), size(s) {}
234 // FIXME not comparing size at the moment
235 bool operator==(const Whf& whf) const {
236 return whf.w == w && whf.h == h &&
237 whf.format == format;
238 }
239 bool operator!=(const Whf& whf) const {
240 return !operator==(whf);
241 }
242 void dump() const;
243 uint32_t w;
244 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245 uint32_t format;
246 uint32_t size;
247};
248
249enum { MAX_PATH_LEN = 256 };
250
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251/**
252 * Rotator flags: not to be confused with orientation flags.
253 * Ususally, you want to open the rotator to make sure it is
254 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255 * ROT_FLAG_DISABLED: Rotator not used unless required.
256 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800258 enum eRotFlags {
259 ROT_FLAGS_NONE = 0,
260 //Use rotator for 0 rotation. It is used anyway for others.
261 ROT_0_ENABLED = 1 << 0,
262 //Enable rotator downscale optimization for hardware bugs not handled in
263 //driver. If downscale optimizatation is required,
264 //then rotator will be used even if its 0 rotation case.
265 ROT_DOWNSCALE_ENABLED = 1 << 1,
266};
267
268enum eRotDownscale {
269 ROT_DS_NONE = 0,
270 ROT_DS_HALF = 1,
271 ROT_DS_FOURTH = 2,
272 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273};
274
Naseer Ahmed29a26812012-06-14 00:56:20 -0700275/* The values for is_fg flag for control alpha and transp
276 * IS_FG_OFF means is_fg = 0
277 * IS_FG_SET means is_fg = 1
278 */
279enum eIsFg {
280 IS_FG_OFF = 0,
281 IS_FG_SET = 1
282};
283
284/*
285 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
286 * kernel/common/linux/msm_mdp.h
287 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
288 * */
289enum eMdpFlags {
290 OV_MDP_FLAGS_NONE = 0,
291 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
292 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700293 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
294 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
295 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700296 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700297 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700298 OV_MDP_FLIP_H = MDP_FLIP_LR,
299 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800300 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700301};
302
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303enum eZorder {
304 ZORDER_0,
305 ZORDER_1,
306 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500307 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700308 Z_SYSTEM_ALLOC = 0xFFFF
309};
310
311enum eMdpPipeType {
312 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500313 OV_MDP_PIPE_VG,
314 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700315};
316
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500317/* Used to identify destination pipes
318 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700319enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500320 OV_VG0 = 0,
321 OV_RGB0,
322 OV_VG1,
323 OV_RGB1,
324 OV_VG2,
325 OV_RGB2,
326 OV_INVALID,
327};
328
329/* Used when a buffer is split over 2 pipes and sent to display */
330enum {
331 OV_LEFT_SPLIT = 0,
332 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700333};
334
335/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
336enum eTransform {
337 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700338 OVERLAY_TRANSFORM_0 = 0x0,
339 /* flip source image horizontally 0x1 */
340 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
341 /* flip source image vertically 0x2 */
342 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343 /* rotate source image 180 degrees
344 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700345 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
346 /* rotate source image 90 degrees 0x4 */
347 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
348 /* rotate source image 90 degrees and flip horizontally 0x5 */
349 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
350 HAL_TRANSFORM_FLIP_H,
351 /* rotate source image 90 degrees and flip vertically 0x6 */
352 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
353 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354 /* rotate source image 270 degrees
355 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700356 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700357 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700358 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700359};
360
361// Used to consolidate pipe params
362struct PipeArgs {
363 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364 zorder(Z_SYSTEM_ALLOC),
365 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800366 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367 }
368
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700369 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700370 eZorder z, eIsFg fg, eRotFlags r) :
371 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700372 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 zorder(z),
374 isFg(fg),
375 rotFlags(r) {
376 }
377
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700378 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700379 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 eZorder zorder; // stage number
381 eIsFg isFg; // control alpha & transp
382 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700383};
384
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
386 f = static_cast<eMdpFlags>(setBit(f, v));
387}
388
389inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
390 f = static_cast<eMdpFlags>(clrBit(f, v));
391}
392
393// fb 0/1/2
394enum { FB0, FB1, FB2 };
395
396//Panels could be categorized as primary and external
397enum { PRIMARY, EXTERNAL };
398
Naseer Ahmed29a26812012-06-14 00:56:20 -0700399// 2 for rgb0/1 double bufs
400enum { RGB_PIPE_NUM_BUFS = 2 };
401
402struct ScreenInfo {
403 ScreenInfo() : mFBWidth(0),
404 mFBHeight(0),
405 mFBbpp(0),
406 mFBystride(0) {}
407 void dump(const char* const s) const;
408 uint32_t mFBWidth;
409 uint32_t mFBHeight;
410 uint32_t mFBbpp;
411 uint32_t mFBystride;
412};
413
414int getMdpFormat(int format);
415int getRotOutFmt(uint32_t format);
416/* flip is upside down and such. V, H flip
417 * rotation is 90, 180 etc
418 * It returns MDP related enum/define that match rot+flip*/
419int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700420const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421
Naseer Ahmed29a26812012-06-14 00:56:20 -0700422// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
423// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
424enum { HW_OV_MAGNIFICATION_LIMIT = 20,
425 HW_OV_MINIFICATION_LIMIT = 8
426};
427
Naseer Ahmed29a26812012-06-14 00:56:20 -0700428template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700429inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430
431template <class T> inline void swap ( T& a, T& b )
432{
433 T c(a); a=b; b=c;
434}
435
436inline int alignup(int value, int a) {
437 //if align = 0, return the value. Else, do alignment.
438 return a ? ((((value - 1) / a) + 1) * a) : value;
439}
440
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800441inline int aligndown(int value, int a) {
442 //if align = 0, return the value. Else, do alignment.
443 return a ? ((value) & ~(a-1)) : value;
444}
445
Naseer Ahmed29a26812012-06-14 00:56:20 -0700446// FIXME that align should replace the upper one.
447inline int align(int value, int a) {
448 //if align = 0, return the value. Else, do alignment.
449 return a ? ((value + (a-1)) & ~(a-1)) : value;
450}
451
Naseer Ahmed29a26812012-06-14 00:56:20 -0700452enum eRotOutFmt {
453 ROT_OUT_FMT_DEFAULT,
454 ROT_OUT_FMT_Y_CRCB_H2V2
455};
456
457template <int ROT_OUT_FMT> struct RotOutFmt;
458
459// FIXME, taken from gralloc_priv.h. Need to
460// put it back as soon as overlay takes place of the old one
461/* possible formats for 3D content*/
462enum {
463 HAL_NO_3D = 0x0000,
464 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
465 HAL_3D_IN_TOP_BOTTOM = 0x20000,
466 HAL_3D_IN_INTERLEAVE = 0x40000,
467 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
468 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
469 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
470 HAL_3D_OUT_INTERLEAVE = 0x4000,
471 HAL_3D_OUT_MONOSCOPIC = 0x8000
472};
473
474enum { HAL_3D_OUT_SBS_MASK =
475 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
476 HAL_3D_OUT_TOP_BOT_MASK =
477 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
478 HAL_3D_OUT_INTERL_MASK =
479 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
480 HAL_3D_OUT_MONOS_MASK =
481 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
482};
483
484
485inline bool isYuv(uint32_t format) {
486 switch(format){
487 case MDP_Y_CBCR_H2V1:
488 case MDP_Y_CBCR_H2V2:
489 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700490 case MDP_Y_CRCB_H1V1:
491 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700492 case MDP_Y_CRCB_H2V2_TILE:
493 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700494 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700495 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700496 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700497 return true;
498 default:
499 return false;
500 }
501 return false;
502}
503
504inline bool isRgb(uint32_t format) {
505 switch(format) {
506 case MDP_RGBA_8888:
507 case MDP_BGRA_8888:
508 case MDP_RGBX_8888:
509 case MDP_RGB_565:
510 return true;
511 default:
512 return false;
513 }
514 return false;
515}
516
Saurabh Shah9c876d92012-08-25 19:29:53 -0700517inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700518 static const char* const formats[] = {
519 "MDP_RGB_565",
520 "MDP_XRGB_8888",
521 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700522 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523 "MDP_ARGB_8888",
524 "MDP_RGB_888",
525 "MDP_Y_CRCB_H2V2",
526 "MDP_YCRYCB_H2V1",
527 "MDP_Y_CRCB_H2V1",
528 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700529 "MDP_Y_CRCB_H1V2",
530 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700531 "MDP_RGBA_8888",
532 "MDP_BGRA_8888",
533 "MDP_RGBX_8888",
534 "MDP_Y_CRCB_H2V2_TILE",
535 "MDP_Y_CBCR_H2V2_TILE",
536 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700537 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700538 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700539 "MDP_Y_CRCB_H1V1",
540 "MDP_Y_CBCR_H1V1",
541 "MDP_YCRCB_H1V1",
542 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700543 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700544 "MDP_BGR_888",
545 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700546 "MDP_IMGTYPE_LIMIT",
547 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700548 "MDP_FB_FORMAT",
549 "MDP_IMGTYPE_LIMIT2"
550 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700551 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
552 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
553 return "Unsupported format";
554 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700555 return formats[format];
556}
557
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558inline void Whf::dump() const {
559 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
560 w, h, format, size);
561}
562
563inline void Dim::dump() const {
564 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
565}
566
567inline int getMdpOrient(eTransform rotation) {
568 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700569 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700570 {
571 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700572 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
573 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
574 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700575 //getMdpOrient will switch the flips if the source is 90 rotated.
576 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700577 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700578 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700579 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
580 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700581 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
582 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700583 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700584 ALOGE("%s: invalid rotation value (value = 0x%x",
585 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700586 }
587 return -1;
588}
589
590inline int getRotOutFmt(uint32_t format) {
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800591
592 if (isMdssRotator())
593 return format;
594
Naseer Ahmed29a26812012-06-14 00:56:20 -0700595 switch (format) {
596 case MDP_Y_CRCB_H2V2_TILE:
597 return MDP_Y_CRCB_H2V2;
598 case MDP_Y_CBCR_H2V2_TILE:
599 return MDP_Y_CBCR_H2V2;
600 case MDP_Y_CB_CR_H2V2:
601 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700602 case MDP_Y_CR_CB_GH2V2:
603 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700604 default:
605 return format;
606 }
607 // not reached
608 OVASSERT(false, "%s not reached", __FUNCTION__);
609 return -1;
610}
611
Naseer Ahmed29a26812012-06-14 00:56:20 -0700612
613inline uint32_t getColorFormat(uint32_t format)
614{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700615 return (format == HAL_PIXEL_FORMAT_YV12) ?
616 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700617}
618
619// FB0
620template <int CHAN>
621inline Dim getPositionS3DImpl(const Whf& whf)
622{
623 switch (whf.format & OUTPUT_3D_MASK)
624 {
625 case HAL_3D_OUT_SBS_MASK:
626 // x, y, w, h
627 return Dim(0, 0, whf.w/2, whf.h);
628 case HAL_3D_OUT_TOP_BOT_MASK:
629 return Dim(0, 0, whf.w, whf.h/2);
630 case HAL_3D_OUT_MONOS_MASK:
631 return Dim();
632 case HAL_3D_OUT_INTERL_MASK:
633 // FIXME error?
634 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
635 return Dim();
636 default:
637 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
638 whf.format);
639 }
640 return Dim();
641}
642
643template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500644inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700645{
646 switch (whf.format & OUTPUT_3D_MASK)
647 {
648 case HAL_3D_OUT_SBS_MASK:
649 return Dim(whf.w/2, 0, whf.w/2, whf.h);
650 case HAL_3D_OUT_TOP_BOT_MASK:
651 return Dim(0, whf.h/2, whf.w, whf.h/2);
652 case HAL_3D_OUT_MONOS_MASK:
653 return Dim(0, 0, whf.w, whf.h);
654 case HAL_3D_OUT_INTERL_MASK:
655 // FIXME error?
656 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
657 return Dim();
658 default:
659 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
660 whf.format);
661 }
662 return Dim();
663}
664
665template <int CHAN>
666inline bool getPositionS3D(const Whf& whf, Dim& out) {
667 out = getPositionS3DImpl<CHAN>(whf);
668 return (out != Dim());
669}
670
671template <int CHAN>
672inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
673 switch (fmt & INPUT_3D_MASK)
674 {
675 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
676 return Dim(0, 0, in.w/2, in.h);
677 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
678 return Dim(in.w/2, 0, in.w/2, in.h);
679 case HAL_3D_IN_TOP_BOTTOM:
680 return Dim(0, 0, in.w, in.h/2);
681 case HAL_3D_IN_INTERLEAVE:
682 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
683 break;
684 default:
685 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
686 break;
687 }
688 return Dim();
689}
690
691template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500692inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700693 switch (fmt & INPUT_3D_MASK)
694 {
695 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
696 return Dim(in.w/2, 0, in.w/2, in.h);
697 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
698 return Dim(0, 0, in.w/2, in.h);
699 case HAL_3D_IN_TOP_BOTTOM:
700 return Dim(0, in.h/2, in.w, in.h/2);
701 case HAL_3D_IN_INTERLEAVE:
702 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
703 break;
704 default:
705 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
706 break;
707 }
708 return Dim();
709}
710
711template <int CHAN>
712inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
713{
714 out = getCropS3DImpl<CHAN>(in, fmt);
715 return (out != Dim());
716}
717
718template <class Type>
719void swapWidthHeight(Type& width, Type& height) {
720 Type tmp = width;
721 width = height;
722 height = tmp;
723}
724
725inline void ScreenInfo::dump(const char* const s) const {
726 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
727 " bpp=%d stride=%d start/end ==",
728 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
729}
730
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700731inline bool openDev(OvFD& fd, int fbnum,
732 const char* const devpath, int flags) {
733 return overlay::open(fd, fbnum, devpath, flags);
734}
735
Saurabh Shahb121e142012-08-20 17:59:13 -0700736template <class T>
737inline void even_ceil(T& value) {
738 if(value & 1)
739 value++;
740}
741
742template <class T>
743inline void even_floor(T& value) {
744 if(value & 1)
745 value--;
746}
747
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500748inline const char* getDestStr(eDest dest) {
749 switch(dest) {
750 case OV_VG0: return "VG0";
751 case OV_RGB0: return "RGB0";
752 case OV_VG1: return "VG1";
753 case OV_RGB1: return "RGB1";
754 case OV_VG2: return "VG2";
755 case OV_RGB2: return "RGB2";
756 default: return "Invalid";
757 }
758 return "Invalid";
759}
760
761inline eMdpPipeType getPipeType(eDest dest) {
762 switch(dest) {
763 case OV_VG0:
764 case OV_VG1:
765 case OV_VG2:
766 return OV_MDP_PIPE_VG;
767 case OV_RGB0:
768 case OV_RGB1:
769 case OV_RGB2:
770 return OV_MDP_PIPE_RGB;
771 default:
772 return OV_MDP_PIPE_ANY;
773 }
774 return OV_MDP_PIPE_ANY;
775}
776
Naseer Ahmed29a26812012-06-14 00:56:20 -0700777} // namespace utils ends
778
779//--------------------Class Res stuff (namespace overlay only) -----------
780
781class Res {
782public:
783 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700784 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700785 // /dev/msm_rotator
786 static const char* const rotPath;
787 // /sys/class/graphics/fb1/format_3d
788 static const char* const format3DFile;
789 // /sys/class/graphics/fb1/3d_present
790 static const char* const edid3dInfoFile;
791 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
792 static const char* const barrierFile;
793};
794
795
796//--------------------Class OvFD stuff (namespace overlay only) -----------
797
Naseer Ahmed29a26812012-06-14 00:56:20 -0700798/*
799* Holds one FD
800* Dtor will NOT close the underlying FD.
801* That enables us to copy that object around
802* */
803class OvFD {
804public:
805 /* Ctor */
806 explicit OvFD();
807
808 /* dtor will NOT close the underlying FD */
809 ~OvFD();
810
811 /* Open fd using the path given by dev.
812 * return false in failure */
813 bool open(const char* const dev,
814 int flags = O_RDWR);
815
816 /* populate path */
817 void setPath(const char* const dev);
818
819 /* Close fd if we have a valid fd. */
820 bool close();
821
822 /* returns underlying fd.*/
823 int getFD() const;
824
825 /* returns true if fd is valid */
826 bool valid() const;
827
828 /* like operator= */
829 void copy(int fd);
830
831 /* dump the state of the instance */
832 void dump() const;
833private:
834 /* helper enum for determine valid/invalid fd */
835 enum { INVAL = -1 };
836
837 /* actual os fd */
838 int mFD;
839
840 /* path, for debugging */
841 char mPath[utils::MAX_PATH_LEN];
842};
843
844//-------------------Inlines--------------------------
845
846inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
847{
848 char dev_name[64] = {0};
849 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
850 return fd.open(dev_name, flags);
851}
852
853inline OvFD::OvFD() : mFD (INVAL) {
854 mPath[0] = 0;
855}
856
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700857inline OvFD::~OvFD() {
858 //no op since copy() can be used to share fd, in 3d cases.
859}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700860
861inline bool OvFD::open(const char* const dev, int flags)
862{
863 mFD = ::open(dev, flags, 0);
864 if (mFD < 0) {
865 // FIXME errno, strerror in bionic?
866 ALOGE("Cant open device %s err=%d", dev, errno);
867 return false;
868 }
869 setPath(dev);
870 return true;
871}
872
873inline void OvFD::setPath(const char* const dev)
874{
875 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
876}
877
878inline bool OvFD::close()
879{
880 int ret = 0;
881 if(valid()) {
882 ret = ::close(mFD);
883 mFD = INVAL;
884 }
885 return (ret == 0);
886}
887
888inline bool OvFD::valid() const
889{
890 return (mFD != INVAL);
891}
892
893inline int OvFD::getFD() const { return mFD; }
894
895inline void OvFD::copy(int fd) {
896 mFD = fd;
897}
898
899inline void OvFD::dump() const
900{
901 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
902 mFD, mPath);
903}
904
905//--------------- class OvFD stuff ends ---------------------
906
907} // overlay
908
909
910#endif // OVERLAY_UTILS_H