blob: bb12c4e7b82748574eaff03d5ca5774c78f70dc9 [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();
Saurabh Shah7a606842013-12-11 14:36:04 -0800137 ctx->mRotMgr = RotMgr::getInstance();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800138
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
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800310 int fbWidth = ctx->dpyAttr[dpy].xres;
311 int 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
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800315 ctx->mExtDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700316 }
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;
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800328 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) {
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800389 hwc_rect_t viewFrame = ctx->mViewFrame[dpy];
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700390 // Physical display resolution
391 float fbWidth = ctx->dpyAttr[dpy].xres;
392 float fbHeight = ctx->dpyAttr[dpy].yres;
393 //display position(x,y,w,h) in correct aspectratio after rotation
394 int xPos = 0;
395 int yPos = 0;
396 float width = fbWidth;
397 float height = fbHeight;
398 // Width/Height used for calculation, after rotation
399 float actualWidth = fbWidth;
400 float actualHeight = fbHeight;
401
402 float wRatio = 1.0;
403 float hRatio = 1.0;
404 float xRatio = 1.0;
405 float yRatio = 1.0;
406 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
407
408 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
409 inRect.bottom - inRect.top);
410 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
411 outRect.bottom - outRect.top);
412
413 Whf whf(fbWidth, fbHeight, 0);
414 eTransform extorient = static_cast<eTransform>(extOrientation);
415 // To calculate the destination co-ordinates in the new orientation
416 preRotateSource(extorient, whf, inPos);
417
418 if(extOrientation & HAL_TRANSFORM_ROT_90) {
419 // Swap width/height for input position
420 swapWidthHeight(actualWidth, actualHeight);
421 getAspectRatioPosition(fbWidth, fbHeight, (int)actualWidth,
422 (int)actualHeight, rect);
423 xPos = rect.left;
424 yPos = rect.top;
425 width = rect.right - rect.left;
426 height = rect.bottom - rect.top;
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800427 // swap viewframe coordinates for 90 degree rotation.
428 swap(viewFrame.left, viewFrame.top);
429 swap(viewFrame.right, viewFrame.bottom);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700430 }
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800431 // if viewframe left and top coordinates are non zero value then exclude it
432 // during the computation of xRatio and yRatio
433 xRatio = (inPos.x - viewFrame.left)/actualWidth;
434 yRatio = (inPos.y - viewFrame.top)/actualHeight;
435 // Use viewframe width and height to compute wRatio and hRatio.
436 wRatio = inPos.w/(viewFrame.right - viewFrame.left);
437 hRatio = inPos.h/(viewFrame.bottom - viewFrame.top);
438
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700439
440 //Calculate the position...
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700441 outPos.x = (xRatio * width) + xPos;
442 outPos.y = (yRatio * height) + yPos;
443 outPos.w = wRatio * width;
444 outPos.h = hRatio * height;
445 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
446 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
447 outPos.w, outPos.h);
448
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700449 // For sidesync, the dest fb will be in portrait orientation, and the crop
450 // will be updated to avoid the black side bands, and it will be upscaled
451 // to fit the dest RB, so recalculate
452 // the position based on the new width and height
453 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
454 isOrientationPortrait(ctx)) {
455 hwc_rect_t r;
456 //Calculate the position
457 xRatio = (outPos.x - xPos)/width;
458 // GetaspectRatio -- tricky to get the correct aspect ratio
459 // But we need to do this.
460 getAspectRatioPosition(width, height, width, height, r);
461 xPos = r.left;
462 yPos = r.top;
463 float tempWidth = r.right - r.left;
464 float tempHeight = r.bottom - r.top;
465 yRatio = yPos/height;
466 wRatio = outPos.w/width;
467 hRatio = tempHeight/height;
468
469 //Map the coordinates back to Framebuffer domain
470 outPos.x = (xRatio * fbWidth);
471 outPos.y = (yRatio * fbHeight);
472 outPos.w = wRatio * fbWidth;
473 outPos.h = hRatio * fbHeight;
474
475 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
476 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
477 outPos.x, outPos.y,
478 outPos.w, outPos.h);
479 }
480 if(ctx->dpyAttr[dpy].mDownScaleMode) {
481 int extW, extH;
482 if(dpy == HWC_DISPLAY_EXTERNAL)
483 ctx->mExtDisplay->getAttributes(extW, extH);
484 else
485 ctx->mVirtualDisplay->getAttributes(extW, extH);
486 fbWidth = ctx->dpyAttr[dpy].xres;
487 fbHeight = ctx->dpyAttr[dpy].yres;
488 //Calculate the position...
489 xRatio = outPos.x/fbWidth;
490 yRatio = outPos.y/fbHeight;
491 wRatio = outPos.w/fbWidth;
492 hRatio = outPos.h/fbHeight;
493
494 outPos.x = xRatio * extW;
495 outPos.y = yRatio * extH;
496 outPos.w = wRatio * extW;
497 outPos.h = hRatio * extH;
498 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700499 // Convert Dim to hwc_rect_t
500 outRect.left = outPos.x;
501 outRect.top = outPos.y;
502 outRect.right = outPos.x + outPos.w;
503 outRect.bottom = outPos.y + outPos.h;
504
505 return;
506}
507
508bool isPrimaryPortrait(hwc_context_t *ctx) {
509 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
510 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
511 if(fbWidth < fbHeight) {
512 return true;
513 }
514 return false;
515}
516
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700517bool isOrientationPortrait(hwc_context_t *ctx) {
518 if(isPrimaryPortrait(ctx)) {
519 return !(ctx->deviceOrientation & 0x1);
520 }
521 return (ctx->deviceOrientation & 0x1);
522}
523
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700524void calcExtDisplayPosition(hwc_context_t *ctx,
525 private_handle_t *hnd,
526 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700527 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700528 hwc_rect_t& displayFrame,
529 int& transform,
530 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700531 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700532 int extOrient = getExtOrientation(ctx);
533 if(dpy && !qdutils::MDPVersion::getInstance().is8x26()) {
534 if(!isYuvBuffer(hnd)) {
535 if(extOrient & HWC_TRANSFORM_ROT_90) {
536 int dstWidth = ctx->dpyAttr[dpy].xres;
537 int dstHeight = ctx->dpyAttr[dpy].yres;;
538 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
539 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
540 if(!isPrimaryPortrait(ctx)) {
541 swap(srcWidth, srcHeight);
542 } // Get Aspect Ratio for external
543 getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
544 srcHeight, displayFrame);
545 // Crop - this is needed, because for sidesync, the dest fb will
546 // be in portrait orientation, so update the crop to not show the
547 // black side bands.
548 if (isOrientationPortrait(ctx)) {
549 sourceCrop = displayFrame;
550 displayFrame.left = 0;
551 displayFrame.top = 0;
552 displayFrame.right = dstWidth;
553 displayFrame.bottom = dstHeight;
554 }
555 }
556 if(ctx->dpyAttr[dpy].mDownScaleMode) {
557 int extW, extH;
558 // if downscale is enabled, map the co-ordinates to new
559 // domain(downscaled)
560 float fbWidth = ctx->dpyAttr[dpy].xres;
561 float fbHeight = ctx->dpyAttr[dpy].yres;
562 // query MDP configured attributes
563 if(dpy == HWC_DISPLAY_EXTERNAL)
564 ctx->mExtDisplay->getAttributes(extW, extH);
565 else
566 ctx->mVirtualDisplay->getAttributes(extW, extH);
567 //Calculate the ratio...
568 float wRatio = ((float)extW)/fbWidth;
569 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700570
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700571 //convert Dim to hwc_rect_t
572 displayFrame.left *= wRatio;
573 displayFrame.top *= hRatio;
574 displayFrame.right *= wRatio;
575 displayFrame.bottom *= hRatio;
576 }
577 }else {
578 if(extOrient || ctx->dpyAttr[dpy].mDownScaleMode) {
579 getAspectRatioPosition(ctx, dpy, extOrient,
580 displayFrame, displayFrame);
581 }
582 }
583 // If there is a external orientation set, use that
584 if(extOrient) {
585 transform = extOrient;
586 orient = static_cast<ovutils::eTransform >(extOrient);
587 }
588 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
589 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700590 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700591}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700592
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700593/* Returns the orientation which needs to be set on External for
594 * SideSync/Buffer Mirrormode
595 */
596int getMirrorModeOrientation(hwc_context_t *ctx) {
597 int extOrientation = 0;
598 int deviceOrientation = ctx->deviceOrientation;
599 if(!isPrimaryPortrait(ctx))
600 deviceOrientation = (deviceOrientation + 1) % 4;
601 if (deviceOrientation == 0)
602 extOrientation = HWC_TRANSFORM_ROT_270;
603 else if (deviceOrientation == 1)//90
604 extOrientation = 0;
605 else if (deviceOrientation == 2)//180
606 extOrientation = HWC_TRANSFORM_ROT_90;
607 else if (deviceOrientation == 3)//270
608 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
609
610 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700611}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700612
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530613bool isDownscaleRequired(hwc_layer_1_t const* layer) {
614 hwc_rect_t displayFrame = layer->displayFrame;
615 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
616 int dst_w, dst_h, src_w, src_h;
617 dst_w = displayFrame.right - displayFrame.left;
618 dst_h = displayFrame.bottom - displayFrame.top;
619 src_w = sourceCrop.right - sourceCrop.left;
620 src_h = sourceCrop.bottom - sourceCrop.top;
621
622 if(((src_w > dst_w) || (src_h > dst_h)))
623 return true;
624
625 return false;
626}
627bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500628 int dst_w, dst_h, src_w, src_h;
629
630 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700631 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500632
633 dst_w = displayFrame.right - displayFrame.left;
634 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500635 src_w = sourceCrop.right - sourceCrop.left;
636 src_h = sourceCrop.bottom - sourceCrop.top;
637
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800638 if(((src_w != dst_w) || (src_h != dst_h)))
639 return true;
640
641 return false;
642}
643
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700644// Checks if layer needs scaling with split
645bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
646 const int& dpy) {
647
648 int src_width_l, src_height_l;
649 int src_width_r, src_height_r;
650 int dst_width_l, dst_height_l;
651 int dst_width_r, dst_height_r;
652 int hw_w = ctx->dpyAttr[dpy].xres;
653 int hw_h = ctx->dpyAttr[dpy].yres;
654 hwc_rect_t cropL, dstL, cropR, dstR;
655 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700656 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700657 hwc_rect_t displayFrame = layer->displayFrame;
658 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700659
660 cropL = sourceCrop;
661 dstL = displayFrame;
662 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800663 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700664 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
665
666 cropR = sourceCrop;
667 dstR = displayFrame;
668 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800669 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700670 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
671
672 // Sanitize Crop to stitch
673 sanitizeSourceCrop(cropL, cropR, hnd);
674
675 // Calculate the left dst
676 dst_width_l = dstL.right - dstL.left;
677 dst_height_l = dstL.bottom - dstL.top;
678 src_width_l = cropL.right - cropL.left;
679 src_height_l = cropL.bottom - cropL.top;
680
681 // check if there is any scaling on the left
682 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
683 return true;
684
685 // Calculate the right dst
686 dst_width_r = dstR.right - dstR.left;
687 dst_height_r = dstR.bottom - dstR.top;
688 src_width_r = cropR.right - cropR.left;
689 src_height_r = cropR.bottom - cropR.top;
690
691 // check if there is any scaling on the right
692 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
693 return true;
694
695 return false;
696}
697
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530698bool isAlphaScaled(hwc_layer_1_t const* layer) {
699 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530700 return true;
701 }
702 return false;
703}
704
705bool isAlphaPresent(hwc_layer_1_t const* layer) {
706 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400707 if(hnd) {
708 int format = hnd->format;
709 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530710 case HAL_PIXEL_FORMAT_RGBA_8888:
711 case HAL_PIXEL_FORMAT_BGRA_8888:
712 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500713 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530714 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400715 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500716 }
717 return false;
718}
719
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700720static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
721 hwc_rect_t& crop, hwc_rect_t& dst) {
722 int hw_w = ctx->dpyAttr[dpy].xres;
723 int hw_h = ctx->dpyAttr[dpy].yres;
724 if(dst.left < 0 || dst.top < 0 ||
725 dst.right > hw_w || dst.bottom > hw_h) {
726 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800727 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700728 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
729 }
730}
731
732static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
733 const int& dpy) {
734 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
735 hwc_layer_1_t *layer = &list->hwLayers[i];
736 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
737 trimLayer(ctx, dpy,
738 list->hwLayers[i].transform,
739 (hwc_rect_t&)crop,
740 (hwc_rect_t&)list->hwLayers[i].displayFrame);
741 layer->sourceCropf.left = crop.left;
742 layer->sourceCropf.right = crop.right;
743 layer->sourceCropf.top = crop.top;
744 layer->sourceCropf.bottom = crop.bottom;
745 }
746}
747
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700748void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700749 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700750 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
751 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700752 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
753 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700754 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530755 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700756 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800757 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400758 char property[PROPERTY_VALUE_MAX];
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800759 ctx->listStats[dpy].extOnlyLayerIndex = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700760 ctx->listStats[dpy].isDisplayAnimating = false;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700761 ctx->listStats[dpy].roi = ovutils::Dim(0, 0,
762 (int)ctx->dpyAttr[dpy].xres, (int)ctx->dpyAttr[dpy].yres);
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700763 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +0530764 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnandd38b822013-12-04 15:15:42 -0800765 ctx->mViewFrame[dpy] = (hwc_rect_t){0, 0, 0, 0};
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700766
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700767 trimList(ctx, list, dpy);
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +0530768 optimizeLayerRects(ctx, list, dpy);
769
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700770 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500771 hwc_layer_1_t const* layer = &list->hwLayers[i];
772 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700773
Ramkumar Radhakrishnandd38b822013-12-04 15:15:42 -0800774 // Calculate view frame of each display from the layer displayframe
775 ctx->mViewFrame[dpy] = getUnion(ctx->mViewFrame[dpy],
776 layer->displayFrame);
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700777#ifdef QCOM_BSP
778 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
779 ctx->listStats[dpy].isDisplayAnimating = true;
780 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700781 if(isSecureDisplayBuffer(hnd)) {
782 ctx->listStats[dpy].secureUI = true;
783 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700784#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700785 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
786 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700787 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800788
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700789 //reset yuv indices
790 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530791 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700792
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700793 if (isSecureBuffer(hnd)) {
794 ctx->listStats[dpy].isSecurePresent = true;
795 }
796
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700797 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700798 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700799 }
800
801 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800802 int& yuvCount = ctx->listStats[dpy].yuvCount;
803 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
804 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800805
radhakrishnac9a67412013-09-25 17:40:42 +0530806 if(UNLIKELY(is4kx2kYuvBuffer(hnd))){
807 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
808 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = i;
809 yuv4k2kCount++;
810 }
811
Saurabh Shahe2474082013-05-15 16:32:13 -0700812 if((layer->transform & HWC_TRANSFORM_ROT_90) &&
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -0700813 canUseRotator(ctx, dpy)) {
814 if( (dpy == HWC_DISPLAY_PRIMARY) &&
815 ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
Saurabh Shah0ceeb6a2013-04-23 10:46:07 -0700816 ctx->isPaddingRound = true;
817 }
Saurabh Shah85234ec2013-04-12 17:09:00 -0700818 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
819 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700820 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530821 if(layer->blending == HWC_BLENDING_PREMULT)
822 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -0800823
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800824
825 if(UNLIKELY(isExtOnly(hnd))){
826 ctx->listStats[dpy].extOnlyLayerIndex = i;
827 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700828 }
Ping Li9404e2a2013-04-24 16:36:03 -0400829 if(ctx->listStats[dpy].yuvCount > 0) {
830 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
831 if (atoi(property) != 1) {
832 property_set("hw.cabl.yuv", "1");
833 }
834 }
835 } else {
836 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
837 if (atoi(property) != 0) {
838 property_set("hw.cabl.yuv", "0");
839 }
840 }
841 }
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700842 if(dpy) {
843 //uncomment the below code for testing purpose.
844 /* char value[PROPERTY_VALUE_MAX];
845 property_get("sys.ext_orientation", value, "0");
846 // Assuming the orientation value is in terms of HAL_TRANSFORM,
847 // This needs mapping to HAL, if its in different convention
848 ctx->mExtOrientation = atoi(value); */
849 // Assuming the orientation value is in terms of HAL_TRANSFORM,
850 // This needs mapping to HAL, if its in different convention
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700851 if(ctx->mExtOrientation || ctx->mBufferMirrorMode) {
852 ALOGD_IF(HWC_UTILS_DEBUG, "%s: ext orientation = %d"
853 "BufferMirrorMode = %d", __FUNCTION__,
854 ctx->mExtOrientation, ctx->mBufferMirrorMode);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700855 if(ctx->mOverlay->isPipeTypeAttached(OV_MDP_PIPE_DMA)) {
856 ctx->isPaddingRound = true;
857 }
858 Overlay::setDMAMode(Overlay::DMA_BLOCK_MODE);
859 }
860 }
Saurabh Shahd4e65852013-06-17 11:33:53 -0700861
862 //The marking of video begin/end is useful on some targets where we need
863 //to have a padding round to be able to shift pipes across mixers.
864 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
865 ctx->mVideoTransFlag = true;
866 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700867 if(dpy == HWC_DISPLAY_PRIMARY) {
868 ctx->mAD->markDoable(ctx, list);
869 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700870}
871
Naseer Ahmed018e5452012-12-03 14:46:15 -0500872
Saurabh Shah68107422013-07-09 11:12:42 -0700873static void calc_cut(double& leftCutRatio, double& topCutRatio,
874 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700875 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700876 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700877 }
878 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700879 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700880 }
881 if(orient & HAL_TRANSFORM_ROT_90) {
882 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -0700883 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -0700884 leftCutRatio = topCutRatio;
885 topCutRatio = rightCutRatio;
886 rightCutRatio = bottomCutRatio;
887 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700888 }
889}
890
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800891bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500892 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
893 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
894 ctx->mSecuring) {
895 return true;
896 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800897 if (isSecureModePolicy(ctx->mMDP.version)) {
898 private_handle_t *hnd = (private_handle_t *)layer->handle;
899 if(ctx->mSecureMode) {
900 if (! isSecureBuffer(hnd)) {
901 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
902 __FUNCTION__);
903 return true;
904 }
905 } else {
906 if (isSecureBuffer(hnd)) {
907 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
908 __FUNCTION__);
909 return true;
910 }
911 }
912 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500913 return false;
914}
915
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800916bool isSecureModePolicy(int mdpVersion) {
917 if (mdpVersion < qdutils::MDSS_V5)
918 return true;
919 else
920 return false;
921}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500922
Naseer Ahmed522ce662013-03-18 20:14:05 -0400923int getBlending(int blending) {
924 switch(blending) {
925 case HWC_BLENDING_NONE:
926 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
927 case HWC_BLENDING_PREMULT:
928 return overlay::utils::OVERLAY_BLENDING_PREMULT;
929 case HWC_BLENDING_COVERAGE :
930 default:
931 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
932 }
933}
934
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700935//Crops source buffer against destination and FB boundaries
936void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800937 const hwc_rect_t& scissor, int orient) {
938
Saurabh Shah27c1d652012-08-14 19:30:28 -0700939 int& crop_l = crop.left;
940 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700941 int& crop_r = crop.right;
942 int& crop_b = crop.bottom;
943 int crop_w = crop.right - crop.left;
944 int crop_h = crop.bottom - crop.top;
945
Saurabh Shah27c1d652012-08-14 19:30:28 -0700946 int& dst_l = dst.left;
947 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700948 int& dst_r = dst.right;
949 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700950 int dst_w = abs(dst.right - dst.left);
951 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700952
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800953 const int& sci_l = scissor.left;
954 const int& sci_t = scissor.top;
955 const int& sci_r = scissor.right;
956 const int& sci_b = scissor.bottom;
957 int sci_w = abs(sci_r - sci_l);
958 int sci_h = abs(sci_b - sci_t);
959
Saurabh Shah68107422013-07-09 11:12:42 -0700960 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
961 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700962
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800963 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -0700964 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800965 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700966 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800967
968 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -0700969 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700971 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800972
973 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -0700974 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800975 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700976 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800977
978 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -0700979 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800980 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700981 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700982
Saurabh Shah541b59d2012-10-11 11:08:12 -0700983 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
984 crop_l += crop_w * leftCutRatio;
985 crop_t += crop_h * topCutRatio;
986 crop_r -= crop_w * rightCutRatio;
987 crop_b -= crop_h * bottomCutRatio;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700988}
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700989
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +0530990bool areLayersIntersecting(const hwc_layer_1_t* layer1,
991 const hwc_layer_1_t* layer2) {
992 hwc_rect_t irect = getIntersection(layer1->displayFrame,
993 layer2->displayFrame);
994 return isValidRect(irect);
995}
996
Jeykumar Sankaran6a585792013-10-03 11:30:55 -0700997bool isValidRect(const hwc_rect& rect)
998{
999 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301000}
1001
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001002/* computes the intersection of two rects */
1003hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1004{
1005 hwc_rect_t res;
1006
1007 if(!isValidRect(rect1) || !isValidRect(rect2)){
1008 return (hwc_rect_t){0, 0, 0, 0};
1009 }
1010
1011
1012 res.left = max(rect1.left, rect2.left);
1013 res.top = max(rect1.top, rect2.top);
1014 res.right = min(rect1.right, rect2.right);
1015 res.bottom = min(rect1.bottom, rect2.bottom);
1016
1017 if(!isValidRect(res))
1018 return (hwc_rect_t){0, 0, 0, 0};
1019
1020 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301021}
1022
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001023/* computes the union of two rects */
1024hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1025{
1026 hwc_rect_t res;
1027
1028 if(!isValidRect(rect1)){
1029 return rect2;
1030 }
1031
1032 if(!isValidRect(rect2)){
1033 return rect1;
1034 }
1035
1036 res.left = min(rect1.left, rect2.left);
1037 res.top = min(rect1.top, rect2.top);
1038 res.right = max(rect1.right, rect2.right);
1039 res.bottom = max(rect1.bottom, rect2.bottom);
1040
1041 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301042}
1043
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001044/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1045 * a single rect */
1046hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301047
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001048 hwc_rect_t res = rect1;
1049
1050 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1051 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1052 res.top = rect2.bottom;
1053 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1054 res.bottom = rect2.top;
1055 }
1056 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1057 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1058 res.left = rect2.right;
1059 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1060 res.right = rect2.left;
1061 }
1062 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301063}
1064
1065void optimizeLayerRects(hwc_context_t *ctx,
1066 const hwc_display_contents_1_t *list, const int& dpy) {
1067 int i=list->numHwLayers-2;
1068 hwc_rect_t irect;
1069 while(i > 0) {
1070
1071 //see if there is no blending required.
1072 //If it is opaque see if we can substract this region from below layers.
1073 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1074 int j= i-1;
1075 hwc_rect_t& topframe =
1076 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1077 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301078 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001079 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1080 hwc_rect_t& bottomframe = layer->displayFrame;
1081 hwc_rect_t& bottomCrop = layer->sourceCrop;
1082 int transform =layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001083
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001084 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1085 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001086 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001087 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001088 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001089 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001090 dest_rect, transform);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001091
1092 }
1093 }
1094 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301095 }
1096 }
1097 i--;
1098 }
1099}
1100
Naseer Ahmed64b81212013-02-14 10:29:47 -05001101void getNonWormholeRegion(hwc_display_contents_1_t* list,
1102 hwc_rect_t& nwr)
1103{
1104 uint32_t last = list->numHwLayers - 1;
1105 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1106 //Initiliaze nwr to first frame
1107 nwr.left = list->hwLayers[0].displayFrame.left;
1108 nwr.top = list->hwLayers[0].displayFrame.top;
1109 nwr.right = list->hwLayers[0].displayFrame.right;
1110 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1111
1112 for (uint32_t i = 1; i < last; i++) {
1113 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001114 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001115 }
1116
1117 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001118 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001119}
1120
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001121bool isExternalActive(hwc_context_t* ctx) {
1122 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001123}
1124
Saurabh Shah747af1e2013-02-26 10:25:12 -08001125void closeAcquireFds(hwc_display_contents_1_t* list) {
1126 for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
1127 //Close the acquireFenceFds
1128 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1129 if(list->hwLayers[i].acquireFenceFd >= 0) {
1130 close(list->hwLayers[i].acquireFenceFd);
1131 list->hwLayers[i].acquireFenceFd = -1;
1132 }
1133 }
1134}
1135
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001136int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001137 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001138 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001139 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001140 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001141 int count = 0;
1142 int releaseFd = -1;
1143 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001144 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001145 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
1146
1147 struct mdp_buf_sync data;
1148 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001149 data.acq_fen_fd = acquireFd;
1150 data.rel_fen_fd = &releaseFd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001151
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001152 char property[PROPERTY_VALUE_MAX];
1153 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1154 if(atoi(property) == 0)
1155 swapzero = true;
1156 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001157
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001158 bool isExtAnimating = false;
1159 if(dpy)
1160 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001161
Saurabh Shah23a813c2013-03-20 16:58:12 -07001162 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001163 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001164 int rotFd = ctx->mRotMgr->getRotDevFd();
1165 int rotReleaseFd = -1;
1166 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001167 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001168 rotData.acq_fen_fd =
1169 &ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd;
1170 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Saurabh Shah23a813c2013-03-20 16:58:12 -07001171 rotData.session_id = ctx->mLayerRotMap[dpy]->getRot(i)->getSessId();
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001172 int ret = 0;
1173 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1174 if(ret < 0) {
1175 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1176 __FUNCTION__, strerror(errno));
1177 } else {
1178 close(ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd);
1179 //For MDP to wait on.
1180 ctx->mLayerRotMap[dpy]->getLayer(i)->acquireFenceFd =
1181 dup(rotReleaseFd);
1182 //A buffer is free to be used by producer as soon as its copied to
1183 //rotator
1184 ctx->mLayerRotMap[dpy]->getLayer(i)->releaseFenceFd =
1185 rotReleaseFd;
1186 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001187 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001188
1189 //Accumulate acquireFenceFds for MDP
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001190 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Terence Hampsonc67b0372013-10-09 11:32:21 -04001191 if((list->hwLayers[i].compositionType == HWC_OVERLAY ||
1192 list->hwLayers[i].compositionType == HWC_BLIT) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001193 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001194 if(UNLIKELY(swapzero))
1195 acquireFd[count++] = -1;
1196 else
1197 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001198 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001199 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1200 if(UNLIKELY(swapzero))
1201 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001202 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001203 //set the acquireFD from fd - which is coming from c2d
1204 acquireFd[count++] = fd;
1205 // Buffer sync IOCTL should be async when using c2d fence is
1206 // used
1207 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001208 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001209 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1210 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001211 }
1212
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001213 data.acq_fen_fd_cnt = count;
1214 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001215
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001216 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001217 if(LIKELY(!swapzero)) {
1218 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001219 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001220 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
1221 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
1222 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001223
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001224 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001225 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1226 __FUNCTION__, strerror(errno));
1227 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
1228 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1229 dpy, list->numHwLayers);
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001230 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001231
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001232 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001233 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Terence Hampsonc67b0372013-10-09 11:32:21 -04001234 list->hwLayers[i].compositionType == HWC_BLIT ||
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001235 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001236 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001237 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001238 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001239 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001240 // Release all the app layer fds immediately,
1241 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001242 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001243 } else if(list->hwLayers[i].releaseFenceFd < 0) {
1244 //If rotator has not already populated this field.
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001245 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001246 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001247 }
1248 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001249
1250 if(fd >= 0) {
1251 close(fd);
1252 fd = -1;
1253 }
1254
Naseer Ahmed64b81212013-02-14 10:29:47 -05001255 if (ctx->mCopyBit[dpy])
1256 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001257
Saurabh Shah23a813c2013-03-20 16:58:12 -07001258 //Signals when MDP finishes reading rotator buffers.
1259 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001260
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001261 // if external is animating, close the relaseFd
1262 if(isExtAnimating) {
1263 close(releaseFd);
1264 releaseFd = -1;
1265 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001266
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001267 if(UNLIKELY(swapzero)){
1268 list->retireFenceFd = -1;
1269 close(releaseFd);
1270 } else {
1271 list->retireFenceFd = releaseFd;
1272 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001273
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001274 return ret;
1275}
1276
Saurabh Shahacf10202013-02-26 10:15:15 -08001277void setMdpFlags(hwc_layer_1_t *layer,
1278 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001279 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001280 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001281 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001282
1283 if(layer->blending == HWC_BLENDING_PREMULT) {
1284 ovutils::setMdpFlags(mdpFlags,
1285 ovutils::OV_MDP_BLEND_FG_PREMULT);
1286 }
1287
1288 if(isYuvBuffer(hnd)) {
1289 if(isSecureBuffer(hnd)) {
1290 ovutils::setMdpFlags(mdpFlags,
1291 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1292 }
1293 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1294 metadata->interlaced) {
1295 ovutils::setMdpFlags(mdpFlags,
1296 ovutils::OV_MDP_DEINTERLACE);
1297 }
1298 //Pre-rotation will be used using rotator.
1299 if(transform & HWC_TRANSFORM_ROT_90) {
1300 ovutils::setMdpFlags(mdpFlags,
1301 ovutils::OV_MDP_SOURCE_ROTATED_90);
1302 }
1303 }
1304
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001305 if(isSecureDisplayBuffer(hnd)) {
1306 // Secure display needs both SECURE_OVERLAY and SECURE_DISPLAY_OV
1307 ovutils::setMdpFlags(mdpFlags,
1308 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1309 ovutils::setMdpFlags(mdpFlags,
1310 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1311 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001312 //No 90 component and no rot-downscale then flips done by MDP
1313 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001314 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1315 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001316 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1317 }
1318
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001319 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001320 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1321 }
1322 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001323
1324 if(metadata &&
1325 ((metadata->operation & PP_PARAM_HSIC)
1326 || (metadata->operation & PP_PARAM_IGC)
1327 || (metadata->operation & PP_PARAM_SHARP2))) {
1328 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1329 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001330}
1331
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301332int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001333 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001334 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001335
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301336 // Fix alignments for TILED format
1337 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1338 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1339 whf.w = utils::alignup(whf.w, 64);
1340 whf.h = utils::alignup(whf.h, 32);
1341 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001342 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001343
1344 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1345 qdutils::MDSS_V5) {
1346 uint32_t crop_w = (crop.right - crop.left);
1347 uint32_t crop_h = (crop.bottom - crop.top);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001348 if (ovutils::isYuv(whf.format)) {
1349 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
1350 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -07001351 // For interlaced, crop.h should be 4-aligned
1352 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
1353 crop_h = ovutils::aligndown(crop_h, 4);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001354 crop.right = crop.left + crop_w;
1355 crop.bottom = crop.top + crop_h;
1356 }
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001357 Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
1358 rot->setCrop(rotCrop);
1359 }
1360
Saurabh Shahacf10202013-02-26 10:15:15 -08001361 rot->setFlags(mdpFlags);
1362 rot->setTransform(orient);
1363 rot->setDownscale(downscale);
1364 if(!rot->commit()) return -1;
1365 return 0;
1366}
1367
Saurabh Shahe2474082013-05-15 16:32:13 -07001368int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001369 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001370 const hwc_rect_t& pos, const MetaData_t *metadata,
1371 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001372 ov->setSource(parg, dest);
1373 ov->setTransform(orient, dest);
1374
1375 int crop_w = crop.right - crop.left;
1376 int crop_h = crop.bottom - crop.top;
1377 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1378 ov->setCrop(dcrop, dest);
1379
1380 int posW = pos.right - pos.left;
1381 int posH = pos.bottom - pos.top;
1382 Dim position(pos.left, pos.top, posW, posH);
1383 ov->setPosition(position, dest);
1384
Saurabh Shah5daeee52013-01-23 16:52:26 +08001385 if (metadata)
1386 ov->setVisualParams(*metadata, dest);
1387
Saurabh Shahacf10202013-02-26 10:15:15 -08001388 if (!ov->commit(dest)) {
1389 return -1;
1390 }
1391 return 0;
1392}
1393
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001394int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1395 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1396 eIsFg& isFg, const eDest& dest) {
1397
1398 hwc_rect_t dst = layer->displayFrame;
1399 trimLayer(ctx, dpy, 0, dst, dst);
1400
1401 int w = ctx->dpyAttr[dpy].xres;
1402 int h = ctx->dpyAttr[dpy].yres;
1403 int dst_w = dst.right - dst.left;
1404 int dst_h = dst.bottom - dst.top;
1405 uint32_t color = layer->transform;
1406 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1407
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001408 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001409 if (layer->blending == HWC_BLENDING_PREMULT)
1410 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1411
1412 PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(0),
1413 layer->planeAlpha,
1414 (ovutils::eBlending) getBlending(layer->blending));
1415
1416 // Configure MDP pipe for Color layer
1417 Dim pos(dst.left, dst.top, dst_w, dst_h);
1418 ctx->mOverlay->setSource(parg, dest);
1419 ctx->mOverlay->setColor(color, dest);
1420 ctx->mOverlay->setTransform(0, dest);
1421 ctx->mOverlay->setCrop(pos, dest);
1422 ctx->mOverlay->setPosition(pos, dest);
1423
1424 if (!ctx->mOverlay->commit(dest)) {
1425 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1426 return -1;
1427 }
1428 return 0;
1429}
1430
Saurabh Shahe2474082013-05-15 16:32:13 -07001431void updateSource(eTransform& orient, Whf& whf,
Saurabh Shahacf10202013-02-26 10:15:15 -08001432 hwc_rect_t& crop) {
1433 Dim srcCrop(crop.left, crop.top,
1434 crop.right - crop.left,
1435 crop.bottom - crop.top);
Saurabh Shah76fd6552013-03-14 14:45:38 -07001436 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
Saurabh Shahacf10202013-02-26 10:15:15 -08001437 preRotateSource(orient, whf, srcCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001438 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1439 qdutils::MDSS_V5) {
1440 // Source for overlay will be the cropped (and rotated)
1441 crop.left = 0;
1442 crop.top = 0;
1443 crop.right = srcCrop.w;
1444 crop.bottom = srcCrop.h;
1445 // Set width & height equal to sourceCrop w & h
1446 whf.w = srcCrop.w;
1447 whf.h = srcCrop.h;
1448 } else {
1449 crop.left = srcCrop.x;
1450 crop.top = srcCrop.y;
1451 crop.right = srcCrop.x + srcCrop.w;
1452 crop.bottom = srcCrop.y + srcCrop.h;
1453 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001454}
1455
Saurabh Shah88e4d272013-09-03 13:31:29 -07001456int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001457 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1458 eIsFg& isFg, const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001459
1460 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001461
Saurabh Shahacf10202013-02-26 10:15:15 -08001462 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001463 if (layer->flags & HWC_COLOR_FILL) {
1464 // Configure Color layer
1465 return configColorLayer(ctx, layer, dpy, mdpFlags, z, isFg, dest);
1466 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001467 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1468 return -1;
1469 }
1470
Saurabh Shah5daeee52013-01-23 16:52:26 +08001471 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1472
Saurabh Shah62e1d732013-09-17 10:44:05 -07001473 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001474 hwc_rect_t dst = layer->displayFrame;
1475 int transform = layer->transform;
1476 eTransform orient = static_cast<eTransform>(transform);
1477 int downscale = 0;
1478 int rotFlags = ovutils::ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001479 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1480 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
Saurabh Shahacf10202013-02-26 10:15:15 -08001481
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001482 // Handle R/B swap
1483 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1484 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1485 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1486 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1487 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1488 }
1489
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08001490 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -07001491
Saurabh Shahacf10202013-02-26 10:15:15 -08001492 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001493 ctx->mMDP.version < qdutils::MDSS_V5) {
1494 downscale = getDownscaleFactor(
1495 crop.right - crop.left,
1496 crop.bottom - crop.top,
1497 dst.right - dst.left,
1498 dst.bottom - dst.top);
Saurabh Shahacf10202013-02-26 10:15:15 -08001499 if(downscale) {
1500 rotFlags = ROT_DOWNSCALE_ENABLED;
1501 }
1502 }
1503
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001504 setMdpFlags(layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001505
1506 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
1507 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
1508 *rot = ctx->mRotMgr->getNext();
1509 if(*rot == NULL) return -1;
Tatenda Chipeperekwa88562702013-10-19 19:56:16 -07001510 if(!dpy)
1511 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001512 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001513 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1514 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001515 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001516 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001517 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001518 whf.format = (*rot)->getDstFormat();
1519 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001520 rotFlags |= ovutils::ROT_PREROTATED;
1521 }
1522
Saurabh Shah76fd6552013-03-14 14:45:38 -07001523 //For the mdp, since either we are pre-rotating or MDP does flips
1524 orient = OVERLAY_TRANSFORM_0;
1525 transform = 0;
Naseer Ahmed522ce662013-03-18 20:14:05 -04001526 PipeArgs parg(mdpFlags, whf, z, isFg,
1527 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1528 (ovutils::eBlending) getBlending(layer->blending));
1529
Saurabh Shah5daeee52013-01-23 16:52:26 +08001530 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001531 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
1532 return -1;
1533 }
1534 return 0;
1535}
1536
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001537//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001538void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001539 private_handle_t *hnd) {
1540 if(cropL.right - cropL.left) {
1541 if(isYuvBuffer(hnd)) {
1542 //Always safe to even down left
1543 ovutils::even_floor(cropL.left);
1544 //If right is even, automatically width is even, since left is
1545 //already even
1546 ovutils::even_floor(cropL.right);
1547 }
1548 //Make sure there are no gaps between left and right splits if the layer
1549 //is spread across BOTH halves
1550 if(cropR.right - cropR.left) {
1551 cropR.left = cropL.right;
1552 }
1553 }
1554
1555 if(cropR.right - cropR.left) {
1556 if(isYuvBuffer(hnd)) {
1557 //Always safe to even down left
1558 ovutils::even_floor(cropR.left);
1559 //If right is even, automatically width is even, since left is
1560 //already even
1561 ovutils::even_floor(cropR.right);
1562 }
1563 }
1564}
1565
Saurabh Shah88e4d272013-09-03 13:31:29 -07001566int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001567 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1568 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001569 Rotator **rot) {
1570 private_handle_t *hnd = (private_handle_t *)layer->handle;
1571 if(!hnd) {
1572 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1573 return -1;
1574 }
1575
Saurabh Shah5daeee52013-01-23 16:52:26 +08001576 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1577
Saurabh Shahacf10202013-02-26 10:15:15 -08001578 int hw_w = ctx->dpyAttr[dpy].xres;
1579 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07001580 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001581 hwc_rect_t dst = layer->displayFrame;
1582 int transform = layer->transform;
1583 eTransform orient = static_cast<eTransform>(transform);
1584 const int downscale = 0;
1585 int rotFlags = ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001586 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1587 Whf whf(getWidth(hnd), getHeight(hnd), format, hnd->size);
Saurabh Shahacf10202013-02-26 10:15:15 -08001588
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001589 // Handle R/B swap
1590 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1591 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1592 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1593 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1594 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1595 }
1596
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -07001597 setMdpFlags(layer, mdpFlagsL, 0, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001598
1599 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1600 //Enable overfetch
1601 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1602 }
1603
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001604 //Will do something only if feature enabled and conditions suitable
1605 //hollow call otherwise
1606 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
1607 overlay::Writeback *wb = overlay::Writeback::getInstance();
1608 whf.format = wb->getOutputFormat();
1609 }
1610
Saurabh Shahacf10202013-02-26 10:15:15 -08001611 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1612 (*rot) = ctx->mRotMgr->getNext();
1613 if((*rot) == NULL) return -1;
1614 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001615 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1616 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001617 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001618 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001619 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001620 whf.format = (*rot)->getDstFormat();
1621 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001622 rotFlags |= ROT_PREROTATED;
1623 }
1624
1625 eMdpFlags mdpFlagsR = mdpFlagsL;
1626 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1627
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001628 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1629 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08001630
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001631 const int lSplit = getLeftSplit(ctx, dpy);
1632
Saurabh Shahacf10202013-02-26 10:15:15 -08001633 if(lDest != OV_INVALID) {
1634 tmp_cropL = crop;
1635 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001636 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001637 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001638 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1639 }
1640 if(rDest != OV_INVALID) {
1641 tmp_cropR = crop;
1642 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001643 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001644 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001645 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1646 }
1647
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001648 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1649
Saurabh Shah94d62362013-07-02 10:58:48 -07001650 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08001651 //Not needed if the layer is confined to one half of the screen.
1652 //If rotator has been used then it has also done the flips, so ignore them.
Saurabh Shah94d62362013-07-02 10:58:48 -07001653 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
Ramkumar Radhakrishnanfe7ce802013-04-30 11:19:17 -07001654 && rDest != OV_INVALID && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001655 hwc_rect_t new_cropR;
1656 new_cropR.left = tmp_cropL.left;
1657 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1658
1659 hwc_rect_t new_cropL;
1660 new_cropL.left = new_cropR.right;
1661 new_cropL.right = tmp_cropR.right;
1662
1663 tmp_cropL.left = new_cropL.left;
1664 tmp_cropL.right = new_cropL.right;
1665
1666 tmp_cropR.left = new_cropR.left;
1667 tmp_cropR.right = new_cropR.right;
1668
1669 }
1670
Saurabh Shah76fd6552013-03-14 14:45:38 -07001671 //For the mdp, since either we are pre-rotating or MDP does flips
1672 orient = OVERLAY_TRANSFORM_0;
1673 transform = 0;
1674
Saurabh Shahacf10202013-02-26 10:15:15 -08001675 //configure left mixer
1676 if(lDest != OV_INVALID) {
1677 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001678 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1679 (ovutils::eBlending) getBlending(layer->blending));
1680
Saurabh Shahacf10202013-02-26 10:15:15 -08001681 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001682 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001683 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1684 return -1;
1685 }
1686 }
1687
1688 //configure right mixer
1689 if(rDest != OV_INVALID) {
1690 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001691 static_cast<eRotFlags>(rotFlags),
1692 layer->planeAlpha,
1693 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07001694 tmp_dstR.right = tmp_dstR.right - lSplit;
1695 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001696 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001697 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001698 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1699 return -1;
1700 }
1701 }
1702
1703 return 0;
1704}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08001705
radhakrishnac9a67412013-09-25 17:40:42 +05301706int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
1707 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1708 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
1709 Rotator **rot) {
1710 private_handle_t *hnd = (private_handle_t *)layer->handle;
1711 if(!hnd) {
1712 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1713 return -1;
1714 }
1715
1716 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1717
1718 int hw_w = ctx->dpyAttr[dpy].xres;
1719 int hw_h = ctx->dpyAttr[dpy].yres;
1720 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
1721 hwc_rect_t dst = layer->displayFrame;
1722 int transform = layer->transform;
1723 eTransform orient = static_cast<eTransform>(transform);
1724 const int downscale = 0;
1725 int rotFlags = ROT_FLAGS_NONE;
1726 //Splitting only YUV layer on primary panel needs different zorders
1727 //for both layers as both the layers are configured to single mixer
1728 eZorder lz = z;
1729 eZorder rz = (eZorder)(z + 1);
1730
1731 Whf whf(getWidth(hnd), getHeight(hnd),
1732 getMdpFormat(hnd->format), hnd->size);
1733
1734 setMdpFlags(layer, mdpFlagsL, 0, transform);
1735 trimLayer(ctx, dpy, transform, crop, dst);
1736
1737 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1738 (*rot) = ctx->mRotMgr->getNext();
1739 if((*rot) == NULL) return -1;
1740 if(!dpy)
1741 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlagsL);
1742 //Configure rotator for pre-rotation
1743 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1744 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05301745 return -1;
1746 }
1747 ctx->mLayerRotMap[dpy]->add(layer, *rot);
1748 whf.format = (*rot)->getDstFormat();
1749 updateSource(orient, whf, crop);
1750 rotFlags |= ROT_PREROTATED;
1751 }
1752
1753 eMdpFlags mdpFlagsR = mdpFlagsL;
1754 int lSplit = dst.left + (dst.right - dst.left)/2;
1755
1756 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1757 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
1758
1759 if(lDest != OV_INVALID) {
1760 tmp_cropL = crop;
1761 tmp_dstL = dst;
1762 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
1763 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1764 }
1765 if(rDest != OV_INVALID) {
1766 tmp_cropR = crop;
1767 tmp_dstR = dst;
1768 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
1769 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1770 }
1771
1772 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1773
1774 //When buffer is H-flipped, contents of mixer config also needs to swapped
1775 //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.
1777 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1778 && rDest != OV_INVALID && (*rot) == NULL) {
1779 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
1795 //For the mdp, since either we are pre-rotating or MDP does flips
1796 orient = OVERLAY_TRANSFORM_0;
1797 transform = 0;
1798
1799 //configure left half
1800 if(lDest != OV_INVALID) {
1801 PipeArgs pargL(mdpFlagsL, whf, lz, isFg,
1802 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1803 (ovutils::eBlending) getBlending(layer->blending));
1804
1805 if(configMdp(ctx->mOverlay, pargL, orient,
1806 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1807 ALOGE("%s: commit failed for left half config", __FUNCTION__);
1808 return -1;
1809 }
1810 }
1811
1812 //configure right half
1813 if(rDest != OV_INVALID) {
1814 PipeArgs pargR(mdpFlagsR, whf, rz, isFg,
1815 static_cast<eRotFlags>(rotFlags),
1816 layer->planeAlpha,
1817 (ovutils::eBlending) getBlending(layer->blending));
1818 if(configMdp(ctx->mOverlay, pargR, orient,
1819 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1820 ALOGE("%s: commit failed for right half config", __FUNCTION__);
1821 return -1;
1822 }
1823 }
1824
1825 return 0;
1826}
1827
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001828bool canUseRotator(hwc_context_t *ctx, int dpy) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001829 if(qdutils::MDPVersion::getInstance().is8x26() &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07001830 ctx->mVirtualDisplay->isConnected() &&
1831 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamala8c065f2013-10-22 14:52:45 +05301832 /* 8x26 mdss driver supports multiplexing of DMA pipe
1833 * in LINE and BLOCK modes for writeback panels.
1834 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001835 if(dpy == HWC_DISPLAY_PRIMARY)
1836 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001837 }
Terence Hampson45c02ef2013-05-17 17:00:11 -04001838 if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1839 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001840 return true;
1841}
1842
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001843int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1844 //Default even split for all displays with high res
1845 int lSplit = ctx->dpyAttr[dpy].xres / 2;
1846 if(dpy == HWC_DISPLAY_PRIMARY &&
1847 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1848 //Override if split published by driver for primary
1849 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1850 }
1851 return lSplit;
1852}
Saurabh Shah1a03d482013-05-29 13:44:20 -07001853
Saurabh Shah88e4d272013-09-03 13:31:29 -07001854bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
1855 if(ctx->dpyAttr[dpy].xres > qdutils::MAX_DISPLAY_DIM) {
1856 return true;
1857 }
1858 //For testing we could split primary via device tree values
1859 if(dpy == HWC_DISPLAY_PRIMARY &&
1860 qdutils::MDPVersion::getInstance().getRightSplit()) {
1861 return true;
1862 }
1863 return false;
1864}
1865
Saurabh Shah1a03d482013-05-29 13:44:20 -07001866void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1867 const hwc_rect_t& dst, const int& transform,
1868 ovutils::eMdpFlags& mdpFlags) {
1869 //Target doesnt support Bwc
1870 if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
1871 return;
1872 }
1873 //src width > MAX mixer supported dim
1874 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
1875 return;
1876 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07001877 //Decimation necessary, cannot use BWC. H/W requirement.
1878 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
1879 int src_w = crop.right - crop.left;
1880 int src_h = crop.bottom - crop.top;
1881 int dst_w = dst.right - dst.left;
1882 int dst_h = dst.bottom - dst.top;
1883 if(transform & HAL_TRANSFORM_ROT_90) {
1884 swap(src_w, src_h);
1885 }
1886 float horDscale = 0.0f;
1887 float verDscale = 0.0f;
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07001888 int horzDeci = 0;
1889 int vertDeci = 0;
Saurabh Shah1a03d482013-05-29 13:44:20 -07001890 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
1891 verDscale);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07001892 //TODO Use log2f once math.h has it
1893 if((int)horDscale)
1894 horzDeci = (int)(log(horDscale) / log(2));
1895 if((int)verDscale)
1896 vertDeci = (int)(log(verDscale) / log(2));
1897 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07001898 }
1899 //Property
1900 char value[PROPERTY_VALUE_MAX];
1901 property_get("debug.disable.bwc", value, "0");
1902 if(atoi(value)) return;
1903
1904 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
1905}
1906
Saurabh Shah23a813c2013-03-20 16:58:12 -07001907void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
1908 if(mCount >= MAX_SESS) return;
1909 mLayer[mCount] = layer;
1910 mRot[mCount] = rot;
1911 mCount++;
1912}
1913
1914void LayerRotMap::reset() {
1915 for (int i = 0; i < MAX_SESS; i++) {
1916 mLayer[i] = 0;
1917 mRot[i] = 0;
1918 }
1919 mCount = 0;
1920}
1921
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001922void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08001923 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08001924 reset();
1925}
1926
Saurabh Shah23a813c2013-03-20 16:58:12 -07001927void LayerRotMap::setReleaseFd(const int& fence) {
1928 for(uint32_t i = 0; i < mCount; i++) {
1929 mRot[i]->setReleaseFd(dup(fence));
1930 }
1931}
1932
Saurabh Shahacf10202013-02-26 10:15:15 -08001933};//namespace qhwc