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" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 27 | |
| 28 | namespace qhwc { |
| 29 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 30 | namespace ovutils = overlay::utils; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 31 | |
| 32 | //Static Members |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 33 | bool VideoOverlay::sIsModeOn[] = {false}; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 34 | ovutils::eDest VideoOverlay::sDest[] = {ovutils::OV_INVALID}; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 35 | |
| 36 | //Cache stats, figure out the state, config overlay |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 37 | bool VideoOverlay::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 38 | int dpy) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 39 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 40 | if(ctx->listStats[dpy].yuvCount > 1) |
| 41 | return false; |
| 42 | |
| 43 | int yuvIndex = ctx->listStats[dpy].yuvIndices[0]; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 44 | sIsModeOn[dpy] = false; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 45 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 46 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 47 | |
| 48 | if(hw_w > MAX_DISPLAY_DIM) { |
| 49 | ALOGD_IF(VIDEO_DEBUG,"%s, \ |
| 50 | Cannot use video path for High Res Panels", __FUNCTION__); |
| 51 | return false; |
| 52 | } |
| 53 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 54 | if(!ctx->mMDP.hasOverlay) { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 55 | ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__); |
| 56 | return false; |
| 57 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 58 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 59 | if(isSecuring(ctx)) { |
| 60 | ALOGD_IF(VIDEO_DEBUG,"%s: MDP Secure is active", __FUNCTION__); |
| 61 | return false; |
| 62 | } |
| 63 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 64 | if(yuvIndex == -1 || ctx->listStats[dpy].yuvCount != 1) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 65 | return false; |
| 66 | } |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 67 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 68 | //index guaranteed to be not -1 at this point |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 69 | hwc_layer_1_t *layer = &list->hwLayers[yuvIndex]; |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 70 | if (isSecureModePolicy(ctx->mMDP.version)) { |
| 71 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 72 | if(ctx->mSecureMode) { |
| 73 | if (! isSecureBuffer(hnd)) { |
| 74 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle non-secure video layer" |
| 75 | "during secure playback gracefully", __FUNCTION__); |
| 76 | return false; |
| 77 | } |
| 78 | } else { |
| 79 | if (isSecureBuffer(hnd)) { |
| 80 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle secure video layer" |
| 81 | "during non-secure playback gracefully", __FUNCTION__); |
| 82 | return false; |
| 83 | } |
Naseer Ahmed | cb5f25b | 2012-10-04 15:56:00 -0400 | [diff] [blame] | 84 | } |
Naseer Ahmed | 68b88cf | 2012-10-02 14:15:12 -0400 | [diff] [blame] | 85 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 86 | if(configure(ctx, dpy, layer)) { |
| 87 | markFlags(layer); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 88 | sIsModeOn[dpy] = true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 91 | return sIsModeOn[dpy]; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 94 | void VideoOverlay::markFlags(hwc_layer_1_t *layer) { |
| 95 | if(layer) { |
| 96 | layer->compositionType = HWC_OVERLAY; |
| 97 | layer->hints |= HWC_HINT_CLEAR_FB; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 101 | bool VideoOverlay::configure(hwc_context_t *ctx, int dpy, |
| 102 | hwc_layer_1_t *layer) { |
| 103 | overlay::Overlay& ov = *(ctx->mOverlay); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 104 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 105 | ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 106 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 107 | //Request a VG pipe |
| 108 | ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, dpy); |
| 109 | if(dest == ovutils::OV_INVALID) { //None available |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | sDest[dpy] = dest; |
| 114 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 115 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 116 | if (isSecureBuffer(hnd)) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 117 | ovutils::setMdpFlags(mdpFlags, |
| 118 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 119 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 120 | |
Saurabh Shah | 91a6a99 | 2012-08-20 15:25:28 -0700 | [diff] [blame] | 121 | if(layer->blending == HWC_BLENDING_PREMULT) { |
| 122 | ovutils::setMdpFlags(mdpFlags, |
| 123 | ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 124 | } |
| 125 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 126 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
Ramkumar Radhakrishnan | 12b103b | 2013-01-09 17:47:56 -0800 | [diff] [blame] | 127 | if (metadata && (metadata->operation & PP_PARAM_INTERLACED) && |
| 128 | metadata->interlaced) { |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 129 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_DEINTERLACE); |
| 130 | } |
| 131 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 132 | ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 133 | if (ctx->listStats[dpy].numAppLayers == 1) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 134 | isFgFlag = ovutils::IS_FG_SET; |
| 135 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 136 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 137 | ovutils::eRotFlags rotFlags = ovutils::ROT_FLAGS_NONE; |
| 138 | if(ctx->mMDP.version >= qdutils::MDP_V4_2 && |
| 139 | ctx->mMDP.version < qdutils::MDSS_V5) { |
| 140 | rotFlags = ovutils::ROT_DOWNSCALE_ENABLED; |
| 141 | } |
| 142 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 143 | ovutils::PipeArgs parg(mdpFlags, |
| 144 | info, |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 145 | ovutils::ZORDER_1, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 146 | isFgFlag, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 147 | rotFlags); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 148 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 149 | ov.setSource(parg, dest); |
| 150 | |
| 151 | int transform = layer->transform; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 152 | ovutils::eTransform orient = |
| 153 | static_cast<ovutils::eTransform>(transform); |
| 154 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 155 | hwc_rect_t sourceCrop = layer->sourceCrop; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 156 | hwc_rect_t displayFrame = layer->displayFrame; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 157 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 158 | //Calculate the rect for primary based on whether the supplied position |
| 159 | //is within or outside bounds. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 160 | const int fbWidth = ctx->dpyAttr[dpy].xres; |
| 161 | const int fbHeight = ctx->dpyAttr[dpy].yres; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 162 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 163 | if( displayFrame.left < 0 || |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 164 | displayFrame.top < 0 || |
| 165 | displayFrame.right > fbWidth || |
| 166 | displayFrame.bottom > fbHeight) { |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 167 | hwc_rect_t scissor = {0, 0, fbWidth, fbHeight}; |
| 168 | calculate_crop_rects(sourceCrop, displayFrame, scissor, transform); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 169 | } |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 170 | |
Saurabh Shah | 1023ce2 | 2012-09-05 18:45:59 -0700 | [diff] [blame] | 171 | // source crop x,y,w,h |
| 172 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
| 173 | sourceCrop.right - sourceCrop.left, |
| 174 | sourceCrop.bottom - sourceCrop.top); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 175 | //Only for Primary |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 176 | ov.setCrop(dcrop, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 177 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 178 | ov.setTransform(orient, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 179 | |
Saurabh Shah | 1023ce2 | 2012-09-05 18:45:59 -0700 | [diff] [blame] | 180 | // position x,y,w,h |
| 181 | ovutils::Dim dpos(displayFrame.left, |
| 182 | displayFrame.top, |
| 183 | displayFrame.right - displayFrame.left, |
| 184 | displayFrame.bottom - displayFrame.top); |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 185 | // Calculate the actionsafe dimensions for External(dpy = 1 or 2) |
| 186 | if(dpy) |
| 187 | getActionSafePosition(ctx, dpy, dpos.x, dpos.y, dpos.w, dpos.h); |
| 188 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 189 | ov.setPosition(dpos, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 190 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 191 | if (!ov.commit(dest)) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 192 | ALOGE("%s: commit fails", __FUNCTION__); |
| 193 | return false; |
| 194 | } |
| 195 | return true; |
| 196 | } |
| 197 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 198 | bool VideoOverlay::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 199 | int dpy) |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 200 | { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 201 | if(!sIsModeOn[dpy]) { |
| 202 | return true; |
| 203 | } |
| 204 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 205 | int yuvIndex = ctx->listStats[dpy].yuvIndices[0]; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 206 | if(yuvIndex == -1) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | return true; |
| 208 | } |
| 209 | |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 210 | private_handle_t *hnd = (private_handle_t *) |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 211 | list->hwLayers[yuvIndex].handle; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 212 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 213 | bool ret = true; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 214 | overlay::Overlay& ov = *(ctx->mOverlay); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 215 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 216 | if (!ov.queueBuffer(hnd->fd, hnd->offset, |
| 217 | sDest[dpy])) { |
| 218 | ALOGE("%s: queueBuffer failed for dpy=%d", __FUNCTION__, dpy); |
| 219 | ret = false; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 220 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 221 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 222 | return ret; |
| 223 | } |
| 224 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 225 | }; //namespace qhwc |