blob: ef8300844b88474c091a2db3ba936c0d391fea8f [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;
52 if (ctx->dpyAttr[dpy].customFBSize) {
53 //GPU will render and compose at new resolution
54 //So need to have FB at new resolution
55 xres = ctx->dpyAttr[mDpy].xres_new;
56 yres = ctx->dpyAttr[mDpy].yres_new;
57 }
58 getBufferAttributes((int)xres, (int)yres,
Saurabh Shah220a30c2013-10-29 16:12:12 -070059 HAL_PIXEL_FORMAT_RGBA_8888,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070060 0,
Saurabh Shah220a30c2013-10-29 16:12:12 -070061 mAlignedFBWidth,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070062 mAlignedFBHeight,
63 mTileEnabled, size);
Saurabh Shah220a30c2013-10-29 16:12:12 -070064}
65
66void IFBUpdate::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080067 mModeOn = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070068 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -080069}
70
Saurabh Shaha36be922013-12-16 18:18:39 -080071bool IFBUpdate::prepareAndValidate(hwc_context_t *ctx,
72 hwc_display_contents_1 *list, int fbZorder) {
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -080073 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070074 mModeOn = prepare(ctx, list, layer->displayFrame, fbZorder) &&
Saurabh Shaha36be922013-12-16 18:18:39 -080075 ctx->mOverlay->validateAndSet(mDpy, ctx->dpyAttr[mDpy].fd);
Ramkumar Radhakrishnan3686b7e2014-03-17 17:30:15 -070076 return mModeOn;
Saurabh Shaha36be922013-12-16 18:18:39 -080077}
78
Saurabh Shahcf053c62012-12-13 12:32:55 -080079//================= Low res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -070080FBUpdateNonSplit::FBUpdateNonSplit(hwc_context_t *ctx, const int& dpy):
81 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -080082
Saurabh Shah220a30c2013-10-29 16:12:12 -070083void FBUpdateNonSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -080084 IFBUpdate::reset();
85 mDest = ovutils::OV_INVALID;
86}
87
Saurabh Shah88e4d272013-09-03 13:31:29 -070088bool FBUpdateNonSplit::preRotateExtDisplay(hwc_context_t *ctx,
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +053089 hwc_layer_1_t *layer,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -070090 ovutils::Whf &info,
91 hwc_rect_t& sourceCrop,
92 ovutils::eMdpFlags& mdpFlags,
93 int& rotFlags)
94{
95 int extOrient = getExtOrientation(ctx);
96 ovutils::eTransform orient = static_cast<ovutils::eTransform >(extOrient);
97 if(mDpy && (extOrient & HWC_TRANSFORM_ROT_90)) {
98 mRot = ctx->mRotMgr->getNext();
99 if(mRot == NULL) return false;
Saurabh Shah39240c92014-03-31 10:31:42 -0700100 ctx->mLayerRotMap[mDpy]->add(layer, mRot);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800101 // Composed FB content will have black bars, if the viewFrame of the
102 // external is different from {0, 0, fbWidth, fbHeight}, so intersect
103 // viewFrame with sourceCrop to avoid those black bars
104 sourceCrop = getIntersection(sourceCrop, ctx->mViewFrame[mDpy]);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700105 //Configure rotator for pre-rotation
106 if(configRotator(mRot, info, sourceCrop, mdpFlags, orient, 0) < 0) {
107 ALOGE("%s: configRotator Failed!", __FUNCTION__);
108 mRot = NULL;
109 return false;
110 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -0700111 updateSource(orient, info, sourceCrop, mRot);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700112 rotFlags |= ovutils::ROT_PREROTATED;
113 }
114 return true;
115}
116
Saurabh Shah88e4d272013-09-03 13:31:29 -0700117bool FBUpdateNonSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800118 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500119 if(!ctx->mMDP.hasOverlay) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800120 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800121 __FUNCTION__);
122 return false;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500123 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800124 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800125 return mModeOn;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500126}
127
128// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700129bool FBUpdateNonSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800130 hwc_rect_t fbUpdatingRect, int fbZorder) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500131 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500132 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500133 if (LIKELY(ctx->mOverlay)) {
134 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shah220a30c2013-10-29 16:12:12 -0700135
Sushil Chauhan65e26302015-01-14 10:48:57 -0800136 int flags = mTileEnabled ?
137 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700138 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800139 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500140
Saurabh Shahc62f3982014-03-05 14:28:26 -0800141 Overlay::PipeSpecs pipeSpecs;
142 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
143 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
144 pipeSpecs.dpy = mDpy;
145 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
146 pipeSpecs.fb = true;
147
148 ovutils::eDest dest = ov.getPipe(pipeSpecs);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500149 if(dest == ovutils::OV_INVALID) { //None available
Saurabh Shahaa236822013-04-24 18:07:26 -0700150 ALOGE("%s: No pipes available to configure fb for dpy %d",
151 __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500152 return false;
153 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800154 mDest = dest;
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500155
Ramkumar Radhakrishnan1829d282013-07-23 14:54:36 -0700156 if((mDpy && ctx->deviceOrientation) &&
157 ctx->listStats[mDpy].isDisplayAnimating) {
158 fbZorder = 0;
159 }
160
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800161 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530162 ovutils::setMdpFlags(mdpFlags,
163 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800164 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500165
Saurabh Shah62e1d732013-09-17 10:44:05 -0700166 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800167 hwc_rect_t displayFrame = layer->displayFrame;
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800168
169 // No FB update optimization on (1) Custom FB resolution,
170 // (2) External Mirror mode, (3) External orientation
171 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
172 && !ctx->mExtOrientation) {
173 sourceCrop = fbUpdatingRect;
174 displayFrame = fbUpdatingRect;
175 }
176
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700177 int transform = layer->transform;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700178 int rotFlags = ovutils::ROT_FLAGS_NONE;
179
180 ovutils::eTransform orient =
181 static_cast<ovutils::eTransform>(transform);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700182 // use ext orientation if any
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700183 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700184
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700185 // Do not use getNonWormholeRegion() function to calculate the
186 // sourceCrop during animation on external display and
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700187 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700188 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700189 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
190 sourceCrop = layer->displayFrame;
Ramkumar Radhakrishnan3b0d9722014-08-06 13:08:40 -0700191 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700192 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Raj Kamal068f4572014-04-14 16:14:06 +0530193 if(ctx->mOverlay->isUIScalingOnExternalSupported() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530194 !ctx->dpyAttr[mDpy].customFBSize) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700195 getNonWormholeRegion(list, sourceCrop);
196 displayFrame = sourceCrop;
197 }
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800198 }
Saurabh Shah220a30c2013-10-29 16:12:12 -0700199 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700200 transform, orient);
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800201 //Store the displayFrame, will be used in getDisplayViewFrame
202 ctx->dpyAttr[mDpy].mDstRect = displayFrame;
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -0800203 setMdpFlags(ctx, layer, mdpFlags, 0, transform);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700204 // For External use rotator if there is a rotation value set
Prabhanjan Kanduladb202b72013-10-30 17:29:46 +0530205 ret = preRotateExtDisplay(ctx, layer, info,
206 sourceCrop, mdpFlags, rotFlags);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700207 if(!ret) {
208 ALOGE("%s: preRotate for external Failed!", __FUNCTION__);
209 return false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700210 }
211 //For the mdp, since either we are pre-rotating or MDP does flips
212 orient = ovutils::OVERLAY_TRANSFORM_0;
213 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -0700214 ovutils::PipeArgs parg(mdpFlags, info, zOrder,
Naseer Ahmed522ce662013-03-18 20:14:05 -0400215 static_cast<ovutils::eRotFlags>(rotFlags),
216 ovutils::DEFAULT_PLANE_ALPHA,
217 (ovutils::eBlending)
218 getBlending(layer->blending));
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500219 ret = true;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700220 if(configMdp(ctx->mOverlay, parg, orient, sourceCrop, displayFrame,
221 NULL, mDest) < 0) {
Saurabh Shahe2474082013-05-15 16:32:13 -0700222 ALOGE("%s: configMdp failed for dpy %d", __FUNCTION__, mDpy);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500223 ret = false;
224 }
225 }
226 return ret;
227}
228
Saurabh Shah88e4d272013-09-03 13:31:29 -0700229bool FBUpdateNonSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500230{
Saurabh Shahcf053c62012-12-13 12:32:55 -0800231 if(!mModeOn) {
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500232 return true;
233 }
234 bool ret = true;
235 overlay::Overlay& ov = *(ctx->mOverlay);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800236 ovutils::eDest dest = mDest;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700237 int fd = hnd->fd;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530238 uint32_t offset = (uint32_t)hnd->offset;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700239 if(mRot) {
240 if(!mRot->queueBuffer(fd, offset))
241 return false;
242 fd = mRot->getDstMemId();
243 offset = mRot->getDstOffset();
244 }
245 if (!ov.queueBuffer(fd, offset, dest)) {
Amara Venkata Mastan Manoj Kumardc01a532013-01-30 18:34:56 -0800246 ALOGE("%s: queueBuffer failed for FBUpdate", __FUNCTION__);
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500247 ret = false;
248 }
249 return ret;
250}
251
Saurabh Shahcf053c62012-12-13 12:32:55 -0800252//================= High res====================================
Saurabh Shah220a30c2013-10-29 16:12:12 -0700253FBUpdateSplit::FBUpdateSplit(hwc_context_t *ctx, const int& dpy):
254 IFBUpdate(ctx, dpy) {}
Saurabh Shahcf053c62012-12-13 12:32:55 -0800255
Saurabh Shah220a30c2013-10-29 16:12:12 -0700256void FBUpdateSplit::reset() {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800257 IFBUpdate::reset();
258 mDestLeft = ovutils::OV_INVALID;
259 mDestRight = ovutils::OV_INVALID;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700260 mRot = NULL;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800261}
262
Saurabh Shah88e4d272013-09-03 13:31:29 -0700263bool FBUpdateSplit::prepare(hwc_context_t *ctx, hwc_display_contents_1 *list,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800264 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800265 if(!ctx->mMDP.hasOverlay) {
266 ALOGD_IF(DEBUG_FBUPDATE, "%s, this hw doesnt support overlays",
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800267 __FUNCTION__);
268 return false;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800269 }
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800270 mModeOn = configure(ctx, list, fbUpdatingRect, fbZorder);
Raj Kamal4393eaa2014-06-06 13:45:20 +0530271 ALOGD_IF(DEBUG_FBUPDATE, "%s, mModeOn = %d", __FUNCTION__, mModeOn);
Saurabh Shahcf053c62012-12-13 12:32:55 -0800272 return mModeOn;
273}
274
275// Configure
Saurabh Shah88e4d272013-09-03 13:31:29 -0700276bool FBUpdateSplit::configure(hwc_context_t *ctx,
Jeykumar Sankaranc2d78d82014-02-14 14:55:29 -0800277 hwc_display_contents_1 *list, hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800278 bool ret = false;
Naseer Ahmed64b81212013-02-14 10:29:47 -0500279 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahcf053c62012-12-13 12:32:55 -0800280 if (LIKELY(ctx->mOverlay)) {
Sushil Chauhan65e26302015-01-14 10:48:57 -0800281 int flags = mTileEnabled ?
282 private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800283 ovutils::Whf info(mAlignedFBWidth, mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800284 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800285
Saurabh Shahcf053c62012-12-13 12:32:55 -0800286 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800287 ovutils::eMdpFlags mdpFlags = ovutils::OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530288 ovutils::setMdpFlags(mdpFlags,
289 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800290 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800291 ovutils::eTransform orient =
292 static_cast<ovutils::eTransform>(layer->transform);
293 const int hw_w = ctx->dpyAttr[mDpy].xres;
294 const int hw_h = ctx->dpyAttr[mDpy].yres;
295 const int lSplit = getLeftSplit(ctx, mDpy);
296 mDestLeft = ovutils::OV_INVALID;
297 mDestRight = ovutils::OV_INVALID;
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700298 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
299 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shahcf053c62012-12-13 12:32:55 -0800300
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700301 // No FB update optimization on (1) Custom FB resolution,
302 // (2) External Mirror mode, (3) External orientation
303 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
304 && !ctx->mExtOrientation) {
305 sourceCrop = fbUpdatingRect;
306 displayFrame = fbUpdatingRect;
307 }
308
309 int transform = layer->transform;
310 // use ext orientation if any
311 int extOrient = getExtOrientation(ctx);
312
313 // Do not use getNonWormholeRegion() function to calculate the
314 // sourceCrop during animation on external display and
315 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700316 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700317 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
318 sourceCrop = layer->displayFrame;
319 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700320 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700321 if(!qdutils::MDPVersion::getInstance().is8x26() &&
322 !ctx->dpyAttr[mDpy].customFBSize) {
323 getNonWormholeRegion(list, sourceCrop);
324 displayFrame = sourceCrop;
325 }
326 }
327
328 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
329 transform, orient);
Saurabh Shah67a38c32013-06-10 16:23:15 -0700330
Saurabh Shahcf053c62012-12-13 12:32:55 -0800331 ret = true;
Saurabh Shahc62f3982014-03-05 14:28:26 -0800332 Overlay::PipeSpecs pipeSpecs;
333 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
334 pipeSpecs.needsScaling = qhwc::needsScaling(layer);
335 pipeSpecs.dpy = mDpy;
336 pipeSpecs.fb = true;
337
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800338 /* Configure left pipe */
339 if(displayFrame.left < lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800340 pipeSpecs.mixer = Overlay::MIXER_LEFT;
341 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800342 if(destL == ovutils::OV_INVALID) { //None available
343 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
344 " mixer", __FUNCTION__, mDpy);
345 return false;
346 }
347
348 mDestLeft = destL;
349
350 //XXX: FB layer plane alpha is currently sent as zero from
351 //surfaceflinger
352 ovutils::PipeArgs pargL(mdpFlags,
353 info,
354 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800355 ovutils::ROT_FLAGS_NONE,
356 ovutils::DEFAULT_PLANE_ALPHA,
357 (ovutils::eBlending)
358 getBlending(layer->blending));
359 hwc_rect_t cropL = sourceCrop;
360 hwc_rect_t dstL = displayFrame;
361 hwc_rect_t scissorL = {0, 0, lSplit, hw_h };
362 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
363
364 if (configMdp(ctx->mOverlay, pargL, orient, cropL,
365 dstL, NULL, destL)< 0) {
366 ALOGE("%s: configMdp fails for left FB", __FUNCTION__);
367 ret = false;
368 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800369 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800370
371 /* Configure right pipe */
372 if(displayFrame.right > lSplit) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800373 pipeSpecs.mixer = Overlay::MIXER_RIGHT;
374 ovutils::eDest destR = ov.getPipe(pipeSpecs);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800375 if(destR == ovutils::OV_INVALID) { //None available
376 ALOGE("%s: No pipes available to configure fb for dpy %d's"
377 " right mixer", __FUNCTION__, mDpy);
378 return false;
379 }
380
381 mDestRight = destR;
382 ovutils::eMdpFlags mdpFlagsR = mdpFlags;
383 ovutils::setMdpFlags(mdpFlagsR, ovutils::OV_MDSS_MDP_RIGHT_MIXER);
384
385 //XXX: FB layer plane alpha is currently sent as zero from
386 //surfaceflinger
387 ovutils::PipeArgs pargR(mdpFlagsR,
388 info,
389 zOrder,
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800390 ovutils::ROT_FLAGS_NONE,
391 ovutils::DEFAULT_PLANE_ALPHA,
392 (ovutils::eBlending)
393 getBlending(layer->blending));
394
395 hwc_rect_t cropR = sourceCrop;
396 hwc_rect_t dstR = displayFrame;
397 hwc_rect_t scissorR = {lSplit, 0, hw_w, hw_h };
398 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
399
400 dstR.left -= lSplit;
401 dstR.right -= lSplit;
402
403 if (configMdp(ctx->mOverlay, pargR, orient, cropR,
404 dstR, NULL, destR) < 0) {
405 ALOGE("%s: configMdp fails for right FB", __FUNCTION__);
406 ret = false;
407 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800408 }
409 }
410 return ret;
411}
412
Saurabh Shah88e4d272013-09-03 13:31:29 -0700413bool FBUpdateSplit::draw(hwc_context_t *ctx, private_handle_t *hnd)
Saurabh Shahcf053c62012-12-13 12:32:55 -0800414{
415 if(!mModeOn) {
416 return true;
417 }
418 bool ret = true;
419 overlay::Overlay& ov = *(ctx->mOverlay);
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800420 if(mDestLeft != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530421 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestLeft)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800422 ALOGE("%s: queue failed for left of dpy = %d",
423 __FUNCTION__, mDpy);
424 ret = false;
425 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800426 }
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800427 if(mDestRight != ovutils::OV_INVALID) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530428 if (!ov.queueBuffer(hnd->fd, (uint32_t)hnd->offset, mDestRight)) {
Jeykumar Sankaranc28eb0b2014-02-27 14:42:35 -0800429 ALOGE("%s: queue failed for right of dpy = %d",
430 __FUNCTION__, mDpy);
431 ret = false;
432 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800433 }
434 return ret;
435}
436
Saurabh Shahab47c692014-02-12 18:45:57 -0800437//=================FBSrcSplit====================================
438FBSrcSplit::FBSrcSplit(hwc_context_t *ctx, const int& dpy):
439 FBUpdateSplit(ctx, dpy) {}
440
441bool FBSrcSplit::configure(hwc_context_t *ctx, hwc_display_contents_1 *list,
442 hwc_rect_t fbUpdatingRect, int fbZorder) {
Saurabh Shahab47c692014-02-12 18:45:57 -0800443 hwc_layer_1_t *layer = &list->hwLayers[list->numHwLayers - 1];
Saurabh Shahab47c692014-02-12 18:45:57 -0800444 overlay::Overlay& ov = *(ctx->mOverlay);
445
Sushil Chauhan65e26302015-01-14 10:48:57 -0800446 int flags = mTileEnabled ? private_handle_t::PRIV_FLAGS_TILE_RENDERED : 0;
Saurabh Shahab47c692014-02-12 18:45:57 -0800447 ovutils::Whf info(mAlignedFBWidth,
448 mAlignedFBHeight,
Sushil Chauhan65e26302015-01-14 10:48:57 -0800449 ovutils::getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888, flags));
Saurabh Shahab47c692014-02-12 18:45:57 -0800450
451 ovutils::eMdpFlags mdpFlags = OV_MDP_BLEND_FG_PREMULT;
Justin Philipd6166602014-08-12 13:42:21 +0530452 ovutils::setMdpFlags(mdpFlags,
453 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahab47c692014-02-12 18:45:57 -0800454 ovutils::eZorder zOrder = static_cast<ovutils::eZorder>(fbZorder);
455
456 ovutils::PipeArgs parg(mdpFlags,
457 info,
458 zOrder,
Saurabh Shahab47c692014-02-12 18:45:57 -0800459 ovutils::ROT_FLAGS_NONE,
460 ovutils::DEFAULT_PLANE_ALPHA,
461 (ovutils::eBlending)
462 getBlending(layer->blending));
Saurabh Shahab47c692014-02-12 18:45:57 -0800463
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700464 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
465 hwc_rect_t displayFrame = layer->displayFrame;
466
467 // No FB update optimization on (1) Custom FB resolution,
468 // (2) External Mirror mode, (3) External orientation
469 if(!ctx->dpyAttr[mDpy].customFBSize && !ctx->mBufferMirrorMode
470 && !ctx->mExtOrientation) {
471 sourceCrop = fbUpdatingRect;
472 displayFrame = fbUpdatingRect;
473 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800474 int transform = layer->transform;
475 ovutils::eTransform orient =
476 static_cast<ovutils::eTransform>(transform);
Saurabh Shahab47c692014-02-12 18:45:57 -0800477
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700478 // use ext orientation if any
479 int extOrient = getExtOrientation(ctx);
480
481 // Do not use getNonWormholeRegion() function to calculate the
482 // sourceCrop during animation on external display and
483 // Dont do wormhole calculation when extorientation is set on External
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700484 // Dont do wormhole calculation when scaling mode is set on External
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700485 if(ctx->listStats[mDpy].isDisplayAnimating && mDpy) {
486 sourceCrop = layer->displayFrame;
487 } else if((mDpy && !extOrient
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700488 && !ctx->dpyAttr[mDpy].mMDPScalingMode)) {
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700489 if(!qdutils::MDPVersion::getInstance().is8x26() &&
490 !ctx->dpyAttr[mDpy].customFBSize) {
491 getNonWormholeRegion(list, sourceCrop);
492 displayFrame = sourceCrop;
493 }
494 }
495
496 calcExtDisplayPosition(ctx, NULL, mDpy, sourceCrop, displayFrame,
497 transform, orient);
498 hwc_rect_t cropL = sourceCrop;
499 hwc_rect_t cropR = sourceCrop;
500 hwc_rect_t dstL = displayFrame;
501 hwc_rect_t dstR = displayFrame;
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800502
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500503 if(ctx->dpyAttr[mDpy].s3dMode == HDMI_S3D_SIDE_BY_SIDE) {
504 dstL.left = displayFrame.left/2;
505 dstL.right = displayFrame.right/2;
506
507 dstR.left = mAlignedFBWidth/2 + displayFrame.left/2;
508 dstR.right = mAlignedFBWidth/2 + displayFrame.right/2;
509 } else if(ctx->dpyAttr[mDpy].s3dMode == HDMI_S3D_TOP_AND_BOTTOM) {
510 dstL.top = displayFrame.top/2;
511 dstL.bottom = displayFrame.bottom/2;
512
513 dstR.top = mAlignedFBHeight/2 + displayFrame.top/2;
514 dstR.bottom = mAlignedFBHeight/2 + displayFrame.bottom/2;
515 }
516
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800517 //Request left pipe (or 1 by default)
Saurabh Shahc62f3982014-03-05 14:28:26 -0800518 Overlay::PipeSpecs pipeSpecs;
519 pipeSpecs.formatClass = Overlay::FORMAT_RGB;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500520 pipeSpecs.needsScaling = (qhwc::needsScaling(layer) ||
521 needs3DComposition(ctx,mDpy));
Saurabh Shahc62f3982014-03-05 14:28:26 -0800522 pipeSpecs.dpy = mDpy;
523 pipeSpecs.mixer = Overlay::MIXER_DEFAULT;
524 pipeSpecs.fb = true;
525 ovutils::eDest destL = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800526 if(destL == ovutils::OV_INVALID) {
527 ALOGE("%s: No pipes available to configure fb for dpy %d's left"
528 " mixer", __FUNCTION__, mDpy);
529 return false;
Saurabh Shahab47c692014-02-12 18:45:57 -0800530 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800531
532 ovutils::eDest destR = ovutils::OV_INVALID;
533
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700534 /* Use 2 pipes IF
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +0530535 a) FB's width is > Mixer width or
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700536 b) On primary, driver has indicated with caps to split always. This is
537 based on an empirically derived value of panel height.
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500538 c) The composition is 3D
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700539 */
540
Saurabh Shah189f23d2014-09-26 17:21:00 -0700541 const bool primarySplitAlways = (mDpy == HWC_DISPLAY_PRIMARY) and
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700542 qdutils::MDPVersion::getInstance().isSrcSplitAlways();
Saurabh Shah189f23d2014-09-26 17:21:00 -0700543 const uint32_t lSplit = getLeftSplit(ctx, mDpy);
544 const uint32_t cropWidth = sourceCrop.right - sourceCrop.left;
Saurabh Shah514759d2014-11-11 18:02:24 -0800545 const uint32_t cropHeight = sourceCrop.bottom - sourceCrop.top;
546 const uint32_t dstWidth = displayFrame.right - displayFrame.left;
547 const uint32_t dstHeight = displayFrame.bottom - displayFrame.top;
548 const uint32_t layerClock = getLayerClock(dstWidth, dstHeight, cropHeight);
549 const uint32_t mixerClock = lSplit;
Saurabh Shahea7a01d2014-05-22 17:45:36 -0700550
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800551 if((cropWidth > qdutils::MDPVersion::getInstance().getMaxPipeWidth()) or
Saurabh Shah514759d2014-11-11 18:02:24 -0800552 (primarySplitAlways and
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500553 (cropWidth > lSplit or layerClock > mixerClock)) or
554 needs3DComposition(ctx, mDpy)) {
Saurabh Shahc62f3982014-03-05 14:28:26 -0800555 destR = ov.getPipe(pipeSpecs);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800556 if(destR == ovutils::OV_INVALID) {
557 ALOGE("%s: No pipes available to configure fb for dpy %d's right"
558 " mixer", __FUNCTION__, mDpy);
559 return false;
560 }
561
Jeykumar Sankaran89e23ab2015-01-28 15:57:46 -0800562 if(ctx->mOverlay->needsPrioritySwap(destL, destR)) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800563 qhwc::swap(destL, destR);
564 }
565
566 //Split crop equally when using 2 pipes
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500567 if(!needs3DComposition(ctx, mDpy)) {
568 cropL.right = (sourceCrop.right + sourceCrop.left) / 2;
569 cropR.left = cropL.right;
570 dstL.right = (displayFrame.right + displayFrame.left) / 2;
571 dstR.left = dstL.right;
572 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800573 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800574
575 mDestLeft = destL;
576 mDestRight = destR;
577
578 if(destL != OV_INVALID) {
579 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700580 cropL, dstL, NULL /*metadata*/, destL) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800581 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800582 return false;
583 }
Saurabh Shahab47c692014-02-12 18:45:57 -0800584 }
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800585
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500586 // XXX: Figure out why we need this with source split
587 // Currently, the driver silently fails to configure the right pipe
588 // if we don't increment the zorder
589 if (needs3DComposition(ctx, mDpy))
590 parg.zorder = eZorder(parg.zorder + 1);
591
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800592 //configure right pipe
593 if(destR != OV_INVALID) {
594 if(configMdp(ctx->mOverlay, parg, orient,
Ramkumar Radhakrishnane1f433a2014-08-06 12:10:33 -0700595 cropR, dstR, NULL /*metadata*/, destR) < 0) {
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800596 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahdd8237a2014-02-28 14:29:09 -0800597 return false;
598 }
599 }
600
601 return true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800602}
603
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500604//---------------------------------------------------------------------
605}; //namespace qhwc