blob: fd0a36c77b4ab3157b705a1888f1d55ff372b726 [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>
Saurabh Shah86c17292013-02-08 15:24:13 -080037
38#define QCLIENT_DEBUG 0
39
40using namespace android;
41using namespace qService;
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080042using namespace qhwc;
Saurabh Shah24eec8a2014-08-22 15:07:25 -070043using namespace overlay;
Saurabh Shah86c17292013-02-08 15:24:13 -080044
45namespace qClient {
46
47// ----------------------------------------------------------------------------
Saurabh Shah7128e502013-02-20 13:24:48 -080048QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx),
49 mMPDeathNotifier(new MPDeathNotifier(ctx))
Saurabh Shah86c17292013-02-08 15:24:13 -080050{
51 ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked");
52}
53
54QClient::~QClient()
55{
56 ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked");
57}
58
Naseer Ahmed4957c522013-11-12 18:07:15 -050059static void securing(hwc_context_t *ctx, uint32_t startEnd) {
60 Locker::Autolock _sl(ctx->mDrawLock);
Saurabh Shahc2125772013-03-15 16:49:50 -070061 //The only way to make this class in this process subscribe to media
62 //player's death.
63 IMediaDeathNotifier::getMediaPlayerService();
64
Naseer Ahmed4957c522013-11-12 18:07:15 -050065 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080066 //We're done securing
67 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050068 ctx->mSecureMode = true;
69 if(ctx->proc)
70 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080071}
72
Naseer Ahmed4957c522013-11-12 18:07:15 -050073static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) {
74 Locker::Autolock _sl(ctx->mDrawLock);
75 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080076 //We're done unsecuring
77 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050078 ctx->mSecureMode = false;
79 if(ctx->proc)
80 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080081}
82
Saurabh Shah7128e502013-02-20 13:24:48 -080083void QClient::MPDeathNotifier::died() {
Saurabh Shahb39f8152013-08-22 10:21:44 -070084 Locker::Autolock _sl(mHwcContext->mDrawLock);
Saurabh Shah7128e502013-02-20 13:24:48 -080085 ALOGD_IF(QCLIENT_DEBUG, "Media Player died");
86 mHwcContext->mSecuring = false;
87 mHwcContext->mSecureMode = false;
88 if(mHwcContext->proc)
89 mHwcContext->proc->invalidate(mHwcContext->proc);
90}
91
Naseer Ahmed4957c522013-11-12 18:07:15 -050092static android::status_t screenRefresh(hwc_context_t *ctx) {
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080093 status_t result = NO_INIT;
Naseer Ahmed4957c522013-11-12 18:07:15 -050094 if(ctx->proc) {
95 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080096 result = NO_ERROR;
97 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080098 return result;
99}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700100
Naseer Ahmed4957c522013-11-12 18:07:15 -0500101static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) {
102 ctx->mExtOrientation = orientation;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700103}
104
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500105static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) {
106 int connected;
107 connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0;
108 outParcel->writeInt32(connected);
109}
110
111static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel,
112 Parcel* outParcel) {
113 int dpy = inParcel->readInt32();
114 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
Dileep Kumar Reddie351d842014-03-25 10:39:21 +0530115 if (ctx->dpyAttr[dpy].customFBSize) {
116 outParcel->writeInt32(ctx->dpyAttr[dpy].xres_new);
117 outParcel->writeInt32(ctx->dpyAttr[dpy].yres_new);
118 } else {
119 outParcel->writeInt32(ctx->dpyAttr[dpy].xres);
120 outParcel->writeInt32(ctx->dpyAttr[dpy].yres);
121 }
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500122 outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi);
123 outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi);
124 //XXX: Need to check what to return for HDMI
125 outParcel->writeInt32(ctx->mMDP.panel);
126}
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800127static void setHSIC(const Parcel* inParcel) {
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500128 int dpy = inParcel->readInt32();
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800129 ALOGD_IF(0, "In %s: dpy = %d", __FUNCTION__, dpy);
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500130 HSICData_t hsic_data;
131 hsic_data.hue = inParcel->readInt32();
132 hsic_data.saturation = inParcel->readFloat();
133 hsic_data.intensity = inParcel->readInt32();
134 hsic_data.contrast = inParcel->readFloat();
135 //XXX: Actually set the HSIC data through ABL lib
136}
137
138
Naseer Ahmed4957c522013-11-12 18:07:15 -0500139static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) {
140 ctx->mBufferMirrorMode = enable;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700141}
142
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800143static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy,
144 Parcel* outParcel) {
145 // Get the info only if the dpy is valid
146 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
147 Locker::Autolock _sl(ctx->mDrawLock);
148 if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) {
149 // Return the destRect on external, if external orienation
150 // is enabled
151 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left);
152 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top);
153 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right);
154 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom);
155 } else {
156 outParcel->writeInt32(ctx->mViewFrame[dpy].left);
157 outParcel->writeInt32(ctx->mViewFrame[dpy].top);
158 outParcel->writeInt32(ctx->mViewFrame[dpy].right);
159 outParcel->writeInt32(ctx->mViewFrame[dpy].bottom);
160 }
161 return NO_ERROR;
162 } else {
163 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
164 return BAD_VALUE;
165 }
166}
167
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700168// USed for setting the secondary(hdmi/wfd) status
169static void setSecondaryDisplayStatus(hwc_context_t *ctx,
170 const Parcel* inParcel) {
171 uint32_t dpy = inParcel->readInt32();
172 uint32_t status = inParcel->readInt32();
173 ALOGD_IF(QCLIENT_DEBUG, "%s: dpy = %d status = %s", __FUNCTION__,
174 dpy, getExternalDisplayState(status));
175
176 if(dpy > HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
177 if(dpy == HWC_DISPLAY_VIRTUAL && status == EXTERNAL_OFFLINE) {
178 ctx->mWfdSyncLock.lock();
179 ctx->mWfdSyncLock.signal();
180 ctx->mWfdSyncLock.unlock();
181 } else if(status == EXTERNAL_PAUSE) {
182 handle_pause(ctx, dpy);
183 } else if(status == EXTERNAL_RESUME) {
184 handle_resume(ctx, dpy);
185 }
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800186 } else {
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700187 ALOGE("%s: Invalid dpy", __FUNCTION__, dpy);
188 return;
Raj kamal59fea562014-04-01 16:52:19 +0530189 }
190}
191
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700192
193static status_t setViewFrame(hwc_context_t* ctx, const Parcel* inParcel) {
194 int dpy = inParcel->readInt32();
195 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
196 Locker::Autolock _sl(ctx->mDrawLock);
197 ctx->mViewFrame[dpy].left = inParcel->readInt32();
198 ctx->mViewFrame[dpy].top = inParcel->readInt32();
199 ctx->mViewFrame[dpy].right = inParcel->readInt32();
200 ctx->mViewFrame[dpy].bottom = inParcel->readInt32();
201 ALOGD_IF(QCLIENT_DEBUG, "%s: mViewFrame[%d] = [%d %d %d %d]",
202 __FUNCTION__, dpy,
203 ctx->mViewFrame[dpy].left, ctx->mViewFrame[dpy].top,
204 ctx->mViewFrame[dpy].right, ctx->mViewFrame[dpy].bottom);
205 return NO_ERROR;
206 } else {
207 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
208 return BAD_VALUE;
209 }
210}
211
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400212static void toggleDynamicDebug(hwc_context_t* ctx, const Parcel* inParcel) {
213 int debug_type = inParcel->readInt32();
214 bool enable = !!inParcel->readInt32();
215 ALOGD("%s: debug_type: %d enable:%d",
216 __FUNCTION__, debug_type, enable);
217 Locker::Autolock _sl(ctx->mDrawLock);
218 switch (debug_type) {
219 //break is ignored for DEBUG_ALL to toggle all of them at once
220 case IQService::DEBUG_ALL:
221 case IQService::DEBUG_MDPCOMP:
222 qhwc::MDPComp::dynamicDebug(enable);
223 if (debug_type != IQService::DEBUG_ALL)
224 break;
225 case IQService::DEBUG_VSYNC:
226 ctx->vstate.debug = enable;
227 if (debug_type != IQService::DEBUG_ALL)
228 break;
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700229 case IQService::DEBUG_VD:
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700230 HWCVirtualVDS::dynamicDebug(enable);
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700231 if (debug_type != IQService::DEBUG_ALL)
232 break;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700233 case IQService::DEBUG_PIPE_LIFECYCLE:
234 Overlay::debugPipeLifecycle(enable);
235 if (debug_type != IQService::DEBUG_ALL)
236 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400237 }
238}
239
Saurabh Shah59562ff2014-09-30 16:13:12 -0700240static void setIdleTimeout(hwc_context_t* ctx, const Parcel* inParcel) {
241 uint32_t timeout = (uint32_t)inParcel->readInt32();
242 ALOGD("%s :%u ms", __FUNCTION__, timeout);
243 Locker::Autolock _sl(ctx->mDrawLock);
244 MDPComp::setIdleTimeout(timeout);
245}
246
Naseer Ahmed4957c522013-11-12 18:07:15 -0500247status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
248 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800249 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500250
Naseer Ahmed4957c522013-11-12 18:07:15 -0500251 switch(command) {
252 case IQService::SECURING:
253 securing(mHwcContext, inParcel->readInt32());
254 break;
255 case IQService::UNSECURING:
256 unsecuring(mHwcContext, inParcel->readInt32());
257 break;
258 case IQService::SCREEN_REFRESH:
259 return screenRefresh(mHwcContext);
260 break;
261 case IQService::EXTERNAL_ORIENTATION:
262 setExtOrientation(mHwcContext, inParcel->readInt32());
263 break;
264 case IQService::BUFFER_MIRRORMODE:
265 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
266 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800267 case IQService::GET_DISPLAY_VISIBLE_REGION:
268 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
269 outParcel);
270 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500271 case IQService::CHECK_EXTERNAL_STATUS:
272 isExternalConnected(mHwcContext, outParcel);
273 break;
274 case IQService::GET_DISPLAY_ATTRIBUTES:
275 getDisplayAttributes(mHwcContext, inParcel, outParcel);
276 break;
277 case IQService::SET_HSIC_DATA:
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800278 setHSIC(inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530279 break;
Arun Kumar K.R33888f52014-10-09 15:56:33 -0700280 case IQService::SET_SECONDARY_DISPLAY_STATUS:
281 setSecondaryDisplayStatus(mHwcContext, inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530282 break;
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700283 case IQService::SET_VIEW_FRAME:
284 setViewFrame(mHwcContext, inParcel);
285 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400286 case IQService::DYNAMIC_DEBUG:
287 toggleDynamicDebug(mHwcContext, inParcel);
288 break;
Saurabh Shah59562ff2014-09-30 16:13:12 -0700289 case IQService::SET_IDLE_TIMEOUT:
290 setIdleTimeout(mHwcContext, inParcel);
291 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500292 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800293 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500294 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800295 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500296}
297
Saurabh Shah86c17292013-02-08 15:24:13 -0800298}