blob: 8707edff527c3440f5eb4356169307696b49a80d [file] [log] [blame]
Naseer Ahmed758bfc52012-11-28 17:02:08 -05001/*
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 Shahcf053c62012-12-13 12:32:55 -080021#define DEBUG_FBUPDATE 0
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070022#include <cutils/properties.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <gralloc_priv.h>
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070024#include <overlayRotator.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050025#include "hwc_fbupdate.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070026#include "mdp_version.h"
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070027#include "external.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070028
29using namespace qdutils;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070031using overlay::Rotator;
32
Naseer Ahmed758bfc52012-11-28 17:02:08 -050033namespace qhwc {
34
35namespace ovutils = overlay::utils;
36
Saurabh Shahcf053c62012-12-13 12:32:55 -080037IFBUpdate* IFBUpdate::getObject(const int& width, const int& dpy) {
38 if(width > MAX_DISPLAY_DIM) {
39 return new FBUpdateHighRes(dpy);
40 }
41 return new FBUpdateLowRes(dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050042}
43
Saurabh Shahcf053c62012-12-13 12:32:55 -080044inline void IFBUpdate::reset() {
45 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070046 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080047}
48
49//================= Low res====================================
50FBUpdateLowRes::FBUpdateLowRes(const int& dpy): IFBUpdate(dpy) {}
51
52inline void FBUpdateLowRes::reset() {
53 IFBUpdate::reset();
54 mDest = ovutils::OV_INVALID;
55}
56
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080057bool FBUpdateLowRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
58 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050059 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -080060 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080061 __FUNCTION__);
62 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050063 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080064 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -080065 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050066}
67
68// Configure
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080069bool FBUpdateLowRes::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
70 int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -050071 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -050072 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -050073 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -080074 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
75 // ext only layer present..
76 if(extOnlyLayerIndex != -1) {
77 layer = &list->hwLayers[extOnlyLayerIndex];
78 layer->compositionType = HWC_OVERLAY;
79 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -050080 overlay::Overlay& ov = *(ctx->mOverlay);
81 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -080082 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080083 ovutils::getMdpFormat(hnd->format), hnd->size);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050084
85 //Request an RGB pipe
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080086 ovutils::eDest dest = ov.nextPipe(ovutils::OV_MDP_PIPE_ANY, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050087 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -070088 ALOGE("%s: No pipes available to configure fb for dpy %d",
89 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050090 return false;
91 }
92
Saurabh Shahcf053c62012-12-13 12:32:55 -080093 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -050094
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080095 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070096 ovutils::eIsFg isFg = ovutils::IS_FG_OFF;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -080097 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050098
Arun Kumar K.Ra2978452013-02-07 01:34:24 -080099 hwc_rect_t sourceCrop = layer->sourceCrop;
100 hwc_rect_t displayFrame = layer->displayFrame;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700101 int transform = layer->transform;
102 int fbWidth = ctx->dpyAttr[mDpy].xres;
103 int fbHeight = ctx->dpyAttr[mDpy].yres;
104 int rotFlags = ovutils::ROT_FLAGS_NONE;
105
106 ovutils::eTransform orient =
107 static_cast<ovutils::eTransform>(transform);
108 if(mDpy && ctx->mExtOrientation) {
109 // If there is a external orientation set, use that
110 transform = ctx->mExtOrientation;
111 orient = static_cast<ovutils::eTransform >(ctx->mExtOrientation);
112 }
113
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700114 // Do not use getNonWormholeRegion() function to calculate the
115 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700116 // Dont do wormhole calculation when extorientation is set on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700117 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
118 sourceCrop = layer->displayFrame;
119 displayFrame = sourceCrop;
120 } else if((!mDpy || (mDpy && !ctx->mExtOrientation))
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700121 && extOnlyLayerIndex == -1) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800122 getNonWormholeRegion(list, sourceCrop);
123 displayFrame = sourceCrop;
124 }
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125 ovutils::Dim dpos(displayFrame.left,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800126 displayFrame.top,
127 displayFrame.right - displayFrame.left,
128 displayFrame.bottom - displayFrame.top);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700130 if(mDpy) {
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700131 // Get Aspect Ratio for external
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700132 getAspectRatioPosition(ctx, mDpy, ctx->mExtOrientation, dpos.x,
133 dpos.y, dpos.w, dpos.h);
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700134 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
135 getActionSafePosition(ctx, mDpy, dpos.x, dpos.y, dpos.w, dpos.h);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700136 // Convert dim to hwc_rect_t
137 displayFrame.left = dpos.x;
138 displayFrame.top = dpos.y;
139 displayFrame.right = dpos.w + displayFrame.left;
140 displayFrame.bottom = dpos.h + displayFrame.top;
141 }
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -0700142 setMdpFlags(layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700143 // For External use rotator if there is a rotation value set
144 if(mDpy && (ctx->mExtOrientation & HWC_TRANSFORM_ROT_90)) {
145 mRot = ctx->mRotMgr->getNext();
146 if(mRot == NULL) return -1;
147 //Configure rotator for pre-rotation
148 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
149 ALOGE("%s: configRotator Failed!", __FUNCTION__);
150 mRot = NULL;
151 return -1;
152 }
153 info.format = (mRot)->getDstFormat();
154 updateSource(orient, info, sourceCrop);
155 rotFlags |= ovutils::ROT_PREROTATED;
156 }
157 //For the mdp, since either we are pre-rotating or MDP does flips
158 orient = ovutils::OVERLAY_TRANSFORM_0;
159 transform = 0;
160 ovutils::PipeArgs parg(mdpFlags, info, zOrder, isFg,
161 static_cast<ovutils::eRotFlags>(rotFlags));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500162 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700163 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
164 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700165 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500166 ret = false;
167 }
168 }
169 return ret;
170}
171
Naseer Ahmed64b81212013-02-14 10:29:47 -0500172bool FBUpdateLowRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500173{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800174 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500175 return true;
176 }
177 bool ret = true;
178 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800179 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700180 int fd = hnd->fd;
181 uint32_t offset = hnd->offset;
182 if(mRot) {
183 if(!mRot->queueBuffer(fd, offset))
184 return false;
185 fd = mRot->getDstMemId();
186 offset = mRot->getDstOffset();
187 }
188 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800189 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500190 ret = false;
191 }
192 return ret;
193}
194
Saurabh Shahcf053c62012-12-13 12:32:55 -0800195//================= High res====================================
196FBUpdateHighRes::FBUpdateHighRes(const int& dpy): IFBUpdate(dpy) {}
197
198inline void FBUpdateHighRes::reset() {
199 IFBUpdate::reset();
200 mDestLeft = ovutils::OV_INVALID;
201 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700202 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800203}
204
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800205bool FBUpdateHighRes::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
206 int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800207 if(!ctx->mMDP.hasOverlay) {
208 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800209 __FUNCTION__);
210 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800211 }
212 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800213 mModeOn = configure(ctx, list, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800214 return mModeOn;
215}
216
217// Configure
Naseer Ahmed64b81212013-02-14 10:29:47 -0500218bool FBUpdateHighRes::configure(hwc_context_t *ctx,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800219 hwc_display_contents_1 *list, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800220 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500221 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800222 if (LIKELY(ctx->mOverlay)) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800223 int extOnlyLayerIndex = ctx->listStats[mDpy].extOnlyLayerIndex;
224 // ext only layer present..
225 if(extOnlyLayerIndex != -1) {
226 layer = &list->hwLayers[extOnlyLayerIndex];
227 layer->compositionType = HWC_OVERLAY;
228 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800229 overlay::Overlay& ov = *(ctx->mOverlay);
230 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shahacf10202013-02-26 10:15:15 -0800231 ovutils::Whf info(hnd->width, hnd->height,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800232 ovutils::getMdpFormat(hnd->format), hnd->size);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800233
234 //Request left RGB pipe
235 ovutils::eDest destL = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
236 if(destL == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700237 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
238 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800239 return false;
240 }
241 //Request right RGB pipe
242 ovutils::eDest destR = ov.nextPipe(ovutils::OV_MDP_PIPE_RGB, mDpy);
243 if(destR == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700244 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
245 " mixer", __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800246 return false;
247 }
248
249 mDestLeft = destL;
250 mDestRight = destR;
251
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800252 ovutils::eMdpFlags mdpFlagsL = ovutils::OV_MDP_BLEND_FG_PREMULT;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530253
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800254 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800255
256 ovutils::PipeArgs pargL(mdpFlagsL,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800257 info,
258 zOrder,
259 ovutils::IS_FG_OFF,
260 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800261 ov.setSource(pargL, destL);
262
263 ovutils::eMdpFlags mdpFlagsR = mdpFlagsL;
264 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
265 ovutils::PipeArgs pargR(mdpFlagsR,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266 info,
267 zOrder,
268 ovutils::IS_FG_OFF,
269 ovutils::ROT_FLAGS_NONE);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800270 ov.setSource(pargR, destR);
271
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800272 hwc_rect_t sourceCrop = layer->sourceCrop;
273 hwc_rect_t displayFrame = layer->displayFrame;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700274 // Do not use getNonWormholeRegion() function to calculate the
275 // sourceCrop during animation on external display.
276 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
277 sourceCrop = layer->displayFrame;
278 displayFrame = sourceCrop;
279 } else if(extOnlyLayerIndex == -1) {
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800280 getNonWormholeRegion(list, sourceCrop);
281 displayFrame = sourceCrop;
282 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800283 ovutils::Dim dcropL(sourceCrop.left, sourceCrop.top,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800284 (sourceCrop.right - sourceCrop.left) / 2,
285 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800286 ovutils::Dim dcropR(
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800287 sourceCrop.left + (sourceCrop.right - sourceCrop.left) / 2,
288 sourceCrop.top,
289 (sourceCrop.right - sourceCrop.left) / 2,
290 sourceCrop.bottom - sourceCrop.top);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800291 ov.setCrop(dcropL, destL);
292 ov.setCrop(dcropR, destR);
293
294 int transform = layer->transform;
295 ovutils::eTransform orient =
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800296 static_cast<ovutils::eTransform>(transform);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800297 ov.setTransform(orient, destL);
298 ov.setTransform(orient, destR);
299
Saurabh Shahce416f02013-04-10 13:33:09 -0700300 const int halfWidth = (displayFrame.right - displayFrame.left) / 2;
301 const int height = displayFrame.bottom - displayFrame.top;
302
Saurabh Shahca317592013-05-02 14:53:58 -0700303 const int halfDpy = ctx->dpyAttr[mDpy].xres / 2;
304 ovutils::Dim dposL(halfDpy - halfWidth,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800305 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700306 halfWidth,
307 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700308 ov.setPosition(dposL, destL);
Saurabh Shahce416f02013-04-10 13:33:09 -0700309
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700310 ovutils::Dim dposR(0,
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800311 displayFrame.top,
Saurabh Shahce416f02013-04-10 13:33:09 -0700312 halfWidth,
313 height);
Arun Kumar K.R0e8efb82013-03-18 17:31:50 -0700314 ov.setPosition(dposR, destR);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800315
316 ret = true;
317 if (!ov.commit(destL)) {
318 ALOGE("%s: commit fails for left", __FUNCTION__);
319 ret = false;
320 }
321 if (!ov.commit(destR)) {
322 ALOGE("%s: commit fails for right", __FUNCTION__);
323 ret = false;
324 }
325 }
326 return ret;
327}
328
Naseer Ahmed64b81212013-02-14 10:29:47 -0500329bool FBUpdateHighRes::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800330{
331 if(!mModeOn) {
332 return true;
333 }
334 bool ret = true;
335 overlay::Overlay& ov = *(ctx->mOverlay);
336 ovutils::eDest destL = mDestLeft;
337 ovutils::eDest destR = mDestRight;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800338 if (!ov.queueBuffer(hnd->fd, hnd->offset, destL)) {
339 ALOGE("%s: queue failed for left of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800340 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800341 ret = false;
342 }
343 if (!ov.queueBuffer(hnd->fd, hnd->offset, destR)) {
344 ALOGE("%s: queue failed for right of dpy = %d",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800345 __FUNCTION__, mDpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800346 ret = false;
347 }
348 return ret;
349}
350
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500351//---------------------------------------------------------------------
352}; //namespace qhwc