Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
Zohaib Alam | c9d00cd | 2014-01-24 16:38:32 -0500 | [diff] [blame] | 2 | * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 3 | * |
| 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 Truong | 73d36df | 2013-02-09 20:33:23 -0800 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor the names of its |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 14 | * 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 Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 38 | #include <linux/msm_mdp.h> // flags |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 39 | #include <linux/msm_rotator.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | #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 Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 46 | #include "gralloc_priv.h" //for interlace |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 47 | |
Sushil Chauhan | 4437bcb | 2013-03-11 10:36:15 -0700 | [diff] [blame] | 48 | // Older platforms do not support Venus |
| 49 | #ifndef VENUS_COLOR_FORMAT |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 50 | #define MDP_Y_CBCR_H2V2_VENUS MDP_IMGTYPE_LIMIT |
Sushil Chauhan | 4437bcb | 2013-03-11 10:36:15 -0700 | [diff] [blame] | 51 | #endif |
| 52 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 53 | /* |
| 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 Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 72 | #ifndef MDSS_MDP_RIGHT_MIXER |
| 73 | #define MDSS_MDP_RIGHT_MIXER 0x100 |
| 74 | #endif |
| 75 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 76 | #ifndef MDP_OV_PIPE_FORCE_DMA |
| 77 | #define MDP_OV_PIPE_FORCE_DMA 0x4000 |
| 78 | #endif |
| 79 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 80 | #ifndef MDSS_MDP_DUAL_PIPE |
| 81 | #define MDSS_MDP_DUAL_PIPE 0x200 |
| 82 | #endif |
| 83 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 84 | #define FB_DEVICE_TEMPLATE "/dev/graphics/fb%u" |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 85 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 86 | namespace overlay { |
| 87 | |
| 88 | // fwd |
| 89 | class Overlay; |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 90 | class OvFD; |
| 91 | |
| 92 | /* helper function to open by using fbnum */ |
| 93 | bool open(OvFD& fd, uint32_t fbnum, const char* const dev, |
| 94 | int flags = O_RDWR); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 95 | |
| 96 | namespace utils { |
| 97 | struct Whf; |
| 98 | struct Dim; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 99 | |
| 100 | inline uint32_t setBit(uint32_t x, uint32_t mask) { |
| 101 | return (x | mask); |
| 102 | } |
| 103 | |
| 104 | inline 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 Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 112 | * class SomeClass : utils::NoCopy {...}; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 113 | */ |
| 114 | class NoCopy { |
| 115 | protected: |
| 116 | NoCopy(){} |
| 117 | ~NoCopy() {} |
| 118 | private: |
| 119 | NoCopy(const NoCopy&); |
| 120 | const NoCopy& operator=(const NoCopy&); |
| 121 | }; |
| 122 | |
Sushil Chauhan | b4d184f | 2013-02-11 16:13:10 -0800 | [diff] [blame] | 123 | bool isMdssRotator(); |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 124 | void normalizeCrop(uint32_t& xy, uint32_t& wh); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 125 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 126 | template <class Type> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 127 | void swapWidthHeight(Type& width, Type& height); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 128 | |
| 129 | struct 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 155 | 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 | |
| 165 | struct 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 Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 182 | uint32_t format; |
| 183 | uint32_t size; |
| 184 | }; |
| 185 | |
| 186 | enum { MAX_PATH_LEN = 256 }; |
| 187 | |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 188 | enum { DEFAULT_PLANE_ALPHA = 0xFF }; |
| 189 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 190 | /** |
| 191 | * Rotator flags: not to be confused with orientation flags. |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 192 | * Usually, you want to open the rotator to make sure it is |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 193 | * ready for business. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 194 | * */ |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 195 | 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 Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 203 | ROT_PREROTATED = 1 << 2, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | enum eRotDownscale { |
| 207 | ROT_DS_NONE = 0, |
| 208 | ROT_DS_HALF = 1, |
| 209 | ROT_DS_FOURTH = 2, |
| 210 | ROT_DS_EIGHTH = 3, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 213 | /* |
| 214 | * Various mdp flags like PIPE SHARE, DEINTERLACE etc... |
| 215 | * kernel/common/linux/msm_mdp.h |
| 216 | * INTERLACE_MASK: hardware/qcom/display/libgralloc/badger/fb_priv.h |
| 217 | * */ |
| 218 | enum eMdpFlags { |
| 219 | OV_MDP_FLAGS_NONE = 0, |
| 220 | OV_MDP_PIPE_SHARE = MDP_OV_PIPE_SHARE, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 221 | OV_MDP_PIPE_FORCE_DMA = MDP_OV_PIPE_FORCE_DMA, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 222 | OV_MDP_DEINTERLACE = MDP_DEINTERLACE, |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 223 | OV_MDP_SECURE_OVERLAY_SESSION = MDP_SECURE_OVERLAY_SESSION, |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 224 | OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION = MDP_SECURE_DISPLAY_OVERLAY_SESSION, |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 225 | OV_MDP_SOURCE_ROTATED_90 = MDP_SOURCE_ROTATED_90, |
Saurabh Shah | 91a6a99 | 2012-08-20 15:25:28 -0700 | [diff] [blame] | 226 | OV_MDP_BLEND_FG_PREMULT = MDP_BLEND_FG_PREMULT, |
Saurabh Shah | 09549f6 | 2012-10-04 13:25:44 -0700 | [diff] [blame] | 227 | OV_MDP_FLIP_H = MDP_FLIP_LR, |
| 228 | OV_MDP_FLIP_V = MDP_FLIP_UD, |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 229 | OV_MDSS_MDP_RIGHT_MIXER = MDSS_MDP_RIGHT_MIXER, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 230 | OV_MDP_PP_EN = MDP_OVERLAY_PP_CFG_EN, |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 231 | OV_MDSS_MDP_BWC_EN = MDP_BWC_EN, |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 232 | OV_MDSS_MDP_DUAL_PIPE = MDSS_MDP_DUAL_PIPE, |
Sushil Chauhan | f10c523 | 2013-12-19 10:35:54 -0800 | [diff] [blame] | 233 | OV_MDP_SOLID_FILL = MDP_SOLID_FILL, |
Justin Philip | d616660 | 2014-08-12 13:42:21 +0530 | [diff] [blame] | 234 | OV_MDP_SMP_FORCE_ALLOC = MDP_SMP_FORCE_ALLOC, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 237 | enum eZorder { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 238 | ZORDER_0 = 0, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 239 | ZORDER_1, |
| 240 | ZORDER_2, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 241 | ZORDER_3, |
Jeykumar Sankaran | be93e27 | 2014-06-19 18:15:57 -0700 | [diff] [blame] | 242 | ZORDER_4, |
| 243 | ZORDER_5, |
| 244 | ZORDER_6, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 245 | Z_SYSTEM_ALLOC = 0xFFFF |
| 246 | }; |
| 247 | |
| 248 | enum eMdpPipeType { |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 249 | OV_MDP_PIPE_RGB = 0, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 250 | OV_MDP_PIPE_VG, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 251 | OV_MDP_PIPE_DMA, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 252 | OV_MDP_PIPE_ANY, //Any |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 255 | // Identify destination pipes |
| 256 | // TODO Names useless, replace with int and change all interfaces |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 257 | enum eDest { |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 258 | OV_P0 = 0, |
| 259 | OV_P1, |
| 260 | OV_P2, |
| 261 | OV_P3, |
| 262 | OV_P4, |
| 263 | OV_P5, |
| 264 | OV_P6, |
| 265 | OV_P7, |
| 266 | OV_P8, |
| 267 | OV_P9, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 268 | OV_INVALID, |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 269 | OV_MAX = OV_INVALID, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | /* Used when a buffer is split over 2 pipes and sent to display */ |
| 273 | enum { |
| 274 | OV_LEFT_SPLIT = 0, |
| 275 | OV_RIGHT_SPLIT, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | /* values for copybit_set_parameter(OVERLAY_TRANSFORM) */ |
| 279 | enum eTransform { |
| 280 | /* No rot */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 281 | OVERLAY_TRANSFORM_0 = 0x0, |
| 282 | /* flip source image horizontally 0x1 */ |
| 283 | OVERLAY_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, |
| 284 | /* flip source image vertically 0x2 */ |
| 285 | OVERLAY_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 286 | /* rotate source image 180 degrees |
| 287 | * It is basically bit-or-ed H | V == 0x3 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 288 | OVERLAY_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, |
| 289 | /* rotate source image 90 degrees 0x4 */ |
| 290 | OVERLAY_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, |
| 291 | /* rotate source image 90 degrees and flip horizontally 0x5 */ |
| 292 | OVERLAY_TRANSFORM_ROT_90_FLIP_H = HAL_TRANSFORM_ROT_90 | |
| 293 | HAL_TRANSFORM_FLIP_H, |
| 294 | /* rotate source image 90 degrees and flip vertically 0x6 */ |
| 295 | OVERLAY_TRANSFORM_ROT_90_FLIP_V = HAL_TRANSFORM_ROT_90 | |
| 296 | HAL_TRANSFORM_FLIP_V, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 297 | /* rotate source image 270 degrees |
| 298 | * Basically 180 | 90 == 0x7 */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 299 | OVERLAY_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 300 | /* rotate invalid like in Transform.h */ |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 301 | OVERLAY_TRANSFORM_INV = 0x80 |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 304 | enum eBlending { |
| 305 | OVERLAY_BLENDING_UNDEFINED = 0x0, |
| 306 | /* No blending */ |
| 307 | OVERLAY_BLENDING_OPAQUE, |
| 308 | /* src.rgb + dst.rgb*(1-src_alpha) */ |
| 309 | OVERLAY_BLENDING_PREMULT, |
| 310 | /* src.rgb * src_alpha + dst.rgb (1 - src_alpha) */ |
| 311 | OVERLAY_BLENDING_COVERAGE, |
| 312 | }; |
| 313 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 314 | // Used to consolidate pipe params |
| 315 | struct PipeArgs { |
| 316 | PipeArgs() : mdpFlags(OV_MDP_FLAGS_NONE), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 317 | zorder(Z_SYSTEM_ALLOC), |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 318 | rotFlags(ROT_FLAGS_NONE), |
| 319 | planeAlpha(DEFAULT_PLANE_ALPHA), |
| 320 | blending(OVERLAY_BLENDING_COVERAGE){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 323 | PipeArgs(eMdpFlags f, Whf _whf, |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 324 | eZorder z, eRotFlags r, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 325 | int pA = DEFAULT_PLANE_ALPHA, eBlending b = OVERLAY_BLENDING_COVERAGE) : |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 326 | mdpFlags(f), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 327 | whf(_whf), |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 328 | zorder(z), |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 329 | rotFlags(r), |
| 330 | planeAlpha(pA), |
| 331 | blending(b){ |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 334 | eMdpFlags mdpFlags; // for mdp_overlay flags |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 335 | Whf whf; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 336 | eZorder zorder; // stage number |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 337 | eRotFlags rotFlags; |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 338 | int planeAlpha; |
| 339 | eBlending blending; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 342 | // Cannot use HW_OVERLAY_MAGNIFICATION_LIMIT, since at the time |
| 343 | // of integration, HW_OVERLAY_MAGNIFICATION_LIMIT was a define |
| 344 | enum { HW_OV_MAGNIFICATION_LIMIT = 20, |
| 345 | HW_OV_MINIFICATION_LIMIT = 8 |
| 346 | }; |
| 347 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 348 | inline void setMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 349 | f = static_cast<eMdpFlags>(setBit(f, v)); |
| 350 | } |
| 351 | |
| 352 | inline void clearMdpFlags(eMdpFlags& f, eMdpFlags v) { |
| 353 | f = static_cast<eMdpFlags>(clrBit(f, v)); |
| 354 | } |
| 355 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 356 | enum { FB0, FB1, FB2 }; |
| 357 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 358 | struct ScreenInfo { |
| 359 | ScreenInfo() : mFBWidth(0), |
| 360 | mFBHeight(0), |
| 361 | mFBbpp(0), |
| 362 | mFBystride(0) {} |
| 363 | void dump(const char* const s) const; |
| 364 | uint32_t mFBWidth; |
| 365 | uint32_t mFBHeight; |
| 366 | uint32_t mFBbpp; |
| 367 | uint32_t mFBystride; |
| 368 | }; |
| 369 | |
| 370 | int getMdpFormat(int format); |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 371 | int getMdpFormat(int format, int flags); |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 372 | int getHALFormat(int mdpFormat); |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 373 | void getDecimationFactor(const int& src_w, const int& src_h, |
Saurabh Shah | b6810df | 2014-06-17 16:00:22 -0700 | [diff] [blame] | 374 | const int& dst_w, const int& dst_h, uint8_t& horzDeci, |
| 375 | uint8_t& vertDeci); |
Saurabh Shah | fc3652f | 2013-02-15 13:15:45 -0800 | [diff] [blame] | 376 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 377 | /* flip is upside down and such. V, H flip |
| 378 | * rotation is 90, 180 etc |
| 379 | * It returns MDP related enum/define that match rot+flip*/ |
| 380 | int getMdpOrient(eTransform rotation); |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 381 | const char* getFormatString(int format); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 382 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 383 | template <class T> |
Saurabh Shah | 912c948 | 2014-02-07 14:01:04 -0800 | [diff] [blame] | 384 | inline void memset0(T& t) { ::memset(&t, 0, sizeof(t)); } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 385 | |
| 386 | template <class T> inline void swap ( T& a, T& b ) |
| 387 | { |
| 388 | T c(a); a=b; b=c; |
| 389 | } |
| 390 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 391 | template<typename T> inline T max(T a, T b) { return (a > b) ? a : b; } |
| 392 | |
| 393 | template<typename T> inline T min(T a, T b) { return (a < b) ? a : b; } |
| 394 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 395 | inline int alignup(int value, int a) { |
| 396 | //if align = 0, return the value. Else, do alignment. |
| 397 | return a ? ((((value - 1) / a) + 1) * a) : value; |
| 398 | } |
| 399 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 400 | inline int aligndown(int value, int a) { |
| 401 | //if align = 0, return the value. Else, do alignment. |
| 402 | return a ? ((value) & ~(a-1)) : value; |
| 403 | } |
| 404 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 405 | // FIXME that align should replace the upper one. |
| 406 | inline int align(int value, int a) { |
| 407 | //if align = 0, return the value. Else, do alignment. |
| 408 | return a ? ((value + (a-1)) & ~(a-1)) : value; |
| 409 | } |
| 410 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 411 | inline bool isYuv(uint32_t format) { |
| 412 | switch(format){ |
| 413 | case MDP_Y_CBCR_H2V1: |
| 414 | case MDP_Y_CBCR_H2V2: |
| 415 | case MDP_Y_CRCB_H2V2: |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 416 | case MDP_Y_CRCB_H1V1: |
| 417 | case MDP_Y_CRCB_H2V1: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 418 | case MDP_Y_CRCB_H2V2_TILE: |
| 419 | case MDP_Y_CBCR_H2V2_TILE: |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 420 | case MDP_Y_CR_CB_H2V2: |
Saurabh Shah | ae1044e | 2012-08-21 16:03:32 -0700 | [diff] [blame] | 421 | case MDP_Y_CR_CB_GH2V2: |
Sushil Chauhan | c5e6148 | 2012-08-22 17:13:32 -0700 | [diff] [blame] | 422 | case MDP_Y_CBCR_H2V2_VENUS: |
Ramkumar Radhakrishnan | b52399c | 2013-08-06 20:17:29 -0700 | [diff] [blame] | 423 | case MDP_YCBYCR_H2V1: |
| 424 | case MDP_YCRYCB_H2V1: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 425 | return true; |
| 426 | default: |
| 427 | return false; |
| 428 | } |
| 429 | return false; |
| 430 | } |
| 431 | |
| 432 | inline bool isRgb(uint32_t format) { |
| 433 | switch(format) { |
| 434 | case MDP_RGBA_8888: |
| 435 | case MDP_BGRA_8888: |
| 436 | case MDP_RGBX_8888: |
| 437 | case MDP_RGB_565: |
Ramkumar Radhakrishnan | b8eb16d | 2014-10-09 13:54:07 -0700 | [diff] [blame] | 438 | case MDP_RGBA_4444: |
| 439 | case MDP_RGBA_5551: |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 440 | return true; |
| 441 | default: |
| 442 | return false; |
| 443 | } |
| 444 | return false; |
| 445 | } |
| 446 | |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 447 | inline const char* getFormatString(int format){ |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 448 | #define STR(f) #f; |
| 449 | static const char* formats[MDP_IMGTYPE_LIMIT + 1] = {0}; |
| 450 | formats[MDP_RGB_565] = STR(MDP_RGB_565); |
Ramkumar Radhakrishnan | b8eb16d | 2014-10-09 13:54:07 -0700 | [diff] [blame] | 451 | formats[MDP_RGBA_5551] = STR(MDP_RGBA_5551); |
| 452 | formats[MDP_RGBA_4444] = STR(MDP_RGBA_4444); |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 453 | formats[MDP_XRGB_8888] = STR(MDP_XRGB_8888); |
| 454 | formats[MDP_Y_CBCR_H2V2] = STR(MDP_Y_CBCR_H2V2); |
| 455 | formats[MDP_Y_CBCR_H2V2_ADRENO] = STR(MDP_Y_CBCR_H2V2_ADRENO); |
| 456 | formats[MDP_ARGB_8888] = STR(MDP_ARGB_8888); |
| 457 | formats[MDP_RGB_888] = STR(MDP_RGB_888); |
| 458 | formats[MDP_Y_CRCB_H2V2] = STR(MDP_Y_CRCB_H2V2); |
Ramkumar Radhakrishnan | b52399c | 2013-08-06 20:17:29 -0700 | [diff] [blame] | 459 | formats[MDP_YCBYCR_H2V1] = STR(MDP_YCBYCR_H2V1); |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 460 | formats[MDP_YCRYCB_H2V1] = STR(MDP_YCRYCB_H2V1); |
| 461 | formats[MDP_CBYCRY_H2V1] = STR(MDP_CBYCRY_H2V1); |
| 462 | formats[MDP_Y_CRCB_H2V1] = STR(MDP_Y_CRCB_H2V1); |
| 463 | formats[MDP_Y_CBCR_H2V1] = STR(MDP_Y_CBCR_H2V1); |
| 464 | formats[MDP_Y_CRCB_H1V2] = STR(MDP_Y_CRCB_H1V2); |
| 465 | formats[MDP_Y_CBCR_H1V2] = STR(MDP_Y_CBCR_H1V2); |
| 466 | formats[MDP_RGBA_8888] = STR(MDP_RGBA_8888); |
| 467 | formats[MDP_BGRA_8888] = STR(MDP_BGRA_8888); |
| 468 | formats[MDP_RGBX_8888] = STR(MDP_RGBX_8888); |
| 469 | formats[MDP_Y_CRCB_H2V2_TILE] = STR(MDP_Y_CRCB_H2V2_TILE); |
| 470 | formats[MDP_Y_CBCR_H2V2_TILE] = STR(MDP_Y_CBCR_H2V2_TILE); |
| 471 | formats[MDP_Y_CR_CB_H2V2] = STR(MDP_Y_CR_CB_H2V2); |
| 472 | formats[MDP_Y_CR_CB_GH2V2] = STR(MDP_Y_CR_CB_GH2V2); |
| 473 | formats[MDP_Y_CB_CR_H2V2] = STR(MDP_Y_CB_CR_H2V2); |
| 474 | formats[MDP_Y_CRCB_H1V1] = STR(MDP_Y_CRCB_H1V1); |
| 475 | formats[MDP_Y_CBCR_H1V1] = STR(MDP_Y_CBCR_H1V1); |
| 476 | formats[MDP_YCRCB_H1V1] = STR(MDP_YCRCB_H1V1); |
| 477 | formats[MDP_YCBCR_H1V1] = STR(MDP_YCBCR_H1V1); |
| 478 | formats[MDP_BGR_565] = STR(MDP_BGR_565); |
| 479 | formats[MDP_BGR_888] = STR(MDP_BGR_888); |
| 480 | formats[MDP_Y_CBCR_H2V2_VENUS] = STR(MDP_Y_CBCR_H2V2_VENUS); |
| 481 | formats[MDP_BGRX_8888] = STR(MDP_BGRX_8888); |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 482 | formats[MDP_RGBA_8888_TILE] = STR(MDP_RGBA_8888_TILE); |
| 483 | formats[MDP_ARGB_8888_TILE] = STR(MDP_ARGB_8888_TILE); |
| 484 | formats[MDP_ABGR_8888_TILE] = STR(MDP_ABGR_8888_TILE); |
| 485 | formats[MDP_BGRA_8888_TILE] = STR(MDP_BGRA_8888_TILE); |
| 486 | formats[MDP_RGBX_8888_TILE] = STR(MDP_RGBX_8888_TILE); |
| 487 | formats[MDP_XRGB_8888_TILE] = STR(MDP_XRGB_8888_TILE); |
| 488 | formats[MDP_XBGR_8888_TILE] = STR(MDP_XBGR_8888_TILE); |
| 489 | formats[MDP_BGRX_8888_TILE] = STR(MDP_BGRX_8888_TILE); |
Manoj Kumar AVM | 5a5529b | 2014-02-24 18:16:37 -0800 | [diff] [blame] | 490 | formats[MDP_RGB_565_TILE] = STR(MDP_RGB_565_TILE); |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 491 | formats[MDP_IMGTYPE_LIMIT] = STR(MDP_IMGTYPE_LIMIT); |
| 492 | |
| 493 | if(format < 0 || format >= MDP_IMGTYPE_LIMIT) { |
Saurabh Shah | 9c876d9 | 2012-08-25 19:29:53 -0700 | [diff] [blame] | 494 | ALOGE("%s wrong fmt %d", __FUNCTION__, format); |
| 495 | return "Unsupported format"; |
| 496 | } |
Saurabh Shah | 5380a23 | 2013-04-10 17:13:11 -0700 | [diff] [blame] | 497 | if(formats[format] == 0) { |
| 498 | ALOGE("%s: table missing format %d from header", __FUNCTION__, format); |
| 499 | return ""; |
| 500 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 501 | return formats[format]; |
| 502 | } |
| 503 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 504 | inline void Whf::dump() const { |
| 505 | ALOGE("== Dump WHF w=%d h=%d f=%d s=%d start/end ==", |
| 506 | w, h, format, size); |
| 507 | } |
| 508 | |
| 509 | inline void Dim::dump() const { |
| 510 | ALOGE("== Dump Dim x=%d y=%d w=%d h=%d start/end ==", x, y, w, h); |
| 511 | } |
| 512 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 513 | template <class Type> |
| 514 | void swapWidthHeight(Type& width, Type& height) { |
| 515 | Type tmp = width; |
| 516 | width = height; |
| 517 | height = tmp; |
| 518 | } |
| 519 | |
| 520 | inline void ScreenInfo::dump(const char* const s) const { |
| 521 | ALOGE("== Dump %s ScreenInfo w=%d h=%d" |
| 522 | " bpp=%d stride=%d start/end ==", |
| 523 | s, mFBWidth, mFBHeight, mFBbpp, mFBystride); |
| 524 | } |
| 525 | |
Saurabh Shah | e012f7a | 2012-08-18 15:11:57 -0700 | [diff] [blame] | 526 | inline bool openDev(OvFD& fd, int fbnum, |
| 527 | const char* const devpath, int flags) { |
| 528 | return overlay::open(fd, fbnum, devpath, flags); |
| 529 | } |
| 530 | |
Saurabh Shah | b121e14 | 2012-08-20 17:59:13 -0700 | [diff] [blame] | 531 | template <class T> |
| 532 | inline void even_ceil(T& value) { |
| 533 | if(value & 1) |
| 534 | value++; |
| 535 | } |
| 536 | |
| 537 | template <class T> |
| 538 | inline void even_floor(T& value) { |
| 539 | if(value & 1) |
| 540 | value--; |
| 541 | } |
| 542 | |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 543 | /* Prerotation adjusts crop co-ordinates to the new transformed values within |
| 544 | * destination buffer. This is necessary only when the entire buffer is rotated |
| 545 | * irrespective of crop (A-family). If only the crop portion of the buffer is |
| 546 | * rotated into a destination buffer matching the size of crop, we don't need to |
| 547 | * use this helper (B-family). |
| 548 | * @Deprecated as of now, retained for the case where a full buffer needs |
| 549 | * transform and also as a reference. |
| 550 | */ |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 551 | void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop); |
Saurabh Shah | 0d0a7cb | 2013-02-12 17:58:19 -0800 | [diff] [blame] | 552 | void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov); |
| 553 | void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov); |
| 554 | void getDump(char *buf, size_t len, const char *prefix, const mdp_rect& ov); |
| 555 | void getDump(char *buf, size_t len, const char *prefix, |
| 556 | const msmfb_overlay_data& ov); |
| 557 | void getDump(char *buf, size_t len, const char *prefix, const msmfb_data& ov); |
| 558 | void getDump(char *buf, size_t len, const char *prefix, |
| 559 | const msm_rotator_img_info& ov); |
| 560 | void getDump(char *buf, size_t len, const char *prefix, |
| 561 | const msm_rotator_data_info& ov); |
| 562 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 563 | } // namespace utils ends |
| 564 | |
| 565 | //--------------------Class Res stuff (namespace overlay only) ----------- |
| 566 | |
| 567 | class Res { |
| 568 | public: |
| 569 | // /dev/graphics/fb%u |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 570 | static const char* const fbPath; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 571 | // /dev/msm_rotator |
| 572 | static const char* const rotPath; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | |
| 576 | //--------------------Class OvFD stuff (namespace overlay only) ----------- |
| 577 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 578 | /* |
| 579 | * Holds one FD |
| 580 | * Dtor will NOT close the underlying FD. |
| 581 | * That enables us to copy that object around |
| 582 | * */ |
| 583 | class OvFD { |
| 584 | public: |
| 585 | /* Ctor */ |
| 586 | explicit OvFD(); |
| 587 | |
| 588 | /* dtor will NOT close the underlying FD */ |
| 589 | ~OvFD(); |
| 590 | |
| 591 | /* Open fd using the path given by dev. |
| 592 | * return false in failure */ |
| 593 | bool open(const char* const dev, |
| 594 | int flags = O_RDWR); |
| 595 | |
| 596 | /* populate path */ |
| 597 | void setPath(const char* const dev); |
| 598 | |
| 599 | /* Close fd if we have a valid fd. */ |
| 600 | bool close(); |
| 601 | |
| 602 | /* returns underlying fd.*/ |
| 603 | int getFD() const; |
| 604 | |
| 605 | /* returns true if fd is valid */ |
| 606 | bool valid() const; |
| 607 | |
| 608 | /* like operator= */ |
| 609 | void copy(int fd); |
| 610 | |
| 611 | /* dump the state of the instance */ |
| 612 | void dump() const; |
| 613 | private: |
| 614 | /* helper enum for determine valid/invalid fd */ |
| 615 | enum { INVAL = -1 }; |
| 616 | |
| 617 | /* actual os fd */ |
| 618 | int mFD; |
| 619 | |
| 620 | /* path, for debugging */ |
| 621 | char mPath[utils::MAX_PATH_LEN]; |
| 622 | }; |
| 623 | |
| 624 | //-------------------Inlines-------------------------- |
| 625 | |
| 626 | inline bool open(OvFD& fd, uint32_t fbnum, const char* const dev, int flags) |
| 627 | { |
| 628 | char dev_name[64] = {0}; |
| 629 | snprintf(dev_name, sizeof(dev_name), dev, fbnum); |
| 630 | return fd.open(dev_name, flags); |
| 631 | } |
| 632 | |
| 633 | inline OvFD::OvFD() : mFD (INVAL) { |
| 634 | mPath[0] = 0; |
| 635 | } |
| 636 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 637 | inline OvFD::~OvFD() { |
| 638 | //no op since copy() can be used to share fd, in 3d cases. |
| 639 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 640 | |
| 641 | inline bool OvFD::open(const char* const dev, int flags) |
| 642 | { |
| 643 | mFD = ::open(dev, flags, 0); |
| 644 | if (mFD < 0) { |
| 645 | // FIXME errno, strerror in bionic? |
| 646 | ALOGE("Cant open device %s err=%d", dev, errno); |
| 647 | return false; |
| 648 | } |
| 649 | setPath(dev); |
| 650 | return true; |
| 651 | } |
| 652 | |
| 653 | inline void OvFD::setPath(const char* const dev) |
| 654 | { |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 655 | ::strlcpy(mPath, dev, sizeof(mPath)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | inline bool OvFD::close() |
| 659 | { |
| 660 | int ret = 0; |
| 661 | if(valid()) { |
| 662 | ret = ::close(mFD); |
| 663 | mFD = INVAL; |
| 664 | } |
| 665 | return (ret == 0); |
| 666 | } |
| 667 | |
| 668 | inline bool OvFD::valid() const |
| 669 | { |
| 670 | return (mFD != INVAL); |
| 671 | } |
| 672 | |
| 673 | inline int OvFD::getFD() const { return mFD; } |
| 674 | |
| 675 | inline void OvFD::copy(int fd) { |
| 676 | mFD = fd; |
| 677 | } |
| 678 | |
| 679 | inline void OvFD::dump() const |
| 680 | { |
| 681 | ALOGE("== Dump OvFD fd=%d path=%s start/end ==", |
| 682 | mFD, mPath); |
| 683 | } |
| 684 | |
| 685 | //--------------- class OvFD stuff ends --------------------- |
| 686 | |
| 687 | } // overlay |
| 688 | |
| 689 | |
| 690 | #endif // OVERLAY_UTILS_H |