Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 1 | /* |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-14, The Linux Foundation. All rights reserved. |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 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> |
Zohaib Alam | 1bb6561 | 2013-09-28 03:38:20 -0400 | [diff] [blame] | 33 | #include <mdp_version.h> |
Naseer Ahmed | 35a268c | 2014-06-24 19:07:13 -0400 | [diff] [blame] | 34 | #include <hwc_mdpcomp.h> |
Tatenda Chipeperekwa | 06af9cb | 2014-08-26 14:51:05 -0700 | [diff] [blame] | 35 | #include <hwc_virtual.h> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 36 | |
| 37 | #define QCLIENT_DEBUG 0 |
| 38 | |
| 39 | using namespace android; |
| 40 | using namespace qService; |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 41 | using namespace qhwc; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 42 | |
| 43 | namespace qClient { |
| 44 | |
| 45 | // ---------------------------------------------------------------------------- |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 46 | QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx), |
| 47 | mMPDeathNotifier(new MPDeathNotifier(ctx)) |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 48 | { |
| 49 | ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked"); |
| 50 | } |
| 51 | |
| 52 | QClient::~QClient() |
| 53 | { |
| 54 | ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked"); |
| 55 | } |
| 56 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 57 | static void securing(hwc_context_t *ctx, uint32_t startEnd) { |
| 58 | Locker::Autolock _sl(ctx->mDrawLock); |
Saurabh Shah | c212577 | 2013-03-15 16:49:50 -0700 | [diff] [blame] | 59 | //The only way to make this class in this process subscribe to media |
| 60 | //player's death. |
| 61 | IMediaDeathNotifier::getMediaPlayerService(); |
| 62 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 63 | ctx->mSecuring = startEnd; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 64 | //We're done securing |
| 65 | if(startEnd == IQService::END) |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 66 | ctx->mSecureMode = true; |
| 67 | if(ctx->proc) |
| 68 | ctx->proc->invalidate(ctx->proc); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 71 | static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) { |
| 72 | Locker::Autolock _sl(ctx->mDrawLock); |
| 73 | ctx->mSecuring = startEnd; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 74 | //We're done unsecuring |
| 75 | if(startEnd == IQService::END) |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 76 | ctx->mSecureMode = false; |
| 77 | if(ctx->proc) |
| 78 | ctx->proc->invalidate(ctx->proc); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 81 | void QClient::MPDeathNotifier::died() { |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 82 | Locker::Autolock _sl(mHwcContext->mDrawLock); |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 83 | ALOGD_IF(QCLIENT_DEBUG, "Media Player died"); |
| 84 | mHwcContext->mSecuring = false; |
| 85 | mHwcContext->mSecureMode = false; |
| 86 | if(mHwcContext->proc) |
| 87 | mHwcContext->proc->invalidate(mHwcContext->proc); |
| 88 | } |
| 89 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 90 | static android::status_t screenRefresh(hwc_context_t *ctx) { |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 91 | status_t result = NO_INIT; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 92 | if(ctx->proc) { |
| 93 | ctx->proc->invalidate(ctx->proc); |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 94 | result = NO_ERROR; |
| 95 | } |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 96 | return result; |
| 97 | } |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 98 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 99 | static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) { |
| 100 | ctx->mExtOrientation = orientation; |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 103 | static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) { |
| 104 | int connected; |
| 105 | connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0; |
| 106 | outParcel->writeInt32(connected); |
| 107 | } |
| 108 | |
| 109 | static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel, |
| 110 | Parcel* outParcel) { |
| 111 | int dpy = inParcel->readInt32(); |
| 112 | outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period); |
Dileep Kumar Reddi | e351d84 | 2014-03-25 10:39:21 +0530 | [diff] [blame] | 113 | if (ctx->dpyAttr[dpy].customFBSize) { |
| 114 | outParcel->writeInt32(ctx->dpyAttr[dpy].xres_new); |
| 115 | outParcel->writeInt32(ctx->dpyAttr[dpy].yres_new); |
| 116 | } else { |
| 117 | outParcel->writeInt32(ctx->dpyAttr[dpy].xres); |
| 118 | outParcel->writeInt32(ctx->dpyAttr[dpy].yres); |
| 119 | } |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 120 | outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi); |
| 121 | outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi); |
| 122 | //XXX: Need to check what to return for HDMI |
| 123 | outParcel->writeInt32(ctx->mMDP.panel); |
| 124 | } |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 125 | static void setHSIC(const Parcel* inParcel) { |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 126 | int dpy = inParcel->readInt32(); |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 127 | ALOGD_IF(0, "In %s: dpy = %d", __FUNCTION__, dpy); |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 128 | HSICData_t hsic_data; |
| 129 | hsic_data.hue = inParcel->readInt32(); |
| 130 | hsic_data.saturation = inParcel->readFloat(); |
| 131 | hsic_data.intensity = inParcel->readInt32(); |
| 132 | hsic_data.contrast = inParcel->readFloat(); |
| 133 | //XXX: Actually set the HSIC data through ABL lib |
| 134 | } |
| 135 | |
| 136 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 137 | static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) { |
| 138 | ctx->mBufferMirrorMode = enable; |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 141 | static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy, |
| 142 | Parcel* outParcel) { |
| 143 | // Get the info only if the dpy is valid |
| 144 | if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) { |
| 145 | Locker::Autolock _sl(ctx->mDrawLock); |
| 146 | if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) { |
| 147 | // Return the destRect on external, if external orienation |
| 148 | // is enabled |
| 149 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left); |
| 150 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top); |
| 151 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right); |
| 152 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom); |
| 153 | } else { |
| 154 | outParcel->writeInt32(ctx->mViewFrame[dpy].left); |
| 155 | outParcel->writeInt32(ctx->mViewFrame[dpy].top); |
| 156 | outParcel->writeInt32(ctx->mViewFrame[dpy].right); |
| 157 | outParcel->writeInt32(ctx->mViewFrame[dpy].bottom); |
| 158 | } |
| 159 | return NO_ERROR; |
| 160 | } else { |
| 161 | ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy); |
| 162 | return BAD_VALUE; |
| 163 | } |
| 164 | } |
| 165 | |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 166 | static void pauseWFD(hwc_context_t *ctx, uint32_t pause) { |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 167 | /* TODO: Will remove pauseWFD once all the clients start using |
| 168 | * setWfdStatus to indicate the status of WFD display |
| 169 | */ |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 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 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 180 | static void setWfdStatus(hwc_context_t *ctx, uint32_t wfdStatus) { |
| 181 | |
| 182 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 183 | "%s: Received a binder call that WFD state is %s", |
| 184 | __FUNCTION__,getExternalDisplayState(wfdStatus)); |
| 185 | int dpy = HWC_DISPLAY_VIRTUAL; |
| 186 | |
| 187 | if(wfdStatus == EXTERNAL_OFFLINE) { |
| 188 | ctx->mWfdSyncLock.lock(); |
| 189 | ctx->mWfdSyncLock.signal(); |
| 190 | ctx->mWfdSyncLock.unlock(); |
| 191 | } else if(wfdStatus == EXTERNAL_PAUSE) { |
| 192 | handle_pause(ctx, dpy); |
| 193 | } else if(wfdStatus == EXTERNAL_RESUME) { |
| 194 | handle_resume(ctx, dpy); |
| 195 | } |
| 196 | } |
| 197 | |
Ramkumar Radhakrishnan | 0a021a8 | 2014-05-19 19:53:56 -0700 | [diff] [blame] | 198 | |
| 199 | static status_t setViewFrame(hwc_context_t* ctx, const Parcel* inParcel) { |
| 200 | int dpy = inParcel->readInt32(); |
| 201 | if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) { |
| 202 | Locker::Autolock _sl(ctx->mDrawLock); |
| 203 | ctx->mViewFrame[dpy].left = inParcel->readInt32(); |
| 204 | ctx->mViewFrame[dpy].top = inParcel->readInt32(); |
| 205 | ctx->mViewFrame[dpy].right = inParcel->readInt32(); |
| 206 | ctx->mViewFrame[dpy].bottom = inParcel->readInt32(); |
| 207 | ALOGD_IF(QCLIENT_DEBUG, "%s: mViewFrame[%d] = [%d %d %d %d]", |
| 208 | __FUNCTION__, dpy, |
| 209 | ctx->mViewFrame[dpy].left, ctx->mViewFrame[dpy].top, |
| 210 | ctx->mViewFrame[dpy].right, ctx->mViewFrame[dpy].bottom); |
| 211 | return NO_ERROR; |
| 212 | } else { |
| 213 | ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy); |
| 214 | return BAD_VALUE; |
| 215 | } |
| 216 | } |
| 217 | |
Naseer Ahmed | 35a268c | 2014-06-24 19:07:13 -0400 | [diff] [blame] | 218 | static void toggleDynamicDebug(hwc_context_t* ctx, const Parcel* inParcel) { |
| 219 | int debug_type = inParcel->readInt32(); |
| 220 | bool enable = !!inParcel->readInt32(); |
| 221 | ALOGD("%s: debug_type: %d enable:%d", |
| 222 | __FUNCTION__, debug_type, enable); |
| 223 | Locker::Autolock _sl(ctx->mDrawLock); |
| 224 | switch (debug_type) { |
| 225 | //break is ignored for DEBUG_ALL to toggle all of them at once |
| 226 | case IQService::DEBUG_ALL: |
| 227 | case IQService::DEBUG_MDPCOMP: |
| 228 | qhwc::MDPComp::dynamicDebug(enable); |
| 229 | if (debug_type != IQService::DEBUG_ALL) |
| 230 | break; |
| 231 | case IQService::DEBUG_VSYNC: |
| 232 | ctx->vstate.debug = enable; |
| 233 | if (debug_type != IQService::DEBUG_ALL) |
| 234 | break; |
Tatenda Chipeperekwa | 06af9cb | 2014-08-26 14:51:05 -0700 | [diff] [blame] | 235 | case IQService::DEBUG_VD: |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame^] | 236 | HWCVirtualVDS::dynamicDebug(enable); |
Tatenda Chipeperekwa | 06af9cb | 2014-08-26 14:51:05 -0700 | [diff] [blame] | 237 | if (debug_type != IQService::DEBUG_ALL) |
| 238 | break; |
Naseer Ahmed | 35a268c | 2014-06-24 19:07:13 -0400 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 242 | status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel, |
| 243 | Parcel* outParcel) { |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 244 | status_t ret = NO_ERROR; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 245 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 246 | switch(command) { |
| 247 | case IQService::SECURING: |
| 248 | securing(mHwcContext, inParcel->readInt32()); |
| 249 | break; |
| 250 | case IQService::UNSECURING: |
| 251 | unsecuring(mHwcContext, inParcel->readInt32()); |
| 252 | break; |
| 253 | case IQService::SCREEN_REFRESH: |
| 254 | return screenRefresh(mHwcContext); |
| 255 | break; |
| 256 | case IQService::EXTERNAL_ORIENTATION: |
| 257 | setExtOrientation(mHwcContext, inParcel->readInt32()); |
| 258 | break; |
| 259 | case IQService::BUFFER_MIRRORMODE: |
| 260 | setBufferMirrorMode(mHwcContext, inParcel->readInt32()); |
| 261 | break; |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 262 | case IQService::GET_DISPLAY_VISIBLE_REGION: |
| 263 | ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(), |
| 264 | outParcel); |
| 265 | break; |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 266 | case IQService::CHECK_EXTERNAL_STATUS: |
| 267 | isExternalConnected(mHwcContext, outParcel); |
| 268 | break; |
| 269 | case IQService::GET_DISPLAY_ATTRIBUTES: |
| 270 | getDisplayAttributes(mHwcContext, inParcel, outParcel); |
| 271 | break; |
| 272 | case IQService::SET_HSIC_DATA: |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 273 | setHSIC(inParcel); |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 274 | break; |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 275 | case IQService::PAUSE_WFD: |
| 276 | pauseWFD(mHwcContext, inParcel->readInt32()); |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 277 | break; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 278 | case IQService::SET_WFD_STATUS: |
| 279 | setWfdStatus(mHwcContext,inParcel->readInt32()); |
| 280 | break; |
Ramkumar Radhakrishnan | 0a021a8 | 2014-05-19 19:53:56 -0700 | [diff] [blame] | 281 | case IQService::SET_VIEW_FRAME: |
| 282 | setViewFrame(mHwcContext, inParcel); |
| 283 | break; |
Naseer Ahmed | 35a268c | 2014-06-24 19:07:13 -0400 | [diff] [blame] | 284 | case IQService::DYNAMIC_DEBUG: |
| 285 | toggleDynamicDebug(mHwcContext, inParcel); |
| 286 | break; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 287 | default: |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 288 | ret = NO_ERROR; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 289 | } |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 290 | return ret; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 291 | } |
| 292 | |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 293 | } |