Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * Copyright (C) 2012, The Linux Foundation. All rights reserved. |
| 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are |
| 6 | * retained for attribution purposes only. |
| 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 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 21 | #define DEBUG_FBUPDATE 0 |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 22 | #include <gralloc_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 23 | #include "hwc_fbupdate.h" |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 24 | |
| 25 | namespace qhwc { |
| 26 | |
| 27 | namespace ovutils = overlay::utils; |
| 28 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 29 | IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) { |
| 30 | if(width > MAX_DISPLAY_DIM) { |
| 31 | return new FBUpdateHighRes(dpy); |
| 32 | } |
| 33 | return new FBUpdateLowRes(dpy); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 34 | } |
| 35 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 36 | inline void IFBUpdate::reset() { |
| 37 | mModeOn = false; |
| 38 | } |
| 39 | |
| 40 | //================= Low res==================================== |
| 41 | FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {} |
| 42 | |
| 43 | inline void FBUpdateLowRes::reset() { |
| 44 | IFBUpdate::reset(); |
| 45 | mDest = ovutils::OV_INVALID; |
| 46 | } |
| 47 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 48 | bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list) |
| 49 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 50 | if(!ctx->mMDP.hasOverlay) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 51 | ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays", |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 52 | __FUNCTION__); |
| 53 | return false; |
| 54 | } |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 55 | mModeOn = configure(ctx, list); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 56 | ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn); |
| 57 | return mModeOn; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // Configure |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 61 | bool FBUpdateLowRes::configure(hwc_context_t *ctx, |
| 62 | hwc_display_contents_1 *list) |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 63 | { |
| 64 | bool ret = false; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 65 | hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 66 | if (LIKELY(ctx->mOverlay)) { |
| 67 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 68 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 69 | if (!hnd) { |
| 70 | ALOGE("%s:NULL private handle for layer!", __FUNCTION__); |
| 71 | return false; |
| 72 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 73 | ovutils::Whf info(hnd->width, hnd->height, |
| 74 | ovutils::getMdpFormat(hnd->format), hnd->size); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 75 | |
| 76 | //Request an RGB pipe |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 77 | ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 78 | if(dest == ovutils::OV_INVALID) { //None available |
| 79 | return false; |
| 80 | } |
| 81 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 82 | mDest = dest; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 83 | |
| 84 | ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_FLAGS_NONE; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 85 | |
| 86 | ovutils::PipeArgs parg(mdpFlags, |
| 87 | info, |
| 88 | ovutils::ZORDER_0, |
| 89 | ovutils::IS_FG_SET, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 90 | ovutils::ROT_FLAGS_NONE); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 91 | ov.setSource(parg, dest); |
| 92 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 93 | hwc_rect_t sourceCrop; |
| 94 | getNonWormholeRegion(list, sourceCrop); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 95 | // x,y,w,h |
| 96 | ovutils::Dim dcrop(sourceCrop.left, sourceCrop.top, |
| 97 | sourceCrop.right - sourceCrop.left, |
| 98 | sourceCrop.bottom - sourceCrop.top); |
| 99 | ov.setCrop(dcrop, dest); |
| 100 | |
| 101 | int transform = layer->transform; |
| 102 | ovutils::eTransform orient = |
| 103 | static_cast<ovutils::eTransform>(transform); |
| 104 | ov.setTransform(orient, dest); |
| 105 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 106 | hwc_rect_t displayFrame = sourceCrop; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 107 | ovutils::Dim dpos(displayFrame.left, |
| 108 | displayFrame.top, |
| 109 | displayFrame.right - displayFrame.left, |
| 110 | displayFrame.bottom - displayFrame.top); |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 111 | // Calculate the actionsafe dimensions for External(dpy = 1 or 2) |
| 112 | if(mDpy) |
| 113 | getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 114 | ov.setPosition(dpos, dest); |
| 115 | |
| 116 | ret = true; |
| 117 | if (!ov.commit(dest)) { |
| 118 | ALOGE("%s: commit fails", __FUNCTION__); |
| 119 | ret = false; |
| 120 | } |
| 121 | } |
| 122 | return ret; |
| 123 | } |
| 124 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 125 | bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd) |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 126 | { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 127 | if(!mModeOn) { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 128 | return true; |
| 129 | } |
| 130 | bool ret = true; |
| 131 | overlay::Overlay& ov = *(ctx->mOverlay); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 132 | ovutils::eDest dest = mDest; |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 133 | if (!ov.queueBuffer(hnd->fd, hnd->offset, dest)) { |
Amara Venkata Mastan Manoj Kumar | dc01a53 | 2013-01-30 18:34:56 -0800 | [diff] [blame] | 134 | ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 135 | ret = false; |
| 136 | } |
| 137 | return ret; |
| 138 | } |
| 139 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 140 | //================= High res==================================== |
| 141 | FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {} |
| 142 | |
| 143 | inline void FBUpdateHighRes::reset() { |
| 144 | IFBUpdate::reset(); |
| 145 | mDestLeft = ovutils::OV_INVALID; |
| 146 | mDestRight = ovutils::OV_INVALID; |
| 147 | } |
| 148 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 149 | bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list) |
| 150 | { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 151 | if(!ctx->mMDP.hasOverlay) { |
| 152 | ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays", |
| 153 | __FUNCTION__); |
| 154 | return false; |
| 155 | } |
| 156 | ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 157 | mModeOn = configure(ctx, list); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 158 | return mModeOn; |
| 159 | } |
| 160 | |
| 161 | // Configure |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 162 | bool FBUpdateHighRes::configure(hwc_context_t *ctx, |
| 163 | hwc_display_contents_1 *list) |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 164 | { |
| 165 | bool ret = false; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 166 | hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1]; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 167 | if (LIKELY(ctx->mOverlay)) { |
| 168 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 169 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 170 | if (!hnd) { |
| 171 | ALOGE("%s:NULL private handle for layer!", __FUNCTION__); |
| 172 | return false; |
| 173 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 174 | ovutils::Whf info(hnd->width, hnd->height, |
| 175 | ovutils::getMdpFormat(hnd->format), hnd->size); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 176 | |
| 177 | //Request left RGB pipe |
| 178 | ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy); |
| 179 | if(destL == ovutils::OV_INVALID) { //None available |
| 180 | return false; |
| 181 | } |
| 182 | //Request right RGB pipe |
| 183 | ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy); |
| 184 | if(destR == ovutils::OV_INVALID) { //None available |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | mDestLeft = destL; |
| 189 | mDestRight = destR; |
| 190 | |
| 191 | ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_FLAGS_NONE; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 192 | |
| 193 | ovutils::PipeArgs pargL(mdpFlagsL, |
| 194 | info, |
| 195 | ovutils::ZORDER_0, |
| 196 | ovutils::IS_FG_SET, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 197 | ovutils::ROT_FLAGS_NONE); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 198 | ov.setSource(pargL, destL); |
| 199 | |
| 200 | ovutils::eMdpFlags mdpFlagsR = mdpFlagsL; |
| 201 | ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER); |
| 202 | ovutils::PipeArgs pargR(mdpFlagsR, |
| 203 | info, |
| 204 | ovutils::ZORDER_0, |
| 205 | ovutils::IS_FG_SET, |
Ramkumar Radhakrishnan | 288f8c7 | 2013-01-15 11:37:54 -0800 | [diff] [blame] | 206 | ovutils::ROT_FLAGS_NONE); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 207 | ov.setSource(pargR, destR); |
| 208 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 209 | hwc_rect_t sourceCrop; |
| 210 | getNonWormholeRegion(list, sourceCrop); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 211 | ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top, |
| 212 | (sourceCrop.right - sourceCrop.left) / 2, |
| 213 | sourceCrop.bottom - sourceCrop.top); |
| 214 | ovutils::Dim dcropR( |
| 215 | sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2, |
| 216 | sourceCrop.top, |
| 217 | (sourceCrop.right - sourceCrop.left) / 2, |
| 218 | sourceCrop.bottom - sourceCrop.top); |
| 219 | ov.setCrop(dcropL, destL); |
| 220 | ov.setCrop(dcropR, destR); |
| 221 | |
| 222 | int transform = layer->transform; |
| 223 | ovutils::eTransform orient = |
| 224 | static_cast<ovutils::eTransform>(transform); |
| 225 | ov.setTransform(orient, destL); |
| 226 | ov.setTransform(orient, destR); |
| 227 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 228 | hwc_rect_t displayFrame = sourceCrop; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 229 | //For FB left, top will always be 0 |
| 230 | //That should also be the case if using 2 mixers for single display |
Arun Kumar K.R | 0e8efb8 | 2013-03-18 17:31:50 -0700 | [diff] [blame] | 231 | ovutils::Dim dposL(displayFrame.left, |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 232 | displayFrame.top, |
| 233 | (displayFrame.right - displayFrame.left) / 2, |
| 234 | displayFrame.bottom - displayFrame.top); |
Arun Kumar K.R | 0e8efb8 | 2013-03-18 17:31:50 -0700 | [diff] [blame] | 235 | ov.setPosition(dposL, destL); |
| 236 | ovutils::Dim dposR(0, |
| 237 | displayFrame.top, |
| 238 | (displayFrame.right - displayFrame.left) / 2, |
| 239 | displayFrame.bottom - displayFrame.top); |
| 240 | ov.setPosition(dposR, destR); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 241 | |
| 242 | ret = true; |
| 243 | if (!ov.commit(destL)) { |
| 244 | ALOGE("%s: commit fails for left", __FUNCTION__); |
| 245 | ret = false; |
| 246 | } |
| 247 | if (!ov.commit(destR)) { |
| 248 | ALOGE("%s: commit fails for right", __FUNCTION__); |
| 249 | ret = false; |
| 250 | } |
| 251 | } |
| 252 | return ret; |
| 253 | } |
| 254 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 255 | bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd) |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 256 | { |
| 257 | if(!mModeOn) { |
| 258 | return true; |
| 259 | } |
| 260 | bool ret = true; |
| 261 | overlay::Overlay& ov = *(ctx->mOverlay); |
| 262 | ovutils::eDest destL = mDestLeft; |
| 263 | ovutils::eDest destR = mDestRight; |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 264 | if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) { |
| 265 | ALOGE("%s: queue failed for left of dpy = %d", |
| 266 | __FUNCTION__, mDpy); |
| 267 | ret = false; |
| 268 | } |
| 269 | if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) { |
| 270 | ALOGE("%s: queue failed for right of dpy = %d", |
| 271 | __FUNCTION__, mDpy); |
| 272 | ret = false; |
| 273 | } |
| 274 | return ret; |
| 275 | } |
| 276 | |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 277 | //--------------------------------------------------------------------- |
| 278 | }; //namespace qhwc |