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