blob: 4a989f69d743545a7222f056dd2ed085ee44d593 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05002* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed29a26812012-06-14 00:56:20 -07003*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are
6* met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above
10* copyright notice, this list of conditions and the following
11* disclaimer in the documentation and/or other materials provided
12* with the distribution.
Duy Truong73d36df2013-02-09 20:33:23 -080013* * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmed29a26812012-06-14 00:56:20 -070014* contributors may be used to endorse or promote products derived
15* from this software without specific prior written permission.
16*
17* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30#ifndef OVERLAY_UTILS_H
31#define OVERLAY_UTILS_H
32
33#include <cutils/log.h> // ALOGE, etc
34#include <errno.h>
35#include <fcntl.h> // open, O_RDWR, etc
36#include <hardware/hardware.h>
37#include <hardware/gralloc.h> // buffer_handle_t
Naseer Ahmedf48aef62012-07-20 09:05:53 -070038#include <linux/msm_mdp.h> // flags
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -080039#include <linux/msm_rotator.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070040#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43#include <sys/stat.h>
44#include <sys/types.h>
45#include <utils/Log.h>
Naseer Ahmedf48aef62012-07-20 09:05:53 -070046#include "gralloc_priv.h" //for interlace
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070048// Older platforms do not support Venus
49#ifndef VENUS_COLOR_FORMAT
Saurabh Shah5380a232013-04-10 17:13:11 -070050#define MDP_Y_CBCR_H2V2_VENUS MDP_IMGTYPE_LIMIT
Sushil Chauhan4437bcb2013-03-11 10:36:15 -070051#endif
52
Naseer Ahmed29a26812012-06-14 00:56:20 -070053/*
54*
55* Collection of utilities functions/structs/enums etc...
56*
57* */
58
59// comment that out if you want to remove asserts
60// or put it as -D in Android.mk. your choice.
61#define OVERLAY_HAS_ASSERT
62
63#ifdef OVERLAY_HAS_ASSERT
64# define OVASSERT(x, ...) if(!(x)) { ALOGE(__VA_ARGS__); abort(); }
65#else
66# define OVASSERT(x, ...) ALOGE_IF(!(x), __VA_ARGS__)
67#endif // OVERLAY_HAS_ASSERT
68
69#define DEBUG_OVERLAY 0
70#define PROFILE_OVERLAY 0
71
Saurabh Shahcf053c62012-12-13 12:32:55 -080072#ifndef MDSS_MDP_RIGHT_MIXER
73#define MDSS_MDP_RIGHT_MIXER 0x100
74#endif
75
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -080076#ifndef MDP_OV_PIPE_FORCE_DMA
77#define MDP_OV_PIPE_FORCE_DMA 0x4000
78#endif
79
Saurabh Shahd9e426d2013-08-01 13:35:31 -070080#ifndef MDSS_MDP_DUAL_PIPE
81#define MDSS_MDP_DUAL_PIPE 0x200
82#endif
83
Sushil Chauhan07a2c762013-03-06 15:36:49 -080084#define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u"
Sushil Chauhan07a2c762013-03-06 15:36:49 -080085
Naseer Ahmed29a26812012-06-14 00:56:20 -070086namespace overlay {
87
88// fwd
89class Overlay;
Saurabh Shahe012f7a2012-08-18 15:11:57 -070090class OvFD;
91
92/* helper function to open by using fbnum */
93bool open(OvFD& fd, uint32_t fbnum, const char* const dev,
94 int flags = O_RDWR);
Naseer Ahmed29a26812012-06-14 00:56:20 -070095
96namespace utils {
97struct Whf;
98struct Dim;
Naseer Ahmed29a26812012-06-14 00:56:20 -070099
100inline uint32_t setBit(uint32_t x, uint32_t mask) {
101 return (x | mask);
102}
103
104inline uint32_t clrBit(uint32_t x, uint32_t mask) {
105 return (x & ~mask);
106}
107
108/* Utility class to help avoid copying instances by making the copy ctor
109* and assignment operator private
110*
111* Usage:
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700112* class SomeClass : utils::NoCopy {...};
Naseer Ahmed29a26812012-06-14 00:56:20 -0700113*/
114class NoCopy {
115protected:
116 NoCopy(){}
117 ~NoCopy() {}
118private:
119 NoCopy(const NoCopy&);
120 const NoCopy& operator=(const NoCopy&);
121};
122
Sushil Chauhanb4d184f2013-02-11 16:13:10 -0800123bool isMdssRotator();
Sushil Chauhan1cac8152013-05-08 15:53:51 -0700124void normalizeCrop(uint32_t& xy, uint32_t& wh);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700125
Naseer Ahmed29a26812012-06-14 00:56:20 -0700126template <class Type>
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700127void swapWidthHeight(Type& width, Type& height);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700128
129struct Dim {
130 Dim () : x(0), y(0),
131 w(0), h(0),
132 o(0) {}
133 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h) :
134 x(_x), y(_y),
135 w(_w), h(_h) {}
136 Dim(uint32_t _x, uint32_t _y, uint32_t _w, uint32_t _h, uint32_t _o) :
137 x(_x), y(_y),
138 w(_w), h(_h),
139 o(_o) {}
140 bool check(uint32_t _w, uint32_t _h) const {
141 return (x+w <= _w && y+h <= _h);
142
143 }
144
145 bool operator==(const Dim& d) const {
146 return d.x == x && d.y == y &&
147 d.w == w && d.h == h &&
148 d.o == o;
149 }
150
151 bool operator!=(const Dim& d) const {
152 return !operator==(d);
153 }
154
Naseer Ahmed29a26812012-06-14 00:56:20 -0700155 void dump() const;
156 uint32_t x;
157 uint32_t y;
158 uint32_t w;
159 uint32_t h;
160 uint32_t o;
161};
162
163// TODO have Whfz
164
165struct Whf {
166 Whf() : w(0), h(0), format(0), size(0) {}
167 Whf(uint32_t wi, uint32_t he, uint32_t f) :
168 w(wi), h(he), format(f), size(0) {}
169 Whf(uint32_t wi, uint32_t he, uint32_t f, uint32_t s) :
170 w(wi), h(he), format(f), size(s) {}
171 // FIXME not comparing size at the moment
172 bool operator==(const Whf& whf) const {
173 return whf.w == w && whf.h == h &&
174 whf.format == format;
175 }
176 bool operator!=(const Whf& whf) const {
177 return !operator==(whf);
178 }
179 void dump() const;
180 uint32_t w;
181 uint32_t h;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700182 uint32_t format;
183 uint32_t size;
184};
185
186enum { MAX_PATH_LEN = 256 };
187
Naseer Ahmed522ce662013-03-18 20:14:05 -0400188enum { DEFAULT_PLANE_ALPHA = 0xFF };
189
Naseer Ahmed29a26812012-06-14 00:56:20 -0700190/**
191 * Rotator flags: not to be confused with orientation flags.
Saurabh Shahacf10202013-02-26 10:15:15 -0800192 * Usually, you want to open the rotator to make sure it is
Naseer Ahmed29a26812012-06-14 00:56:20 -0700193 * ready for business.
Naseer Ahmed29a26812012-06-14 00:56:20 -0700194 * */
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800195 enum eRotFlags {
196 ROT_FLAGS_NONE = 0,
197 //Use rotator for 0 rotation. It is used anyway for others.
198 ROT_0_ENABLED = 1 << 0,
199 //Enable rotator downscale optimization for hardware bugs not handled in
200 //driver. If downscale optimizatation is required,
201 //then rotator will be used even if its 0 rotation case.
202 ROT_DOWNSCALE_ENABLED = 1 << 1,
Saurabh Shahacf10202013-02-26 10:15:15 -0800203 ROT_PREROTATED = 1 << 2,
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800204};
205
206enum eRotDownscale {
207 ROT_DS_NONE = 0,
208 ROT_DS_HALF = 1,
209 ROT_DS_FOURTH = 2,
210 ROT_DS_EIGHTH = 3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700211};
212
Naseer Ahmed29a26812012-06-14 00:56:20 -0700213/* The values for is_fg flag for control alpha and transp
214 * IS_FG_OFF means is_fg = 0
215 * IS_FG_SET means is_fg = 1
216 */
217enum eIsFg {
218 IS_FG_OFF = 0,
219 IS_FG_SET = 1
220};
221
222/*
223 * Various mdp flags like PIPE SHARE, DEINTERLACE etc...
224 * kernel/common/linux/msm_mdp.h
225 * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h
226 * */
227enum eMdpFlags {
228 OV_MDP_FLAGS_NONE = 0,
229 OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800230 OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700231 OV_MDP_DEINTERLACE = MDP_DEINTERLACE,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700232 OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION,
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700233 OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION = MDP_SECURE_DISPLAY_OVERLAY_SESSION,
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700234 OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90,
Saurabh Shah799a3972012-09-01 12:16:12 -0700235 OV_MDP_BACKEND_COMPOSITION = MDP_BACKEND_COMPOSITION,
Saurabh Shah91a6a992012-08-20 15:25:28 -0700236 OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT,
Saurabh Shah09549f62012-10-04 13:25:44 -0700237 OV_MDP_FLIP_H = MDP_FLIP_LR,
238 OV_MDP_FLIP_V = MDP_FLIP_UD,
Saurabh Shahcf053c62012-12-13 12:32:55 -0800239 OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER,
Saurabh Shah5daeee52013-01-23 16:52:26 +0800240 OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN,
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800241 OV_MDSS_MDP_BWC_EN = MDP_BWC_EN,
Saurabh Shahd9e426d2013-08-01 13:35:31 -0700242 OV_MDSS_MDP_DUAL_PIPE = MDSS_MDP_DUAL_PIPE,
Sushil Chauhanf10c5232013-12-19 10:35:54 -0800243 OV_MDP_SOLID_FILL = MDP_SOLID_FILL,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700244};
245
Naseer Ahmed29a26812012-06-14 00:56:20 -0700246enum eZorder {
Saurabh Shahacf10202013-02-26 10:15:15 -0800247 ZORDER_0 = 0,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700248 ZORDER_1,
249 ZORDER_2,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500250 ZORDER_3,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700251 Z_SYSTEM_ALLOC = 0xFFFF
252};
253
254enum eMdpPipeType {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800255 OV_MDP_PIPE_RGB = 0,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 OV_MDP_PIPE_VG,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800257 OV_MDP_PIPE_DMA,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500258 OV_MDP_PIPE_ANY, //Any
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259};
260
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800261// Identify destination pipes
262// TODO Names useless, replace with int and change all interfaces
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263enum eDest {
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800264 OV_P0 = 0,
265 OV_P1,
266 OV_P2,
267 OV_P3,
268 OV_P4,
269 OV_P5,
270 OV_P6,
271 OV_P7,
272 OV_P8,
273 OV_P9,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500274 OV_INVALID,
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800275 OV_MAX = OV_INVALID,
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500276};
277
278/* Used when a buffer is split over 2 pipes and sent to display */
279enum {
280 OV_LEFT_SPLIT = 0,
281 OV_RIGHT_SPLIT,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700282};
283
284/* values for copybit_set_parameter(OVERLAY_TRANSFORM) */
285enum eTransform {
286 /* No rot */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700287 OVERLAY_TRANSFORM_0 = 0x0,
288 /* flip source image horizontally 0x1 */
289 OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H,
290 /* flip source image vertically 0x2 */
291 OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700292 /* rotate source image 180 degrees
293 * It is basically bit-or-ed H | V == 0x3 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700294 OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
295 /* rotate source image 90 degrees 0x4 */
296 OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
297 /* rotate source image 90 degrees and flip horizontally 0x5 */
298 OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 |
299 HAL_TRANSFORM_FLIP_H,
300 /* rotate source image 90 degrees and flip vertically 0x6 */
301 OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 |
302 HAL_TRANSFORM_FLIP_V,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700303 /* rotate source image 270 degrees
304 * Basically 180 | 90 == 0x7 */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700305 OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700306 /* rotate invalid like in Transform.h */
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700307 OVERLAY_TRANSFORM_INV = 0x80
Naseer Ahmed29a26812012-06-14 00:56:20 -0700308};
309
Naseer Ahmed522ce662013-03-18 20:14:05 -0400310enum eBlending {
311 OVERLAY_BLENDING_UNDEFINED = 0x0,
312 /* No blending */
313 OVERLAY_BLENDING_OPAQUE,
314 /* src.rgb + dst.rgb*(1-src_alpha) */
315 OVERLAY_BLENDING_PREMULT,
316 /* src.rgb * src_alpha + dst.rgb (1 - src_alpha) */
317 OVERLAY_BLENDING_COVERAGE,
318};
319
Naseer Ahmed29a26812012-06-14 00:56:20 -0700320// Used to consolidate pipe params
321struct PipeArgs {
322 PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700323 zorder(Z_SYSTEM_ALLOC),
324 isFg(IS_FG_OFF),
Naseer Ahmed522ce662013-03-18 20:14:05 -0400325 rotFlags(ROT_FLAGS_NONE),
326 planeAlpha(DEFAULT_PLANE_ALPHA),
327 blending(OVERLAY_BLENDING_COVERAGE){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700328 }
329
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700330 PipeArgs(eMdpFlags f, Whf _whf,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400331 eZorder z, eIsFg fg, eRotFlags r,
332 int pA = DEFAULT_PLANE_ALPHA, eBlending b = OVERLAY_BLENDING_COVERAGE) :
Naseer Ahmed29a26812012-06-14 00:56:20 -0700333 mdpFlags(f),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700334 whf(_whf),
Naseer Ahmed29a26812012-06-14 00:56:20 -0700335 zorder(z),
336 isFg(fg),
Naseer Ahmed522ce662013-03-18 20:14:05 -0400337 rotFlags(r),
338 planeAlpha(pA),
339 blending(b){
Naseer Ahmed29a26812012-06-14 00:56:20 -0700340 }
341
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700342 eMdpFlags mdpFlags; // for mdp_overlay flags
Naseer Ahmed29a26812012-06-14 00:56:20 -0700343 Whf whf;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700344 eZorder zorder; // stage number
345 eIsFg isFg; // control alpha & transp
346 eRotFlags rotFlags;
Naseer Ahmed522ce662013-03-18 20:14:05 -0400347 int planeAlpha;
348 eBlending blending;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700349};
350
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800351// Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time
352// of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define
353enum { HW_OV_MAGNIFICATION_LIMIT = 20,
354 HW_OV_MINIFICATION_LIMIT = 8
355};
356
Naseer Ahmed29a26812012-06-14 00:56:20 -0700357inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) {
358 f = static_cast<eMdpFlags>(setBit(f, v));
359}
360
361inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) {
362 f = static_cast<eMdpFlags>(clrBit(f, v));
363}
364
Naseer Ahmed29a26812012-06-14 00:56:20 -0700365enum { FB0, FB1, FB2 };
366
Naseer Ahmed29a26812012-06-14 00:56:20 -0700367struct ScreenInfo {
368 ScreenInfo() : mFBWidth(0),
369 mFBHeight(0),
370 mFBbpp(0),
371 mFBystride(0) {}
372 void dump(const char* const s) const;
373 uint32_t mFBWidth;
374 uint32_t mFBHeight;
375 uint32_t mFBbpp;
376 uint32_t mFBystride;
377};
378
379int getMdpFormat(int format);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700380int getMdpFormat(int format, bool tileEnabled);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800381int getHALFormat(int mdpFormat);
Saurabh Shah1a03d482013-05-29 13:44:20 -0700382void getDecimationFactor(const int& src_w, const int& src_h,
Saurabh Shahb6810df2014-06-17 16:00:22 -0700383 const int& dst_w, const int& dst_h, uint8_t& horzDeci,
384 uint8_t& vertDeci);
Saurabh Shahfc3652f2013-02-15 13:15:45 -0800385
Naseer Ahmed29a26812012-06-14 00:56:20 -0700386/* flip is upside down and such. V, H flip
387 * rotation is 90, 180 etc
388 * It returns MDP related enum/define that match rot+flip*/
389int getMdpOrient(eTransform rotation);
Saurabh Shah9c876d92012-08-25 19:29:53 -0700390const char* getFormatString(int format);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700391
Naseer Ahmed29a26812012-06-14 00:56:20 -0700392template <class T>
Saurabh Shah912c9482014-02-07 14:01:04 -0800393inline void memset0(T& t) { ::memset(&t, 0, sizeof(t)); }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700394
395template <class T> inline void swap ( T& a, T& b )
396{
397 T c(a); a=b; b=c;
398}
399
Saurabh Shahc46cf9d2014-07-02 15:22:34 -0700400template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; }
401
402template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; }
403
Naseer Ahmed29a26812012-06-14 00:56:20 -0700404inline int alignup(int value, int a) {
405 //if align = 0, return the value. Else, do alignment.
406 return a ? ((((value - 1) / a) + 1) * a) : value;
407}
408
Ramkumar Radhakrishnan288f8c72013-01-15 11:37:54 -0800409inline int aligndown(int value, int a) {
410 //if align = 0, return the value. Else, do alignment.
411 return a ? ((value) & ~(a-1)) : value;
412}
413
Naseer Ahmed29a26812012-06-14 00:56:20 -0700414// FIXME that align should replace the upper one.
415inline int align(int value, int a) {
416 //if align = 0, return the value. Else, do alignment.
417 return a ? ((value + (a-1)) & ~(a-1)) : value;
418}
419
Naseer Ahmed29a26812012-06-14 00:56:20 -0700420inline bool isYuv(uint32_t format) {
421 switch(format){
422 case MDP_Y_CBCR_H2V1:
423 case MDP_Y_CBCR_H2V2:
424 case MDP_Y_CRCB_H2V2:
Saurabh Shahb121e142012-08-20 17:59:13 -0700425 case MDP_Y_CRCB_H1V1:
426 case MDP_Y_CRCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700427 case MDP_Y_CRCB_H2V2_TILE:
428 case MDP_Y_CBCR_H2V2_TILE:
Saurabh Shahb121e142012-08-20 17:59:13 -0700429 case MDP_Y_CR_CB_H2V2:
Saurabh Shahae1044e2012-08-21 16:03:32 -0700430 case MDP_Y_CR_CB_GH2V2:
Sushil Chauhanc5e61482012-08-22 17:13:32 -0700431 case MDP_Y_CBCR_H2V2_VENUS:
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700432 case MDP_YCBYCR_H2V1:
433 case MDP_YCRYCB_H2V1:
Naseer Ahmed29a26812012-06-14 00:56:20 -0700434 return true;
435 default:
436 return false;
437 }
438 return false;
439}
440
441inline bool isRgb(uint32_t format) {
442 switch(format) {
443 case MDP_RGBA_8888:
444 case MDP_BGRA_8888:
445 case MDP_RGBX_8888:
446 case MDP_RGB_565:
447 return true;
448 default:
449 return false;
450 }
451 return false;
452}
453
Saurabh Shah9c876d92012-08-25 19:29:53 -0700454inline const char* getFormatString(int format){
Saurabh Shah5380a232013-04-10 17:13:11 -0700455 #define STR(f) #f;
456 static const char* formats[MDP_IMGTYPE_LIMIT + 1] = {0};
457 formats[MDP_RGB_565] = STR(MDP_RGB_565);
458 formats[MDP_XRGB_8888] = STR(MDP_XRGB_8888);
459 formats[MDP_Y_CBCR_H2V2] = STR(MDP_Y_CBCR_H2V2);
460 formats[MDP_Y_CBCR_H2V2_ADRENO] = STR(MDP_Y_CBCR_H2V2_ADRENO);
461 formats[MDP_ARGB_8888] = STR(MDP_ARGB_8888);
462 formats[MDP_RGB_888] = STR(MDP_RGB_888);
463 formats[MDP_Y_CRCB_H2V2] = STR(MDP_Y_CRCB_H2V2);
Ramkumar Radhakrishnanb52399c2013-08-06 20:17:29 -0700464 formats[MDP_YCBYCR_H2V1] = STR(MDP_YCBYCR_H2V1);
Saurabh Shah5380a232013-04-10 17:13:11 -0700465 formats[MDP_YCRYCB_H2V1] = STR(MDP_YCRYCB_H2V1);
466 formats[MDP_CBYCRY_H2V1] = STR(MDP_CBYCRY_H2V1);
467 formats[MDP_Y_CRCB_H2V1] = STR(MDP_Y_CRCB_H2V1);
468 formats[MDP_Y_CBCR_H2V1] = STR(MDP_Y_CBCR_H2V1);
469 formats[MDP_Y_CRCB_H1V2] = STR(MDP_Y_CRCB_H1V2);
470 formats[MDP_Y_CBCR_H1V2] = STR(MDP_Y_CBCR_H1V2);
471 formats[MDP_RGBA_8888] = STR(MDP_RGBA_8888);
472 formats[MDP_BGRA_8888] = STR(MDP_BGRA_8888);
473 formats[MDP_RGBX_8888] = STR(MDP_RGBX_8888);
474 formats[MDP_Y_CRCB_H2V2_TILE] = STR(MDP_Y_CRCB_H2V2_TILE);
475 formats[MDP_Y_CBCR_H2V2_TILE] = STR(MDP_Y_CBCR_H2V2_TILE);
476 formats[MDP_Y_CR_CB_H2V2] = STR(MDP_Y_CR_CB_H2V2);
477 formats[MDP_Y_CR_CB_GH2V2] = STR(MDP_Y_CR_CB_GH2V2);
478 formats[MDP_Y_CB_CR_H2V2] = STR(MDP_Y_CB_CR_H2V2);
479 formats[MDP_Y_CRCB_H1V1] = STR(MDP_Y_CRCB_H1V1);
480 formats[MDP_Y_CBCR_H1V1] = STR(MDP_Y_CBCR_H1V1);
481 formats[MDP_YCRCB_H1V1] = STR(MDP_YCRCB_H1V1);
482 formats[MDP_YCBCR_H1V1] = STR(MDP_YCBCR_H1V1);
483 formats[MDP_BGR_565] = STR(MDP_BGR_565);
484 formats[MDP_BGR_888] = STR(MDP_BGR_888);
485 formats[MDP_Y_CBCR_H2V2_VENUS] = STR(MDP_Y_CBCR_H2V2_VENUS);
486 formats[MDP_BGRX_8888] = STR(MDP_BGRX_8888);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700487 formats[MDP_RGBA_8888_TILE] = STR(MDP_RGBA_8888_TILE);
488 formats[MDP_ARGB_8888_TILE] = STR(MDP_ARGB_8888_TILE);
489 formats[MDP_ABGR_8888_TILE] = STR(MDP_ABGR_8888_TILE);
490 formats[MDP_BGRA_8888_TILE] = STR(MDP_BGRA_8888_TILE);
491 formats[MDP_RGBX_8888_TILE] = STR(MDP_RGBX_8888_TILE);
492 formats[MDP_XRGB_8888_TILE] = STR(MDP_XRGB_8888_TILE);
493 formats[MDP_XBGR_8888_TILE] = STR(MDP_XBGR_8888_TILE);
494 formats[MDP_BGRX_8888_TILE] = STR(MDP_BGRX_8888_TILE);
Manoj Kumar AVM5a5529b2014-02-24 18:16:37 -0800495 formats[MDP_RGB_565_TILE] = STR(MDP_RGB_565_TILE);
Saurabh Shah5380a232013-04-10 17:13:11 -0700496 formats[MDP_IMGTYPE_LIMIT] = STR(MDP_IMGTYPE_LIMIT);
497
498 if(format < 0 || format >= MDP_IMGTYPE_LIMIT) {
Saurabh Shah9c876d92012-08-25 19:29:53 -0700499 ALOGE("%s wrong fmt %d", __FUNCTION__, format);
500 return "Unsupported format";
501 }
Saurabh Shah5380a232013-04-10 17:13:11 -0700502 if(formats[format] == 0) {
503 ALOGE("%s: table missing format %d from header", __FUNCTION__, format);
504 return "";
505 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700506 return formats[format];
507}
508
Naseer Ahmed29a26812012-06-14 00:56:20 -0700509inline void Whf::dump() const {
510 ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==",
511 w, h, format, size);
512}
513
514inline void Dim::dump() const {
515 ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h);
516}
517
Naseer Ahmed29a26812012-06-14 00:56:20 -0700518template <class Type>
519void swapWidthHeight(Type& width, Type& height) {
520 Type tmp = width;
521 width = height;
522 height = tmp;
523}
524
525inline void ScreenInfo::dump(const char* const s) const {
526 ALOGE("== Dump %s ScreenInfo w=%d h=%d"
527 " bpp=%d stride=%d start/end ==",
528 s, mFBWidth, mFBHeight, mFBbpp, mFBystride);
529}
530
Saurabh Shahe012f7a2012-08-18 15:11:57 -0700531inline bool openDev(OvFD& fd, int fbnum,
532 const char* const devpath, int flags) {
533 return overlay::open(fd, fbnum, devpath, flags);
534}
535
Saurabh Shahb121e142012-08-20 17:59:13 -0700536template <class T>
537inline void even_ceil(T& value) {
538 if(value & 1)
539 value++;
540}
541
542template <class T>
543inline void even_floor(T& value) {
544 if(value & 1)
545 value--;
546}
547
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700548/* Prerotation adjusts crop co-ordinates to the new transformed values within
549 * destination buffer. This is necessary only when the entire buffer is rotated
550 * irrespective of crop (A-family). If only the crop portion of the buffer is
551 * rotated into a destination buffer matching the size of crop, we don't need to
552 * use this helper (B-family).
553 * @Deprecated as of now, retained for the case where a full buffer needs
554 * transform and also as a reference.
555 */
Saurabh Shah76fd6552013-03-14 14:45:38 -0700556void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
Saurabh Shah0d0a7cb2013-02-12 17:58:19 -0800557void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
558void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
559void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov);
560void getDump(char *buf, size_t len, const char *prefix,
561 const msmfb_overlay_data& ov);
562void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov);
563void getDump(char *buf, size_t len, const char *prefix,
564 const msm_rotator_img_info& ov);
565void getDump(char *buf, size_t len, const char *prefix,
566 const msm_rotator_data_info& ov);
567
Naseer Ahmed29a26812012-06-14 00:56:20 -0700568} // namespace utils ends
569
570//--------------------Class Res stuff (namespace overlay only) -----------
571
572class Res {
573public:
574 // /dev/graphics/fb%u
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700575 static const char* const fbPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700576 // /dev/msm_rotator
577 static const char* const rotPath;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700578};
579
580
581//--------------------Class OvFD stuff (namespace overlay only) -----------
582
Naseer Ahmed29a26812012-06-14 00:56:20 -0700583/*
584* Holds one FD
585* Dtor will NOT close the underlying FD.
586* That enables us to copy that object around
587* */
588class OvFD {
589public:
590 /* Ctor */
591 explicit OvFD();
592
593 /* dtor will NOT close the underlying FD */
594 ~OvFD();
595
596 /* Open fd using the path given by dev.
597 * return false in failure */
598 bool open(const char* const dev,
599 int flags = O_RDWR);
600
601 /* populate path */
602 void setPath(const char* const dev);
603
604 /* Close fd if we have a valid fd. */
605 bool close();
606
607 /* returns underlying fd.*/
608 int getFD() const;
609
610 /* returns true if fd is valid */
611 bool valid() const;
612
613 /* like operator= */
614 void copy(int fd);
615
616 /* dump the state of the instance */
617 void dump() const;
618private:
619 /* helper enum for determine valid/invalid fd */
620 enum { INVAL = -1 };
621
622 /* actual os fd */
623 int mFD;
624
625 /* path, for debugging */
626 char mPath[utils::MAX_PATH_LEN];
627};
628
629//-------------------Inlines--------------------------
630
631inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags)
632{
633 char dev_name[64] = {0};
634 snprintf(dev_name, sizeof(dev_name), dev, fbnum);
635 return fd.open(dev_name, flags);
636}
637
638inline OvFD::OvFD() : mFD (INVAL) {
639 mPath[0] = 0;
640}
641
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700642inline OvFD::~OvFD() {
643 //no op since copy() can be used to share fd, in 3d cases.
644}
Naseer Ahmed29a26812012-06-14 00:56:20 -0700645
646inline bool OvFD::open(const char* const dev, int flags)
647{
648 mFD = ::open(dev, flags, 0);
649 if (mFD < 0) {
650 // FIXME errno, strerror in bionic?
651 ALOGE("Cant open device %s err=%d", dev, errno);
652 return false;
653 }
654 setPath(dev);
655 return true;
656}
657
658inline void OvFD::setPath(const char* const dev)
659{
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800660 ::strlcpy(mPath, dev, sizeof(mPath));
Naseer Ahmed29a26812012-06-14 00:56:20 -0700661}
662
663inline bool OvFD::close()
664{
665 int ret = 0;
666 if(valid()) {
667 ret = ::close(mFD);
668 mFD = INVAL;
669 }
670 return (ret == 0);
671}
672
673inline bool OvFD::valid() const
674{
675 return (mFD != INVAL);
676}
677
678inline int OvFD::getFD() const { return mFD; }
679
680inline void OvFD::copy(int fd) {
681 mFD = fd;
682}
683
684inline void OvFD::dump() const
685{
686 ALOGE("== Dump OvFD fd=%d path=%s start/end ==",
687 mFD, mPath);
688}
689
690//--------------- class OvFD stuff ends ---------------------
691
692} // overlay
693
694
695#endif // OVERLAY_UTILS_H