blob: 74d95e7f9572600b49e13c76df09b6d3788585fc [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"
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050028#include <video/msm_hdmi_modes.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;
Saurabh Shah90c55cf2015-02-10 15:37:39 -080052 if (ctx->dpyAttr[dpy].fbScaling) {
53 xres = ctx->dpyAttr[mDpy].xresFB;
54 yres = ctx->dpyAttr[mDpy].yresFB;
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053055 }
56 getBufferAttributes((int)xres, (int)yres,
radhakrishnac3198ff2015-03-10 17:10:02 +053057 ctx->dpyAttr[mDpy].fbformat,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070058 0,
Saurabh Shah220a30c2013-10-29 16:12:12 -070059 mAlignedFBWidth,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070060 mAlignedFBHeight,
61 mTileEnabled, size);
Saurabh Shah220a30c2013-10-29 16:12:12 -070062}
63
64void IFBUpdate::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080065 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070066 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080067}
68
Saurabh Shaha36be922013-12-16 18:18:39 -080069bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx,
70 hwc_display_contents_1 *list, int fbZorder) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -080071 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070072 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) &&
Saurabh Shaha36be922013-12-16 18:18:39 -080073 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd);
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070074 return mModeOn;
Saurabh Shaha36be922013-12-16 18:18:39 -080075}
76
Saurabh Shahcf053c62012-12-13 12:32:55 -080077//================= Low res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -070078FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy):
79 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -080080
Saurabh Shah220a30c2013-10-29 16:12:12 -070081void FBUpdateNonSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080082 IFBUpdate::reset();
83 mDest = ovutils::OV_INVALID;
84}
85
Saurabh Shah88e4d272013-09-03 13:31:29 -070086bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx,
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +053087 hwc_layer_1_t *layer,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -070088 ovutils::Whf &info,
89 hwc_rect_t& sourceCrop,
90 ovutils::eMdpFlags& mdpFlags,
91 int& rotFlags)
92{
93 int extOrient = getExtOrientation(ctx);
94 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient);
95 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) {
96 mRot = ctx->mRotMgr->getNext();
97 if(mRot == NULL) return false;
Saurabh Shah39240c92014-03-31 10:31:42 -070098 ctx->mLayerRotMap[mDpy]->add(layer, mRot);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -080099 // Composed FB content will have black bars, if the viewFrame of the
100 // external is different from {0, 0, fbWidth, fbHeight}, so intersect
101 // viewFrame with sourceCrop to avoid those black bars
102 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700103 //Configure rotator for pre-rotation
104 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
105 ALOGE("%s: configRotator Failed!", __FUNCTION__);
106 mRot = NULL;
107 return false;
108 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700109 updateSource(orient, info, sourceCrop, mRot);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700110 rotFlags |= ovutils::ROT_PREROTATED;
111 }
112 return true;
113}
114
Saurabh Shah88e4d272013-09-03 13:31:29 -0700115bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800116 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500117 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800118 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800119 __FUNCTION__);
120 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500121 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800122 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800123 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500124}
125
126// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700127bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800128 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500129 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500130 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 if (LIKELY(ctx->mOverlay)) {
132 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700133
Sushil Chauhan65e26302015-01-14 10:48:57 -0800134 int flags = mTileEnabled ?
135 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700136 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
radhakrishnac3198ff2015-03-10 17:10:02 +0530137 ovutils::getMdpFormat(ctx->dpyAttr[mDpy].fbformat, flags));
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;
Justin Philipd6166602014-08-12 13:42:21 +0530160 ovutils::setMdpFlags(mdpFlags,
161 ovutils::OV_MDP_SMP_FORCE_ALLOC);
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
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800169 if(!ctx->dpyAttr[mDpy].fbScaling && !ctx->mBufferMirrorMode
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800170 && !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
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700186 // Dont do wormhole calculation when scaling mode is set 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
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700190 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530191 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800192 !ctx->dpyAttr[mDpy].fbScaling) {
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)) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800279 int flags = mTileEnabled ?
280 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800281 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800282 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800283
Saurabh Shahcf053c62012-12-13 12:32:55 -0800284 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800285 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530286 ovutils::setMdpFlags(mdpFlags,
287 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800288 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800289 ovutils::eTransform orient =
290 static_cast<ovutils::eTransform>(layer->transform);
291 const int hw_w = ctx->dpyAttr[mDpy].xres;
292 const int hw_h = ctx->dpyAttr[mDpy].yres;
293 const int lSplit = getLeftSplit(ctx, mDpy);
294 mDestLeft = ovutils::OV_INVALID;
295 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700296 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
297 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800298
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700299 // No FB update optimization on (1) Custom FB resolution,
300 // (2) External Mirror mode, (3) External orientation
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800301 if(!ctx->dpyAttr[mDpy].fbScaling && !ctx->mBufferMirrorMode
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700302 && !ctx->mExtOrientation) {
303 sourceCrop = fbUpdatingRect;
304 displayFrame = fbUpdatingRect;
305 }
306
307 int transform = layer->transform;
308 // use ext orientation if any
309 int extOrient = getExtOrientation(ctx);
310
311 // Do not use getNonWormholeRegion() function to calculate the
312 // sourceCrop during animation on external display and
313 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700314 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700315 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
316 sourceCrop = layer->displayFrame;
317 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700318 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700319 if(!qdutils::MDPVersion::getInstance().is8x26() &&
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800320 !ctx->dpyAttr[mDpy].fbScaling) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700321 getNonWormholeRegion(list, sourceCrop);
322 displayFrame = sourceCrop;
323 }
324 }
325
326 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
327 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700328
Saurabh Shahcf053c62012-12-13 12:32:55 -0800329 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800330 Overlay::PipeSpecs pipeSpecs;
331 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
332 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
333 pipeSpecs.dpy = mDpy;
334 pipeSpecs.fb = true;
335
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800336 /* Configure left pipe */
337 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800338 pipeSpecs.mixer = Overlay::MIXER_LEFT;
339 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800340 if(destL == ovutils::OV_INVALID) { //None available
341 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
342 " mixer", __FUNCTION__, mDpy);
343 return false;
344 }
345
346 mDestLeft = destL;
347
348 //XXX: FB layer plane alpha is currently sent as zero from
349 //surfaceflinger
350 ovutils::PipeArgs pargL(mdpFlags,
351 info,
352 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800353 ovutils::ROT_FLAGS_NONE,
354 ovutils::DEFAULT_PLANE_ALPHA,
355 (ovutils::eBlending)
356 getBlending(layer->blending));
357 hwc_rect_t cropL = sourceCrop;
358 hwc_rect_t dstL = displayFrame;
359 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
360 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
361
362 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
363 dstL, NULL, destL)< 0) {
364 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
365 ret = false;
366 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800367 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800368
369 /* Configure right pipe */
370 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800371 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
372 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800373 if(destR == ovutils::OV_INVALID) { //None available
374 ALOGE("%s: No pipes available to configure fb for dpy %d's"
375 " right mixer", __FUNCTION__, mDpy);
376 return false;
377 }
378
379 mDestRight = destR;
380 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
381 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
382
383 //XXX: FB layer plane alpha is currently sent as zero from
384 //surfaceflinger
385 ovutils::PipeArgs pargR(mdpFlagsR,
386 info,
387 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800388 ovutils::ROT_FLAGS_NONE,
389 ovutils::DEFAULT_PLANE_ALPHA,
390 (ovutils::eBlending)
391 getBlending(layer->blending));
392
393 hwc_rect_t cropR = sourceCrop;
394 hwc_rect_t dstR = displayFrame;
395 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
396 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
397
398 dstR.left -= lSplit;
399 dstR.right -= lSplit;
400
401 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
402 dstR, NULL, destR) < 0) {
403 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
404 ret = false;
405 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800406 }
407 }
408 return ret;
409}
410
Saurabh Shah88e4d272013-09-03 13:31:29 -0700411bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800412{
413 if(!mModeOn) {
414 return true;
415 }
416 bool ret = true;
417 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800418 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530419 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800420 ALOGE("%s: queue failed for left of dpy = %d",
421 __FUNCTION__, mDpy);
422 ret = false;
423 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800424 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800425 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530426 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800427 ALOGE("%s: queue failed for right of dpy = %d",
428 __FUNCTION__, mDpy);
429 ret = false;
430 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800431 }
432 return ret;
433}
434
Saurabh Shahab47c692014-02-12 18:45:57 -0800435//=================FBSrcSplit====================================
436FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
437 FBUpdateSplit(ctx, dpy) {}
438
439bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
440 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800441 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800442 overlay::Overlay& ov = *(ctx->mOverlay);
443
Sushil Chauhan65e26302015-01-14 10:48:57 -0800444 int flags = mTileEnabled ? private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Saurabh Shahab47c692014-02-12 18:45:57 -0800445 ovutils::Whf info(mAlignedFBWidth,
446 mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800447 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Saurabh Shahab47c692014-02-12 18:45:57 -0800448
449 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530450 ovutils::setMdpFlags(mdpFlags,
451 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahab47c692014-02-12 18:45:57 -0800452 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
453
454 ovutils::PipeArgs parg(mdpFlags,
455 info,
456 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800457 ovutils::ROT_FLAGS_NONE,
458 ovutils::DEFAULT_PLANE_ALPHA,
459 (ovutils::eBlending)
460 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800461
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700462 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
463 hwc_rect_t displayFrame = layer->displayFrame;
464
465 // No FB update optimization on (1) Custom FB resolution,
466 // (2) External Mirror mode, (3) External orientation
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800467 if(!ctx->dpyAttr[mDpy].fbScaling && !ctx->mBufferMirrorMode
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700468 && !ctx->mExtOrientation) {
469 sourceCrop = fbUpdatingRect;
470 displayFrame = fbUpdatingRect;
471 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800472 int transform = layer->transform;
473 ovutils::eTransform orient =
474 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800475
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700476 // use ext orientation if any
477 int extOrient = getExtOrientation(ctx);
478
479 // Do not use getNonWormholeRegion() function to calculate the
480 // sourceCrop during animation on external display and
481 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700482 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700483 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
484 sourceCrop = layer->displayFrame;
485 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700486 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700487 if(!qdutils::MDPVersion::getInstance().is8x26() &&
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800488 !ctx->dpyAttr[mDpy].fbScaling) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700489 getNonWormholeRegion(list, sourceCrop);
490 displayFrame = sourceCrop;
491 }
492 }
493
494 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
495 transform, orient);
496 hwc_rect_t cropL = sourceCrop;
497 hwc_rect_t cropR = sourceCrop;
498 hwc_rect_t dstL = displayFrame;
499 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800500
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500501 if(ctx->dpyAttr[mDpy].s3dMode == HDMI_S3D_SIDE_BY_SIDE) {
502 dstL.left = displayFrame.left/2;
503 dstL.right = displayFrame.right/2;
504
505 dstR.left = mAlignedFBWidth/2 + displayFrame.left/2;
506 dstR.right = mAlignedFBWidth/2 + displayFrame.right/2;
507 } else if(ctx->dpyAttr[mDpy].s3dMode == HDMI_S3D_TOP_AND_BOTTOM) {
508 dstL.top = displayFrame.top/2;
509 dstL.bottom = displayFrame.bottom/2;
510
511 dstR.top = mAlignedFBHeight/2 + displayFrame.top/2;
512 dstR.bottom = mAlignedFBHeight/2 + displayFrame.bottom/2;
513 }
514
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800515 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800516 Overlay::PipeSpecs pipeSpecs;
517 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500518 pipeSpecs.needsScaling = (qhwc::needsScaling(layer) ||
519 needs3DComposition(ctx,mDpy));
Saurabh Shahc62f3982014-03-05 14:28:26 -0800520 pipeSpecs.dpy = mDpy;
521 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
522 pipeSpecs.fb = true;
523 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800524 if(destL == ovutils::OV_INVALID) {
525 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
526 " mixer", __FUNCTION__, mDpy);
527 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800528 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800529
530 ovutils::eDest destR = ovutils::OV_INVALID;
531
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700532 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530533 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700534 b) On primary, driver has indicated with caps to split always. This is
535 based on an empirically derived value of panel height.
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500536 c) The composition is 3D
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700537 */
538
Saurabh Shah189f23d2014-09-26 17:21:00 -0700539 const bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700540 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
Saurabh Shah189f23d2014-09-26 17:21:00 -0700541 const uint32_t lSplit = getLeftSplit(ctx, mDpy);
542 const uint32_t cropWidth = sourceCrop.right - sourceCrop.left;
Saurabh Shah514759d2014-11-11 18:02:24 -0800543 const uint32_t cropHeight = sourceCrop.bottom - sourceCrop.top;
544 const uint32_t dstWidth = displayFrame.right - displayFrame.left;
545 const uint32_t dstHeight = displayFrame.bottom - displayFrame.top;
546 const uint32_t layerClock = getLayerClock(dstWidth, dstHeight, cropHeight);
547 const uint32_t mixerClock = lSplit;
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700548
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800549 if((cropWidth > qdutils::MDPVersion::getInstance().getMaxPipeWidth()) or
Saurabh Shah514759d2014-11-11 18:02:24 -0800550 (primarySplitAlways and
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500551 (cropWidth > lSplit or layerClock > mixerClock)) or
552 needs3DComposition(ctx, mDpy)) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800553 destR = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800554 if(destR == ovutils::OV_INVALID) {
555 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
556 " mixer", __FUNCTION__, mDpy);
557 return false;
558 }
559
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800560 if(ctx->mOverlay->needsPrioritySwap(destL, destR)) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800561 qhwc::swap(destL, destR);
562 }
563
564 //Split crop equally when using 2 pipes
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500565 if(!needs3DComposition(ctx, mDpy)) {
566 cropL.right = (sourceCrop.right + sourceCrop.left) / 2;
567 cropR.left = cropL.right;
568 dstL.right = (displayFrame.right + displayFrame.left) / 2;
569 dstR.left = dstL.right;
570 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800571 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800572
573 mDestLeft = destL;
574 mDestRight = destR;
575
576 if(destL != OV_INVALID) {
577 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700578 cropL, dstL, NULL /*metadata*/, destL) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800579 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800580 return false;
581 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800582 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800583
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500584 // XXX: Figure out why we need this with source split
585 // Currently, the driver silently fails to configure the right pipe
586 // if we don't increment the zorder
587 if (needs3DComposition(ctx, mDpy))
588 parg.zorder = eZorder(parg.zorder + 1);
589
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800590 //configure right pipe
591 if(destR != OV_INVALID) {
592 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700593 cropR, dstR, NULL /*metadata*/, destR) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800594 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800595 return false;
596 }
597 }
598
599 return true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800600}
601
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500602//---------------------------------------------------------------------
603}; //namespace qhwc