blob: 50e94c9b6540aae6ba0f311606d4a6a481cc29ba [file] [log] [blame]
Saurabh Shah86c17292013-02-08 15:24:13 -08001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 *
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;
39
40namespace qClient {
41
42// ----------------------------------------------------------------------------
Saurabh Shah7128e502013-02-20 13:24:48 -080043QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx),
44 mMPDeathNotifier(new MPDeathNotifier(ctx))
Saurabh Shah86c17292013-02-08 15:24:13 -080045{
46 ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked");
47}
48
49QClient::~QClient()
50{
51 ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked");
52}
53
Naseer Ahmed4957c522013-11-12 18:07:15 -050054static void securing(hwc_context_t *ctx, uint32_t startEnd) {
55 Locker::Autolock _sl(ctx->mDrawLock);
Saurabh Shahc2125772013-03-15 16:49:50 -070056 //The only way to make this class in this process subscribe to media
57 //player's death.
58 IMediaDeathNotifier::getMediaPlayerService();
59
Naseer Ahmed4957c522013-11-12 18:07:15 -050060 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080061 //We're done securing
62 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050063 ctx->mSecureMode = true;
64 if(ctx->proc)
65 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080066}
67
Naseer Ahmed4957c522013-11-12 18:07:15 -050068static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) {
69 Locker::Autolock _sl(ctx->mDrawLock);
70 ctx->mSecuring = startEnd;
Saurabh Shah86c17292013-02-08 15:24:13 -080071 //We're done unsecuring
72 if(startEnd == IQService::END)
Naseer Ahmed4957c522013-11-12 18:07:15 -050073 ctx->mSecureMode = false;
74 if(ctx->proc)
75 ctx->proc->invalidate(ctx->proc);
Saurabh Shah86c17292013-02-08 15:24:13 -080076}
77
Saurabh Shah7128e502013-02-20 13:24:48 -080078void QClient::MPDeathNotifier::died() {
Saurabh Shahb39f8152013-08-22 10:21:44 -070079 Locker::Autolock _sl(mHwcContext->mDrawLock);
Saurabh Shah7128e502013-02-20 13:24:48 -080080 ALOGD_IF(QCLIENT_DEBUG, "Media Player died");
81 mHwcContext->mSecuring = false;
82 mHwcContext->mSecureMode = false;
83 if(mHwcContext->proc)
84 mHwcContext->proc->invalidate(mHwcContext->proc);
85}
86
Naseer Ahmed4957c522013-11-12 18:07:15 -050087static android::status_t screenRefresh(hwc_context_t *ctx) {
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080088 status_t result = NO_INIT;
Naseer Ahmed4957c522013-11-12 18:07:15 -050089 if(ctx->proc) {
90 ctx->proc->invalidate(ctx->proc);
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080091 result = NO_ERROR;
92 }
Jeykumar Sankaran9f59a762013-02-28 10:45:56 -080093 return result;
94}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -070095
Naseer Ahmed4957c522013-11-12 18:07:15 -050096static android::status_t vpuCommand(hwc_context_t *ctx,
97 uint32_t command,
98 const Parcel* inParcel,
99 Parcel* outParcel) {
Naseer Ahmed58780b92013-07-29 17:41:40 -0400100 status_t result = NO_INIT;
Naseer Ahmed58780b92013-07-29 17:41:40 -0400101#ifdef VPU_TARGET
Naseer Ahmed4957c522013-11-12 18:07:15 -0500102 result = ctx->mVPUClient->processCommand(command, inParcel, outParcel);
Naseer Ahmed58780b92013-07-29 17:41:40 -0400103#endif
Naseer Ahmed58780b92013-07-29 17:41:40 -0400104 return result;
105}
106
Naseer Ahmed4957c522013-11-12 18:07:15 -0500107static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) {
108 ctx->mExtOrientation = orientation;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700109}
110
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500111static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) {
112 int connected;
113 connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0;
114 outParcel->writeInt32(connected);
115}
116
117static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel,
118 Parcel* outParcel) {
119 int dpy = inParcel->readInt32();
120 outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period);
121 outParcel->writeInt32(ctx->dpyAttr[dpy].xres);
122 outParcel->writeInt32(ctx->dpyAttr[dpy].yres);
123 outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi);
124 outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi);
125 //XXX: Need to check what to return for HDMI
126 outParcel->writeInt32(ctx->mMDP.panel);
127}
128static void setHSIC(hwc_context_t* ctx, const Parcel* inParcel) {
129 int dpy = inParcel->readInt32();
130 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
Naseer Ahmed4957c522013-11-12 18:07:15 -0500168status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
169 Parcel* outParcel) {
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800170 status_t ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500171
172 if (command > IQService::VPU_COMMAND_LIST_START &&
173 command < IQService::VPU_COMMAND_LIST_END) {
174 return vpuCommand(mHwcContext, command, inParcel, outParcel);
175 }
176
177 switch(command) {
178 case IQService::SECURING:
179 securing(mHwcContext, inParcel->readInt32());
180 break;
181 case IQService::UNSECURING:
182 unsecuring(mHwcContext, inParcel->readInt32());
183 break;
184 case IQService::SCREEN_REFRESH:
185 return screenRefresh(mHwcContext);
186 break;
187 case IQService::EXTERNAL_ORIENTATION:
188 setExtOrientation(mHwcContext, inParcel->readInt32());
189 break;
190 case IQService::BUFFER_MIRRORMODE:
191 setBufferMirrorMode(mHwcContext, inParcel->readInt32());
192 break;
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800193 case IQService::GET_DISPLAY_VISIBLE_REGION:
194 ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(),
195 outParcel);
196 break;
Naseer Ahmed78c952e2013-11-25 18:12:23 -0500197 case IQService::CHECK_EXTERNAL_STATUS:
198 isExternalConnected(mHwcContext, outParcel);
199 break;
200 case IQService::GET_DISPLAY_ATTRIBUTES:
201 getDisplayAttributes(mHwcContext, inParcel, outParcel);
202 break;
203 case IQService::SET_HSIC_DATA:
204 setHSIC(mHwcContext, inParcel);
205 break;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500206 default:
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800207 ret = NO_ERROR;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500208 }
Arun Kumar K.R8e7a62f2013-12-06 18:55:41 -0800209 return ret;
Naseer Ahmed4957c522013-11-12 18:07:15 -0500210}
211
212
213
Saurabh Shah86c17292013-02-08 15:24:13 -0800214}