Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. |
| 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are retained for |
| 6 | * attribution purposes only |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 21 | #define VIDEO_DEBUG 0 |
| 22 | #include <overlay.h> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 23 | #include "hwc_video.h" |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 24 | #include "hwc_utils.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 25 | #include "qdMetaData.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 26 | #include "mdp_version.h" |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 27 | #include <overlayRotator.h> |
| 28 | |
| 29 | using overlay::Rotator; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 30 | |
| 31 | namespace qhwc { |
| 32 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 33 | namespace ovutils = overlay::utils; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 34 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 35 | //===========IVideoOverlay========================= |
| 36 | IVideoOverlay* IVideoOverlay::getObject(const int& width, const int& dpy) { |
| 37 | if(width > MAX_DISPLAY_DIM) { |
| 38 | return new VideoOverlayHighRes(dpy); |
| 39 | } |
| 40 | return new VideoOverlayLowRes(dpy); |
| 41 | } |
| 42 | |
| 43 | //===========VideoOverlayLowRes========================= |
| 44 | |
| 45 | VideoOverlayLowRes::VideoOverlayLowRes(const int& dpy): IVideoOverlay(dpy) {} |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 46 | |
| 47 | //Cache stats, figure out the state, config overlay |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 48 | bool VideoOverlayLowRes::prepare(hwc_context_t *ctx, |
| 49 | hwc_display_contents_1_t *list) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 50 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 51 | if(ctx->listStats[mDpy].yuvCount > 1) |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 52 | return false; |
| 53 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 54 | int yuvIndex = ctx->listStats[mDpy].yuvIndices[0]; |
| 55 | int hw_w = ctx->dpyAttr[mDpy].xres; |
| 56 | mModeOn = false; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 57 | |
| 58 | if(hw_w > MAX_DISPLAY_DIM) { |
| 59 | ALOGD_IF(VIDEO_DEBUG,"%s, \ |
| 60 | Cannot use video path for High Res Panels", __FUNCTION__); |
| 61 | return false; |
| 62 | } |
| 63 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 64 | if(!ctx->mMDP.hasOverlay) { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 65 | ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__); |
| 66 | return false; |
| 67 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 68 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 69 | if(isSecuring(ctx)) { |
| 70 | ALOGD_IF(VIDEO_DEBUG,"%s: MDP Secure is active", __FUNCTION__); |
| 71 | return false; |
| 72 | } |
| 73 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 74 | if(yuvIndex == -1 || ctx->listStats[mDpy].yuvCount != 1) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 75 | return false; |
| 76 | } |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 77 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 78 | //index guaranteed to be not -1 at this point |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 79 | hwc_layer_1_t *layer = &list->hwLayers[yuvIndex]; |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 80 | if (isSecureModePolicy(ctx->mMDP.version)) { |
| 81 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 82 | if(ctx->mSecureMode) { |
| 83 | if (! isSecureBuffer(hnd)) { |
| 84 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle non-secure video layer" |
| 85 | "during secure playback gracefully", __FUNCTION__); |
| 86 | return false; |
| 87 | } |
| 88 | } else { |
| 89 | if (isSecureBuffer(hnd)) { |
| 90 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle secure video layer" |
| 91 | "during non-secure playback gracefully", __FUNCTION__); |
| 92 | return false; |
| 93 | } |
Naseer Ahmed | cb5f25b | 2012-10-04 15:56:00 -0400 | [diff] [blame] | 94 | } |
Naseer Ahmed | 68b88cf | 2012-10-02 14:15:12 -0400 | [diff] [blame] | 95 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 96 | |
| 97 | if(configure(ctx, layer)) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 98 | markFlags(layer); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 99 | mModeOn = true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 102 | return mModeOn; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 105 | void VideoOverlayLowRes::markFlags(hwc_layer_1_t *layer) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 106 | if(layer) { |
| 107 | layer->compositionType = HWC_OVERLAY; |
| 108 | layer->hints |= HWC_HINT_CLEAR_FB; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 112 | bool VideoOverlayLowRes::configure(hwc_context_t *ctx, |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 113 | hwc_layer_1_t *layer) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 114 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 115 | overlay::Overlay& ov = *(ctx->mOverlay); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 116 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 117 | ovutils::Whf info(hnd->width, hnd->height, |
| 118 | ovutils::getMdpFormat(hnd->format), hnd->size); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 119 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 120 | //Request a VG pipe |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 121 | ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 122 | if(dest == ovutils::OV_INVALID) { //None available |
| 123 | return false; |
| 124 | } |
| 125 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 126 | mDest = dest; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 127 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 128 | ovutils::eZorder zOrder = ovutils::ZORDER_1; |
| 129 | ovutils::eIsFg isFg = ovutils::IS_FG_OFF; |
| 130 | if (ctx->listStats[mDpy].numAppLayers == 1) { |
| 131 | isFg = ovutils::IS_FG_SET; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 132 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 133 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 134 | return (configureLowRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, dest, |
| 135 | &mRot) == 0 ); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 138 | bool VideoOverlayLowRes::draw(hwc_context_t *ctx, |
| 139 | hwc_display_contents_1_t *list) { |
| 140 | if(!mModeOn) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 141 | return true; |
| 142 | } |
| 143 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 144 | int yuvIndex = ctx->listStats[mDpy].yuvIndices[0]; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 145 | if(yuvIndex == -1) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 146 | return true; |
| 147 | } |
| 148 | |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 149 | private_handle_t *hnd = (private_handle_t *) |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 150 | list->hwLayers[yuvIndex].handle; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 151 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 152 | overlay::Overlay& ov = *(ctx->mOverlay); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 153 | int fd = hnd->fd; |
| 154 | uint32_t offset = hnd->offset; |
| 155 | Rotator *rot = mRot; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 156 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 157 | if(rot) { |
| 158 | if(!rot->queueBuffer(fd, offset)) |
| 159 | return false; |
| 160 | fd = rot->getDstMemId(); |
| 161 | offset = rot->getDstOffset(); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 162 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 163 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 164 | if (!ov.queueBuffer(fd, offset, mDest)) { |
| 165 | ALOGE("%s: queueBuffer failed for dpy=%d", __FUNCTION__, mDpy); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | return true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 172 | //===========VideoOverlayHighRes========================= |
| 173 | |
| 174 | VideoOverlayHighRes::VideoOverlayHighRes(const int& dpy): IVideoOverlay(dpy) {} |
| 175 | |
| 176 | //Cache stats, figure out the state, config overlay |
| 177 | bool VideoOverlayHighRes::prepare(hwc_context_t *ctx, |
| 178 | hwc_display_contents_1_t *list) { |
| 179 | |
| 180 | int yuvIndex = ctx->listStats[mDpy].yuvIndices[0]; |
| 181 | int hw_w = ctx->dpyAttr[mDpy].xres; |
| 182 | mModeOn = false; |
| 183 | |
| 184 | if(!ctx->mMDP.hasOverlay) { |
| 185 | ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__); |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | if(yuvIndex == -1 || ctx->listStats[mDpy].yuvCount != 1) { |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | //index guaranteed to be not -1 at this point |
| 194 | hwc_layer_1_t *layer = &list->hwLayers[yuvIndex]; |
| 195 | if(configure(ctx, layer)) { |
| 196 | markFlags(layer); |
| 197 | mModeOn = true; |
| 198 | } |
| 199 | |
| 200 | return mModeOn; |
| 201 | } |
| 202 | |
| 203 | void VideoOverlayHighRes::markFlags(hwc_layer_1_t *layer) { |
| 204 | if(layer) { |
| 205 | layer->compositionType = HWC_OVERLAY; |
| 206 | layer->hints |= HWC_HINT_CLEAR_FB; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | bool VideoOverlayHighRes::configure(hwc_context_t *ctx, |
| 211 | hwc_layer_1_t *layer) { |
| 212 | |
| 213 | int hw_w = ctx->dpyAttr[mDpy].xres; |
| 214 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 215 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 216 | ovutils::Whf info(hnd->width, hnd->height, |
| 217 | ovutils::getMdpFormat(hnd->format), hnd->size); |
| 218 | |
| 219 | //Request a VG pipe |
| 220 | mDestL = ovutils::OV_INVALID; |
| 221 | mDestR = ovutils::OV_INVALID; |
| 222 | hwc_rect_t dst = layer->displayFrame; |
| 223 | if(dst.left > hw_w/2) { |
| 224 | mDestR = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 225 | if(mDestR == ovutils::OV_INVALID) |
| 226 | return false; |
| 227 | } else if (dst.right <= hw_w/2) { |
| 228 | mDestL = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 229 | if(mDestL == ovutils::OV_INVALID) |
| 230 | return false; |
| 231 | } else { |
| 232 | mDestL = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 233 | mDestR = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, mDpy); |
| 234 | if(mDestL == ovutils::OV_INVALID || |
| 235 | mDestR == ovutils::OV_INVALID) |
| 236 | return false; |
| 237 | } |
| 238 | |
| 239 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
| 240 | ovutils::eZorder zOrder = ovutils::ZORDER_1; |
| 241 | ovutils::eIsFg isFg = ovutils::IS_FG_OFF; |
| 242 | if (ctx->listStats[mDpy].numAppLayers == 1) { |
| 243 | isFg = ovutils::IS_FG_SET; |
| 244 | } |
| 245 | |
| 246 | return (configureHighRes(ctx, layer, mDpy, mdpFlags, zOrder, isFg, mDestL, |
| 247 | mDestR, &mRot) == 0 ); |
| 248 | } |
| 249 | |
| 250 | bool VideoOverlayHighRes::draw(hwc_context_t *ctx, |
| 251 | hwc_display_contents_1_t *list) { |
| 252 | if(!mModeOn) { |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | int yuvIndex = ctx->listStats[mDpy].yuvIndices[0]; |
| 257 | if(yuvIndex == -1) { |
| 258 | return true; |
| 259 | } |
| 260 | |
| 261 | private_handle_t *hnd = (private_handle_t *) |
| 262 | list->hwLayers[yuvIndex].handle; |
| 263 | |
| 264 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 265 | int fd = hnd->fd; |
| 266 | uint32_t offset = hnd->offset; |
| 267 | Rotator *rot = mRot; |
| 268 | |
| 269 | if(rot) { |
| 270 | if(!rot->queueBuffer(fd, offset)) |
| 271 | return false; |
| 272 | fd = rot->getDstMemId(); |
| 273 | offset = rot->getDstOffset(); |
| 274 | } |
| 275 | |
| 276 | if(mDestL != ovutils::OV_INVALID) { |
| 277 | if (!ov.queueBuffer(fd, offset, mDestL)) { |
| 278 | ALOGE("%s: queueBuffer failed for dpy=%d's left mixer", |
| 279 | __FUNCTION__, mDpy); |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if(mDestR != ovutils::OV_INVALID) { |
| 285 | if (!ov.queueBuffer(fd, offset, mDestR)) { |
| 286 | ALOGE("%s: queueBuffer failed for dpy=%d's right mixer" |
| 287 | , __FUNCTION__, mDpy); |
| 288 | return false; |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 296 | }; //namespace qhwc |