Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 18 | #define VIDEO_DEBUG 0 |
| 19 | #include <overlay.h> |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 20 | #include "hwc_video.h" |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 21 | #include "hwc_utils.h" |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 22 | #include "qdMetaData.h" |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame^] | 23 | #include "mdp_version.h" |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 24 | |
| 25 | namespace qhwc { |
| 26 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 27 | namespace ovutils = overlay::utils; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 28 | |
| 29 | //Static Members |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 30 | bool VideoOverlay::sIsModeOn[] = {false}; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 31 | ovutils::eDest VideoOverlay::sDest[] = {ovutils::OV_INVALID}; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 32 | |
| 33 | //Cache stats, figure out the state, config overlay |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 34 | bool VideoOverlay::prepare(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 35 | int dpy) { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 36 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 37 | int yuvIndex = ctx->listStats[dpy].yuvIndex; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 38 | sIsModeOn[dpy] = false; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 39 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 40 | if(!ctx->mMDP.hasOverlay) { |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 41 | ALOGD_IF(VIDEO_DEBUG,"%s, this hw doesnt support overlay", __FUNCTION__); |
| 42 | return false; |
| 43 | } |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 44 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 45 | if(isSecuring(ctx)) { |
| 46 | ALOGD_IF(VIDEO_DEBUG,"%s: MDP Secure is active", __FUNCTION__); |
| 47 | return false; |
| 48 | } |
| 49 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 50 | if(yuvIndex == -1 || ctx->listStats[dpy].yuvCount != 1) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 51 | return false; |
| 52 | } |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 53 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 54 | //index guaranteed to be not -1 at this point |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 55 | hwc_layer_1_t *layer = &list->hwLayers[yuvIndex]; |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 56 | if (isSecureModePolicy(ctx->mMDP.version)) { |
| 57 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 58 | if(ctx->mSecureMode) { |
| 59 | if (! isSecureBuffer(hnd)) { |
| 60 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle non-secure video layer" |
| 61 | "during secure playback gracefully", __FUNCTION__); |
| 62 | return false; |
| 63 | } |
| 64 | } else { |
| 65 | if (isSecureBuffer(hnd)) { |
| 66 | ALOGD_IF(VIDEO_DEBUG, "%s: Handle secure video layer" |
| 67 | "during non-secure playback gracefully", __FUNCTION__); |
| 68 | return false; |
| 69 | } |
Naseer Ahmed | cb5f25b | 2012-10-04 15:56:00 -0400 | [diff] [blame] | 70 | } |
Naseer Ahmed | 68b88cf | 2012-10-02 14:15:12 -0400 | [diff] [blame] | 71 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 72 | if(configure(ctx, dpy, layer)) { |
| 73 | markFlags(layer); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 74 | sIsModeOn[dpy] = true; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 77 | return sIsModeOn[dpy]; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 80 | void VideoOverlay::markFlags(hwc_layer_1_t *layer) { |
| 81 | if(layer) { |
| 82 | layer->compositionType = HWC_OVERLAY; |
| 83 | layer->hints |= HWC_HINT_CLEAR_FB; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 87 | bool VideoOverlay::configure(hwc_context_t *ctx, int dpy, |
| 88 | hwc_layer_1_t *layer) { |
| 89 | overlay::Overlay& ov = *(ctx->mOverlay); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 90 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 91 | ovutils::Whf info(hnd->width, hnd->height, hnd->format, hnd->size); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 92 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 93 | //Request a VG pipe |
| 94 | ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_VG, dpy); |
| 95 | if(dest == ovutils::OV_INVALID) { //None available |
| 96 | return false; |
| 97 | } |
| 98 | |
| 99 | sDest[dpy] = dest; |
| 100 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 101 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 102 | if (isSecureBuffer(hnd)) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 103 | ovutils::setMdpFlags(mdpFlags, |
| 104 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 105 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 106 | |
Saurabh Shah | 91a6a99 | 2012-08-20 15:25:28 -0700 | [diff] [blame] | 107 | if(layer->blending == HWC_BLENDING_PREMULT) { |
| 108 | ovutils::setMdpFlags(mdpFlags, |
| 109 | ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 110 | } |
| 111 | |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 112 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
Ramkumar Radhakrishnan | 12b103b | 2013-01-09 17:47:56 -0800 | [diff] [blame] | 113 | if (metadata && (metadata->operation & PP_PARAM_INTERLACED) && |
| 114 | metadata->interlaced) { |
Ramkumar Radhakrishnan | 47573e2 | 2012-11-07 11:36:41 -0800 | [diff] [blame] | 115 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_DEINTERLACE); |
| 116 | } |
| 117 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 118 | ovutils::eIsFg isFgFlag = ovutils::IS_FG_OFF; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 119 | if (ctx->listStats[dpy].numAppLayers == 1) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 120 | isFgFlag = ovutils::IS_FG_SET; |
| 121 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 122 | |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame^] | 123 | ovutils::eRotFlags rotFlags = ovutils::ROT_FLAGS_NONE; |
| 124 | if(ctx->mMDP.version >= qdutils::MDP_V4_2 && |
| 125 | ctx->mMDP.version < qdutils::MDSS_V5) { |
| 126 | rotFlags = ovutils::ROT_DOWNSCALE_ENABLED; |
| 127 | } |
| 128 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 129 | ovutils::PipeArgs parg(mdpFlags, |
| 130 | info, |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 131 | ovutils::ZORDER_1, |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 132 | isFgFlag, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame^] | 133 | rotFlags); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 134 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 135 | ov.setSource(parg, dest); |
| 136 | |
| 137 | int transform = layer->transform; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 138 | ovutils::eTransform orient = |
| 139 | static_cast<ovutils::eTransform>(transform); |
| 140 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 141 | hwc_rect_t sourceCrop = layer->sourceCrop; |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 142 | hwc_rect_t displayFrame = layer->displayFrame; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 143 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 144 | //Calculate the rect for primary based on whether the supplied position |
| 145 | //is within or outside bounds. |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 146 | const int fbWidth = ctx->dpyAttr[dpy].xres; |
| 147 | const int fbHeight = ctx->dpyAttr[dpy].yres; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 148 | |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 149 | if( displayFrame.left < 0 || |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 150 | displayFrame.top < 0 || |
| 151 | displayFrame.right > fbWidth || |
| 152 | displayFrame.bottom > fbHeight) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 153 | calculate_crop_rects(sourceCrop, displayFrame, fbWidth, fbHeight, |
| 154 | transform); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 155 | } |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 156 | |
Saurabh Shah | 1023ce2 | 2012-09-05 18:45:59 -0700 | [diff] [blame] | 157 | // source crop x,y,w,h |
| 158 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
| 159 | sourceCrop.right - sourceCrop.left, |
| 160 | sourceCrop.bottom - sourceCrop.top); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 161 | //Only for Primary |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 162 | ov.setCrop(dcrop, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 163 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 164 | ov.setTransform(orient, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 165 | |
Saurabh Shah | 1023ce2 | 2012-09-05 18:45:59 -0700 | [diff] [blame] | 166 | // position x,y,w,h |
| 167 | ovutils::Dim dpos(displayFrame.left, |
| 168 | displayFrame.top, |
| 169 | displayFrame.right - displayFrame.left, |
| 170 | displayFrame.bottom - displayFrame.top); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 171 | ov.setPosition(dpos, dest); |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 172 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 173 | if (!ov.commit(dest)) { |
Naseer Ahmed | 2cc53dd | 2012-07-31 19:11:48 -0700 | [diff] [blame] | 174 | ALOGE("%s: commit fails", __FUNCTION__); |
| 175 | return false; |
| 176 | } |
| 177 | return true; |
| 178 | } |
| 179 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 180 | bool VideoOverlay::draw(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 181 | int dpy) |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 182 | { |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 183 | if(!sIsModeOn[dpy]) { |
| 184 | return true; |
| 185 | } |
| 186 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 187 | int yuvIndex = ctx->listStats[dpy].yuvIndex; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 188 | if(yuvIndex == -1) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 189 | return true; |
| 190 | } |
| 191 | |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 192 | private_handle_t *hnd = (private_handle_t *) |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 193 | list->hwLayers[yuvIndex].handle; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 194 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 195 | bool ret = true; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 196 | overlay::Overlay& ov = *(ctx->mOverlay); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 197 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 198 | if (!ov.queueBuffer(hnd->fd, hnd->offset, |
| 199 | sDest[dpy])) { |
| 200 | ALOGE("%s: queueBuffer failed for dpy=%d", __FUNCTION__, dpy); |
| 201 | ret = false; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 202 | } |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 203 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 204 | return ret; |
| 205 | } |
| 206 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 207 | }; //namespace qhwc |