blob: 8a42b3898efff99c607840248a5e04cb559be2a1 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05003 * Copyright (C) 2012-2014, The Linux Foundation All rights reserved.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
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 */
Naseer Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080021#define HWC_UTILS_DEBUG 0
Saurabh Shahc5b96dc2013-06-05 13:19:52 -070022#include <math.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040024#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080025#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070026#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070027#include <cutils/properties.h>
Naseer Ahmed099a6932013-09-09 14:25:20 -040028#include <utils/Trace.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070029#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080031#include <overlayRotator.h>
Saurabh Shaha9da08f2013-07-03 13:27:53 -070032#include <overlayWriteback.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080035#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070036#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070037#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070039#include "hwc_dump_layers.h"
Naseer Ahmed58780b92013-07-29 17:41:40 -040040#include "hwc_vpuclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070041#include "external.h"
Jeykumar Sankaran27dee262013-08-01 17:09:54 -070042#include "virtual.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080043#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070044#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080045#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080046#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080047#include "qd_utils.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080048
49using namespace qClient;
50using namespace qService;
51using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080052using namespace overlay;
53using namespace overlay::utils;
54namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080055
Naseer Ahmed29a26812012-06-14 00:56:20 -070056namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070057
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053058bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
59{
60 return !((xres > qdutils::MAX_DISPLAY_DIM &&
61 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
62 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
63}
64
65void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig) {
66 //Store original display resolution.
67 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_orig = xres_orig;
68 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_orig = yres_orig;
69 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false;
70
71 char property[PROPERTY_VALUE_MAX] = {'\0'};
72 char *yptr = NULL;
73 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
74 yptr = strcasestr(property,"x");
75 int xres = atoi(property);
76 int yres = atoi(yptr + 1);
77 if (isValidResolution(ctx,xres,yres) &&
78 xres != xres_orig && yres != yres_orig) {
79 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = xres;
80 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = yres;
81 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
82 }
83 }
84}
85
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080086static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -070087{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080088 struct fb_fix_screeninfo finfo;
89 struct fb_var_screeninfo info;
90
91 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053092 if(fb_fd < 0) {
93 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080094 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053095 }
96
97 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
98 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
99 strerror(errno));
100 close(fb_fd);
101 return -errno;
102 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800103
104 if (int(info.width) <= 0 || int(info.height) <= 0) {
105 // the driver doesn't return that information
106 // default to 160 dpi
107 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
108 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700109 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800110
111 float xdpi = (info.xres * 25.4f) / info.width;
112 float ydpi = (info.yres * 25.4f) / info.height;
113
114#ifdef MSMFB_METADATA_GET
115 struct msmfb_metadata metadata;
116 memset(&metadata, 0 , sizeof(metadata));
117 metadata.op = metadata_op_frame_rate;
118
119 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530120 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
121 strerror(errno));
122 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800123 return -errno;
124 }
125
126 float fps = metadata.data.panel_frame_rate;
127#else
128 //XXX: Remove reserved field usage on all baselines
129 //The reserved[3] field is used to store FPS by the driver.
130 float fps = info.reserved[3] & 0xFF;
131#endif
132
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530133 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
134 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
135 strerror(errno));
136 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800137 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530138 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800139
140 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
141 //xres, yres may not be 32 aligned
142 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
143 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
144 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
145 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
146 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
147 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
148
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530149 //To change resolution of primary display
150 changeResolution(ctx, info.xres, info.yres);
151
Naseer Ahmed22616d92013-05-15 17:20:26 -0400152 //Unblank primary on first boot
153 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
154 ALOGE("%s: Failed to unblank display", __FUNCTION__);
155 return -errno;
156 }
157 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
158
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800159 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700160}
161
Naseer Ahmed29a26812012-06-14 00:56:20 -0700162void initContext(hwc_context_t *ctx)
163{
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700164 openFramebufferDevice(ctx);
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700165 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
166 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
167 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800168 overlay::Overlay::initOverlay();
169 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800170 ctx->mRotMgr = RotMgr::getInstance();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800171
Saurabh Shahcf053c62012-12-13 12:32:55 -0800172 //Is created and destroyed only once for primary
173 //For external it could get created and destroyed multiple times depending
174 //on what external we connect to.
175 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700176 IFBUpdate::getObject(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800177
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800178 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800179 // decide if we need to open the copybit module.
180 int compositionType =
181 qdutils::QCCompositionType::getInstance().getCompositionType();
182
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800183 // Only MDP copybit is used
184 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
185 qdutils::COMPOSITION_TYPE_MDP)) &&
186 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
187 qdutils::MDP_V3_0_4)) {
188 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
189 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800190 }
191
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700192 ctx->mExtDisplay = new ExternalDisplay(ctx);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700193 ctx->mVirtualDisplay = new VirtualDisplay(ctx);
194 ctx->mVirtualonExtActive = false;
195 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
196 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
197 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
198 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700199 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mDownScaleMode= false;
200 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mDownScaleMode = false;
201 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800202
203 ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700204 MDPComp::getObject(ctx, HWC_DISPLAY_PRIMARY);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700205 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800206 ctx->mHWCVirtual = HWCVirtualBase::getObject();
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800207
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700208 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700209 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700210 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700211 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800212 ctx->dpyAttr[i].mActionSafePresent = false;
213 ctx->dpyAttr[i].mAsWidthRatio = 0;
214 ctx->dpyAttr[i].mAsHeightRatio = 0;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700215 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700216
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530217 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
218 ctx->mPrevHwLayerCount[i] = 0;
219 }
220
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500221 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700222 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700223
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400224 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500225 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700226 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530227 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800228
229 //Right now hwc starts the service but anybody could do it, or it could be
230 //independent process as well.
231 QService::init();
232 sp<IQClient> client = new QClient(ctx);
233 interface_cast<IQService>(
234 defaultServiceManager()->getService(
235 String16("display.qservice")))->connect(client);
236
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700237 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700238 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700239 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400240 ctx->mVPUClient = NULL;
241
Tatenda Chipeperekwa5d14c712014-02-20 19:07:01 -0800242 // Read the system property to determine if downscale feature is enabled.
243 ctx->mMDPDownscaleEnabled = false;
244 char value[PROPERTY_VALUE_MAX];
245 if(property_get("sys.hwc.mdp_downscale_enabled", value, "false")
246 && !strcmp(value, "true")) {
247 ctx->mMDPDownscaleEnabled = true;
248 }
249
Naseer Ahmed58780b92013-07-29 17:41:40 -0400250#ifdef VPU_TARGET
Zohaib Alam1bb65612013-09-28 03:38:20 -0400251 if(qdutils::MDPVersion::getInstance().is8092())
252 ctx->mVPUClient = new VPUClient(ctx);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400253#endif
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700254
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700255 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700256 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700257}
258
259void closeContext(hwc_context_t *ctx)
260{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500261 if(ctx->mOverlay) {
262 delete ctx->mOverlay;
263 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700264 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700265
Saurabh Shahacf10202013-02-26 10:15:15 -0800266 if(ctx->mRotMgr) {
267 delete ctx->mRotMgr;
268 ctx->mRotMgr = NULL;
269 }
270
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700271 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800272 if(ctx->mCopyBit[i]) {
273 delete ctx->mCopyBit[i];
274 ctx->mCopyBit[i] = NULL;
275 }
276 }
277
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800278 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700279 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
280 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700281 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700282
283 if(ctx->mExtDisplay) {
284 delete ctx->mExtDisplay;
285 ctx->mExtDisplay = NULL;
286 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400287
Naseer Ahmed58780b92013-07-29 17:41:40 -0400288#ifdef VPU_TARGET
Zohaib Alam1bb65612013-09-28 03:38:20 -0400289 if(ctx->mVPUClient != NULL)
Naseer Ahmed58780b92013-07-29 17:41:40 -0400290 delete ctx->mVPUClient;
Naseer Ahmed58780b92013-07-29 17:41:40 -0400291#endif
292
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700293 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800294 if(ctx->mFBUpdate[i]) {
295 delete ctx->mFBUpdate[i];
296 ctx->mFBUpdate[i] = NULL;
297 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800298 if(ctx->mMDPComp[i]) {
299 delete ctx->mMDPComp[i];
300 ctx->mMDPComp[i] = NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800301 }
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700302 if(ctx->mHwcDebug[i]) {
303 delete ctx->mHwcDebug[i];
304 ctx->mHwcDebug[i] = NULL;
305 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700306 if(ctx->mLayerRotMap[i]) {
307 delete ctx->mLayerRotMap[i];
308 ctx->mLayerRotMap[i] = NULL;
309 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800310 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800311 if(ctx->mHWCVirtual) {
312 delete ctx->mHWCVirtual;
313 ctx->mHWCVirtual = NULL;
314 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700315 if(ctx->mAD) {
316 delete ctx->mAD;
317 ctx->mAD = NULL;
318 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800319
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800320
Naseer Ahmed29a26812012-06-14 00:56:20 -0700321}
322
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500323
324void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700325{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500326 va_list varargs;
327 va_start(varargs, fmt);
328 buf.appendFormatV(fmt, varargs);
329 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700330}
331
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700332int getExtOrientation(hwc_context_t* ctx) {
333 int extOrient = ctx->mExtOrientation;
334 if(ctx->mBufferMirrorMode)
335 extOrient = getMirrorModeOrientation(ctx);
336 return extOrient;
337}
338
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800339/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700340void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
341 // Position
342 int x = rect.left, y = rect.top;
343 int w = rect.right - rect.left;
344 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800345
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800346 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800347 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800348 // Read action safe properties
349 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
350 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700351
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800352 float wRatio = 1.0;
353 float hRatio = 1.0;
354 float xRatio = 1.0;
355 float yRatio = 1.0;
356
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800357 int fbWidth = ctx->dpyAttr[dpy].xres;
358 int fbHeight = ctx->dpyAttr[dpy].yres;
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700359 if(ctx->dpyAttr[dpy].mDownScaleMode) {
360 // if downscale Mode is enabled for external, need to query
361 // the actual width and height, as that is the physical w & h
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800362 ctx->mExtDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700363 }
364
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800365
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700366 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700367 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700368
369 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700370 swap(fbWidth, fbHeight);
371
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800372 float asX = 0;
373 float asY = 0;
374 float asW = fbWidth;
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800375 float asH = fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800376
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800377 // based on the action safe ratio, get the Action safe rectangle
378 asW = fbWidth * (1.0f - asWidthRatio / 100.0f);
379 asH = fbHeight * (1.0f - asHeightRatio / 100.0f);
380 asX = (fbWidth - asW) / 2;
381 asY = (fbHeight - asH) / 2;
382
383 // calculate the position ratio
384 xRatio = (float)x/fbWidth;
385 yRatio = (float)y/fbHeight;
386 wRatio = (float)w/fbWidth;
387 hRatio = (float)h/fbHeight;
388
389 //Calculate the position...
390 x = (xRatio * asW) + asX;
391 y = (yRatio * asH) + asY;
392 w = (wRatio * asW);
393 h = (hRatio * asH);
394
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700395 // Convert it back to hwc_rect_t
396 rect.left = x;
397 rect.top = y;
398 rect.right = w + rect.left;
399 rect.bottom = h + rect.top;
400
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800401 return;
402}
403
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700404// This function gets the destination position for Seconday display
405// based on the position and aspect ratio with orientation
406void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
407 hwc_rect_t& inRect, hwc_rect_t& outRect) {
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800408 hwc_rect_t viewFrame = ctx->mViewFrame[dpy];
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700409 // Physical display resolution
410 float fbWidth = ctx->dpyAttr[dpy].xres;
411 float fbHeight = ctx->dpyAttr[dpy].yres;
412 //display position(x,y,w,h) in correct aspectratio after rotation
413 int xPos = 0;
414 int yPos = 0;
415 float width = fbWidth;
416 float height = fbHeight;
417 // Width/Height used for calculation, after rotation
418 float actualWidth = fbWidth;
419 float actualHeight = fbHeight;
420
421 float wRatio = 1.0;
422 float hRatio = 1.0;
423 float xRatio = 1.0;
424 float yRatio = 1.0;
425 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
426
427 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
428 inRect.bottom - inRect.top);
429 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
430 outRect.bottom - outRect.top);
431
432 Whf whf(fbWidth, fbHeight, 0);
433 eTransform extorient = static_cast<eTransform>(extOrientation);
434 // To calculate the destination co-ordinates in the new orientation
435 preRotateSource(extorient, whf, inPos);
436
437 if(extOrientation & HAL_TRANSFORM_ROT_90) {
438 // Swap width/height for input position
439 swapWidthHeight(actualWidth, actualHeight);
440 getAspectRatioPosition(fbWidth, fbHeight, (int)actualWidth,
441 (int)actualHeight, rect);
442 xPos = rect.left;
443 yPos = rect.top;
444 width = rect.right - rect.left;
445 height = rect.bottom - rect.top;
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800446 // swap viewframe coordinates for 90 degree rotation.
447 swap(viewFrame.left, viewFrame.top);
448 swap(viewFrame.right, viewFrame.bottom);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700449 }
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800450 // if viewframe left and top coordinates are non zero value then exclude it
451 // during the computation of xRatio and yRatio
452 xRatio = (inPos.x - viewFrame.left)/actualWidth;
453 yRatio = (inPos.y - viewFrame.top)/actualHeight;
454 // Use viewframe width and height to compute wRatio and hRatio.
Tatenda Chipeperekwa7dfeecf2014-01-23 17:51:16 -0800455 wRatio = (float)inPos.w/(float)(viewFrame.right - viewFrame.left);
456 hRatio = (float)inPos.h/(float)(viewFrame.bottom - viewFrame.top);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800457
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700458
459 //Calculate the position...
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700460 outPos.x = (xRatio * width) + xPos;
461 outPos.y = (yRatio * height) + yPos;
462 outPos.w = wRatio * width;
463 outPos.h = hRatio * height;
464 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
465 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
466 outPos.w, outPos.h);
467
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700468 // For sidesync, the dest fb will be in portrait orientation, and the crop
469 // will be updated to avoid the black side bands, and it will be upscaled
470 // to fit the dest RB, so recalculate
471 // the position based on the new width and height
472 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
473 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800474 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700475 //Calculate the position
476 xRatio = (outPos.x - xPos)/width;
477 // GetaspectRatio -- tricky to get the correct aspect ratio
478 // But we need to do this.
479 getAspectRatioPosition(width, height, width, height, r);
480 xPos = r.left;
481 yPos = r.top;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700482 float tempHeight = r.bottom - r.top;
483 yRatio = yPos/height;
484 wRatio = outPos.w/width;
485 hRatio = tempHeight/height;
486
487 //Map the coordinates back to Framebuffer domain
488 outPos.x = (xRatio * fbWidth);
489 outPos.y = (yRatio * fbHeight);
490 outPos.w = wRatio * fbWidth;
491 outPos.h = hRatio * fbHeight;
492
493 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
494 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
495 outPos.x, outPos.y,
496 outPos.w, outPos.h);
497 }
498 if(ctx->dpyAttr[dpy].mDownScaleMode) {
499 int extW, extH;
500 if(dpy == HWC_DISPLAY_EXTERNAL)
501 ctx->mExtDisplay->getAttributes(extW, extH);
502 else
503 ctx->mVirtualDisplay->getAttributes(extW, extH);
504 fbWidth = ctx->dpyAttr[dpy].xres;
505 fbHeight = ctx->dpyAttr[dpy].yres;
506 //Calculate the position...
507 xRatio = outPos.x/fbWidth;
508 yRatio = outPos.y/fbHeight;
509 wRatio = outPos.w/fbWidth;
510 hRatio = outPos.h/fbHeight;
511
512 outPos.x = xRatio * extW;
513 outPos.y = yRatio * extH;
514 outPos.w = wRatio * extW;
515 outPos.h = hRatio * extH;
516 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700517 // Convert Dim to hwc_rect_t
518 outRect.left = outPos.x;
519 outRect.top = outPos.y;
520 outRect.right = outPos.x + outPos.w;
521 outRect.bottom = outPos.y + outPos.h;
522
523 return;
524}
525
526bool isPrimaryPortrait(hwc_context_t *ctx) {
527 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
528 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
529 if(fbWidth < fbHeight) {
530 return true;
531 }
532 return false;
533}
534
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700535bool isOrientationPortrait(hwc_context_t *ctx) {
536 if(isPrimaryPortrait(ctx)) {
537 return !(ctx->deviceOrientation & 0x1);
538 }
539 return (ctx->deviceOrientation & 0x1);
540}
541
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700542void calcExtDisplayPosition(hwc_context_t *ctx,
543 private_handle_t *hnd,
544 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700545 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700546 hwc_rect_t& displayFrame,
547 int& transform,
548 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700549 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700550 int extOrient = getExtOrientation(ctx);
551 if(dpy && !qdutils::MDPVersion::getInstance().is8x26()) {
552 if(!isYuvBuffer(hnd)) {
553 if(extOrient & HWC_TRANSFORM_ROT_90) {
554 int dstWidth = ctx->dpyAttr[dpy].xres;
555 int dstHeight = ctx->dpyAttr[dpy].yres;;
556 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
557 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
558 if(!isPrimaryPortrait(ctx)) {
559 swap(srcWidth, srcHeight);
560 } // Get Aspect Ratio for external
561 getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
562 srcHeight, displayFrame);
563 // Crop - this is needed, because for sidesync, the dest fb will
564 // be in portrait orientation, so update the crop to not show the
565 // black side bands.
566 if (isOrientationPortrait(ctx)) {
567 sourceCrop = displayFrame;
568 displayFrame.left = 0;
569 displayFrame.top = 0;
570 displayFrame.right = dstWidth;
571 displayFrame.bottom = dstHeight;
572 }
573 }
574 if(ctx->dpyAttr[dpy].mDownScaleMode) {
575 int extW, extH;
576 // if downscale is enabled, map the co-ordinates to new
577 // domain(downscaled)
578 float fbWidth = ctx->dpyAttr[dpy].xres;
579 float fbHeight = ctx->dpyAttr[dpy].yres;
580 // query MDP configured attributes
581 if(dpy == HWC_DISPLAY_EXTERNAL)
582 ctx->mExtDisplay->getAttributes(extW, extH);
583 else
584 ctx->mVirtualDisplay->getAttributes(extW, extH);
585 //Calculate the ratio...
586 float wRatio = ((float)extW)/fbWidth;
587 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700588
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700589 //convert Dim to hwc_rect_t
590 displayFrame.left *= wRatio;
591 displayFrame.top *= hRatio;
592 displayFrame.right *= wRatio;
593 displayFrame.bottom *= hRatio;
594 }
595 }else {
596 if(extOrient || ctx->dpyAttr[dpy].mDownScaleMode) {
597 getAspectRatioPosition(ctx, dpy, extOrient,
598 displayFrame, displayFrame);
599 }
600 }
601 // If there is a external orientation set, use that
602 if(extOrient) {
603 transform = extOrient;
604 orient = static_cast<ovutils::eTransform >(extOrient);
605 }
606 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
607 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700608 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700609}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700610
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700611/* Returns the orientation which needs to be set on External for
612 * SideSync/Buffer Mirrormode
613 */
614int getMirrorModeOrientation(hwc_context_t *ctx) {
615 int extOrientation = 0;
616 int deviceOrientation = ctx->deviceOrientation;
617 if(!isPrimaryPortrait(ctx))
618 deviceOrientation = (deviceOrientation + 1) % 4;
619 if (deviceOrientation == 0)
620 extOrientation = HWC_TRANSFORM_ROT_270;
621 else if (deviceOrientation == 1)//90
622 extOrientation = 0;
623 else if (deviceOrientation == 2)//180
624 extOrientation = HWC_TRANSFORM_ROT_90;
625 else if (deviceOrientation == 3)//270
626 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
627
628 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700629}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700630
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530631bool isDownscaleRequired(hwc_layer_1_t const* layer) {
632 hwc_rect_t displayFrame = layer->displayFrame;
633 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
634 int dst_w, dst_h, src_w, src_h;
635 dst_w = displayFrame.right - displayFrame.left;
636 dst_h = displayFrame.bottom - displayFrame.top;
637 src_w = sourceCrop.right - sourceCrop.left;
638 src_h = sourceCrop.bottom - sourceCrop.top;
639
640 if(((src_w > dst_w) || (src_h > dst_h)))
641 return true;
642
643 return false;
644}
645bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500646 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500647 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700648 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500649
650 dst_w = displayFrame.right - displayFrame.left;
651 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500652 src_w = sourceCrop.right - sourceCrop.left;
653 src_h = sourceCrop.bottom - sourceCrop.top;
654
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800655 if(((src_w != dst_w) || (src_h != dst_h)))
656 return true;
657
658 return false;
659}
660
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700661// Checks if layer needs scaling with split
662bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
663 const int& dpy) {
664
665 int src_width_l, src_height_l;
666 int src_width_r, src_height_r;
667 int dst_width_l, dst_height_l;
668 int dst_width_r, dst_height_r;
669 int hw_w = ctx->dpyAttr[dpy].xres;
670 int hw_h = ctx->dpyAttr[dpy].yres;
671 hwc_rect_t cropL, dstL, cropR, dstR;
672 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700673 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700674 hwc_rect_t displayFrame = layer->displayFrame;
675 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700676
677 cropL = sourceCrop;
678 dstL = displayFrame;
679 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800680 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700681 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
682
683 cropR = sourceCrop;
684 dstR = displayFrame;
685 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800686 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700687 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
688
689 // Sanitize Crop to stitch
690 sanitizeSourceCrop(cropL, cropR, hnd);
691
692 // Calculate the left dst
693 dst_width_l = dstL.right - dstL.left;
694 dst_height_l = dstL.bottom - dstL.top;
695 src_width_l = cropL.right - cropL.left;
696 src_height_l = cropL.bottom - cropL.top;
697
698 // check if there is any scaling on the left
699 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
700 return true;
701
702 // Calculate the right dst
703 dst_width_r = dstR.right - dstR.left;
704 dst_height_r = dstR.bottom - dstR.top;
705 src_width_r = cropR.right - cropR.left;
706 src_height_r = cropR.bottom - cropR.top;
707
708 // check if there is any scaling on the right
709 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
710 return true;
711
712 return false;
713}
714
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530715bool isAlphaScaled(hwc_layer_1_t const* layer) {
716 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530717 return true;
718 }
719 return false;
720}
721
722bool isAlphaPresent(hwc_layer_1_t const* layer) {
723 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400724 if(hnd) {
725 int format = hnd->format;
726 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530727 case HAL_PIXEL_FORMAT_RGBA_8888:
728 case HAL_PIXEL_FORMAT_BGRA_8888:
729 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500730 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530731 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400732 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500733 }
734 return false;
735}
736
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700737static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
738 hwc_rect_t& crop, hwc_rect_t& dst) {
739 int hw_w = ctx->dpyAttr[dpy].xres;
740 int hw_h = ctx->dpyAttr[dpy].yres;
741 if(dst.left < 0 || dst.top < 0 ||
742 dst.right > hw_w || dst.bottom > hw_h) {
743 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800744 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700745 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
746 }
747}
748
749static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
750 const int& dpy) {
751 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
752 hwc_layer_1_t *layer = &list->hwLayers[i];
753 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700754 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
755 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700756 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700757 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700758 (hwc_rect_t&)crop,
759 (hwc_rect_t&)list->hwLayers[i].displayFrame);
760 layer->sourceCropf.left = crop.left;
761 layer->sourceCropf.right = crop.right;
762 layer->sourceCropf.top = crop.top;
763 layer->sourceCropf.bottom = crop.bottom;
764 }
765}
766
Ramkumar Radhakrishnan773e1882014-02-03 18:12:29 -0800767hwc_rect_t calculateDisplayViewFrame(hwc_context_t *ctx, int dpy) {
768 int dstWidth = ctx->dpyAttr[dpy].xres;
769 int dstHeight = ctx->dpyAttr[dpy].yres;
770 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
771 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
772 // default we assume viewframe as a full frame for primary display
773 hwc_rect outRect = {0, 0, dstWidth, dstHeight};
774 if(dpy) {
775 // swap srcWidth and srcHeight, if the device orientation is 90 or 270.
776 if(ctx->deviceOrientation & 0x1) {
777 swap(srcWidth, srcHeight);
778 }
779 // Get Aspect Ratio for external
780 getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
781 srcHeight, outRect);
782 }
783 ALOGD_IF(HWC_UTILS_DEBUG, "%s: view frame for dpy %d is [%d %d %d %d]",
784 __FUNCTION__, dpy, outRect.left, outRect.top,
785 outRect.right, outRect.bottom);
786 return outRect;
787}
788
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700789void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700790 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700791 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
792 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700793 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
794 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700795 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530796 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700797 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800798 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400799 char property[PROPERTY_VALUE_MAX];
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800800 ctx->listStats[dpy].extOnlyLayerIndex = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700801 ctx->listStats[dpy].isDisplayAnimating = false;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700802 ctx->listStats[dpy].roi = ovutils::Dim(0, 0,
803 (int)ctx->dpyAttr[dpy].xres, (int)ctx->dpyAttr[dpy].yres);
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700804 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +0530805 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnandd38b822013-12-04 15:15:42 -0800806 ctx->mViewFrame[dpy] = (hwc_rect_t){0, 0, 0, 0};
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800807 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700808
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700809 trimList(ctx, list, dpy);
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800810 optimizeLayerRects(list);
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +0530811
Ramkumar Radhakrishnan773e1882014-02-03 18:12:29 -0800812 // Calculate view frame of ext display from primary resolution
813 // and primary device orientation.
814 ctx->mViewFrame[dpy] = calculateDisplayViewFrame(ctx, dpy);
815
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700816 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500817 hwc_layer_1_t const* layer = &list->hwLayers[i];
818 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700819
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700820#ifdef QCOM_BSP
821 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
822 ctx->listStats[dpy].isDisplayAnimating = true;
823 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700824 if(isSecureDisplayBuffer(hnd)) {
825 ctx->listStats[dpy].secureUI = true;
826 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700827#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700828 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
829 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700830 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800831
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700832 //reset yuv indices
833 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530834 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700835
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700836 if (isSecureBuffer(hnd)) {
837 ctx->listStats[dpy].isSecurePresent = true;
838 }
839
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700840 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700841 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700842 }
843
844 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800845 int& yuvCount = ctx->listStats[dpy].yuvCount;
846 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
847 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800848
radhakrishnac9a67412013-09-25 17:40:42 +0530849 if(UNLIKELY(is4kx2kYuvBuffer(hnd))){
850 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
851 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = i;
852 yuv4k2kCount++;
853 }
854
Saurabh Shahe2474082013-05-15 16:32:13 -0700855 if((layer->transform & HWC_TRANSFORM_ROT_90) &&
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700856 canUseRotator(ctx, dpy)) {
857 if( (dpy == HWC_DISPLAY_PRIMARY) &&
858 ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700859 ctx->isPaddingRound = true;
860 }
Saurabh Shah85234ec2013-04-12 17:09:00 -0700861 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
862 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700863 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530864 if(layer->blending == HWC_BLENDING_PREMULT)
865 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -0800866
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800867
868 if(UNLIKELY(isExtOnly(hnd))){
869 ctx->listStats[dpy].extOnlyLayerIndex = i;
870 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700871 }
Ping Li9404e2a2013-04-24 16:36:03 -0400872 if(ctx->listStats[dpy].yuvCount > 0) {
873 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
874 if (atoi(property) != 1) {
875 property_set("hw.cabl.yuv", "1");
876 }
877 }
878 } else {
879 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
880 if (atoi(property) != 0) {
881 property_set("hw.cabl.yuv", "0");
882 }
883 }
884 }
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700885 if(dpy) {
886 //uncomment the below code for testing purpose.
887 /* char value[PROPERTY_VALUE_MAX];
888 property_get("sys.ext_orientation", value, "0");
889 // Assuming the orientation value is in terms of HAL_TRANSFORM,
890 // This needs mapping to HAL, if its in different convention
891 ctx->mExtOrientation = atoi(value); */
892 // Assuming the orientation value is in terms of HAL_TRANSFORM,
893 // This needs mapping to HAL, if its in different convention
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700894 if(ctx->mExtOrientation || ctx->mBufferMirrorMode) {
895 ALOGD_IF(HWC_UTILS_DEBUG, "%s: ext orientation = %d"
896 "BufferMirrorMode = %d", __FUNCTION__,
897 ctx->mExtOrientation, ctx->mBufferMirrorMode);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700898 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
899 ctx->isPaddingRound = true;
900 }
901 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
902 }
903 }
Saurabh Shahd4e65852013-06-17 11:33:53 -0700904
905 //The marking of video begin/end is useful on some targets where we need
906 //to have a padding round to be able to shift pipes across mixers.
907 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
908 ctx->mVideoTransFlag = true;
909 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530910
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700911 if(dpy == HWC_DISPLAY_PRIMARY) {
912 ctx->mAD->markDoable(ctx, list);
913 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700914}
915
Naseer Ahmed018e5452012-12-03 14:46:15 -0500916
Saurabh Shah68107422013-07-09 11:12:42 -0700917static void calc_cut(double& leftCutRatio, double& topCutRatio,
918 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700919 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700920 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700921 }
922 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700923 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700924 }
925 if(orient & HAL_TRANSFORM_ROT_90) {
926 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -0700927 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -0700928 leftCutRatio = topCutRatio;
929 topCutRatio = rightCutRatio;
930 rightCutRatio = bottomCutRatio;
931 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700932 }
933}
934
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800935bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500936 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
937 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
938 ctx->mSecuring) {
939 return true;
940 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800941 if (isSecureModePolicy(ctx->mMDP.version)) {
942 private_handle_t *hnd = (private_handle_t *)layer->handle;
943 if(ctx->mSecureMode) {
944 if (! isSecureBuffer(hnd)) {
945 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
946 __FUNCTION__);
947 return true;
948 }
949 } else {
950 if (isSecureBuffer(hnd)) {
951 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
952 __FUNCTION__);
953 return true;
954 }
955 }
956 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500957 return false;
958}
959
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800960bool isSecureModePolicy(int mdpVersion) {
961 if (mdpVersion < qdutils::MDSS_V5)
962 return true;
963 else
964 return false;
965}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500966
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800967// returns true if Action safe dimensions are set and target supports Actionsafe
968bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
969 // if external supports underscan, do nothing
970 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -0800971 // Disable Action safe for 8974 due to HW limitation for downscaling
972 // layers with overlapped region
973 // Disable Actionsafe for non HDMI displays.
974 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
975 qdutils::MDPVersion::getInstance().is8x74v2() ||
976 ctx->mExtDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800977 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -0800978 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800979
980 char value[PROPERTY_VALUE_MAX];
981 // Read action safe properties
982 property_get("persist.sys.actionsafe.width", value, "0");
983 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
984 property_get("persist.sys.actionsafe.height", value, "0");
985 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
986
987 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
988 //No action safe ratio set, return
989 return false;
990 }
991 return true;
992}
993
Naseer Ahmed522ce662013-03-18 20:14:05 -0400994int getBlending(int blending) {
995 switch(blending) {
996 case HWC_BLENDING_NONE:
997 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
998 case HWC_BLENDING_PREMULT:
999 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1000 case HWC_BLENDING_COVERAGE :
1001 default:
1002 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1003 }
1004}
1005
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001006//Crops source buffer against destination and FB boundaries
1007void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001008 const hwc_rect_t& scissor, int orient) {
1009
Saurabh Shah27c1d652012-08-14 19:30:28 -07001010 int& crop_l = crop.left;
1011 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001012 int& crop_r = crop.right;
1013 int& crop_b = crop.bottom;
1014 int crop_w = crop.right - crop.left;
1015 int crop_h = crop.bottom - crop.top;
1016
Saurabh Shah27c1d652012-08-14 19:30:28 -07001017 int& dst_l = dst.left;
1018 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001019 int& dst_r = dst.right;
1020 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001021 int dst_w = abs(dst.right - dst.left);
1022 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001023
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001024 const int& sci_l = scissor.left;
1025 const int& sci_t = scissor.top;
1026 const int& sci_r = scissor.right;
1027 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001028
Saurabh Shah68107422013-07-09 11:12:42 -07001029 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1030 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001031
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001032 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001033 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001034 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001035 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001036
1037 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001038 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001039 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001040 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001041
1042 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001043 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001044 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001045 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001046
1047 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001048 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001049 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001050 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001051
Saurabh Shah541b59d2012-10-11 11:08:12 -07001052 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301053 crop_l += (int)round((double)crop_w * leftCutRatio);
1054 crop_t += (int)round((double)crop_h * topCutRatio);
1055 crop_r -= (int)round((double)crop_w * rightCutRatio);
1056 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001057}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001058
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301059bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1060 const hwc_layer_1_t* layer2) {
1061 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1062 layer2->displayFrame);
1063 return isValidRect(irect);
1064}
1065
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001066bool isValidRect(const hwc_rect& rect)
1067{
1068 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301069}
1070
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001071/* computes the intersection of two rects */
1072hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1073{
1074 hwc_rect_t res;
1075
1076 if(!isValidRect(rect1) || !isValidRect(rect2)){
1077 return (hwc_rect_t){0, 0, 0, 0};
1078 }
1079
1080
1081 res.left = max(rect1.left, rect2.left);
1082 res.top = max(rect1.top, rect2.top);
1083 res.right = min(rect1.right, rect2.right);
1084 res.bottom = min(rect1.bottom, rect2.bottom);
1085
1086 if(!isValidRect(res))
1087 return (hwc_rect_t){0, 0, 0, 0};
1088
1089 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301090}
1091
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001092/* computes the union of two rects */
1093hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1094{
1095 hwc_rect_t res;
1096
1097 if(!isValidRect(rect1)){
1098 return rect2;
1099 }
1100
1101 if(!isValidRect(rect2)){
1102 return rect1;
1103 }
1104
1105 res.left = min(rect1.left, rect2.left);
1106 res.top = min(rect1.top, rect2.top);
1107 res.right = max(rect1.right, rect2.right);
1108 res.bottom = max(rect1.bottom, rect2.bottom);
1109
1110 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301111}
1112
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001113/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1114 * a single rect */
1115hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301116
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001117 hwc_rect_t res = rect1;
1118
1119 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1120 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1121 res.top = rect2.bottom;
1122 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1123 res.bottom = rect2.top;
1124 }
1125 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1126 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1127 res.left = rect2.right;
1128 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1129 res.right = rect2.left;
1130 }
1131 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301132}
1133
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001134void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301135 int i=list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301136 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301137 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001138 //If it is opaque see if we can substract this region from below
1139 //layers.
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301140 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1141 int j= i-1;
1142 hwc_rect_t& topframe =
1143 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1144 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301145 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001146 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1147 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001148 hwc_rect_t bottomCrop =
1149 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001150 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1151 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001152
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001153 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1154 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001155 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001156 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001157 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001158 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001159 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001160 //Update layer sourceCropf
1161 layer->sourceCropf.left = bottomCrop.left;
1162 layer->sourceCropf.top = bottomCrop.top;
1163 layer->sourceCropf.right = bottomCrop.right;
1164 layer->sourceCropf.bottom = bottomCrop.bottom;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001165 }
1166 }
1167 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301168 }
1169 }
1170 i--;
1171 }
1172}
1173
Naseer Ahmed64b81212013-02-14 10:29:47 -05001174void getNonWormholeRegion(hwc_display_contents_1_t* list,
1175 hwc_rect_t& nwr)
1176{
1177 uint32_t last = list->numHwLayers - 1;
1178 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1179 //Initiliaze nwr to first frame
1180 nwr.left = list->hwLayers[0].displayFrame.left;
1181 nwr.top = list->hwLayers[0].displayFrame.top;
1182 nwr.right = list->hwLayers[0].displayFrame.right;
1183 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1184
1185 for (uint32_t i = 1; i < last; i++) {
1186 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001187 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001188 }
1189
1190 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001191 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001192}
1193
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001194bool isExternalActive(hwc_context_t* ctx) {
1195 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001196}
1197
Saurabh Shah747af1e2013-02-26 10:25:12 -08001198void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001199 if(LIKELY(list)) {
1200 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1201 //Close the acquireFenceFds
1202 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1203 if(list->hwLayers[i].acquireFenceFd >= 0) {
1204 close(list->hwLayers[i].acquireFenceFd);
1205 list->hwLayers[i].acquireFenceFd = -1;
1206 }
1207 }
1208 //Writeback
1209 if(list->outbufAcquireFenceFd >= 0) {
1210 close(list->outbufAcquireFenceFd);
1211 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001212 }
1213 }
1214}
1215
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001216int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001217 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001218 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001219 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001220 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001221 int count = 0;
1222 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001223 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001224 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001225 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001226
1227 struct mdp_buf_sync data;
1228 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001229 data.acq_fen_fd = acquireFd;
1230 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001231 data.retire_fen_fd = &retireFd;
1232 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001233
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001234 char property[PROPERTY_VALUE_MAX];
1235 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1236 if(atoi(property) == 0)
1237 swapzero = true;
1238 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001239
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001240 bool isExtAnimating = false;
1241 if(dpy)
1242 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001243
Saurabh Shah23a813c2013-03-20 16:58:12 -07001244 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001245 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001246 int rotFd = ctx->mRotMgr->getRotDevFd();
1247 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001248 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1249 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1250 if((currRot == NULL) || (currLayer == NULL)) {
1251 continue;
1252 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001253 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001254 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001255 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001256 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001257 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001258 rotData.session_id = currRot->getSessId();
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001259 int ret = 0;
1260 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1261 if(ret < 0) {
1262 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1263 __FUNCTION__, strerror(errno));
1264 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001265 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001266 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001267 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001268 dup(rotReleaseFd);
1269 //A buffer is free to be used by producer as soon as its copied to
1270 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001271 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001272 rotReleaseFd;
1273 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001274 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001275
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301276 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001277 if(list->outbufAcquireFenceFd >= 0) {
1278 //Writeback output buffer
1279 acquireFd[count++] = list->outbufAcquireFenceFd;
1280 }
1281
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001282 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301283 if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001284 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001285 if(UNLIKELY(swapzero))
1286 acquireFd[count++] = -1;
1287 else
1288 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001289 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001290 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1291 if(UNLIKELY(swapzero))
1292 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001293 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001294 //set the acquireFD from fd - which is coming from c2d
1295 acquireFd[count++] = fd;
1296 // Buffer sync IOCTL should be async when using c2d fence is
1297 // used
1298 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001299 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001300 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1301 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001302 }
1303
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001304 data.acq_fen_fd_cnt = count;
1305 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001306
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001307 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001308 if(LIKELY(!swapzero)) {
1309 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001310 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001311 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
1312 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
1313 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001314
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001315 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001316 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1317 __FUNCTION__, strerror(errno));
1318 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
1319 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1320 dpy, list->numHwLayers);
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001321 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001322
Zohaib Alam1bb65612013-09-28 03:38:20 -04001323 LayerProp *layerProp = ctx->layerProp[dpy];
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001324 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001325 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Terence Hampsonc67b0372013-10-09 11:32:21 -04001326 list->hwLayers[i].compositionType == HWC_BLIT ||
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001327 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001328 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001329 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001330 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001331 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001332 // Release all the app layer fds immediately,
1333 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001334 list->hwLayers[i].releaseFenceFd = -1;
Zohaib Alam1bb65612013-09-28 03:38:20 -04001335 } else if(list->hwLayers[i].releaseFenceFd < 0 &&
1336 !(layerProp[i].mFlags & HWC_VPUCOMP)) {
1337 //If rotator has not already populated this field
1338 // & if it's a not VPU layer
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301339 if(list->hwLayers[i].compositionType == HWC_BLIT) {
1340 //For Blit, the app layers should be released when the Blit is
1341 //complete. This fd was passed from copybit->draw
1342 list->hwLayers[i].releaseFenceFd = dup(fd);
1343 } else {
1344 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1345 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001346 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001347 }
1348 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001349
1350 if(fd >= 0) {
1351 close(fd);
1352 fd = -1;
1353 }
1354
Naseer Ahmed64b81212013-02-14 10:29:47 -05001355 if (ctx->mCopyBit[dpy])
1356 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001357
Saurabh Shah23a813c2013-03-20 16:58:12 -07001358 //Signals when MDP finishes reading rotator buffers.
1359 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001360 close(releaseFd);
1361 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001362
Arun Kumar K.R51835182013-11-19 11:20:28 -08001363 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001364 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001365 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001366 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001367 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001368 return ret;
1369}
1370
Saurabh Shahacf10202013-02-26 10:15:15 -08001371void setMdpFlags(hwc_layer_1_t *layer,
1372 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001373 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001374 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001375 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001376
1377 if(layer->blending == HWC_BLENDING_PREMULT) {
1378 ovutils::setMdpFlags(mdpFlags,
1379 ovutils::OV_MDP_BLEND_FG_PREMULT);
1380 }
1381
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05001382 if (layer->flags & HWC_VPU_PIPE) {
1383 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_VPU_PIPE);
1384 }
1385
Saurabh Shahacf10202013-02-26 10:15:15 -08001386 if(isYuvBuffer(hnd)) {
1387 if(isSecureBuffer(hnd)) {
1388 ovutils::setMdpFlags(mdpFlags,
1389 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1390 }
Zohaib Alam1bb65612013-09-28 03:38:20 -04001391 // in mpq, deinterlacing is done in vpu
Saurabh Shahacf10202013-02-26 10:15:15 -08001392 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
Zohaib Alam1bb65612013-09-28 03:38:20 -04001393 metadata->interlaced &&
1394 (!qdutils::MDPVersion::getInstance().is8092())) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001395 ovutils::setMdpFlags(mdpFlags,
1396 ovutils::OV_MDP_DEINTERLACE);
1397 }
1398 //Pre-rotation will be used using rotator.
1399 if(transform & HWC_TRANSFORM_ROT_90) {
1400 ovutils::setMdpFlags(mdpFlags,
1401 ovutils::OV_MDP_SOURCE_ROTATED_90);
1402 }
1403 }
1404
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001405 if(isSecureDisplayBuffer(hnd)) {
1406 // Secure display needs both SECURE_OVERLAY and SECURE_DISPLAY_OV
1407 ovutils::setMdpFlags(mdpFlags,
1408 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1409 ovutils::setMdpFlags(mdpFlags,
1410 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1411 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001412 //No 90 component and no rot-downscale then flips done by MDP
1413 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001414 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1415 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001416 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1417 }
1418
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001419 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001420 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1421 }
1422 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001423
1424 if(metadata &&
1425 ((metadata->operation & PP_PARAM_HSIC)
1426 || (metadata->operation & PP_PARAM_IGC)
1427 || (metadata->operation & PP_PARAM_SHARP2))) {
1428 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1429 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001430}
1431
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301432int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001433 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001434 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001435
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301436 // Fix alignments for TILED format
1437 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1438 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1439 whf.w = utils::alignup(whf.w, 64);
1440 whf.h = utils::alignup(whf.h, 32);
1441 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001442 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001443
1444 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1445 qdutils::MDSS_V5) {
1446 uint32_t crop_w = (crop.right - crop.left);
1447 uint32_t crop_h = (crop.bottom - crop.top);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001448 if (ovutils::isYuv(whf.format)) {
1449 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
1450 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -07001451 // For interlaced, crop.h should be 4-aligned
1452 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
1453 crop_h = ovutils::aligndown(crop_h, 4);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001454 crop.right = crop.left + crop_w;
1455 crop.bottom = crop.top + crop_h;
1456 }
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001457 Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
1458 rot->setCrop(rotCrop);
1459 }
1460
Saurabh Shahacf10202013-02-26 10:15:15 -08001461 rot->setFlags(mdpFlags);
1462 rot->setTransform(orient);
1463 rot->setDownscale(downscale);
1464 if(!rot->commit()) return -1;
1465 return 0;
1466}
1467
Saurabh Shahe2474082013-05-15 16:32:13 -07001468int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001469 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001470 const hwc_rect_t& pos, const MetaData_t *metadata,
1471 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001472 ov->setSource(parg, dest);
1473 ov->setTransform(orient, dest);
1474
1475 int crop_w = crop.right - crop.left;
1476 int crop_h = crop.bottom - crop.top;
1477 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1478 ov->setCrop(dcrop, dest);
1479
1480 int posW = pos.right - pos.left;
1481 int posH = pos.bottom - pos.top;
1482 Dim position(pos.left, pos.top, posW, posH);
1483 ov->setPosition(position, dest);
1484
Saurabh Shah5daeee52013-01-23 16:52:26 +08001485 if (metadata)
1486 ov->setVisualParams(*metadata, dest);
1487
Saurabh Shahacf10202013-02-26 10:15:15 -08001488 if (!ov->commit(dest)) {
1489 return -1;
1490 }
1491 return 0;
1492}
1493
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001494int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1495 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1496 eIsFg& isFg, const eDest& dest) {
1497
1498 hwc_rect_t dst = layer->displayFrame;
1499 trimLayer(ctx, dpy, 0, dst, dst);
1500
1501 int w = ctx->dpyAttr[dpy].xres;
1502 int h = ctx->dpyAttr[dpy].yres;
1503 int dst_w = dst.right - dst.left;
1504 int dst_h = dst.bottom - dst.top;
1505 uint32_t color = layer->transform;
1506 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1507
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001508 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001509 if (layer->blending == HWC_BLENDING_PREMULT)
1510 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1511
1512 PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(0),
1513 layer->planeAlpha,
1514 (ovutils::eBlending) getBlending(layer->blending));
1515
1516 // Configure MDP pipe for Color layer
1517 Dim pos(dst.left, dst.top, dst_w, dst_h);
1518 ctx->mOverlay->setSource(parg, dest);
1519 ctx->mOverlay->setColor(color, dest);
1520 ctx->mOverlay->setTransform(0, dest);
1521 ctx->mOverlay->setCrop(pos, dest);
1522 ctx->mOverlay->setPosition(pos, dest);
1523
1524 if (!ctx->mOverlay->commit(dest)) {
1525 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1526 return -1;
1527 }
1528 return 0;
1529}
1530
Saurabh Shahe2474082013-05-15 16:32:13 -07001531void updateSource(eTransform& orient, Whf& whf,
Saurabh Shahacf10202013-02-26 10:15:15 -08001532 hwc_rect_t& crop) {
1533 Dim srcCrop(crop.left, crop.top,
1534 crop.right - crop.left,
1535 crop.bottom - crop.top);
Saurabh Shah76fd6552013-03-14 14:45:38 -07001536 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
Saurabh Shahacf10202013-02-26 10:15:15 -08001537 preRotateSource(orient, whf, srcCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001538 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1539 qdutils::MDSS_V5) {
1540 // Source for overlay will be the cropped (and rotated)
1541 crop.left = 0;
1542 crop.top = 0;
1543 crop.right = srcCrop.w;
1544 crop.bottom = srcCrop.h;
1545 // Set width & height equal to sourceCrop w & h
1546 whf.w = srcCrop.w;
1547 whf.h = srcCrop.h;
1548 } else {
1549 crop.left = srcCrop.x;
1550 crop.top = srcCrop.y;
1551 crop.right = srcCrop.x + srcCrop.w;
1552 crop.bottom = srcCrop.y + srcCrop.h;
1553 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001554}
1555
Saurabh Shah88e4d272013-09-03 13:31:29 -07001556int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001557 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1558 eIsFg& isFg, const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001559
1560 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001561
Saurabh Shahacf10202013-02-26 10:15:15 -08001562 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001563 if (layer->flags & HWC_COLOR_FILL) {
1564 // Configure Color layer
1565 return configColorLayer(ctx, layer, dpy, mdpFlags, z, isFg, dest);
1566 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001567 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1568 return -1;
1569 }
1570
Saurabh Shah5daeee52013-01-23 16:52:26 +08001571 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1572
Saurabh Shah62e1d732013-09-17 10:44:05 -07001573 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001574 hwc_rect_t dst = layer->displayFrame;
1575 int transform = layer->transform;
1576 eTransform orient = static_cast<eTransform>(transform);
1577 int downscale = 0;
1578 int rotFlags = ovutils::ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001579 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1580 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04001581
1582#ifdef VPU_TARGET
1583 if(ctx->mVPUClient != NULL &&
1584 ctx->mVPUClient->supportedVPULayer(dpy, layer)) {
1585 whf.format = getMdpFormat(
1586 ctx->mVPUClient->getLayerFormat(dpy, layer));
1587 whf.w = ctx->mVPUClient->getWidth(dpy, layer);
1588 whf.h = ctx->mVPUClient->getHeight(dpy, layer);
1589 }
1590#endif
Saurabh Shahacf10202013-02-26 10:15:15 -08001591
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001592 // Handle R/B swap
1593 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1594 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1595 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1596 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1597 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1598 }
1599
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08001600 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -07001601
Saurabh Shahacf10202013-02-26 10:15:15 -08001602 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001603 ctx->mMDP.version < qdutils::MDSS_V5) {
1604 downscale = getDownscaleFactor(
1605 crop.right - crop.left,
1606 crop.bottom - crop.top,
1607 dst.right - dst.left,
1608 dst.bottom - dst.top);
Saurabh Shahacf10202013-02-26 10:15:15 -08001609 if(downscale) {
1610 rotFlags = ROT_DOWNSCALE_ENABLED;
1611 }
1612 }
1613
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001614 setMdpFlags(layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001615
1616 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
1617 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
1618 *rot = ctx->mRotMgr->getNext();
1619 if(*rot == NULL) return -1;
Tatenda Chipeperekwa88562702013-10-19 19:56:16 -07001620 if(!dpy)
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001621 BwcPM::setBwc(crop, dst, transform, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001622 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001623 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1624 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001625 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001626 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001627 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001628 whf.format = (*rot)->getDstFormat();
1629 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001630 rotFlags |= ovutils::ROT_PREROTATED;
1631 }
1632
Saurabh Shah76fd6552013-03-14 14:45:38 -07001633 //For the mdp, since either we are pre-rotating or MDP does flips
1634 orient = OVERLAY_TRANSFORM_0;
1635 transform = 0;
Naseer Ahmed522ce662013-03-18 20:14:05 -04001636 PipeArgs parg(mdpFlags, whf, z, isFg,
1637 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1638 (ovutils::eBlending) getBlending(layer->blending));
1639
Saurabh Shah5daeee52013-01-23 16:52:26 +08001640 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001641 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
1642 return -1;
1643 }
1644 return 0;
1645}
1646
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001647//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001648void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001649 private_handle_t *hnd) {
1650 if(cropL.right - cropL.left) {
1651 if(isYuvBuffer(hnd)) {
1652 //Always safe to even down left
1653 ovutils::even_floor(cropL.left);
1654 //If right is even, automatically width is even, since left is
1655 //already even
1656 ovutils::even_floor(cropL.right);
1657 }
1658 //Make sure there are no gaps between left and right splits if the layer
1659 //is spread across BOTH halves
1660 if(cropR.right - cropR.left) {
1661 cropR.left = cropL.right;
1662 }
1663 }
1664
1665 if(cropR.right - cropR.left) {
1666 if(isYuvBuffer(hnd)) {
1667 //Always safe to even down left
1668 ovutils::even_floor(cropR.left);
1669 //If right is even, automatically width is even, since left is
1670 //already even
1671 ovutils::even_floor(cropR.right);
1672 }
1673 }
1674}
1675
Saurabh Shah88e4d272013-09-03 13:31:29 -07001676int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001677 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1678 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001679 Rotator **rot) {
1680 private_handle_t *hnd = (private_handle_t *)layer->handle;
1681 if(!hnd) {
1682 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1683 return -1;
1684 }
1685
Saurabh Shah5daeee52013-01-23 16:52:26 +08001686 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1687
Saurabh Shahacf10202013-02-26 10:15:15 -08001688 int hw_w = ctx->dpyAttr[dpy].xres;
1689 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07001690 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001691 hwc_rect_t dst = layer->displayFrame;
1692 int transform = layer->transform;
1693 eTransform orient = static_cast<eTransform>(transform);
1694 const int downscale = 0;
1695 int rotFlags = ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001696 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1697 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04001698
1699#ifdef VPU_TARGET
1700 if(ctx->mVPUClient != NULL &&
1701 ctx->mVPUClient->supportedVPULayer(dpy, layer)) {
1702 whf.format = getMdpFormat(
1703 ctx->mVPUClient->getLayerFormat(dpy, layer));
1704 whf.w = ctx->mVPUClient->getWidth(dpy, layer);
1705 whf.h = ctx->mVPUClient->getHeight(dpy, layer);
1706 }
1707#endif
Saurabh Shahacf10202013-02-26 10:15:15 -08001708
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001709 // Handle R/B swap
1710 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1711 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1712 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1713 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1714 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1715 }
1716
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001717 /* Calculate the external display position based on MDP downscale,
1718 ActionSafe, and extorientation features. */
1719 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
1720
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -07001721 setMdpFlags(layer, mdpFlagsL, 0, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001722
1723 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1724 //Enable overfetch
1725 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1726 }
1727
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001728 //Will do something only if feature enabled and conditions suitable
1729 //hollow call otherwise
1730 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
1731 overlay::Writeback *wb = overlay::Writeback::getInstance();
1732 whf.format = wb->getOutputFormat();
1733 }
1734
Saurabh Shahacf10202013-02-26 10:15:15 -08001735 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1736 (*rot) = ctx->mRotMgr->getNext();
1737 if((*rot) == NULL) return -1;
1738 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001739 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1740 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001741 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001742 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001743 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 whf.format = (*rot)->getDstFormat();
1745 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001746 rotFlags |= ROT_PREROTATED;
1747 }
1748
1749 eMdpFlags mdpFlagsR = mdpFlagsL;
1750 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1751
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001752 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1753 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08001754
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001755 const int lSplit = getLeftSplit(ctx, dpy);
1756
Saurabh Shahacf10202013-02-26 10:15:15 -08001757 if(lDest != OV_INVALID) {
1758 tmp_cropL = crop;
1759 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001760 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001761 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001762 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1763 }
1764 if(rDest != OV_INVALID) {
1765 tmp_cropR = crop;
1766 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001767 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001768 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001769 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1770 }
1771
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001772 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1773
Saurabh Shah94d62362013-07-02 10:58:48 -07001774 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08001775 //Not needed if the layer is confined to one half of the screen.
1776 //If rotator has been used then it has also done the flips, so ignore them.
Saurabh Shah94d62362013-07-02 10:58:48 -07001777 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
Ramkumar Radhakrishnanfe7ce802013-04-30 11:19:17 -07001778 && rDest != OV_INVALID && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001779 hwc_rect_t new_cropR;
1780 new_cropR.left = tmp_cropL.left;
1781 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1782
1783 hwc_rect_t new_cropL;
1784 new_cropL.left = new_cropR.right;
1785 new_cropL.right = tmp_cropR.right;
1786
1787 tmp_cropL.left = new_cropL.left;
1788 tmp_cropL.right = new_cropL.right;
1789
1790 tmp_cropR.left = new_cropR.left;
1791 tmp_cropR.right = new_cropR.right;
1792
1793 }
1794
Saurabh Shah76fd6552013-03-14 14:45:38 -07001795 //For the mdp, since either we are pre-rotating or MDP does flips
1796 orient = OVERLAY_TRANSFORM_0;
1797 transform = 0;
1798
Saurabh Shahacf10202013-02-26 10:15:15 -08001799 //configure left mixer
1800 if(lDest != OV_INVALID) {
1801 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001802 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1803 (ovutils::eBlending) getBlending(layer->blending));
1804
Saurabh Shahacf10202013-02-26 10:15:15 -08001805 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001806 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001807 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1808 return -1;
1809 }
1810 }
1811
1812 //configure right mixer
1813 if(rDest != OV_INVALID) {
1814 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001815 static_cast<eRotFlags>(rotFlags),
1816 layer->planeAlpha,
1817 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07001818 tmp_dstR.right = tmp_dstR.right - lSplit;
1819 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001820 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001821 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001822 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1823 return -1;
1824 }
1825 }
1826
1827 return 0;
1828}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08001829
radhakrishnac9a67412013-09-25 17:40:42 +05301830int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
1831 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1832 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
1833 Rotator **rot) {
1834 private_handle_t *hnd = (private_handle_t *)layer->handle;
1835 if(!hnd) {
1836 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1837 return -1;
1838 }
1839
1840 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1841
radhakrishnac9a67412013-09-25 17:40:42 +05301842 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
1843 hwc_rect_t dst = layer->displayFrame;
1844 int transform = layer->transform;
1845 eTransform orient = static_cast<eTransform>(transform);
1846 const int downscale = 0;
1847 int rotFlags = ROT_FLAGS_NONE;
1848 //Splitting only YUV layer on primary panel needs different zorders
1849 //for both layers as both the layers are configured to single mixer
1850 eZorder lz = z;
1851 eZorder rz = (eZorder)(z + 1);
1852
1853 Whf whf(getWidth(hnd), getHeight(hnd),
1854 getMdpFormat(hnd->format), hnd->size);
1855
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08001856 /* Calculate the external display position based on MDP downscale,
1857 ActionSafe, and extorientation features. */
1858 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
1859
radhakrishnac9a67412013-09-25 17:40:42 +05301860 setMdpFlags(layer, mdpFlagsL, 0, transform);
1861 trimLayer(ctx, dpy, transform, crop, dst);
1862
1863 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1864 (*rot) = ctx->mRotMgr->getNext();
1865 if((*rot) == NULL) return -1;
1866 if(!dpy)
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001867 BwcPM::setBwc(crop, dst, transform, mdpFlagsL);
radhakrishnac9a67412013-09-25 17:40:42 +05301868 //Configure rotator for pre-rotation
1869 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1870 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05301871 return -1;
1872 }
1873 ctx->mLayerRotMap[dpy]->add(layer, *rot);
1874 whf.format = (*rot)->getDstFormat();
1875 updateSource(orient, whf, crop);
1876 rotFlags |= ROT_PREROTATED;
1877 }
1878
1879 eMdpFlags mdpFlagsR = mdpFlagsL;
1880 int lSplit = dst.left + (dst.right - dst.left)/2;
1881
1882 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1883 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
1884
1885 if(lDest != OV_INVALID) {
1886 tmp_cropL = crop;
1887 tmp_dstL = dst;
1888 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
1889 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1890 }
1891 if(rDest != OV_INVALID) {
1892 tmp_cropR = crop;
1893 tmp_dstR = dst;
1894 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
1895 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1896 }
1897
1898 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1899
1900 //When buffer is H-flipped, contents of mixer config also needs to swapped
1901 //Not needed if the layer is confined to one half of the screen.
1902 //If rotator has been used then it has also done the flips, so ignore them.
1903 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1904 && rDest != OV_INVALID && (*rot) == NULL) {
1905 hwc_rect_t new_cropR;
1906 new_cropR.left = tmp_cropL.left;
1907 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1908
1909 hwc_rect_t new_cropL;
1910 new_cropL.left = new_cropR.right;
1911 new_cropL.right = tmp_cropR.right;
1912
1913 tmp_cropL.left = new_cropL.left;
1914 tmp_cropL.right = new_cropL.right;
1915
1916 tmp_cropR.left = new_cropR.left;
1917 tmp_cropR.right = new_cropR.right;
1918
1919 }
1920
1921 //For the mdp, since either we are pre-rotating or MDP does flips
1922 orient = OVERLAY_TRANSFORM_0;
1923 transform = 0;
1924
1925 //configure left half
1926 if(lDest != OV_INVALID) {
1927 PipeArgs pargL(mdpFlagsL, whf, lz, isFg,
1928 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1929 (ovutils::eBlending) getBlending(layer->blending));
1930
1931 if(configMdp(ctx->mOverlay, pargL, orient,
1932 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1933 ALOGE("%s: commit failed for left half config", __FUNCTION__);
1934 return -1;
1935 }
1936 }
1937
1938 //configure right half
1939 if(rDest != OV_INVALID) {
1940 PipeArgs pargR(mdpFlagsR, whf, rz, isFg,
1941 static_cast<eRotFlags>(rotFlags),
1942 layer->planeAlpha,
1943 (ovutils::eBlending) getBlending(layer->blending));
1944 if(configMdp(ctx->mOverlay, pargR, orient,
1945 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1946 ALOGE("%s: commit failed for right half config", __FUNCTION__);
1947 return -1;
1948 }
1949 }
1950
1951 return 0;
1952}
1953
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001954bool canUseRotator(hwc_context_t *ctx, int dpy) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001955 if(qdutils::MDPVersion::getInstance().is8x26() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001956 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07001957 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamala8c065f2013-10-22 14:52:45 +05301958 /* 8x26 mdss driver supports multiplexing of DMA pipe
1959 * in LINE and BLOCK modes for writeback panels.
1960 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001961 if(dpy == HWC_DISPLAY_PRIMARY)
1962 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001963 }
Terence Hampson45c02ef2013-05-17 17:00:11 -04001964 if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1965 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001966 return true;
1967}
1968
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001969int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1970 //Default even split for all displays with high res
1971 int lSplit = ctx->dpyAttr[dpy].xres / 2;
1972 if(dpy == HWC_DISPLAY_PRIMARY &&
1973 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1974 //Override if split published by driver for primary
1975 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1976 }
1977 return lSplit;
1978}
Saurabh Shah1a03d482013-05-29 13:44:20 -07001979
Saurabh Shah88e4d272013-09-03 13:31:29 -07001980bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
1981 if(ctx->dpyAttr[dpy].xres > qdutils::MAX_DISPLAY_DIM) {
1982 return true;
1983 }
1984 //For testing we could split primary via device tree values
1985 if(dpy == HWC_DISPLAY_PRIMARY &&
1986 qdutils::MDPVersion::getInstance().getRightSplit()) {
1987 return true;
1988 }
1989 return false;
1990}
1991
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001992//clear prev layer prop flags and realloc for current frame
1993void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
1994 if(ctx->layerProp[dpy]) {
1995 delete[] ctx->layerProp[dpy];
1996 ctx->layerProp[dpy] = NULL;
1997 }
1998 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
1999}
2000
Raj Kamal52b4fdb2014-01-27 19:35:13 +05302001/* Since we fake non-Hybrid WFD solution as external display, this
2002 * function helps us in determining the priority between external
2003 * (hdmi/non-Hybrid WFD display) and virtual display devices(SSD/
2004 * screenrecord). This can be removed once wfd-client migrates to
2005 * using virtual-display api's.
2006 */
2007bool canUseMDPforVirtualDisplay(hwc_context_t* ctx,
2008 const hwc_display_contents_1_t *list) {
2009
2010 /* We rely on the fact that for pure virtual display solution
2011 * list->outbuf will be a non-NULL handle.
2012 *
2013 * If there are three active displays (which means there is one
2014 * primary, one external and one virtual active display)
2015 * we give mdss/mdp hw resources(pipes,smp,etc) for external
2016 * display(hdmi/non-Hybrid WFD display) rather than for virtual
2017 * display(SSD/screenrecord)
2018 */
2019
2020 if(list->outbuf and (ctx->numActiveDisplays == HWC_NUM_DISPLAY_TYPES)) {
2021 return false;
2022 }
2023
2024 return true;
2025}
2026
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08002027void BwcPM::setBwc(const hwc_rect_t& crop,
Saurabh Shah1a03d482013-05-29 13:44:20 -07002028 const hwc_rect_t& dst, const int& transform,
2029 ovutils::eMdpFlags& mdpFlags) {
2030 //Target doesnt support Bwc
2031 if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
2032 return;
2033 }
2034 //src width > MAX mixer supported dim
2035 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
2036 return;
2037 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002038 //Decimation necessary, cannot use BWC. H/W requirement.
2039 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
2040 int src_w = crop.right - crop.left;
2041 int src_h = crop.bottom - crop.top;
2042 int dst_w = dst.right - dst.left;
2043 int dst_h = dst.bottom - dst.top;
2044 if(transform & HAL_TRANSFORM_ROT_90) {
2045 swap(src_w, src_h);
2046 }
2047 float horDscale = 0.0f;
2048 float verDscale = 0.0f;
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002049 int horzDeci = 0;
2050 int vertDeci = 0;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002051 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
2052 verDscale);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002053 //TODO Use log2f once math.h has it
2054 if((int)horDscale)
2055 horzDeci = (int)(log(horDscale) / log(2));
2056 if((int)verDscale)
2057 vertDeci = (int)(log(verDscale) / log(2));
2058 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002059 }
2060 //Property
2061 char value[PROPERTY_VALUE_MAX];
2062 property_get("debug.disable.bwc", value, "0");
2063 if(atoi(value)) return;
2064
2065 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2066}
2067
Saurabh Shah23a813c2013-03-20 16:58:12 -07002068void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
2069 if(mCount >= MAX_SESS) return;
2070 mLayer[mCount] = layer;
2071 mRot[mCount] = rot;
2072 mCount++;
2073}
2074
2075void LayerRotMap::reset() {
2076 for (int i = 0; i < MAX_SESS; i++) {
2077 mLayer[i] = 0;
2078 mRot[i] = 0;
2079 }
2080 mCount = 0;
2081}
2082
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002083void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002084 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002085 reset();
2086}
2087
Saurabh Shah23a813c2013-03-20 16:58:12 -07002088void LayerRotMap::setReleaseFd(const int& fence) {
2089 for(uint32_t i = 0; i < mCount; i++) {
2090 mRot[i]->setReleaseFd(dup(fence));
2091 }
2092}
2093
Saurabh Shahacf10202013-02-26 10:15:15 -08002094};//namespace qhwc