blob: 7d00d9cfeaeb11fa769e9ebd854d3d40af903867 [file] [log] [blame]
Naseer Ahmed758bfc52012-11-28 17:02:08 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +05303 * Copyright (C) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmed758bfc52012-11-28 17:02:08 -05004 *
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>
Saurabh Shahaf5f5972013-07-30 13:56:35 -070024#include <overlay.h>
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070025#include <overlayRotator.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050026#include "hwc_fbupdate.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070027#include "mdp_version.h"
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070028#include "external.h"
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -070029#include "virtual.h"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070030
31using namespace qdutils;
Saurabh Shahaf5f5972013-07-30 13:56:35 -070032using namespace overlay;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070033using overlay::Rotator;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -070034using namespace overlay::utils;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070035
Naseer Ahmed758bfc52012-11-28 17:02:08 -050036namespace qhwc {
37
38namespace ovutils = overlay::utils;
39
Saurabh Shah88e4d272013-09-03 13:31:29 -070040IFBUpdate* IFBUpdate::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070041 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
42 return new FBSrcSplit(ctx, dpy);
43 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah220a30c2013-10-29 16:12:12 -070044 return new FBUpdateSplit(ctx, dpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -080045 }
Saurabh Shah220a30c2013-10-29 16:12:12 -070046 return new FBUpdateNonSplit(ctx, dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050047}
48
Saurabh Shah220a30c2013-10-29 16:12:12 -070049IFBUpdate::IFBUpdate(hwc_context_t *ctx, const int& dpy) : mDpy(dpy) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070050 unsigned int size = 0;
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053051 uint32_t xres = ctx->dpyAttr[mDpy].xres;
52 uint32_t yres = ctx->dpyAttr[mDpy].yres;
53 if (ctx->dpyAttr[dpy].customFBSize) {
54 //GPU will render and compose at new resolution
55 //So need to have FB at new resolution
56 xres = ctx->dpyAttr[mDpy].xres_new;
57 yres = ctx->dpyAttr[mDpy].yres_new;
58 }
59 getBufferAttributes((int)xres, (int)yres,
Saurabh Shah220a30c2013-10-29 16:12:12 -070060 HAL_PIXEL_FORMAT_RGBA_8888,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070061 0,
Saurabh Shah220a30c2013-10-29 16:12:12 -070062 mAlignedFBWidth,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070063 mAlignedFBHeight,
64 mTileEnabled, size);
Saurabh Shah220a30c2013-10-29 16:12:12 -070065}
66
67void IFBUpdate::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080068 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070069 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080070}
71
Saurabh Shaha36be922013-12-16 18:18:39 -080072bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx,
73 hwc_display_contents_1 *list, int fbZorder) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -080074 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070075 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) &&
Saurabh Shaha36be922013-12-16 18:18:39 -080076 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd);
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070077 return mModeOn;
Saurabh Shaha36be922013-12-16 18:18:39 -080078}
79
Saurabh Shahcf053c62012-12-13 12:32:55 -080080//================= Low res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -070081FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy):
82 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -080083
Saurabh Shah220a30c2013-10-29 16:12:12 -070084void FBUpdateNonSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080085 IFBUpdate::reset();
86 mDest = ovutils::OV_INVALID;
87}
88
Saurabh Shah88e4d272013-09-03 13:31:29 -070089bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx,
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +053090 hwc_layer_1_t *layer,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -070091 ovutils::Whf &info,
92 hwc_rect_t& sourceCrop,
93 ovutils::eMdpFlags& mdpFlags,
94 int& rotFlags)
95{
96 int extOrient = getExtOrientation(ctx);
97 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient);
98 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) {
99 mRot = ctx->mRotMgr->getNext();
100 if(mRot == NULL) return false;
Saurabh Shah39240c92014-03-31 10:31:42 -0700101 ctx->mLayerRotMap[mDpy]->add(layer, mRot);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800102 // Composed FB content will have black bars, if the viewFrame of the
103 // external is different from {0, 0, fbWidth, fbHeight}, so intersect
104 // viewFrame with sourceCrop to avoid those black bars
105 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700106 //Configure rotator for pre-rotation
107 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
108 ALOGE("%s: configRotator Failed!", __FUNCTION__);
109 mRot = NULL;
110 return false;
111 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700112 updateSource(orient, info, sourceCrop, mRot);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700113 rotFlags |= ovutils::ROT_PREROTATED;
114 }
115 return true;
116}
117
Saurabh Shah88e4d272013-09-03 13:31:29 -0700118bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800119 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500120 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800121 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800122 __FUNCTION__);
123 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800125 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800126 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500127}
128
129// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700130bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800131 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500133 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500134 if (LIKELY(ctx->mOverlay)) {
135 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700136
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700137 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
138 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
139 mTileEnabled));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140
Saurabh Shahc62f3982014-03-05 14:28:26 -0800141 Overlay::PipeSpecs pipeSpecs;
142 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
143 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
144 pipeSpecs.dpy = mDpy;
145 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
146 pipeSpecs.fb = true;
147
148 ovutils::eDest dest = ov.getPipe(pipeSpecs);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700150 ALOGE("%s: No pipes available to configure fb for dpy %d",
151 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 return false;
153 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800154 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155
Ramkumar Radhakrishnan1829d282013-07-23 14:54:36 -0700156 if((mDpy && ctx->deviceOrientation) &&
157 ctx->listStats[mDpy].isDisplayAnimating) {
158 fbZorder = 0;
159 }
160
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800162 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500163
Saurabh Shah62e1d732013-09-17 10:44:05 -0700164 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800165 hwc_rect_t displayFrame = layer->displayFrame;
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800166
167 // No FB update optimization on (1) Custom FB resolution,
168 // (2) External Mirror mode, (3) External orientation
169 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
170 && !ctx->mExtOrientation) {
171 sourceCrop = fbUpdatingRect;
172 displayFrame = fbUpdatingRect;
173 }
174
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700175 int transform = layer->transform;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700176 int rotFlags = ovutils::ROT_FLAGS_NONE;
177
178 ovutils::eTransform orient =
179 static_cast<ovutils::eTransform>(transform);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700180 // use ext orientation if any
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700181 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700182
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700183 // Do not use getNonWormholeRegion() function to calculate the
184 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700185 // Dont do wormhole calculation when extorientation is set on External
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700186 // Dont do wormhole calculation when extDownscale is enabled on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700187 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
188 sourceCrop = layer->displayFrame;
Ramkumar Radhakrishnan3b0d9722014-08-06 13:08:40 -0700189 } else if((mDpy && !extOrient
190 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530191 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530192 !ctx->dpyAttr[mDpy].customFBSize) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700193 getNonWormholeRegion(list, sourceCrop);
194 displayFrame = sourceCrop;
195 }
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800196 }
Saurabh Shah220a30c2013-10-29 16:12:12 -0700197 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700198 transform, orient);
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800199 //Store the displayFrame, will be used in getDisplayViewFrame
200 ctx->dpyAttr[mDpy].mDstRect = displayFrame;
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800201 setMdpFlags(ctx, layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700202 // For External use rotator if there is a rotation value set
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +0530203 ret = preRotateExtDisplay(ctx, layer, info,
204 sourceCrop, mdpFlags, rotFlags);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700205 if(!ret) {
206 ALOGE("%s: preRotate for external Failed!", __FUNCTION__);
207 return false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700208 }
209 //For the mdp, since either we are pre-rotating or MDP does flips
210 orient = ovutils::OVERLAY_TRANSFORM_0;
211 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700212 ovutils::PipeArgs parg(mdpFlags, info, zOrder,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400213 static_cast<ovutils::eRotFlags>(rotFlags),
214 ovutils::DEFAULT_PLANE_ALPHA,
215 (ovutils::eBlending)
216 getBlending(layer->blending));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500217 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700218 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
219 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700220 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500221 ret = false;
222 }
223 }
224 return ret;
225}
226
Saurabh Shah88e4d272013-09-03 13:31:29 -0700227bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500228{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800229 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500230 return true;
231 }
232 bool ret = true;
233 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800234 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700235 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530236 uint32_t offset = (uint32_t)hnd->offset;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700237 if(mRot) {
238 if(!mRot->queueBuffer(fd, offset))
239 return false;
240 fd = mRot->getDstMemId();
241 offset = mRot->getDstOffset();
242 }
243 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800244 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500245 ret = false;
246 }
247 return ret;
248}
249
Saurabh Shahcf053c62012-12-13 12:32:55 -0800250//================= High res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -0700251FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy):
252 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -0800253
Saurabh Shah220a30c2013-10-29 16:12:12 -0700254void FBUpdateSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800255 IFBUpdate::reset();
256 mDestLeft = ovutils::OV_INVALID;
257 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700258 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800259}
260
Saurabh Shah88e4d272013-09-03 13:31:29 -0700261bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800262 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800263 if(!ctx->mMDP.hasOverlay) {
264 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800265 __FUNCTION__);
266 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800267 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800268 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Raj Kamal4393eaa2014-06-06 13:45:20 +0530269 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800270 return mModeOn;
271}
272
273// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700274bool FBUpdateSplit::configure(hwc_context_t *ctx,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800275 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800276 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500277 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800278 if (LIKELY(ctx->mOverlay)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800279 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
280 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
281 mTileEnabled));
282
Saurabh Shahcf053c62012-12-13 12:32:55 -0800283 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800284 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800285 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800286 ovutils::eTransform orient =
287 static_cast<ovutils::eTransform>(layer->transform);
288 const int hw_w = ctx->dpyAttr[mDpy].xres;
289 const int hw_h = ctx->dpyAttr[mDpy].yres;
290 const int lSplit = getLeftSplit(ctx, mDpy);
291 mDestLeft = ovutils::OV_INVALID;
292 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700293 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
294 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800295
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700296 // No FB update optimization on (1) Custom FB resolution,
297 // (2) External Mirror mode, (3) External orientation
298 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
299 && !ctx->mExtOrientation) {
300 sourceCrop = fbUpdatingRect;
301 displayFrame = fbUpdatingRect;
302 }
303
304 int transform = layer->transform;
305 // use ext orientation if any
306 int extOrient = getExtOrientation(ctx);
307
308 // Do not use getNonWormholeRegion() function to calculate the
309 // sourceCrop during animation on external display and
310 // Dont do wormhole calculation when extorientation is set on External
311 // Dont do wormhole calculation when extDownscale is enabled on External
312 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
313 sourceCrop = layer->displayFrame;
314 } else if((mDpy && !extOrient
315 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
316 if(!qdutils::MDPVersion::getInstance().is8x26() &&
317 !ctx->dpyAttr[mDpy].customFBSize) {
318 getNonWormholeRegion(list, sourceCrop);
319 displayFrame = sourceCrop;
320 }
321 }
322
323 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
324 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700325
Saurabh Shahcf053c62012-12-13 12:32:55 -0800326 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800327 Overlay::PipeSpecs pipeSpecs;
328 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
329 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
330 pipeSpecs.dpy = mDpy;
331 pipeSpecs.fb = true;
332
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800333 /* Configure left pipe */
334 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800335 pipeSpecs.mixer = Overlay::MIXER_LEFT;
336 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800337 if(destL == ovutils::OV_INVALID) { //None available
338 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
339 " mixer", __FUNCTION__, mDpy);
340 return false;
341 }
342
343 mDestLeft = destL;
344
345 //XXX: FB layer plane alpha is currently sent as zero from
346 //surfaceflinger
347 ovutils::PipeArgs pargL(mdpFlags,
348 info,
349 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800350 ovutils::ROT_FLAGS_NONE,
351 ovutils::DEFAULT_PLANE_ALPHA,
352 (ovutils::eBlending)
353 getBlending(layer->blending));
354 hwc_rect_t cropL = sourceCrop;
355 hwc_rect_t dstL = displayFrame;
356 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
357 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
358
359 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
360 dstL, NULL, destL)< 0) {
361 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
362 ret = false;
363 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800364 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800365
366 /* Configure right pipe */
367 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800368 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
369 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800370 if(destR == ovutils::OV_INVALID) { //None available
371 ALOGE("%s: No pipes available to configure fb for dpy %d's"
372 " right mixer", __FUNCTION__, mDpy);
373 return false;
374 }
375
376 mDestRight = destR;
377 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
378 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
379
380 //XXX: FB layer plane alpha is currently sent as zero from
381 //surfaceflinger
382 ovutils::PipeArgs pargR(mdpFlagsR,
383 info,
384 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800385 ovutils::ROT_FLAGS_NONE,
386 ovutils::DEFAULT_PLANE_ALPHA,
387 (ovutils::eBlending)
388 getBlending(layer->blending));
389
390 hwc_rect_t cropR = sourceCrop;
391 hwc_rect_t dstR = displayFrame;
392 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
393 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
394
395 dstR.left -= lSplit;
396 dstR.right -= lSplit;
397
398 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
399 dstR, NULL, destR) < 0) {
400 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
401 ret = false;
402 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800403 }
404 }
405 return ret;
406}
407
Saurabh Shah88e4d272013-09-03 13:31:29 -0700408bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800409{
410 if(!mModeOn) {
411 return true;
412 }
413 bool ret = true;
414 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800415 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530416 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800417 ALOGE("%s: queue failed for left of dpy = %d",
418 __FUNCTION__, mDpy);
419 ret = false;
420 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800421 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800422 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530423 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800424 ALOGE("%s: queue failed for right of dpy = %d",
425 __FUNCTION__, mDpy);
426 ret = false;
427 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800428 }
429 return ret;
430}
431
Saurabh Shahab47c692014-02-12 18:45:57 -0800432//=================FBSrcSplit====================================
433FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
434 FBUpdateSplit(ctx, dpy) {}
435
436bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
437 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800438 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800439 overlay::Overlay& ov = *(ctx->mOverlay);
440
441 ovutils::Whf info(mAlignedFBWidth,
442 mAlignedFBHeight,
443 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
444 mTileEnabled));
Saurabh Shahab47c692014-02-12 18:45:57 -0800445
446 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
447 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
448
449 ovutils::PipeArgs parg(mdpFlags,
450 info,
451 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800452 ovutils::ROT_FLAGS_NONE,
453 ovutils::DEFAULT_PLANE_ALPHA,
454 (ovutils::eBlending)
455 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800456
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700457 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
458 hwc_rect_t displayFrame = layer->displayFrame;
459
460 // No FB update optimization on (1) Custom FB resolution,
461 // (2) External Mirror mode, (3) External orientation
462 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
463 && !ctx->mExtOrientation) {
464 sourceCrop = fbUpdatingRect;
465 displayFrame = fbUpdatingRect;
466 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800467 int transform = layer->transform;
468 ovutils::eTransform orient =
469 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800470
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700471 // use ext orientation if any
472 int extOrient = getExtOrientation(ctx);
473
474 // Do not use getNonWormholeRegion() function to calculate the
475 // sourceCrop during animation on external display and
476 // Dont do wormhole calculation when extorientation is set on External
477 // Dont do wormhole calculation when extDownscale is enabled on External
478 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
479 sourceCrop = layer->displayFrame;
480 } else if((mDpy && !extOrient
481 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
482 if(!qdutils::MDPVersion::getInstance().is8x26() &&
483 !ctx->dpyAttr[mDpy].customFBSize) {
484 getNonWormholeRegion(list, sourceCrop);
485 displayFrame = sourceCrop;
486 }
487 }
488
489 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
490 transform, orient);
491 hwc_rect_t cropL = sourceCrop;
492 hwc_rect_t cropR = sourceCrop;
493 hwc_rect_t dstL = displayFrame;
494 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800495
496 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800497 Overlay::PipeSpecs pipeSpecs;
498 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
499 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
500 pipeSpecs.dpy = mDpy;
501 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
502 pipeSpecs.fb = true;
503 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800504 if(destL == ovutils::OV_INVALID) {
505 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
506 " mixer", __FUNCTION__, mDpy);
507 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800508 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800509
510 ovutils::eDest destR = ovutils::OV_INVALID;
511
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700512 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530513 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700514 b) On primary, driver has indicated with caps to split always. This is
515 based on an empirically derived value of panel height.
516 */
517
518 bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
519 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
520
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700521 if(((sourceCrop.right - sourceCrop.left) >
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530522 (int)qdutils::MDPVersion::getInstance().getMaxMixerWidth()) or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700523 primarySplitAlways) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800524 destR = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800525 if(destR == ovutils::OV_INVALID) {
526 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
527 " mixer", __FUNCTION__, mDpy);
528 return false;
529 }
530
531 if(ctx->mOverlay->comparePipePriority(destL, destR) == -1) {
532 qhwc::swap(destL, destR);
533 }
534
535 //Split crop equally when using 2 pipes
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700536 cropL.right = (sourceCrop.right + sourceCrop.left) / 2;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800537 cropR.left = cropL.right;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700538 dstL.right = (displayFrame.right + displayFrame.left) / 2;
539 dstR.left = dstL.right;
Saurabh Shahab47c692014-02-12 18:45:57 -0800540 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800541
542 mDestLeft = destL;
543 mDestRight = destR;
544
545 if(destL != OV_INVALID) {
546 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700547 cropL, dstL, NULL /*metadata*/, destL) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800548 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800549 return false;
550 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800551 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800552
553 //configure right pipe
554 if(destR != OV_INVALID) {
555 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700556 cropR, dstR, NULL /*metadata*/, destR) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800557 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800558 return false;
559 }
560 }
561
562 return true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800563}
564
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500565//---------------------------------------------------------------------
566}; //namespace qhwc