blob: a36a9448c163d14be53711baaa728b8ec2c69a41 [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08003 * Copyright (C) 2012-2013, The Linux Foundation All rights reserved.
4 *
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"
Saurabh Shah86c17292013-02-08 15:24:13 -080046
47using namespace qClient;
48using namespace qService;
49using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080050using namespace overlay;
51using namespace overlay::utils;
52namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080053
Naseer Ahmed29a26812012-06-14 00:56:20 -070054namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070055
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080056static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -070057{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080058 struct fb_fix_screeninfo finfo;
59 struct fb_var_screeninfo info;
60
61 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053062 if(fb_fd < 0) {
63 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080064 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053065 }
66
67 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
68 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
69 strerror(errno));
70 close(fb_fd);
71 return -errno;
72 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080073
74 if (int(info.width) <= 0 || int(info.height) <= 0) {
75 // the driver doesn't return that information
76 // default to 160 dpi
77 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
78 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -070079 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080080
81 float xdpi = (info.xres * 25.4f) / info.width;
82 float ydpi = (info.yres * 25.4f) / info.height;
83
84#ifdef MSMFB_METADATA_GET
85 struct msmfb_metadata metadata;
86 memset(&metadata, 0 , sizeof(metadata));
87 metadata.op = metadata_op_frame_rate;
88
89 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053090 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
91 strerror(errno));
92 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080093 return -errno;
94 }
95
96 float fps = metadata.data.panel_frame_rate;
97#else
98 //XXX: Remove reserved field usage on all baselines
99 //The reserved[3] field is used to store FPS by the driver.
100 float fps = info.reserved[3] & 0xFF;
101#endif
102
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530103 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
104 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
105 strerror(errno));
106 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800107 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530108 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800109
110 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
111 //xres, yres may not be 32 aligned
112 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
113 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
114 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
115 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
116 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
117 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
118
Naseer Ahmed22616d92013-05-15 17:20:26 -0400119 //Unblank primary on first boot
120 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
121 ALOGE("%s: Failed to unblank display", __FUNCTION__);
122 return -errno;
123 }
124 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
125
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800126 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700127}
128
Naseer Ahmed29a26812012-06-14 00:56:20 -0700129void initContext(hwc_context_t *ctx)
130{
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700131 openFramebufferDevice(ctx);
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700132 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
133 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
134 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800135 overlay::Overlay::initOverlay();
136 ctx->mOverlay = overlay::Overlay::getInstance();
137 ctx->mRotMgr = new RotMgr();
138
Saurabh Shahcf053c62012-12-13 12:32:55 -0800139 //Is created and destroyed only once for primary
140 //For external it could get created and destroyed multiple times depending
141 //on what external we connect to.
142 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700143 IFBUpdate::getObject(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800144
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800145 // Check if the target supports copybit compostion (dyn/mdp/c2d) to
146 // decide if we need to open the copybit module.
147 int compositionType =
148 qdutils::QCCompositionType::getInstance().getCompositionType();
149
150 if (compositionType & (qdutils::COMPOSITION_TYPE_DYN |
151 qdutils::COMPOSITION_TYPE_MDP |
152 qdutils::COMPOSITION_TYPE_C2D)) {
Saurabh Shah220a30c2013-10-29 16:12:12 -0700153 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
154 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800155 }
156
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700157 ctx->mExtDisplay = new ExternalDisplay(ctx);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700158 ctx->mVirtualDisplay = new VirtualDisplay(ctx);
159 ctx->mVirtualonExtActive = false;
160 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
161 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
162 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
163 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700164 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mDownScaleMode= false;
165 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mDownScaleMode = false;
166 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800167
168 ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700169 MDPComp::getObject(ctx, HWC_DISPLAY_PRIMARY);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700170 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800171
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700172 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700173 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700174 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700175 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700176 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700177
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500178 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700179 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700180
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400181 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500182 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700183 ctx->mExtOrientation = 0;
Saurabh Shah86c17292013-02-08 15:24:13 -0800184
185 //Right now hwc starts the service but anybody could do it, or it could be
186 //independent process as well.
187 QService::init();
188 sp<IQClient> client = new QClient(ctx);
189 interface_cast<IQService>(
190 defaultServiceManager()->getService(
191 String16("display.qservice")))->connect(client);
192
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700193 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700194 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700195 ctx->mBufferMirrorMode = false;
Naseer Ahmed58780b92013-07-29 17:41:40 -0400196#ifdef VPU_TARGET
197 ctx->mVPUClient = new VPUClient();
198#endif
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700199
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700200 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700201 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700202}
203
204void closeContext(hwc_context_t *ctx)
205{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500206 if(ctx->mOverlay) {
207 delete ctx->mOverlay;
208 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700209 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700210
Saurabh Shahacf10202013-02-26 10:15:15 -0800211 if(ctx->mRotMgr) {
212 delete ctx->mRotMgr;
213 ctx->mRotMgr = NULL;
214 }
215
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700216 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800217 if(ctx->mCopyBit[i]) {
218 delete ctx->mCopyBit[i];
219 ctx->mCopyBit[i] = NULL;
220 }
221 }
222
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800223 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700224 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
225 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700226 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700227
228 if(ctx->mExtDisplay) {
229 delete ctx->mExtDisplay;
230 ctx->mExtDisplay = NULL;
231 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400232
Naseer Ahmed58780b92013-07-29 17:41:40 -0400233#ifdef VPU_TARGET
234 if(ctx->mVPUClient) {
235 delete ctx->mVPUClient;
236 }
237#endif
238
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700239 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800240 if(ctx->mFBUpdate[i]) {
241 delete ctx->mFBUpdate[i];
242 ctx->mFBUpdate[i] = NULL;
243 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800244 if(ctx->mMDPComp[i]) {
245 delete ctx->mMDPComp[i];
246 ctx->mMDPComp[i] = NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800247 }
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700248 if(ctx->mHwcDebug[i]) {
249 delete ctx->mHwcDebug[i];
250 ctx->mHwcDebug[i] = NULL;
251 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700252 if(ctx->mLayerRotMap[i]) {
253 delete ctx->mLayerRotMap[i];
254 ctx->mLayerRotMap[i] = NULL;
255 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800256 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700257 if(ctx->mAD) {
258 delete ctx->mAD;
259 ctx->mAD = NULL;
260 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800261
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800262
Naseer Ahmed29a26812012-06-14 00:56:20 -0700263}
264
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500265
266void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700267{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500268 va_list varargs;
269 va_start(varargs, fmt);
270 buf.appendFormatV(fmt, varargs);
271 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700272}
273
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700274int getExtOrientation(hwc_context_t* ctx) {
275 int extOrient = ctx->mExtOrientation;
276 if(ctx->mBufferMirrorMode)
277 extOrient = getMirrorModeOrientation(ctx);
278 return extOrient;
279}
280
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800281/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700282void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
283 // Position
284 int x = rect.left, y = rect.top;
285 int w = rect.right - rect.left;
286 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800287
288 // if external supports underscan, do nothing
289 // it will be taken care in the driver
290 if(ctx->mExtDisplay->isCEUnderscanSupported())
291 return;
292
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700293 char value[PROPERTY_VALUE_MAX];
294 // Read action safe properties
295 property_get("persist.sys.actionsafe.width", value, "0");
296 int asWidthRatio = atoi(value);
297 property_get("persist.sys.actionsafe.height", value, "0");
298 int asHeightRatio = atoi(value);
299
300 if(!asWidthRatio && !asHeightRatio) {
301 //No action safe ratio set, return
302 return;
303 }
304
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800305 float wRatio = 1.0;
306 float hRatio = 1.0;
307 float xRatio = 1.0;
308 float yRatio = 1.0;
309
310 float fbWidth = ctx->dpyAttr[dpy].xres;
311 float fbHeight = ctx->dpyAttr[dpy].yres;
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700312 if(ctx->dpyAttr[dpy].mDownScaleMode) {
313 // if downscale Mode is enabled for external, need to query
314 // the actual width and height, as that is the physical w & h
315 ctx->mExtDisplay->getAttributes((int&)fbWidth, (int&)fbHeight);
316 }
317
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800318
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700319 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700320 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700321
322 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700323 swap(fbWidth, fbHeight);
324
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800325 float asX = 0;
326 float asY = 0;
327 float asW = fbWidth;
328 float asH= fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800329
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800330 // based on the action safe ratio, get the Action safe rectangle
331 asW = fbWidth * (1.0f - asWidthRatio / 100.0f);
332 asH = fbHeight * (1.0f - asHeightRatio / 100.0f);
333 asX = (fbWidth - asW) / 2;
334 asY = (fbHeight - asH) / 2;
335
336 // calculate the position ratio
337 xRatio = (float)x/fbWidth;
338 yRatio = (float)y/fbHeight;
339 wRatio = (float)w/fbWidth;
340 hRatio = (float)h/fbHeight;
341
342 //Calculate the position...
343 x = (xRatio * asW) + asX;
344 y = (yRatio * asH) + asY;
345 w = (wRatio * asW);
346 h = (hRatio * asH);
347
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700348 // Convert it back to hwc_rect_t
349 rect.left = x;
350 rect.top = y;
351 rect.right = w + rect.left;
352 rect.bottom = h + rect.top;
353
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800354 return;
355}
356
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700357/* Calculates the aspect ratio for based on src & dest */
358void getAspectRatioPosition(int destWidth, int destHeight, int srcWidth,
359 int srcHeight, hwc_rect_t& rect) {
360 int x =0, y =0;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700361
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700362 if (srcWidth * destHeight > destWidth * srcHeight) {
363 srcHeight = destWidth * srcHeight / srcWidth;
364 srcWidth = destWidth;
365 } else if (srcWidth * destHeight < destWidth * srcHeight) {
366 srcWidth = destHeight * srcWidth / srcHeight;
367 srcHeight = destHeight;
368 } else {
369 srcWidth = destWidth;
370 srcHeight = destHeight;
371 }
372 if (srcWidth > destWidth) srcWidth = destWidth;
373 if (srcHeight > destHeight) srcHeight = destHeight;
374 x = (destWidth - srcWidth) / 2;
375 y = (destHeight - srcHeight) / 2;
376 ALOGD_IF(HWC_UTILS_DEBUG, "%s: AS Position: x = %d, y = %d w = %d h = %d",
377 __FUNCTION__, x, y, srcWidth , srcHeight);
378 // Convert it back to hwc_rect_t
379 rect.left = x;
380 rect.top = y;
381 rect.right = srcWidth + rect.left;
382 rect.bottom = srcHeight + rect.top;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700383}
384
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700385// This function gets the destination position for Seconday display
386// based on the position and aspect ratio with orientation
387void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
388 hwc_rect_t& inRect, hwc_rect_t& outRect) {
389 // Physical display resolution
390 float fbWidth = ctx->dpyAttr[dpy].xres;
391 float fbHeight = ctx->dpyAttr[dpy].yres;
392 //display position(x,y,w,h) in correct aspectratio after rotation
393 int xPos = 0;
394 int yPos = 0;
395 float width = fbWidth;
396 float height = fbHeight;
397 // Width/Height used for calculation, after rotation
398 float actualWidth = fbWidth;
399 float actualHeight = fbHeight;
400
401 float wRatio = 1.0;
402 float hRatio = 1.0;
403 float xRatio = 1.0;
404 float yRatio = 1.0;
405 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
406
407 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
408 inRect.bottom - inRect.top);
409 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
410 outRect.bottom - outRect.top);
411
412 Whf whf(fbWidth, fbHeight, 0);
413 eTransform extorient = static_cast<eTransform>(extOrientation);
414 // To calculate the destination co-ordinates in the new orientation
415 preRotateSource(extorient, whf, inPos);
416
417 if(extOrientation & HAL_TRANSFORM_ROT_90) {
418 // Swap width/height for input position
419 swapWidthHeight(actualWidth, actualHeight);
420 getAspectRatioPosition(fbWidth, fbHeight, (int)actualWidth,
421 (int)actualHeight, rect);
422 xPos = rect.left;
423 yPos = rect.top;
424 width = rect.right - rect.left;
425 height = rect.bottom - rect.top;
426 }
427
428 //Calculate the position...
429 xRatio = inPos.x/actualWidth;
430 yRatio = inPos.y/actualHeight;
431 wRatio = inPos.w/actualWidth;
432 hRatio = inPos.h/actualHeight;
433
434 outPos.x = (xRatio * width) + xPos;
435 outPos.y = (yRatio * height) + yPos;
436 outPos.w = wRatio * width;
437 outPos.h = hRatio * height;
438 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
439 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
440 outPos.w, outPos.h);
441
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700442 // For sidesync, the dest fb will be in portrait orientation, and the crop
443 // will be updated to avoid the black side bands, and it will be upscaled
444 // to fit the dest RB, so recalculate
445 // the position based on the new width and height
446 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
447 isOrientationPortrait(ctx)) {
448 hwc_rect_t r;
449 //Calculate the position
450 xRatio = (outPos.x - xPos)/width;
451 // GetaspectRatio -- tricky to get the correct aspect ratio
452 // But we need to do this.
453 getAspectRatioPosition(width, height, width, height, r);
454 xPos = r.left;
455 yPos = r.top;
456 float tempWidth = r.right - r.left;
457 float tempHeight = r.bottom - r.top;
458 yRatio = yPos/height;
459 wRatio = outPos.w/width;
460 hRatio = tempHeight/height;
461
462 //Map the coordinates back to Framebuffer domain
463 outPos.x = (xRatio * fbWidth);
464 outPos.y = (yRatio * fbHeight);
465 outPos.w = wRatio * fbWidth;
466 outPos.h = hRatio * fbHeight;
467
468 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
469 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
470 outPos.x, outPos.y,
471 outPos.w, outPos.h);
472 }
473 if(ctx->dpyAttr[dpy].mDownScaleMode) {
474 int extW, extH;
475 if(dpy == HWC_DISPLAY_EXTERNAL)
476 ctx->mExtDisplay->getAttributes(extW, extH);
477 else
478 ctx->mVirtualDisplay->getAttributes(extW, extH);
479 fbWidth = ctx->dpyAttr[dpy].xres;
480 fbHeight = ctx->dpyAttr[dpy].yres;
481 //Calculate the position...
482 xRatio = outPos.x/fbWidth;
483 yRatio = outPos.y/fbHeight;
484 wRatio = outPos.w/fbWidth;
485 hRatio = outPos.h/fbHeight;
486
487 outPos.x = xRatio * extW;
488 outPos.y = yRatio * extH;
489 outPos.w = wRatio * extW;
490 outPos.h = hRatio * extH;
491 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700492 // Convert Dim to hwc_rect_t
493 outRect.left = outPos.x;
494 outRect.top = outPos.y;
495 outRect.right = outPos.x + outPos.w;
496 outRect.bottom = outPos.y + outPos.h;
497
498 return;
499}
500
501bool isPrimaryPortrait(hwc_context_t *ctx) {
502 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
503 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
504 if(fbWidth < fbHeight) {
505 return true;
506 }
507 return false;
508}
509
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700510bool isOrientationPortrait(hwc_context_t *ctx) {
511 if(isPrimaryPortrait(ctx)) {
512 return !(ctx->deviceOrientation & 0x1);
513 }
514 return (ctx->deviceOrientation & 0x1);
515}
516
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700517void calcExtDisplayPosition(hwc_context_t *ctx,
518 private_handle_t *hnd,
519 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700520 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700521 hwc_rect_t& displayFrame,
522 int& transform,
523 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700524 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700525 int extOrient = getExtOrientation(ctx);
526 if(dpy && !qdutils::MDPVersion::getInstance().is8x26()) {
527 if(!isYuvBuffer(hnd)) {
528 if(extOrient & HWC_TRANSFORM_ROT_90) {
529 int dstWidth = ctx->dpyAttr[dpy].xres;
530 int dstHeight = ctx->dpyAttr[dpy].yres;;
531 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
532 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
533 if(!isPrimaryPortrait(ctx)) {
534 swap(srcWidth, srcHeight);
535 } // Get Aspect Ratio for external
536 getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
537 srcHeight, displayFrame);
538 // Crop - this is needed, because for sidesync, the dest fb will
539 // be in portrait orientation, so update the crop to not show the
540 // black side bands.
541 if (isOrientationPortrait(ctx)) {
542 sourceCrop = displayFrame;
543 displayFrame.left = 0;
544 displayFrame.top = 0;
545 displayFrame.right = dstWidth;
546 displayFrame.bottom = dstHeight;
547 }
548 }
549 if(ctx->dpyAttr[dpy].mDownScaleMode) {
550 int extW, extH;
551 // if downscale is enabled, map the co-ordinates to new
552 // domain(downscaled)
553 float fbWidth = ctx->dpyAttr[dpy].xres;
554 float fbHeight = ctx->dpyAttr[dpy].yres;
555 // query MDP configured attributes
556 if(dpy == HWC_DISPLAY_EXTERNAL)
557 ctx->mExtDisplay->getAttributes(extW, extH);
558 else
559 ctx->mVirtualDisplay->getAttributes(extW, extH);
560 //Calculate the ratio...
561 float wRatio = ((float)extW)/fbWidth;
562 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700563
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700564 //convert Dim to hwc_rect_t
565 displayFrame.left *= wRatio;
566 displayFrame.top *= hRatio;
567 displayFrame.right *= wRatio;
568 displayFrame.bottom *= hRatio;
569 }
570 }else {
571 if(extOrient || ctx->dpyAttr[dpy].mDownScaleMode) {
572 getAspectRatioPosition(ctx, dpy, extOrient,
573 displayFrame, displayFrame);
574 }
575 }
576 // If there is a external orientation set, use that
577 if(extOrient) {
578 transform = extOrient;
579 orient = static_cast<ovutils::eTransform >(extOrient);
580 }
581 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
582 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700583 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700584}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700585
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700586/* Returns the orientation which needs to be set on External for
587 * SideSync/Buffer Mirrormode
588 */
589int getMirrorModeOrientation(hwc_context_t *ctx) {
590 int extOrientation = 0;
591 int deviceOrientation = ctx->deviceOrientation;
592 if(!isPrimaryPortrait(ctx))
593 deviceOrientation = (deviceOrientation + 1) % 4;
594 if (deviceOrientation == 0)
595 extOrientation = HWC_TRANSFORM_ROT_270;
596 else if (deviceOrientation == 1)//90
597 extOrientation = 0;
598 else if (deviceOrientation == 2)//180
599 extOrientation = HWC_TRANSFORM_ROT_90;
600 else if (deviceOrientation == 3)//270
601 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
602
603 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700604}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700605
Saurabh Shah8a117932013-05-23 12:48:13 -0700606bool needsScaling(hwc_context_t* ctx, hwc_layer_1_t const* layer,
607 const int& dpy) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500608 int dst_w, dst_h, src_w, src_h;
609
610 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700611 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500612
613 dst_w = displayFrame.right - displayFrame.left;
614 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500615 src_w = sourceCrop.right - sourceCrop.left;
616 src_h = sourceCrop.bottom - sourceCrop.top;
617
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800618 if(((src_w != dst_w) || (src_h != dst_h)))
619 return true;
620
621 return false;
622}
623
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700624// Checks if layer needs scaling with split
625bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
626 const int& dpy) {
627
628 int src_width_l, src_height_l;
629 int src_width_r, src_height_r;
630 int dst_width_l, dst_height_l;
631 int dst_width_r, dst_height_r;
632 int hw_w = ctx->dpyAttr[dpy].xres;
633 int hw_h = ctx->dpyAttr[dpy].yres;
634 hwc_rect_t cropL, dstL, cropR, dstR;
635 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700636 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700637 hwc_rect_t displayFrame = layer->displayFrame;
638 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700639
640 cropL = sourceCrop;
641 dstL = displayFrame;
642 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
643 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
644
645 cropR = sourceCrop;
646 dstR = displayFrame;
647 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
648 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
649
650 // Sanitize Crop to stitch
651 sanitizeSourceCrop(cropL, cropR, hnd);
652
653 // Calculate the left dst
654 dst_width_l = dstL.right - dstL.left;
655 dst_height_l = dstL.bottom - dstL.top;
656 src_width_l = cropL.right - cropL.left;
657 src_height_l = cropL.bottom - cropL.top;
658
659 // check if there is any scaling on the left
660 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
661 return true;
662
663 // Calculate the right dst
664 dst_width_r = dstR.right - dstR.left;
665 dst_height_r = dstR.bottom - dstR.top;
666 src_width_r = cropR.right - cropR.left;
667 src_height_r = cropR.bottom - cropR.top;
668
669 // check if there is any scaling on the right
670 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
671 return true;
672
673 return false;
674}
675
Saurabh Shah8a117932013-05-23 12:48:13 -0700676bool isAlphaScaled(hwc_context_t* ctx, hwc_layer_1_t const* layer,
677 const int& dpy) {
678 if(needsScaling(ctx, layer, dpy) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530679 return true;
680 }
681 return false;
682}
683
684bool isAlphaPresent(hwc_layer_1_t const* layer) {
685 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400686 if(hnd) {
687 int format = hnd->format;
688 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530689 case HAL_PIXEL_FORMAT_RGBA_8888:
690 case HAL_PIXEL_FORMAT_BGRA_8888:
691 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500692 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530693 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400694 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500695 }
696 return false;
697}
698
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700699static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
700 hwc_rect_t& crop, hwc_rect_t& dst) {
701 int hw_w = ctx->dpyAttr[dpy].xres;
702 int hw_h = ctx->dpyAttr[dpy].yres;
703 if(dst.left < 0 || dst.top < 0 ||
704 dst.right > hw_w || dst.bottom > hw_h) {
705 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
706 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
707 }
708}
709
710static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
711 const int& dpy) {
712 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
713 hwc_layer_1_t *layer = &list->hwLayers[i];
714 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
715 trimLayer(ctx, dpy,
716 list->hwLayers[i].transform,
717 (hwc_rect_t&)crop,
718 (hwc_rect_t&)list->hwLayers[i].displayFrame);
719 layer->sourceCropf.left = crop.left;
720 layer->sourceCropf.right = crop.right;
721 layer->sourceCropf.top = crop.top;
722 layer->sourceCropf.bottom = crop.bottom;
723 }
724}
725
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700726void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700727 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700728 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
729 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700730 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
731 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700732 ctx->listStats[dpy].skipCount = 0;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500733 ctx->listStats[dpy].needsAlphaScale = false;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530734 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700735 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800736 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400737 char property[PROPERTY_VALUE_MAX];
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800738 ctx->listStats[dpy].extOnlyLayerIndex = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700739 ctx->listStats[dpy].isDisplayAnimating = false;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700740 ctx->listStats[dpy].roi = ovutils::Dim(0, 0,
741 (int)ctx->dpyAttr[dpy].xres, (int)ctx->dpyAttr[dpy].yres);
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700742 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +0530743 ctx->listStats[dpy].yuv4k2kCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700744
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700745 trimList(ctx, list, dpy);
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +0530746 optimizeLayerRects(ctx, list, dpy);
747
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700748 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500749 hwc_layer_1_t const* layer = &list->hwLayers[i];
750 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700751
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700752#ifdef QCOM_BSP
753 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
754 ctx->listStats[dpy].isDisplayAnimating = true;
755 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700756 if(isSecureDisplayBuffer(hnd)) {
757 ctx->listStats[dpy].secureUI = true;
758 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700759#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700760 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
761 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700762 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800763
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700764 //reset yuv indices
765 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530766 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700767
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700768 if (isSecureBuffer(hnd)) {
769 ctx->listStats[dpy].isSecurePresent = true;
770 }
771
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700772 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700773 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700774 }
775
776 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800777 int& yuvCount = ctx->listStats[dpy].yuvCount;
778 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
779 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800780
radhakrishnac9a67412013-09-25 17:40:42 +0530781 if(UNLIKELY(is4kx2kYuvBuffer(hnd))){
782 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
783 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = i;
784 yuv4k2kCount++;
785 }
786
Saurabh Shahe2474082013-05-15 16:32:13 -0700787 if((layer->transform & HWC_TRANSFORM_ROT_90) &&
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700788 canUseRotator(ctx, dpy)) {
789 if( (dpy == HWC_DISPLAY_PRIMARY) &&
790 ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700791 ctx->isPaddingRound = true;
792 }
Saurabh Shah85234ec2013-04-12 17:09:00 -0700793 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
794 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700795 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530796 if(layer->blending == HWC_BLENDING_PREMULT)
797 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -0800798
799 if(!ctx->listStats[dpy].needsAlphaScale)
Saurabh Shah8a117932013-05-23 12:48:13 -0700800 ctx->listStats[dpy].needsAlphaScale =
801 isAlphaScaled(ctx, layer, dpy);
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800802
803 if(UNLIKELY(isExtOnly(hnd))){
804 ctx->listStats[dpy].extOnlyLayerIndex = i;
805 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700806 }
Ping Li9404e2a2013-04-24 16:36:03 -0400807 if(ctx->listStats[dpy].yuvCount > 0) {
808 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
809 if (atoi(property) != 1) {
810 property_set("hw.cabl.yuv", "1");
811 }
812 }
813 } else {
814 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
815 if (atoi(property) != 0) {
816 property_set("hw.cabl.yuv", "0");
817 }
818 }
819 }
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700820 if(dpy) {
821 //uncomment the below code for testing purpose.
822 /* char value[PROPERTY_VALUE_MAX];
823 property_get("sys.ext_orientation", value, "0");
824 // Assuming the orientation value is in terms of HAL_TRANSFORM,
825 // This needs mapping to HAL, if its in different convention
826 ctx->mExtOrientation = atoi(value); */
827 // Assuming the orientation value is in terms of HAL_TRANSFORM,
828 // This needs mapping to HAL, if its in different convention
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700829 if(ctx->mExtOrientation || ctx->mBufferMirrorMode) {
830 ALOGD_IF(HWC_UTILS_DEBUG, "%s: ext orientation = %d"
831 "BufferMirrorMode = %d", __FUNCTION__,
832 ctx->mExtOrientation, ctx->mBufferMirrorMode);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700833 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
834 ctx->isPaddingRound = true;
835 }
836 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
837 }
838 }
Saurabh Shahd4e65852013-06-17 11:33:53 -0700839
840 //The marking of video begin/end is useful on some targets where we need
841 //to have a padding round to be able to shift pipes across mixers.
842 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
843 ctx->mVideoTransFlag = true;
844 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700845 if(dpy == HWC_DISPLAY_PRIMARY) {
846 ctx->mAD->markDoable(ctx, list);
847 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700848}
849
Naseer Ahmed018e5452012-12-03 14:46:15 -0500850
Saurabh Shah68107422013-07-09 11:12:42 -0700851static void calc_cut(double& leftCutRatio, double& topCutRatio,
852 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700853 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700854 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700855 }
856 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700857 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700858 }
859 if(orient & HAL_TRANSFORM_ROT_90) {
860 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -0700861 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -0700862 leftCutRatio = topCutRatio;
863 topCutRatio = rightCutRatio;
864 rightCutRatio = bottomCutRatio;
865 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700866 }
867}
868
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800869bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500870 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
871 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
872 ctx->mSecuring) {
873 return true;
874 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800875 if (isSecureModePolicy(ctx->mMDP.version)) {
876 private_handle_t *hnd = (private_handle_t *)layer->handle;
877 if(ctx->mSecureMode) {
878 if (! isSecureBuffer(hnd)) {
879 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
880 __FUNCTION__);
881 return true;
882 }
883 } else {
884 if (isSecureBuffer(hnd)) {
885 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
886 __FUNCTION__);
887 return true;
888 }
889 }
890 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500891 return false;
892}
893
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800894bool isSecureModePolicy(int mdpVersion) {
895 if (mdpVersion < qdutils::MDSS_V5)
896 return true;
897 else
898 return false;
899}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500900
Naseer Ahmed522ce662013-03-18 20:14:05 -0400901int getBlending(int blending) {
902 switch(blending) {
903 case HWC_BLENDING_NONE:
904 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
905 case HWC_BLENDING_PREMULT:
906 return overlay::utils::OVERLAY_BLENDING_PREMULT;
907 case HWC_BLENDING_COVERAGE :
908 default:
909 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
910 }
911}
912
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700913//Crops source buffer against destination and FB boundaries
914void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800915 const hwc_rect_t& scissor, int orient) {
916
Saurabh Shah27c1d652012-08-14 19:30:28 -0700917 int& crop_l = crop.left;
918 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700919 int& crop_r = crop.right;
920 int& crop_b = crop.bottom;
921 int crop_w = crop.right - crop.left;
922 int crop_h = crop.bottom - crop.top;
923
Saurabh Shah27c1d652012-08-14 19:30:28 -0700924 int& dst_l = dst.left;
925 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700926 int& dst_r = dst.right;
927 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700928 int dst_w = abs(dst.right - dst.left);
929 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700930
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800931 const int& sci_l = scissor.left;
932 const int& sci_t = scissor.top;
933 const int& sci_r = scissor.right;
934 const int& sci_b = scissor.bottom;
935 int sci_w = abs(sci_r - sci_l);
936 int sci_h = abs(sci_b - sci_t);
937
Saurabh Shah68107422013-07-09 11:12:42 -0700938 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
939 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700940
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800941 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -0700942 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800943 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700944 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800945
946 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -0700947 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800948 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700949 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800950
951 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -0700952 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700954 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800955
956 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -0700957 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800958 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700959 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700960
Saurabh Shah541b59d2012-10-11 11:08:12 -0700961 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
962 crop_l += crop_w * leftCutRatio;
963 crop_t += crop_h * topCutRatio;
964 crop_r -= crop_w * rightCutRatio;
965 crop_b -= crop_h * bottomCutRatio;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700966}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700967
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530968bool areLayersIntersecting(const hwc_layer_1_t* layer1,
969 const hwc_layer_1_t* layer2) {
970 hwc_rect_t irect = getIntersection(layer1->displayFrame,
971 layer2->displayFrame);
972 return isValidRect(irect);
973}
974
Jeykumar Sankaran6a585792013-10-03 11:30:55 -0700975bool isValidRect(const hwc_rect& rect)
976{
977 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +0530978}
979
Jeykumar Sankaran6a585792013-10-03 11:30:55 -0700980/* computes the intersection of two rects */
981hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
982{
983 hwc_rect_t res;
984
985 if(!isValidRect(rect1) || !isValidRect(rect2)){
986 return (hwc_rect_t){0, 0, 0, 0};
987 }
988
989
990 res.left = max(rect1.left, rect2.left);
991 res.top = max(rect1.top, rect2.top);
992 res.right = min(rect1.right, rect2.right);
993 res.bottom = min(rect1.bottom, rect2.bottom);
994
995 if(!isValidRect(res))
996 return (hwc_rect_t){0, 0, 0, 0};
997
998 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +0530999}
1000
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001001/* computes the union of two rects */
1002hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1003{
1004 hwc_rect_t res;
1005
1006 if(!isValidRect(rect1)){
1007 return rect2;
1008 }
1009
1010 if(!isValidRect(rect2)){
1011 return rect1;
1012 }
1013
1014 res.left = min(rect1.left, rect2.left);
1015 res.top = min(rect1.top, rect2.top);
1016 res.right = max(rect1.right, rect2.right);
1017 res.bottom = max(rect1.bottom, rect2.bottom);
1018
1019 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301020}
1021
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001022/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1023 * a single rect */
1024hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301025
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001026 hwc_rect_t res = rect1;
1027
1028 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1029 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1030 res.top = rect2.bottom;
1031 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1032 res.bottom = rect2.top;
1033 }
1034 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1035 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1036 res.left = rect2.right;
1037 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1038 res.right = rect2.left;
1039 }
1040 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301041}
1042
1043void optimizeLayerRects(hwc_context_t *ctx,
1044 const hwc_display_contents_1_t *list, const int& dpy) {
1045 int i=list->numHwLayers-2;
1046 hwc_rect_t irect;
1047 while(i > 0) {
1048
1049 //see if there is no blending required.
1050 //If it is opaque see if we can substract this region from below layers.
1051 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1052 int j= i-1;
1053 hwc_rect_t& topframe =
1054 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1055 while(j >= 0) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001056 if(!needsScaling(ctx, &list->hwLayers[j], dpy)) {
1057 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1058 hwc_rect_t& bottomframe = layer->displayFrame;
1059 hwc_rect_t& bottomCrop = layer->sourceCrop;
1060 int transform =layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001061
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001062 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1063 if(isValidRect(irect)) {
1064 //if intersection is valid rect, deduct it
1065 bottomframe = deductRect(bottomframe, irect);
1066 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
1067 bottomframe, transform);
1068
1069 }
1070 }
1071 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301072 }
1073 }
1074 i--;
1075 }
1076}
1077
Naseer Ahmed64b81212013-02-14 10:29:47 -05001078void getNonWormholeRegion(hwc_display_contents_1_t* list,
1079 hwc_rect_t& nwr)
1080{
1081 uint32_t last = list->numHwLayers - 1;
1082 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1083 //Initiliaze nwr to first frame
1084 nwr.left = list->hwLayers[0].displayFrame.left;
1085 nwr.top = list->hwLayers[0].displayFrame.top;
1086 nwr.right = list->hwLayers[0].displayFrame.right;
1087 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1088
1089 for (uint32_t i = 1; i < last; i++) {
1090 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001091 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001092 }
1093
1094 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001095 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001096}
1097
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001098bool isExternalActive(hwc_context_t* ctx) {
1099 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001100}
1101
Saurabh Shah747af1e2013-02-26 10:25:12 -08001102void closeAcquireFds(hwc_display_contents_1_t* list) {
1103 for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
1104 //Close the acquireFenceFds
1105 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1106 if(list->hwLayers[i].acquireFenceFd >= 0) {
1107 close(list->hwLayers[i].acquireFenceFd);
1108 list->hwLayers[i].acquireFenceFd = -1;
1109 }
1110 }
1111}
1112
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001113int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001114 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001115 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001116 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001117 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001118 int count = 0;
1119 int releaseFd = -1;
1120 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001121 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001122 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
1123
1124 struct mdp_buf_sync data;
1125 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001126 data.acq_fen_fd = acquireFd;
1127 data.rel_fen_fd = &releaseFd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001128
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001129 char property[PROPERTY_VALUE_MAX];
1130 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1131 if(atoi(property) == 0)
1132 swapzero = true;
1133 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001134
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001135 bool isExtAnimating = false;
1136 if(dpy)
1137 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001138
Saurabh Shah23a813c2013-03-20 16:58:12 -07001139 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001140 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001141 int rotFd = ctx->mRotMgr->getRotDevFd();
1142 int rotReleaseFd = -1;
1143 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001144 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001145 rotData.acq_fen_fd =
1146 &ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd;
1147 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Saurabh Shah23a813c2013-03-20 16:58:12 -07001148 rotData.session_id = ctx->mLayerRotMap[dpy]->getRot(i)->getSessId();
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001149 int ret = 0;
1150 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1151 if(ret < 0) {
1152 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1153 __FUNCTION__, strerror(errno));
1154 } else {
1155 close(ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd);
1156 //For MDP to wait on.
1157 ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd =
1158 dup(rotReleaseFd);
1159 //A buffer is free to be used by producer as soon as its copied to
1160 //rotator
1161 ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd =
1162 rotReleaseFd;
1163 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001164 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001165
1166 //Accumulate acquireFenceFds for MDP
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001167 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001168 if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001169 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001170 if(UNLIKELY(swapzero))
1171 acquireFd[count++] = -1;
1172 else
1173 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001174 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001175 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1176 if(UNLIKELY(swapzero))
1177 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001178 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001179 //set the acquireFD from fd - which is coming from c2d
1180 acquireFd[count++] = fd;
1181 // Buffer sync IOCTL should be async when using c2d fence is
1182 // used
1183 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001184 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001185 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1186 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001187 }
1188
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001189 data.acq_fen_fd_cnt = count;
1190 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001191
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001192 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001193 if(LIKELY(!swapzero)) {
1194 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001195 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001196 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
1197 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
1198 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001199
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001200 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001201 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1202 __FUNCTION__, strerror(errno));
1203 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
1204 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1205 dpy, list->numHwLayers);
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001206 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001207
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001208 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001209 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
1210 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001211 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001212 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001213 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001214 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001215 // Release all the app layer fds immediately,
1216 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001217 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001218 } else if(list->hwLayers[i].releaseFenceFd < 0) {
1219 //If rotator has not already populated this field.
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001220 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001221 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001222 }
1223 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001224
1225 if(fd >= 0) {
1226 close(fd);
1227 fd = -1;
1228 }
1229
Naseer Ahmed64b81212013-02-14 10:29:47 -05001230 if (ctx->mCopyBit[dpy])
1231 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001232
Saurabh Shah23a813c2013-03-20 16:58:12 -07001233 //Signals when MDP finishes reading rotator buffers.
1234 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001235
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001236 // if external is animating, close the relaseFd
1237 if(isExtAnimating) {
1238 close(releaseFd);
1239 releaseFd = -1;
1240 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001241
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001242 if(UNLIKELY(swapzero)){
1243 list->retireFenceFd = -1;
1244 close(releaseFd);
1245 } else {
1246 list->retireFenceFd = releaseFd;
1247 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001248
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001249 return ret;
1250}
1251
Saurabh Shahacf10202013-02-26 10:15:15 -08001252void setMdpFlags(hwc_layer_1_t *layer,
1253 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001254 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001255 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001256 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001257
1258 if(layer->blending == HWC_BLENDING_PREMULT) {
1259 ovutils::setMdpFlags(mdpFlags,
1260 ovutils::OV_MDP_BLEND_FG_PREMULT);
1261 }
1262
1263 if(isYuvBuffer(hnd)) {
1264 if(isSecureBuffer(hnd)) {
1265 ovutils::setMdpFlags(mdpFlags,
1266 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1267 }
1268 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1269 metadata->interlaced) {
1270 ovutils::setMdpFlags(mdpFlags,
1271 ovutils::OV_MDP_DEINTERLACE);
1272 }
1273 //Pre-rotation will be used using rotator.
1274 if(transform & HWC_TRANSFORM_ROT_90) {
1275 ovutils::setMdpFlags(mdpFlags,
1276 ovutils::OV_MDP_SOURCE_ROTATED_90);
1277 }
1278 }
1279
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001280 if(isSecureDisplayBuffer(hnd)) {
1281 // Secure display needs both SECURE_OVERLAY and SECURE_DISPLAY_OV
1282 ovutils::setMdpFlags(mdpFlags,
1283 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1284 ovutils::setMdpFlags(mdpFlags,
1285 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1286 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001287 //No 90 component and no rot-downscale then flips done by MDP
1288 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001289 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1290 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001291 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1292 }
1293
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001294 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001295 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1296 }
1297 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001298
1299 if(metadata &&
1300 ((metadata->operation & PP_PARAM_HSIC)
1301 || (metadata->operation & PP_PARAM_IGC)
1302 || (metadata->operation & PP_PARAM_SHARP2))) {
1303 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1304 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001305}
1306
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301307int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001308 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001309 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001310
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301311 // Fix alignments for TILED format
1312 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1313 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1314 whf.w = utils::alignup(whf.w, 64);
1315 whf.h = utils::alignup(whf.h, 32);
1316 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001317 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001318
1319 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1320 qdutils::MDSS_V5) {
1321 uint32_t crop_w = (crop.right - crop.left);
1322 uint32_t crop_h = (crop.bottom - crop.top);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001323 if (ovutils::isYuv(whf.format)) {
1324 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
1325 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -07001326 // For interlaced, crop.h should be 4-aligned
1327 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
1328 crop_h = ovutils::aligndown(crop_h, 4);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001329 crop.right = crop.left + crop_w;
1330 crop.bottom = crop.top + crop_h;
1331 }
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001332 Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
1333 rot->setCrop(rotCrop);
1334 }
1335
Saurabh Shahacf10202013-02-26 10:15:15 -08001336 rot->setFlags(mdpFlags);
1337 rot->setTransform(orient);
1338 rot->setDownscale(downscale);
1339 if(!rot->commit()) return -1;
1340 return 0;
1341}
1342
Saurabh Shahe2474082013-05-15 16:32:13 -07001343int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001344 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001345 const hwc_rect_t& pos, const MetaData_t *metadata,
1346 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001347 ov->setSource(parg, dest);
1348 ov->setTransform(orient, dest);
1349
1350 int crop_w = crop.right - crop.left;
1351 int crop_h = crop.bottom - crop.top;
1352 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1353 ov->setCrop(dcrop, dest);
1354
1355 int posW = pos.right - pos.left;
1356 int posH = pos.bottom - pos.top;
1357 Dim position(pos.left, pos.top, posW, posH);
1358 ov->setPosition(position, dest);
1359
Saurabh Shah5daeee52013-01-23 16:52:26 +08001360 if (metadata)
1361 ov->setVisualParams(*metadata, dest);
1362
Saurabh Shahacf10202013-02-26 10:15:15 -08001363 if (!ov->commit(dest)) {
1364 return -1;
1365 }
1366 return 0;
1367}
1368
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001369int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1370 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1371 eIsFg& isFg, const eDest& dest) {
1372
1373 hwc_rect_t dst = layer->displayFrame;
1374 trimLayer(ctx, dpy, 0, dst, dst);
1375
1376 int w = ctx->dpyAttr[dpy].xres;
1377 int h = ctx->dpyAttr[dpy].yres;
1378 int dst_w = dst.right - dst.left;
1379 int dst_h = dst.bottom - dst.top;
1380 uint32_t color = layer->transform;
1381 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1382
1383 if (layer->blending == HWC_BLENDING_PREMULT)
1384 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1385
1386 PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(0),
1387 layer->planeAlpha,
1388 (ovutils::eBlending) getBlending(layer->blending));
1389
1390 // Configure MDP pipe for Color layer
1391 Dim pos(dst.left, dst.top, dst_w, dst_h);
1392 ctx->mOverlay->setSource(parg, dest);
1393 ctx->mOverlay->setColor(color, dest);
1394 ctx->mOverlay->setTransform(0, dest);
1395 ctx->mOverlay->setCrop(pos, dest);
1396 ctx->mOverlay->setPosition(pos, dest);
1397
1398 if (!ctx->mOverlay->commit(dest)) {
1399 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1400 return -1;
1401 }
1402 return 0;
1403}
1404
Saurabh Shahe2474082013-05-15 16:32:13 -07001405void updateSource(eTransform& orient, Whf& whf,
Saurabh Shahacf10202013-02-26 10:15:15 -08001406 hwc_rect_t& crop) {
1407 Dim srcCrop(crop.left, crop.top,
1408 crop.right - crop.left,
1409 crop.bottom - crop.top);
Saurabh Shah76fd6552013-03-14 14:45:38 -07001410 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
Saurabh Shahacf10202013-02-26 10:15:15 -08001411 preRotateSource(orient, whf, srcCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001412 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1413 qdutils::MDSS_V5) {
1414 // Source for overlay will be the cropped (and rotated)
1415 crop.left = 0;
1416 crop.top = 0;
1417 crop.right = srcCrop.w;
1418 crop.bottom = srcCrop.h;
1419 // Set width & height equal to sourceCrop w & h
1420 whf.w = srcCrop.w;
1421 whf.h = srcCrop.h;
1422 } else {
1423 crop.left = srcCrop.x;
1424 crop.top = srcCrop.y;
1425 crop.right = srcCrop.x + srcCrop.w;
1426 crop.bottom = srcCrop.y + srcCrop.h;
1427 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001428}
1429
Saurabh Shah88e4d272013-09-03 13:31:29 -07001430int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001431 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1432 eIsFg& isFg, const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001433
1434 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001435
Saurabh Shahacf10202013-02-26 10:15:15 -08001436 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001437 if (layer->flags & HWC_COLOR_FILL) {
1438 // Configure Color layer
1439 return configColorLayer(ctx, layer, dpy, mdpFlags, z, isFg, dest);
1440 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001441 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1442 return -1;
1443 }
1444
Saurabh Shah5daeee52013-01-23 16:52:26 +08001445 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1446
Saurabh Shah62e1d732013-09-17 10:44:05 -07001447 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001448 hwc_rect_t dst = layer->displayFrame;
1449 int transform = layer->transform;
1450 eTransform orient = static_cast<eTransform>(transform);
1451 int downscale = 0;
1452 int rotFlags = ovutils::ROT_FLAGS_NONE;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -07001453 Whf whf(getWidth(hnd), getHeight(hnd),
Saurabh Shahacf10202013-02-26 10:15:15 -08001454 getMdpFormat(hnd->format), hnd->size);
1455
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001456 // Handle R/B swap
1457 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1458 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1459 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1460 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1461 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1462 }
1463
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001464 if(dpy && isYuvBuffer(hnd)) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -07001465 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst,
1466 transform, orient);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -07001467 }
1468
Saurabh Shahacf10202013-02-26 10:15:15 -08001469 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001470 ctx->mMDP.version < qdutils::MDSS_V5) {
1471 downscale = getDownscaleFactor(
1472 crop.right - crop.left,
1473 crop.bottom - crop.top,
1474 dst.right - dst.left,
1475 dst.bottom - dst.top);
Saurabh Shahacf10202013-02-26 10:15:15 -08001476 if(downscale) {
1477 rotFlags = ROT_DOWNSCALE_ENABLED;
1478 }
1479 }
1480
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001481 setMdpFlags(layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001482
1483 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
1484 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
1485 *rot = ctx->mRotMgr->getNext();
1486 if(*rot == NULL) return -1;
Tatenda Chipeperekwa88562702013-10-19 19:56:16 -07001487 if(!dpy)
1488 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001489 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001490 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1491 ALOGE("%s: configRotator failed!", __FUNCTION__);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -07001492 ctx->mOverlay->clear(dpy);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001493 ctx->mLayerRotMap[dpy]->clear();
Saurabh Shahacf10202013-02-26 10:15:15 -08001494 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001495 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001496 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001497 whf.format = (*rot)->getDstFormat();
1498 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001499 rotFlags |= ovutils::ROT_PREROTATED;
1500 }
1501
Saurabh Shah76fd6552013-03-14 14:45:38 -07001502 //For the mdp, since either we are pre-rotating or MDP does flips
1503 orient = OVERLAY_TRANSFORM_0;
1504 transform = 0;
Naseer Ahmed522ce662013-03-18 20:14:05 -04001505 PipeArgs parg(mdpFlags, whf, z, isFg,
1506 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1507 (ovutils::eBlending) getBlending(layer->blending));
1508
Saurabh Shah5daeee52013-01-23 16:52:26 +08001509 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001510 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001511 ctx->mLayerRotMap[dpy]->clear();
Saurabh Shahacf10202013-02-26 10:15:15 -08001512 return -1;
1513 }
1514 return 0;
1515}
1516
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001517//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001518void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001519 private_handle_t *hnd) {
1520 if(cropL.right - cropL.left) {
1521 if(isYuvBuffer(hnd)) {
1522 //Always safe to even down left
1523 ovutils::even_floor(cropL.left);
1524 //If right is even, automatically width is even, since left is
1525 //already even
1526 ovutils::even_floor(cropL.right);
1527 }
1528 //Make sure there are no gaps between left and right splits if the layer
1529 //is spread across BOTH halves
1530 if(cropR.right - cropR.left) {
1531 cropR.left = cropL.right;
1532 }
1533 }
1534
1535 if(cropR.right - cropR.left) {
1536 if(isYuvBuffer(hnd)) {
1537 //Always safe to even down left
1538 ovutils::even_floor(cropR.left);
1539 //If right is even, automatically width is even, since left is
1540 //already even
1541 ovutils::even_floor(cropR.right);
1542 }
1543 }
1544}
1545
Saurabh Shah88e4d272013-09-03 13:31:29 -07001546int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001547 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1548 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001549 Rotator **rot) {
1550 private_handle_t *hnd = (private_handle_t *)layer->handle;
1551 if(!hnd) {
1552 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1553 return -1;
1554 }
1555
Saurabh Shah5daeee52013-01-23 16:52:26 +08001556 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1557
Saurabh Shahacf10202013-02-26 10:15:15 -08001558 int hw_w = ctx->dpyAttr[dpy].xres;
1559 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07001560 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001561 hwc_rect_t dst = layer->displayFrame;
1562 int transform = layer->transform;
1563 eTransform orient = static_cast<eTransform>(transform);
1564 const int downscale = 0;
1565 int rotFlags = ROT_FLAGS_NONE;
1566
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -07001567 Whf whf(getWidth(hnd), getHeight(hnd),
Saurabh Shahacf10202013-02-26 10:15:15 -08001568 getMdpFormat(hnd->format), hnd->size);
1569
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001570 // Handle R/B swap
1571 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1572 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1573 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1574 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1575 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1576 }
1577
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -07001578 setMdpFlags(layer, mdpFlagsL, 0, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001579
1580 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1581 //Enable overfetch
1582 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1583 }
1584
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001585 //Will do something only if feature enabled and conditions suitable
1586 //hollow call otherwise
1587 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
1588 overlay::Writeback *wb = overlay::Writeback::getInstance();
1589 whf.format = wb->getOutputFormat();
1590 }
1591
Saurabh Shahacf10202013-02-26 10:15:15 -08001592 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1593 (*rot) = ctx->mRotMgr->getNext();
1594 if((*rot) == NULL) return -1;
1595 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001596 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1597 ALOGE("%s: configRotator failed!", __FUNCTION__);
Sushil Chauhanbd3ea922013-05-15 12:25:26 -07001598 ctx->mOverlay->clear(dpy);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001599 ctx->mLayerRotMap[dpy]->clear();
Saurabh Shahacf10202013-02-26 10:15:15 -08001600 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001601 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001602 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001603 whf.format = (*rot)->getDstFormat();
1604 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001605 rotFlags |= ROT_PREROTATED;
1606 }
1607
1608 eMdpFlags mdpFlagsR = mdpFlagsL;
1609 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1610
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001611 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1612 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08001613
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001614 const int lSplit = getLeftSplit(ctx, dpy);
1615
Saurabh Shahacf10202013-02-26 10:15:15 -08001616 if(lDest != OV_INVALID) {
1617 tmp_cropL = crop;
1618 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001619 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Saurabh Shahacf10202013-02-26 10:15:15 -08001620 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1621 }
1622 if(rDest != OV_INVALID) {
1623 tmp_cropR = crop;
1624 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001625 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Saurabh Shahacf10202013-02-26 10:15:15 -08001626 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1627 }
1628
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001629 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1630
Saurabh Shah94d62362013-07-02 10:58:48 -07001631 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08001632 //Not needed if the layer is confined to one half of the screen.
1633 //If rotator has been used then it has also done the flips, so ignore them.
Saurabh Shah94d62362013-07-02 10:58:48 -07001634 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
Ramkumar Radhakrishnanfe7ce802013-04-30 11:19:17 -07001635 && rDest != OV_INVALID && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001636 hwc_rect_t new_cropR;
1637 new_cropR.left = tmp_cropL.left;
1638 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1639
1640 hwc_rect_t new_cropL;
1641 new_cropL.left = new_cropR.right;
1642 new_cropL.right = tmp_cropR.right;
1643
1644 tmp_cropL.left = new_cropL.left;
1645 tmp_cropL.right = new_cropL.right;
1646
1647 tmp_cropR.left = new_cropR.left;
1648 tmp_cropR.right = new_cropR.right;
1649
1650 }
1651
Saurabh Shah76fd6552013-03-14 14:45:38 -07001652 //For the mdp, since either we are pre-rotating or MDP does flips
1653 orient = OVERLAY_TRANSFORM_0;
1654 transform = 0;
1655
Saurabh Shahacf10202013-02-26 10:15:15 -08001656 //configure left mixer
1657 if(lDest != OV_INVALID) {
1658 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001659 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1660 (ovutils::eBlending) getBlending(layer->blending));
1661
Saurabh Shahacf10202013-02-26 10:15:15 -08001662 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001663 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001664 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001665 ctx->mLayerRotMap[dpy]->clear();
Saurabh Shahacf10202013-02-26 10:15:15 -08001666 return -1;
1667 }
1668 }
1669
1670 //configure right mixer
1671 if(rDest != OV_INVALID) {
1672 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001673 static_cast<eRotFlags>(rotFlags),
1674 layer->planeAlpha,
1675 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07001676 tmp_dstR.right = tmp_dstR.right - lSplit;
1677 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001678 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001679 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001680 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001681 ctx->mLayerRotMap[dpy]->clear();
Saurabh Shahacf10202013-02-26 10:15:15 -08001682 return -1;
1683 }
1684 }
1685
1686 return 0;
1687}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08001688
radhakrishnac9a67412013-09-25 17:40:42 +05301689int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
1690 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1691 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
1692 Rotator **rot) {
1693 private_handle_t *hnd = (private_handle_t *)layer->handle;
1694 if(!hnd) {
1695 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1696 return -1;
1697 }
1698
1699 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1700
1701 int hw_w = ctx->dpyAttr[dpy].xres;
1702 int hw_h = ctx->dpyAttr[dpy].yres;
1703 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
1704 hwc_rect_t dst = layer->displayFrame;
1705 int transform = layer->transform;
1706 eTransform orient = static_cast<eTransform>(transform);
1707 const int downscale = 0;
1708 int rotFlags = ROT_FLAGS_NONE;
1709 //Splitting only YUV layer on primary panel needs different zorders
1710 //for both layers as both the layers are configured to single mixer
1711 eZorder lz = z;
1712 eZorder rz = (eZorder)(z + 1);
1713
1714 Whf whf(getWidth(hnd), getHeight(hnd),
1715 getMdpFormat(hnd->format), hnd->size);
1716
1717 setMdpFlags(layer, mdpFlagsL, 0, transform);
1718 trimLayer(ctx, dpy, transform, crop, dst);
1719
1720 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1721 (*rot) = ctx->mRotMgr->getNext();
1722 if((*rot) == NULL) return -1;
1723 if(!dpy)
1724 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlagsL);
1725 //Configure rotator for pre-rotation
1726 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1727 ALOGE("%s: configRotator failed!", __FUNCTION__);
1728 ctx->mOverlay->clear(dpy);
1729 return -1;
1730 }
1731 ctx->mLayerRotMap[dpy]->add(layer, *rot);
1732 whf.format = (*rot)->getDstFormat();
1733 updateSource(orient, whf, crop);
1734 rotFlags |= ROT_PREROTATED;
1735 }
1736
1737 eMdpFlags mdpFlagsR = mdpFlagsL;
1738 int lSplit = dst.left + (dst.right - dst.left)/2;
1739
1740 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1741 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
1742
1743 if(lDest != OV_INVALID) {
1744 tmp_cropL = crop;
1745 tmp_dstL = dst;
1746 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
1747 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1748 }
1749 if(rDest != OV_INVALID) {
1750 tmp_cropR = crop;
1751 tmp_dstR = dst;
1752 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
1753 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1754 }
1755
1756 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1757
1758 //When buffer is H-flipped, contents of mixer config also needs to swapped
1759 //Not needed if the layer is confined to one half of the screen.
1760 //If rotator has been used then it has also done the flips, so ignore them.
1761 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1762 && rDest != OV_INVALID && (*rot) == NULL) {
1763 hwc_rect_t new_cropR;
1764 new_cropR.left = tmp_cropL.left;
1765 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1766
1767 hwc_rect_t new_cropL;
1768 new_cropL.left = new_cropR.right;
1769 new_cropL.right = tmp_cropR.right;
1770
1771 tmp_cropL.left = new_cropL.left;
1772 tmp_cropL.right = new_cropL.right;
1773
1774 tmp_cropR.left = new_cropR.left;
1775 tmp_cropR.right = new_cropR.right;
1776
1777 }
1778
1779 //For the mdp, since either we are pre-rotating or MDP does flips
1780 orient = OVERLAY_TRANSFORM_0;
1781 transform = 0;
1782
1783 //configure left half
1784 if(lDest != OV_INVALID) {
1785 PipeArgs pargL(mdpFlagsL, whf, lz, isFg,
1786 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1787 (ovutils::eBlending) getBlending(layer->blending));
1788
1789 if(configMdp(ctx->mOverlay, pargL, orient,
1790 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1791 ALOGE("%s: commit failed for left half config", __FUNCTION__);
1792 return -1;
1793 }
1794 }
1795
1796 //configure right half
1797 if(rDest != OV_INVALID) {
1798 PipeArgs pargR(mdpFlagsR, whf, rz, isFg,
1799 static_cast<eRotFlags>(rotFlags),
1800 layer->planeAlpha,
1801 (ovutils::eBlending) getBlending(layer->blending));
1802 if(configMdp(ctx->mOverlay, pargR, orient,
1803 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1804 ALOGE("%s: commit failed for right half config", __FUNCTION__);
1805 return -1;
1806 }
1807 }
1808
1809 return 0;
1810}
1811
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001812bool canUseRotator(hwc_context_t *ctx, int dpy) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001813 if(qdutils::MDPVersion::getInstance().is8x26() &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07001814 ctx->mVirtualDisplay->isConnected() &&
1815 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamala8c065f2013-10-22 14:52:45 +05301816 /* 8x26 mdss driver supports multiplexing of DMA pipe
1817 * in LINE and BLOCK modes for writeback panels.
1818 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001819 if(dpy == HWC_DISPLAY_PRIMARY)
1820 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001821 }
Terence Hampson45c02ef2013-05-17 17:00:11 -04001822 if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1823 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001824 return true;
1825}
1826
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001827int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1828 //Default even split for all displays with high res
1829 int lSplit = ctx->dpyAttr[dpy].xres / 2;
1830 if(dpy == HWC_DISPLAY_PRIMARY &&
1831 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1832 //Override if split published by driver for primary
1833 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1834 }
1835 return lSplit;
1836}
Saurabh Shah1a03d482013-05-29 13:44:20 -07001837
Saurabh Shah88e4d272013-09-03 13:31:29 -07001838bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
1839 if(ctx->dpyAttr[dpy].xres > qdutils::MAX_DISPLAY_DIM) {
1840 return true;
1841 }
1842 //For testing we could split primary via device tree values
1843 if(dpy == HWC_DISPLAY_PRIMARY &&
1844 qdutils::MDPVersion::getInstance().getRightSplit()) {
1845 return true;
1846 }
1847 return false;
1848}
1849
Saurabh Shah1a03d482013-05-29 13:44:20 -07001850void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1851 const hwc_rect_t& dst, const int& transform,
1852 ovutils::eMdpFlags& mdpFlags) {
1853 //Target doesnt support Bwc
1854 if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
1855 return;
1856 }
1857 //src width > MAX mixer supported dim
1858 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1859 return;
1860 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07001861 //Decimation necessary, cannot use BWC. H/W requirement.
1862 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
1863 int src_w = crop.right - crop.left;
1864 int src_h = crop.bottom - crop.top;
1865 int dst_w = dst.right - dst.left;
1866 int dst_h = dst.bottom - dst.top;
1867 if(transform & HAL_TRANSFORM_ROT_90) {
1868 swap(src_w, src_h);
1869 }
1870 float horDscale = 0.0f;
1871 float verDscale = 0.0f;
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07001872 int horzDeci = 0;
1873 int vertDeci = 0;
Saurabh Shah1a03d482013-05-29 13:44:20 -07001874 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
1875 verDscale);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07001876 //TODO Use log2f once math.h has it
1877 if((int)horDscale)
1878 horzDeci = (int)(log(horDscale) / log(2));
1879 if((int)verDscale)
1880 vertDeci = (int)(log(verDscale) / log(2));
1881 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07001882 }
1883 //Property
1884 char value[PROPERTY_VALUE_MAX];
1885 property_get("debug.disable.bwc", value, "0");
1886 if(atoi(value)) return;
1887
1888 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
1889}
1890
Saurabh Shah23a813c2013-03-20 16:58:12 -07001891void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
1892 if(mCount >= MAX_SESS) return;
1893 mLayer[mCount] = layer;
1894 mRot[mCount] = rot;
1895 mCount++;
1896}
1897
1898void LayerRotMap::reset() {
1899 for (int i = 0; i < MAX_SESS; i++) {
1900 mLayer[i] = 0;
1901 mRot[i] = 0;
1902 }
1903 mCount = 0;
1904}
1905
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001906void LayerRotMap::clear() {
1907 for (uint32_t i = 0; i < mCount; i++) {
1908 //mCount represents rotator objects for just this display.
1909 //We could have popped mCount topmost objects from mRotMgr, but if each
1910 //round has the same failure, typical of stability runs, it would lead
1911 //to unnecessary memory allocation, deallocation each time. So we let
1912 //the rotator objects be around, but just knock off the fences they
1913 //hold. Ultimately the rotator objects will be GCed when not required.
1914 //Also resetting fences is required if at least one rotation round has
1915 //succeeded before. It'll be a NOP otherwise.
1916 mRot[i]->resetReleaseFd();
1917 }
1918 reset();
1919}
1920
Saurabh Shah23a813c2013-03-20 16:58:12 -07001921void LayerRotMap::setReleaseFd(const int& fence) {
1922 for(uint32_t i = 0; i < mCount; i++) {
1923 mRot[i]->setReleaseFd(dup(fence));
1924 }
1925}
1926
Saurabh Shahacf10202013-02-26 10:15:15 -08001927};//namespace qhwc