blob: 946748e1586978ab0d5c71baef4e06a40cd8fcc2 [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 Chauhan81c4e7d2012-12-27 22:52:30 -080048// Older platforms do not support Venus.
49#ifndef VENUS_COLOR_FORMAT
Sushil Chauhanc5e61482012-08-22 17:13:32 -070050#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
Naseer Ahmed29a26812012-06-14 00:56:20 -070076namespace overlay {
77
78// fwd
79class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070080class OvFD;
81
82/* helper function to open by using fbnum */
83bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
84 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070085
86namespace utils {
87struct Whf;
88struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070089
90inline uint32_t setBit(uint32_t x, uint32_t mask) {
91 return (x | mask);
92}
93
94inline uint32_t clrBit(uint32_t x, uint32_t mask) {
95 return (x & ~mask);
96}
97
98/* Utility class to help avoid copying instances by making the copy ctor
99* and assignment operator private
100*
101* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700102* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700103*/
104class NoCopy {
105protected:
106 NoCopy(){}
107 ~NoCopy() {}
108private:
109 NoCopy(const NoCopy&);
110 const NoCopy& operator=(const NoCopy&);
111};
112
113/*
114* Utility class to query the framebuffer info for primary display
115*
116* Usage:
117* Outside of functions:
118* utils::FrameBufferInfo* utils::FrameBufferInfo::sFBInfoInstance = 0;
119* Inside functions:
120* utils::FrameBufferInfo::getInstance()->supportTrueMirroring()
121*/
122class FrameBufferInfo {
123
124public:
125 /* ctor init */
126 explicit FrameBufferInfo();
127
128 /* Gets an instance if one does not already exist */
129 static FrameBufferInfo* getInstance();
130
131 /* Gets width of primary framebuffer */
132 int getWidth() const;
133
134 /* Gets height of primary framebuffer */
135 int getHeight() const;
136
Naseer Ahmed29a26812012-06-14 00:56:20 -0700137private:
138 int mFBWidth;
139 int mFBHeight;
140 bool mBorderFillSupported;
141 static FrameBufferInfo *sFBInfoInstance;
142};
143
144/* 3D related utils, defines etc...
145 * The compound format passed to the overlay is
146 * ABCCC where A is the input 3D format
147 * B is the output 3D format
148 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
149enum { SHIFT_OUT_3D = 12,
150 SHIFT_TOT_3D = 16 };
151enum { INPUT_3D_MASK = 0xFFFF0000,
152 OUTPUT_3D_MASK = 0x0000FFFF };
153enum { BARRIER_LAND = 1,
154 BARRIER_PORT = 2 };
155
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700156/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
157 * close all the pipes if it is opened after reboot.
158 */
159int initOverlay(void);
160
Naseer Ahmed29a26812012-06-14 00:56:20 -0700161inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700162inline uint32_t colorFormat(uint32_t fmt) {
163 /*TODO enable this block only if format has interlace / 3D info in top bits.
164 if(fmt & INTERLACE_MASK) {
165 fmt = fmt ^ HAL_PIXEL_FORMAT_INTERLACE;
166 }
167 fmt = fmt & 0xFFF;*/
168 return fmt;
169}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700170inline uint32_t format3DOutput(uint32_t x) {
171 return (x & 0xF000) >> SHIFT_OUT_3D; }
172inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
173uint32_t getColorFormat(uint32_t format);
174
175bool isHDMIConnected ();
176bool is3DTV();
177bool isPanel3D();
178bool usePanel3D();
179bool send3DInfoPacket (uint32_t fmt);
180bool enableBarrier (uint32_t orientation);
181uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800182bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700183
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700185bool getPositionS3D(const Whf& whf, Dim& out);
186
Naseer Ahmed29a26812012-06-14 00:56:20 -0700187template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700188bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700191void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700192
193struct Dim {
194 Dim () : x(0), y(0),
195 w(0), h(0),
196 o(0) {}
197 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
198 x(_x), y(_y),
199 w(_w), h(_h) {}
200 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
201 x(_x), y(_y),
202 w(_w), h(_h),
203 o(_o) {}
204 bool check(uint32_t _w, uint32_t _h) const {
205 return (x+w <= _w && y+h <= _h);
206
207 }
208
209 bool operator==(const Dim& d) const {
210 return d.x == x && d.y == y &&
211 d.w == w && d.h == h &&
212 d.o == o;
213 }
214
215 bool operator!=(const Dim& d) const {
216 return !operator==(d);
217 }
218
Naseer Ahmed29a26812012-06-14 00:56:20 -0700219 void dump() const;
220 uint32_t x;
221 uint32_t y;
222 uint32_t w;
223 uint32_t h;
224 uint32_t o;
225};
226
227// TODO have Whfz
228
229struct Whf {
230 Whf() : w(0), h(0), format(0), size(0) {}
231 Whf(uint32_t wi, uint32_t he, uint32_t f) :
232 w(wi), h(he), format(f), size(0) {}
233 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
234 w(wi), h(he), format(f), size(s) {}
235 // FIXME not comparing size at the moment
236 bool operator==(const Whf& whf) const {
237 return whf.w == w && whf.h == h &&
238 whf.format == format;
239 }
240 bool operator!=(const Whf& whf) const {
241 return !operator==(whf);
242 }
243 void dump() const;
244 uint32_t w;
245 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246 uint32_t format;
247 uint32_t size;
248};
249
250enum { MAX_PATH_LEN = 256 };
251
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252/**
253 * Rotator flags: not to be confused with orientation flags.
254 * Ususally, you want to open the rotator to make sure it is
255 * ready for business.
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 * ROT_FLAG_DISABLED: Rotator not used unless required.
257 * ROT_FLAG_ENABLED: Rotator used even if not required.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800259 enum eRotFlags {
260 ROT_FLAGS_NONE = 0,
261 //Use rotator for 0 rotation. It is used anyway for others.
262 ROT_0_ENABLED = 1 << 0,
263 //Enable rotator downscale optimization for hardware bugs not handled in
264 //driver. If downscale optimizatation is required,
265 //then rotator will be used even if its 0 rotation case.
266 ROT_DOWNSCALE_ENABLED = 1 << 1,
267};
268
269enum eRotDownscale {
270 ROT_DS_NONE = 0,
271 ROT_DS_HALF = 1,
272 ROT_DS_FOURTH = 2,
273 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274};
275
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276/* The values for is_fg flag for control alpha and transp
277 * IS_FG_OFF means is_fg = 0
278 * IS_FG_SET means is_fg = 1
279 */
280enum eIsFg {
281 IS_FG_OFF = 0,
282 IS_FG_SET = 1
283};
284
285/*
286 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
287 * kernel/common/linux/msm_mdp.h
288 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
289 * */
290enum eMdpFlags {
291 OV_MDP_FLAGS_NONE = 0,
292 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
293 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,
315 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700316};
317
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500318/* Used to identify destination pipes
319 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500321 OV_VG0 = 0,
322 OV_RGB0,
323 OV_VG1,
324 OV_RGB1,
325 OV_VG2,
326 OV_RGB2,
327 OV_INVALID,
328};
329
330/* Used when a buffer is split over 2 pipes and sent to display */
331enum {
332 OV_LEFT_SPLIT = 0,
333 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334};
335
336/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
337enum eTransform {
338 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700339 OVERLAY_TRANSFORM_0 = 0x0,
340 /* flip source image horizontally 0x1 */
341 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
342 /* flip source image vertically 0x2 */
343 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 /* rotate source image 180 degrees
345 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700346 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
347 /* rotate source image 90 degrees 0x4 */
348 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
349 /* rotate source image 90 degrees and flip horizontally 0x5 */
350 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
351 HAL_TRANSFORM_FLIP_H,
352 /* rotate source image 90 degrees and flip vertically 0x6 */
353 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
354 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700355 /* rotate source image 270 degrees
356 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700357 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700358 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700359 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700360};
361
362// Used to consolidate pipe params
363struct PipeArgs {
364 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365 zorder(Z_SYSTEM_ALLOC),
366 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800367 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700368 }
369
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700370 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700371 eZorder z, eIsFg fg, eRotFlags r) :
372 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700373 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700374 zorder(z),
375 isFg(fg),
376 rotFlags(r) {
377 }
378
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700379 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700380 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381 eZorder zorder; // stage number
382 eIsFg isFg; // control alpha & transp
383 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700384};
385
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
387 f = static_cast<eMdpFlags>(setBit(f, v));
388}
389
390inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
391 f = static_cast<eMdpFlags>(clrBit(f, v));
392}
393
394// fb 0/1/2
395enum { FB0, FB1, FB2 };
396
397//Panels could be categorized as primary and external
398enum { PRIMARY, EXTERNAL };
399
Naseer Ahmed29a26812012-06-14 00:56:20 -0700400// 2 for rgb0/1 double bufs
401enum { RGB_PIPE_NUM_BUFS = 2 };
402
403struct ScreenInfo {
404 ScreenInfo() : mFBWidth(0),
405 mFBHeight(0),
406 mFBbpp(0),
407 mFBystride(0) {}
408 void dump(const char* const s) const;
409 uint32_t mFBWidth;
410 uint32_t mFBHeight;
411 uint32_t mFBbpp;
412 uint32_t mFBystride;
413};
414
415int getMdpFormat(int format);
416int getRotOutFmt(uint32_t format);
417/* flip is upside down and such. V, H flip
418 * rotation is 90, 180 etc
419 * It returns MDP related enum/define that match rot+flip*/
420int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700421const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700422
Naseer Ahmed29a26812012-06-14 00:56:20 -0700423// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
424// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
425enum { HW_OV_MAGNIFICATION_LIMIT = 20,
426 HW_OV_MINIFICATION_LIMIT = 8
427};
428
Naseer Ahmed29a26812012-06-14 00:56:20 -0700429template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700430inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700431
432template <class T> inline void swap ( T& a, T& b )
433{
434 T c(a); a=b; b=c;
435}
436
437inline int alignup(int value, int a) {
438 //if align = 0, return the value. Else, do alignment.
439 return a ? ((((value - 1) / a) + 1) * a) : value;
440}
441
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800442inline int aligndown(int value, int a) {
443 //if align = 0, return the value. Else, do alignment.
444 return a ? ((value) & ~(a-1)) : value;
445}
446
Naseer Ahmed29a26812012-06-14 00:56:20 -0700447// FIXME that align should replace the upper one.
448inline int align(int value, int a) {
449 //if align = 0, return the value. Else, do alignment.
450 return a ? ((value + (a-1)) & ~(a-1)) : value;
451}
452
Naseer Ahmed29a26812012-06-14 00:56:20 -0700453enum eRotOutFmt {
454 ROT_OUT_FMT_DEFAULT,
455 ROT_OUT_FMT_Y_CRCB_H2V2
456};
457
458template <int ROT_OUT_FMT> struct RotOutFmt;
459
460// FIXME, taken from gralloc_priv.h. Need to
461// put it back as soon as overlay takes place of the old one
462/* possible formats for 3D content*/
463enum {
464 HAL_NO_3D = 0x0000,
465 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
466 HAL_3D_IN_TOP_BOTTOM = 0x20000,
467 HAL_3D_IN_INTERLEAVE = 0x40000,
468 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
469 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
470 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
471 HAL_3D_OUT_INTERLEAVE = 0x4000,
472 HAL_3D_OUT_MONOSCOPIC = 0x8000
473};
474
475enum { HAL_3D_OUT_SBS_MASK =
476 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
477 HAL_3D_OUT_TOP_BOT_MASK =
478 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
479 HAL_3D_OUT_INTERL_MASK =
480 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
481 HAL_3D_OUT_MONOS_MASK =
482 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
483};
484
485
486inline bool isYuv(uint32_t format) {
487 switch(format){
488 case MDP_Y_CBCR_H2V1:
489 case MDP_Y_CBCR_H2V2:
490 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700491 case MDP_Y_CRCB_H1V1:
492 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700493 case MDP_Y_CRCB_H2V2_TILE:
494 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700495 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700496 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700497 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700498 return true;
499 default:
500 return false;
501 }
502 return false;
503}
504
505inline bool isRgb(uint32_t format) {
506 switch(format) {
507 case MDP_RGBA_8888:
508 case MDP_BGRA_8888:
509 case MDP_RGBX_8888:
510 case MDP_RGB_565:
511 return true;
512 default:
513 return false;
514 }
515 return false;
516}
517
Saurabh Shah9c876d92012-08-25 19:29:53 -0700518inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700519 static const char* const formats[] = {
520 "MDP_RGB_565",
521 "MDP_XRGB_8888",
522 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700523 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700524 "MDP_ARGB_8888",
525 "MDP_RGB_888",
526 "MDP_Y_CRCB_H2V2",
527 "MDP_YCRYCB_H2V1",
528 "MDP_Y_CRCB_H2V1",
529 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700530 "MDP_Y_CRCB_H1V2",
531 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700532 "MDP_RGBA_8888",
533 "MDP_BGRA_8888",
534 "MDP_RGBX_8888",
535 "MDP_Y_CRCB_H2V2_TILE",
536 "MDP_Y_CBCR_H2V2_TILE",
537 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700538 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700539 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700540 "MDP_Y_CRCB_H1V1",
541 "MDP_Y_CBCR_H1V1",
542 "MDP_YCRCB_H1V1",
543 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700544 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700545 "MDP_BGR_888",
546 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700547 "MDP_IMGTYPE_LIMIT",
548 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700549 "MDP_FB_FORMAT",
550 "MDP_IMGTYPE_LIMIT2"
551 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700552 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
553 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
554 return "Unsupported format";
555 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700556 return formats[format];
557}
558
Naseer Ahmed29a26812012-06-14 00:56:20 -0700559inline void Whf::dump() const {
560 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
561 w, h, format, size);
562}
563
564inline void Dim::dump() const {
565 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
566}
567
568inline int getMdpOrient(eTransform rotation) {
569 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700570 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700571 {
572 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700573 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
574 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
575 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700576 //getMdpOrient will switch the flips if the source is 90 rotated.
577 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700578 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700579 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700580 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
581 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700582 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
583 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700584 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700585 ALOGE("%s: invalid rotation value (value = 0x%x",
586 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700587 }
588 return -1;
589}
590
591inline int getRotOutFmt(uint32_t format) {
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800592
593 if (isMdssRotator())
594 return format;
595
Naseer Ahmed29a26812012-06-14 00:56:20 -0700596 switch (format) {
597 case MDP_Y_CRCB_H2V2_TILE:
598 return MDP_Y_CRCB_H2V2;
599 case MDP_Y_CBCR_H2V2_TILE:
600 return MDP_Y_CBCR_H2V2;
601 case MDP_Y_CB_CR_H2V2:
602 return MDP_Y_CBCR_H2V2;
Saurabh Shahae1044e2012-08-21 16:03:32 -0700603 case MDP_Y_CR_CB_GH2V2:
604 return MDP_Y_CRCB_H2V2;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700605 default:
606 return format;
607 }
608 // not reached
609 OVASSERT(false, "%s not reached", __FUNCTION__);
610 return -1;
611}
612
Naseer Ahmed29a26812012-06-14 00:56:20 -0700613
614inline uint32_t getColorFormat(uint32_t format)
615{
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700616 return (format == HAL_PIXEL_FORMAT_YV12) ?
617 format : colorFormat(format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700618}
619
620// FB0
621template <int CHAN>
622inline Dim getPositionS3DImpl(const Whf& whf)
623{
624 switch (whf.format & OUTPUT_3D_MASK)
625 {
626 case HAL_3D_OUT_SBS_MASK:
627 // x, y, w, h
628 return Dim(0, 0, whf.w/2, whf.h);
629 case HAL_3D_OUT_TOP_BOT_MASK:
630 return Dim(0, 0, whf.w, whf.h/2);
631 case HAL_3D_OUT_MONOS_MASK:
632 return Dim();
633 case HAL_3D_OUT_INTERL_MASK:
634 // FIXME error?
635 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
636 return Dim();
637 default:
638 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
639 whf.format);
640 }
641 return Dim();
642}
643
644template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500645inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700646{
647 switch (whf.format & OUTPUT_3D_MASK)
648 {
649 case HAL_3D_OUT_SBS_MASK:
650 return Dim(whf.w/2, 0, whf.w/2, whf.h);
651 case HAL_3D_OUT_TOP_BOT_MASK:
652 return Dim(0, whf.h/2, whf.w, whf.h/2);
653 case HAL_3D_OUT_MONOS_MASK:
654 return Dim(0, 0, whf.w, whf.h);
655 case HAL_3D_OUT_INTERL_MASK:
656 // FIXME error?
657 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
658 return Dim();
659 default:
660 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
661 whf.format);
662 }
663 return Dim();
664}
665
666template <int CHAN>
667inline bool getPositionS3D(const Whf& whf, Dim& out) {
668 out = getPositionS3DImpl<CHAN>(whf);
669 return (out != Dim());
670}
671
672template <int CHAN>
673inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
674 switch (fmt & INPUT_3D_MASK)
675 {
676 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
677 return Dim(0, 0, in.w/2, in.h);
678 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
679 return Dim(in.w/2, 0, in.w/2, in.h);
680 case HAL_3D_IN_TOP_BOTTOM:
681 return Dim(0, 0, in.w, in.h/2);
682 case HAL_3D_IN_INTERLEAVE:
683 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
684 break;
685 default:
686 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
687 break;
688 }
689 return Dim();
690}
691
692template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500693inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700694 switch (fmt & INPUT_3D_MASK)
695 {
696 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
697 return Dim(in.w/2, 0, in.w/2, in.h);
698 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
699 return Dim(0, 0, in.w/2, in.h);
700 case HAL_3D_IN_TOP_BOTTOM:
701 return Dim(0, in.h/2, in.w, in.h/2);
702 case HAL_3D_IN_INTERLEAVE:
703 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
704 break;
705 default:
706 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
707 break;
708 }
709 return Dim();
710}
711
712template <int CHAN>
713inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
714{
715 out = getCropS3DImpl<CHAN>(in, fmt);
716 return (out != Dim());
717}
718
719template <class Type>
720void swapWidthHeight(Type& width, Type& height) {
721 Type tmp = width;
722 width = height;
723 height = tmp;
724}
725
726inline void ScreenInfo::dump(const char* const s) const {
727 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
728 " bpp=%d stride=%d start/end ==",
729 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
730}
731
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700732inline bool openDev(OvFD& fd, int fbnum,
733 const char* const devpath, int flags) {
734 return overlay::open(fd, fbnum, devpath, flags);
735}
736
Saurabh Shahb121e142012-08-20 17:59:13 -0700737template <class T>
738inline void even_ceil(T& value) {
739 if(value & 1)
740 value++;
741}
742
743template <class T>
744inline void even_floor(T& value) {
745 if(value & 1)
746 value--;
747}
748
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500749inline const char* getDestStr(eDest dest) {
750 switch(dest) {
751 case OV_VG0: return "VG0";
752 case OV_RGB0: return "RGB0";
753 case OV_VG1: return "VG1";
754 case OV_RGB1: return "RGB1";
755 case OV_VG2: return "VG2";
756 case OV_RGB2: return "RGB2";
757 default: return "Invalid";
758 }
759 return "Invalid";
760}
761
762inline eMdpPipeType getPipeType(eDest dest) {
763 switch(dest) {
764 case OV_VG0:
765 case OV_VG1:
766 case OV_VG2:
767 return OV_MDP_PIPE_VG;
768 case OV_RGB0:
769 case OV_RGB1:
770 case OV_RGB2:
771 return OV_MDP_PIPE_RGB;
772 default:
773 return OV_MDP_PIPE_ANY;
774 }
775 return OV_MDP_PIPE_ANY;
776}
777
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800778void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
779void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
780void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
781void getDump(char *buf, size_t len, const char *prefix,
782 const msmfb_overlay_data& ov);
783void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
784void getDump(char *buf, size_t len, const char *prefix,
785 const msm_rotator_img_info& ov);
786void getDump(char *buf, size_t len, const char *prefix,
787 const msm_rotator_data_info& ov);
788
Naseer Ahmed29a26812012-06-14 00:56:20 -0700789} // namespace utils ends
790
791//--------------------Class Res stuff (namespace overlay only) -----------
792
793class Res {
794public:
795 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700796 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700797 // /dev/msm_rotator
798 static const char* const rotPath;
799 // /sys/class/graphics/fb1/format_3d
800 static const char* const format3DFile;
801 // /sys/class/graphics/fb1/3d_present
802 static const char* const edid3dInfoFile;
803 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
804 static const char* const barrierFile;
805};
806
807
808//--------------------Class OvFD stuff (namespace overlay only) -----------
809
Naseer Ahmed29a26812012-06-14 00:56:20 -0700810/*
811* Holds one FD
812* Dtor will NOT close the underlying FD.
813* That enables us to copy that object around
814* */
815class OvFD {
816public:
817 /* Ctor */
818 explicit OvFD();
819
820 /* dtor will NOT close the underlying FD */
821 ~OvFD();
822
823 /* Open fd using the path given by dev.
824 * return false in failure */
825 bool open(const char* const dev,
826 int flags = O_RDWR);
827
828 /* populate path */
829 void setPath(const char* const dev);
830
831 /* Close fd if we have a valid fd. */
832 bool close();
833
834 /* returns underlying fd.*/
835 int getFD() const;
836
837 /* returns true if fd is valid */
838 bool valid() const;
839
840 /* like operator= */
841 void copy(int fd);
842
843 /* dump the state of the instance */
844 void dump() const;
845private:
846 /* helper enum for determine valid/invalid fd */
847 enum { INVAL = -1 };
848
849 /* actual os fd */
850 int mFD;
851
852 /* path, for debugging */
853 char mPath[utils::MAX_PATH_LEN];
854};
855
856//-------------------Inlines--------------------------
857
858inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
859{
860 char dev_name[64] = {0};
861 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
862 return fd.open(dev_name, flags);
863}
864
865inline OvFD::OvFD() : mFD (INVAL) {
866 mPath[0] = 0;
867}
868
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700869inline OvFD::~OvFD() {
870 //no op since copy() can be used to share fd, in 3d cases.
871}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700872
873inline bool OvFD::open(const char* const dev, int flags)
874{
875 mFD = ::open(dev, flags, 0);
876 if (mFD < 0) {
877 // FIXME errno, strerror in bionic?
878 ALOGE("Cant open device %s err=%d", dev, errno);
879 return false;
880 }
881 setPath(dev);
882 return true;
883}
884
885inline void OvFD::setPath(const char* const dev)
886{
887 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
888}
889
890inline bool OvFD::close()
891{
892 int ret = 0;
893 if(valid()) {
894 ret = ::close(mFD);
895 mFD = INVAL;
896 }
897 return (ret == 0);
898}
899
900inline bool OvFD::valid() const
901{
902 return (mFD != INVAL);
903}
904
905inline int OvFD::getFD() const { return mFD; }
906
907inline void OvFD::copy(int fd) {
908 mFD = fd;
909}
910
911inline void OvFD::dump() const
912{
913 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
914 mFD, mPath);
915}
916
917//--------------- class OvFD stuff ends ---------------------
918
919} // overlay
920
921
922#endif // OVERLAY_UTILS_H