blob: 5a1b047e12ae6bbbd77a4b307332b1597b1e1248 [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>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050038#include <hdmi.h>
39#include <video/msm_hdmi_modes.h>
Zohaib Alam83ea46d2015-03-23 15:44:19 -040040#include <hwc_qdcm.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080041
42#define QCLIENT_DEBUG 0
Prabhanjan Kanduladb274fa2015-03-30 22:35:09 +053043#define FILE_MAX_MDSSBW_FLAG \
44 "/sys/devices/virtual/graphics/fb0/mdp/bw_mode_bitmap"
Saurabh Shah86c17292013-02-08 15:24:13 -080045
46using namespace android;
47using namespace qService;
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080048using namespace qhwc;
Saurabh Shah24eec8a2014-08-22 15:07:25 -070049using namespace overlay;
Saurabh Shahcd018352014-11-11 13:54:19 -080050using namespace qdutils;
Zohaib Alam83ea46d2015-03-23 15:44:19 -040051using namespace qQdcm;
Saurabh Shah86c17292013-02-08 15:24:13 -080052
53namespace qClient {
54
55// ----------------------------------------------------------------------------
Saurabh Shah7128e502013-02-20 13:24:48 -080056QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx),
Prabhanjan Kanduladb274fa2015-03-30 22:35:09 +053057 mMPDeathNotifier(new MPDeathNotifier(ctx)),
58 mCamDeathNotifier(new CamDeathNotifier())
Saurabh Shah86c17292013-02-08 15:24:13 -080059{
60 ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked");
61}
62
63QClient::~QClient()
64{
65 ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked");
66}
67
Naseer Ahmed4957c522013-11-12 18:07:15 -050068static void securing(hwc_context_t *ctx, uint32_t startEnd) {
Saurabh Shahc2125772013-03-15 16:49:50 -070069 //The only way to make this class in this process subscribe to media
70 //player's death.
71 IMediaDeathNotifier::getMediaPlayerService();
72
Raj Kamal58b31a02014-12-16 15:53:53 +053073 ctx->mDrawLock.lock();
Naseer Ahmed4957c522013-11-12 18:07:15 -050074 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080075 //We're done securing
76 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050077 ctx->mSecureMode = true;
Raj Kamal58b31a02014-12-16 15:53:53 +053078 ctx->mDrawLock.unlock();
79
Naseer Ahmed4957c522013-11-12 18:07:15 -050080 if(ctx->proc)
81 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080082}
83
Naseer Ahmed4957c522013-11-12 18:07:15 -050084static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) {
Raj Kamal58b31a02014-12-16 15:53:53 +053085 ctx->mDrawLock.lock();
Naseer Ahmed4957c522013-11-12 18:07:15 -050086 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080087 //We're done unsecuring
88 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050089 ctx->mSecureMode = false;
Raj Kamal58b31a02014-12-16 15:53:53 +053090 ctx->mDrawLock.unlock();
91
Naseer Ahmed4957c522013-11-12 18:07:15 -050092 if(ctx->proc)
93 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080094}
95
Saurabh Shah7128e502013-02-20 13:24:48 -080096void QClient::MPDeathNotifier::died() {
Raj Kamal58b31a02014-12-16 15:53:53 +053097 mHwcContext->mDrawLock.lock();
Saurabh Shah7128e502013-02-20 13:24:48 -080098 ALOGD_IF(QCLIENT_DEBUG, "Media Player died");
99 mHwcContext->mSecuring = false;
100 mHwcContext->mSecureMode = false;
Raj Kamal58b31a02014-12-16 15:53:53 +0530101 mHwcContext->mDrawLock.unlock();
Saurabh Shah7128e502013-02-20 13:24:48 -0800102 if(mHwcContext->proc)
103 mHwcContext->proc->invalidate(mHwcContext->proc);
104}
105
Naseer Ahmed4957c522013-11-12 18:07:15 -0500106static android::status_t screenRefresh(hwc_context_t *ctx) {
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -0800107 status_t result = NO_INIT;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500108 if(ctx->proc) {
109 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -0800110 result = NO_ERROR;
111 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -0800112 return result;
113}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700114
Naseer Ahmed4957c522013-11-12 18:07:15 -0500115static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) {
116 ctx->mExtOrientation = orientation;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700117}
118
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500119static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) {
120 int connected;
121 connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0;
122 outParcel->writeInt32(connected);
123}
124
125static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel,
126 Parcel* outParcel) {
127 int dpy = inParcel->readInt32();
128 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800129 outParcel->writeInt32(ctx->dpyAttr[dpy].xres);
130 outParcel->writeInt32(ctx->dpyAttr[dpy].yres);
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500131 outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi);
132 outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi);
133 //XXX: Need to check what to return for HDMI
134 outParcel->writeInt32(ctx->mMDP.panel);
135}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800136static void setHSIC(const Parcel* inParcel) {
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500137 int dpy = inParcel->readInt32();
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800138 ALOGD_IF(0, "In %s: dpy = %d", __FUNCTION__, dpy);
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500139 HSICData_t hsic_data;
140 hsic_data.hue = inParcel->readInt32();
141 hsic_data.saturation = inParcel->readFloat();
142 hsic_data.intensity = inParcel->readInt32();
143 hsic_data.contrast = inParcel->readFloat();
144 //XXX: Actually set the HSIC data through ABL lib
145}
146
147
Naseer Ahmed4957c522013-11-12 18:07:15 -0500148static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) {
149 ctx->mBufferMirrorMode = enable;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700150}
151
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800152static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy,
153 Parcel* outParcel) {
154 // Get the info only if the dpy is valid
155 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
156 Locker::Autolock _sl(ctx->mDrawLock);
157 if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) {
158 // Return the destRect on external, if external orienation
159 // is enabled
160 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left);
161 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top);
162 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right);
163 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom);
164 } else {
165 outParcel->writeInt32(ctx->mViewFrame[dpy].left);
166 outParcel->writeInt32(ctx->mViewFrame[dpy].top);
167 outParcel->writeInt32(ctx->mViewFrame[dpy].right);
168 outParcel->writeInt32(ctx->mViewFrame[dpy].bottom);
169 }
170 return NO_ERROR;
171 } else {
172 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
173 return BAD_VALUE;
174 }
175}
176
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700177// USed for setting the secondary(hdmi/wfd) status
178static void setSecondaryDisplayStatus(hwc_context_t *ctx,
179 const Parcel* inParcel) {
180 uint32_t dpy = inParcel->readInt32();
181 uint32_t status = inParcel->readInt32();
182 ALOGD_IF(QCLIENT_DEBUG, "%s: dpy = %d status = %s", __FUNCTION__,
183 dpy, getExternalDisplayState(status));
184
185 if(dpy > HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
Raj Kamal0d53fc62014-11-25 17:36:36 +0530186 if(dpy == HWC_DISPLAY_VIRTUAL && status == qdutils::EXTERNAL_OFFLINE) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700187 ctx->mWfdSyncLock.lock();
188 ctx->mWfdSyncLock.signal();
189 ctx->mWfdSyncLock.unlock();
Raj Kamal0d53fc62014-11-25 17:36:36 +0530190 } else if(status == qdutils::EXTERNAL_PAUSE) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700191 handle_pause(ctx, dpy);
Raj Kamal0d53fc62014-11-25 17:36:36 +0530192 } else if(status == qdutils::EXTERNAL_RESUME) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700193 handle_resume(ctx, dpy);
194 }
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800195 } else {
Ramakant Singh8595cca2014-11-06 16:17:08 +0530196 ALOGE("%s: Invalid dpy %d", __FUNCTION__, dpy);
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700197 return;
Raj kamal59fea562014-04-01 16:52:19 +0530198 }
199}
200
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700201
202static status_t setViewFrame(hwc_context_t* ctx, const Parcel* inParcel) {
203 int dpy = inParcel->readInt32();
204 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
205 Locker::Autolock _sl(ctx->mDrawLock);
206 ctx->mViewFrame[dpy].left = inParcel->readInt32();
207 ctx->mViewFrame[dpy].top = inParcel->readInt32();
208 ctx->mViewFrame[dpy].right = inParcel->readInt32();
209 ctx->mViewFrame[dpy].bottom = inParcel->readInt32();
210 ALOGD_IF(QCLIENT_DEBUG, "%s: mViewFrame[%d] = [%d %d %d %d]",
211 __FUNCTION__, dpy,
212 ctx->mViewFrame[dpy].left, ctx->mViewFrame[dpy].top,
213 ctx->mViewFrame[dpy].right, ctx->mViewFrame[dpy].bottom);
214 return NO_ERROR;
215 } else {
216 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
217 return BAD_VALUE;
218 }
219}
220
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400221static void toggleDynamicDebug(hwc_context_t* ctx, const Parcel* inParcel) {
222 int debug_type = inParcel->readInt32();
223 bool enable = !!inParcel->readInt32();
224 ALOGD("%s: debug_type: %d enable:%d",
225 __FUNCTION__, debug_type, enable);
226 Locker::Autolock _sl(ctx->mDrawLock);
227 switch (debug_type) {
228 //break is ignored for DEBUG_ALL to toggle all of them at once
229 case IQService::DEBUG_ALL:
230 case IQService::DEBUG_MDPCOMP:
231 qhwc::MDPComp::dynamicDebug(enable);
232 if (debug_type != IQService::DEBUG_ALL)
233 break;
234 case IQService::DEBUG_VSYNC:
235 ctx->vstate.debug = enable;
236 if (debug_type != IQService::DEBUG_ALL)
237 break;
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700238 case IQService::DEBUG_VD:
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700239 HWCVirtualVDS::dynamicDebug(enable);
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700240 if (debug_type != IQService::DEBUG_ALL)
241 break;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700242 case IQService::DEBUG_PIPE_LIFECYCLE:
243 Overlay::debugPipeLifecycle(enable);
244 if (debug_type != IQService::DEBUG_ALL)
245 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400246 }
247}
248
Saurabh Shah59562ff2014-09-30 16:13:12 -0700249static void setIdleTimeout(hwc_context_t* ctx, const Parcel* inParcel) {
250 uint32_t timeout = (uint32_t)inParcel->readInt32();
251 ALOGD("%s :%u ms", __FUNCTION__, timeout);
252 Locker::Autolock _sl(ctx->mDrawLock);
253 MDPComp::setIdleTimeout(timeout);
254}
255
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700256static void setMaxPipesPerMixer(hwc_context_t* ctx, const Parcel* inParcel) {
257 uint32_t value = (uint32_t)inParcel->readInt32();
258 ALOGD("%s : setting MaxPipesPerMixer: %d ", __FUNCTION__, value);
259 Locker::Autolock _sl(ctx->mDrawLock);
260 MDPComp::setMaxPipesPerMixer(value);
261}
262
Saurabh Shahcd018352014-11-11 13:54:19 -0800263static void toggleBWC(hwc_context_t* ctx, const Parcel* inParcel) {
264 uint32_t enable = (uint32_t)inParcel->readInt32();
265 if(MDPVersion::getInstance().supportsBWC()) {
266 Locker::Autolock _sl(ctx->mDrawLock);
267 ctx->mBWCEnabled = (bool) enable;
268 ALOGI("%s: Set BWC to %d", __FUNCTION__, enable);
269 } else {
270 ALOGI("%s: Target doesn't support BWC", __FUNCTION__);
271 }
272}
273
Raj Kamal0d53fc62014-11-25 17:36:36 +0530274static void configureDynRefreshRate(hwc_context_t* ctx,
275 const Parcel* inParcel) {
276 uint32_t op = (uint32_t)inParcel->readInt32();
277 uint32_t refresh_rate = (uint32_t)inParcel->readInt32();
278 MDPVersion& mdpHw = MDPVersion::getInstance();
279 uint32_t dpy = HWC_DISPLAY_PRIMARY;
280
281 if(mdpHw.isDynFpsSupported()) {
282 Locker::Autolock _sl(ctx->mDrawLock);
283
284 switch (op) {
285 case DISABLE_METADATA_DYN_REFRESH_RATE:
286 ctx->mUseMetaDataRefreshRate = false;
287 setRefreshRate(ctx, dpy, ctx->dpyAttr[dpy].refreshRate);
288 break;
289 case ENABLE_METADATA_DYN_REFRESH_RATE:
290 ctx->mUseMetaDataRefreshRate = true;
291 setRefreshRate(ctx, dpy, ctx->dpyAttr[dpy].refreshRate);
292 break;
293 case SET_BINDER_DYN_REFRESH_RATE:
294 if(ctx->mUseMetaDataRefreshRate)
295 ALOGW("%s: Ignoring binder request to change refresh-rate",
296 __FUNCTION__);
297 else {
298 uint32_t rate = roundOff(refresh_rate);
299 if((rate >= mdpHw.getMinFpsSupported() &&
300 rate <= mdpHw.getMaxFpsSupported())) {
301 setRefreshRate(ctx, dpy, rate);
302 } else {
303 ALOGE("%s: Requested refresh-rate should be between \
304 (%d) and (%d). Given (%d)", __FUNCTION__,
305 mdpHw.getMinFpsSupported(),
306 mdpHw.getMaxFpsSupported(), rate);
307 }
308 }
309 break;
310 default:
311 ALOGE("%s: Invalid op %d",__FUNCTION__,op);
312 }
313 }
314}
315
Jeykumar Sankaran14d41a82015-03-11 14:13:43 -0700316static status_t setPartialUpdateState(hwc_context_t *ctx, uint32_t state) {
317 ALOGD("%s: state: %d", __FUNCTION__, state);
318 switch(state) {
319 case IQService::PREF_PARTIAL_UPDATE:
320 if(qhwc::MDPComp::setPartialUpdatePref(ctx, true) < 0)
321 return NO_INIT;
322 return NO_ERROR;
323 case IQService::PREF_POST_PROCESSING:
324 if(qhwc::MDPComp::setPartialUpdatePref(ctx, false) < 0)
325 return NO_INIT;
326 qhwc::MDPComp::enablePartialUpdate(false);
327 return NO_ERROR;
328 case IQService::ENABLE_PARTIAL_UPDATE:
329 qhwc::MDPComp::enablePartialUpdate(true);
330 return NO_ERROR;
331 default:
332 ALOGE("%s: Invalid state", __FUNCTION__);
333 return NO_ERROR;
334 };
Jeykumar Sankaran53b05f22014-08-05 11:27:03 -0700335}
336
Naseer Ahmed78951b22014-12-10 18:19:21 -0500337static void toggleScreenUpdate(hwc_context_t* ctx, uint32_t on) {
338 ALOGD("%s: toggle update: %d", __FUNCTION__, on);
Naseer Ahmed78951b22014-12-10 18:19:21 -0500339 if (on == 0) {
Raj Kamal58b31a02014-12-16 15:53:53 +0530340 ctx->mDrawLock.lock();
Naseer Ahmed78951b22014-12-10 18:19:21 -0500341 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isPause = true;
342 ctx->mOverlay->configBegin();
343 ctx->mOverlay->configDone();
344 ctx->mRotMgr->clear();
345 if(!Overlay::displayCommit(ctx->dpyAttr[0].fd)) {
346 ALOGE("%s: Display commit failed", __FUNCTION__);
347 }
Raj Kamal58b31a02014-12-16 15:53:53 +0530348 ctx->mDrawLock.unlock();
Naseer Ahmed78951b22014-12-10 18:19:21 -0500349 } else {
Raj Kamal58b31a02014-12-16 15:53:53 +0530350 ctx->mDrawLock.lock();
Naseer Ahmed78951b22014-12-10 18:19:21 -0500351 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isPause = false;
Raj Kamal58b31a02014-12-16 15:53:53 +0530352 ctx->mDrawLock.unlock();
Naseer Ahmed78951b22014-12-10 18:19:21 -0500353 ctx->proc->invalidate(ctx->proc);
354 }
355}
356
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500357static void setS3DMode(hwc_context_t* ctx, int mode) {
358 if (ctx->mHDMIDisplay) {
359 if(ctx->mHDMIDisplay->isS3DModeSupported(mode)) {
360 ALOGD("%s: Force S3D mode to %d", __FUNCTION__, mode);
361 Locker::Autolock _sl(ctx->mDrawLock);
362 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].s3dModeForced = true;
363 setup3DMode(ctx, HWC_DISPLAY_EXTERNAL, mode);
364 } else {
365 ALOGD("%s: mode %d is not supported", __FUNCTION__, mode);
366 }
367 } else {
368 ALOGE("%s: No HDMI Display detected", __FUNCTION__);
369 }
370}
371
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800372static status_t setActiveConfig(hwc_context_t* ctx, const Parcel *inParcel,
373 Parcel *outParcel) {
374 uint32_t index = inParcel->readInt32();
375 int dpy = inParcel->readInt32();
376 //Currently only primary supported
377 if(dpy > HWC_DISPLAY_PRIMARY) {
378 return BAD_VALUE;
379 }
380
381 Configs *configs = Configs::getInstance();
382 if(configs == NULL) {
383 ALOGE("%s(): Unable to acquire a Configs instance", __FUNCTION__);
384 return INVALID_OPERATION;
385 }
386
387 if(configs->getActiveConfig() == index) {
388 ALOGI("%s(): Config %u is already set", __FUNCTION__, index);
389 return ALREADY_EXISTS;
390 }
391
392 ctx->mDrawLock.lock();
393 //Updates the necessary sysfs nodes and reads split info again which is
394 //needed to reinitialize composition resources.
395 if(configs->setActiveConfig(index) == false) {
396 ALOGE("%s(): Failed to set config %u", __FUNCTION__, index);
397 ctx->mDrawLock.unlock();
398 return UNKNOWN_ERROR;
399 }
400
401 qdutils::DisplayAttributes attr = configs->getAttributes(index);
402
403 ctx->dpyAttr[dpy].xres = attr.xres;
404 ctx->dpyAttr[dpy].yres = attr.yres;
405
406 ctx->dpyAttr[dpy].fbScaling = ((ctx->dpyAttr[dpy].xres !=
407 ctx->dpyAttr[dpy].xresFB) || (ctx->dpyAttr[dpy].yres !=
408 ctx->dpyAttr[dpy].yresFB));
409
410 destroyCompositionResources(ctx, dpy);
411 initCompositionResources(ctx, dpy);
412 ctx->dpyAttr[dpy].configSwitched = true;
413 ctx->mDrawLock.unlock();
414 ctx->proc->invalidate(ctx->proc);
415 return NO_ERROR;
416}
417
418static status_t getActiveConfig(hwc_context_t* ctx, const Parcel *inParcel,
419 Parcel *outParcel) {
420 Locker::Autolock _sl(ctx->mDrawLock);
421 int dpy = inParcel->readInt32();
422 //Currently only primary supported
423 if(dpy > HWC_DISPLAY_PRIMARY) {
424 return BAD_VALUE;
425 }
426
427 Configs *configs = Configs::getInstance();
428 if(configs == NULL) {
429 ALOGE("%s(): Unable to acquire a Configs instance", __FUNCTION__);
430 return INVALID_OPERATION;
431 }
432
433 outParcel->writeInt32(configs->getActiveConfig());
434 return NO_ERROR;
435}
436
437static status_t getConfigCount(hwc_context_t* ctx, const Parcel *inParcel,
438 Parcel *outParcel) {
439 Locker::Autolock _sl(ctx->mDrawLock);
440 int dpy = inParcel->readInt32();
441 //Currently only primary supported
442 if(dpy > HWC_DISPLAY_PRIMARY) {
443 return BAD_VALUE;
444 }
445
446 Configs *configs = Configs::getInstance();
447 if(configs == NULL) {
448 ALOGE("%s(): Unable to acquire a Configs instance", __FUNCTION__);
449 return INVALID_OPERATION;
450 }
451
452 outParcel->writeInt32(configs->getConfigCount());
453 return NO_ERROR;
454}
455
456static status_t getDisplayAttributesForConfig(hwc_context_t* ctx,
457 const Parcel *inParcel, Parcel *outParcel) {
458 Locker::Autolock _sl(ctx->mDrawLock);
459 uint32_t index = inParcel->readInt32();
460 int dpy = inParcel->readInt32();
461 //Currently only primary supported
462 if(dpy > HWC_DISPLAY_PRIMARY) {
463 return BAD_VALUE;
464 }
465
466 Configs *configs = Configs::getInstance();
467 if(configs == NULL) {
468 ALOGE("%s(): Unable to acquire a Configs instance", __FUNCTION__);
469 return INVALID_OPERATION;
470 }
471
472 //xres, yres are used from the Config class, we assume for now that the
473 //other params are the same. This might change in the future.
474 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
475
476 qdutils::DisplayAttributes attr = configs->getAttributes(index);
477 outParcel->writeInt32(attr.xres);
478 outParcel->writeInt32(attr.yres);
479
480 outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi);
481 outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi);
482 outParcel->writeInt32(ctx->mMDP.panel);
483
484 return NO_ERROR;
485}
486
Prabhanjan Kanduladb274fa2015-03-30 22:35:09 +0530487/* register/unregister camera service */
488static bool setCameraDeathNotifier(
489 android::sp<QClient::CamDeathNotifier> camDeathNotifier, bool on) {
490 sp<IServiceManager> sm = defaultServiceManager();
491 sp<IBinder> binder = sm->getService(String16("media.camera"));
492 if (binder == 0) {
493 ALOGW("%s: CameraService not published or dead...", __FUNCTION__);
494 return false;
495 }
496 if(on) {
497 binder->linkToDeath(camDeathNotifier);
498 } else {
499 binder->unlinkToDeath(camDeathNotifier);
500 }
501 return true;
502}
503
504static bool updateDisplayBWCapForCam(bool on) {
505 char sysfsPath[255];
506 char bw[64];
507 int bw_flag = 0; // to reset to default.
508
509 memset(sysfsPath, 0, sizeof(sysfsPath));
510 snprintf(sysfsPath , sizeof(sysfsPath), FILE_MAX_MDSSBW_FLAG);
511 int sysfsFd = open(sysfsPath, O_RDWR);
512 if(sysfsFd < 0 ) {
513 ALOGE("%s: Status: %d Error in opening %s: %s",
514 __FUNCTION__, on, sysfsPath, strerror(errno));
515 return false;
516 }
517
518 if(on) {
519 bw_flag = MDSS_MAX_BW_LIMIT_CAMERA;
520 }
521 snprintf(bw, sizeof(bw), "%d", bw_flag);
522 ssize_t bytes = pwrite(sysfsFd, bw, strlen(bw), 0);
523 if(bytes < 0) {
524 ALOGE ("%s: Unable to write into %s node %s",
525 __FUNCTION__, sysfsPath, strerror(errno));
526 close(sysfsFd);
527 return false;
528 }
529 close(sysfsFd);
530 return true;
531}
532
533static void setCameraStatus(hwc_context_t* ctx,
534 android::sp<QClient::CamDeathNotifier> camDeathNotifier, uint32_t on) {
535
536 //Currently we need this only for 8952.
537 if(!MDPVersion::getInstance().is8x52()) {
538 ALOGI("%s Not 8952?? return", __FUNCTION__);
539 return;
540 }
541
542 if(!setCameraDeathNotifier(camDeathNotifier, on)) {
543 ALOGE("%s failed in updateCameraStatus", __FUNCTION__);
544 return;
545 }
546
547 if(!updateDisplayBWCapForCam(on)) {
548 ALOGE("%s failed in updateDisplayBWCap", __FUNCTION__);
549 return;
550 }
551
552 // Trigger a screen update so that our BW setting will reflect
553 // atleast by next vsync.
554 screenRefresh(ctx);
555}
556
557void QClient::CamDeathNotifier::binderDied(const wp<IBinder>& who) {
558 //If Cameraservice abruptly gone, reset mdss bw caps
559 //This new cap will be applicable from next frame onwards
560 if(!updateDisplayBWCapForCam(false)) {
561 ALOGE("%s failed in updateDisplayBWCap", __FUNCTION__);
562 }
563}
564
Naseer Ahmed4957c522013-11-12 18:07:15 -0500565status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
566 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800567 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500568
Naseer Ahmed4957c522013-11-12 18:07:15 -0500569 switch(command) {
570 case IQService::SECURING:
571 securing(mHwcContext, inParcel->readInt32());
572 break;
573 case IQService::UNSECURING:
574 unsecuring(mHwcContext, inParcel->readInt32());
575 break;
576 case IQService::SCREEN_REFRESH:
577 return screenRefresh(mHwcContext);
578 break;
579 case IQService::EXTERNAL_ORIENTATION:
580 setExtOrientation(mHwcContext, inParcel->readInt32());
581 break;
582 case IQService::BUFFER_MIRRORMODE:
583 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
584 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800585 case IQService::GET_DISPLAY_VISIBLE_REGION:
586 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
587 outParcel);
588 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500589 case IQService::CHECK_EXTERNAL_STATUS:
590 isExternalConnected(mHwcContext, outParcel);
591 break;
592 case IQService::GET_DISPLAY_ATTRIBUTES:
593 getDisplayAttributes(mHwcContext, inParcel, outParcel);
594 break;
595 case IQService::SET_HSIC_DATA:
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800596 setHSIC(inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530597 break;
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700598 case IQService::SET_SECONDARY_DISPLAY_STATUS:
599 setSecondaryDisplayStatus(mHwcContext, inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530600 break;
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700601 case IQService::SET_VIEW_FRAME:
602 setViewFrame(mHwcContext, inParcel);
603 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400604 case IQService::DYNAMIC_DEBUG:
605 toggleDynamicDebug(mHwcContext, inParcel);
606 break;
Saurabh Shah59562ff2014-09-30 16:13:12 -0700607 case IQService::SET_IDLE_TIMEOUT:
608 setIdleTimeout(mHwcContext, inParcel);
609 break;
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700610 case IQService::SET_MAX_PIPES_PER_MIXER:
611 setMaxPipesPerMixer(mHwcContext, inParcel);
Jeykumar Sankaran85ddc0c2014-12-17 14:39:26 -0800612 break;
Jeykumar Sankaran53b05f22014-08-05 11:27:03 -0700613 case IQService::SET_PARTIAL_UPDATE:
Jeykumar Sankaran14d41a82015-03-11 14:13:43 -0700614 ret = setPartialUpdateState(mHwcContext, inParcel->readInt32());
Jeykumar Sankaranbe93e272014-06-19 18:15:57 -0700615 break;
Saurabh Shahcd018352014-11-11 13:54:19 -0800616 case IQService::TOGGLE_BWC:
617 toggleBWC(mHwcContext, inParcel);
618 break;
Raj Kamal0d53fc62014-11-25 17:36:36 +0530619 case IQService::CONFIGURE_DYN_REFRESH_RATE:
620 configureDynRefreshRate(mHwcContext, inParcel);
621 break;
Naseer Ahmed78951b22014-12-10 18:19:21 -0500622 case IQService::TOGGLE_SCREEN_UPDATE:
623 toggleScreenUpdate(mHwcContext, inParcel->readInt32());
624 break;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500625 case IQService::SET_S3D_MODE:
626 setS3DMode(mHwcContext, inParcel->readInt32());
627 break;
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800628 case IQService::SET_ACTIVE_CONFIG:
629 ret = setActiveConfig(mHwcContext, inParcel, outParcel);
630 break;
631 case IQService::GET_ACTIVE_CONFIG:
632 ret = getActiveConfig(mHwcContext, inParcel, outParcel);
633 break;
634 case IQService::GET_CONFIG_COUNT:
635 ret = getConfigCount(mHwcContext, inParcel, outParcel);
636 break;
637 case IQService::GET_DISPLAY_ATTRIBUTES_FOR_CONFIG:
638 ret = getDisplayAttributesForConfig(mHwcContext, inParcel,
639 outParcel);
Zohaib Alam83ea46d2015-03-23 15:44:19 -0400640 case IQService::QDCM_SVC_CMDS:
641 qdcmCmdsHandler(mHwcContext, inParcel, outParcel);
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800642 break;
Prabhanjan Kanduladb274fa2015-03-30 22:35:09 +0530643 case IQService::SET_CAMERA_STATUS:
644 setCameraStatus(mHwcContext,
645 mCamDeathNotifier, inParcel->readInt32());
646 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500647 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800648 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500649 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800650 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500651}
652
Saurabh Shah86c17292013-02-08 15:24:13 -0800653}