blob: 45d1924977a1ee9e3b40ad9bfaa73a3a653872b1 [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 Chauhan81c4e7d2012-12-27 22:52:30 -080048// Older platforms do not support Venus.
49#ifndef VENUS_COLOR_FORMAT
Sushil Chauhanc5e61482012-08-22 17:13:32 -070050#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
Naseer Ahmed29a26812012-06-14 00:56:20 -070076namespace overlay {
77
78// fwd
79class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070080class OvFD;
81
82/* helper function to open by using fbnum */
83bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
84 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
86namespace utils {
87struct Whf;
88struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070089
90inline uint32_t setBit(uint32_t x, uint32_t mask) {
91 return (x | mask);
92}
93
94inline uint32_t clrBit(uint32_t x, uint32_t mask) {
95 return (x & ~mask);
96}
97
98/* Utility class to help avoid copying instances by making the copy ctor
99* and assignment operator private
100*
101* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103*/
104class NoCopy {
105protected:
106 NoCopy(){}
107 ~NoCopy() {}
108private:
109 NoCopy(const NoCopy&);
110 const NoCopy& operator=(const NoCopy&);
111};
112
113/*
114* Utility class to query the framebuffer info for primary display
115*
116* Usage:
117* Outside of functions:
118* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
119* Inside functions:
120* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
121*/
122class FrameBufferInfo {
123
124public:
125 /* ctor init */
126 explicit FrameBufferInfo();
127
128 /* Gets an instance if one does not already exist */
129 static FrameBufferInfo* getInstance();
130
131 /* Gets width of primary framebuffer */
132 int getWidth() const;
133
134 /* Gets height of primary framebuffer */
135 int getHeight() const;
136
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137private:
138 int mFBWidth;
139 int mFBHeight;
140 bool mBorderFillSupported;
141 static FrameBufferInfo *sFBInfoInstance;
142};
143
144/* 3D related utils, defines etc...
145 * The compound format passed to the overlay is
146 * ABCCC where A is the input 3D format
147 * B is the output 3D format
148 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
149enum { SHIFT_OUT_3D = 12,
150 SHIFT_TOT_3D = 16 };
151enum { INPUT_3D_MASK = 0xFFFF0000,
152 OUTPUT_3D_MASK = 0x0000FFFF };
153enum { BARRIER_LAND = 1,
154 BARRIER_PORT = 2 };
155
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700156/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
157 * close all the pipes if it is opened after reboot.
158 */
159int initOverlay(void);
160
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162inline uint32_t colorFormat(uint32_t fmt) {
163 /*TODO enable this block only if format has interlace / 3D info in top bits.
164 if(fmt & INTERLACE_MASK) {
165 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
166 }
167 fmt = fmt & 0xFFF;*/
168 return fmt;
169}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170inline uint32_t format3DOutput(uint32_t x) {
171 return (x & 0xF000) >> SHIFT_OUT_3D; }
172inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
173uint32_t getColorFormat(uint32_t format);
174
175bool isHDMIConnected ();
176bool is3DTV();
177bool isPanel3D();
178bool usePanel3D();
179bool send3DInfoPacket (uint32_t fmt);
180bool enableBarrier (uint32_t orientation);
181uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800182bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185bool getPositionS3D(const Whf& whf, Dim& out);
186
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700191void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192
193struct Dim {
194 Dim () : x(0), y(0),
195 w(0), h(0),
196 o(0) {}
197 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
198 x(_x), y(_y),
199 w(_w), h(_h) {}
200 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
201 x(_x), y(_y),
202 w(_w), h(_h),
203 o(_o) {}
204 bool check(uint32_t _w, uint32_t _h) const {
205 return (x+w <= _w && y+h <= _h);
206
207 }
208
209 bool operator==(const Dim& d) const {
210 return d.x == x && d.y == y &&
211 d.w == w && d.h == h &&
212 d.o == o;
213 }
214
215 bool operator!=(const Dim& d) const {
216 return !operator==(d);
217 }
218
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 void dump() const;
220 uint32_t x;
221 uint32_t y;
222 uint32_t w;
223 uint32_t h;
224 uint32_t o;
225};
226
227// TODO have Whfz
228
229struct Whf {
230 Whf() : w(0), h(0), format(0), size(0) {}
231 Whf(uint32_t wi, uint32_t he, uint32_t f) :
232 w(wi), h(he), format(f), size(0) {}
233 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
234 w(wi), h(he), format(f), size(s) {}
235 // FIXME not comparing size at the moment
236 bool operator==(const Whf& whf) const {
237 return whf.w == w && whf.h == h &&
238 whf.format == format;
239 }
240 bool operator!=(const Whf& whf) const {
241 return !operator==(whf);
242 }
243 void dump() const;
244 uint32_t w;
245 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246 uint32_t format;
247 uint32_t size;
248};
249
250enum { MAX_PATH_LEN = 256 };
251
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252/**
253 * Rotator flags: not to be confused with orientation flags.
254 * Ususally, you want to open the rotator to make sure it is
255 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 * ROT_FLAG_DISABLED: Rotator not used unless required.
257 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800259 enum eRotFlags {
260 ROT_FLAGS_NONE = 0,
261 //Use rotator for 0 rotation. It is used anyway for others.
262 ROT_0_ENABLED = 1 << 0,
263 //Enable rotator downscale optimization for hardware bugs not handled in
264 //driver. If downscale optimizatation is required,
265 //then rotator will be used even if its 0 rotation case.
266 ROT_DOWNSCALE_ENABLED = 1 << 1,
267};
268
269enum eRotDownscale {
270 ROT_DS_NONE = 0,
271 ROT_DS_HALF = 1,
272 ROT_DS_FOURTH = 2,
273 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274};
275
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276/* The values for is_fg flag for control alpha and transp
277 * IS_FG_OFF means is_fg = 0
278 * IS_FG_SET means is_fg = 1
279 */
280enum eIsFg {
281 IS_FG_OFF = 0,
282 IS_FG_SET = 1
283};
284
285/*
286 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
287 * kernel/common/linux/msm_mdp.h
288 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
289 * */
290enum eMdpFlags {
291 OV_MDP_FLAGS_NONE = 0,
292 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
293 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700294 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
295 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
296 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700297 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700298 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700299 OV_MDP_FLIP_H = MDP_FLIP_LR,
300 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800301 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302};
303
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304enum eZorder {
305 ZORDER_0,
306 ZORDER_1,
307 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500308 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309 Z_SYSTEM_ALLOC = 0xFFFF
310};
311
312enum eMdpPipeType {
313 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500314 OV_MDP_PIPE_VG,
315 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316};
317
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500318/* Used to identify destination pipes
319 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500321 OV_VG0 = 0,
322 OV_RGB0,
323 OV_VG1,
324 OV_RGB1,
325 OV_VG2,
326 OV_RGB2,
327 OV_INVALID,
328};
329
330/* Used when a buffer is split over 2 pipes and sent to display */
331enum {
332 OV_LEFT_SPLIT = 0,
333 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334};
335
336/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
337enum eTransform {
338 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700339 OVERLAY_TRANSFORM_0 = 0x0,
340 /* flip source image horizontally 0x1 */
341 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
342 /* flip source image vertically 0x2 */
343 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 /* rotate source image 180 degrees
345 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700346 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
347 /* rotate source image 90 degrees 0x4 */
348 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
349 /* rotate source image 90 degrees and flip horizontally 0x5 */
350 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
351 HAL_TRANSFORM_FLIP_H,
352 /* rotate source image 90 degrees and flip vertically 0x6 */
353 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
354 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355 /* rotate source image 270 degrees
356 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700357 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700358 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700359 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360};
361
362// Used to consolidate pipe params
363struct PipeArgs {
364 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 zorder(Z_SYSTEM_ALLOC),
366 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800367 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368 }
369
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371 eZorder z, eIsFg fg, eRotFlags r) :
372 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 zorder(z),
375 isFg(fg),
376 rotFlags(r) {
377 }
378
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700379 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 eZorder zorder; // stage number
382 eIsFg isFg; // control alpha & transp
383 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700384};
385
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
387 f = static_cast<eMdpFlags>(setBit(f, v));
388}
389
390inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
391 f = static_cast<eMdpFlags>(clrBit(f, v));
392}
393
394// fb 0/1/2
395enum { FB0, FB1, FB2 };
396
397//Panels could be categorized as primary and external
398enum { PRIMARY, EXTERNAL };
399
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400// 2 for rgb0/1 double bufs
401enum { RGB_PIPE_NUM_BUFS = 2 };
402
403struct ScreenInfo {
404 ScreenInfo() : mFBWidth(0),
405 mFBHeight(0),
406 mFBbpp(0),
407 mFBystride(0) {}
408 void dump(const char* const s) const;
409 uint32_t mFBWidth;
410 uint32_t mFBHeight;
411 uint32_t mFBbpp;
412 uint32_t mFBystride;
413};
414
415int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800416int getHALFormat(int mdpFormat);
417
Naseer Ahmed29a26812012-06-14 00:56:20 -0700418/* flip is upside down and such. V, H flip
419 * rotation is 90, 180 etc
420 * It returns MDP related enum/define that match rot+flip*/
421int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700422const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700423
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
425// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
426enum { HW_OV_MAGNIFICATION_LIMIT = 20,
427 HW_OV_MINIFICATION_LIMIT = 8
428};
429
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700431inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700432
433template <class T> inline void swap ( T& a, T& b )
434{
435 T c(a); a=b; b=c;
436}
437
438inline int alignup(int value, int a) {
439 //if align = 0, return the value. Else, do alignment.
440 return a ? ((((value - 1) / a) + 1) * a) : value;
441}
442
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800443inline int aligndown(int value, int a) {
444 //if align = 0, return the value. Else, do alignment.
445 return a ? ((value) & ~(a-1)) : value;
446}
447
Naseer Ahmed29a26812012-06-14 00:56:20 -0700448// FIXME that align should replace the upper one.
449inline int align(int value, int a) {
450 //if align = 0, return the value. Else, do alignment.
451 return a ? ((value + (a-1)) & ~(a-1)) : value;
452}
453
Naseer Ahmed29a26812012-06-14 00:56:20 -0700454enum eRotOutFmt {
455 ROT_OUT_FMT_DEFAULT,
456 ROT_OUT_FMT_Y_CRCB_H2V2
457};
458
459template <int ROT_OUT_FMT> struct RotOutFmt;
460
461// FIXME, taken from gralloc_priv.h. Need to
462// put it back as soon as overlay takes place of the old one
463/* possible formats for 3D content*/
464enum {
465 HAL_NO_3D = 0x0000,
466 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
467 HAL_3D_IN_TOP_BOTTOM = 0x20000,
468 HAL_3D_IN_INTERLEAVE = 0x40000,
469 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
470 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
471 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
472 HAL_3D_OUT_INTERLEAVE = 0x4000,
473 HAL_3D_OUT_MONOSCOPIC = 0x8000
474};
475
476enum { HAL_3D_OUT_SBS_MASK =
477 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
478 HAL_3D_OUT_TOP_BOT_MASK =
479 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
480 HAL_3D_OUT_INTERL_MASK =
481 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
482 HAL_3D_OUT_MONOS_MASK =
483 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
484};
485
486
487inline bool isYuv(uint32_t format) {
488 switch(format){
489 case MDP_Y_CBCR_H2V1:
490 case MDP_Y_CBCR_H2V2:
491 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700492 case MDP_Y_CRCB_H1V1:
493 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700494 case MDP_Y_CRCB_H2V2_TILE:
495 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700496 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700497 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700498 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700499 return true;
500 default:
501 return false;
502 }
503 return false;
504}
505
506inline bool isRgb(uint32_t format) {
507 switch(format) {
508 case MDP_RGBA_8888:
509 case MDP_BGRA_8888:
510 case MDP_RGBX_8888:
511 case MDP_RGB_565:
512 return true;
513 default:
514 return false;
515 }
516 return false;
517}
518
Saurabh Shah9c876d92012-08-25 19:29:53 -0700519inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700520 static const char* const formats[] = {
521 "MDP_RGB_565",
522 "MDP_XRGB_8888",
523 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700524 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700525 "MDP_ARGB_8888",
526 "MDP_RGB_888",
527 "MDP_Y_CRCB_H2V2",
528 "MDP_YCRYCB_H2V1",
529 "MDP_Y_CRCB_H2V1",
530 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700531 "MDP_Y_CRCB_H1V2",
532 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700533 "MDP_RGBA_8888",
534 "MDP_BGRA_8888",
535 "MDP_RGBX_8888",
536 "MDP_Y_CRCB_H2V2_TILE",
537 "MDP_Y_CBCR_H2V2_TILE",
538 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700539 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700540 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700541 "MDP_Y_CRCB_H1V1",
542 "MDP_Y_CBCR_H1V1",
543 "MDP_YCRCB_H1V1",
544 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700546 "MDP_BGR_888",
547 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700548 "MDP_IMGTYPE_LIMIT",
549 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700550 "MDP_FB_FORMAT",
551 "MDP_IMGTYPE_LIMIT2"
552 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700553 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
554 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
555 return "Unsupported format";
556 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700557 return formats[format];
558}
559
Naseer Ahmed29a26812012-06-14 00:56:20 -0700560inline void Whf::dump() const {
561 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
562 w, h, format, size);
563}
564
565inline void Dim::dump() const {
566 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
567}
568
569inline int getMdpOrient(eTransform rotation) {
570 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700571 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700572 {
573 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700574 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
575 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
576 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700577 //getMdpOrient will switch the flips if the source is 90 rotated.
578 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700579 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700580 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700581 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
582 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700583 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
584 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700585 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700586 ALOGE("%s: invalid rotation value (value = 0x%x",
587 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700588 }
589 return -1;
590}
591
Naseer Ahmed29a26812012-06-14 00:56:20 -0700592inline uint32_t getColorFormat(uint32_t format)
593{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700594 return (format == HAL_PIXEL_FORMAT_YV12) ?
595 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700596}
597
598// FB0
599template <int CHAN>
600inline Dim getPositionS3DImpl(const Whf& whf)
601{
602 switch (whf.format & OUTPUT_3D_MASK)
603 {
604 case HAL_3D_OUT_SBS_MASK:
605 // x, y, w, h
606 return Dim(0, 0, whf.w/2, whf.h);
607 case HAL_3D_OUT_TOP_BOT_MASK:
608 return Dim(0, 0, whf.w, whf.h/2);
609 case HAL_3D_OUT_MONOS_MASK:
610 return Dim();
611 case HAL_3D_OUT_INTERL_MASK:
612 // FIXME error?
613 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
614 return Dim();
615 default:
616 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
617 whf.format);
618 }
619 return Dim();
620}
621
622template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500623inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700624{
625 switch (whf.format & OUTPUT_3D_MASK)
626 {
627 case HAL_3D_OUT_SBS_MASK:
628 return Dim(whf.w/2, 0, whf.w/2, whf.h);
629 case HAL_3D_OUT_TOP_BOT_MASK:
630 return Dim(0, whf.h/2, whf.w, whf.h/2);
631 case HAL_3D_OUT_MONOS_MASK:
632 return Dim(0, 0, whf.w, whf.h);
633 case HAL_3D_OUT_INTERL_MASK:
634 // FIXME error?
635 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
636 return Dim();
637 default:
638 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
639 whf.format);
640 }
641 return Dim();
642}
643
644template <int CHAN>
645inline bool getPositionS3D(const Whf& whf, Dim& out) {
646 out = getPositionS3DImpl<CHAN>(whf);
647 return (out != Dim());
648}
649
650template <int CHAN>
651inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
652 switch (fmt & INPUT_3D_MASK)
653 {
654 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
655 return Dim(0, 0, in.w/2, in.h);
656 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
657 return Dim(in.w/2, 0, in.w/2, in.h);
658 case HAL_3D_IN_TOP_BOTTOM:
659 return Dim(0, 0, in.w, in.h/2);
660 case HAL_3D_IN_INTERLEAVE:
661 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
662 break;
663 default:
664 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
665 break;
666 }
667 return Dim();
668}
669
670template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500671inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700672 switch (fmt & INPUT_3D_MASK)
673 {
674 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
675 return Dim(in.w/2, 0, in.w/2, in.h);
676 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
677 return Dim(0, 0, in.w/2, in.h);
678 case HAL_3D_IN_TOP_BOTTOM:
679 return Dim(0, in.h/2, 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 <int CHAN>
691inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
692{
693 out = getCropS3DImpl<CHAN>(in, fmt);
694 return (out != Dim());
695}
696
697template <class Type>
698void swapWidthHeight(Type& width, Type& height) {
699 Type tmp = width;
700 width = height;
701 height = tmp;
702}
703
704inline void ScreenInfo::dump(const char* const s) const {
705 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
706 " bpp=%d stride=%d start/end ==",
707 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
708}
709
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700710inline bool openDev(OvFD& fd, int fbnum,
711 const char* const devpath, int flags) {
712 return overlay::open(fd, fbnum, devpath, flags);
713}
714
Saurabh Shahb121e142012-08-20 17:59:13 -0700715template <class T>
716inline void even_ceil(T& value) {
717 if(value & 1)
718 value++;
719}
720
721template <class T>
722inline void even_floor(T& value) {
723 if(value & 1)
724 value--;
725}
726
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500727inline const char* getDestStr(eDest dest) {
728 switch(dest) {
729 case OV_VG0: return "VG0";
730 case OV_RGB0: return "RGB0";
731 case OV_VG1: return "VG1";
732 case OV_RGB1: return "RGB1";
733 case OV_VG2: return "VG2";
734 case OV_RGB2: return "RGB2";
735 default: return "Invalid";
736 }
737 return "Invalid";
738}
739
740inline eMdpPipeType getPipeType(eDest dest) {
741 switch(dest) {
742 case OV_VG0:
743 case OV_VG1:
744 case OV_VG2:
745 return OV_MDP_PIPE_VG;
746 case OV_RGB0:
747 case OV_RGB1:
748 case OV_RGB2:
749 return OV_MDP_PIPE_RGB;
750 default:
751 return OV_MDP_PIPE_ANY;
752 }
753 return OV_MDP_PIPE_ANY;
754}
755
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800756void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
757void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
758void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
759void getDump(char *buf, size_t len, const char *prefix,
760 const msmfb_overlay_data& ov);
761void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
762void getDump(char *buf, size_t len, const char *prefix,
763 const msm_rotator_img_info& ov);
764void getDump(char *buf, size_t len, const char *prefix,
765 const msm_rotator_data_info& ov);
766
Naseer Ahmed29a26812012-06-14 00:56:20 -0700767} // namespace utils ends
768
769//--------------------Class Res stuff (namespace overlay only) -----------
770
771class Res {
772public:
773 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700774 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700775 // /dev/msm_rotator
776 static const char* const rotPath;
777 // /sys/class/graphics/fb1/format_3d
778 static const char* const format3DFile;
779 // /sys/class/graphics/fb1/3d_present
780 static const char* const edid3dInfoFile;
781 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
782 static const char* const barrierFile;
783};
784
785
786//--------------------Class OvFD stuff (namespace overlay only) -----------
787
Naseer Ahmed29a26812012-06-14 00:56:20 -0700788/*
789* Holds one FD
790* Dtor will NOT close the underlying FD.
791* That enables us to copy that object around
792* */
793class OvFD {
794public:
795 /* Ctor */
796 explicit OvFD();
797
798 /* dtor will NOT close the underlying FD */
799 ~OvFD();
800
801 /* Open fd using the path given by dev.
802 * return false in failure */
803 bool open(const char* const dev,
804 int flags = O_RDWR);
805
806 /* populate path */
807 void setPath(const char* const dev);
808
809 /* Close fd if we have a valid fd. */
810 bool close();
811
812 /* returns underlying fd.*/
813 int getFD() const;
814
815 /* returns true if fd is valid */
816 bool valid() const;
817
818 /* like operator= */
819 void copy(int fd);
820
821 /* dump the state of the instance */
822 void dump() const;
823private:
824 /* helper enum for determine valid/invalid fd */
825 enum { INVAL = -1 };
826
827 /* actual os fd */
828 int mFD;
829
830 /* path, for debugging */
831 char mPath[utils::MAX_PATH_LEN];
832};
833
834//-------------------Inlines--------------------------
835
836inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
837{
838 char dev_name[64] = {0};
839 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
840 return fd.open(dev_name, flags);
841}
842
843inline OvFD::OvFD() : mFD (INVAL) {
844 mPath[0] = 0;
845}
846
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700847inline OvFD::~OvFD() {
848 //no op since copy() can be used to share fd, in 3d cases.
849}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700850
851inline bool OvFD::open(const char* const dev, int flags)
852{
853 mFD = ::open(dev, flags, 0);
854 if (mFD < 0) {
855 // FIXME errno, strerror in bionic?
856 ALOGE("Cant open device %s err=%d", dev, errno);
857 return false;
858 }
859 setPath(dev);
860 return true;
861}
862
863inline void OvFD::setPath(const char* const dev)
864{
865 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
866}
867
868inline bool OvFD::close()
869{
870 int ret = 0;
871 if(valid()) {
872 ret = ::close(mFD);
873 mFD = INVAL;
874 }
875 return (ret == 0);
876}
877
878inline bool OvFD::valid() const
879{
880 return (mFD != INVAL);
881}
882
883inline int OvFD::getFD() const { return mFD; }
884
885inline void OvFD::copy(int fd) {
886 mFD = fd;
887}
888
889inline void OvFD::dump() const
890{
891 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
892 mFD, mPath);
893}
894
895//--------------- class OvFD stuff ends ---------------------
896
897} // overlay
898
899
900#endif // OVERLAY_UTILS_H