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> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 34 | |
| 35 | #define QCLIENT_DEBUG 0 |
| 36 | |
| 37 | using namespace android; |
| 38 | using namespace qService; |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 39 | using namespace qhwc; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 40 | |
| 41 | namespace qClient { |
| 42 | |
| 43 | // ---------------------------------------------------------------------------- |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 44 | QClient::QClient(hwc_context_t *ctx) : mHwcContext(ctx), |
| 45 | mMPDeathNotifier(new MPDeathNotifier(ctx)) |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 46 | { |
| 47 | ALOGD_IF(QCLIENT_DEBUG, "QClient Constructor invoked"); |
| 48 | } |
| 49 | |
| 50 | QClient::~QClient() |
| 51 | { |
| 52 | ALOGD_IF(QCLIENT_DEBUG,"QClient Destructor invoked"); |
| 53 | } |
| 54 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 55 | static void securing(hwc_context_t *ctx, uint32_t startEnd) { |
| 56 | Locker::Autolock _sl(ctx->mDrawLock); |
Saurabh Shah | c212577 | 2013-03-15 16:49:50 -0700 | [diff] [blame] | 57 | //The only way to make this class in this process subscribe to media |
| 58 | //player's death. |
| 59 | IMediaDeathNotifier::getMediaPlayerService(); |
| 60 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 61 | ctx->mSecuring = startEnd; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 62 | //We're done securing |
| 63 | if(startEnd == IQService::END) |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 64 | ctx->mSecureMode = true; |
| 65 | if(ctx->proc) |
| 66 | ctx->proc->invalidate(ctx->proc); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 69 | static void unsecuring(hwc_context_t *ctx, uint32_t startEnd) { |
| 70 | Locker::Autolock _sl(ctx->mDrawLock); |
| 71 | ctx->mSecuring = startEnd; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 72 | //We're done unsecuring |
| 73 | if(startEnd == IQService::END) |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 74 | ctx->mSecureMode = false; |
| 75 | if(ctx->proc) |
| 76 | ctx->proc->invalidate(ctx->proc); |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 79 | void QClient::MPDeathNotifier::died() { |
Saurabh Shah | b39f815 | 2013-08-22 10:21:44 -0700 | [diff] [blame] | 80 | Locker::Autolock _sl(mHwcContext->mDrawLock); |
Saurabh Shah | 7128e50 | 2013-02-20 13:24:48 -0800 | [diff] [blame] | 81 | 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 Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 88 | static android::status_t screenRefresh(hwc_context_t *ctx) { |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 89 | status_t result = NO_INIT; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 90 | if(ctx->proc) { |
| 91 | ctx->proc->invalidate(ctx->proc); |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 92 | result = NO_ERROR; |
| 93 | } |
Jeykumar Sankaran | 9f59a76 | 2013-02-28 10:45:56 -0800 | [diff] [blame] | 94 | return result; |
| 95 | } |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 96 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 97 | static void setExtOrientation(hwc_context_t *ctx, uint32_t orientation) { |
| 98 | ctx->mExtOrientation = orientation; |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 101 | static void isExternalConnected(hwc_context_t* ctx, Parcel* outParcel) { |
| 102 | int connected; |
| 103 | connected = ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected ? 1 : 0; |
| 104 | outParcel->writeInt32(connected); |
| 105 | } |
| 106 | |
| 107 | static void getDisplayAttributes(hwc_context_t* ctx, const Parcel* inParcel, |
| 108 | Parcel* outParcel) { |
| 109 | int dpy = inParcel->readInt32(); |
| 110 | outParcel->writeInt32(ctx->dpyAttr[dpy].vsync_period); |
Dileep Kumar Reddi | e351d84 | 2014-03-25 10:39:21 +0530 | [diff] [blame^] | 111 | if (ctx->dpyAttr[dpy].customFBSize) { |
| 112 | outParcel->writeInt32(ctx->dpyAttr[dpy].xres_new); |
| 113 | outParcel->writeInt32(ctx->dpyAttr[dpy].yres_new); |
| 114 | } else { |
| 115 | outParcel->writeInt32(ctx->dpyAttr[dpy].xres); |
| 116 | outParcel->writeInt32(ctx->dpyAttr[dpy].yres); |
| 117 | } |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 118 | outParcel->writeFloat(ctx->dpyAttr[dpy].xdpi); |
| 119 | outParcel->writeFloat(ctx->dpyAttr[dpy].ydpi); |
| 120 | //XXX: Need to check what to return for HDMI |
| 121 | outParcel->writeInt32(ctx->mMDP.panel); |
| 122 | } |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 123 | static void setHSIC(const Parcel* inParcel) { |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 124 | int dpy = inParcel->readInt32(); |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 125 | ALOGD_IF(0, "In %s: dpy = %d", __FUNCTION__, dpy); |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 126 | HSICData_t hsic_data; |
| 127 | hsic_data.hue = inParcel->readInt32(); |
| 128 | hsic_data.saturation = inParcel->readFloat(); |
| 129 | hsic_data.intensity = inParcel->readInt32(); |
| 130 | hsic_data.contrast = inParcel->readFloat(); |
| 131 | //XXX: Actually set the HSIC data through ABL lib |
| 132 | } |
| 133 | |
| 134 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 135 | static void setBufferMirrorMode(hwc_context_t *ctx, uint32_t enable) { |
| 136 | ctx->mBufferMirrorMode = enable; |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 139 | static status_t getDisplayVisibleRegion(hwc_context_t* ctx, int dpy, |
| 140 | Parcel* outParcel) { |
| 141 | // Get the info only if the dpy is valid |
| 142 | if(dpy >= HWC_DISPLAY_PRIMARY && dpy <= HWC_DISPLAY_VIRTUAL) { |
| 143 | Locker::Autolock _sl(ctx->mDrawLock); |
| 144 | if(dpy && (ctx->mExtOrientation || ctx->mBufferMirrorMode)) { |
| 145 | // Return the destRect on external, if external orienation |
| 146 | // is enabled |
| 147 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.left); |
| 148 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.top); |
| 149 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.right); |
| 150 | outParcel->writeInt32(ctx->dpyAttr[dpy].mDstRect.bottom); |
| 151 | } else { |
| 152 | outParcel->writeInt32(ctx->mViewFrame[dpy].left); |
| 153 | outParcel->writeInt32(ctx->mViewFrame[dpy].top); |
| 154 | outParcel->writeInt32(ctx->mViewFrame[dpy].right); |
| 155 | outParcel->writeInt32(ctx->mViewFrame[dpy].bottom); |
| 156 | } |
| 157 | return NO_ERROR; |
| 158 | } else { |
| 159 | ALOGE("In %s: invalid dpy index %d", __FUNCTION__, dpy); |
| 160 | return BAD_VALUE; |
| 161 | } |
| 162 | } |
| 163 | |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 164 | static void pauseWFD(hwc_context_t *ctx, uint32_t pause) { |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 165 | /* TODO: Will remove pauseWFD once all the clients start using |
| 166 | * setWfdStatus to indicate the status of WFD display |
| 167 | */ |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 168 | int dpy = HWC_DISPLAY_VIRTUAL; |
| 169 | if(pause) { |
| 170 | //WFD Pause |
| 171 | handle_pause(ctx, dpy); |
| 172 | } else { |
| 173 | //WFD Resume |
| 174 | handle_resume(ctx, dpy); |
| 175 | } |
| 176 | } |
| 177 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 178 | static void setWfdStatus(hwc_context_t *ctx, uint32_t wfdStatus) { |
| 179 | |
| 180 | ALOGD_IF(HWC_WFDDISPSYNC_LOG, |
| 181 | "%s: Received a binder call that WFD state is %s", |
| 182 | __FUNCTION__,getExternalDisplayState(wfdStatus)); |
| 183 | int dpy = HWC_DISPLAY_VIRTUAL; |
| 184 | |
| 185 | if(wfdStatus == EXTERNAL_OFFLINE) { |
| 186 | ctx->mWfdSyncLock.lock(); |
| 187 | ctx->mWfdSyncLock.signal(); |
| 188 | ctx->mWfdSyncLock.unlock(); |
| 189 | } else if(wfdStatus == EXTERNAL_PAUSE) { |
| 190 | handle_pause(ctx, dpy); |
| 191 | } else if(wfdStatus == EXTERNAL_RESUME) { |
| 192 | handle_resume(ctx, dpy); |
| 193 | } |
| 194 | } |
| 195 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 196 | status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel, |
| 197 | Parcel* outParcel) { |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 198 | status_t ret = NO_ERROR; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 199 | |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 200 | switch(command) { |
| 201 | case IQService::SECURING: |
| 202 | securing(mHwcContext, inParcel->readInt32()); |
| 203 | break; |
| 204 | case IQService::UNSECURING: |
| 205 | unsecuring(mHwcContext, inParcel->readInt32()); |
| 206 | break; |
| 207 | case IQService::SCREEN_REFRESH: |
| 208 | return screenRefresh(mHwcContext); |
| 209 | break; |
| 210 | case IQService::EXTERNAL_ORIENTATION: |
| 211 | setExtOrientation(mHwcContext, inParcel->readInt32()); |
| 212 | break; |
| 213 | case IQService::BUFFER_MIRRORMODE: |
| 214 | setBufferMirrorMode(mHwcContext, inParcel->readInt32()); |
| 215 | break; |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 216 | case IQService::GET_DISPLAY_VISIBLE_REGION: |
| 217 | ret = getDisplayVisibleRegion(mHwcContext, inParcel->readInt32(), |
| 218 | outParcel); |
| 219 | break; |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 220 | case IQService::CHECK_EXTERNAL_STATUS: |
| 221 | isExternalConnected(mHwcContext, outParcel); |
| 222 | break; |
| 223 | case IQService::GET_DISPLAY_ATTRIBUTES: |
| 224 | getDisplayAttributes(mHwcContext, inParcel, outParcel); |
| 225 | break; |
| 226 | case IQService::SET_HSIC_DATA: |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 227 | setHSIC(inParcel); |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 228 | break; |
Arun Kumar K.R | c62935a | 2013-12-03 16:47:47 -0800 | [diff] [blame] | 229 | case IQService::PAUSE_WFD: |
| 230 | pauseWFD(mHwcContext, inParcel->readInt32()); |
Naseer Ahmed | 78c952e | 2013-11-25 18:12:23 -0500 | [diff] [blame] | 231 | break; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 232 | case IQService::SET_WFD_STATUS: |
| 233 | setWfdStatus(mHwcContext,inParcel->readInt32()); |
| 234 | break; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 235 | default: |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 236 | ret = NO_ERROR; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 237 | } |
Arun Kumar K.R | 8e7a62f | 2013-12-06 18:55:41 -0800 | [diff] [blame] | 238 | return ret; |
Naseer Ahmed | 4957c52 | 2013-11-12 18:07:15 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 241 | } |