1/* 2 * Copyright (c) 2014, 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 SERVICES; 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_qdcm.h> 31#include <hwc_utils.h> 32#include <utils/String16.h> 33#include <mdp_version.h> 34#include "mode_manager.h" 35#include "libmm-disp-apis.h" 36#include "IQService.h" 37 38using namespace android; 39using namespace qService; 40using namespace qhwc; 41using namespace qmode; 42 43namespace qQdcm { 44//---------------------------------------------------------------------------- 45void qdcmInitContext(hwc_context_t *ctx) 46{ 47 loadQdcmLibrary(ctx); 48} 49 50void qdcmCloseContext(hwc_context_t *ctx) 51{ 52 if (ctx->mQdcmInfo.mQdcmMode) { 53 unloadQdcmLibrary(ctx); 54 } 55} 56 57void qdcmApplyDefaultAfterBootAnimationDone(hwc_context_t *ctx) 58{ 59 if (ctx->mQdcmInfo.mQdcmMode) 60 ctx->mQdcmInfo.mQdcmMode->applyDefaultMode(0); 61} 62 63static void qdcmSetActiveMode(hwc_context_t *ctx, const Parcel *in, Parcel *out) 64{ 65 int ret = 0; 66 67 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 68 69 struct SET_MODE_PROP_IN params = 70 { (disp_id_type)in->readInt32(), in->readInt32()}; 71 72 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_SET_ACTIVE_MODE, 73 (void *)¶ms, (void *)NULL); 74 75 out->writeInt32(ret); //return operation status via binder. 76 } 77} 78 79static void qdcmSetDefaultMode(hwc_context_t *ctx, const Parcel *in, Parcel *out) 80{ 81 int ret = 0; 82 83 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 84 85 struct SET_MODE_PROP_IN params = 86 { (disp_id_type)in->readInt32(), in->readInt32()}; 87 88 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_SET_DEFAULT_MODE, 89 (void *)¶ms, (void *)NULL); 90 91 out->writeInt32(ret); //return operation status via binder. 92 } 93} 94 95static void qdcmGetDefaultMode(hwc_context_t *ctx, 96 const Parcel *in, Parcel *out) 97{ 98 int ret = 0; 99 100 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 101 102 int params = in->readInt32(); 103 int modeid = 0; 104 105 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_GET_DEFAULT_MODE, 106 (const void *)¶ms, (void *)&modeid); 107 108 out->writeInt32(modeid); 109 out->writeInt32(ret); //return operation status via binder. 110 } 111} 112 113static void qdcmGetColorBalanceRange(hwc_context_t *ctx __unused, 114 const Parcel *in __unused, Parcel *out __unused) 115{ 116} 117 118static void qdcmGetColorBalance(hwc_context_t *ctx, 119 const Parcel *in, Parcel *out) 120{ 121 int ret = 0; 122 123 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 124 125 int params = in->readInt32(); 126 int warmness = 0; 127 128 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_GET_CB, 129 (const void *)¶ms, (void *)&warmness); 130 131 out->writeInt32(warmness); 132 out->writeInt32(ret); //return operation status via binder. 133 } 134} 135 136static void qdcmSetColorBalance(hwc_context_t *ctx, 137 const Parcel *in, Parcel *out) 138{ 139 int ret = 0; 140 141 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 142 143 struct SET_CB_IN params = 144 { (disp_id_type)in->readInt32(), in->readInt32() }; 145 146 ALOGD_IF(QDCM_DEBUG, "%s dispID = %d, warmness = %d\n", 147 __FUNCTION__, params.id, params.warmness); 148 149 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_SET_CB, 150 (const void *)¶ms, NULL); 151 152 out->writeInt32(ret); //return operation status via binder. 153 } 154} 155 156static void qdcmSaveModeV2(hwc_context_t *ctx, const Parcel *in, Parcel *out) 157{ 158 int ret = 0; 159 160 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 161 162 struct SAVE_DISPLAY_MODE_V2_IN params = 163 { (disp_id_type)in->readInt32(), 164 in->readCString(), 165 (uint32_t)in->readInt32(), 166 in->readInt32() 167 }; 168 int value = 0; 169 170 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_SAVE_MODE_V2, 171 (const void *)¶ms, (void *)&value); 172 173 out->writeInt32(value); 174 out->writeInt32(ret); //return operation status via binder. 175 } 176} 177 178static void qdcmSetPaConfig(hwc_context_t *ctx, const Parcel *in, Parcel *out) 179{ 180 int ret = 0; 181 182 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 183 184 struct SET_PA_CONFIG_IN params; 185 186 params.id = (disp_id_type)in->readInt32(); 187 params.pa.ops = in->readInt32(); 188 params.pa.data.hue = in->readInt32(); 189 params.pa.data.saturation = in->readInt32(); 190 params.pa.data.value = in->readInt32(); 191 params.pa.data.contrast = in->readInt32(); 192 params.pa.data.sat_thresh = in->readInt32(); 193 194 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_SET_PA_CONFIG, 195 (const void *)¶ms, NULL); 196 197 out->writeInt32(ret); //return operation status via binder. 198 } 199} 200 201static void qdcmGetPaConfig(hwc_context_t *ctx, const Parcel *in, Parcel *out) 202{ 203 int ret = 0; 204 205 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 206 207 int params = in->readInt32(); 208 struct disp_pa_config value; 209 210 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_GET_PA_CONFIG, 211 (const void *)¶ms, (void *)&value); 212 213 out->writeInt32(value.ops); 214 out->writeInt32(value.data.hue); 215 out->writeInt32(value.data.saturation); 216 out->writeInt32(value.data.value); 217 out->writeInt32(value.data.contrast); 218 out->writeInt32(value.data.sat_thresh); 219 220 out->writeInt32(ret); //return operation status via binder. 221 } 222} 223 224static void qdcmGetPaRange(hwc_context_t *ctx, const Parcel *in, Parcel *out) 225{ 226 int ret = 0; 227 228 if (ctx->mQdcmInfo.mQdcmMode && in && out) { 229 230 int params = in->readInt32(); 231 struct disp_pa_range value; 232 233 ret = ctx->mQdcmInfo.mQdcmMode->requestRoute((int)CMD_GET_PA_RANGE, 234 (const void *)¶ms, (void *)&value); 235 236 out->writeInt32(value.max.hue); 237 out->writeInt32(value.max.saturation); 238 out->writeInt32(value.max.value); 239 out->writeInt32(value.max.contrast); 240 out->writeInt32(value.max.sat_thresh); 241 out->writeInt32(value.min.hue); 242 out->writeInt32(value.min.saturation); 243 out->writeInt32(value.min.value); 244 out->writeInt32(value.min.contrast); 245 out->writeInt32(value.min.sat_thresh); 246 247 out->writeInt32(ret); //return operation status via binder. 248 } 249} 250 251void qdcmCmdsHandler(hwc_context_t *ctx, const Parcel *in, Parcel *out) 252{ 253 int subcmd = in->readInt32(); 254 255 ALOGD_IF(QDCM_DEBUG, "%s enter subcmd = %d\n", __FUNCTION__, subcmd); 256 switch (subcmd) { 257 case CMD_SET_ACTIVE_MODE: 258 qdcmSetActiveMode(ctx, in, out); 259 break; 260 case CMD_SET_DEFAULT_MODE: 261 qdcmSetDefaultMode(ctx, in, out); 262 break; 263 case CMD_GET_DEFAULT_MODE: 264 qdcmGetDefaultMode(ctx, in, out); 265 break; 266 case CMD_GET_CB_RANGE: 267 qdcmGetColorBalanceRange(ctx, in, out); 268 break; 269 case CMD_GET_CB: 270 qdcmGetColorBalance(ctx, in, out); 271 break; 272 case CMD_SET_CB: 273 qdcmSetColorBalance(ctx, in, out); 274 break; 275 case CMD_SAVE_MODE_V2: 276 qdcmSaveModeV2(ctx, in, out); 277 break; 278 case CMD_SET_PA_CONFIG: 279 qdcmSetPaConfig(ctx, in, out); 280 break; 281 case CMD_GET_PA_CONFIG: 282 qdcmGetPaConfig(ctx, in, out); 283 break; 284 case CMD_GET_PA_RANGE: 285 qdcmGetPaRange(ctx, in, out); 286 break; 287 } 288} 289 290 291} //namespace qQdcm 292 293