blob: 6f06b0d09288fae05bceef5ad6506c0157b13682 [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
Naseer Ahmed29a26812012-06-14 00:56:20 -070039#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <sys/stat.h>
43#include <sys/types.h>
44#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070045#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -080047// Older platforms do not support Venus.
48#ifndef VENUS_COLOR_FORMAT
Sushil Chauhanc5e61482012-08-22 17:13:32 -070049#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
50#endif
51
Naseer Ahmed29a26812012-06-14 00:56:20 -070052/*
53*
54* Collection of utilities functions/structs/enums etc...
55*
56* */
57
58// comment that out if you want to remove asserts
59// or put it as -D in Android.mk. your choice.
60#define OVERLAY_HAS_ASSERT
61
62#ifdef OVERLAY_HAS_ASSERT
63# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
64#else
65# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
66#endif // OVERLAY_HAS_ASSERT
67
68#define DEBUG_OVERLAY 0
69#define PROFILE_OVERLAY 0
70
Saurabh Shahcf053c62012-12-13 12:32:55 -080071#ifndef MDSS_MDP_RIGHT_MIXER
72#define MDSS_MDP_RIGHT_MIXER 0x100
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);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700181
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183bool getPositionS3D(const Whf& whf, Dim& out);
184
Naseer Ahmed29a26812012-06-14 00:56:20 -0700185template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700186bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
187
Naseer Ahmed29a26812012-06-14 00:56:20 -0700188template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700189void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190
191struct Dim {
192 Dim () : x(0), y(0),
193 w(0), h(0),
194 o(0) {}
195 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
196 x(_x), y(_y),
197 w(_w), h(_h) {}
198 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
199 x(_x), y(_y),
200 w(_w), h(_h),
201 o(_o) {}
202 bool check(uint32_t _w, uint32_t _h) const {
203 return (x+w <= _w && y+h <= _h);
204
205 }
206
207 bool operator==(const Dim& d) const {
208 return d.x == x && d.y == y &&
209 d.w == w && d.h == h &&
210 d.o == o;
211 }
212
213 bool operator!=(const Dim& d) const {
214 return !operator==(d);
215 }
216
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217 void dump() const;
218 uint32_t x;
219 uint32_t y;
220 uint32_t w;
221 uint32_t h;
222 uint32_t o;
223};
224
225// TODO have Whfz
226
227struct Whf {
228 Whf() : w(0), h(0), format(0), size(0) {}
229 Whf(uint32_t wi, uint32_t he, uint32_t f) :
230 w(wi), h(he), format(f), size(0) {}
231 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
232 w(wi), h(he), format(f), size(s) {}
233 // FIXME not comparing size at the moment
234 bool operator==(const Whf& whf) const {
235 return whf.w == w && whf.h == h &&
236 whf.format == format;
237 }
238 bool operator!=(const Whf& whf) const {
239 return !operator==(whf);
240 }
241 void dump() const;
242 uint32_t w;
243 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244 uint32_t format;
245 uint32_t size;
246};
247
Saurabh Shah56f610d2012-08-07 15:27:06 -0700248class ActionSafe {
249private:
250 ActionSafe() : mWidth(0.0f), mHeight(0.0f) { };
251 float mWidth;
252 float mHeight;
253 static ActionSafe *sActionSafe;
254public:
255 ~ActionSafe() { };
256 static ActionSafe* getInstance() {
257 if(!sActionSafe) {
258 sActionSafe = new ActionSafe();
259 }
260 return sActionSafe;
261 }
262 void setDimension(int w, int h) {
263 mWidth = (float)w;
264 mHeight = (float)h;
265 }
266 float getWidth() { return mWidth; }
267 float getHeight() { return mHeight; }
268};
269
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270enum { MAX_PATH_LEN = 256 };
271
Naseer Ahmed29a26812012-06-14 00:56:20 -0700272/**
273 * Rotator flags: not to be confused with orientation flags.
274 * Ususally, you want to open the rotator to make sure it is
275 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500276 * ROT_FLAG_DISABLED: Rotator not used unless required.
277 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700278 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800279 enum eRotFlags {
280 ROT_FLAGS_NONE = 0,
281 //Use rotator for 0 rotation. It is used anyway for others.
282 ROT_0_ENABLED = 1 << 0,
283 //Enable rotator downscale optimization for hardware bugs not handled in
284 //driver. If downscale optimizatation is required,
285 //then rotator will be used even if its 0 rotation case.
286 ROT_DOWNSCALE_ENABLED = 1 << 1,
287};
288
289enum eRotDownscale {
290 ROT_DS_NONE = 0,
291 ROT_DS_HALF = 1,
292 ROT_DS_FOURTH = 2,
293 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700294};
295
Naseer Ahmed29a26812012-06-14 00:56:20 -0700296/* The values for is_fg flag for control alpha and transp
297 * IS_FG_OFF means is_fg = 0
298 * IS_FG_SET means is_fg = 1
299 */
300enum eIsFg {
301 IS_FG_OFF = 0,
302 IS_FG_SET = 1
303};
304
305/*
306 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
307 * kernel/common/linux/msm_mdp.h
308 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
309 * */
310enum eMdpFlags {
311 OV_MDP_FLAGS_NONE = 0,
312 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
313 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700314 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
315 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
316 OV_MDP_MEMORY_ID_TYPE_FB = MDP_MEMORY_ID_TYPE_FB,
Saurabh Shah799a3972012-09-01 12:16:12 -0700317 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700318 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700319 OV_MDP_FLIP_H = MDP_FLIP_LR,
320 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800321 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322};
323
Naseer Ahmed29a26812012-06-14 00:56:20 -0700324enum eZorder {
325 ZORDER_0,
326 ZORDER_1,
327 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500328 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700329 Z_SYSTEM_ALLOC = 0xFFFF
330};
331
332enum eMdpPipeType {
333 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500334 OV_MDP_PIPE_VG,
335 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700336};
337
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500338/* Used to identify destination pipes
339 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500341 OV_VG0 = 0,
342 OV_RGB0,
343 OV_VG1,
344 OV_RGB1,
345 OV_VG2,
346 OV_RGB2,
347 OV_INVALID,
348};
349
350/* Used when a buffer is split over 2 pipes and sent to display */
351enum {
352 OV_LEFT_SPLIT = 0,
353 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700354};
355
356/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
357enum eTransform {
358 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700359 OVERLAY_TRANSFORM_0 = 0x0,
360 /* flip source image horizontally 0x1 */
361 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
362 /* flip source image vertically 0x2 */
363 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700364 /* rotate source image 180 degrees
365 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700366 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
367 /* rotate source image 90 degrees 0x4 */
368 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
369 /* rotate source image 90 degrees and flip horizontally 0x5 */
370 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
371 HAL_TRANSFORM_FLIP_H,
372 /* rotate source image 90 degrees and flip vertically 0x6 */
373 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
374 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700375 /* rotate source image 270 degrees
376 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700377 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700378 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700379 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380};
381
382// Used to consolidate pipe params
383struct PipeArgs {
384 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700385 zorder(Z_SYSTEM_ALLOC),
386 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800387 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 }
389
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700390 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700391 eZorder z, eIsFg fg, eRotFlags r) :
392 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700394 zorder(z),
395 isFg(fg),
396 rotFlags(r) {
397 }
398
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700399 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700401 eZorder zorder; // stage number
402 eIsFg isFg; // control alpha & transp
403 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404};
405
Naseer Ahmed29a26812012-06-14 00:56:20 -0700406inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
407 f = static_cast<eMdpFlags>(setBit(f, v));
408}
409
410inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
411 f = static_cast<eMdpFlags>(clrBit(f, v));
412}
413
414// fb 0/1/2
415enum { FB0, FB1, FB2 };
416
417//Panels could be categorized as primary and external
418enum { PRIMARY, EXTERNAL };
419
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420// 2 for rgb0/1 double bufs
421enum { RGB_PIPE_NUM_BUFS = 2 };
422
423struct ScreenInfo {
424 ScreenInfo() : mFBWidth(0),
425 mFBHeight(0),
426 mFBbpp(0),
427 mFBystride(0) {}
428 void dump(const char* const s) const;
429 uint32_t mFBWidth;
430 uint32_t mFBHeight;
431 uint32_t mFBbpp;
432 uint32_t mFBystride;
433};
434
435int getMdpFormat(int format);
436int getRotOutFmt(uint32_t format);
437/* flip is upside down and such. V, H flip
438 * rotation is 90, 180 etc
439 * It returns MDP related enum/define that match rot+flip*/
440int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700441const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442
Naseer Ahmed29a26812012-06-14 00:56:20 -0700443// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
444// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
445enum { HW_OV_MAGNIFICATION_LIMIT = 20,
446 HW_OV_MINIFICATION_LIMIT = 8
447};
448
Naseer Ahmed29a26812012-06-14 00:56:20 -0700449template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700450inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700451
452template <class T> inline void swap ( T& a, T& b )
453{
454 T c(a); a=b; b=c;
455}
456
457inline int alignup(int value, int a) {
458 //if align = 0, return the value. Else, do alignment.
459 return a ? ((((value - 1) / a) + 1) * a) : value;
460}
461
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800462inline int aligndown(int value, int a) {
463 //if align = 0, return the value. Else, do alignment.
464 return a ? ((value) & ~(a-1)) : value;
465}
466
Naseer Ahmed29a26812012-06-14 00:56:20 -0700467// FIXME that align should replace the upper one.
468inline int align(int value, int a) {
469 //if align = 0, return the value. Else, do alignment.
470 return a ? ((value + (a-1)) & ~(a-1)) : value;
471}
472
Naseer Ahmed29a26812012-06-14 00:56:20 -0700473enum eRotOutFmt {
474 ROT_OUT_FMT_DEFAULT,
475 ROT_OUT_FMT_Y_CRCB_H2V2
476};
477
478template <int ROT_OUT_FMT> struct RotOutFmt;
479
480// FIXME, taken from gralloc_priv.h. Need to
481// put it back as soon as overlay takes place of the old one
482/* possible formats for 3D content*/
483enum {
484 HAL_NO_3D = 0x0000,
485 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
486 HAL_3D_IN_TOP_BOTTOM = 0x20000,
487 HAL_3D_IN_INTERLEAVE = 0x40000,
488 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
489 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
490 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
491 HAL_3D_OUT_INTERLEAVE = 0x4000,
492 HAL_3D_OUT_MONOSCOPIC = 0x8000
493};
494
495enum { HAL_3D_OUT_SBS_MASK =
496 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
497 HAL_3D_OUT_TOP_BOT_MASK =
498 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
499 HAL_3D_OUT_INTERL_MASK =
500 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
501 HAL_3D_OUT_MONOS_MASK =
502 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
503};
504
505
506inline bool isYuv(uint32_t format) {
507 switch(format){
508 case MDP_Y_CBCR_H2V1:
509 case MDP_Y_CBCR_H2V2:
510 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700511 case MDP_Y_CRCB_H1V1:
512 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700513 case MDP_Y_CRCB_H2V2_TILE:
514 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700515 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700516 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700517 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700518 return true;
519 default:
520 return false;
521 }
522 return false;
523}
524
525inline bool isRgb(uint32_t format) {
526 switch(format) {
527 case MDP_RGBA_8888:
528 case MDP_BGRA_8888:
529 case MDP_RGBX_8888:
530 case MDP_RGB_565:
531 return true;
532 default:
533 return false;
534 }
535 return false;
536}
537
Saurabh Shah9c876d92012-08-25 19:29:53 -0700538inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700539 static const char* const formats[] = {
540 "MDP_RGB_565",
541 "MDP_XRGB_8888",
542 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700543 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700544 "MDP_ARGB_8888",
545 "MDP_RGB_888",
546 "MDP_Y_CRCB_H2V2",
547 "MDP_YCRYCB_H2V1",
548 "MDP_Y_CRCB_H2V1",
549 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700550 "MDP_Y_CRCB_H1V2",
551 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700552 "MDP_RGBA_8888",
553 "MDP_BGRA_8888",
554 "MDP_RGBX_8888",
555 "MDP_Y_CRCB_H2V2_TILE",
556 "MDP_Y_CBCR_H2V2_TILE",
557 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700558 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700559 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700560 "MDP_Y_CRCB_H1V1",
561 "MDP_Y_CBCR_H1V1",
562 "MDP_YCRCB_H1V1",
563 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700564 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700565 "MDP_BGR_888",
566 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700567 "MDP_IMGTYPE_LIMIT",
568 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700569 "MDP_FB_FORMAT",
570 "MDP_IMGTYPE_LIMIT2"
571 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700572 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
573 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
574 return "Unsupported format";
575 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700576 return formats[format];
577}
578
Naseer Ahmed29a26812012-06-14 00:56:20 -0700579inline void Whf::dump() const {
580 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
581 w, h, format, size);
582}
583
584inline void Dim::dump() const {
585 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
586}
587
588inline int getMdpOrient(eTransform rotation) {
589 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700590 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700591 {
592 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700593 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
594 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
595 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700596 //getMdpOrient will switch the flips if the source is 90 rotated.
597 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700598 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700599 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700600 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
601 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700602 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
603 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700604 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700605 ALOGE("%s: invalid rotation value (value = 0x%x",
606 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700607 }
608 return -1;
609}
610
611inline int getRotOutFmt(uint32_t format) {
612 switch (format) {
613 case MDP_Y_CRCB_H2V2_TILE:
614 return MDP_Y_CRCB_H2V2;
615 case MDP_Y_CBCR_H2V2_TILE:
616 return MDP_Y_CBCR_H2V2;
617 case MDP_Y_CB_CR_H2V2:
618 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700619 case MDP_Y_CR_CB_GH2V2:
620 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700621 default:
622 return format;
623 }
624 // not reached
625 OVASSERT(false, "%s not reached", __FUNCTION__);
626 return -1;
627}
628
Naseer Ahmed29a26812012-06-14 00:56:20 -0700629
630inline uint32_t getColorFormat(uint32_t format)
631{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700632 return (format == HAL_PIXEL_FORMAT_YV12) ?
633 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700634}
635
636// FB0
637template <int CHAN>
638inline Dim getPositionS3DImpl(const Whf& whf)
639{
640 switch (whf.format & OUTPUT_3D_MASK)
641 {
642 case HAL_3D_OUT_SBS_MASK:
643 // x, y, w, h
644 return Dim(0, 0, whf.w/2, whf.h);
645 case HAL_3D_OUT_TOP_BOT_MASK:
646 return Dim(0, 0, whf.w, whf.h/2);
647 case HAL_3D_OUT_MONOS_MASK:
648 return Dim();
649 case HAL_3D_OUT_INTERL_MASK:
650 // FIXME error?
651 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
652 return Dim();
653 default:
654 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
655 whf.format);
656 }
657 return Dim();
658}
659
660template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500661inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700662{
663 switch (whf.format & OUTPUT_3D_MASK)
664 {
665 case HAL_3D_OUT_SBS_MASK:
666 return Dim(whf.w/2, 0, whf.w/2, whf.h);
667 case HAL_3D_OUT_TOP_BOT_MASK:
668 return Dim(0, whf.h/2, whf.w, whf.h/2);
669 case HAL_3D_OUT_MONOS_MASK:
670 return Dim(0, 0, whf.w, whf.h);
671 case HAL_3D_OUT_INTERL_MASK:
672 // FIXME error?
673 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
674 return Dim();
675 default:
676 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
677 whf.format);
678 }
679 return Dim();
680}
681
682template <int CHAN>
683inline bool getPositionS3D(const Whf& whf, Dim& out) {
684 out = getPositionS3DImpl<CHAN>(whf);
685 return (out != Dim());
686}
687
688template <int CHAN>
689inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
690 switch (fmt & INPUT_3D_MASK)
691 {
692 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
693 return Dim(0, 0, in.w/2, in.h);
694 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
695 return Dim(in.w/2, 0, in.w/2, in.h);
696 case HAL_3D_IN_TOP_BOTTOM:
697 return Dim(0, 0, in.w, in.h/2);
698 case HAL_3D_IN_INTERLEAVE:
699 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
700 break;
701 default:
702 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
703 break;
704 }
705 return Dim();
706}
707
708template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500709inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700710 switch (fmt & INPUT_3D_MASK)
711 {
712 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
713 return Dim(in.w/2, 0, in.w/2, in.h);
714 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
715 return Dim(0, 0, in.w/2, in.h);
716 case HAL_3D_IN_TOP_BOTTOM:
717 return Dim(0, in.h/2, in.w, in.h/2);
718 case HAL_3D_IN_INTERLEAVE:
719 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
720 break;
721 default:
722 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
723 break;
724 }
725 return Dim();
726}
727
728template <int CHAN>
729inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
730{
731 out = getCropS3DImpl<CHAN>(in, fmt);
732 return (out != Dim());
733}
734
735template <class Type>
736void swapWidthHeight(Type& width, Type& height) {
737 Type tmp = width;
738 width = height;
739 height = tmp;
740}
741
742inline void ScreenInfo::dump(const char* const s) const {
743 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
744 " bpp=%d stride=%d start/end ==",
745 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
746}
747
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700748inline bool openDev(OvFD& fd, int fbnum,
749 const char* const devpath, int flags) {
750 return overlay::open(fd, fbnum, devpath, flags);
751}
752
Saurabh Shahb121e142012-08-20 17:59:13 -0700753template <class T>
754inline void even_ceil(T& value) {
755 if(value & 1)
756 value++;
757}
758
759template <class T>
760inline void even_floor(T& value) {
761 if(value & 1)
762 value--;
763}
764
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500765inline const char* getDestStr(eDest dest) {
766 switch(dest) {
767 case OV_VG0: return "VG0";
768 case OV_RGB0: return "RGB0";
769 case OV_VG1: return "VG1";
770 case OV_RGB1: return "RGB1";
771 case OV_VG2: return "VG2";
772 case OV_RGB2: return "RGB2";
773 default: return "Invalid";
774 }
775 return "Invalid";
776}
777
778inline eMdpPipeType getPipeType(eDest dest) {
779 switch(dest) {
780 case OV_VG0:
781 case OV_VG1:
782 case OV_VG2:
783 return OV_MDP_PIPE_VG;
784 case OV_RGB0:
785 case OV_RGB1:
786 case OV_RGB2:
787 return OV_MDP_PIPE_RGB;
788 default:
789 return OV_MDP_PIPE_ANY;
790 }
791 return OV_MDP_PIPE_ANY;
792}
793
Naseer Ahmed29a26812012-06-14 00:56:20 -0700794} // namespace utils ends
795
796//--------------------Class Res stuff (namespace overlay only) -----------
797
798class Res {
799public:
800 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700801 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700802 // /dev/msm_rotator
803 static const char* const rotPath;
804 // /sys/class/graphics/fb1/format_3d
805 static const char* const format3DFile;
806 // /sys/class/graphics/fb1/3d_present
807 static const char* const edid3dInfoFile;
808 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
809 static const char* const barrierFile;
810};
811
812
813//--------------------Class OvFD stuff (namespace overlay only) -----------
814
Naseer Ahmed29a26812012-06-14 00:56:20 -0700815/*
816* Holds one FD
817* Dtor will NOT close the underlying FD.
818* That enables us to copy that object around
819* */
820class OvFD {
821public:
822 /* Ctor */
823 explicit OvFD();
824
825 /* dtor will NOT close the underlying FD */
826 ~OvFD();
827
828 /* Open fd using the path given by dev.
829 * return false in failure */
830 bool open(const char* const dev,
831 int flags = O_RDWR);
832
833 /* populate path */
834 void setPath(const char* const dev);
835
836 /* Close fd if we have a valid fd. */
837 bool close();
838
839 /* returns underlying fd.*/
840 int getFD() const;
841
842 /* returns true if fd is valid */
843 bool valid() const;
844
845 /* like operator= */
846 void copy(int fd);
847
848 /* dump the state of the instance */
849 void dump() const;
850private:
851 /* helper enum for determine valid/invalid fd */
852 enum { INVAL = -1 };
853
854 /* actual os fd */
855 int mFD;
856
857 /* path, for debugging */
858 char mPath[utils::MAX_PATH_LEN];
859};
860
861//-------------------Inlines--------------------------
862
863inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
864{
865 char dev_name[64] = {0};
866 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
867 return fd.open(dev_name, flags);
868}
869
870inline OvFD::OvFD() : mFD (INVAL) {
871 mPath[0] = 0;
872}
873
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700874inline OvFD::~OvFD() {
875 //no op since copy() can be used to share fd, in 3d cases.
876}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700877
878inline bool OvFD::open(const char* const dev, int flags)
879{
880 mFD = ::open(dev, flags, 0);
881 if (mFD < 0) {
882 // FIXME errno, strerror in bionic?
883 ALOGE("Cant open device %s err=%d", dev, errno);
884 return false;
885 }
886 setPath(dev);
887 return true;
888}
889
890inline void OvFD::setPath(const char* const dev)
891{
892 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
893}
894
895inline bool OvFD::close()
896{
897 int ret = 0;
898 if(valid()) {
899 ret = ::close(mFD);
900 mFD = INVAL;
901 }
902 return (ret == 0);
903}
904
905inline bool OvFD::valid() const
906{
907 return (mFD != INVAL);
908}
909
910inline int OvFD::getFD() const { return mFD; }
911
912inline void OvFD::copy(int fd) {
913 mFD = fd;
914}
915
916inline void OvFD::dump() const
917{
918 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
919 mFD, mPath);
920}
921
922//--------------- class OvFD stuff ends ---------------------
923
924} // overlay
925
926
927#endif // OVERLAY_UTILS_H