blob: 8660740d0d8afaa39d97f3330bb63ef799e1c4bd [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
Sushil Chauhan65e26302015-01-14 10:48:57 -0800135 int flags = mTileEnabled ?
136 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700137 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800138 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
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;
Justin Philipd6166602014-08-12 13:42:21 +0530161 ovutils::setMdpFlags(mdpFlags,
162 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800163 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500164
Saurabh Shah62e1d732013-09-17 10:44:05 -0700165 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800166 hwc_rect_t displayFrame = layer->displayFrame;
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800167
168 // No FB update optimization on (1) Custom FB resolution,
169 // (2) External Mirror mode, (3) External orientation
170 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
171 && !ctx->mExtOrientation) {
172 sourceCrop = fbUpdatingRect;
173 displayFrame = fbUpdatingRect;
174 }
175
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700176 int transform = layer->transform;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700177 int rotFlags = ovutils::ROT_FLAGS_NONE;
178
179 ovutils::eTransform orient =
180 static_cast<ovutils::eTransform>(transform);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700181 // use ext orientation if any
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700182 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700183
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700184 // Do not use getNonWormholeRegion() function to calculate the
185 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700186 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700187 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700188 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
189 sourceCrop = layer->displayFrame;
Ramkumar Radhakrishnan3b0d9722014-08-06 13:08:40 -0700190 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700191 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530192 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530193 !ctx->dpyAttr[mDpy].customFBSize) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700194 getNonWormholeRegion(list, sourceCrop);
195 displayFrame = sourceCrop;
196 }
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800197 }
Saurabh Shah220a30c2013-10-29 16:12:12 -0700198 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700199 transform, orient);
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800200 //Store the displayFrame, will be used in getDisplayViewFrame
201 ctx->dpyAttr[mDpy].mDstRect = displayFrame;
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800202 setMdpFlags(ctx, layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700203 // For External use rotator if there is a rotation value set
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +0530204 ret = preRotateExtDisplay(ctx, layer, info,
205 sourceCrop, mdpFlags, rotFlags);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700206 if(!ret) {
207 ALOGE("%s: preRotate for external Failed!", __FUNCTION__);
208 return false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700209 }
210 //For the mdp, since either we are pre-rotating or MDP does flips
211 orient = ovutils::OVERLAY_TRANSFORM_0;
212 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700213 ovutils::PipeArgs parg(mdpFlags, info, zOrder,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400214 static_cast<ovutils::eRotFlags>(rotFlags),
215 ovutils::DEFAULT_PLANE_ALPHA,
216 (ovutils::eBlending)
217 getBlending(layer->blending));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500218 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700219 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
220 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700221 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500222 ret = false;
223 }
224 }
225 return ret;
226}
227
Saurabh Shah88e4d272013-09-03 13:31:29 -0700228bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500229{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800230 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500231 return true;
232 }
233 bool ret = true;
234 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800235 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700236 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530237 uint32_t offset = (uint32_t)hnd->offset;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700238 if(mRot) {
239 if(!mRot->queueBuffer(fd, offset))
240 return false;
241 fd = mRot->getDstMemId();
242 offset = mRot->getDstOffset();
243 }
244 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800245 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500246 ret = false;
247 }
248 return ret;
249}
250
Saurabh Shahcf053c62012-12-13 12:32:55 -0800251//================= High res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -0700252FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy):
253 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -0800254
Saurabh Shah220a30c2013-10-29 16:12:12 -0700255void FBUpdateSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800256 IFBUpdate::reset();
257 mDestLeft = ovutils::OV_INVALID;
258 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700259 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800260}
261
Saurabh Shah88e4d272013-09-03 13:31:29 -0700262bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800263 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800264 if(!ctx->mMDP.hasOverlay) {
265 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800266 __FUNCTION__);
267 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800268 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800269 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Raj Kamal4393eaa2014-06-06 13:45:20 +0530270 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800271 return mModeOn;
272}
273
274// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700275bool FBUpdateSplit::configure(hwc_context_t *ctx,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800276 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800277 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500278 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800279 if (LIKELY(ctx->mOverlay)) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800280 int flags = mTileEnabled ?
281 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800282 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800283 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800284
Saurabh Shahcf053c62012-12-13 12:32:55 -0800285 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800286 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530287 ovutils::setMdpFlags(mdpFlags,
288 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800289 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800290 ovutils::eTransform orient =
291 static_cast<ovutils::eTransform>(layer->transform);
292 const int hw_w = ctx->dpyAttr[mDpy].xres;
293 const int hw_h = ctx->dpyAttr[mDpy].yres;
294 const int lSplit = getLeftSplit(ctx, mDpy);
295 mDestLeft = ovutils::OV_INVALID;
296 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700297 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
298 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800299
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700300 // No FB update optimization on (1) Custom FB resolution,
301 // (2) External Mirror mode, (3) External orientation
302 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
303 && !ctx->mExtOrientation) {
304 sourceCrop = fbUpdatingRect;
305 displayFrame = fbUpdatingRect;
306 }
307
308 int transform = layer->transform;
309 // use ext orientation if any
310 int extOrient = getExtOrientation(ctx);
311
312 // Do not use getNonWormholeRegion() function to calculate the
313 // sourceCrop during animation on external display and
314 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700315 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700316 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
317 sourceCrop = layer->displayFrame;
318 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700319 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700320 if(!qdutils::MDPVersion::getInstance().is8x26() &&
321 !ctx->dpyAttr[mDpy].customFBSize) {
322 getNonWormholeRegion(list, sourceCrop);
323 displayFrame = sourceCrop;
324 }
325 }
326
327 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
328 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700329
Saurabh Shahcf053c62012-12-13 12:32:55 -0800330 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800331 Overlay::PipeSpecs pipeSpecs;
332 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
333 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
334 pipeSpecs.dpy = mDpy;
335 pipeSpecs.fb = true;
336
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800337 /* Configure left pipe */
338 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800339 pipeSpecs.mixer = Overlay::MIXER_LEFT;
340 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800341 if(destL == ovutils::OV_INVALID) { //None available
342 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
343 " mixer", __FUNCTION__, mDpy);
344 return false;
345 }
346
347 mDestLeft = destL;
348
349 //XXX: FB layer plane alpha is currently sent as zero from
350 //surfaceflinger
351 ovutils::PipeArgs pargL(mdpFlags,
352 info,
353 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800354 ovutils::ROT_FLAGS_NONE,
355 ovutils::DEFAULT_PLANE_ALPHA,
356 (ovutils::eBlending)
357 getBlending(layer->blending));
358 hwc_rect_t cropL = sourceCrop;
359 hwc_rect_t dstL = displayFrame;
360 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
361 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
362
363 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
364 dstL, NULL, destL)< 0) {
365 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
366 ret = false;
367 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800368 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800369
370 /* Configure right pipe */
371 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800372 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
373 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800374 if(destR == ovutils::OV_INVALID) { //None available
375 ALOGE("%s: No pipes available to configure fb for dpy %d's"
376 " right mixer", __FUNCTION__, mDpy);
377 return false;
378 }
379
380 mDestRight = destR;
381 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
382 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
383
384 //XXX: FB layer plane alpha is currently sent as zero from
385 //surfaceflinger
386 ovutils::PipeArgs pargR(mdpFlagsR,
387 info,
388 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800389 ovutils::ROT_FLAGS_NONE,
390 ovutils::DEFAULT_PLANE_ALPHA,
391 (ovutils::eBlending)
392 getBlending(layer->blending));
393
394 hwc_rect_t cropR = sourceCrop;
395 hwc_rect_t dstR = displayFrame;
396 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
397 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
398
399 dstR.left -= lSplit;
400 dstR.right -= lSplit;
401
402 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
403 dstR, NULL, destR) < 0) {
404 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
405 ret = false;
406 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800407 }
408 }
409 return ret;
410}
411
Saurabh Shah88e4d272013-09-03 13:31:29 -0700412bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800413{
414 if(!mModeOn) {
415 return true;
416 }
417 bool ret = true;
418 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800419 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530420 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800421 ALOGE("%s: queue failed for left of dpy = %d",
422 __FUNCTION__, mDpy);
423 ret = false;
424 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800425 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800426 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530427 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800428 ALOGE("%s: queue failed for right of dpy = %d",
429 __FUNCTION__, mDpy);
430 ret = false;
431 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800432 }
433 return ret;
434}
435
Saurabh Shahab47c692014-02-12 18:45:57 -0800436//=================FBSrcSplit====================================
437FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
438 FBUpdateSplit(ctx, dpy) {}
439
440bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
441 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800442 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800443 overlay::Overlay& ov = *(ctx->mOverlay);
444
Sushil Chauhan65e26302015-01-14 10:48:57 -0800445 int flags = mTileEnabled ? private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Saurabh Shahab47c692014-02-12 18:45:57 -0800446 ovutils::Whf info(mAlignedFBWidth,
447 mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800448 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Saurabh Shahab47c692014-02-12 18:45:57 -0800449
450 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530451 ovutils::setMdpFlags(mdpFlags,
452 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahab47c692014-02-12 18:45:57 -0800453 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
454
455 ovutils::PipeArgs parg(mdpFlags,
456 info,
457 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800458 ovutils::ROT_FLAGS_NONE,
459 ovutils::DEFAULT_PLANE_ALPHA,
460 (ovutils::eBlending)
461 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800462
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700463 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
464 hwc_rect_t displayFrame = layer->displayFrame;
465
466 // No FB update optimization on (1) Custom FB resolution,
467 // (2) External Mirror mode, (3) External orientation
468 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
469 && !ctx->mExtOrientation) {
470 sourceCrop = fbUpdatingRect;
471 displayFrame = fbUpdatingRect;
472 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800473 int transform = layer->transform;
474 ovutils::eTransform orient =
475 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800476
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700477 // use ext orientation if any
478 int extOrient = getExtOrientation(ctx);
479
480 // Do not use getNonWormholeRegion() function to calculate the
481 // sourceCrop during animation on external display and
482 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700483 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700484 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
485 sourceCrop = layer->displayFrame;
486 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700487 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700488 if(!qdutils::MDPVersion::getInstance().is8x26() &&
489 !ctx->dpyAttr[mDpy].customFBSize) {
490 getNonWormholeRegion(list, sourceCrop);
491 displayFrame = sourceCrop;
492 }
493 }
494
495 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
496 transform, orient);
497 hwc_rect_t cropL = sourceCrop;
498 hwc_rect_t cropR = sourceCrop;
499 hwc_rect_t dstL = displayFrame;
500 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800501
502 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800503 Overlay::PipeSpecs pipeSpecs;
504 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
505 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
506 pipeSpecs.dpy = mDpy;
507 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
508 pipeSpecs.fb = true;
509 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800510 if(destL == ovutils::OV_INVALID) {
511 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
512 " mixer", __FUNCTION__, mDpy);
513 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800514 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800515
516 ovutils::eDest destR = ovutils::OV_INVALID;
517
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700518 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530519 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700520 b) On primary, driver has indicated with caps to split always. This is
521 based on an empirically derived value of panel height.
522 */
523
Saurabh Shah189f23d2014-09-26 17:21:00 -0700524 const bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700525 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
Saurabh Shah189f23d2014-09-26 17:21:00 -0700526 const uint32_t lSplit = getLeftSplit(ctx, mDpy);
527 const uint32_t cropWidth = sourceCrop.right - sourceCrop.left;
Saurabh Shah514759d2014-11-11 18:02:24 -0800528 const uint32_t cropHeight = sourceCrop.bottom - sourceCrop.top;
529 const uint32_t dstWidth = displayFrame.right - displayFrame.left;
530 const uint32_t dstHeight = displayFrame.bottom - displayFrame.top;
531 const uint32_t layerClock = getLayerClock(dstWidth, dstHeight, cropHeight);
532 const uint32_t mixerClock = lSplit;
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700533
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800534 if((cropWidth > qdutils::MDPVersion::getInstance().getMaxPipeWidth()) or
Saurabh Shah514759d2014-11-11 18:02:24 -0800535 (primarySplitAlways and
536 (cropWidth > lSplit or layerClock > mixerClock))) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800537 destR = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800538 if(destR == ovutils::OV_INVALID) {
539 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
540 " mixer", __FUNCTION__, mDpy);
541 return false;
542 }
543
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800544 if(ctx->mOverlay->needsPrioritySwap(destL, destR)) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800545 qhwc::swap(destL, destR);
546 }
547
548 //Split crop equally when using 2 pipes
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700549 cropL.right = (sourceCrop.right + sourceCrop.left) / 2;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800550 cropR.left = cropL.right;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700551 dstL.right = (displayFrame.right + displayFrame.left) / 2;
552 dstR.left = dstL.right;
Saurabh Shahab47c692014-02-12 18:45:57 -0800553 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800554
555 mDestLeft = destL;
556 mDestRight = destR;
557
558 if(destL != OV_INVALID) {
559 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700560 cropL, dstL, NULL /*metadata*/, destL) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800561 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800562 return false;
563 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800564 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800565
566 //configure right pipe
567 if(destR != OV_INVALID) {
568 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700569 cropR, dstR, NULL /*metadata*/, destR) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800570 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800571 return false;
572 }
573 }
574
575 return true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800576}
577
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500578//---------------------------------------------------------------------
579}; //namespace qhwc