blob: 41358be77b6b53e1e3f59a3d72ca055fc7a5f135 [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"
Tatenda Chipeperekwa266ef782014-03-05 13:02:24 -080046#include "qd_utils.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080047
48using namespace qClient;
49using namespace qService;
50using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080051using namespace overlay;
52using namespace overlay::utils;
53namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080054
Ramkumar Radhakrishnan9c9a94b2014-03-14 17:28:14 -070055#ifdef __cplusplus
56extern "C" {
57#endif
58
59EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
60 EGLint *attrib_list);
61#define EGL_GPU_HINT_1 0x32D0
62#define EGL_GPU_HINT_2 0x32D1
63
64#define EGL_GPU_LEVEL_0 0x0
65#define EGL_GPU_LEVEL_1 0x1
66#define EGL_GPU_LEVEL_2 0x2
67#define EGL_GPU_LEVEL_3 0x3
68#define EGL_GPU_LEVEL_4 0x4
69#define EGL_GPU_LEVEL_5 0x5
70
71#ifdef __cplusplus
72}
73#endif
74
Naseer Ahmed29a26812012-06-14 00:56:20 -070075namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070076
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080077static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -070078{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080079 struct fb_fix_screeninfo finfo;
80 struct fb_var_screeninfo info;
81
82 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053083 if(fb_fd < 0) {
84 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080085 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +053086 }
87
88 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
89 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
90 strerror(errno));
91 close(fb_fd);
92 return -errno;
93 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -080094
95 if (int(info.width) <= 0 || int(info.height) <= 0) {
96 // the driver doesn't return that information
97 // default to 160 dpi
98 info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
99 info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700100 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800101
102 float xdpi = (info.xres * 25.4f) / info.width;
103 float ydpi = (info.yres * 25.4f) / info.height;
104
105#ifdef MSMFB_METADATA_GET
106 struct msmfb_metadata metadata;
107 memset(&metadata, 0 , sizeof(metadata));
108 metadata.op = metadata_op_frame_rate;
109
110 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530111 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
112 strerror(errno));
113 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800114 return -errno;
115 }
116
117 float fps = metadata.data.panel_frame_rate;
118#else
119 //XXX: Remove reserved field usage on all baselines
120 //The reserved[3] field is used to store FPS by the driver.
121 float fps = info.reserved[3] & 0xFF;
122#endif
123
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530124 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
125 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
126 strerror(errno));
127 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800128 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530129 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800130
131 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
132 //xres, yres may not be 32 aligned
133 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
134 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
135 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
136 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
137 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
138 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps;
139
Naseer Ahmed22616d92013-05-15 17:20:26 -0400140 //Unblank primary on first boot
141 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
142 ALOGE("%s: Failed to unblank display", __FUNCTION__);
143 return -errno;
144 }
145 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
146
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800147 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700148}
149
Naseer Ahmed29a26812012-06-14 00:56:20 -0700150void initContext(hwc_context_t *ctx)
151{
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700152 openFramebufferDevice(ctx);
Raj kamal9af062e2014-04-01 16:52:19 +0530153 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700154 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
155 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
156 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800157 overlay::Overlay::initOverlay();
158 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800159 ctx->mRotMgr = RotMgr::getInstance();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800160
Saurabh Shahcf053c62012-12-13 12:32:55 -0800161 //Is created and destroyed only once for primary
162 //For external it could get created and destroyed multiple times depending
163 //on what external we connect to.
164 ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700165 IFBUpdate::getObject(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800166
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800167 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800168 // decide if we need to open the copybit module.
169 int compositionType =
170 qdutils::QCCompositionType::getInstance().getCompositionType();
171
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800172 // Only MDP copybit is used
173 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
174 qdutils::COMPOSITION_TYPE_MDP)) &&
175 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
176 qdutils::MDP_V3_0_4)) {
177 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
178 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800179 }
180
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700181 ctx->mExtDisplay = new ExternalDisplay(ctx);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700182 ctx->mVirtualDisplay = new VirtualDisplay(ctx);
183 ctx->mVirtualonExtActive = false;
184 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
185 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
186 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
187 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700188 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mDownScaleMode= false;
189 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mDownScaleMode = false;
190 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800191
192 ctx->mMDPComp[HWC_DISPLAY_PRIMARY] =
Saurabh Shah88e4d272013-09-03 13:31:29 -0700193 MDPComp::getObject(ctx, HWC_DISPLAY_PRIMARY);
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700194 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800195
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700196 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700197 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700198 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700199 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800200 ctx->dpyAttr[i].mActionSafePresent = false;
201 ctx->dpyAttr[i].mAsWidthRatio = 0;
202 ctx->dpyAttr[i].mAsHeightRatio = 0;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700203 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700204
Raj Kamalfc5b9222014-02-07 16:15:17 +0530205 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
206 ctx->mPrevHwLayerCount[i] = 0;
207 }
208
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500209 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700210 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700211
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400212 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500213 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700214 ctx->mExtOrientation = 0;
Raj Kamal1cbe8392014-01-27 19:35:13 +0530215 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800216
217 //Right now hwc starts the service but anybody could do it, or it could be
218 //independent process as well.
219 QService::init();
220 sp<IQClient> client = new QClient(ctx);
221 interface_cast<IQService>(
222 defaultServiceManager()->getService(
223 String16("display.qservice")))->connect(client);
224
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700225 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700226 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700227 ctx->mBufferMirrorMode = false;
Tatenda Chipeperekwa093a0b62014-02-20 19:07:01 -0800228 ctx->mVPUClient = NULL;
229
230 // Read the system property to determine if downscale feature is enabled.
231 ctx->mMDPDownscaleEnabled = false;
Tatenda Chipeperekwa093a0b62014-02-20 19:07:01 -0800232 if(property_get("sys.hwc.mdp_downscale_enabled", value, "false")
233 && !strcmp(value, "true")) {
234 ctx->mMDPDownscaleEnabled = true;
235 }
236
Naseer Ahmed58780b92013-07-29 17:41:40 -0400237#ifdef VPU_TARGET
238 ctx->mVPUClient = new VPUClient();
239#endif
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700240
Ramkumar Radhakrishnan9c9a94b2014-03-14 17:28:14 -0700241 // Initialize gpu perfomance hint related parameters
242 property_get("sys.hwc.gpu_perf_mode", value, "0");
243 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
244
245 ctx->mGPUHintInfo.mEGLDisplay = NULL;
246 ctx->mGPUHintInfo.mEGLContext = NULL;
247 ctx->mGPUHintInfo.mPrevCompositionGLES = false;
248 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
249
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700250 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700251 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700252}
253
254void closeContext(hwc_context_t *ctx)
255{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500256 if(ctx->mOverlay) {
257 delete ctx->mOverlay;
258 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700259 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700260
Saurabh Shahacf10202013-02-26 10:15:15 -0800261 if(ctx->mRotMgr) {
262 delete ctx->mRotMgr;
263 ctx->mRotMgr = NULL;
264 }
265
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700266 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800267 if(ctx->mCopyBit[i]) {
268 delete ctx->mCopyBit[i];
269 ctx->mCopyBit[i] = NULL;
270 }
271 }
272
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800273 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700274 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
275 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700276 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700277
278 if(ctx->mExtDisplay) {
279 delete ctx->mExtDisplay;
280 ctx->mExtDisplay = NULL;
281 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400282
Naseer Ahmed58780b92013-07-29 17:41:40 -0400283#ifdef VPU_TARGET
284 if(ctx->mVPUClient) {
285 delete ctx->mVPUClient;
286 }
287#endif
288
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700289 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Saurabh Shahcf053c62012-12-13 12:32:55 -0800290 if(ctx->mFBUpdate[i]) {
291 delete ctx->mFBUpdate[i];
292 ctx->mFBUpdate[i] = NULL;
293 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800294 if(ctx->mMDPComp[i]) {
295 delete ctx->mMDPComp[i];
296 ctx->mMDPComp[i] = NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -0800297 }
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700298 if(ctx->mHwcDebug[i]) {
299 delete ctx->mHwcDebug[i];
300 ctx->mHwcDebug[i] = NULL;
301 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700302 if(ctx->mLayerRotMap[i]) {
303 delete ctx->mLayerRotMap[i];
304 ctx->mLayerRotMap[i] = NULL;
305 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800306 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700307 if(ctx->mAD) {
308 delete ctx->mAD;
309 ctx->mAD = NULL;
310 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800311
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800312
Naseer Ahmed29a26812012-06-14 00:56:20 -0700313}
314
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500315
316void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700317{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500318 va_list varargs;
319 va_start(varargs, fmt);
320 buf.appendFormatV(fmt, varargs);
321 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700322}
323
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700324int getExtOrientation(hwc_context_t* ctx) {
325 int extOrient = ctx->mExtOrientation;
326 if(ctx->mBufferMirrorMode)
327 extOrient = getMirrorModeOrientation(ctx);
328 return extOrient;
329}
330
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800331/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700332void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
333 // Position
334 int x = rect.left, y = rect.top;
335 int w = rect.right - rect.left;
336 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800337
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800338 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800339 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800340 // Read action safe properties
341 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
342 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700343
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800344 float wRatio = 1.0;
345 float hRatio = 1.0;
346 float xRatio = 1.0;
347 float yRatio = 1.0;
348
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800349 int fbWidth = ctx->dpyAttr[dpy].xres;
350 int fbHeight = ctx->dpyAttr[dpy].yres;
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700351 if(ctx->dpyAttr[dpy].mDownScaleMode) {
352 // if downscale Mode is enabled for external, need to query
353 // the actual width and height, as that is the physical w & h
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800354 ctx->mExtDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700355 }
356
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800357
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700358 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700359 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700360
361 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700362 swap(fbWidth, fbHeight);
363
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800364 float asX = 0;
365 float asY = 0;
366 float asW = fbWidth;
Arpita Banerjeeb28b3092013-12-06 20:14:23 -0800367 float asH = fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800368
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800369 // based on the action safe ratio, get the Action safe rectangle
370 asW = fbWidth * (1.0f - asWidthRatio / 100.0f);
371 asH = fbHeight * (1.0f - asHeightRatio / 100.0f);
372 asX = (fbWidth - asW) / 2;
373 asY = (fbHeight - asH) / 2;
374
375 // calculate the position ratio
376 xRatio = (float)x/fbWidth;
377 yRatio = (float)y/fbHeight;
378 wRatio = (float)w/fbWidth;
379 hRatio = (float)h/fbHeight;
380
381 //Calculate the position...
382 x = (xRatio * asW) + asX;
383 y = (yRatio * asH) + asY;
384 w = (wRatio * asW);
385 h = (hRatio * asH);
386
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700387 // Convert it back to hwc_rect_t
388 rect.left = x;
389 rect.top = y;
390 rect.right = w + rect.left;
391 rect.bottom = h + rect.top;
392
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800393 return;
394}
395
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700396// This function gets the destination position for Seconday display
397// based on the position and aspect ratio with orientation
398void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
399 hwc_rect_t& inRect, hwc_rect_t& outRect) {
400 // Physical display resolution
401 float fbWidth = ctx->dpyAttr[dpy].xres;
402 float fbHeight = ctx->dpyAttr[dpy].yres;
403 //display position(x,y,w,h) in correct aspectratio after rotation
404 int xPos = 0;
405 int yPos = 0;
406 float width = fbWidth;
407 float height = fbHeight;
408 // Width/Height used for calculation, after rotation
409 float actualWidth = fbWidth;
410 float actualHeight = fbHeight;
411
412 float wRatio = 1.0;
413 float hRatio = 1.0;
414 float xRatio = 1.0;
415 float yRatio = 1.0;
416 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
417
418 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
419 inRect.bottom - inRect.top);
420 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
421 outRect.bottom - outRect.top);
422
423 Whf whf(fbWidth, fbHeight, 0);
424 eTransform extorient = static_cast<eTransform>(extOrientation);
425 // To calculate the destination co-ordinates in the new orientation
426 preRotateSource(extorient, whf, inPos);
427
428 if(extOrientation & HAL_TRANSFORM_ROT_90) {
429 // Swap width/height for input position
430 swapWidthHeight(actualWidth, actualHeight);
431 getAspectRatioPosition(fbWidth, fbHeight, (int)actualWidth,
432 (int)actualHeight, rect);
433 xPos = rect.left;
434 yPos = rect.top;
435 width = rect.right - rect.left;
436 height = rect.bottom - rect.top;
437 }
Ramkumar Radhakrishnan2d41c762014-03-24 14:33:17 -0700438 xRatio = inPos.x/actualWidth;
439 yRatio = inPos.y/actualHeight;
440 wRatio = inPos.w/actualWidth;
441 hRatio = inPos.h/actualHeight;
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800442
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700443
444 //Calculate the position...
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700445 outPos.x = (xRatio * width) + xPos;
446 outPos.y = (yRatio * height) + yPos;
447 outPos.w = wRatio * width;
448 outPos.h = hRatio * height;
449 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
450 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
451 outPos.w, outPos.h);
452
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700453 // For sidesync, the dest fb will be in portrait orientation, and the crop
454 // will be updated to avoid the black side bands, and it will be upscaled
455 // to fit the dest RB, so recalculate
456 // the position based on the new width and height
457 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
458 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -0800459 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700460 //Calculate the position
461 xRatio = (outPos.x - xPos)/width;
462 // GetaspectRatio -- tricky to get the correct aspect ratio
463 // But we need to do this.
464 getAspectRatioPosition(width, height, width, height, r);
465 xPos = r.left;
466 yPos = r.top;
467 float tempWidth = r.right - r.left;
468 float tempHeight = r.bottom - r.top;
469 yRatio = yPos/height;
470 wRatio = outPos.w/width;
471 hRatio = tempHeight/height;
472
473 //Map the coordinates back to Framebuffer domain
474 outPos.x = (xRatio * fbWidth);
475 outPos.y = (yRatio * fbHeight);
476 outPos.w = wRatio * fbWidth;
477 outPos.h = hRatio * fbHeight;
478
479 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
480 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
481 outPos.x, outPos.y,
482 outPos.w, outPos.h);
483 }
484 if(ctx->dpyAttr[dpy].mDownScaleMode) {
485 int extW, extH;
486 if(dpy == HWC_DISPLAY_EXTERNAL)
487 ctx->mExtDisplay->getAttributes(extW, extH);
488 else
489 ctx->mVirtualDisplay->getAttributes(extW, extH);
490 fbWidth = ctx->dpyAttr[dpy].xres;
491 fbHeight = ctx->dpyAttr[dpy].yres;
492 //Calculate the position...
493 xRatio = outPos.x/fbWidth;
494 yRatio = outPos.y/fbHeight;
495 wRatio = outPos.w/fbWidth;
496 hRatio = outPos.h/fbHeight;
497
498 outPos.x = xRatio * extW;
499 outPos.y = yRatio * extH;
500 outPos.w = wRatio * extW;
501 outPos.h = hRatio * extH;
502 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700503 // Convert Dim to hwc_rect_t
504 outRect.left = outPos.x;
505 outRect.top = outPos.y;
506 outRect.right = outPos.x + outPos.w;
507 outRect.bottom = outPos.y + outPos.h;
508
509 return;
510}
511
512bool isPrimaryPortrait(hwc_context_t *ctx) {
513 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
514 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
515 if(fbWidth < fbHeight) {
516 return true;
517 }
518 return false;
519}
520
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700521bool isOrientationPortrait(hwc_context_t *ctx) {
522 if(isPrimaryPortrait(ctx)) {
523 return !(ctx->deviceOrientation & 0x1);
524 }
525 return (ctx->deviceOrientation & 0x1);
526}
527
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700528void calcExtDisplayPosition(hwc_context_t *ctx,
529 private_handle_t *hnd,
530 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700531 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700532 hwc_rect_t& displayFrame,
533 int& transform,
534 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700535 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700536 int extOrient = getExtOrientation(ctx);
537 if(dpy && !qdutils::MDPVersion::getInstance().is8x26()) {
538 if(!isYuvBuffer(hnd)) {
539 if(extOrient & HWC_TRANSFORM_ROT_90) {
540 int dstWidth = ctx->dpyAttr[dpy].xres;
541 int dstHeight = ctx->dpyAttr[dpy].yres;;
542 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
543 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
544 if(!isPrimaryPortrait(ctx)) {
545 swap(srcWidth, srcHeight);
546 } // Get Aspect Ratio for external
547 getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
548 srcHeight, displayFrame);
549 // Crop - this is needed, because for sidesync, the dest fb will
550 // be in portrait orientation, so update the crop to not show the
551 // black side bands.
552 if (isOrientationPortrait(ctx)) {
553 sourceCrop = displayFrame;
554 displayFrame.left = 0;
555 displayFrame.top = 0;
556 displayFrame.right = dstWidth;
557 displayFrame.bottom = dstHeight;
558 }
559 }
560 if(ctx->dpyAttr[dpy].mDownScaleMode) {
561 int extW, extH;
562 // if downscale is enabled, map the co-ordinates to new
563 // domain(downscaled)
564 float fbWidth = ctx->dpyAttr[dpy].xres;
565 float fbHeight = ctx->dpyAttr[dpy].yres;
566 // query MDP configured attributes
567 if(dpy == HWC_DISPLAY_EXTERNAL)
568 ctx->mExtDisplay->getAttributes(extW, extH);
569 else
570 ctx->mVirtualDisplay->getAttributes(extW, extH);
571 //Calculate the ratio...
572 float wRatio = ((float)extW)/fbWidth;
573 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700574
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700575 //convert Dim to hwc_rect_t
576 displayFrame.left *= wRatio;
577 displayFrame.top *= hRatio;
578 displayFrame.right *= wRatio;
579 displayFrame.bottom *= hRatio;
580 }
581 }else {
582 if(extOrient || ctx->dpyAttr[dpy].mDownScaleMode) {
583 getAspectRatioPosition(ctx, dpy, extOrient,
584 displayFrame, displayFrame);
585 }
586 }
587 // If there is a external orientation set, use that
588 if(extOrient) {
589 transform = extOrient;
590 orient = static_cast<ovutils::eTransform >(extOrient);
591 }
592 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
593 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700594 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700595}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700596
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700597/* Returns the orientation which needs to be set on External for
598 * SideSync/Buffer Mirrormode
599 */
600int getMirrorModeOrientation(hwc_context_t *ctx) {
601 int extOrientation = 0;
602 int deviceOrientation = ctx->deviceOrientation;
603 if(!isPrimaryPortrait(ctx))
604 deviceOrientation = (deviceOrientation + 1) % 4;
605 if (deviceOrientation == 0)
606 extOrientation = HWC_TRANSFORM_ROT_270;
607 else if (deviceOrientation == 1)//90
608 extOrientation = 0;
609 else if (deviceOrientation == 2)//180
610 extOrientation = HWC_TRANSFORM_ROT_90;
611 else if (deviceOrientation == 3)//270
612 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
613
614 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700615}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700616
Raj kamal9af062e2014-04-01 16:52:19 +0530617/* Get External State names */
618const char* getExternalDisplayState(uint32_t external_state) {
619 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
620 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
621 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
622 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
623 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
624
625 if(external_state >= EXTERNAL_MAXSTATES) {
626 return "EXTERNAL_INVALID";
627 }
628
629 return externalStates[external_state];
630}
631
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530632bool isDownscaleRequired(hwc_layer_1_t const* layer) {
633 hwc_rect_t displayFrame = layer->displayFrame;
634 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
635 int dst_w, dst_h, src_w, src_h;
636 dst_w = displayFrame.right - displayFrame.left;
637 dst_h = displayFrame.bottom - displayFrame.top;
638 src_w = sourceCrop.right - sourceCrop.left;
639 src_h = sourceCrop.bottom - sourceCrop.top;
640
641 if(((src_w > dst_w) || (src_h > dst_h)))
642 return true;
643
644 return false;
645}
646bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500647 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500648 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700649 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500650
651 dst_w = displayFrame.right - displayFrame.left;
652 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500653 src_w = sourceCrop.right - sourceCrop.left;
654 src_h = sourceCrop.bottom - sourceCrop.top;
655
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800656 if(((src_w != dst_w) || (src_h != dst_h)))
657 return true;
658
659 return false;
660}
661
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700662// Checks if layer needs scaling with split
663bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
664 const int& dpy) {
665
666 int src_width_l, src_height_l;
667 int src_width_r, src_height_r;
668 int dst_width_l, dst_height_l;
669 int dst_width_r, dst_height_r;
670 int hw_w = ctx->dpyAttr[dpy].xres;
671 int hw_h = ctx->dpyAttr[dpy].yres;
672 hwc_rect_t cropL, dstL, cropR, dstR;
673 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700674 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700675 hwc_rect_t displayFrame = layer->displayFrame;
676 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700677
678 cropL = sourceCrop;
679 dstL = displayFrame;
680 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800681 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700682 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
683
684 cropR = sourceCrop;
685 dstR = displayFrame;
686 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800687 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700688 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
689
690 // Sanitize Crop to stitch
691 sanitizeSourceCrop(cropL, cropR, hnd);
692
693 // Calculate the left dst
694 dst_width_l = dstL.right - dstL.left;
695 dst_height_l = dstL.bottom - dstL.top;
696 src_width_l = cropL.right - cropL.left;
697 src_height_l = cropL.bottom - cropL.top;
698
699 // check if there is any scaling on the left
700 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
701 return true;
702
703 // Calculate the right dst
704 dst_width_r = dstR.right - dstR.left;
705 dst_height_r = dstR.bottom - dstR.top;
706 src_width_r = cropR.right - cropR.left;
707 src_height_r = cropR.bottom - cropR.top;
708
709 // check if there is any scaling on the right
710 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
711 return true;
712
713 return false;
714}
715
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530716bool isAlphaScaled(hwc_layer_1_t const* layer) {
717 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530718 return true;
719 }
720 return false;
721}
722
723bool isAlphaPresent(hwc_layer_1_t const* layer) {
724 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400725 if(hnd) {
726 int format = hnd->format;
727 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530728 case HAL_PIXEL_FORMAT_RGBA_8888:
729 case HAL_PIXEL_FORMAT_BGRA_8888:
730 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500731 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530732 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400733 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500734 }
735 return false;
736}
737
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700738static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
739 hwc_rect_t& crop, hwc_rect_t& dst) {
740 int hw_w = ctx->dpyAttr[dpy].xres;
741 int hw_h = ctx->dpyAttr[dpy].yres;
742 if(dst.left < 0 || dst.top < 0 ||
743 dst.right > hw_w || dst.bottom > hw_h) {
744 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800745 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700746 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
747 }
748}
749
750static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
751 const int& dpy) {
752 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
753 hwc_layer_1_t *layer = &list->hwLayers[i];
754 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700755 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
756 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700757 trimLayer(ctx, dpy,
Sushil Chauhand8ef93f2014-03-20 11:08:41 -0700758 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700759 (hwc_rect_t&)crop,
760 (hwc_rect_t&)list->hwLayers[i].displayFrame);
761 layer->sourceCropf.left = crop.left;
762 layer->sourceCropf.right = crop.right;
763 layer->sourceCropf.top = crop.top;
764 layer->sourceCropf.bottom = crop.bottom;
765 }
766}
767
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700768void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700769 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700770 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
771 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700772 ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1;
773 ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700774 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530775 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700776 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800777 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400778 char property[PROPERTY_VALUE_MAX];
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800779 ctx->listStats[dpy].extOnlyLayerIndex = -1;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700780 ctx->listStats[dpy].isDisplayAnimating = false;
Jeykumar Sankaran6a9bb9e2013-08-01 14:19:26 -0700781 ctx->listStats[dpy].roi = ovutils::Dim(0, 0,
782 (int)ctx->dpyAttr[dpy].xres, (int)ctx->dpyAttr[dpy].yres);
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700783 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +0530784 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800785 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700786
Sushil Chauhan5c698792014-04-09 09:15:37 -0700787 trimList(ctx, list, dpy);
788 optimizeLayerRects(ctx, list, dpy);
789
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700790 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500791 hwc_layer_1_t const* layer = &list->hwLayers[i];
792 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700793
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700794#ifdef QCOM_BSP
795 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
796 ctx->listStats[dpy].isDisplayAnimating = true;
797 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700798 if(isSecureDisplayBuffer(hnd)) {
799 ctx->listStats[dpy].secureUI = true;
800 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700801#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700802 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
803 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700804 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800805
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700806 //reset yuv indices
807 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530808 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700809
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700810 if (isSecureBuffer(hnd)) {
811 ctx->listStats[dpy].isSecurePresent = true;
812 }
813
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700814 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700815 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700816 }
817
818 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800819 int& yuvCount = ctx->listStats[dpy].yuvCount;
820 ctx->listStats[dpy].yuvIndices[yuvCount] = i;
821 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800822
radhakrishnac9a67412013-09-25 17:40:42 +0530823 if(UNLIKELY(is4kx2kYuvBuffer(hnd))){
824 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
825 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = i;
826 yuv4k2kCount++;
827 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700828 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530829 if(layer->blending == HWC_BLENDING_PREMULT)
830 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -0800831
Arun Kumar K.Ra2978452013-02-07 01:34:24 -0800832
833 if(UNLIKELY(isExtOnly(hnd))){
834 ctx->listStats[dpy].extOnlyLayerIndex = i;
835 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700836 }
Ping Li9404e2a2013-04-24 16:36:03 -0400837 if(ctx->listStats[dpy].yuvCount > 0) {
838 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
839 if (atoi(property) != 1) {
840 property_set("hw.cabl.yuv", "1");
841 }
842 }
843 } else {
844 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
845 if (atoi(property) != 0) {
846 property_set("hw.cabl.yuv", "0");
847 }
848 }
849 }
Saurabh Shahd4e65852013-06-17 11:33:53 -0700850
851 //The marking of video begin/end is useful on some targets where we need
852 //to have a padding round to be able to shift pipes across mixers.
853 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
854 ctx->mVideoTransFlag = true;
855 }
Raj Kamalfc5b9222014-02-07 16:15:17 +0530856
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700857 if(dpy == HWC_DISPLAY_PRIMARY) {
858 ctx->mAD->markDoable(ctx, list);
859 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700860}
861
Naseer Ahmed018e5452012-12-03 14:46:15 -0500862
Saurabh Shah68107422013-07-09 11:12:42 -0700863static void calc_cut(double& leftCutRatio, double& topCutRatio,
864 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -0700865 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700866 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700867 }
868 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -0700869 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -0700870 }
871 if(orient & HAL_TRANSFORM_ROT_90) {
872 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -0700873 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -0700874 leftCutRatio = topCutRatio;
875 topCutRatio = rightCutRatio;
876 rightCutRatio = bottomCutRatio;
877 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700878 }
879}
880
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800881bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500882 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
883 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
884 ctx->mSecuring) {
885 return true;
886 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800887 if (isSecureModePolicy(ctx->mMDP.version)) {
888 private_handle_t *hnd = (private_handle_t *)layer->handle;
889 if(ctx->mSecureMode) {
890 if (! isSecureBuffer(hnd)) {
891 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
892 __FUNCTION__);
893 return true;
894 }
895 } else {
896 if (isSecureBuffer(hnd)) {
897 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
898 __FUNCTION__);
899 return true;
900 }
901 }
902 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500903 return false;
904}
905
Sushil Chauhan2515abf2013-01-08 16:40:05 -0800906bool isSecureModePolicy(int mdpVersion) {
907 if (mdpVersion < qdutils::MDSS_V5)
908 return true;
909 else
910 return false;
911}
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500912
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800913// returns true if Action safe dimensions are set and target supports Actionsafe
914bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
915 // if external supports underscan, do nothing
916 // it will be taken care in the driver
Ramkumar Radhakrishnan9921b4c2014-03-03 14:46:21 -0800917 // Disable Action safe for 8974 due to HW limitation for downscaling
918 // layers with overlapped region
919 // Disable Actionsafe for non HDMI displays.
920 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
921 qdutils::MDPVersion::getInstance().is8x74v2() ||
922 ctx->mExtDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800923 return false;
Ramkumar Radhakrishnan9921b4c2014-03-03 14:46:21 -0800924 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800925
926 char value[PROPERTY_VALUE_MAX];
927 // Read action safe properties
928 property_get("persist.sys.actionsafe.width", value, "0");
929 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
930 property_get("persist.sys.actionsafe.height", value, "0");
931 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
932
933 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
934 //No action safe ratio set, return
935 return false;
936 }
937 return true;
938}
939
Naseer Ahmed522ce662013-03-18 20:14:05 -0400940int getBlending(int blending) {
941 switch(blending) {
942 case HWC_BLENDING_NONE:
943 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
944 case HWC_BLENDING_PREMULT:
945 return overlay::utils::OVERLAY_BLENDING_PREMULT;
946 case HWC_BLENDING_COVERAGE :
947 default:
948 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
949 }
950}
951
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700952//Crops source buffer against destination and FB boundaries
953void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800954 const hwc_rect_t& scissor, int orient) {
955
Saurabh Shah27c1d652012-08-14 19:30:28 -0700956 int& crop_l = crop.left;
957 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700958 int& crop_r = crop.right;
959 int& crop_b = crop.bottom;
960 int crop_w = crop.right - crop.left;
961 int crop_h = crop.bottom - crop.top;
962
Saurabh Shah27c1d652012-08-14 19:30:28 -0700963 int& dst_l = dst.left;
964 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700965 int& dst_r = dst.right;
966 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -0700967 int dst_w = abs(dst.right - dst.left);
968 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700969
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800970 const int& sci_l = scissor.left;
971 const int& sci_t = scissor.top;
972 const int& sci_r = scissor.right;
973 const int& sci_b = scissor.bottom;
974 int sci_w = abs(sci_r - sci_l);
975 int sci_h = abs(sci_b - sci_t);
976
Saurabh Shah68107422013-07-09 11:12:42 -0700977 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
978 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700979
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800980 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -0700981 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800982 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700983 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800984
985 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -0700986 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800987 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700988 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800989
990 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -0700991 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800992 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700993 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800994
995 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -0700996 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800997 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700998 }
Saurabh Shah27c1d652012-08-14 19:30:28 -0700999
Saurabh Shah541b59d2012-10-11 11:08:12 -07001000 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddiaff14c92014-03-06 11:56:10 +05301001 crop_l += (int)round((double)crop_w * leftCutRatio);
1002 crop_t += (int)round((double)crop_h * topCutRatio);
1003 crop_r -= (int)round((double)crop_w * rightCutRatio);
1004 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001005}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001006
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301007bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1008 const hwc_layer_1_t* layer2) {
1009 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1010 layer2->displayFrame);
1011 return isValidRect(irect);
1012}
1013
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001014bool isValidRect(const hwc_rect& rect)
1015{
1016 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301017}
1018
Jeykumar Sankaran78893422014-05-07 16:23:14 -07001019hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1020{
1021 hwc_rect_t res;
1022
1023 if(!isValidRect(rect))
1024 return (hwc_rect_t){0, 0, 0, 0};
1025
1026 res.left = rect.left + x_off;
1027 res.top = rect.top + y_off;
1028 res.right = rect.right + x_off;
1029 res.bottom = rect.bottom + y_off;
1030
1031 return res;
1032}
1033
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001034/* computes the intersection of two rects */
1035hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1036{
1037 hwc_rect_t res;
1038
1039 if(!isValidRect(rect1) || !isValidRect(rect2)){
1040 return (hwc_rect_t){0, 0, 0, 0};
1041 }
1042
1043
1044 res.left = max(rect1.left, rect2.left);
1045 res.top = max(rect1.top, rect2.top);
1046 res.right = min(rect1.right, rect2.right);
1047 res.bottom = min(rect1.bottom, rect2.bottom);
1048
1049 if(!isValidRect(res))
1050 return (hwc_rect_t){0, 0, 0, 0};
1051
1052 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301053}
1054
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001055/* computes the union of two rects */
1056hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1057{
1058 hwc_rect_t res;
1059
1060 if(!isValidRect(rect1)){
1061 return rect2;
1062 }
1063
1064 if(!isValidRect(rect2)){
1065 return rect1;
1066 }
1067
1068 res.left = min(rect1.left, rect2.left);
1069 res.top = min(rect1.top, rect2.top);
1070 res.right = max(rect1.right, rect2.right);
1071 res.bottom = max(rect1.bottom, rect2.bottom);
1072
1073 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301074}
1075
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001076/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1077 * a single rect */
1078hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301079
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001080 hwc_rect_t res = rect1;
1081
1082 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1083 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1084 res.top = rect2.bottom;
1085 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1086 res.bottom = rect2.top;
1087 }
1088 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1089 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1090 res.left = rect2.right;
1091 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1092 res.right = rect2.left;
1093 }
1094 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301095}
1096
1097void optimizeLayerRects(hwc_context_t *ctx,
1098 const hwc_display_contents_1_t *list, const int& dpy) {
1099 int i=list->numHwLayers-2;
1100 hwc_rect_t irect;
1101 while(i > 0) {
1102
1103 //see if there is no blending required.
1104 //If it is opaque see if we can substract this region from below layers.
1105 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1106 int j= i-1;
1107 hwc_rect_t& topframe =
1108 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1109 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301110 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001111 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1112 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaranccf281c2014-01-14 17:21:49 -08001113 hwc_rect_t bottomCrop =
1114 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhand8ef93f2014-03-20 11:08:41 -07001115 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1116 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001117
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001118 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1119 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001120 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001121 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001122 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001123 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001124 dest_rect, transform);
Jeykumar Sankaranccf281c2014-01-14 17:21:49 -08001125 //Update layer sourceCropf
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -08001126 layer->sourceCropf.left =(float)bottomCrop.left;
1127 layer->sourceCropf.top = (float)bottomCrop.top;
1128 layer->sourceCropf.right = (float)bottomCrop.right;
1129 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
1130#ifdef QCOM_BSP
1131 //Update layer dirtyRect
1132 layer->dirtyRect = getIntersection(bottomCrop,
1133 layer->dirtyRect);
1134#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001135 }
1136 }
1137 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301138 }
1139 }
1140 i--;
1141 }
1142}
1143
Naseer Ahmed64b81212013-02-14 10:29:47 -05001144void getNonWormholeRegion(hwc_display_contents_1_t* list,
1145 hwc_rect_t& nwr)
1146{
1147 uint32_t last = list->numHwLayers - 1;
1148 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1149 //Initiliaze nwr to first frame
1150 nwr.left = list->hwLayers[0].displayFrame.left;
1151 nwr.top = list->hwLayers[0].displayFrame.top;
1152 nwr.right = list->hwLayers[0].displayFrame.right;
1153 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1154
1155 for (uint32_t i = 1; i < last; i++) {
1156 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001157 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001158 }
1159
1160 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001161 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001162}
1163
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001164bool isExternalActive(hwc_context_t* ctx) {
1165 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001166}
1167
Saurabh Shah747af1e2013-02-26 10:25:12 -08001168void closeAcquireFds(hwc_display_contents_1_t* list) {
1169 for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
1170 //Close the acquireFenceFds
1171 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1172 if(list->hwLayers[i].acquireFenceFd >= 0) {
1173 close(list->hwLayers[i].acquireFenceFd);
1174 list->hwLayers[i].acquireFenceFd = -1;
1175 }
1176 }
1177}
1178
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001179int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001180 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001181 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001182 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001183 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001184 int count = 0;
1185 int releaseFd = -1;
Arun Kumar K.R641a3be2013-11-19 11:20:28 -08001186 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001187 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001188 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001189 int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
1190
1191 struct mdp_buf_sync data;
1192 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001193 data.acq_fen_fd = acquireFd;
1194 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R641a3be2013-11-19 11:20:28 -08001195 data.retire_fen_fd = &retireFd;
1196 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001197
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001198 char property[PROPERTY_VALUE_MAX];
1199 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1200 if(atoi(property) == 0)
1201 swapzero = true;
1202 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001203
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001204 bool isExtAnimating = false;
1205 if(dpy)
1206 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001207
Saurabh Shah23a813c2013-03-20 16:58:12 -07001208 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001209 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001210 int rotFd = ctx->mRotMgr->getRotDevFd();
1211 int rotReleaseFd = -1;
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001212 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1213 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1214 if((currRot == NULL) || (currLayer == NULL)) {
1215 continue;
1216 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001217 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001218 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001219 rotData.acq_fen_fd =
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001220 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001221 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001222 rotData.session_id = currRot->getSessId();
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001223 int ret = 0;
1224 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1225 if(ret < 0) {
1226 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1227 __FUNCTION__, strerror(errno));
1228 } else {
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001229 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001230 //For MDP to wait on.
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001231 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001232 dup(rotReleaseFd);
1233 //A buffer is free to be used by producer as soon as its copied to
1234 //rotator
Ramkumar Radhakrishnan56db0cc2014-01-31 20:03:01 -08001235 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001236 rotReleaseFd;
1237 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001238 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001239
Balamurugan Thanikachalam770d9e82014-01-31 18:23:20 +05301240 //Accumulate acquireFenceFds for MDP Overlays
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001241 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Balamurugan Thanikachalam770d9e82014-01-31 18:23:20 +05301242 if(list->hwLayers[i].compositionType == HWC_OVERLAY &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001243 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001244 if(UNLIKELY(swapzero))
1245 acquireFd[count++] = -1;
1246 else
1247 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001248 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001249 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1250 if(UNLIKELY(swapzero))
1251 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001252 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001253 //set the acquireFD from fd - which is coming from c2d
1254 acquireFd[count++] = fd;
1255 // Buffer sync IOCTL should be async when using c2d fence is
1256 // used
1257 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001258 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001259 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1260 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001261 }
1262
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001263 data.acq_fen_fd_cnt = count;
1264 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001265
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001266 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001267 if(LIKELY(!swapzero)) {
1268 uint64_t start = systemTime();
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001269 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001270 ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
1271 __FUNCTION__, (size_t) ns2ms(systemTime() - start));
1272 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001273
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001274 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001275 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1276 __FUNCTION__, strerror(errno));
1277 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d",
1278 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1279 dpy, list->numHwLayers);
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001280 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001281
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001282 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001283 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Justin Philip8e5f9662014-07-31 11:52:34 +05301284 list->hwLayers[i].compositionType == HWC_BLIT ||
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001285 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001286 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001287 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001288 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001289 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001290 // Release all the app layer fds immediately,
1291 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001292 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001293 } else if(list->hwLayers[i].releaseFenceFd < 0) {
1294 //If rotator has not already populated this field.
Justin Philip8e5f9662014-07-31 11:52:34 +05301295 if(list->hwLayers[i].compositionType == HWC_BLIT) {
1296 //For Blit, the app layers should be released when the Blit is
1297 //complete. This fd was passed from copybit->draw
1298 list->hwLayers[i].releaseFenceFd = dup(fd);
1299 } else {
Balamurugan Thanikachalam770d9e82014-01-31 18:23:20 +05301300 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
Justin Philip8e5f9662014-07-31 11:52:34 +05301301 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001302 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001303 }
1304 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001305
1306 if(fd >= 0) {
1307 close(fd);
1308 fd = -1;
1309 }
1310
Naseer Ahmed64b81212013-02-14 10:29:47 -05001311 if (ctx->mCopyBit[dpy])
1312 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
Saurabh Shah23a813c2013-03-20 16:58:12 -07001313
Saurabh Shah23a813c2013-03-20 16:58:12 -07001314 //Signals when MDP finishes reading rotator buffers.
1315 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R641a3be2013-11-19 11:20:28 -08001316 close(releaseFd);
1317 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001318
Arun Kumar K.R641a3be2013-11-19 11:20:28 -08001319 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001320 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001321 } else {
Arun Kumar K.R641a3be2013-11-19 11:20:28 -08001322 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001323 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001324 return ret;
1325}
1326
Saurabh Shahacf10202013-02-26 10:15:15 -08001327void setMdpFlags(hwc_layer_1_t *layer,
1328 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001329 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001330 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001331 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001332
1333 if(layer->blending == HWC_BLENDING_PREMULT) {
1334 ovutils::setMdpFlags(mdpFlags,
1335 ovutils::OV_MDP_BLEND_FG_PREMULT);
1336 }
1337
1338 if(isYuvBuffer(hnd)) {
1339 if(isSecureBuffer(hnd)) {
1340 ovutils::setMdpFlags(mdpFlags,
1341 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1342 }
1343 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1344 metadata->interlaced) {
1345 ovutils::setMdpFlags(mdpFlags,
1346 ovutils::OV_MDP_DEINTERLACE);
1347 }
1348 //Pre-rotation will be used using rotator.
1349 if(transform & HWC_TRANSFORM_ROT_90) {
1350 ovutils::setMdpFlags(mdpFlags,
1351 ovutils::OV_MDP_SOURCE_ROTATED_90);
1352 }
1353 }
1354
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001355 if(isSecureDisplayBuffer(hnd)) {
1356 // Secure display needs both SECURE_OVERLAY and SECURE_DISPLAY_OV
1357 ovutils::setMdpFlags(mdpFlags,
1358 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
1359 ovutils::setMdpFlags(mdpFlags,
1360 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1361 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001362 //No 90 component and no rot-downscale then flips done by MDP
1363 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001364 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1365 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001366 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1367 }
1368
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001369 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001370 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1371 }
1372 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001373
1374 if(metadata &&
1375 ((metadata->operation & PP_PARAM_HSIC)
1376 || (metadata->operation & PP_PARAM_IGC)
1377 || (metadata->operation & PP_PARAM_SHARP2))) {
1378 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1379 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001380}
1381
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301382int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001383 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001384 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001385
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301386 // Fix alignments for TILED format
1387 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1388 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1389 whf.w = utils::alignup(whf.w, 64);
1390 whf.h = utils::alignup(whf.h, 32);
1391 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001392 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001393
1394 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1395 qdutils::MDSS_V5) {
1396 uint32_t crop_w = (crop.right - crop.left);
1397 uint32_t crop_h = (crop.bottom - crop.top);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001398 if (ovutils::isYuv(whf.format)) {
1399 ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
1400 ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
Sushil Chauhan5491c8a2013-05-24 10:15:30 -07001401 // For interlaced, crop.h should be 4-aligned
1402 if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
1403 crop_h = ovutils::aligndown(crop_h, 4);
Sushil Chauhan6181aa22013-05-17 18:04:10 -07001404 crop.right = crop.left + crop_w;
1405 crop.bottom = crop.top + crop_h;
1406 }
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001407 Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
1408 rot->setCrop(rotCrop);
1409 }
1410
Saurabh Shahacf10202013-02-26 10:15:15 -08001411 rot->setFlags(mdpFlags);
1412 rot->setTransform(orient);
1413 rot->setDownscale(downscale);
1414 if(!rot->commit()) return -1;
1415 return 0;
1416}
1417
Saurabh Shahe2474082013-05-15 16:32:13 -07001418int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001419 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001420 const hwc_rect_t& pos, const MetaData_t *metadata,
1421 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001422 ov->setSource(parg, dest);
1423 ov->setTransform(orient, dest);
1424
1425 int crop_w = crop.right - crop.left;
1426 int crop_h = crop.bottom - crop.top;
1427 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1428 ov->setCrop(dcrop, dest);
1429
1430 int posW = pos.right - pos.left;
1431 int posH = pos.bottom - pos.top;
1432 Dim position(pos.left, pos.top, posW, posH);
1433 ov->setPosition(position, dest);
1434
Saurabh Shah5daeee52013-01-23 16:52:26 +08001435 if (metadata)
1436 ov->setVisualParams(*metadata, dest);
1437
Saurabh Shahacf10202013-02-26 10:15:15 -08001438 if (!ov->commit(dest)) {
1439 return -1;
1440 }
1441 return 0;
1442}
1443
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001444int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1445 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1446 eIsFg& isFg, const eDest& dest) {
1447
1448 hwc_rect_t dst = layer->displayFrame;
1449 trimLayer(ctx, dpy, 0, dst, dst);
1450
1451 int w = ctx->dpyAttr[dpy].xres;
1452 int h = ctx->dpyAttr[dpy].yres;
1453 int dst_w = dst.right - dst.left;
1454 int dst_h = dst.bottom - dst.top;
1455 uint32_t color = layer->transform;
1456 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1457
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001458 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001459 if (layer->blending == HWC_BLENDING_PREMULT)
1460 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1461
1462 PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(0),
1463 layer->planeAlpha,
1464 (ovutils::eBlending) getBlending(layer->blending));
1465
1466 // Configure MDP pipe for Color layer
1467 Dim pos(dst.left, dst.top, dst_w, dst_h);
1468 ctx->mOverlay->setSource(parg, dest);
1469 ctx->mOverlay->setColor(color, dest);
1470 ctx->mOverlay->setTransform(0, dest);
1471 ctx->mOverlay->setCrop(pos, dest);
1472 ctx->mOverlay->setPosition(pos, dest);
1473
1474 if (!ctx->mOverlay->commit(dest)) {
1475 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1476 return -1;
1477 }
1478 return 0;
1479}
1480
Saurabh Shahe2474082013-05-15 16:32:13 -07001481void updateSource(eTransform& orient, Whf& whf,
Saurabh Shahacf10202013-02-26 10:15:15 -08001482 hwc_rect_t& crop) {
1483 Dim srcCrop(crop.left, crop.top,
1484 crop.right - crop.left,
1485 crop.bottom - crop.top);
Saurabh Shah76fd6552013-03-14 14:45:38 -07001486 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
Saurabh Shahacf10202013-02-26 10:15:15 -08001487 preRotateSource(orient, whf, srcCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001488 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1489 qdutils::MDSS_V5) {
1490 // Source for overlay will be the cropped (and rotated)
1491 crop.left = 0;
1492 crop.top = 0;
1493 crop.right = srcCrop.w;
1494 crop.bottom = srcCrop.h;
1495 // Set width & height equal to sourceCrop w & h
1496 whf.w = srcCrop.w;
1497 whf.h = srcCrop.h;
1498 } else {
1499 crop.left = srcCrop.x;
1500 crop.top = srcCrop.y;
1501 crop.right = srcCrop.x + srcCrop.w;
1502 crop.bottom = srcCrop.y + srcCrop.h;
1503 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001504}
1505
Saurabh Shah88e4d272013-09-03 13:31:29 -07001506int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001507 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
1508 eIsFg& isFg, const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001509
1510 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001511
Saurabh Shahacf10202013-02-26 10:15:15 -08001512 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001513 if (layer->flags & HWC_COLOR_FILL) {
1514 // Configure Color layer
1515 return configColorLayer(ctx, layer, dpy, mdpFlags, z, isFg, dest);
1516 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001517 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1518 return -1;
1519 }
1520
Saurabh Shah5daeee52013-01-23 16:52:26 +08001521 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1522
Saurabh Shah62e1d732013-09-17 10:44:05 -07001523 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001524 hwc_rect_t dst = layer->displayFrame;
1525 int transform = layer->transform;
1526 eTransform orient = static_cast<eTransform>(transform);
1527 int downscale = 0;
1528 int rotFlags = ovutils::ROT_FLAGS_NONE;
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -07001529 Whf whf(getWidth(hnd), getHeight(hnd),
Saurabh Shahacf10202013-02-26 10:15:15 -08001530 getMdpFormat(hnd->format), hnd->size);
1531
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001532 // Handle R/B swap
1533 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1534 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1535 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1536 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1537 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1538 }
1539
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08001540 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Arun Kumar K.Rffef7482013-04-10 14:17:22 -07001541
Saurabh Shahacf10202013-02-26 10:15:15 -08001542 if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 &&
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001543 ctx->mMDP.version < qdutils::MDSS_V5) {
1544 downscale = getDownscaleFactor(
1545 crop.right - crop.left,
1546 crop.bottom - crop.top,
1547 dst.right - dst.left,
1548 dst.bottom - dst.top);
Saurabh Shahacf10202013-02-26 10:15:15 -08001549 if(downscale) {
1550 rotFlags = ROT_DOWNSCALE_ENABLED;
1551 }
1552 }
1553
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001554 setMdpFlags(layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001555
1556 if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot
1557 ((transform & HWC_TRANSFORM_ROT_90) || downscale)) {
1558 *rot = ctx->mRotMgr->getNext();
1559 if(*rot == NULL) return -1;
Saurabh Shah70b62f52014-03-31 10:31:42 -07001560 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Tatenda Chipeperekwa88562702013-10-19 19:56:16 -07001561 if(!dpy)
1562 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001563 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001564 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1565 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001566 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001567 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001568 whf.format = (*rot)->getDstFormat();
1569 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001570 rotFlags |= ovutils::ROT_PREROTATED;
1571 }
1572
Saurabh Shah76fd6552013-03-14 14:45:38 -07001573 //For the mdp, since either we are pre-rotating or MDP does flips
1574 orient = OVERLAY_TRANSFORM_0;
1575 transform = 0;
Naseer Ahmed522ce662013-03-18 20:14:05 -04001576 PipeArgs parg(mdpFlags, whf, z, isFg,
1577 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1578 (ovutils::eBlending) getBlending(layer->blending));
1579
Saurabh Shah5daeee52013-01-23 16:52:26 +08001580 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001581 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
1582 return -1;
1583 }
1584 return 0;
1585}
1586
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001587//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001588void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001589 private_handle_t *hnd) {
1590 if(cropL.right - cropL.left) {
1591 if(isYuvBuffer(hnd)) {
1592 //Always safe to even down left
1593 ovutils::even_floor(cropL.left);
1594 //If right is even, automatically width is even, since left is
1595 //already even
1596 ovutils::even_floor(cropL.right);
1597 }
1598 //Make sure there are no gaps between left and right splits if the layer
1599 //is spread across BOTH halves
1600 if(cropR.right - cropR.left) {
1601 cropR.left = cropL.right;
1602 }
1603 }
1604
1605 if(cropR.right - cropR.left) {
1606 if(isYuvBuffer(hnd)) {
1607 //Always safe to even down left
1608 ovutils::even_floor(cropR.left);
1609 //If right is even, automatically width is even, since left is
1610 //already even
1611 ovutils::even_floor(cropR.right);
1612 }
1613 }
1614}
1615
Saurabh Shah88e4d272013-09-03 13:31:29 -07001616int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001617 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1618 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001619 Rotator **rot) {
1620 private_handle_t *hnd = (private_handle_t *)layer->handle;
1621 if(!hnd) {
1622 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1623 return -1;
1624 }
1625
Saurabh Shah5daeee52013-01-23 16:52:26 +08001626 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1627
Saurabh Shahacf10202013-02-26 10:15:15 -08001628 int hw_w = ctx->dpyAttr[dpy].xres;
1629 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07001630 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001631 hwc_rect_t dst = layer->displayFrame;
1632 int transform = layer->transform;
1633 eTransform orient = static_cast<eTransform>(transform);
1634 const int downscale = 0;
1635 int rotFlags = ROT_FLAGS_NONE;
1636
Ramkumar Radhakrishnan92f3abe2013-06-05 13:52:40 -07001637 Whf whf(getWidth(hnd), getHeight(hnd),
Saurabh Shahacf10202013-02-26 10:15:15 -08001638 getMdpFormat(hnd->format), hnd->size);
1639
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001640 // Handle R/B swap
1641 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1642 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1643 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1644 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1645 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1646 }
1647
Ramkumar Radhakrishnan9921b4c2014-03-03 14:46:21 -08001648 /* Calculate the external display position based on MDP downscale,
1649 ActionSafe, and extorientation features. */
1650 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
1651
Ramkumar Radhakrishnan9d52f432013-05-14 14:46:59 -07001652 setMdpFlags(layer, mdpFlagsL, 0, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001653
1654 if(lDest != OV_INVALID && rDest != OV_INVALID) {
1655 //Enable overfetch
1656 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
1657 }
1658
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001659 //Will do something only if feature enabled and conditions suitable
1660 //hollow call otherwise
1661 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
1662 overlay::Writeback *wb = overlay::Writeback::getInstance();
1663 whf.format = wb->getOutputFormat();
1664 }
1665
Saurabh Shahacf10202013-02-26 10:15:15 -08001666 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1667 (*rot) = ctx->mRotMgr->getNext();
1668 if((*rot) == NULL) return -1;
Saurabh Shah70b62f52014-03-31 10:31:42 -07001669 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08001670 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001671 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1672 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001673 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001674 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001675 whf.format = (*rot)->getDstFormat();
1676 updateSource(orient, whf, crop);
Saurabh Shahacf10202013-02-26 10:15:15 -08001677 rotFlags |= ROT_PREROTATED;
1678 }
1679
1680 eMdpFlags mdpFlagsR = mdpFlagsL;
1681 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
1682
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001683 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1684 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08001685
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001686 const int lSplit = getLeftSplit(ctx, dpy);
1687
Saurabh Shahacf10202013-02-26 10:15:15 -08001688 if(lDest != OV_INVALID) {
1689 tmp_cropL = crop;
1690 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001691 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001692 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001693 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1694 }
1695 if(rDest != OV_INVALID) {
1696 tmp_cropR = crop;
1697 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07001698 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001699 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08001700 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1701 }
1702
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001703 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1704
Saurabh Shah94d62362013-07-02 10:58:48 -07001705 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08001706 //Not needed if the layer is confined to one half of the screen.
1707 //If rotator has been used then it has also done the flips, so ignore them.
Saurabh Shah94d62362013-07-02 10:58:48 -07001708 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
Ramkumar Radhakrishnanfe7ce802013-04-30 11:19:17 -07001709 && rDest != OV_INVALID && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001710 hwc_rect_t new_cropR;
1711 new_cropR.left = tmp_cropL.left;
1712 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1713
1714 hwc_rect_t new_cropL;
1715 new_cropL.left = new_cropR.right;
1716 new_cropL.right = tmp_cropR.right;
1717
1718 tmp_cropL.left = new_cropL.left;
1719 tmp_cropL.right = new_cropL.right;
1720
1721 tmp_cropR.left = new_cropR.left;
1722 tmp_cropR.right = new_cropR.right;
1723
1724 }
1725
Saurabh Shah76fd6552013-03-14 14:45:38 -07001726 //For the mdp, since either we are pre-rotating or MDP does flips
1727 orient = OVERLAY_TRANSFORM_0;
1728 transform = 0;
1729
Saurabh Shahacf10202013-02-26 10:15:15 -08001730 //configure left mixer
1731 if(lDest != OV_INVALID) {
1732 PipeArgs pargL(mdpFlagsL, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001733 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1734 (ovutils::eBlending) getBlending(layer->blending));
1735
Saurabh Shahacf10202013-02-26 10:15:15 -08001736 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001737 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001738 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
1739 return -1;
1740 }
1741 }
1742
1743 //configure right mixer
1744 if(rDest != OV_INVALID) {
1745 PipeArgs pargR(mdpFlagsR, whf, z, isFg,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001746 static_cast<eRotFlags>(rotFlags),
1747 layer->planeAlpha,
1748 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07001749 tmp_dstR.right = tmp_dstR.right - lSplit;
1750 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08001751 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001752 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001753 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
1754 return -1;
1755 }
1756 }
1757
1758 return 0;
1759}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08001760
radhakrishnac9a67412013-09-25 17:40:42 +05301761int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
1762 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
1763 eIsFg& isFg, const eDest& lDest, const eDest& rDest,
1764 Rotator **rot) {
1765 private_handle_t *hnd = (private_handle_t *)layer->handle;
1766 if(!hnd) {
1767 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1768 return -1;
1769 }
1770
1771 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1772
1773 int hw_w = ctx->dpyAttr[dpy].xres;
1774 int hw_h = ctx->dpyAttr[dpy].yres;
1775 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
1776 hwc_rect_t dst = layer->displayFrame;
1777 int transform = layer->transform;
1778 eTransform orient = static_cast<eTransform>(transform);
1779 const int downscale = 0;
1780 int rotFlags = ROT_FLAGS_NONE;
1781 //Splitting only YUV layer on primary panel needs different zorders
1782 //for both layers as both the layers are configured to single mixer
1783 eZorder lz = z;
1784 eZorder rz = (eZorder)(z + 1);
1785
1786 Whf whf(getWidth(hnd), getHeight(hnd),
1787 getMdpFormat(hnd->format), hnd->size);
1788
Ramkumar Radhakrishnan3a070cc2014-02-20 19:37:15 -08001789 /* Calculate the external display position based on MDP downscale,
1790 ActionSafe, and extorientation features. */
1791 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
1792
radhakrishnac9a67412013-09-25 17:40:42 +05301793 setMdpFlags(layer, mdpFlagsL, 0, transform);
1794 trimLayer(ctx, dpy, transform, crop, dst);
1795
1796 if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) {
1797 (*rot) = ctx->mRotMgr->getNext();
1798 if((*rot) == NULL) return -1;
Saurabh Shah70b62f52014-03-31 10:31:42 -07001799 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05301800 if(!dpy)
1801 BwcPM::setBwc(ctx, crop, dst, transform, mdpFlagsL);
1802 //Configure rotator for pre-rotation
1803 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
1804 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05301805 return -1;
1806 }
radhakrishnac9a67412013-09-25 17:40:42 +05301807 whf.format = (*rot)->getDstFormat();
1808 updateSource(orient, whf, crop);
1809 rotFlags |= ROT_PREROTATED;
1810 }
1811
1812 eMdpFlags mdpFlagsR = mdpFlagsL;
1813 int lSplit = dst.left + (dst.right - dst.left)/2;
1814
1815 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
1816 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
1817
1818 if(lDest != OV_INVALID) {
1819 tmp_cropL = crop;
1820 tmp_dstL = dst;
1821 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
1822 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
1823 }
1824 if(rDest != OV_INVALID) {
1825 tmp_cropR = crop;
1826 tmp_dstR = dst;
1827 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
1828 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
1829 }
1830
1831 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
1832
1833 //When buffer is H-flipped, contents of mixer config also needs to swapped
1834 //Not needed if the layer is confined to one half of the screen.
1835 //If rotator has been used then it has also done the flips, so ignore them.
1836 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
1837 && rDest != OV_INVALID && (*rot) == NULL) {
1838 hwc_rect_t new_cropR;
1839 new_cropR.left = tmp_cropL.left;
1840 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
1841
1842 hwc_rect_t new_cropL;
1843 new_cropL.left = new_cropR.right;
1844 new_cropL.right = tmp_cropR.right;
1845
1846 tmp_cropL.left = new_cropL.left;
1847 tmp_cropL.right = new_cropL.right;
1848
1849 tmp_cropR.left = new_cropR.left;
1850 tmp_cropR.right = new_cropR.right;
1851
1852 }
1853
1854 //For the mdp, since either we are pre-rotating or MDP does flips
1855 orient = OVERLAY_TRANSFORM_0;
1856 transform = 0;
1857
1858 //configure left half
1859 if(lDest != OV_INVALID) {
1860 PipeArgs pargL(mdpFlagsL, whf, lz, isFg,
1861 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1862 (ovutils::eBlending) getBlending(layer->blending));
1863
1864 if(configMdp(ctx->mOverlay, pargL, orient,
1865 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
1866 ALOGE("%s: commit failed for left half config", __FUNCTION__);
1867 return -1;
1868 }
1869 }
1870
1871 //configure right half
1872 if(rDest != OV_INVALID) {
1873 PipeArgs pargR(mdpFlagsR, whf, rz, isFg,
1874 static_cast<eRotFlags>(rotFlags),
1875 layer->planeAlpha,
1876 (ovutils::eBlending) getBlending(layer->blending));
1877 if(configMdp(ctx->mOverlay, pargR, orient,
1878 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
1879 ALOGE("%s: commit failed for right half config", __FUNCTION__);
1880 return -1;
1881 }
1882 }
1883
1884 return 0;
1885}
1886
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001887bool canUseRotator(hwc_context_t *ctx, int dpy) {
Saurabh Shahe2474082013-05-15 16:32:13 -07001888 if(qdutils::MDPVersion::getInstance().is8x26() &&
Tatenda Chipeperekwa75a41812014-04-01 12:54:13 -07001889 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07001890 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamala8c065f2013-10-22 14:52:45 +05301891 /* 8x26 mdss driver supports multiplexing of DMA pipe
1892 * in LINE and BLOCK modes for writeback panels.
1893 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07001894 if(dpy == HWC_DISPLAY_PRIMARY)
1895 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001896 }
Terence Hampson45c02ef2013-05-17 17:00:11 -04001897 if(ctx->mMDP.version == qdutils::MDP_V3_0_4)
1898 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07001899 return true;
1900}
1901
Saurabh Shah07a8ca82013-08-06 18:45:42 -07001902int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
1903 //Default even split for all displays with high res
1904 int lSplit = ctx->dpyAttr[dpy].xres / 2;
1905 if(dpy == HWC_DISPLAY_PRIMARY &&
1906 qdutils::MDPVersion::getInstance().getLeftSplit()) {
1907 //Override if split published by driver for primary
1908 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
1909 }
1910 return lSplit;
1911}
Saurabh Shah1a03d482013-05-29 13:44:20 -07001912
Saurabh Shah88e4d272013-09-03 13:31:29 -07001913bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
1914 if(ctx->dpyAttr[dpy].xres > qdutils::MAX_DISPLAY_DIM) {
1915 return true;
1916 }
1917 //For testing we could split primary via device tree values
1918 if(dpy == HWC_DISPLAY_PRIMARY &&
1919 qdutils::MDPVersion::getInstance().getRightSplit()) {
1920 return true;
1921 }
1922 return false;
1923}
1924
Ramkumar Radhakrishnan9c9a94b2014-03-14 17:28:14 -07001925bool isGLESComp(hwc_context_t *ctx,
1926 hwc_display_contents_1_t* list) {
1927 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
1928 for(int index = 0; index < numAppLayers; index++) {
1929 hwc_layer_1_t* layer = &(list->hwLayers[index]);
1930 if(layer->compositionType == HWC_FRAMEBUFFER)
1931 return true;
1932 }
1933 return false;
1934}
1935
1936void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
1937 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
1938 if(!gpuHint->mGpuPerfModeEnable)
1939 return;
1940 /* Set the GPU hint flag to high for MIXED/GPU composition only for
1941 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
1942 hint to default if the previous composition is GPU or current GPU
1943 composition is due to idle fallback */
1944 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
1945 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
1946 if(!gpuHint->mEGLDisplay) {
1947 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
1948 return;
1949 }
1950 gpuHint->mEGLContext = eglGetCurrentContext();
1951 if(!gpuHint->mEGLContext) {
1952 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
1953 return;
1954 }
1955 }
1956 if(isGLESComp(ctx, list)) {
1957 if(!gpuHint->mPrevCompositionGLES && !MDPComp::isIdleFallback()) {
1958 EGLint attr_list[] = {EGL_GPU_HINT_1,
1959 EGL_GPU_LEVEL_3,
1960 EGL_NONE };
1961 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
1962 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
1963 gpuHint->mEGLContext, attr_list)) {
1964 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
1965 } else {
1966 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
1967 gpuHint->mPrevCompositionGLES = true;
1968 }
1969 } else {
1970 EGLint attr_list[] = {EGL_GPU_HINT_1,
1971 EGL_GPU_LEVEL_0,
1972 EGL_NONE };
1973 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
1974 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
1975 gpuHint->mEGLContext, attr_list)) {
1976 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
1977 } else {
1978 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
1979 }
1980 }
1981 } else {
1982 /* set the GPU hint flag to default for MDP composition */
1983 EGLint attr_list[] = {EGL_GPU_HINT_1,
1984 EGL_GPU_LEVEL_0,
1985 EGL_NONE };
1986 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
1987 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
1988 gpuHint->mEGLContext, attr_list)) {
1989 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
1990 } else {
1991 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
1992 }
1993 gpuHint->mPrevCompositionGLES = false;
1994 }
1995}
1996
Saurabh Shah1a03d482013-05-29 13:44:20 -07001997void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
1998 const hwc_rect_t& dst, const int& transform,
1999 ovutils::eMdpFlags& mdpFlags) {
2000 //Target doesnt support Bwc
2001 if(!qdutils::MDPVersion::getInstance().supportsBWC()) {
2002 return;
2003 }
2004 //src width > MAX mixer supported dim
2005 if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) {
2006 return;
2007 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002008 //Decimation necessary, cannot use BWC. H/W requirement.
2009 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
2010 int src_w = crop.right - crop.left;
2011 int src_h = crop.bottom - crop.top;
2012 int dst_w = dst.right - dst.left;
2013 int dst_h = dst.bottom - dst.top;
2014 if(transform & HAL_TRANSFORM_ROT_90) {
2015 swap(src_w, src_h);
2016 }
2017 float horDscale = 0.0f;
2018 float verDscale = 0.0f;
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002019 int horzDeci = 0;
2020 int vertDeci = 0;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002021 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale,
2022 verDscale);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002023 //TODO Use log2f once math.h has it
2024 if((int)horDscale)
2025 horzDeci = (int)(log(horDscale) / log(2));
2026 if((int)verDscale)
2027 vertDeci = (int)(log(verDscale) / log(2));
2028 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002029 }
2030 //Property
2031 char value[PROPERTY_VALUE_MAX];
2032 property_get("debug.disable.bwc", value, "0");
2033 if(atoi(value)) return;
2034
2035 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2036}
2037
Saurabh Shah23a813c2013-03-20 16:58:12 -07002038void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
2039 if(mCount >= MAX_SESS) return;
2040 mLayer[mCount] = layer;
2041 mRot[mCount] = rot;
2042 mCount++;
2043}
2044
2045void LayerRotMap::reset() {
2046 for (int i = 0; i < MAX_SESS; i++) {
2047 mLayer[i] = 0;
2048 mRot[i] = 0;
2049 }
2050 mCount = 0;
2051}
2052
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002053void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002054 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002055 reset();
2056}
2057
Saurabh Shah23a813c2013-03-20 16:58:12 -07002058void LayerRotMap::setReleaseFd(const int& fence) {
2059 for(uint32_t i = 0; i < mCount; i++) {
2060 mRot[i]->setReleaseFd(dup(fence));
2061 }
2062}
2063
Jeykumar Sankaran4d76a382014-02-26 18:26:58 -08002064hwc_rect_t sanitizeROI(struct hwc_rect roi, hwc_rect boundary)
2065{
2066 if(!isValidRect(roi))
2067 return roi;
2068
2069 struct hwc_rect t_roi = roi;
2070
2071 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2072 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2073 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2074 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2075 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
2076
2077 /* Align to minimum width recommended by the panel */
2078 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2079 if((t_roi.left + MIN_WIDTH) > boundary.right)
2080 t_roi.left = t_roi.right - MIN_WIDTH;
2081 else
2082 t_roi.right = t_roi.left + MIN_WIDTH;
2083 }
2084
2085 if(LEFT_ALIGN)
2086 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2087
2088 /* Align left and width to meet panel restrictions */
2089 if(WIDTH_ALIGN) {
2090 int width = t_roi.right - t_roi.left;
2091 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2092 t_roi.right = t_roi.left + width;
2093
2094 if(t_roi.right > boundary.right) {
2095 t_roi.right = boundary.right;
2096 t_roi.left = t_roi.right - width;
2097
2098 if(LEFT_ALIGN)
2099 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2100 }
2101 }
2102
2103 /* Align top and height to meet panel restrictions */
2104 if(TOP_ALIGN)
2105 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2106
2107 if(HEIGHT_ALIGN) {
2108 int height = t_roi.bottom - t_roi.top;
2109 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2110 t_roi.bottom = t_roi.top + height;
2111
2112 if(t_roi.bottom > boundary.bottom) {
2113 t_roi.bottom = boundary.bottom;
2114 t_roi.top = t_roi.bottom - height;
2115
2116 if(TOP_ALIGN)
2117 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2118 }
2119 }
2120
2121 return t_roi;
2122}
2123
Saurabh Shahacf10202013-02-26 10:15:15 -08002124};//namespace qhwc