blob: add5dc83662f8f8a3ff89e62f4c63ed6abd41df0 [file] [log] [blame]
Saurabh Shah86c17292013-02-08 15:24:13 -08001/*
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -08002 * Copyright (c) 2013-14, The Linux Foundation. All rights reserved.
Saurabh Shah86c17292013-02-08 15:24:13 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR CLIENTS; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <hwc_qclient.h>
31#include <IQService.h>
32#include <hwc_utils.h>
Zohaib Alam1bb65612013-09-28 03:38:20 -040033#include <mdp_version.h>
Naseer Ahmed35a268c2014-06-24 19:07:13 -040034#include <hwc_mdpcomp.h>
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -070035#include <hwc_virtual.h>
Saurabh Shah24eec8a2014-08-22 15:07:25 -070036#include <overlay.h>
Raj Kamal0d53fc62014-11-25 17:36:36 +053037#include <display_config.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080038
39#define QCLIENT_DEBUG 0
40
41using namespace android;
42using namespace qService;
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080043using namespace qhwc;
Saurabh Shah24eec8a2014-08-22 15:07:25 -070044using namespace overlay;
Saurabh Shahcd018352014-11-11 13:54:19 -080045using namespace qdutils;
Saurabh Shah86c17292013-02-08 15:24:13 -080046
47namespace qClient {
48
49// ----------------------------------------------------------------------------
Saurabh Shah7128e502013-02-20 13:24:48 -080050QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx),
51 mMPDeathNotifier(new MPDeathNotifier(ctx))
Saurabh Shah86c17292013-02-08 15:24:13 -080052{
53 ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked");
54}
55
56QClient::~QClient()
57{
58 ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked");
59}
60
Naseer Ahmed4957c522013-11-12 18:07:15 -050061static void securing(hwc_context_t *ctx, uint32_t startEnd) {
62 Locker::Autolock _sl(ctx->mDrawLock);
Saurabh Shahc2125772013-03-15 16:49:50 -070063 //The only way to make this class in this process subscribe to media
64 //player's death.
65 IMediaDeathNotifier::getMediaPlayerService();
66
Naseer Ahmed4957c522013-11-12 18:07:15 -050067 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080068 //We're done securing
69 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050070 ctx->mSecureMode = true;
71 if(ctx->proc)
72 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080073}
74
Naseer Ahmed4957c522013-11-12 18:07:15 -050075static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) {
76 Locker::Autolock _sl(ctx->mDrawLock);
77 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080078 //We're done unsecuring
79 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050080 ctx->mSecureMode = false;
81 if(ctx->proc)
82 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080083}
84
Saurabh Shah7128e502013-02-20 13:24:48 -080085void QClient::MPDeathNotifier::died() {
Saurabh Shahb39f8152013-08-22 10:21:44 -070086 Locker::Autolock _sl(mHwcContext->mDrawLock);
Saurabh Shah7128e502013-02-20 13:24:48 -080087 ALOGD_IF(QCLIENT_DEBUG, "Media Player died");
88 mHwcContext->mSecuring = false;
89 mHwcContext->mSecureMode = false;
90 if(mHwcContext->proc)
91 mHwcContext->proc->invalidate(mHwcContext->proc);
92}
93
Naseer Ahmed4957c522013-11-12 18:07:15 -050094static android::status_t screenRefresh(hwc_context_t *ctx) {
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080095 status_t result = NO_INIT;
Naseer Ahmed4957c522013-11-12 18:07:15 -050096 if(ctx->proc) {
97 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080098 result = NO_ERROR;
99 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -0800100 return result;
101}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700102
Naseer Ahmed4957c522013-11-12 18:07:15 -0500103static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) {
104 ctx->mExtOrientation = orientation;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700105}
106
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500107static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) {
108 int connected;
109 connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0;
110 outParcel->writeInt32(connected);
111}
112
113static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel,
114 Parcel* outParcel) {
115 int dpy = inParcel->readInt32();
116 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
Dileep Kumar Reddie351d842014-03-25 10:39:21 +0530117 if (ctx->dpyAttr[dpy].customFBSize) {
118 outParcel->writeInt32(ctx->dpyAttr[dpy].xres_new);
119 outParcel->writeInt32(ctx->dpyAttr[dpy].yres_new);
120 } else {
121 outParcel->writeInt32(ctx->dpyAttr[dpy].xres);
122 outParcel->writeInt32(ctx->dpyAttr[dpy].yres);
123 }
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500124 outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi);
125 outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi);
126 //XXX: Need to check what to return for HDMI
127 outParcel->writeInt32(ctx->mMDP.panel);
128}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800129static void setHSIC(const Parcel* inParcel) {
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500130 int dpy = inParcel->readInt32();
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800131 ALOGD_IF(0, "In %s: dpy = %d", __FUNCTION__, dpy);
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500132 HSICData_t hsic_data;
133 hsic_data.hue = inParcel->readInt32();
134 hsic_data.saturation = inParcel->readFloat();
135 hsic_data.intensity = inParcel->readInt32();
136 hsic_data.contrast = inParcel->readFloat();
137 //XXX: Actually set the HSIC data through ABL lib
138}
139
140
Naseer Ahmed4957c522013-11-12 18:07:15 -0500141static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) {
142 ctx->mBufferMirrorMode = enable;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700143}
144
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800145static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy,
146 Parcel* outParcel) {
147 // Get the info only if the dpy is valid
148 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
149 Locker::Autolock _sl(ctx->mDrawLock);
150 if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) {
151 // Return the destRect on external, if external orienation
152 // is enabled
153 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left);
154 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top);
155 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right);
156 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom);
157 } else {
158 outParcel->writeInt32(ctx->mViewFrame[dpy].left);
159 outParcel->writeInt32(ctx->mViewFrame[dpy].top);
160 outParcel->writeInt32(ctx->mViewFrame[dpy].right);
161 outParcel->writeInt32(ctx->mViewFrame[dpy].bottom);
162 }
163 return NO_ERROR;
164 } else {
165 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
166 return BAD_VALUE;
167 }
168}
169
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700170// USed for setting the secondary(hdmi/wfd) status
171static void setSecondaryDisplayStatus(hwc_context_t *ctx,
172 const Parcel* inParcel) {
173 uint32_t dpy = inParcel->readInt32();
174 uint32_t status = inParcel->readInt32();
175 ALOGD_IF(QCLIENT_DEBUG, "%s: dpy = %d status = %s", __FUNCTION__,
176 dpy, getExternalDisplayState(status));
177
178 if(dpy > HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
Raj Kamal0d53fc62014-11-25 17:36:36 +0530179 if(dpy == HWC_DISPLAY_VIRTUAL && status == qdutils::EXTERNAL_OFFLINE) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700180 ctx->mWfdSyncLock.lock();
181 ctx->mWfdSyncLock.signal();
182 ctx->mWfdSyncLock.unlock();
Raj Kamal0d53fc62014-11-25 17:36:36 +0530183 } else if(status == qdutils::EXTERNAL_PAUSE) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700184 handle_pause(ctx, dpy);
Raj Kamal0d53fc62014-11-25 17:36:36 +0530185 } else if(status == qdutils::EXTERNAL_RESUME) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700186 handle_resume(ctx, dpy);
187 }
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800188 } else {
Ramakant Singh8595cca2014-11-06 16:17:08 +0530189 ALOGE("%s: Invalid dpy %d", __FUNCTION__, dpy);
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700190 return;
Raj kamal59fea562014-04-01 16:52:19 +0530191 }
192}
193
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700194
195static status_t setViewFrame(hwc_context_t* ctx, const Parcel* inParcel) {
196 int dpy = inParcel->readInt32();
197 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
198 Locker::Autolock _sl(ctx->mDrawLock);
199 ctx->mViewFrame[dpy].left = inParcel->readInt32();
200 ctx->mViewFrame[dpy].top = inParcel->readInt32();
201 ctx->mViewFrame[dpy].right = inParcel->readInt32();
202 ctx->mViewFrame[dpy].bottom = inParcel->readInt32();
203 ALOGD_IF(QCLIENT_DEBUG, "%s: mViewFrame[%d] = [%d %d %d %d]",
204 __FUNCTION__, dpy,
205 ctx->mViewFrame[dpy].left, ctx->mViewFrame[dpy].top,
206 ctx->mViewFrame[dpy].right, ctx->mViewFrame[dpy].bottom);
207 return NO_ERROR;
208 } else {
209 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
210 return BAD_VALUE;
211 }
212}
213
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400214static void toggleDynamicDebug(hwc_context_t* ctx, const Parcel* inParcel) {
215 int debug_type = inParcel->readInt32();
216 bool enable = !!inParcel->readInt32();
217 ALOGD("%s: debug_type: %d enable:%d",
218 __FUNCTION__, debug_type, enable);
219 Locker::Autolock _sl(ctx->mDrawLock);
220 switch (debug_type) {
221 //break is ignored for DEBUG_ALL to toggle all of them at once
222 case IQService::DEBUG_ALL:
223 case IQService::DEBUG_MDPCOMP:
224 qhwc::MDPComp::dynamicDebug(enable);
225 if (debug_type != IQService::DEBUG_ALL)
226 break;
227 case IQService::DEBUG_VSYNC:
228 ctx->vstate.debug = enable;
229 if (debug_type != IQService::DEBUG_ALL)
230 break;
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700231 case IQService::DEBUG_VD:
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700232 HWCVirtualVDS::dynamicDebug(enable);
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700233 if (debug_type != IQService::DEBUG_ALL)
234 break;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700235 case IQService::DEBUG_PIPE_LIFECYCLE:
236 Overlay::debugPipeLifecycle(enable);
237 if (debug_type != IQService::DEBUG_ALL)
238 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400239 }
240}
241
Saurabh Shah59562ff2014-09-30 16:13:12 -0700242static void setIdleTimeout(hwc_context_t* ctx, const Parcel* inParcel) {
243 uint32_t timeout = (uint32_t)inParcel->readInt32();
244 ALOGD("%s :%u ms", __FUNCTION__, timeout);
245 Locker::Autolock _sl(ctx->mDrawLock);
246 MDPComp::setIdleTimeout(timeout);
247}
248
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700249static void setMaxPipesPerMixer(hwc_context_t* ctx, const Parcel* inParcel) {
250 uint32_t value = (uint32_t)inParcel->readInt32();
251 ALOGD("%s : setting MaxPipesPerMixer: %d ", __FUNCTION__, value);
252 Locker::Autolock _sl(ctx->mDrawLock);
253 MDPComp::setMaxPipesPerMixer(value);
254}
255
Saurabh Shahcd018352014-11-11 13:54:19 -0800256static void toggleBWC(hwc_context_t* ctx, const Parcel* inParcel) {
257 uint32_t enable = (uint32_t)inParcel->readInt32();
258 if(MDPVersion::getInstance().supportsBWC()) {
259 Locker::Autolock _sl(ctx->mDrawLock);
260 ctx->mBWCEnabled = (bool) enable;
261 ALOGI("%s: Set BWC to %d", __FUNCTION__, enable);
262 } else {
263 ALOGI("%s: Target doesn't support BWC", __FUNCTION__);
264 }
265}
266
Raj Kamal0d53fc62014-11-25 17:36:36 +0530267static void configureDynRefreshRate(hwc_context_t* ctx,
268 const Parcel* inParcel) {
269 uint32_t op = (uint32_t)inParcel->readInt32();
270 uint32_t refresh_rate = (uint32_t)inParcel->readInt32();
271 MDPVersion& mdpHw = MDPVersion::getInstance();
272 uint32_t dpy = HWC_DISPLAY_PRIMARY;
273
274 if(mdpHw.isDynFpsSupported()) {
275 Locker::Autolock _sl(ctx->mDrawLock);
276
277 switch (op) {
278 case DISABLE_METADATA_DYN_REFRESH_RATE:
279 ctx->mUseMetaDataRefreshRate = false;
280 setRefreshRate(ctx, dpy, ctx->dpyAttr[dpy].refreshRate);
281 break;
282 case ENABLE_METADATA_DYN_REFRESH_RATE:
283 ctx->mUseMetaDataRefreshRate = true;
284 setRefreshRate(ctx, dpy, ctx->dpyAttr[dpy].refreshRate);
285 break;
286 case SET_BINDER_DYN_REFRESH_RATE:
287 if(ctx->mUseMetaDataRefreshRate)
288 ALOGW("%s: Ignoring binder request to change refresh-rate",
289 __FUNCTION__);
290 else {
291 uint32_t rate = roundOff(refresh_rate);
292 if((rate >= mdpHw.getMinFpsSupported() &&
293 rate <= mdpHw.getMaxFpsSupported())) {
294 setRefreshRate(ctx, dpy, rate);
295 } else {
296 ALOGE("%s: Requested refresh-rate should be between \
297 (%d) and (%d). Given (%d)", __FUNCTION__,
298 mdpHw.getMinFpsSupported(),
299 mdpHw.getMaxFpsSupported(), rate);
300 }
301 }
302 break;
303 default:
304 ALOGE("%s: Invalid op %d",__FUNCTION__,op);
305 }
306 }
307}
308
Jeykumar Sankaran53b05f22014-08-05 11:27:03 -0700309static status_t setPartialUpdatePref(hwc_context_t *ctx, uint32_t enable) {
310 ALOGD("%s: enable: %d", __FUNCTION__, enable);
311 if(qhwc::MDPComp::setPartialUpdatePref(ctx, (bool)enable) < 0)
312 return NO_INIT;
313 return NO_ERROR;
314}
315
Naseer Ahmed4957c522013-11-12 18:07:15 -0500316status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
317 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800318 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500319
Naseer Ahmed4957c522013-11-12 18:07:15 -0500320 switch(command) {
321 case IQService::SECURING:
322 securing(mHwcContext, inParcel->readInt32());
323 break;
324 case IQService::UNSECURING:
325 unsecuring(mHwcContext, inParcel->readInt32());
326 break;
327 case IQService::SCREEN_REFRESH:
328 return screenRefresh(mHwcContext);
329 break;
330 case IQService::EXTERNAL_ORIENTATION:
331 setExtOrientation(mHwcContext, inParcel->readInt32());
332 break;
333 case IQService::BUFFER_MIRRORMODE:
334 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
335 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800336 case IQService::GET_DISPLAY_VISIBLE_REGION:
337 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
338 outParcel);
339 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500340 case IQService::CHECK_EXTERNAL_STATUS:
341 isExternalConnected(mHwcContext, outParcel);
342 break;
343 case IQService::GET_DISPLAY_ATTRIBUTES:
344 getDisplayAttributes(mHwcContext, inParcel, outParcel);
345 break;
346 case IQService::SET_HSIC_DATA:
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800347 setHSIC(inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530348 break;
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700349 case IQService::SET_SECONDARY_DISPLAY_STATUS:
350 setSecondaryDisplayStatus(mHwcContext, inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530351 break;
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700352 case IQService::SET_VIEW_FRAME:
353 setViewFrame(mHwcContext, inParcel);
354 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400355 case IQService::DYNAMIC_DEBUG:
356 toggleDynamicDebug(mHwcContext, inParcel);
357 break;
Saurabh Shah59562ff2014-09-30 16:13:12 -0700358 case IQService::SET_IDLE_TIMEOUT:
359 setIdleTimeout(mHwcContext, inParcel);
360 break;
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700361 case IQService::SET_MAX_PIPES_PER_MIXER:
362 setMaxPipesPerMixer(mHwcContext, inParcel);
Jeykumar Sankaran53b05f22014-08-05 11:27:03 -0700363 case IQService::SET_PARTIAL_UPDATE:
364 ret = setPartialUpdatePref(mHwcContext, inParcel->readInt32());
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700365 break;
Saurabh Shahcd018352014-11-11 13:54:19 -0800366 case IQService::TOGGLE_BWC:
367 toggleBWC(mHwcContext, inParcel);
368 break;
Raj Kamal0d53fc62014-11-25 17:36:36 +0530369 case IQService::CONFIGURE_DYN_REFRESH_RATE:
370 configureDynRefreshRate(mHwcContext, inParcel);
371 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500372 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800373 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500374 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800375 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500376}
377
Saurabh Shah86c17292013-02-08 15:24:13 -0800378}