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