blob: d5139f4b3f33fe3e5912749fcdad6400ea9e0350 [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"
Saurabh Shahbd2d0832013-04-04 14:33:08 -070029
30using namespace qdutils;
Saurabh Shahaf5f5972013-07-30 13:56:35 -070031using namespace overlay;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070032using overlay::Rotator;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -070033using namespace overlay::utils;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070034
Naseer Ahmed758bfc52012-11-28 17:02:08 -050035namespace qhwc {
36
37namespace ovutils = overlay::utils;
38
Saurabh Shah88e4d272013-09-03 13:31:29 -070039IFBUpdate* IFBUpdate::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070040 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
41 return new FBSrcSplit(ctx, dpy);
42 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah220a30c2013-10-29 16:12:12 -070043 return new FBUpdateSplit(ctx, dpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -080044 }
Saurabh Shah220a30c2013-10-29 16:12:12 -070045 return new FBUpdateNonSplit(ctx, dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050046}
47
Saurabh Shah220a30c2013-10-29 16:12:12 -070048IFBUpdate::IFBUpdate(hwc_context_t *ctx, const int& dpy) : mDpy(dpy) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070049 unsigned int size = 0;
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053050 uint32_t xres = ctx->dpyAttr[mDpy].xres;
51 uint32_t yres = ctx->dpyAttr[mDpy].yres;
52 if (ctx->dpyAttr[dpy].customFBSize) {
53 //GPU will render and compose at new resolution
54 //So need to have FB at new resolution
55 xres = ctx->dpyAttr[mDpy].xres_new;
56 yres = ctx->dpyAttr[mDpy].yres_new;
57 }
58 getBufferAttributes((int)xres, (int)yres,
Saurabh Shah220a30c2013-10-29 16:12:12 -070059 HAL_PIXEL_FORMAT_RGBA_8888,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070060 0,
Saurabh Shah220a30c2013-10-29 16:12:12 -070061 mAlignedFBWidth,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070062 mAlignedFBHeight,
63 mTileEnabled, size);
Saurabh Shah220a30c2013-10-29 16:12:12 -070064}
65
66void IFBUpdate::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080067 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070068 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080069}
70
Saurabh Shaha36be922013-12-16 18:18:39 -080071bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx,
72 hwc_display_contents_1 *list, int fbZorder) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -080073 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070074 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) &&
Saurabh Shaha36be922013-12-16 18:18:39 -080075 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd);
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070076 return mModeOn;
Saurabh Shaha36be922013-12-16 18:18:39 -080077}
78
Saurabh Shahcf053c62012-12-13 12:32:55 -080079//================= Low res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -070080FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy):
81 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -080082
Saurabh Shah220a30c2013-10-29 16:12:12 -070083void FBUpdateNonSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080084 IFBUpdate::reset();
85 mDest = ovutils::OV_INVALID;
86}
87
Saurabh Shah88e4d272013-09-03 13:31:29 -070088bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx,
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +053089 hwc_layer_1_t *layer,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -070090 ovutils::Whf &info,
91 hwc_rect_t& sourceCrop,
92 ovutils::eMdpFlags& mdpFlags,
93 int& rotFlags)
94{
95 int extOrient = getExtOrientation(ctx);
96 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient);
97 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) {
98 mRot = ctx->mRotMgr->getNext();
99 if(mRot == NULL) return false;
Saurabh Shah39240c92014-03-31 10:31:42 -0700100 ctx->mLayerRotMap[mDpy]->add(layer, mRot);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800101 // Composed FB content will have black bars, if the viewFrame of the
102 // external is different from {0, 0, fbWidth, fbHeight}, so intersect
103 // viewFrame with sourceCrop to avoid those black bars
104 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700105 //Configure rotator for pre-rotation
106 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
107 ALOGE("%s: configRotator Failed!", __FUNCTION__);
108 mRot = NULL;
109 return false;
110 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700111 updateSource(orient, info, sourceCrop, mRot);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700112 rotFlags |= ovutils::ROT_PREROTATED;
113 }
114 return true;
115}
116
Saurabh Shah88e4d272013-09-03 13:31:29 -0700117bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800118 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800120 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 __FUNCTION__);
122 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800124 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800125 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126}
127
128// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700129bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800130 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500132 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 if (LIKELY(ctx->mOverlay)) {
134 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700135
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700136 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
137 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
138 mTileEnabled));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500139
Saurabh Shahc62f3982014-03-05 14:28:26 -0800140 Overlay::PipeSpecs pipeSpecs;
141 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
142 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
143 pipeSpecs.dpy = mDpy;
144 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
145 pipeSpecs.fb = true;
146
147 ovutils::eDest dest = ov.getPipe(pipeSpecs);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500148 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700149 ALOGE("%s: No pipes available to configure fb for dpy %d",
150 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500151 return false;
152 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800153 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500154
Ramkumar Radhakrishnan1829d282013-07-23 14:54:36 -0700155 if((mDpy && ctx->deviceOrientation) &&
156 ctx->listStats[mDpy].isDisplayAnimating) {
157 fbZorder = 0;
158 }
159
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800160 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500162
Saurabh Shah62e1d732013-09-17 10:44:05 -0700163 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800164 hwc_rect_t displayFrame = layer->displayFrame;
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800165
166 // No FB update optimization on (1) Custom FB resolution,
167 // (2) External Mirror mode, (3) External orientation
168 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
169 && !ctx->mExtOrientation) {
170 sourceCrop = fbUpdatingRect;
171 displayFrame = fbUpdatingRect;
172 }
173
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700174 int transform = layer->transform;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700175 int rotFlags = ovutils::ROT_FLAGS_NONE;
176
177 ovutils::eTransform orient =
178 static_cast<ovutils::eTransform>(transform);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700179 // use ext orientation if any
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700180 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700181
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700182 // Do not use getNonWormholeRegion() function to calculate the
183 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700184 // Dont do wormhole calculation when extorientation is set on External
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700185 // Dont do wormhole calculation when extDownscale is enabled on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700186 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
187 sourceCrop = layer->displayFrame;
Ramkumar Radhakrishnan3b0d9722014-08-06 13:08:40 -0700188 } else if((mDpy && !extOrient
189 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530190 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530191 !ctx->dpyAttr[mDpy].customFBSize) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700192 getNonWormholeRegion(list, sourceCrop);
193 displayFrame = sourceCrop;
194 }
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800195 }
Saurabh Shah220a30c2013-10-29 16:12:12 -0700196 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700197 transform, orient);
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800198 //Store the displayFrame, will be used in getDisplayViewFrame
199 ctx->dpyAttr[mDpy].mDstRect = displayFrame;
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800200 setMdpFlags(ctx, layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700201 // For External use rotator if there is a rotation value set
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +0530202 ret = preRotateExtDisplay(ctx, layer, info,
203 sourceCrop, mdpFlags, rotFlags);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700204 if(!ret) {
205 ALOGE("%s: preRotate for external Failed!", __FUNCTION__);
206 return false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700207 }
208 //For the mdp, since either we are pre-rotating or MDP does flips
209 orient = ovutils::OVERLAY_TRANSFORM_0;
210 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700211 ovutils::PipeArgs parg(mdpFlags, info, zOrder,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400212 static_cast<ovutils::eRotFlags>(rotFlags),
213 ovutils::DEFAULT_PLANE_ALPHA,
214 (ovutils::eBlending)
215 getBlending(layer->blending));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500216 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700217 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
218 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700219 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500220 ret = false;
221 }
222 }
223 return ret;
224}
225
Saurabh Shah88e4d272013-09-03 13:31:29 -0700226bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500227{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800228 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500229 return true;
230 }
231 bool ret = true;
232 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800233 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700234 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530235 uint32_t offset = (uint32_t)hnd->offset;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700236 if(mRot) {
237 if(!mRot->queueBuffer(fd, offset))
238 return false;
239 fd = mRot->getDstMemId();
240 offset = mRot->getDstOffset();
241 }
242 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800243 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500244 ret = false;
245 }
246 return ret;
247}
248
Saurabh Shahcf053c62012-12-13 12:32:55 -0800249//================= High res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -0700250FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy):
251 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -0800252
Saurabh Shah220a30c2013-10-29 16:12:12 -0700253void FBUpdateSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800254 IFBUpdate::reset();
255 mDestLeft = ovutils::OV_INVALID;
256 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700257 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800258}
259
Saurabh Shah88e4d272013-09-03 13:31:29 -0700260bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800261 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800262 if(!ctx->mMDP.hasOverlay) {
263 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800264 __FUNCTION__);
265 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800266 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800267 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Raj Kamal4393eaa2014-06-06 13:45:20 +0530268 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800269 return mModeOn;
270}
271
272// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700273bool FBUpdateSplit::configure(hwc_context_t *ctx,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800274 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800275 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500276 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800277 if (LIKELY(ctx->mOverlay)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800278 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
279 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
280 mTileEnabled));
281
Saurabh Shahcf053c62012-12-13 12:32:55 -0800282 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800283 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800284 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800285 ovutils::eTransform orient =
286 static_cast<ovutils::eTransform>(layer->transform);
287 const int hw_w = ctx->dpyAttr[mDpy].xres;
288 const int hw_h = ctx->dpyAttr[mDpy].yres;
289 const int lSplit = getLeftSplit(ctx, mDpy);
290 mDestLeft = ovutils::OV_INVALID;
291 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700292 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
293 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800294
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700295 // No FB update optimization on (1) Custom FB resolution,
296 // (2) External Mirror mode, (3) External orientation
297 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
298 && !ctx->mExtOrientation) {
299 sourceCrop = fbUpdatingRect;
300 displayFrame = fbUpdatingRect;
301 }
302
303 int transform = layer->transform;
304 // use ext orientation if any
305 int extOrient = getExtOrientation(ctx);
306
307 // Do not use getNonWormholeRegion() function to calculate the
308 // sourceCrop during animation on external display and
309 // Dont do wormhole calculation when extorientation is set on External
310 // Dont do wormhole calculation when extDownscale is enabled on External
311 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
312 sourceCrop = layer->displayFrame;
313 } else if((mDpy && !extOrient
314 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
315 if(!qdutils::MDPVersion::getInstance().is8x26() &&
316 !ctx->dpyAttr[mDpy].customFBSize) {
317 getNonWormholeRegion(list, sourceCrop);
318 displayFrame = sourceCrop;
319 }
320 }
321
322 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
323 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700324
Saurabh Shahcf053c62012-12-13 12:32:55 -0800325 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800326 Overlay::PipeSpecs pipeSpecs;
327 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
328 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
329 pipeSpecs.dpy = mDpy;
330 pipeSpecs.fb = true;
331
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800332 /* Configure left pipe */
333 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800334 pipeSpecs.mixer = Overlay::MIXER_LEFT;
335 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800336 if(destL == ovutils::OV_INVALID) { //None available
337 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
338 " mixer", __FUNCTION__, mDpy);
339 return false;
340 }
341
342 mDestLeft = destL;
343
344 //XXX: FB layer plane alpha is currently sent as zero from
345 //surfaceflinger
346 ovutils::PipeArgs pargL(mdpFlags,
347 info,
348 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800349 ovutils::ROT_FLAGS_NONE,
350 ovutils::DEFAULT_PLANE_ALPHA,
351 (ovutils::eBlending)
352 getBlending(layer->blending));
353 hwc_rect_t cropL = sourceCrop;
354 hwc_rect_t dstL = displayFrame;
355 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
356 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
357
358 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
359 dstL, NULL, destL)< 0) {
360 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
361 ret = false;
362 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800363 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800364
365 /* Configure right pipe */
366 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800367 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
368 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800369 if(destR == ovutils::OV_INVALID) { //None available
370 ALOGE("%s: No pipes available to configure fb for dpy %d's"
371 " right mixer", __FUNCTION__, mDpy);
372 return false;
373 }
374
375 mDestRight = destR;
376 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
377 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
378
379 //XXX: FB layer plane alpha is currently sent as zero from
380 //surfaceflinger
381 ovutils::PipeArgs pargR(mdpFlagsR,
382 info,
383 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800384 ovutils::ROT_FLAGS_NONE,
385 ovutils::DEFAULT_PLANE_ALPHA,
386 (ovutils::eBlending)
387 getBlending(layer->blending));
388
389 hwc_rect_t cropR = sourceCrop;
390 hwc_rect_t dstR = displayFrame;
391 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
392 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
393
394 dstR.left -= lSplit;
395 dstR.right -= lSplit;
396
397 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
398 dstR, NULL, destR) < 0) {
399 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
400 ret = false;
401 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800402 }
403 }
404 return ret;
405}
406
Saurabh Shah88e4d272013-09-03 13:31:29 -0700407bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800408{
409 if(!mModeOn) {
410 return true;
411 }
412 bool ret = true;
413 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800414 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530415 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800416 ALOGE("%s: queue failed for left of dpy = %d",
417 __FUNCTION__, mDpy);
418 ret = false;
419 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800420 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800421 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530422 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800423 ALOGE("%s: queue failed for right of dpy = %d",
424 __FUNCTION__, mDpy);
425 ret = false;
426 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800427 }
428 return ret;
429}
430
Saurabh Shahab47c692014-02-12 18:45:57 -0800431//=================FBSrcSplit====================================
432FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
433 FBUpdateSplit(ctx, dpy) {}
434
435bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
436 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800437 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800438 overlay::Overlay& ov = *(ctx->mOverlay);
439
440 ovutils::Whf info(mAlignedFBWidth,
441 mAlignedFBHeight,
442 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
443 mTileEnabled));
Saurabh Shahab47c692014-02-12 18:45:57 -0800444
445 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
446 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
447
448 ovutils::PipeArgs parg(mdpFlags,
449 info,
450 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800451 ovutils::ROT_FLAGS_NONE,
452 ovutils::DEFAULT_PLANE_ALPHA,
453 (ovutils::eBlending)
454 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800455
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700456 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
457 hwc_rect_t displayFrame = layer->displayFrame;
458
459 // No FB update optimization on (1) Custom FB resolution,
460 // (2) External Mirror mode, (3) External orientation
461 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
462 && !ctx->mExtOrientation) {
463 sourceCrop = fbUpdatingRect;
464 displayFrame = fbUpdatingRect;
465 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800466 int transform = layer->transform;
467 ovutils::eTransform orient =
468 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800469
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700470 // use ext orientation if any
471 int extOrient = getExtOrientation(ctx);
472
473 // Do not use getNonWormholeRegion() function to calculate the
474 // sourceCrop during animation on external display and
475 // Dont do wormhole calculation when extorientation is set on External
476 // Dont do wormhole calculation when extDownscale is enabled on External
477 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
478 sourceCrop = layer->displayFrame;
479 } else if((mDpy && !extOrient
480 && !ctx->dpyAttr[mDpy].mDownScaleMode)) {
481 if(!qdutils::MDPVersion::getInstance().is8x26() &&
482 !ctx->dpyAttr[mDpy].customFBSize) {
483 getNonWormholeRegion(list, sourceCrop);
484 displayFrame = sourceCrop;
485 }
486 }
487
488 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
489 transform, orient);
490 hwc_rect_t cropL = sourceCrop;
491 hwc_rect_t cropR = sourceCrop;
492 hwc_rect_t dstL = displayFrame;
493 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800494
495 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800496 Overlay::PipeSpecs pipeSpecs;
497 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
498 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
499 pipeSpecs.dpy = mDpy;
500 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
501 pipeSpecs.fb = true;
502 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800503 if(destL == ovutils::OV_INVALID) {
504 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
505 " mixer", __FUNCTION__, mDpy);
506 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800507 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800508
509 ovutils::eDest destR = ovutils::OV_INVALID;
510
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700511 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530512 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700513 b) On primary, driver has indicated with caps to split always. This is
514 based on an empirically derived value of panel height.
515 */
516
517 bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
518 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
519
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700520 if(((sourceCrop.right - sourceCrop.left) >
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530521 (int)qdutils::MDPVersion::getInstance().getMaxMixerWidth()) or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700522 primarySplitAlways) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800523 destR = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800524 if(destR == ovutils::OV_INVALID) {
525 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
526 " mixer", __FUNCTION__, mDpy);
527 return false;
528 }
529
530 if(ctx->mOverlay->comparePipePriority(destL, destR) == -1) {
531 qhwc::swap(destL, destR);
532 }
533
534 //Split crop equally when using 2 pipes
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700535 cropL.right = (sourceCrop.right + sourceCrop.left) / 2;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800536 cropR.left = cropL.right;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700537 dstL.right = (displayFrame.right + displayFrame.left) / 2;
538 dstR.left = dstL.right;
Saurabh Shahab47c692014-02-12 18:45:57 -0800539 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800540
541 mDestLeft = destL;
542 mDestRight = destR;
543
544 if(destL != OV_INVALID) {
545 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700546 cropL, dstL, NULL /*metadata*/, destL) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800547 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800548 return false;
549 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800550 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800551
552 //configure right pipe
553 if(destR != OV_INVALID) {
554 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700555 cropR, dstR, NULL /*metadata*/, destR) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800556 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800557 return false;
558 }
559 }
560
561 return true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800562}
563
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500564//---------------------------------------------------------------------
565}; //namespace qhwc