blob: 8c99d64f37571f04ef40041fae22081390ab11d6 [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>
Naseer Ahmed58780b92013-07-29 17:41:40 -040033#include <hwc_vpuclient.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080034
35#define QCLIENT_DEBUG 0
36
37using namespace android;
38using namespace qService;
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -080039using namespace qhwc;
Saurabh Shah86c17292013-02-08 15:24:13 -080040
41namespace qClient {
42
43// ----------------------------------------------------------------------------
Saurabh Shah7128e502013-02-20 13:24:48 -080044QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx),
45 mMPDeathNotifier(new MPDeathNotifier(ctx))
Saurabh Shah86c17292013-02-08 15:24:13 -080046{
47 ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked");
48}
49
50QClient::~QClient()
51{
52 ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked");
53}
54
Naseer Ahmed4957c522013-11-12 18:07:15 -050055static void securing(hwc_context_t *ctx, uint32_t startEnd) {
56 Locker::Autolock _sl(ctx->mDrawLock);
Saurabh Shahc2125772013-03-15 16:49:50 -070057 //The only way to make this class in this process subscribe to media
58 //player's death.
59 IMediaDeathNotifier::getMediaPlayerService();
60
Naseer Ahmed4957c522013-11-12 18:07:15 -050061 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080062 //We're done securing
63 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050064 ctx->mSecureMode = true;
65 if(ctx->proc)
66 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080067}
68
Naseer Ahmed4957c522013-11-12 18:07:15 -050069static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) {
70 Locker::Autolock _sl(ctx->mDrawLock);
71 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080072 //We're done unsecuring
73 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050074 ctx->mSecureMode = false;
75 if(ctx->proc)
76 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080077}
78
Saurabh Shah7128e502013-02-20 13:24:48 -080079void QClient::MPDeathNotifier::died() {
Saurabh Shahb39f8152013-08-22 10:21:44 -070080 Locker::Autolock _sl(mHwcContext->mDrawLock);
Saurabh Shah7128e502013-02-20 13:24:48 -080081 ALOGD_IF(QCLIENT_DEBUG, "Media Player died");
82 mHwcContext->mSecuring = false;
83 mHwcContext->mSecureMode = false;
84 if(mHwcContext->proc)
85 mHwcContext->proc->invalidate(mHwcContext->proc);
86}
87
Naseer Ahmed4957c522013-11-12 18:07:15 -050088static android::status_t screenRefresh(hwc_context_t *ctx) {
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080089 status_t result = NO_INIT;
Naseer Ahmed4957c522013-11-12 18:07:15 -050090 if(ctx->proc) {
91 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080092 result = NO_ERROR;
93 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080094 return result;
95}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070096
Naseer Ahmed4957c522013-11-12 18:07:15 -050097static android::status_t vpuCommand(hwc_context_t *ctx,
98 uint32_t command,
99 const Parcel* inParcel,
100 Parcel* outParcel) {
Naseer Ahmed58780b92013-07-29 17:41:40 -0400101 status_t result = NO_INIT;
Naseer Ahmed58780b92013-07-29 17:41:40 -0400102#ifdef VPU_TARGET
Naseer Ahmed4957c522013-11-12 18:07:15 -0500103 result = ctx->mVPUClient->processCommand(command, inParcel, outParcel);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400104#endif
Naseer Ahmed58780b92013-07-29 17:41:40 -0400105 return result;
106}
107
Naseer Ahmed4957c522013-11-12 18:07:15 -0500108static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) {
109 ctx->mExtOrientation = orientation;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700110}
111
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500112static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) {
113 int connected;
114 connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0;
115 outParcel->writeInt32(connected);
116}
117
118static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel,
119 Parcel* outParcel) {
120 int dpy = inParcel->readInt32();
121 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
122 outParcel->writeInt32(ctx->dpyAttr[dpy].xres);
123 outParcel->writeInt32(ctx->dpyAttr[dpy].yres);
124 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}
129static void setHSIC(hwc_context_t* ctx, const Parcel* inParcel) {
130 int dpy = inParcel->readInt32();
131 HSICData_t hsic_data;
132 hsic_data.hue = inParcel->readInt32();
133 hsic_data.saturation = inParcel->readFloat();
134 hsic_data.intensity = inParcel->readInt32();
135 hsic_data.contrast = inParcel->readFloat();
136 //XXX: Actually set the HSIC data through ABL lib
137}
138
139
Naseer Ahmed4957c522013-11-12 18:07:15 -0500140static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) {
141 ctx->mBufferMirrorMode = enable;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700142}
143
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800144static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy,
145 Parcel* outParcel) {
146 // Get the info only if the dpy is valid
147 if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) {
148 Locker::Autolock _sl(ctx->mDrawLock);
149 if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) {
150 // Return the destRect on external, if external orienation
151 // is enabled
152 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left);
153 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top);
154 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right);
155 outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom);
156 } else {
157 outParcel->writeInt32(ctx->mViewFrame[dpy].left);
158 outParcel->writeInt32(ctx->mViewFrame[dpy].top);
159 outParcel->writeInt32(ctx->mViewFrame[dpy].right);
160 outParcel->writeInt32(ctx->mViewFrame[dpy].bottom);
161 }
162 return NO_ERROR;
163 } else {
164 ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy);
165 return BAD_VALUE;
166 }
167}
168
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800169static void pauseWFD(hwc_context_t *ctx, uint32_t pause) {
170 int dpy = HWC_DISPLAY_VIRTUAL;
171 if(pause) {
172 //WFD Pause
173 handle_pause(ctx, dpy);
174 } else {
175 //WFD Resume
176 handle_resume(ctx, dpy);
177 }
178}
179
Naseer Ahmed4957c522013-11-12 18:07:15 -0500180status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
181 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800182 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500183
184 if (command > IQService::VPU_COMMAND_LIST_START &&
185 command < IQService::VPU_COMMAND_LIST_END) {
186 return vpuCommand(mHwcContext, command, inParcel, outParcel);
187 }
188
189 switch(command) {
190 case IQService::SECURING:
191 securing(mHwcContext, inParcel->readInt32());
192 break;
193 case IQService::UNSECURING:
194 unsecuring(mHwcContext, inParcel->readInt32());
195 break;
196 case IQService::SCREEN_REFRESH:
197 return screenRefresh(mHwcContext);
198 break;
199 case IQService::EXTERNAL_ORIENTATION:
200 setExtOrientation(mHwcContext, inParcel->readInt32());
201 break;
202 case IQService::BUFFER_MIRRORMODE:
203 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
204 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800205 case IQService::GET_DISPLAY_VISIBLE_REGION:
206 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
207 outParcel);
208 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500209 case IQService::CHECK_EXTERNAL_STATUS:
210 isExternalConnected(mHwcContext, outParcel);
211 break;
212 case IQService::GET_DISPLAY_ATTRIBUTES:
213 getDisplayAttributes(mHwcContext, inParcel, outParcel);
214 break;
215 case IQService::SET_HSIC_DATA:
216 setHSIC(mHwcContext, inParcel);
Arun Kumar K.Rc62935a2013-12-03 16:47:47 -0800217 case IQService::PAUSE_WFD:
218 pauseWFD(mHwcContext, inParcel->readInt32());
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500219 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500220 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800221 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500222 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800223 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500224}
225
226
227
Saurabh Shah86c17292013-02-08 15:24:13 -0800228}