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