blob: c189bb78d794e966c72203f03f326558699fa224 [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,
Saurabh Shah5daeee52013-01-23 16:52:26 +0800264 OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700265};
266
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800268 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269 ZORDER_1,
270 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500271 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700272 Z_SYSTEM_ALLOC = 0xFFFF
273};
274
275enum eMdpPipeType {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800276 OV_MDP_PIPE_RGB = 0,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500277 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800278 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500279 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700280};
281
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800282// Identify destination pipes
283// TODO Names useless, replace with int and change all interfaces
Naseer Ahmed29a26812012-06-14 00:56:20 -0700284enum eDest {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800285 OV_P0 = 0,
286 OV_P1,
287 OV_P2,
288 OV_P3,
289 OV_P4,
290 OV_P5,
291 OV_P6,
292 OV_P7,
293 OV_P8,
294 OV_P9,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500295 OV_INVALID,
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800296 OV_MAX = OV_INVALID,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500297};
298
299/* Used when a buffer is split over 2 pipes and sent to display */
300enum {
301 OV_LEFT_SPLIT = 0,
302 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303};
304
305/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
306enum eTransform {
307 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700308 OVERLAY_TRANSFORM_0 = 0x0,
309 /* flip source image horizontally 0x1 */
310 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
311 /* flip source image vertically 0x2 */
312 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700313 /* rotate source image 180 degrees
314 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700315 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
316 /* rotate source image 90 degrees 0x4 */
317 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
318 /* rotate source image 90 degrees and flip horizontally 0x5 */
319 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
320 HAL_TRANSFORM_FLIP_H,
321 /* rotate source image 90 degrees and flip vertically 0x6 */
322 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
323 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324 /* rotate source image 270 degrees
325 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700326 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700327 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700328 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700329};
330
331// Used to consolidate pipe params
332struct PipeArgs {
333 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334 zorder(Z_SYSTEM_ALLOC),
335 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800336 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700337 }
338
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700339 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340 eZorder z, eIsFg fg, eRotFlags r) :
341 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343 zorder(z),
344 isFg(fg),
345 rotFlags(r) {
346 }
347
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700348 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700349 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700350 eZorder zorder; // stage number
351 eIsFg isFg; // control alpha & transp
352 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353};
354
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800355// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
356// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
357enum { HW_OV_MAGNIFICATION_LIMIT = 20,
358 HW_OV_MINIFICATION_LIMIT = 8
359};
360
Naseer Ahmed29a26812012-06-14 00:56:20 -0700361inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
362 f = static_cast<eMdpFlags>(setBit(f, v));
363}
364
365inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
366 f = static_cast<eMdpFlags>(clrBit(f, v));
367}
368
369// fb 0/1/2
370enum { FB0, FB1, FB2 };
371
372//Panels could be categorized as primary and external
373enum { PRIMARY, EXTERNAL };
374
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375// 2 for rgb0/1 double bufs
376enum { RGB_PIPE_NUM_BUFS = 2 };
377
378struct ScreenInfo {
379 ScreenInfo() : mFBWidth(0),
380 mFBHeight(0),
381 mFBbpp(0),
382 mFBystride(0) {}
383 void dump(const char* const s) const;
384 uint32_t mFBWidth;
385 uint32_t mFBHeight;
386 uint32_t mFBbpp;
387 uint32_t mFBystride;
388};
389
390int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800391int getHALFormat(int mdpFormat);
Saurabh Shahacf10202013-02-26 10:15:15 -0800392int getDownscaleFactor(const int& src_w, const int& src_h,
393 const int& dst_w, const int& dst_h);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800394
Naseer Ahmed29a26812012-06-14 00:56:20 -0700395/* flip is upside down and such. V, H flip
396 * rotation is 90, 180 etc
397 * It returns MDP related enum/define that match rot+flip*/
398int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700399const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400
Naseer Ahmed29a26812012-06-14 00:56:20 -0700401template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700402inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700403
404template <class T> inline void swap ( T& a, T& b )
405{
406 T c(a); a=b; b=c;
407}
408
409inline int alignup(int value, int a) {
410 //if align = 0, return the value. Else, do alignment.
411 return a ? ((((value - 1) / a) + 1) * a) : value;
412}
413
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800414inline int aligndown(int value, int a) {
415 //if align = 0, return the value. Else, do alignment.
416 return a ? ((value) & ~(a-1)) : value;
417}
418
Naseer Ahmed29a26812012-06-14 00:56:20 -0700419// FIXME that align should replace the upper one.
420inline int align(int value, int a) {
421 //if align = 0, return the value. Else, do alignment.
422 return a ? ((value + (a-1)) & ~(a-1)) : value;
423}
424
Naseer Ahmed29a26812012-06-14 00:56:20 -0700425enum eRotOutFmt {
426 ROT_OUT_FMT_DEFAULT,
427 ROT_OUT_FMT_Y_CRCB_H2V2
428};
429
430template <int ROT_OUT_FMT> struct RotOutFmt;
431
432// FIXME, taken from gralloc_priv.h. Need to
433// put it back as soon as overlay takes place of the old one
434/* possible formats for 3D content*/
435enum {
436 HAL_NO_3D = 0x0000,
437 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
438 HAL_3D_IN_TOP_BOTTOM = 0x20000,
439 HAL_3D_IN_INTERLEAVE = 0x40000,
440 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
441 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
442 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
443 HAL_3D_OUT_INTERLEAVE = 0x4000,
444 HAL_3D_OUT_MONOSCOPIC = 0x8000
445};
446
447enum { HAL_3D_OUT_SBS_MASK =
448 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
449 HAL_3D_OUT_TOP_BOT_MASK =
450 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
451 HAL_3D_OUT_INTERL_MASK =
452 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
453 HAL_3D_OUT_MONOS_MASK =
454 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
455};
456
457
458inline bool isYuv(uint32_t format) {
459 switch(format){
460 case MDP_Y_CBCR_H2V1:
461 case MDP_Y_CBCR_H2V2:
462 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700463 case MDP_Y_CRCB_H1V1:
464 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700465 case MDP_Y_CRCB_H2V2_TILE:
466 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700467 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700468 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700469 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700470 return true;
471 default:
472 return false;
473 }
474 return false;
475}
476
477inline bool isRgb(uint32_t format) {
478 switch(format) {
479 case MDP_RGBA_8888:
480 case MDP_BGRA_8888:
481 case MDP_RGBX_8888:
482 case MDP_RGB_565:
483 return true;
484 default:
485 return false;
486 }
487 return false;
488}
489
Saurabh Shah9c876d92012-08-25 19:29:53 -0700490inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700491 static const char* const formats[] = {
492 "MDP_RGB_565",
493 "MDP_XRGB_8888",
494 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700495 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496 "MDP_ARGB_8888",
497 "MDP_RGB_888",
498 "MDP_Y_CRCB_H2V2",
499 "MDP_YCRYCB_H2V1",
500 "MDP_Y_CRCB_H2V1",
501 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700502 "MDP_Y_CRCB_H1V2",
503 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700504 "MDP_RGBA_8888",
505 "MDP_BGRA_8888",
506 "MDP_RGBX_8888",
507 "MDP_Y_CRCB_H2V2_TILE",
508 "MDP_Y_CBCR_H2V2_TILE",
509 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700510 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700511 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700512 "MDP_Y_CRCB_H1V1",
513 "MDP_Y_CBCR_H1V1",
514 "MDP_YCRCB_H1V1",
515 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700516 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700517 "MDP_BGR_888",
518 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700519 "MDP_IMGTYPE_LIMIT",
520 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700521 "MDP_FB_FORMAT",
522 "MDP_IMGTYPE_LIMIT2"
523 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700524 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
525 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
526 return "Unsupported format";
527 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700528 return formats[format];
529}
530
Naseer Ahmed29a26812012-06-14 00:56:20 -0700531inline void Whf::dump() const {
532 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
533 w, h, format, size);
534}
535
536inline void Dim::dump() const {
537 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
538}
539
540inline int getMdpOrient(eTransform rotation) {
541 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700542 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700543 {
544 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700545 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
546 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
547 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700548 //getMdpOrient will switch the flips if the source is 90 rotated.
549 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700550 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700551 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700552 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
553 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700554 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
555 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700556 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700557 ALOGE("%s: invalid rotation value (value = 0x%x",
558 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700559 }
560 return -1;
561}
562
Naseer Ahmed29a26812012-06-14 00:56:20 -0700563// FB0
564template <int CHAN>
565inline Dim getPositionS3DImpl(const Whf& whf)
566{
567 switch (whf.format & OUTPUT_3D_MASK)
568 {
569 case HAL_3D_OUT_SBS_MASK:
570 // x, y, w, h
571 return Dim(0, 0, whf.w/2, whf.h);
572 case HAL_3D_OUT_TOP_BOT_MASK:
573 return Dim(0, 0, whf.w, whf.h/2);
574 case HAL_3D_OUT_MONOS_MASK:
575 return Dim();
576 case HAL_3D_OUT_INTERL_MASK:
577 // FIXME error?
578 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
579 return Dim();
580 default:
581 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
582 whf.format);
583 }
584 return Dim();
585}
586
587template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500588inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700589{
590 switch (whf.format & OUTPUT_3D_MASK)
591 {
592 case HAL_3D_OUT_SBS_MASK:
593 return Dim(whf.w/2, 0, whf.w/2, whf.h);
594 case HAL_3D_OUT_TOP_BOT_MASK:
595 return Dim(0, whf.h/2, whf.w, whf.h/2);
596 case HAL_3D_OUT_MONOS_MASK:
597 return Dim(0, 0, whf.w, whf.h);
598 case HAL_3D_OUT_INTERL_MASK:
599 // FIXME error?
600 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
601 return Dim();
602 default:
603 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
604 whf.format);
605 }
606 return Dim();
607}
608
609template <int CHAN>
610inline bool getPositionS3D(const Whf& whf, Dim& out) {
611 out = getPositionS3DImpl<CHAN>(whf);
612 return (out != Dim());
613}
614
615template <int CHAN>
616inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
617 switch (fmt & INPUT_3D_MASK)
618 {
619 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
620 return Dim(0, 0, in.w/2, in.h);
621 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
622 return Dim(in.w/2, 0, in.w/2, in.h);
623 case HAL_3D_IN_TOP_BOTTOM:
624 return Dim(0, 0, in.w, in.h/2);
625 case HAL_3D_IN_INTERLEAVE:
626 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
627 break;
628 default:
629 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
630 break;
631 }
632 return Dim();
633}
634
635template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500636inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700637 switch (fmt & INPUT_3D_MASK)
638 {
639 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
640 return Dim(in.w/2, 0, in.w/2, in.h);
641 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
642 return Dim(0, 0, in.w/2, in.h);
643 case HAL_3D_IN_TOP_BOTTOM:
644 return Dim(0, in.h/2, in.w, in.h/2);
645 case HAL_3D_IN_INTERLEAVE:
646 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
647 break;
648 default:
649 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
650 break;
651 }
652 return Dim();
653}
654
655template <int CHAN>
656inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
657{
658 out = getCropS3DImpl<CHAN>(in, fmt);
659 return (out != Dim());
660}
661
662template <class Type>
663void swapWidthHeight(Type& width, Type& height) {
664 Type tmp = width;
665 width = height;
666 height = tmp;
667}
668
669inline void ScreenInfo::dump(const char* const s) const {
670 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
671 " bpp=%d stride=%d start/end ==",
672 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
673}
674
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700675inline bool openDev(OvFD& fd, int fbnum,
676 const char* const devpath, int flags) {
677 return overlay::open(fd, fbnum, devpath, flags);
678}
679
Saurabh Shahb121e142012-08-20 17:59:13 -0700680template <class T>
681inline void even_ceil(T& value) {
682 if(value & 1)
683 value++;
684}
685
686template <class T>
687inline void even_floor(T& value) {
688 if(value & 1)
689 value--;
690}
691
Saurabh Shah76fd6552013-03-14 14:45:38 -0700692void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800693void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
694void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
695void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
696void getDump(char *buf, size_t len, const char *prefix,
697 const msmfb_overlay_data& ov);
698void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
699void getDump(char *buf, size_t len, const char *prefix,
700 const msm_rotator_img_info& ov);
701void getDump(char *buf, size_t len, const char *prefix,
702 const msm_rotator_data_info& ov);
703
Naseer Ahmed29a26812012-06-14 00:56:20 -0700704} // namespace utils ends
705
706//--------------------Class Res stuff (namespace overlay only) -----------
707
708class Res {
709public:
710 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700711 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700712 // /dev/msm_rotator
713 static const char* const rotPath;
714 // /sys/class/graphics/fb1/format_3d
715 static const char* const format3DFile;
716 // /sys/class/graphics/fb1/3d_present
717 static const char* const edid3dInfoFile;
718 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
719 static const char* const barrierFile;
720};
721
722
723//--------------------Class OvFD stuff (namespace overlay only) -----------
724
Naseer Ahmed29a26812012-06-14 00:56:20 -0700725/*
726* Holds one FD
727* Dtor will NOT close the underlying FD.
728* That enables us to copy that object around
729* */
730class OvFD {
731public:
732 /* Ctor */
733 explicit OvFD();
734
735 /* dtor will NOT close the underlying FD */
736 ~OvFD();
737
738 /* Open fd using the path given by dev.
739 * return false in failure */
740 bool open(const char* const dev,
741 int flags = O_RDWR);
742
743 /* populate path */
744 void setPath(const char* const dev);
745
746 /* Close fd if we have a valid fd. */
747 bool close();
748
749 /* returns underlying fd.*/
750 int getFD() const;
751
752 /* returns true if fd is valid */
753 bool valid() const;
754
755 /* like operator= */
756 void copy(int fd);
757
758 /* dump the state of the instance */
759 void dump() const;
760private:
761 /* helper enum for determine valid/invalid fd */
762 enum { INVAL = -1 };
763
764 /* actual os fd */
765 int mFD;
766
767 /* path, for debugging */
768 char mPath[utils::MAX_PATH_LEN];
769};
770
771//-------------------Inlines--------------------------
772
773inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
774{
775 char dev_name[64] = {0};
776 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
777 return fd.open(dev_name, flags);
778}
779
780inline OvFD::OvFD() : mFD (INVAL) {
781 mPath[0] = 0;
782}
783
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700784inline OvFD::~OvFD() {
785 //no op since copy() can be used to share fd, in 3d cases.
786}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700787
788inline bool OvFD::open(const char* const dev, int flags)
789{
790 mFD = ::open(dev, flags, 0);
791 if (mFD < 0) {
792 // FIXME errno, strerror in bionic?
793 ALOGE("Cant open device %s err=%d", dev, errno);
794 return false;
795 }
796 setPath(dev);
797 return true;
798}
799
800inline void OvFD::setPath(const char* const dev)
801{
802 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
803}
804
805inline bool OvFD::close()
806{
807 int ret = 0;
808 if(valid()) {
809 ret = ::close(mFD);
810 mFD = INVAL;
811 }
812 return (ret == 0);
813}
814
815inline bool OvFD::valid() const
816{
817 return (mFD != INVAL);
818}
819
820inline int OvFD::getFD() const { return mFD; }
821
822inline void OvFD::copy(int fd) {
823 mFD = fd;
824}
825
826inline void OvFD::dump() const
827{
828 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
829 mFD, mPath);
830}
831
832//--------------- class OvFD stuff ends ---------------------
833
834} // overlay
835
836
837#endif // OVERLAY_UTILS_H