blob: a6b27b59be602d6d9594b2bd2b37ada159efa511 [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
Naseer Ahmed29a26812012-06-14 00:56:20 -070048/*
49*
50* Collection of utilities functions/structs/enums etc...
51*
52* */
53
54// comment that out if you want to remove asserts
55// or put it as -D in Android.mk. your choice.
56#define OVERLAY_HAS_ASSERT
57
58#ifdef OVERLAY_HAS_ASSERT
59# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
60#else
61# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
62#endif // OVERLAY_HAS_ASSERT
63
64#define DEBUG_OVERLAY 0
65#define PROFILE_OVERLAY 0
66
Saurabh Shahcf053c62012-12-13 12:32:55 -080067#ifndef MDSS_MDP_RIGHT_MIXER
68#define MDSS_MDP_RIGHT_MIXER 0x100
69#endif
70
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080071#ifndef MDP_OV_PIPE_FORCE_DMA
72#define MDP_OV_PIPE_FORCE_DMA 0x4000
73#endif
74
Naseer Ahmed29a26812012-06-14 00:56:20 -070075namespace overlay {
76
77// fwd
78class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070079class OvFD;
80
81/* helper function to open by using fbnum */
82bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
83 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070084
85namespace utils {
86struct Whf;
87struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070088
89inline uint32_t setBit(uint32_t x, uint32_t mask) {
90 return (x | mask);
91}
92
93inline uint32_t clrBit(uint32_t x, uint32_t mask) {
94 return (x & ~mask);
95}
96
97/* Utility class to help avoid copying instances by making the copy ctor
98* and assignment operator private
99*
100* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700101* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700102*/
103class NoCopy {
104protected:
105 NoCopy(){}
106 ~NoCopy() {}
107private:
108 NoCopy(const NoCopy&);
109 const NoCopy& operator=(const NoCopy&);
110};
111
112/*
113* Utility class to query the framebuffer info for primary display
114*
115* Usage:
116* Outside of functions:
117* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
118* Inside functions:
119* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
120*/
121class FrameBufferInfo {
122
123public:
124 /* ctor init */
125 explicit FrameBufferInfo();
126
127 /* Gets an instance if one does not already exist */
128 static FrameBufferInfo* getInstance();
129
130 /* Gets width of primary framebuffer */
131 int getWidth() const;
132
133 /* Gets height of primary framebuffer */
134 int getHeight() const;
135
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136private:
137 int mFBWidth;
138 int mFBHeight;
139 bool mBorderFillSupported;
140 static FrameBufferInfo *sFBInfoInstance;
141};
142
143/* 3D related utils, defines etc...
144 * The compound format passed to the overlay is
145 * ABCCC where A is the input 3D format
146 * B is the output 3D format
147 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
148enum { SHIFT_OUT_3D = 12,
149 SHIFT_TOT_3D = 16 };
150enum { INPUT_3D_MASK = 0xFFFF0000,
151 OUTPUT_3D_MASK = 0x0000FFFF };
152enum { BARRIER_LAND = 1,
153 BARRIER_PORT = 2 };
154
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700155/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
156 * close all the pipes if it is opened after reboot.
157 */
158int initOverlay(void);
159
Naseer Ahmed29a26812012-06-14 00:56:20 -0700160inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700161inline uint32_t colorFormat(uint32_t fmt) {
162 /*TODO enable this block only if format has interlace / 3D info in top bits.
163 if(fmt & INTERLACE_MASK) {
164 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
165 }
166 fmt = fmt & 0xFFF;*/
167 return fmt;
168}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700169inline uint32_t format3DOutput(uint32_t x) {
170 return (x & 0xF000) >> SHIFT_OUT_3D; }
171inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
172uint32_t getColorFormat(uint32_t format);
173
174bool isHDMIConnected ();
175bool is3DTV();
176bool isPanel3D();
177bool usePanel3D();
178bool send3DInfoPacket (uint32_t fmt);
179bool enableBarrier (uint32_t orientation);
180uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800181bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700182
Naseer Ahmed29a26812012-06-14 00:56:20 -0700183template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700184bool getPositionS3D(const Whf& whf, Dim& out);
185
Naseer Ahmed29a26812012-06-14 00:56:20 -0700186template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700187bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
188
Naseer Ahmed29a26812012-06-14 00:56:20 -0700189template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700190void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700191
192struct Dim {
193 Dim () : x(0), y(0),
194 w(0), h(0),
195 o(0) {}
196 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
197 x(_x), y(_y),
198 w(_w), h(_h) {}
199 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
200 x(_x), y(_y),
201 w(_w), h(_h),
202 o(_o) {}
203 bool check(uint32_t _w, uint32_t _h) const {
204 return (x+w <= _w && y+h <= _h);
205
206 }
207
208 bool operator==(const Dim& d) const {
209 return d.x == x && d.y == y &&
210 d.w == w && d.h == h &&
211 d.o == o;
212 }
213
214 bool operator!=(const Dim& d) const {
215 return !operator==(d);
216 }
217
Naseer Ahmed29a26812012-06-14 00:56:20 -0700218 void dump() const;
219 uint32_t x;
220 uint32_t y;
221 uint32_t w;
222 uint32_t h;
223 uint32_t o;
224};
225
226// TODO have Whfz
227
228struct Whf {
229 Whf() : w(0), h(0), format(0), size(0) {}
230 Whf(uint32_t wi, uint32_t he, uint32_t f) :
231 w(wi), h(he), format(f), size(0) {}
232 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
233 w(wi), h(he), format(f), size(s) {}
234 // FIXME not comparing size at the moment
235 bool operator==(const Whf& whf) const {
236 return whf.w == w && whf.h == h &&
237 whf.format == format;
238 }
239 bool operator!=(const Whf& whf) const {
240 return !operator==(whf);
241 }
242 void dump() const;
243 uint32_t w;
244 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700245 uint32_t format;
246 uint32_t size;
247};
248
249enum { MAX_PATH_LEN = 256 };
250
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251/**
252 * Rotator flags: not to be confused with orientation flags.
253 * Ususally, you want to open the rotator to make sure it is
254 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500255 * ROT_FLAG_DISABLED: Rotator not used unless required.
256 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800258 enum eRotFlags {
259 ROT_FLAGS_NONE = 0,
260 //Use rotator for 0 rotation. It is used anyway for others.
261 ROT_0_ENABLED = 1 << 0,
262 //Enable rotator downscale optimization for hardware bugs not handled in
263 //driver. If downscale optimizatation is required,
264 //then rotator will be used even if its 0 rotation case.
265 ROT_DOWNSCALE_ENABLED = 1 << 1,
266};
267
268enum eRotDownscale {
269 ROT_DS_NONE = 0,
270 ROT_DS_HALF = 1,
271 ROT_DS_FOURTH = 2,
272 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273};
274
Naseer Ahmed29a26812012-06-14 00:56:20 -0700275/* The values for is_fg flag for control alpha and transp
276 * IS_FG_OFF means is_fg = 0
277 * IS_FG_SET means is_fg = 1
278 */
279enum eIsFg {
280 IS_FG_OFF = 0,
281 IS_FG_SET = 1
282};
283
284/*
285 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
286 * kernel/common/linux/msm_mdp.h
287 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
288 * */
289enum eMdpFlags {
290 OV_MDP_FLAGS_NONE = 0,
291 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800292 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700293 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,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800315 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500316 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700317};
318
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500319/* Used to identify destination pipes
320 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500322 OV_VG0 = 0,
323 OV_RGB0,
324 OV_VG1,
325 OV_RGB1,
326 OV_VG2,
327 OV_RGB2,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800328 OV_DMA0,
329 OV_DMA1,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500330 OV_INVALID,
331};
332
333/* Used when a buffer is split over 2 pipes and sent to display */
334enum {
335 OV_LEFT_SPLIT = 0,
336 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700337};
338
339/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
340enum eTransform {
341 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700342 OVERLAY_TRANSFORM_0 = 0x0,
343 /* flip source image horizontally 0x1 */
344 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
345 /* flip source image vertically 0x2 */
346 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700347 /* rotate source image 180 degrees
348 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700349 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
350 /* rotate source image 90 degrees 0x4 */
351 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
352 /* rotate source image 90 degrees and flip horizontally 0x5 */
353 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
354 HAL_TRANSFORM_FLIP_H,
355 /* rotate source image 90 degrees and flip vertically 0x6 */
356 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
357 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700358 /* rotate source image 270 degrees
359 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700360 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700361 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700362 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700363};
364
365// Used to consolidate pipe params
366struct PipeArgs {
367 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368 zorder(Z_SYSTEM_ALLOC),
369 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800370 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371 }
372
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700373 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 eZorder z, eIsFg fg, eRotFlags r) :
375 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700376 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700377 zorder(z),
378 isFg(fg),
379 rotFlags(r) {
380 }
381
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700382 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700383 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700384 eZorder zorder; // stage number
385 eIsFg isFg; // control alpha & transp
386 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387};
388
Naseer Ahmed29a26812012-06-14 00:56:20 -0700389inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
390 f = static_cast<eMdpFlags>(setBit(f, v));
391}
392
393inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
394 f = static_cast<eMdpFlags>(clrBit(f, v));
395}
396
397// fb 0/1/2
398enum { FB0, FB1, FB2 };
399
400//Panels could be categorized as primary and external
401enum { PRIMARY, EXTERNAL };
402
Naseer Ahmed29a26812012-06-14 00:56:20 -0700403// 2 for rgb0/1 double bufs
404enum { RGB_PIPE_NUM_BUFS = 2 };
405
406struct ScreenInfo {
407 ScreenInfo() : mFBWidth(0),
408 mFBHeight(0),
409 mFBbpp(0),
410 mFBystride(0) {}
411 void dump(const char* const s) const;
412 uint32_t mFBWidth;
413 uint32_t mFBHeight;
414 uint32_t mFBbpp;
415 uint32_t mFBystride;
416};
417
418int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800419int getHALFormat(int mdpFormat);
420
Naseer Ahmed29a26812012-06-14 00:56:20 -0700421/* flip is upside down and such. V, H flip
422 * rotation is 90, 180 etc
423 * It returns MDP related enum/define that match rot+flip*/
424int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700425const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700426
Naseer Ahmed29a26812012-06-14 00:56:20 -0700427// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
428// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
429enum { HW_OV_MAGNIFICATION_LIMIT = 20,
430 HW_OV_MINIFICATION_LIMIT = 8
431};
432
Naseer Ahmed29a26812012-06-14 00:56:20 -0700433template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700434inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700435
436template <class T> inline void swap ( T& a, T& b )
437{
438 T c(a); a=b; b=c;
439}
440
441inline int alignup(int value, int a) {
442 //if align = 0, return the value. Else, do alignment.
443 return a ? ((((value - 1) / a) + 1) * a) : value;
444}
445
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800446inline int aligndown(int value, int a) {
447 //if align = 0, return the value. Else, do alignment.
448 return a ? ((value) & ~(a-1)) : value;
449}
450
Naseer Ahmed29a26812012-06-14 00:56:20 -0700451// FIXME that align should replace the upper one.
452inline int align(int value, int a) {
453 //if align = 0, return the value. Else, do alignment.
454 return a ? ((value + (a-1)) & ~(a-1)) : value;
455}
456
Naseer Ahmed29a26812012-06-14 00:56:20 -0700457enum eRotOutFmt {
458 ROT_OUT_FMT_DEFAULT,
459 ROT_OUT_FMT_Y_CRCB_H2V2
460};
461
462template <int ROT_OUT_FMT> struct RotOutFmt;
463
464// FIXME, taken from gralloc_priv.h. Need to
465// put it back as soon as overlay takes place of the old one
466/* possible formats for 3D content*/
467enum {
468 HAL_NO_3D = 0x0000,
469 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
470 HAL_3D_IN_TOP_BOTTOM = 0x20000,
471 HAL_3D_IN_INTERLEAVE = 0x40000,
472 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
473 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
474 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
475 HAL_3D_OUT_INTERLEAVE = 0x4000,
476 HAL_3D_OUT_MONOSCOPIC = 0x8000
477};
478
479enum { HAL_3D_OUT_SBS_MASK =
480 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
481 HAL_3D_OUT_TOP_BOT_MASK =
482 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
483 HAL_3D_OUT_INTERL_MASK =
484 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
485 HAL_3D_OUT_MONOS_MASK =
486 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
487};
488
489
490inline bool isYuv(uint32_t format) {
491 switch(format){
492 case MDP_Y_CBCR_H2V1:
493 case MDP_Y_CBCR_H2V2:
494 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700495 case MDP_Y_CRCB_H1V1:
496 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700497 case MDP_Y_CRCB_H2V2_TILE:
498 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700499 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700500 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700501 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700502 return true;
503 default:
504 return false;
505 }
506 return false;
507}
508
509inline bool isRgb(uint32_t format) {
510 switch(format) {
511 case MDP_RGBA_8888:
512 case MDP_BGRA_8888:
513 case MDP_RGBX_8888:
514 case MDP_RGB_565:
515 return true;
516 default:
517 return false;
518 }
519 return false;
520}
521
Saurabh Shah9c876d92012-08-25 19:29:53 -0700522inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700523 static const char* const formats[] = {
524 "MDP_RGB_565",
525 "MDP_XRGB_8888",
526 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700527 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700528 "MDP_ARGB_8888",
529 "MDP_RGB_888",
530 "MDP_Y_CRCB_H2V2",
531 "MDP_YCRYCB_H2V1",
532 "MDP_Y_CRCB_H2V1",
533 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700534 "MDP_Y_CRCB_H1V2",
535 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700536 "MDP_RGBA_8888",
537 "MDP_BGRA_8888",
538 "MDP_RGBX_8888",
539 "MDP_Y_CRCB_H2V2_TILE",
540 "MDP_Y_CBCR_H2V2_TILE",
541 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700542 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700543 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700544 "MDP_Y_CRCB_H1V1",
545 "MDP_Y_CBCR_H1V1",
546 "MDP_YCRCB_H1V1",
547 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700548 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700549 "MDP_BGR_888",
550 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700551 "MDP_IMGTYPE_LIMIT",
552 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700553 "MDP_FB_FORMAT",
554 "MDP_IMGTYPE_LIMIT2"
555 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700556 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
557 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
558 return "Unsupported format";
559 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700560 return formats[format];
561}
562
Naseer Ahmed29a26812012-06-14 00:56:20 -0700563inline void Whf::dump() const {
564 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
565 w, h, format, size);
566}
567
568inline void Dim::dump() const {
569 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
570}
571
572inline int getMdpOrient(eTransform rotation) {
573 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700574 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700575 {
576 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700577 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
578 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
579 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700580 //getMdpOrient will switch the flips if the source is 90 rotated.
581 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700582 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700583 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700584 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
585 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700586 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
587 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700588 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700589 ALOGE("%s: invalid rotation value (value = 0x%x",
590 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700591 }
592 return -1;
593}
594
Naseer Ahmed29a26812012-06-14 00:56:20 -0700595inline uint32_t getColorFormat(uint32_t format)
596{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700597 return (format == HAL_PIXEL_FORMAT_YV12) ?
598 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700599}
600
601// FB0
602template <int CHAN>
603inline Dim getPositionS3DImpl(const Whf& whf)
604{
605 switch (whf.format & OUTPUT_3D_MASK)
606 {
607 case HAL_3D_OUT_SBS_MASK:
608 // x, y, w, h
609 return Dim(0, 0, whf.w/2, whf.h);
610 case HAL_3D_OUT_TOP_BOT_MASK:
611 return Dim(0, 0, whf.w, whf.h/2);
612 case HAL_3D_OUT_MONOS_MASK:
613 return Dim();
614 case HAL_3D_OUT_INTERL_MASK:
615 // FIXME error?
616 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
617 return Dim();
618 default:
619 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
620 whf.format);
621 }
622 return Dim();
623}
624
625template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500626inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700627{
628 switch (whf.format & OUTPUT_3D_MASK)
629 {
630 case HAL_3D_OUT_SBS_MASK:
631 return Dim(whf.w/2, 0, whf.w/2, whf.h);
632 case HAL_3D_OUT_TOP_BOT_MASK:
633 return Dim(0, whf.h/2, whf.w, whf.h/2);
634 case HAL_3D_OUT_MONOS_MASK:
635 return Dim(0, 0, whf.w, whf.h);
636 case HAL_3D_OUT_INTERL_MASK:
637 // FIXME error?
638 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
639 return Dim();
640 default:
641 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
642 whf.format);
643 }
644 return Dim();
645}
646
647template <int CHAN>
648inline bool getPositionS3D(const Whf& whf, Dim& out) {
649 out = getPositionS3DImpl<CHAN>(whf);
650 return (out != Dim());
651}
652
653template <int CHAN>
654inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
655 switch (fmt & INPUT_3D_MASK)
656 {
657 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
658 return Dim(0, 0, in.w/2, in.h);
659 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
660 return Dim(in.w/2, 0, in.w/2, in.h);
661 case HAL_3D_IN_TOP_BOTTOM:
662 return Dim(0, 0, in.w, in.h/2);
663 case HAL_3D_IN_INTERLEAVE:
664 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
665 break;
666 default:
667 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
668 break;
669 }
670 return Dim();
671}
672
673template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500674inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700675 switch (fmt & INPUT_3D_MASK)
676 {
677 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
678 return Dim(in.w/2, 0, in.w/2, in.h);
679 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
680 return Dim(0, 0, in.w/2, in.h);
681 case HAL_3D_IN_TOP_BOTTOM:
682 return Dim(0, in.h/2, in.w, in.h/2);
683 case HAL_3D_IN_INTERLEAVE:
684 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
685 break;
686 default:
687 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
688 break;
689 }
690 return Dim();
691}
692
693template <int CHAN>
694inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
695{
696 out = getCropS3DImpl<CHAN>(in, fmt);
697 return (out != Dim());
698}
699
700template <class Type>
701void swapWidthHeight(Type& width, Type& height) {
702 Type tmp = width;
703 width = height;
704 height = tmp;
705}
706
707inline void ScreenInfo::dump(const char* const s) const {
708 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
709 " bpp=%d stride=%d start/end ==",
710 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
711}
712
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700713inline bool openDev(OvFD& fd, int fbnum,
714 const char* const devpath, int flags) {
715 return overlay::open(fd, fbnum, devpath, flags);
716}
717
Saurabh Shahb121e142012-08-20 17:59:13 -0700718template <class T>
719inline void even_ceil(T& value) {
720 if(value & 1)
721 value++;
722}
723
724template <class T>
725inline void even_floor(T& value) {
726 if(value & 1)
727 value--;
728}
729
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500730inline const char* getDestStr(eDest dest) {
731 switch(dest) {
732 case OV_VG0: return "VG0";
733 case OV_RGB0: return "RGB0";
734 case OV_VG1: return "VG1";
735 case OV_RGB1: return "RGB1";
736 case OV_VG2: return "VG2";
737 case OV_RGB2: return "RGB2";
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800738 case OV_DMA0: return "DMA0";
739 case OV_DMA1: return "DMA1";
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500740 default: return "Invalid";
741 }
742 return "Invalid";
743}
744
745inline eMdpPipeType getPipeType(eDest dest) {
746 switch(dest) {
747 case OV_VG0:
748 case OV_VG1:
749 case OV_VG2:
750 return OV_MDP_PIPE_VG;
751 case OV_RGB0:
752 case OV_RGB1:
753 case OV_RGB2:
754 return OV_MDP_PIPE_RGB;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800755 case OV_DMA0:
756 case OV_DMA1:
757 return OV_MDP_PIPE_DMA;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500758 default:
759 return OV_MDP_PIPE_ANY;
760 }
761 return OV_MDP_PIPE_ANY;
762}
763
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800764void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
765void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
766void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
767void getDump(char *buf, size_t len, const char *prefix,
768 const msmfb_overlay_data& ov);
769void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
770void getDump(char *buf, size_t len, const char *prefix,
771 const msm_rotator_img_info& ov);
772void getDump(char *buf, size_t len, const char *prefix,
773 const msm_rotator_data_info& ov);
774
Naseer Ahmed29a26812012-06-14 00:56:20 -0700775} // namespace utils ends
776
777//--------------------Class Res stuff (namespace overlay only) -----------
778
779class Res {
780public:
781 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700782 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700783 // /dev/msm_rotator
784 static const char* const rotPath;
785 // /sys/class/graphics/fb1/format_3d
786 static const char* const format3DFile;
787 // /sys/class/graphics/fb1/3d_present
788 static const char* const edid3dInfoFile;
789 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
790 static const char* const barrierFile;
791};
792
793
794//--------------------Class OvFD stuff (namespace overlay only) -----------
795
Naseer Ahmed29a26812012-06-14 00:56:20 -0700796/*
797* Holds one FD
798* Dtor will NOT close the underlying FD.
799* That enables us to copy that object around
800* */
801class OvFD {
802public:
803 /* Ctor */
804 explicit OvFD();
805
806 /* dtor will NOT close the underlying FD */
807 ~OvFD();
808
809 /* Open fd using the path given by dev.
810 * return false in failure */
811 bool open(const char* const dev,
812 int flags = O_RDWR);
813
814 /* populate path */
815 void setPath(const char* const dev);
816
817 /* Close fd if we have a valid fd. */
818 bool close();
819
820 /* returns underlying fd.*/
821 int getFD() const;
822
823 /* returns true if fd is valid */
824 bool valid() const;
825
826 /* like operator= */
827 void copy(int fd);
828
829 /* dump the state of the instance */
830 void dump() const;
831private:
832 /* helper enum for determine valid/invalid fd */
833 enum { INVAL = -1 };
834
835 /* actual os fd */
836 int mFD;
837
838 /* path, for debugging */
839 char mPath[utils::MAX_PATH_LEN];
840};
841
842//-------------------Inlines--------------------------
843
844inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
845{
846 char dev_name[64] = {0};
847 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
848 return fd.open(dev_name, flags);
849}
850
851inline OvFD::OvFD() : mFD (INVAL) {
852 mPath[0] = 0;
853}
854
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700855inline OvFD::~OvFD() {
856 //no op since copy() can be used to share fd, in 3d cases.
857}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700858
859inline bool OvFD::open(const char* const dev, int flags)
860{
861 mFD = ::open(dev, flags, 0);
862 if (mFD < 0) {
863 // FIXME errno, strerror in bionic?
864 ALOGE("Cant open device %s err=%d", dev, errno);
865 return false;
866 }
867 setPath(dev);
868 return true;
869}
870
871inline void OvFD::setPath(const char* const dev)
872{
873 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
874}
875
876inline bool OvFD::close()
877{
878 int ret = 0;
879 if(valid()) {
880 ret = ::close(mFD);
881 mFD = INVAL;
882 }
883 return (ret == 0);
884}
885
886inline bool OvFD::valid() const
887{
888 return (mFD != INVAL);
889}
890
891inline int OvFD::getFD() const { return mFD; }
892
893inline void OvFD::copy(int fd) {
894 mFD = fd;
895}
896
897inline void OvFD::dump() const
898{
899 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
900 mFD, mPath);
901}
902
903//--------------- class OvFD stuff ends ---------------------
904
905} // overlay
906
907
908#endif // OVERLAY_UTILS_H