blob: 555232a5b4a8e52b3c1ed079e6cc3b4a07f99be8 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Sushil Chauhan81c4e7d2012-12-27 22:52:30 -08002* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef OVERLAY_UTILS_H
31#define OVERLAY_UTILS_H
32
33#include <cutils/log.h> // ALOGE, etc
34#include <errno.h>
35#include <fcntl.h> // open, O_RDWR, etc
36#include <hardware/hardware.h>
37#include <hardware/gralloc.h> // buffer_handle_t
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038#include <linux/msm_mdp.h> // flags
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080039#include <linux/msm_rotator.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070048// Older platforms do not support Venus
49#ifndef VENUS_COLOR_FORMAT
50#define MDP_Y_CBCR_H2V2_VENUS (MDP_IMGTYPE_LIMIT2 + 1)
51#endif
52
Naseer Ahmed29a26812012-06-14 00:56:20 -070053/*
54*
55* Collection of utilities functions/structs/enums etc...
56*
57* */
58
59// comment that out if you want to remove asserts
60// or put it as -D in Android.mk. your choice.
61#define OVERLAY_HAS_ASSERT
62
63#ifdef OVERLAY_HAS_ASSERT
64# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
65#else
66# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
67#endif // OVERLAY_HAS_ASSERT
68
69#define DEBUG_OVERLAY 0
70#define PROFILE_OVERLAY 0
71
Saurabh Shahcf053c62012-12-13 12:32:55 -080072#ifndef MDSS_MDP_RIGHT_MIXER
73#define MDSS_MDP_RIGHT_MIXER 0x100
74#endif
75
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080076#ifndef MDP_OV_PIPE_FORCE_DMA
77#define MDP_OV_PIPE_FORCE_DMA 0x4000
78#endif
79
Naseer Ahmed29a26812012-06-14 00:56:20 -070080namespace overlay {
81
82// fwd
83class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070084class OvFD;
85
86/* helper function to open by using fbnum */
87bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
88 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070089
90namespace utils {
91struct Whf;
92struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070093
94inline uint32_t setBit(uint32_t x, uint32_t mask) {
95 return (x | mask);
96}
97
98inline uint32_t clrBit(uint32_t x, uint32_t mask) {
99 return (x & ~mask);
100}
101
102/* Utility class to help avoid copying instances by making the copy ctor
103* and assignment operator private
104*
105* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700106* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700107*/
108class NoCopy {
109protected:
110 NoCopy(){}
111 ~NoCopy() {}
112private:
113 NoCopy(const NoCopy&);
114 const NoCopy& operator=(const NoCopy&);
115};
116
Naseer Ahmed29a26812012-06-14 00:56:20 -0700117
118/* 3D related utils, defines etc...
119 * The compound format passed to the overlay is
120 * ABCCC where A is the input 3D format
121 * B is the output 3D format
122 * CCC is the color format e.g YCbCr420SP YCrCb420SP etc */
123enum { SHIFT_OUT_3D = 12,
124 SHIFT_TOT_3D = 16 };
125enum { INPUT_3D_MASK = 0xFFFF0000,
126 OUTPUT_3D_MASK = 0x0000FFFF };
127enum { BARRIER_LAND = 1,
128 BARRIER_PORT = 2 };
129
Ajay Dudanicb3da0a2012-09-07 13:37:49 -0700130/* if SurfaceFlinger process gets killed in bypass mode, In initOverlay()
131 * close all the pipes if it is opened after reboot.
132 */
133int initOverlay(void);
134
Naseer Ahmed29a26812012-06-14 00:56:20 -0700135inline uint32_t format3D(uint32_t x) { return x & 0xFF000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700136inline uint32_t format3DOutput(uint32_t x) {
137 return (x & 0xF000) >> SHIFT_OUT_3D; }
138inline uint32_t format3DInput(uint32_t x) { return x & 0xF0000; }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700139
140bool isHDMIConnected ();
141bool is3DTV();
142bool isPanel3D();
143bool usePanel3D();
144bool send3DInfoPacket (uint32_t fmt);
145bool enableBarrier (uint32_t orientation);
146uint32_t getS3DFormat(uint32_t fmt);
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800147bool isMdssRotator();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700148
Naseer Ahmed29a26812012-06-14 00:56:20 -0700149template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700150bool getPositionS3D(const Whf& whf, Dim& out);
151
Naseer Ahmed29a26812012-06-14 00:56:20 -0700152template <int CHAN>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700153bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt);
154
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700156void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700157
158struct Dim {
159 Dim () : x(0), y(0),
160 w(0), h(0),
161 o(0) {}
162 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
163 x(_x), y(_y),
164 w(_w), h(_h) {}
165 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
166 x(_x), y(_y),
167 w(_w), h(_h),
168 o(_o) {}
169 bool check(uint32_t _w, uint32_t _h) const {
170 return (x+w <= _w && y+h <= _h);
171
172 }
173
174 bool operator==(const Dim& d) const {
175 return d.x == x && d.y == y &&
176 d.w == w && d.h == h &&
177 d.o == o;
178 }
179
180 bool operator!=(const Dim& d) const {
181 return !operator==(d);
182 }
183
Naseer Ahmed29a26812012-06-14 00:56:20 -0700184 void dump() const;
185 uint32_t x;
186 uint32_t y;
187 uint32_t w;
188 uint32_t h;
189 uint32_t o;
190};
191
192// TODO have Whfz
193
194struct Whf {
195 Whf() : w(0), h(0), format(0), size(0) {}
196 Whf(uint32_t wi, uint32_t he, uint32_t f) :
197 w(wi), h(he), format(f), size(0) {}
198 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
199 w(wi), h(he), format(f), size(s) {}
200 // FIXME not comparing size at the moment
201 bool operator==(const Whf& whf) const {
202 return whf.w == w && whf.h == h &&
203 whf.format == format;
204 }
205 bool operator!=(const Whf& whf) const {
206 return !operator==(whf);
207 }
208 void dump() const;
209 uint32_t w;
210 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211 uint32_t format;
212 uint32_t size;
213};
214
215enum { MAX_PATH_LEN = 256 };
216
Naseer Ahmed29a26812012-06-14 00:56:20 -0700217/**
218 * Rotator flags: not to be confused with orientation flags.
Saurabh Shahacf10202013-02-26 10:15:15 -0800219 * Usually, you want to open the rotator to make sure it is
Naseer Ahmed29a26812012-06-14 00:56:20 -0700220 * ready for business.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700221 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800222 enum eRotFlags {
223 ROT_FLAGS_NONE = 0,
224 //Use rotator for 0 rotation. It is used anyway for others.
225 ROT_0_ENABLED = 1 << 0,
226 //Enable rotator downscale optimization for hardware bugs not handled in
227 //driver. If downscale optimizatation is required,
228 //then rotator will be used even if its 0 rotation case.
229 ROT_DOWNSCALE_ENABLED = 1 << 1,
Saurabh Shahacf10202013-02-26 10:15:15 -0800230 ROT_PREROTATED = 1 << 2,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800231};
232
233enum eRotDownscale {
234 ROT_DS_NONE = 0,
235 ROT_DS_HALF = 1,
236 ROT_DS_FOURTH = 2,
237 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700238};
239
Naseer Ahmed29a26812012-06-14 00:56:20 -0700240/* The values for is_fg flag for control alpha and transp
241 * IS_FG_OFF means is_fg = 0
242 * IS_FG_SET means is_fg = 1
243 */
244enum eIsFg {
245 IS_FG_OFF = 0,
246 IS_FG_SET = 1
247};
248
249/*
250 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
251 * kernel/common/linux/msm_mdp.h
252 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
253 * */
254enum eMdpFlags {
255 OV_MDP_FLAGS_NONE = 0,
256 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800257 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700258 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700259 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
260 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
Saurabh Shah799a3972012-09-01 12:16:12 -0700261 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700262 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700263 OV_MDP_FLIP_H = MDP_FLIP_LR,
264 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800265 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266};
267
Naseer Ahmed29a26812012-06-14 00:56:20 -0700268enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800269 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270 ZORDER_1,
271 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500272 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273 Z_SYSTEM_ALLOC = 0xFFFF
274};
275
276enum eMdpPipeType {
277 OV_MDP_PIPE_RGB,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500278 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800279 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500280 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700281};
282
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500283/* Used to identify destination pipes
284 */
Naseer Ahmed29a26812012-06-14 00:56:20 -0700285enum eDest {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500286 OV_VG0 = 0,
287 OV_RGB0,
288 OV_VG1,
289 OV_RGB1,
290 OV_VG2,
291 OV_RGB2,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800292 OV_DMA0,
293 OV_DMA1,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500294 OV_INVALID,
295};
296
297/* Used when a buffer is split over 2 pipes and sent to display */
298enum {
299 OV_LEFT_SPLIT = 0,
300 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700301};
302
303/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
304enum eTransform {
305 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700306 OVERLAY_TRANSFORM_0 = 0x0,
307 /* flip source image horizontally 0x1 */
308 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
309 /* flip source image vertically 0x2 */
310 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700311 /* rotate source image 180 degrees
312 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700313 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
314 /* rotate source image 90 degrees 0x4 */
315 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
316 /* rotate source image 90 degrees and flip horizontally 0x5 */
317 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
318 HAL_TRANSFORM_FLIP_H,
319 /* rotate source image 90 degrees and flip vertically 0x6 */
320 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
321 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322 /* rotate source image 270 degrees
323 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700324 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700326 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700327};
328
329// Used to consolidate pipe params
330struct PipeArgs {
331 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700332 zorder(Z_SYSTEM_ALLOC),
333 isFg(IS_FG_OFF),
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800334 rotFlags(ROT_FLAGS_NONE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700335 }
336
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700337 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700338 eZorder z, eIsFg fg, eRotFlags r) :
339 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700341 zorder(z),
342 isFg(fg),
343 rotFlags(r) {
344 }
345
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700346 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700347 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700348 eZorder zorder; // stage number
349 eIsFg isFg; // control alpha & transp
350 eRotFlags rotFlags;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700351};
352
Naseer Ahmed29a26812012-06-14 00:56:20 -0700353inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
354 f = static_cast<eMdpFlags>(setBit(f, v));
355}
356
357inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
358 f = static_cast<eMdpFlags>(clrBit(f, v));
359}
360
361// fb 0/1/2
362enum { FB0, FB1, FB2 };
363
364//Panels could be categorized as primary and external
365enum { PRIMARY, EXTERNAL };
366
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367// 2 for rgb0/1 double bufs
368enum { RGB_PIPE_NUM_BUFS = 2 };
369
370struct ScreenInfo {
371 ScreenInfo() : mFBWidth(0),
372 mFBHeight(0),
373 mFBbpp(0),
374 mFBystride(0) {}
375 void dump(const char* const s) const;
376 uint32_t mFBWidth;
377 uint32_t mFBHeight;
378 uint32_t mFBbpp;
379 uint32_t mFBystride;
380};
381
382int getMdpFormat(int format);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800383int getHALFormat(int mdpFormat);
Saurabh Shahacf10202013-02-26 10:15:15 -0800384int getDownscaleFactor(const int& src_w, const int& src_h,
385 const int& dst_w, const int& dst_h);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800386
Naseer Ahmed29a26812012-06-14 00:56:20 -0700387/* flip is upside down and such. V, H flip
388 * rotation is 90, 180 etc
389 * It returns MDP related enum/define that match rot+flip*/
390int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700391const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392
Naseer Ahmed29a26812012-06-14 00:56:20 -0700393// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
394// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
395enum { HW_OV_MAGNIFICATION_LIMIT = 20,
396 HW_OV_MINIFICATION_LIMIT = 8
397};
398
Naseer Ahmed29a26812012-06-14 00:56:20 -0700399template <class T>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700400inline void memset0(T& t) { ::memset(&t, 0, sizeof(T)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700401
402template <class T> inline void swap ( T& a, T& b )
403{
404 T c(a); a=b; b=c;
405}
406
407inline int alignup(int value, int a) {
408 //if align = 0, return the value. Else, do alignment.
409 return a ? ((((value - 1) / a) + 1) * a) : value;
410}
411
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800412inline int aligndown(int value, int a) {
413 //if align = 0, return the value. Else, do alignment.
414 return a ? ((value) & ~(a-1)) : value;
415}
416
Naseer Ahmed29a26812012-06-14 00:56:20 -0700417// FIXME that align should replace the upper one.
418inline int align(int value, int a) {
419 //if align = 0, return the value. Else, do alignment.
420 return a ? ((value + (a-1)) & ~(a-1)) : value;
421}
422
Naseer Ahmed29a26812012-06-14 00:56:20 -0700423enum eRotOutFmt {
424 ROT_OUT_FMT_DEFAULT,
425 ROT_OUT_FMT_Y_CRCB_H2V2
426};
427
428template <int ROT_OUT_FMT> struct RotOutFmt;
429
430// FIXME, taken from gralloc_priv.h. Need to
431// put it back as soon as overlay takes place of the old one
432/* possible formats for 3D content*/
433enum {
434 HAL_NO_3D = 0x0000,
435 HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000,
436 HAL_3D_IN_TOP_BOTTOM = 0x20000,
437 HAL_3D_IN_INTERLEAVE = 0x40000,
438 HAL_3D_IN_SIDE_BY_SIDE_R_L = 0x80000,
439 HAL_3D_OUT_SIDE_BY_SIDE = 0x1000,
440 HAL_3D_OUT_TOP_BOTTOM = 0x2000,
441 HAL_3D_OUT_INTERLEAVE = 0x4000,
442 HAL_3D_OUT_MONOSCOPIC = 0x8000
443};
444
445enum { HAL_3D_OUT_SBS_MASK =
446 HAL_3D_OUT_SIDE_BY_SIDE >> overlay::utils::SHIFT_OUT_3D,
447 HAL_3D_OUT_TOP_BOT_MASK =
448 HAL_3D_OUT_TOP_BOTTOM >> overlay::utils::SHIFT_OUT_3D,
449 HAL_3D_OUT_INTERL_MASK =
450 HAL_3D_OUT_INTERLEAVE >> overlay::utils::SHIFT_OUT_3D,
451 HAL_3D_OUT_MONOS_MASK =
452 HAL_3D_OUT_MONOSCOPIC >> overlay::utils::SHIFT_OUT_3D
453};
454
455
456inline bool isYuv(uint32_t format) {
457 switch(format){
458 case MDP_Y_CBCR_H2V1:
459 case MDP_Y_CBCR_H2V2:
460 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700461 case MDP_Y_CRCB_H1V1:
462 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700463 case MDP_Y_CRCB_H2V2_TILE:
464 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700465 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700466 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700467 case MDP_Y_CBCR_H2V2_VENUS:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700468 return true;
469 default:
470 return false;
471 }
472 return false;
473}
474
475inline bool isRgb(uint32_t format) {
476 switch(format) {
477 case MDP_RGBA_8888:
478 case MDP_BGRA_8888:
479 case MDP_RGBX_8888:
480 case MDP_RGB_565:
481 return true;
482 default:
483 return false;
484 }
485 return false;
486}
487
Saurabh Shah9c876d92012-08-25 19:29:53 -0700488inline const char* getFormatString(int format){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489 static const char* const formats[] = {
490 "MDP_RGB_565",
491 "MDP_XRGB_8888",
492 "MDP_Y_CBCR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700493 "MDP_Y_CBCR_H2V2_ADRENO",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700494 "MDP_ARGB_8888",
495 "MDP_RGB_888",
496 "MDP_Y_CRCB_H2V2",
497 "MDP_YCRYCB_H2V1",
498 "MDP_Y_CRCB_H2V1",
499 "MDP_Y_CBCR_H2V1",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700500 "MDP_Y_CRCB_H1V2",
501 "MDP_Y_CBCR_H1V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700502 "MDP_RGBA_8888",
503 "MDP_BGRA_8888",
504 "MDP_RGBX_8888",
505 "MDP_Y_CRCB_H2V2_TILE",
506 "MDP_Y_CBCR_H2V2_TILE",
507 "MDP_Y_CR_CB_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700508 "MDP_Y_CR_CB_GH2V2",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700509 "MDP_Y_CB_CR_H2V2",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700510 "MDP_Y_CRCB_H1V1",
511 "MDP_Y_CBCR_H1V1",
512 "MDP_YCRCB_H1V1",
513 "MDP_YCBCR_H1V1",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700514 "MDP_BGR_565",
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700515 "MDP_BGR_888",
516 "MDP_Y_CBCR_H2V2_VENUS",
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700517 "MDP_IMGTYPE_LIMIT",
518 "MDP_RGB_BORDERFILL",
Naseer Ahmed29a26812012-06-14 00:56:20 -0700519 "MDP_FB_FORMAT",
520 "MDP_IMGTYPE_LIMIT2"
521 };
Saurabh Shah9c876d92012-08-25 19:29:53 -0700522 if(format < 0 || format >= (int)(sizeof(formats) / sizeof(formats[0]))) {
523 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
524 return "Unsupported format";
525 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700526 return formats[format];
527}
528
Naseer Ahmed29a26812012-06-14 00:56:20 -0700529inline void Whf::dump() const {
530 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
531 w, h, format, size);
532}
533
534inline void Dim::dump() const {
535 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
536}
537
538inline int getMdpOrient(eTransform rotation) {
539 ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, rotation);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700540 switch(rotation)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700541 {
542 case OVERLAY_TRANSFORM_0 : return 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700543 case OVERLAY_TRANSFORM_FLIP_V: return MDP_FLIP_UD;
544 case OVERLAY_TRANSFORM_FLIP_H: return MDP_FLIP_LR;
545 case OVERLAY_TRANSFORM_ROT_90: return MDP_ROT_90;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700546 //getMdpOrient will switch the flips if the source is 90 rotated.
547 //Clients in Android dont factor in 90 rotation while deciding flip.
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700548 case OVERLAY_TRANSFORM_ROT_90_FLIP_V:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700549 return MDP_ROT_90 | MDP_FLIP_LR;
Saurabh Shaha73738d2012-08-09 18:15:18 -0700550 case OVERLAY_TRANSFORM_ROT_90_FLIP_H:
551 return MDP_ROT_90 | MDP_FLIP_UD;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700552 case OVERLAY_TRANSFORM_ROT_180: return MDP_ROT_180;
553 case OVERLAY_TRANSFORM_ROT_270: return MDP_ROT_270;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700554 default:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700555 ALOGE("%s: invalid rotation value (value = 0x%x",
556 __FUNCTION__, rotation);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700557 }
558 return -1;
559}
560
Naseer Ahmed29a26812012-06-14 00:56:20 -0700561// FB0
562template <int CHAN>
563inline Dim getPositionS3DImpl(const Whf& whf)
564{
565 switch (whf.format & OUTPUT_3D_MASK)
566 {
567 case HAL_3D_OUT_SBS_MASK:
568 // x, y, w, h
569 return Dim(0, 0, whf.w/2, whf.h);
570 case HAL_3D_OUT_TOP_BOT_MASK:
571 return Dim(0, 0, whf.w, whf.h/2);
572 case HAL_3D_OUT_MONOS_MASK:
573 return Dim();
574 case HAL_3D_OUT_INTERL_MASK:
575 // FIXME error?
576 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
577 return Dim();
578 default:
579 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
580 whf.format);
581 }
582 return Dim();
583}
584
585template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500586inline Dim getPositionS3DImpl<utils::OV_RIGHT_SPLIT>(const Whf& whf)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700587{
588 switch (whf.format & OUTPUT_3D_MASK)
589 {
590 case HAL_3D_OUT_SBS_MASK:
591 return Dim(whf.w/2, 0, whf.w/2, whf.h);
592 case HAL_3D_OUT_TOP_BOT_MASK:
593 return Dim(0, whf.h/2, whf.w, whf.h/2);
594 case HAL_3D_OUT_MONOS_MASK:
595 return Dim(0, 0, whf.w, whf.h);
596 case HAL_3D_OUT_INTERL_MASK:
597 // FIXME error?
598 ALOGE("%s HAL_3D_OUT_INTERLEAVE_MASK", __FUNCTION__);
599 return Dim();
600 default:
601 ALOGE("%s Unsupported 3D output format %d", __FUNCTION__,
602 whf.format);
603 }
604 return Dim();
605}
606
607template <int CHAN>
608inline bool getPositionS3D(const Whf& whf, Dim& out) {
609 out = getPositionS3DImpl<CHAN>(whf);
610 return (out != Dim());
611}
612
613template <int CHAN>
614inline Dim getCropS3DImpl(const Dim& in, uint32_t fmt) {
615 switch (fmt & INPUT_3D_MASK)
616 {
617 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
618 return Dim(0, 0, in.w/2, in.h);
619 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
620 return Dim(in.w/2, 0, in.w/2, in.h);
621 case HAL_3D_IN_TOP_BOTTOM:
622 return Dim(0, 0, in.w, in.h/2);
623 case HAL_3D_IN_INTERLEAVE:
624 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
625 break;
626 default:
627 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
628 break;
629 }
630 return Dim();
631}
632
633template <>
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500634inline Dim getCropS3DImpl<utils::OV_RIGHT_SPLIT>(const Dim& in, uint32_t fmt) {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700635 switch (fmt & INPUT_3D_MASK)
636 {
637 case HAL_3D_IN_SIDE_BY_SIDE_L_R:
638 return Dim(in.w/2, 0, in.w/2, in.h);
639 case HAL_3D_IN_SIDE_BY_SIDE_R_L:
640 return Dim(0, 0, in.w/2, in.h);
641 case HAL_3D_IN_TOP_BOTTOM:
642 return Dim(0, in.h/2, in.w, in.h/2);
643 case HAL_3D_IN_INTERLEAVE:
644 ALOGE("%s HAL_3D_IN_INTERLEAVE", __FUNCTION__);
645 break;
646 default:
647 ALOGE("%s Unsupported 3D format %d", __FUNCTION__, fmt);
648 break;
649 }
650 return Dim();
651}
652
653template <int CHAN>
654inline bool getCropS3D(const Dim& in, Dim& out, uint32_t fmt)
655{
656 out = getCropS3DImpl<CHAN>(in, fmt);
657 return (out != Dim());
658}
659
660template <class Type>
661void swapWidthHeight(Type& width, Type& height) {
662 Type tmp = width;
663 width = height;
664 height = tmp;
665}
666
667inline void ScreenInfo::dump(const char* const s) const {
668 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
669 " bpp=%d stride=%d start/end ==",
670 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
671}
672
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700673inline bool openDev(OvFD& fd, int fbnum,
674 const char* const devpath, int flags) {
675 return overlay::open(fd, fbnum, devpath, flags);
676}
677
Saurabh Shahb121e142012-08-20 17:59:13 -0700678template <class T>
679inline void even_ceil(T& value) {
680 if(value & 1)
681 value++;
682}
683
684template <class T>
685inline void even_floor(T& value) {
686 if(value & 1)
687 value--;
688}
689
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500690inline const char* getDestStr(eDest dest) {
691 switch(dest) {
692 case OV_VG0: return "VG0";
693 case OV_RGB0: return "RGB0";
694 case OV_VG1: return "VG1";
695 case OV_RGB1: return "RGB1";
696 case OV_VG2: return "VG2";
697 case OV_RGB2: return "RGB2";
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800698 case OV_DMA0: return "DMA0";
699 case OV_DMA1: return "DMA1";
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500700 default: return "Invalid";
701 }
702 return "Invalid";
703}
704
705inline eMdpPipeType getPipeType(eDest dest) {
706 switch(dest) {
707 case OV_VG0:
708 case OV_VG1:
709 case OV_VG2:
710 return OV_MDP_PIPE_VG;
711 case OV_RGB0:
712 case OV_RGB1:
713 case OV_RGB2:
714 return OV_MDP_PIPE_RGB;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800715 case OV_DMA0:
716 case OV_DMA1:
717 return OV_MDP_PIPE_DMA;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500718 default:
719 return OV_MDP_PIPE_ANY;
720 }
721 return OV_MDP_PIPE_ANY;
722}
723
Saurabh Shahacf10202013-02-26 10:15:15 -0800724void preRotateSource(eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800725void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
726void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
727void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
728void getDump(char *buf, size_t len, const char *prefix,
729 const msmfb_overlay_data& ov);
730void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
731void getDump(char *buf, size_t len, const char *prefix,
732 const msm_rotator_img_info& ov);
733void getDump(char *buf, size_t len, const char *prefix,
734 const msm_rotator_data_info& ov);
735
Naseer Ahmed29a26812012-06-14 00:56:20 -0700736} // namespace utils ends
737
738//--------------------Class Res stuff (namespace overlay only) -----------
739
740class Res {
741public:
742 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700743 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700744 // /dev/msm_rotator
745 static const char* const rotPath;
746 // /sys/class/graphics/fb1/format_3d
747 static const char* const format3DFile;
748 // /sys/class/graphics/fb1/3d_present
749 static const char* const edid3dInfoFile;
750 // /sys/devices/platform/mipi_novatek.0/enable_3d_barrier
751 static const char* const barrierFile;
752};
753
754
755//--------------------Class OvFD stuff (namespace overlay only) -----------
756
Naseer Ahmed29a26812012-06-14 00:56:20 -0700757/*
758* Holds one FD
759* Dtor will NOT close the underlying FD.
760* That enables us to copy that object around
761* */
762class OvFD {
763public:
764 /* Ctor */
765 explicit OvFD();
766
767 /* dtor will NOT close the underlying FD */
768 ~OvFD();
769
770 /* Open fd using the path given by dev.
771 * return false in failure */
772 bool open(const char* const dev,
773 int flags = O_RDWR);
774
775 /* populate path */
776 void setPath(const char* const dev);
777
778 /* Close fd if we have a valid fd. */
779 bool close();
780
781 /* returns underlying fd.*/
782 int getFD() const;
783
784 /* returns true if fd is valid */
785 bool valid() const;
786
787 /* like operator= */
788 void copy(int fd);
789
790 /* dump the state of the instance */
791 void dump() const;
792private:
793 /* helper enum for determine valid/invalid fd */
794 enum { INVAL = -1 };
795
796 /* actual os fd */
797 int mFD;
798
799 /* path, for debugging */
800 char mPath[utils::MAX_PATH_LEN];
801};
802
803//-------------------Inlines--------------------------
804
805inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
806{
807 char dev_name[64] = {0};
808 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
809 return fd.open(dev_name, flags);
810}
811
812inline OvFD::OvFD() : mFD (INVAL) {
813 mPath[0] = 0;
814}
815
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700816inline OvFD::~OvFD() {
817 //no op since copy() can be used to share fd, in 3d cases.
818}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700819
820inline bool OvFD::open(const char* const dev, int flags)
821{
822 mFD = ::open(dev, flags, 0);
823 if (mFD < 0) {
824 // FIXME errno, strerror in bionic?
825 ALOGE("Cant open device %s err=%d", dev, errno);
826 return false;
827 }
828 setPath(dev);
829 return true;
830}
831
832inline void OvFD::setPath(const char* const dev)
833{
834 ::strncpy(mPath, dev, utils::MAX_PATH_LEN);
835}
836
837inline bool OvFD::close()
838{
839 int ret = 0;
840 if(valid()) {
841 ret = ::close(mFD);
842 mFD = INVAL;
843 }
844 return (ret == 0);
845}
846
847inline bool OvFD::valid() const
848{
849 return (mFD != INVAL);
850}
851
852inline int OvFD::getFD() const { return mFD; }
853
854inline void OvFD::copy(int fd) {
855 mFD = fd;
856}
857
858inline void OvFD::dump() const
859{
860 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
861 mFD, mPath);
862}
863
864//--------------- class OvFD stuff ends ---------------------
865
866} // overlay
867
868
869#endif // OVERLAY_UTILS_H