blob: 3fa097962683889b7bf7f028ebc52ac9ac890518 [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
Saurabh Shah5380a232013-04-10 17:13:11 -070050#define MDP_Y_CBCR_H2V2_VENUS MDP_IMGTYPE_LIMIT
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070051#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();
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700146void normalizeCrop(uint32_t& xy, uint32_t& wh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700147
Naseer Ahmed29a26812012-06-14 00:56:20 -0700148template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700149bool getPositionS3D(const Whf& whf, Dim& out);
150
Naseer Ahmed29a26812012-06-14 00:56:20 -0700151template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700152bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
153
Naseer Ahmed29a26812012-06-14 00:56:20 -0700154template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700155void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700156
157struct Dim {
158 Dim () : x(0), y(0),
159 w(0), h(0),
160 o(0) {}
161 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
162 x(_x), y(_y),
163 w(_w), h(_h) {}
164 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
165 x(_x), y(_y),
166 w(_w), h(_h),
167 o(_o) {}
168 bool check(uint32_t _w, uint32_t _h) const {
169 return (x+w <= _w && y+h <= _h);
170
171 }
172
173 bool operator==(const Dim& d) const {
174 return d.x == x && d.y == y &&
175 d.w == w && d.h == h &&
176 d.o == o;
177 }
178
179 bool operator!=(const Dim& d) const {
180 return !operator==(d);
181 }
182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183 void dump() const;
184 uint32_t x;
185 uint32_t y;
186 uint32_t w;
187 uint32_t h;
188 uint32_t o;
189};
190
191// TODO have Whfz
192
193struct Whf {
194 Whf() : w(0), h(0), format(0), size(0) {}
195 Whf(uint32_t wi, uint32_t he, uint32_t f) :
196 w(wi), h(he), format(f), size(0) {}
197 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
198 w(wi), h(he), format(f), size(s) {}
199 // FIXME not comparing size at the moment
200 bool operator==(const Whf& whf) const {
201 return whf.w == w && whf.h == h &&
202 whf.format == format;
203 }
204 bool operator!=(const Whf& whf) const {
205 return !operator==(whf);
206 }
207 void dump() const;
208 uint32_t w;
209 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700210 uint32_t format;
211 uint32_t size;
212};
213
214enum { MAX_PATH_LEN = 256 };
215
Naseer Ahmed29a26812012-06-14 00:56:20 -0700216/**
217 * Rotator flags: not to be confused with orientation flags.
Saurabh Shahacf10202013-02-26 10:15:15 -0800218 * Usually, you want to open the rotator to make sure it is
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 * ready for business.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800221 enum eRotFlags {
222 ROT_FLAGS_NONE = 0,
223 //Use rotator for 0 rotation. It is used anyway for others.
224 ROT_0_ENABLED = 1 << 0,
225 //Enable rotator downscale optimization for hardware bugs not handled in
226 //driver. If downscale optimizatation is required,
227 //then rotator will be used even if its 0 rotation case.
228 ROT_DOWNSCALE_ENABLED = 1 << 1,
Saurabh Shahacf10202013-02-26 10:15:15 -0800229 ROT_PREROTATED = 1 << 2,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800230};
231
232enum eRotDownscale {
233 ROT_DS_NONE = 0,
234 ROT_DS_HALF = 1,
235 ROT_DS_FOURTH = 2,
236 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700237};
238
Naseer Ahmed29a26812012-06-14 00:56:20 -0700239/* The values for is_fg flag for control alpha and transp
240 * IS_FG_OFF means is_fg = 0
241 * IS_FG_SET means is_fg = 1
242 */
243enum eIsFg {
244 IS_FG_OFF = 0,
245 IS_FG_SET = 1
246};
247
248/*
249 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
250 * kernel/common/linux/msm_mdp.h
251 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
252 * */
253enum eMdpFlags {
254 OV_MDP_FLAGS_NONE = 0,
255 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800256 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700258 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
259 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
Saurabh Shah799a3972012-09-01 12:16:12 -0700260 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700261 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700262 OV_MDP_FLIP_H = MDP_FLIP_LR,
263 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800264 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Saurabh Shah5daeee52013-01-23 16:52:26 +0800265 OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN,
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800266 OV_MDSS_MDP_BWC_EN = MDP_BWC_EN,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267};
268
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800270 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700271 ZORDER_1,
272 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500273 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274 Z_SYSTEM_ALLOC = 0xFFFF
275};
276
277enum eMdpPipeType {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800278 OV_MDP_PIPE_RGB = 0,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500279 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800280 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500281 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700282};
283
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800284// Identify destination pipes
285// TODO Names useless, replace with int and change all interfaces
Naseer Ahmed29a26812012-06-14 00:56:20 -0700286enum eDest {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800287 OV_P0 = 0,
288 OV_P1,
289 OV_P2,
290 OV_P3,
291 OV_P4,
292 OV_P5,
293 OV_P6,
294 OV_P7,
295 OV_P8,
296 OV_P9,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500297 OV_INVALID,
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800298 OV_MAX = OV_INVALID,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500299};
300
301/* Used when a buffer is split over 2 pipes and sent to display */
302enum {
303 OV_LEFT_SPLIT = 0,
304 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700305};
306
307/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
308enum eTransform {
309 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700310 OVERLAY_TRANSFORM_0 = 0x0,
311 /* flip source image horizontally 0x1 */
312 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
313 /* flip source image vertically 0x2 */
314 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700315 /* rotate source image 180 degrees
316 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700317 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
318 /* rotate source image 90 degrees 0x4 */
319 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
320 /* rotate source image 90 degrees and flip horizontally 0x5 */
321 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
322 HAL_TRANSFORM_FLIP_H,
323 /* rotate source image 90 degrees and flip vertically 0x6 */
324 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
325 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700326 /* rotate source image 270 degrees
327 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700328 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700329 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700330 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700331};
332
333// Used to consolidate pipe params
334struct PipeArgs {
335 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336 zorder(Z_SYSTEM_ALLOC),
337 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800338 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700339 }
340
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700341 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700342 eZorder z, eIsFg fg, eRotFlags r) :
343 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700345 zorder(z),
346 isFg(fg),
347 rotFlags(r) {
348 }
349
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700350 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700352 eZorder zorder; // stage number
353 eIsFg isFg; // control alpha & transp
354 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355};
356
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800357// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
358// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
359enum { HW_OV_MAGNIFICATION_LIMIT = 20,
360 HW_OV_MINIFICATION_LIMIT = 8
361};
362
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
364 f = static_cast<eMdpFlags>(setBit(f, v));
365}
366
367inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
368 f = static_cast<eMdpFlags>(clrBit(f, v));
369}
370
371// fb 0/1/2
372enum { FB0, FB1, FB2 };
373
374//Panels could be categorized as primary and external
375enum { PRIMARY, EXTERNAL };
376
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377// 2 for rgb0/1 double bufs
378enum { RGB_PIPE_NUM_BUFS = 2 };
379
380struct ScreenInfo {
381 ScreenInfo() : mFBWidth(0),
382 mFBHeight(0),
383 mFBbpp(0),
384 mFBystride(0) {}
385 void dump(const char* const s) const;
386 uint32_t mFBWidth;
387 uint32_t mFBHeight;
388 uint32_t mFBbpp;
389 uint32_t mFBystride;
390};
391
392int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800393int getHALFormat(int mdpFormat);
Saurabh Shahacf10202013-02-26 10:15:15 -0800394int getDownscaleFactor(const int& src_w, const int& src_h,
395 const int& dst_w, const int& dst_h);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800396
Naseer Ahmed29a26812012-06-14 00:56:20 -0700397/* flip is upside down and such. V, H flip
398 * rotation is 90, 180 etc
399 * It returns MDP related enum/define that match rot+flip*/
400int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700401const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700402
Naseer Ahmed29a26812012-06-14 00:56:20 -0700403template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700404inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700405
406template <class T> inline void swap ( T& a, T& b )
407{
408 T c(a); a=b; b=c;
409}
410
411inline int alignup(int value, int a) {
412 //if align = 0, return the value. Else, do alignment.
413 return a ? ((((value - 1) / a) + 1) * a) : value;
414}
415
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800416inline int aligndown(int value, int a) {
417 //if align = 0, return the value. Else, do alignment.
418 return a ? ((value) & ~(a-1)) : value;
419}
420
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421// FIXME that align should replace the upper one.
422inline int align(int value, int a) {
423 //if align = 0, return the value. Else, do alignment.
424 return a ? ((value + (a-1)) & ~(a-1)) : value;
425}
426
Naseer Ahmed29a26812012-06-14 00:56:20 -0700427enum eRotOutFmt {
428 ROT_OUT_FMT_DEFAULT,
429 ROT_OUT_FMT_Y_CRCB_H2V2
430};
431
432template <int ROT_OUT_FMT> struct RotOutFmt;
433
434// FIXME, taken from gralloc_priv.h. Need to
435// put it back as soon as overlay takes place of the old one
436/* possible formats for 3D content*/
437enum {
438 HAL_NO_3D = 0x0000,
439 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
440 HAL_3D_IN_TOP_BOTTOM = 0x20000,
441 HAL_3D_IN_INTERLEAVE = 0x40000,
442 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
443 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
444 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
445 HAL_3D_OUT_INTERLEAVE = 0x4000,
446 HAL_3D_OUT_MONOSCOPIC = 0x8000
447};
448
449enum { HAL_3D_OUT_SBS_MASK =
450 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
451 HAL_3D_OUT_TOP_BOT_MASK =
452 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
453 HAL_3D_OUT_INTERL_MASK =
454 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
455 HAL_3D_OUT_MONOS_MASK =
456 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
457};
458
459
460inline bool isYuv(uint32_t format) {
461 switch(format){
462 case MDP_Y_CBCR_H2V1:
463 case MDP_Y_CBCR_H2V2:
464 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700465 case MDP_Y_CRCB_H1V1:
466 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700467 case MDP_Y_CRCB_H2V2_TILE:
468 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700469 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700470 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700471 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700472 return true;
473 default:
474 return false;
475 }
476 return false;
477}
478
479inline bool isRgb(uint32_t format) {
480 switch(format) {
481 case MDP_RGBA_8888:
482 case MDP_BGRA_8888:
483 case MDP_RGBX_8888:
484 case MDP_RGB_565:
485 return true;
486 default:
487 return false;
488 }
489 return false;
490}
491
Saurabh Shah9c876d92012-08-25 19:29:53 -0700492inline const char* getFormatString(int format){
Saurabh Shah5380a232013-04-10 17:13:11 -0700493 #define STR(f) #f;
494 static const char* formats[MDP_IMGTYPE_LIMIT + 1] = {0};
495 formats[MDP_RGB_565] = STR(MDP_RGB_565);
496 formats[MDP_XRGB_8888] = STR(MDP_XRGB_8888);
497 formats[MDP_Y_CBCR_H2V2] = STR(MDP_Y_CBCR_H2V2);
498 formats[MDP_Y_CBCR_H2V2_ADRENO] = STR(MDP_Y_CBCR_H2V2_ADRENO);
499 formats[MDP_ARGB_8888] = STR(MDP_ARGB_8888);
500 formats[MDP_RGB_888] = STR(MDP_RGB_888);
501 formats[MDP_Y_CRCB_H2V2] = STR(MDP_Y_CRCB_H2V2);
502 formats[MDP_YCRYCB_H2V1] = STR(MDP_YCRYCB_H2V1);
503 formats[MDP_CBYCRY_H2V1] = STR(MDP_CBYCRY_H2V1);
504 formats[MDP_Y_CRCB_H2V1] = STR(MDP_Y_CRCB_H2V1);
505 formats[MDP_Y_CBCR_H2V1] = STR(MDP_Y_CBCR_H2V1);
506 formats[MDP_Y_CRCB_H1V2] = STR(MDP_Y_CRCB_H1V2);
507 formats[MDP_Y_CBCR_H1V2] = STR(MDP_Y_CBCR_H1V2);
508 formats[MDP_RGBA_8888] = STR(MDP_RGBA_8888);
509 formats[MDP_BGRA_8888] = STR(MDP_BGRA_8888);
510 formats[MDP_RGBX_8888] = STR(MDP_RGBX_8888);
511 formats[MDP_Y_CRCB_H2V2_TILE] = STR(MDP_Y_CRCB_H2V2_TILE);
512 formats[MDP_Y_CBCR_H2V2_TILE] = STR(MDP_Y_CBCR_H2V2_TILE);
513 formats[MDP_Y_CR_CB_H2V2] = STR(MDP_Y_CR_CB_H2V2);
514 formats[MDP_Y_CR_CB_GH2V2] = STR(MDP_Y_CR_CB_GH2V2);
515 formats[MDP_Y_CB_CR_H2V2] = STR(MDP_Y_CB_CR_H2V2);
516 formats[MDP_Y_CRCB_H1V1] = STR(MDP_Y_CRCB_H1V1);
517 formats[MDP_Y_CBCR_H1V1] = STR(MDP_Y_CBCR_H1V1);
518 formats[MDP_YCRCB_H1V1] = STR(MDP_YCRCB_H1V1);
519 formats[MDP_YCBCR_H1V1] = STR(MDP_YCBCR_H1V1);
520 formats[MDP_BGR_565] = STR(MDP_BGR_565);
521 formats[MDP_BGR_888] = STR(MDP_BGR_888);
522 formats[MDP_Y_CBCR_H2V2_VENUS] = STR(MDP_Y_CBCR_H2V2_VENUS);
523 formats[MDP_BGRX_8888] = STR(MDP_BGRX_8888);
524 formats[MDP_IMGTYPE_LIMIT] = STR(MDP_IMGTYPE_LIMIT);
525
526 if(format < 0 || format >= MDP_IMGTYPE_LIMIT) {
Saurabh Shah9c876d92012-08-25 19:29:53 -0700527 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
528 return "Unsupported format";
529 }
Saurabh Shah5380a232013-04-10 17:13:11 -0700530 if(formats[format] == 0) {
531 ALOGE("%s: table missing format %d from header", __FUNCTION__, format);
532 return "";
533 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700534 return formats[format];
535}
536
Naseer Ahmed29a26812012-06-14 00:56:20 -0700537inline void Whf::dump() const {
538 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
539 w, h, format, size);
540}
541
542inline void Dim::dump() const {
543 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
544}
545
Naseer Ahmed29a26812012-06-14 00:56:20 -0700546// FB0
547template <int CHAN>
548inline Dim getPositionS3DImpl(const Whf& whf)
549{
550 switch (whf.format & OUTPUT_3D_MASK)
551 {
552 case HAL_3D_OUT_SBS_MASK:
553 // x, y, w, h
554 return Dim(0, 0, whf.w/2, whf.h);
555 case HAL_3D_OUT_TOP_BOT_MASK:
556 return Dim(0, 0, whf.w, whf.h/2);
557 case HAL_3D_OUT_MONOS_MASK:
558 return Dim();
559 case HAL_3D_OUT_INTERL_MASK:
560 // FIXME error?
561 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
562 return Dim();
563 default:
564 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
565 whf.format);
566 }
567 return Dim();
568}
569
570template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500571inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700572{
573 switch (whf.format & OUTPUT_3D_MASK)
574 {
575 case HAL_3D_OUT_SBS_MASK:
576 return Dim(whf.w/2, 0, whf.w/2, whf.h);
577 case HAL_3D_OUT_TOP_BOT_MASK:
578 return Dim(0, whf.h/2, whf.w, whf.h/2);
579 case HAL_3D_OUT_MONOS_MASK:
580 return Dim(0, 0, whf.w, whf.h);
581 case HAL_3D_OUT_INTERL_MASK:
582 // FIXME error?
583 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
584 return Dim();
585 default:
586 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
587 whf.format);
588 }
589 return Dim();
590}
591
592template <int CHAN>
593inline bool getPositionS3D(const Whf& whf, Dim& out) {
594 out = getPositionS3DImpl<CHAN>(whf);
595 return (out != Dim());
596}
597
598template <int CHAN>
599inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
600 switch (fmt & INPUT_3D_MASK)
601 {
602 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
603 return Dim(0, 0, in.w/2, in.h);
604 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
605 return Dim(in.w/2, 0, in.w/2, in.h);
606 case HAL_3D_IN_TOP_BOTTOM:
607 return Dim(0, 0, in.w, in.h/2);
608 case HAL_3D_IN_INTERLEAVE:
609 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
610 break;
611 default:
612 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
613 break;
614 }
615 return Dim();
616}
617
618template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500619inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700620 switch (fmt & INPUT_3D_MASK)
621 {
622 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
623 return Dim(in.w/2, 0, in.w/2, in.h);
624 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
625 return Dim(0, 0, in.w/2, in.h);
626 case HAL_3D_IN_TOP_BOTTOM:
627 return Dim(0, in.h/2, in.w, in.h/2);
628 case HAL_3D_IN_INTERLEAVE:
629 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
630 break;
631 default:
632 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
633 break;
634 }
635 return Dim();
636}
637
638template <int CHAN>
639inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
640{
641 out = getCropS3DImpl<CHAN>(in, fmt);
642 return (out != Dim());
643}
644
645template <class Type>
646void swapWidthHeight(Type& width, Type& height) {
647 Type tmp = width;
648 width = height;
649 height = tmp;
650}
651
652inline void ScreenInfo::dump(const char* const s) const {
653 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
654 " bpp=%d stride=%d start/end ==",
655 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
656}
657
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700658inline bool openDev(OvFD& fd, int fbnum,
659 const char* const devpath, int flags) {
660 return overlay::open(fd, fbnum, devpath, flags);
661}
662
Saurabh Shahb121e142012-08-20 17:59:13 -0700663template <class T>
664inline void even_ceil(T& value) {
665 if(value & 1)
666 value++;
667}
668
669template <class T>
670inline void even_floor(T& value) {
671 if(value & 1)
672 value--;
673}
674
Saurabh Shah76fd6552013-03-14 14:45:38 -0700675void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800676void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
677void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
678void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
679void getDump(char *buf, size_t len, const char *prefix,
680 const msmfb_overlay_data& ov);
681void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
682void getDump(char *buf, size_t len, const char *prefix,
683 const msm_rotator_img_info& ov);
684void getDump(char *buf, size_t len, const char *prefix,
685 const msm_rotator_data_info& ov);
686
Naseer Ahmed29a26812012-06-14 00:56:20 -0700687} // namespace utils ends
688
689//--------------------Class Res stuff (namespace overlay only) -----------
690
691class Res {
692public:
693 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700694 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700695 // /dev/msm_rotator
696 static const char* const rotPath;
697 // /sys/class/graphics/fb1/format_3d
698 static const char* const format3DFile;
699 // /sys/class/graphics/fb1/3d_present
700 static const char* const edid3dInfoFile;
701 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
702 static const char* const barrierFile;
703};
704
705
706//--------------------Class OvFD stuff (namespace overlay only) -----------
707
Naseer Ahmed29a26812012-06-14 00:56:20 -0700708/*
709* Holds one FD
710* Dtor will NOT close the underlying FD.
711* That enables us to copy that object around
712* */
713class OvFD {
714public:
715 /* Ctor */
716 explicit OvFD();
717
718 /* dtor will NOT close the underlying FD */
719 ~OvFD();
720
721 /* Open fd using the path given by dev.
722 * return false in failure */
723 bool open(const char* const dev,
724 int flags = O_RDWR);
725
726 /* populate path */
727 void setPath(const char* const dev);
728
729 /* Close fd if we have a valid fd. */
730 bool close();
731
732 /* returns underlying fd.*/
733 int getFD() const;
734
735 /* returns true if fd is valid */
736 bool valid() const;
737
738 /* like operator= */
739 void copy(int fd);
740
741 /* dump the state of the instance */
742 void dump() const;
743private:
744 /* helper enum for determine valid/invalid fd */
745 enum { INVAL = -1 };
746
747 /* actual os fd */
748 int mFD;
749
750 /* path, for debugging */
751 char mPath[utils::MAX_PATH_LEN];
752};
753
754//-------------------Inlines--------------------------
755
756inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
757{
758 char dev_name[64] = {0};
759 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
760 return fd.open(dev_name, flags);
761}
762
763inline OvFD::OvFD() : mFD (INVAL) {
764 mPath[0] = 0;
765}
766
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700767inline OvFD::~OvFD() {
768 //no op since copy() can be used to share fd, in 3d cases.
769}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700770
771inline bool OvFD::open(const char* const dev, int flags)
772{
773 mFD = ::open(dev, flags, 0);
774 if (mFD < 0) {
775 // FIXME errno, strerror in bionic?
776 ALOGE("Cant open device %s err=%d", dev, errno);
777 return false;
778 }
779 setPath(dev);
780 return true;
781}
782
783inline void OvFD::setPath(const char* const dev)
784{
785 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
786}
787
788inline bool OvFD::close()
789{
790 int ret = 0;
791 if(valid()) {
792 ret = ::close(mFD);
793 mFD = INVAL;
794 }
795 return (ret == 0);
796}
797
798inline bool OvFD::valid() const
799{
800 return (mFD != INVAL);
801}
802
803inline int OvFD::getFD() const { return mFD; }
804
805inline void OvFD::copy(int fd) {
806 mFD = fd;
807}
808
809inline void OvFD::dump() const
810{
811 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
812 mFD, mPath);
813}
814
815//--------------- class OvFD stuff ends ---------------------
816
817} // overlay
818
819
820#endif // OVERLAY_UTILS_H