blob: 5eb0e1e5d6927fbd4152ce900529a3fe63e10765 [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
Sushil Chauhan07a2c762013-03-06 15:36:49 -080080#define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u"
81#define NUM_FB_DEVICES 3
82
Naseer Ahmed29a26812012-06-14 00:56:20 -070083namespace overlay {
84
85// fwd
86class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070087class OvFD;
88
89/* helper function to open by using fbnum */
90bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
91 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070092
93namespace utils {
94struct Whf;
95struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070096
97inline uint32_t setBit(uint32_t x, uint32_t mask) {
98 return (x | mask);
99}
100
101inline uint32_t clrBit(uint32_t x, uint32_t mask) {
102 return (x & ~mask);
103}
104
105/* Utility class to help avoid copying instances by making the copy ctor
106* and assignment operator private
107*
108* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700109* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700110*/
111class NoCopy {
112protected:
113 NoCopy(){}
114 ~NoCopy() {}
115private:
116 NoCopy(const NoCopy&);
117 const NoCopy& operator=(const NoCopy&);
118};
119
Naseer Ahmed29a26812012-06-14 00:56:20 -0700120
121/* 3D related utils, defines etc...
122 * The compound format passed to the overlay is
123 * ABCCC where A is the input 3D format
124 * B is the output 3D format
125 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
126enum { SHIFT_OUT_3D = 12,
127 SHIFT_TOT_3D = 16 };
128enum { INPUT_3D_MASK = 0xFFFF0000,
129 OUTPUT_3D_MASK = 0x0000FFFF };
130enum { BARRIER_LAND = 1,
131 BARRIER_PORT = 2 };
132
133inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700134inline uint32_t format3DOutput(uint32_t x) {
135 return (x & 0xF000) >> SHIFT_OUT_3D; }
136inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137
138bool isHDMIConnected ();
139bool is3DTV();
140bool isPanel3D();
141bool usePanel3D();
142bool send3DInfoPacket (uint32_t fmt);
143bool enableBarrier (uint32_t orientation);
144uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800145bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700146
Naseer Ahmed29a26812012-06-14 00:56:20 -0700147template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148bool getPositionS3D(const Whf& whf, Dim& out);
149
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700151bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
152
Naseer Ahmed29a26812012-06-14 00:56:20 -0700153template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700154void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155
156struct Dim {
157 Dim () : x(0), y(0),
158 w(0), h(0),
159 o(0) {}
160 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
161 x(_x), y(_y),
162 w(_w), h(_h) {}
163 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
164 x(_x), y(_y),
165 w(_w), h(_h),
166 o(_o) {}
167 bool check(uint32_t _w, uint32_t _h) const {
168 return (x+w <= _w && y+h <= _h);
169
170 }
171
172 bool operator==(const Dim& d) const {
173 return d.x == x && d.y == y &&
174 d.w == w && d.h == h &&
175 d.o == o;
176 }
177
178 bool operator!=(const Dim& d) const {
179 return !operator==(d);
180 }
181
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 void dump() const;
183 uint32_t x;
184 uint32_t y;
185 uint32_t w;
186 uint32_t h;
187 uint32_t o;
188};
189
190// TODO have Whfz
191
192struct Whf {
193 Whf() : w(0), h(0), format(0), size(0) {}
194 Whf(uint32_t wi, uint32_t he, uint32_t f) :
195 w(wi), h(he), format(f), size(0) {}
196 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
197 w(wi), h(he), format(f), size(s) {}
198 // FIXME not comparing size at the moment
199 bool operator==(const Whf& whf) const {
200 return whf.w == w && whf.h == h &&
201 whf.format == format;
202 }
203 bool operator!=(const Whf& whf) const {
204 return !operator==(whf);
205 }
206 void dump() const;
207 uint32_t w;
208 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 uint32_t format;
210 uint32_t size;
211};
212
213enum { MAX_PATH_LEN = 256 };
214
Naseer Ahmed29a26812012-06-14 00:56:20 -0700215/**
216 * Rotator flags: not to be confused with orientation flags.
Saurabh Shahacf10202013-02-26 10:15:15 -0800217 * Usually, you want to open the rotator to make sure it is
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 * ready for business.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800220 enum eRotFlags {
221 ROT_FLAGS_NONE = 0,
222 //Use rotator for 0 rotation. It is used anyway for others.
223 ROT_0_ENABLED = 1 << 0,
224 //Enable rotator downscale optimization for hardware bugs not handled in
225 //driver. If downscale optimizatation is required,
226 //then rotator will be used even if its 0 rotation case.
227 ROT_DOWNSCALE_ENABLED = 1 << 1,
Saurabh Shahacf10202013-02-26 10:15:15 -0800228 ROT_PREROTATED = 1 << 2,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800229};
230
231enum eRotDownscale {
232 ROT_DS_NONE = 0,
233 ROT_DS_HALF = 1,
234 ROT_DS_FOURTH = 2,
235 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700236};
237
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238/* The values for is_fg flag for control alpha and transp
239 * IS_FG_OFF means is_fg = 0
240 * IS_FG_SET means is_fg = 1
241 */
242enum eIsFg {
243 IS_FG_OFF = 0,
244 IS_FG_SET = 1
245};
246
247/*
248 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
249 * kernel/common/linux/msm_mdp.h
250 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
251 * */
252enum eMdpFlags {
253 OV_MDP_FLAGS_NONE = 0,
254 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800255 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700256 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700257 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
258 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
Saurabh Shah799a3972012-09-01 12:16:12 -0700259 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700260 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700261 OV_MDP_FLIP_H = MDP_FLIP_LR,
262 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800263 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700264};
265
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800267 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268 ZORDER_1,
269 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500270 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271 Z_SYSTEM_ALLOC = 0xFFFF
272};
273
274enum eMdpPipeType {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800275 OV_MDP_PIPE_RGB = 0,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500276 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800277 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500278 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700279};
280
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800281// Identify destination pipes
282// TODO Names useless, replace with int and change all interfaces
Naseer Ahmed29a26812012-06-14 00:56:20 -0700283enum eDest {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800284 OV_P0 = 0,
285 OV_P1,
286 OV_P2,
287 OV_P3,
288 OV_P4,
289 OV_P5,
290 OV_P6,
291 OV_P7,
292 OV_P8,
293 OV_P9,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500294 OV_INVALID,
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800295 OV_MAX = OV_INVALID,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500296};
297
298/* Used when a buffer is split over 2 pipes and sent to display */
299enum {
300 OV_LEFT_SPLIT = 0,
301 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700302};
303
304/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
305enum eTransform {
306 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700307 OVERLAY_TRANSFORM_0 = 0x0,
308 /* flip source image horizontally 0x1 */
309 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
310 /* flip source image vertically 0x2 */
311 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700312 /* rotate source image 180 degrees
313 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700314 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
315 /* rotate source image 90 degrees 0x4 */
316 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
317 /* rotate source image 90 degrees and flip horizontally 0x5 */
318 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
319 HAL_TRANSFORM_FLIP_H,
320 /* rotate source image 90 degrees and flip vertically 0x6 */
321 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
322 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323 /* rotate source image 270 degrees
324 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700325 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700327 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700328};
329
330// Used to consolidate pipe params
331struct PipeArgs {
332 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700333 zorder(Z_SYSTEM_ALLOC),
334 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800335 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336 }
337
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700338 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700339 eZorder z, eIsFg fg, eRotFlags r) :
340 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342 zorder(z),
343 isFg(fg),
344 rotFlags(r) {
345 }
346
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700347 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700348 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700349 eZorder zorder; // stage number
350 eIsFg isFg; // control alpha & transp
351 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700352};
353
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800354// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
355// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
356enum { HW_OV_MAGNIFICATION_LIMIT = 20,
357 HW_OV_MINIFICATION_LIMIT = 8
358};
359
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
361 f = static_cast<eMdpFlags>(setBit(f, v));
362}
363
364inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
365 f = static_cast<eMdpFlags>(clrBit(f, v));
366}
367
368// fb 0/1/2
369enum { FB0, FB1, FB2 };
370
371//Panels could be categorized as primary and external
372enum { PRIMARY, EXTERNAL };
373
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374// 2 for rgb0/1 double bufs
375enum { RGB_PIPE_NUM_BUFS = 2 };
376
377struct ScreenInfo {
378 ScreenInfo() : mFBWidth(0),
379 mFBHeight(0),
380 mFBbpp(0),
381 mFBystride(0) {}
382 void dump(const char* const s) const;
383 uint32_t mFBWidth;
384 uint32_t mFBHeight;
385 uint32_t mFBbpp;
386 uint32_t mFBystride;
387};
388
389int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800390int getHALFormat(int mdpFormat);
Saurabh Shahacf10202013-02-26 10:15:15 -0800391int getDownscaleFactor(const int& src_w, const int& src_h,
392 const int& dst_w, const int& dst_h);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800393
Naseer Ahmed29a26812012-06-14 00:56:20 -0700394/* flip is upside down and such. V, H flip
395 * rotation is 90, 180 etc
396 * It returns MDP related enum/define that match rot+flip*/
397int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700398const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700399
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700401inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700402
403template <class T> inline void swap ( T& a, T& b )
404{
405 T c(a); a=b; b=c;
406}
407
408inline int alignup(int value, int a) {
409 //if align = 0, return the value. Else, do alignment.
410 return a ? ((((value - 1) / a) + 1) * a) : value;
411}
412
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800413inline int aligndown(int value, int a) {
414 //if align = 0, return the value. Else, do alignment.
415 return a ? ((value) & ~(a-1)) : value;
416}
417
Naseer Ahmed29a26812012-06-14 00:56:20 -0700418// FIXME that align should replace the upper one.
419inline int align(int value, int a) {
420 //if align = 0, return the value. Else, do alignment.
421 return a ? ((value + (a-1)) & ~(a-1)) : value;
422}
423
Naseer Ahmed29a26812012-06-14 00:56:20 -0700424enum eRotOutFmt {
425 ROT_OUT_FMT_DEFAULT,
426 ROT_OUT_FMT_Y_CRCB_H2V2
427};
428
429template <int ROT_OUT_FMT> struct RotOutFmt;
430
431// FIXME, taken from gralloc_priv.h. Need to
432// put it back as soon as overlay takes place of the old one
433/* possible formats for 3D content*/
434enum {
435 HAL_NO_3D = 0x0000,
436 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
437 HAL_3D_IN_TOP_BOTTOM = 0x20000,
438 HAL_3D_IN_INTERLEAVE = 0x40000,
439 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
440 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
441 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
442 HAL_3D_OUT_INTERLEAVE = 0x4000,
443 HAL_3D_OUT_MONOSCOPIC = 0x8000
444};
445
446enum { HAL_3D_OUT_SBS_MASK =
447 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
448 HAL_3D_OUT_TOP_BOT_MASK =
449 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
450 HAL_3D_OUT_INTERL_MASK =
451 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
452 HAL_3D_OUT_MONOS_MASK =
453 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
454};
455
456
457inline bool isYuv(uint32_t format) {
458 switch(format){
459 case MDP_Y_CBCR_H2V1:
460 case MDP_Y_CBCR_H2V2:
461 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700462 case MDP_Y_CRCB_H1V1:
463 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700464 case MDP_Y_CRCB_H2V2_TILE:
465 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700466 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700467 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700468 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700469 return true;
470 default:
471 return false;
472 }
473 return false;
474}
475
476inline bool isRgb(uint32_t format) {
477 switch(format) {
478 case MDP_RGBA_8888:
479 case MDP_BGRA_8888:
480 case MDP_RGBX_8888:
481 case MDP_RGB_565:
482 return true;
483 default:
484 return false;
485 }
486 return false;
487}
488
Saurabh Shah9c876d92012-08-25 19:29:53 -0700489inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700490 static const char* const formats[] = {
491 "MDP_RGB_565",
492 "MDP_XRGB_8888",
493 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700494 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495 "MDP_ARGB_8888",
496 "MDP_RGB_888",
497 "MDP_Y_CRCB_H2V2",
498 "MDP_YCRYCB_H2V1",
499 "MDP_Y_CRCB_H2V1",
500 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700501 "MDP_Y_CRCB_H1V2",
502 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700503 "MDP_RGBA_8888",
504 "MDP_BGRA_8888",
505 "MDP_RGBX_8888",
506 "MDP_Y_CRCB_H2V2_TILE",
507 "MDP_Y_CBCR_H2V2_TILE",
508 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700509 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700510 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700511 "MDP_Y_CRCB_H1V1",
512 "MDP_Y_CBCR_H1V1",
513 "MDP_YCRCB_H1V1",
514 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700515 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700516 "MDP_BGR_888",
517 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700518 "MDP_IMGTYPE_LIMIT",
519 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700520 "MDP_FB_FORMAT",
521 "MDP_IMGTYPE_LIMIT2"
522 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700523 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
524 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
525 return "Unsupported format";
526 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700527 return formats[format];
528}
529
Naseer Ahmed29a26812012-06-14 00:56:20 -0700530inline void Whf::dump() const {
531 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
532 w, h, format, size);
533}
534
535inline void Dim::dump() const {
536 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
537}
538
539inline int getMdpOrient(eTransform rotation) {
540 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700541 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700542 {
543 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700544 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
545 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
546 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700547 //getMdpOrient will switch the flips if the source is 90 rotated.
548 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700549 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700550 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700551 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
552 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700553 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
554 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700555 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700556 ALOGE("%s: invalid rotation value (value = 0x%x",
557 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558 }
559 return -1;
560}
561
Naseer Ahmed29a26812012-06-14 00:56:20 -0700562// FB0
563template <int CHAN>
564inline Dim getPositionS3DImpl(const Whf& whf)
565{
566 switch (whf.format & OUTPUT_3D_MASK)
567 {
568 case HAL_3D_OUT_SBS_MASK:
569 // x, y, w, h
570 return Dim(0, 0, whf.w/2, whf.h);
571 case HAL_3D_OUT_TOP_BOT_MASK:
572 return Dim(0, 0, whf.w, whf.h/2);
573 case HAL_3D_OUT_MONOS_MASK:
574 return Dim();
575 case HAL_3D_OUT_INTERL_MASK:
576 // FIXME error?
577 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
578 return Dim();
579 default:
580 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
581 whf.format);
582 }
583 return Dim();
584}
585
586template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500587inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700588{
589 switch (whf.format & OUTPUT_3D_MASK)
590 {
591 case HAL_3D_OUT_SBS_MASK:
592 return Dim(whf.w/2, 0, whf.w/2, whf.h);
593 case HAL_3D_OUT_TOP_BOT_MASK:
594 return Dim(0, whf.h/2, whf.w, whf.h/2);
595 case HAL_3D_OUT_MONOS_MASK:
596 return Dim(0, 0, whf.w, whf.h);
597 case HAL_3D_OUT_INTERL_MASK:
598 // FIXME error?
599 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
600 return Dim();
601 default:
602 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
603 whf.format);
604 }
605 return Dim();
606}
607
608template <int CHAN>
609inline bool getPositionS3D(const Whf& whf, Dim& out) {
610 out = getPositionS3DImpl<CHAN>(whf);
611 return (out != Dim());
612}
613
614template <int CHAN>
615inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
616 switch (fmt & INPUT_3D_MASK)
617 {
618 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
619 return Dim(0, 0, in.w/2, in.h);
620 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
621 return Dim(in.w/2, 0, in.w/2, in.h);
622 case HAL_3D_IN_TOP_BOTTOM:
623 return Dim(0, 0, in.w, in.h/2);
624 case HAL_3D_IN_INTERLEAVE:
625 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
626 break;
627 default:
628 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
629 break;
630 }
631 return Dim();
632}
633
634template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500635inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700636 switch (fmt & INPUT_3D_MASK)
637 {
638 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
639 return Dim(in.w/2, 0, in.w/2, in.h);
640 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
641 return Dim(0, 0, in.w/2, in.h);
642 case HAL_3D_IN_TOP_BOTTOM:
643 return Dim(0, in.h/2, in.w, in.h/2);
644 case HAL_3D_IN_INTERLEAVE:
645 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
646 break;
647 default:
648 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
649 break;
650 }
651 return Dim();
652}
653
654template <int CHAN>
655inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
656{
657 out = getCropS3DImpl<CHAN>(in, fmt);
658 return (out != Dim());
659}
660
661template <class Type>
662void swapWidthHeight(Type& width, Type& height) {
663 Type tmp = width;
664 width = height;
665 height = tmp;
666}
667
668inline void ScreenInfo::dump(const char* const s) const {
669 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
670 " bpp=%d stride=%d start/end ==",
671 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
672}
673
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700674inline bool openDev(OvFD& fd, int fbnum,
675 const char* const devpath, int flags) {
676 return overlay::open(fd, fbnum, devpath, flags);
677}
678
Saurabh Shahb121e142012-08-20 17:59:13 -0700679template <class T>
680inline void even_ceil(T& value) {
681 if(value & 1)
682 value++;
683}
684
685template <class T>
686inline void even_floor(T& value) {
687 if(value & 1)
688 value--;
689}
690
Saurabh Shahacf10202013-02-26 10:15:15 -0800691void preRotateSource(eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800692void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
693void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
694void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
695void getDump(char *buf, size_t len, const char *prefix,
696 const msmfb_overlay_data& ov);
697void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
698void getDump(char *buf, size_t len, const char *prefix,
699 const msm_rotator_img_info& ov);
700void getDump(char *buf, size_t len, const char *prefix,
701 const msm_rotator_data_info& ov);
702
Naseer Ahmed29a26812012-06-14 00:56:20 -0700703} // namespace utils ends
704
705//--------------------Class Res stuff (namespace overlay only) -----------
706
707class Res {
708public:
709 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700710 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700711 // /dev/msm_rotator
712 static const char* const rotPath;
713 // /sys/class/graphics/fb1/format_3d
714 static const char* const format3DFile;
715 // /sys/class/graphics/fb1/3d_present
716 static const char* const edid3dInfoFile;
717 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
718 static const char* const barrierFile;
719};
720
721
722//--------------------Class OvFD stuff (namespace overlay only) -----------
723
Naseer Ahmed29a26812012-06-14 00:56:20 -0700724/*
725* Holds one FD
726* Dtor will NOT close the underlying FD.
727* That enables us to copy that object around
728* */
729class OvFD {
730public:
731 /* Ctor */
732 explicit OvFD();
733
734 /* dtor will NOT close the underlying FD */
735 ~OvFD();
736
737 /* Open fd using the path given by dev.
738 * return false in failure */
739 bool open(const char* const dev,
740 int flags = O_RDWR);
741
742 /* populate path */
743 void setPath(const char* const dev);
744
745 /* Close fd if we have a valid fd. */
746 bool close();
747
748 /* returns underlying fd.*/
749 int getFD() const;
750
751 /* returns true if fd is valid */
752 bool valid() const;
753
754 /* like operator= */
755 void copy(int fd);
756
757 /* dump the state of the instance */
758 void dump() const;
759private:
760 /* helper enum for determine valid/invalid fd */
761 enum { INVAL = -1 };
762
763 /* actual os fd */
764 int mFD;
765
766 /* path, for debugging */
767 char mPath[utils::MAX_PATH_LEN];
768};
769
770//-------------------Inlines--------------------------
771
772inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
773{
774 char dev_name[64] = {0};
775 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
776 return fd.open(dev_name, flags);
777}
778
779inline OvFD::OvFD() : mFD (INVAL) {
780 mPath[0] = 0;
781}
782
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700783inline OvFD::~OvFD() {
784 //no op since copy() can be used to share fd, in 3d cases.
785}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700786
787inline bool OvFD::open(const char* const dev, int flags)
788{
789 mFD = ::open(dev, flags, 0);
790 if (mFD < 0) {
791 // FIXME errno, strerror in bionic?
792 ALOGE("Cant open device %s err=%d", dev, errno);
793 return false;
794 }
795 setPath(dev);
796 return true;
797}
798
799inline void OvFD::setPath(const char* const dev)
800{
801 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
802}
803
804inline bool OvFD::close()
805{
806 int ret = 0;
807 if(valid()) {
808 ret = ::close(mFD);
809 mFD = INVAL;
810 }
811 return (ret == 0);
812}
813
814inline bool OvFD::valid() const
815{
816 return (mFD != INVAL);
817}
818
819inline int OvFD::getFD() const { return mFD; }
820
821inline void OvFD::copy(int fd) {
822 mFD = fd;
823}
824
825inline void OvFD::dump() const
826{
827 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
828 mFD, mPath);
829}
830
831//--------------- class OvFD stuff ends ---------------------
832
833} // overlay
834
835
836#endif // OVERLAY_UTILS_H