blob: 8490058c2848b11bf297fddba2678fc7b46c7a47 [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.Rc62935a2013-12-03 16:47:47 -0800168static void pauseWFD(hwc_context_t *ctx, uint32_t pause) {
Raj kamal59fea562014-04-01 16:52:19 +0530169 /* TODO: Will remove pauseWFD once all the clients start using
170 * setWfdStatus to indicate the status of WFD display
171 */
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800172 int dpy = HWC_DISPLAY_VIRTUAL;
173 if(pause) {
174 //WFD Pause
175 handle_pause(ctx, dpy);
176 } else {
177 //WFD Resume
178 handle_resume(ctx, dpy);
179 }
180}
181
Raj kamal59fea562014-04-01 16:52:19 +0530182static void setWfdStatus(hwc_context_t *ctx, uint32_t wfdStatus) {
183
184 ALOGD_IF(HWC_WFDDISPSYNC_LOG,
185 "%s: Received a binder call that WFD state is %s",
186 __FUNCTION__,getExternalDisplayState(wfdStatus));
187 int dpy = HWC_DISPLAY_VIRTUAL;
188
189 if(wfdStatus == EXTERNAL_OFFLINE) {
190 ctx->mWfdSyncLock.lock();
191 ctx->mWfdSyncLock.signal();
192 ctx->mWfdSyncLock.unlock();
193 } else if(wfdStatus == EXTERNAL_PAUSE) {
194 handle_pause(ctx, dpy);
195 } else if(wfdStatus == EXTERNAL_RESUME) {
196 handle_resume(ctx, dpy);
197 }
198}
199
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700200
201static status_t setViewFrame(hwc_context_t* ctx, const Parcel* inParcel) {
202 int dpy = inParcel->readInt32();
203 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
204 Locker::Autolock _sl(ctx->mDrawLock);
205 ctx->mViewFrame[dpy].left = inParcel->readInt32();
206 ctx->mViewFrame[dpy].top = inParcel->readInt32();
207 ctx->mViewFrame[dpy].right = inParcel->readInt32();
208 ctx->mViewFrame[dpy].bottom = inParcel->readInt32();
209 ALOGD_IF(QCLIENT_DEBUG, "%s: mViewFrame[%d] = [%d %d %d %d]",
210 __FUNCTION__, dpy,
211 ctx->mViewFrame[dpy].left, ctx->mViewFrame[dpy].top,
212 ctx->mViewFrame[dpy].right, ctx->mViewFrame[dpy].bottom);
213 return NO_ERROR;
214 } else {
215 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
216 return BAD_VALUE;
217 }
218}
219
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400220static void toggleDynamicDebug(hwc_context_t* ctx, const Parcel* inParcel) {
221 int debug_type = inParcel->readInt32();
222 bool enable = !!inParcel->readInt32();
223 ALOGD("%s: debug_type: %d enable:%d",
224 __FUNCTION__, debug_type, enable);
225 Locker::Autolock _sl(ctx->mDrawLock);
226 switch (debug_type) {
227 //break is ignored for DEBUG_ALL to toggle all of them at once
228 case IQService::DEBUG_ALL:
229 case IQService::DEBUG_MDPCOMP:
230 qhwc::MDPComp::dynamicDebug(enable);
231 if (debug_type != IQService::DEBUG_ALL)
232 break;
233 case IQService::DEBUG_VSYNC:
234 ctx->vstate.debug = enable;
235 if (debug_type != IQService::DEBUG_ALL)
236 break;
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700237 case IQService::DEBUG_VD:
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700238 HWCVirtualVDS::dynamicDebug(enable);
Tatenda Chipeperekwa06af9cb2014-08-26 14:51:05 -0700239 if (debug_type != IQService::DEBUG_ALL)
240 break;
Saurabh Shah24eec8a2014-08-22 15:07:25 -0700241 case IQService::DEBUG_PIPE_LIFECYCLE:
242 Overlay::debugPipeLifecycle(enable);
243 if (debug_type != IQService::DEBUG_ALL)
244 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400245 }
246}
247
Naseer Ahmed4957c522013-11-12 18:07:15 -0500248status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
249 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800250 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500251
Naseer Ahmed4957c522013-11-12 18:07:15 -0500252 switch(command) {
253 case IQService::SECURING:
254 securing(mHwcContext, inParcel->readInt32());
255 break;
256 case IQService::UNSECURING:
257 unsecuring(mHwcContext, inParcel->readInt32());
258 break;
259 case IQService::SCREEN_REFRESH:
260 return screenRefresh(mHwcContext);
261 break;
262 case IQService::EXTERNAL_ORIENTATION:
263 setExtOrientation(mHwcContext, inParcel->readInt32());
264 break;
265 case IQService::BUFFER_MIRRORMODE:
266 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
267 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800268 case IQService::GET_DISPLAY_VISIBLE_REGION:
269 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
270 outParcel);
271 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500272 case IQService::CHECK_EXTERNAL_STATUS:
273 isExternalConnected(mHwcContext, outParcel);
274 break;
275 case IQService::GET_DISPLAY_ATTRIBUTES:
276 getDisplayAttributes(mHwcContext, inParcel, outParcel);
277 break;
278 case IQService::SET_HSIC_DATA:
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -0800279 setHSIC(inParcel);
Raj kamal59fea562014-04-01 16:52:19 +0530280 break;
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800281 case IQService::PAUSE_WFD:
282 pauseWFD(mHwcContext, inParcel->readInt32());
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500283 break;
Raj kamal59fea562014-04-01 16:52:19 +0530284 case IQService::SET_WFD_STATUS:
285 setWfdStatus(mHwcContext,inParcel->readInt32());
286 break;
Ramkumar Radhakrishnan0a021a82014-05-19 19:53:56 -0700287 case IQService::SET_VIEW_FRAME:
288 setViewFrame(mHwcContext, inParcel);
289 break;
Naseer Ahmed35a268c2014-06-24 19:07:13 -0400290 case IQService::DYNAMIC_DEBUG:
291 toggleDynamicDebug(mHwcContext, inParcel);
292 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500293 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800294 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500295 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800296 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500297}
298
Saurabh Shah86c17292013-02-08 15:24:13 -0800299}