blob: 43ae916c08b4ef986086ef1e21a819bc858ebe8e [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"
28
29using namespace qdutils;
Saurabh Shahaf5f5972013-07-30 13:56:35 -070030using namespace overlay;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070031using overlay::Rotator;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -070032using namespace overlay::utils;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070033
Naseer Ahmed758bfc52012-11-28 17:02:08 -050034namespace qhwc {
35
36namespace ovutils = overlay::utils;
37
Saurabh Shah88e4d272013-09-03 13:31:29 -070038IFBUpdate* IFBUpdate::getObject(hwc_context_t *ctx, const int& dpy) {
Saurabh Shah60e8bde2014-04-30 14:46:03 -070039 if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
40 return new FBSrcSplit(ctx, dpy);
41 } else if(isDisplaySplit(ctx, dpy)) {
Saurabh Shah220a30c2013-10-29 16:12:12 -070042 return new FBUpdateSplit(ctx, dpy);
Saurabh Shahcf053c62012-12-13 12:32:55 -080043 }
Saurabh Shah220a30c2013-10-29 16:12:12 -070044 return new FBUpdateNonSplit(ctx, dpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -050045}
46
Saurabh Shah220a30c2013-10-29 16:12:12 -070047IFBUpdate::IFBUpdate(hwc_context_t *ctx, const int& dpy) : mDpy(dpy) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070048 unsigned int size = 0;
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053049 uint32_t xres = ctx->dpyAttr[mDpy].xres;
50 uint32_t yres = ctx->dpyAttr[mDpy].yres;
51 if (ctx->dpyAttr[dpy].customFBSize) {
52 //GPU will render and compose at new resolution
53 //So need to have FB at new resolution
54 xres = ctx->dpyAttr[mDpy].xres_new;
55 yres = ctx->dpyAttr[mDpy].yres_new;
56 }
57 getBufferAttributes((int)xres, (int)yres,
Saurabh Shah220a30c2013-10-29 16:12:12 -070058 HAL_PIXEL_FORMAT_RGBA_8888,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070059 0,
Saurabh Shah220a30c2013-10-29 16:12:12 -070060 mAlignedFBWidth,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070061 mAlignedFBHeight,
62 mTileEnabled, size);
Saurabh Shah220a30c2013-10-29 16:12:12 -070063}
64
65void IFBUpdate::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080066 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070067 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080068}
69
Saurabh Shaha36be922013-12-16 18:18:39 -080070bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx,
71 hwc_display_contents_1 *list, int fbZorder) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -080072 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070073 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) &&
Saurabh Shaha36be922013-12-16 18:18:39 -080074 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd);
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070075 return mModeOn;
Saurabh Shaha36be922013-12-16 18:18:39 -080076}
77
Saurabh Shahcf053c62012-12-13 12:32:55 -080078//================= Low res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -070079FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy):
80 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -080081
Saurabh Shah220a30c2013-10-29 16:12:12 -070082void FBUpdateNonSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080083 IFBUpdate::reset();
84 mDest = ovutils::OV_INVALID;
85}
86
Saurabh Shah88e4d272013-09-03 13:31:29 -070087bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx,
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +053088 hwc_layer_1_t *layer,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -070089 ovutils::Whf &info,
90 hwc_rect_t& sourceCrop,
91 ovutils::eMdpFlags& mdpFlags,
92 int& rotFlags)
93{
94 int extOrient = getExtOrientation(ctx);
95 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient);
96 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) {
97 mRot = ctx->mRotMgr->getNext();
98 if(mRot == NULL) return false;
Saurabh Shah39240c92014-03-31 10:31:42 -070099 ctx->mLayerRotMap[mDpy]->add(layer, mRot);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800100 // Composed FB content will have black bars, if the viewFrame of the
101 // external is different from {0, 0, fbWidth, fbHeight}, so intersect
102 // viewFrame with sourceCrop to avoid those black bars
103 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700104 //Configure rotator for pre-rotation
105 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
106 ALOGE("%s: configRotator Failed!", __FUNCTION__);
107 mRot = NULL;
108 return false;
109 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700110 updateSource(orient, info, sourceCrop, mRot);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700111 rotFlags |= ovutils::ROT_PREROTATED;
112 }
113 return true;
114}
115
Saurabh Shah88e4d272013-09-03 13:31:29 -0700116bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800117 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500118 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800119 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800120 __FUNCTION__);
121 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500122 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800123 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800124 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500125}
126
127// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700128bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800129 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500130 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500131 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500132 if (LIKELY(ctx->mOverlay)) {
133 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700134
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700135 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
136 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
137 mTileEnabled));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500138
Saurabh Shahc62f3982014-03-05 14:28:26 -0800139 Overlay::PipeSpecs pipeSpecs;
140 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
141 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
142 pipeSpecs.dpy = mDpy;
143 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
144 pipeSpecs.fb = true;
145
146 ovutils::eDest dest = ov.getPipe(pipeSpecs);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500147 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700148 ALOGE("%s: No pipes available to configure fb for dpy %d",
149 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500150 return false;
151 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800152 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500153
Ramkumar Radhakrishnan1829d282013-07-23 14:54:36 -0700154 if((mDpy && ctx->deviceOrientation) &&
155 ctx->listStats[mDpy].isDisplayAnimating) {
156 fbZorder = 0;
157 }
158
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800159 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800160 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500161
Saurabh Shah62e1d732013-09-17 10:44:05 -0700162 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800163 hwc_rect_t displayFrame = layer->displayFrame;
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800164
165 // No FB update optimization on (1) Custom FB resolution,
166 // (2) External Mirror mode, (3) External orientation
167 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
168 && !ctx->mExtOrientation) {
169 sourceCrop = fbUpdatingRect;
170 displayFrame = fbUpdatingRect;
171 }
172
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700173 int transform = layer->transform;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700174 int rotFlags = ovutils::ROT_FLAGS_NONE;
175
176 ovutils::eTransform orient =
177 static_cast<ovutils::eTransform>(transform);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700178 // use ext orientation if any
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700179 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700180
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700181 // Do not use getNonWormholeRegion() function to calculate the
182 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700183 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700184 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700185 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
186 sourceCrop = layer->displayFrame;
Ramkumar Radhakrishnan3b0d9722014-08-06 13:08:40 -0700187 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700188 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530189 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530190 !ctx->dpyAttr[mDpy].customFBSize) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700191 getNonWormholeRegion(list, sourceCrop);
192 displayFrame = sourceCrop;
193 }
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800194 }
Saurabh Shah220a30c2013-10-29 16:12:12 -0700195 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700196 transform, orient);
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800197 //Store the displayFrame, will be used in getDisplayViewFrame
198 ctx->dpyAttr[mDpy].mDstRect = displayFrame;
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800199 setMdpFlags(ctx, layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700200 // For External use rotator if there is a rotation value set
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +0530201 ret = preRotateExtDisplay(ctx, layer, info,
202 sourceCrop, mdpFlags, rotFlags);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700203 if(!ret) {
204 ALOGE("%s: preRotate for external Failed!", __FUNCTION__);
205 return false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700206 }
207 //For the mdp, since either we are pre-rotating or MDP does flips
208 orient = ovutils::OVERLAY_TRANSFORM_0;
209 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700210 ovutils::PipeArgs parg(mdpFlags, info, zOrder,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400211 static_cast<ovutils::eRotFlags>(rotFlags),
212 ovutils::DEFAULT_PLANE_ALPHA,
213 (ovutils::eBlending)
214 getBlending(layer->blending));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500215 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700216 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
217 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700218 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219 ret = false;
220 }
221 }
222 return ret;
223}
224
Saurabh Shah88e4d272013-09-03 13:31:29 -0700225bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500226{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800227 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500228 return true;
229 }
230 bool ret = true;
231 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800232 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700233 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530234 uint32_t offset = (uint32_t)hnd->offset;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700235 if(mRot) {
236 if(!mRot->queueBuffer(fd, offset))
237 return false;
238 fd = mRot->getDstMemId();
239 offset = mRot->getDstOffset();
240 }
241 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800242 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500243 ret = false;
244 }
245 return ret;
246}
247
Saurabh Shahcf053c62012-12-13 12:32:55 -0800248//================= High res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -0700249FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy):
250 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -0800251
Saurabh Shah220a30c2013-10-29 16:12:12 -0700252void FBUpdateSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800253 IFBUpdate::reset();
254 mDestLeft = ovutils::OV_INVALID;
255 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700256 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800257}
258
Saurabh Shah88e4d272013-09-03 13:31:29 -0700259bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800260 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800261 if(!ctx->mMDP.hasOverlay) {
262 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800263 __FUNCTION__);
264 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800265 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800266 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Raj Kamal4393eaa2014-06-06 13:45:20 +0530267 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800268 return mModeOn;
269}
270
271// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700272bool FBUpdateSplit::configure(hwc_context_t *ctx,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800273 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800274 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500275 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800276 if (LIKELY(ctx->mOverlay)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800277 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
278 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
279 mTileEnabled));
280
Saurabh Shahcf053c62012-12-13 12:32:55 -0800281 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800282 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800283 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800284 ovutils::eTransform orient =
285 static_cast<ovutils::eTransform>(layer->transform);
286 const int hw_w = ctx->dpyAttr[mDpy].xres;
287 const int hw_h = ctx->dpyAttr[mDpy].yres;
288 const int lSplit = getLeftSplit(ctx, mDpy);
289 mDestLeft = ovutils::OV_INVALID;
290 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700291 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
292 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800293
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700294 // No FB update optimization on (1) Custom FB resolution,
295 // (2) External Mirror mode, (3) External orientation
296 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
297 && !ctx->mExtOrientation) {
298 sourceCrop = fbUpdatingRect;
299 displayFrame = fbUpdatingRect;
300 }
301
302 int transform = layer->transform;
303 // use ext orientation if any
304 int extOrient = getExtOrientation(ctx);
305
306 // Do not use getNonWormholeRegion() function to calculate the
307 // sourceCrop during animation on external display and
308 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700309 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700310 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
311 sourceCrop = layer->displayFrame;
312 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700313 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700314 if(!qdutils::MDPVersion::getInstance().is8x26() &&
315 !ctx->dpyAttr[mDpy].customFBSize) {
316 getNonWormholeRegion(list, sourceCrop);
317 displayFrame = sourceCrop;
318 }
319 }
320
321 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
322 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700323
Saurabh Shahcf053c62012-12-13 12:32:55 -0800324 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800325 Overlay::PipeSpecs pipeSpecs;
326 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
327 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
328 pipeSpecs.dpy = mDpy;
329 pipeSpecs.fb = true;
330
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800331 /* Configure left pipe */
332 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800333 pipeSpecs.mixer = Overlay::MIXER_LEFT;
334 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800335 if(destL == ovutils::OV_INVALID) { //None available
336 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
337 " mixer", __FUNCTION__, mDpy);
338 return false;
339 }
340
341 mDestLeft = destL;
342
343 //XXX: FB layer plane alpha is currently sent as zero from
344 //surfaceflinger
345 ovutils::PipeArgs pargL(mdpFlags,
346 info,
347 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800348 ovutils::ROT_FLAGS_NONE,
349 ovutils::DEFAULT_PLANE_ALPHA,
350 (ovutils::eBlending)
351 getBlending(layer->blending));
352 hwc_rect_t cropL = sourceCrop;
353 hwc_rect_t dstL = displayFrame;
354 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
355 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
356
357 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
358 dstL, NULL, destL)< 0) {
359 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
360 ret = false;
361 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800362 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800363
364 /* Configure right pipe */
365 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800366 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
367 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800368 if(destR == ovutils::OV_INVALID) { //None available
369 ALOGE("%s: No pipes available to configure fb for dpy %d's"
370 " right mixer", __FUNCTION__, mDpy);
371 return false;
372 }
373
374 mDestRight = destR;
375 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
376 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
377
378 //XXX: FB layer plane alpha is currently sent as zero from
379 //surfaceflinger
380 ovutils::PipeArgs pargR(mdpFlagsR,
381 info,
382 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800383 ovutils::ROT_FLAGS_NONE,
384 ovutils::DEFAULT_PLANE_ALPHA,
385 (ovutils::eBlending)
386 getBlending(layer->blending));
387
388 hwc_rect_t cropR = sourceCrop;
389 hwc_rect_t dstR = displayFrame;
390 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
391 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
392
393 dstR.left -= lSplit;
394 dstR.right -= lSplit;
395
396 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
397 dstR, NULL, destR) < 0) {
398 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
399 ret = false;
400 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800401 }
402 }
403 return ret;
404}
405
Saurabh Shah88e4d272013-09-03 13:31:29 -0700406bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800407{
408 if(!mModeOn) {
409 return true;
410 }
411 bool ret = true;
412 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800413 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530414 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800415 ALOGE("%s: queue failed for left of dpy = %d",
416 __FUNCTION__, mDpy);
417 ret = false;
418 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800419 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800420 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530421 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800422 ALOGE("%s: queue failed for right of dpy = %d",
423 __FUNCTION__, mDpy);
424 ret = false;
425 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800426 }
427 return ret;
428}
429
Saurabh Shahab47c692014-02-12 18:45:57 -0800430//=================FBSrcSplit====================================
431FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
432 FBUpdateSplit(ctx, dpy) {}
433
434bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
435 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800436 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800437 overlay::Overlay& ov = *(ctx->mOverlay);
438
439 ovutils::Whf info(mAlignedFBWidth,
440 mAlignedFBHeight,
441 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888,
442 mTileEnabled));
Saurabh Shahab47c692014-02-12 18:45:57 -0800443
444 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
445 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
446
447 ovutils::PipeArgs parg(mdpFlags,
448 info,
449 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800450 ovutils::ROT_FLAGS_NONE,
451 ovutils::DEFAULT_PLANE_ALPHA,
452 (ovutils::eBlending)
453 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800454
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700455 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
456 hwc_rect_t displayFrame = layer->displayFrame;
457
458 // No FB update optimization on (1) Custom FB resolution,
459 // (2) External Mirror mode, (3) External orientation
460 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
461 && !ctx->mExtOrientation) {
462 sourceCrop = fbUpdatingRect;
463 displayFrame = fbUpdatingRect;
464 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800465 int transform = layer->transform;
466 ovutils::eTransform orient =
467 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800468
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700469 // use ext orientation if any
470 int extOrient = getExtOrientation(ctx);
471
472 // Do not use getNonWormholeRegion() function to calculate the
473 // sourceCrop during animation on external display and
474 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700475 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700476 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
477 sourceCrop = layer->displayFrame;
478 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700479 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700480 if(!qdutils::MDPVersion::getInstance().is8x26() &&
481 !ctx->dpyAttr[mDpy].customFBSize) {
482 getNonWormholeRegion(list, sourceCrop);
483 displayFrame = sourceCrop;
484 }
485 }
486
487 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
488 transform, orient);
489 hwc_rect_t cropL = sourceCrop;
490 hwc_rect_t cropR = sourceCrop;
491 hwc_rect_t dstL = displayFrame;
492 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800493
494 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800495 Overlay::PipeSpecs pipeSpecs;
496 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
497 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
498 pipeSpecs.dpy = mDpy;
499 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
500 pipeSpecs.fb = true;
501 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800502 if(destL == ovutils::OV_INVALID) {
503 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
504 " mixer", __FUNCTION__, mDpy);
505 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800506 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800507
508 ovutils::eDest destR = ovutils::OV_INVALID;
509
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700510 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530511 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700512 b) On primary, driver has indicated with caps to split always. This is
513 based on an empirically derived value of panel height.
514 */
515
Saurabh Shah189f23d2014-09-26 17:21:00 -0700516 const bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700517 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
Saurabh Shah189f23d2014-09-26 17:21:00 -0700518 const uint32_t lSplit = getLeftSplit(ctx, mDpy);
519 const uint32_t cropWidth = sourceCrop.right - sourceCrop.left;
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700520
Saurabh Shah189f23d2014-09-26 17:21:00 -0700521 if((cropWidth > qdutils::MDPVersion::getInstance().getMaxMixerWidth()) or
522 (primarySplitAlways and cropWidth > lSplit)) {
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