12e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed/*
20de84c911980050d32a6bb35836ce099acfc496dArun Kumar K.R* Copyright (c) 2013-2014 The Linux Foundation. All rights reserved.
32e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*
42e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* Redistribution and use in source and binary forms, with or without
52e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* modification, are permitted provided that the following conditions are
62e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* met:
72e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*    * Redistributions of source code must retain the above copyright
82e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      notice, this list of conditions and the following disclaimer.
92e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*    * Redistributions in binary form must reproduce the above
102e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      copyright notice, this list of conditions and the following
112e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      disclaimer in the documentation and/or other materials provided
122e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      with the distribution.
132e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*    * Neither the name of The Linux Foundation. nor the names of its
142e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      contributors may be used to endorse or promote products derived
152e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*      from this software without specific prior written permission.
162e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*
172e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
182e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
192e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
202e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
212e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
222e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
232e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
242e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
252e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
262e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
272e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed*/
292e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
302e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed#include <display_config.h>
312e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed#include <QServiceUtils.h>
322e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
332e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmedusing namespace android;
342e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmedusing namespace qService;
352e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
362e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmednamespace qdutils {
372e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
382e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmedint isExternalConnected(void) {
392e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    int ret;
400de84c911980050d32a6bb35836ce099acfc496dArun Kumar K.R    status_t err = (status_t) FAILED_TRANSACTION;
412e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    sp<IQService> binder = getBinder();
422e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    Parcel inParcel, outParcel;
432e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(binder != NULL) {
442e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        err = binder->dispatch(IQService::CHECK_EXTERNAL_STATUS,
452e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed                &inParcel , &outParcel);
462e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    }
472e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(err) {
482e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        ALOGE("%s: Failed to get external status err=%d", __FUNCTION__, err);
492e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        ret = err;
502e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    } else {
512e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        ret = outParcel.readInt32();
522e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    }
532e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    return ret;
542e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed}
552e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
562e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmedint getDisplayAttributes(int dpy, DisplayAttributes_t& dpyattr) {
570de84c911980050d32a6bb35836ce099acfc496dArun Kumar K.R    status_t err = (status_t) FAILED_TRANSACTION;
582e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    sp<IQService> binder = getBinder();
592e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    Parcel inParcel, outParcel;
602e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeInt32(dpy);
612e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(binder != NULL) {
622e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        err = binder->dispatch(IQService::GET_DISPLAY_ATTRIBUTES,
632e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed                &inParcel, &outParcel);
642e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    }
652e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(!err) {
662e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.vsync_period = outParcel.readInt32();
672e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.xres = outParcel.readInt32();
682e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.yres = outParcel.readInt32();
692e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.xdpi = outParcel.readFloat();
702e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.ydpi = outParcel.readFloat();
712e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        dpyattr.panel_type = (char) outParcel.readInt32();
722e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    } else {
732e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        ALOGE("%s: Failed to get display attributes err=%d", __FUNCTION__, err);
742e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    }
752e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    return err;
762e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed}
772e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed
782e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmedint setHSIC(int dpy, const HSICData_t& hsic_data) {
790de84c911980050d32a6bb35836ce099acfc496dArun Kumar K.R    status_t err = (status_t) FAILED_TRANSACTION;
802e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    sp<IQService> binder = getBinder();
812e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    Parcel inParcel, outParcel;
822e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeInt32(dpy);
832e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeInt32(hsic_data.hue);
842e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeFloat(hsic_data.saturation);
852e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeInt32(hsic_data.intensity);
862e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    inParcel.writeFloat(hsic_data.contrast);
872e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(binder != NULL) {
882e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        err = binder->dispatch(IQService::SET_HSIC_DATA, &inParcel, &outParcel);
892e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    }
902e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    if(err)
912e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed        ALOGE("%s: Failed to get external status err=%d", __FUNCTION__, err);
922e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed    return err;
932e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed}
94ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R
95ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.Rint getDisplayVisibleRegion(int dpy, hwc_rect_t &rect) {
960de84c911980050d32a6bb35836ce099acfc496dArun Kumar K.R    status_t err = (status_t) FAILED_TRANSACTION;
97ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    sp<IQService> binder = getBinder();
98ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    Parcel inParcel, outParcel;
99ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    inParcel.writeInt32(dpy);
100ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    if(binder != NULL) {
101ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        err = binder->dispatch(IQService::GET_DISPLAY_VISIBLE_REGION,
102ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R                &inParcel, &outParcel);
103ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    }
104ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    if(!err) {
105ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        rect.left = outParcel.readInt32();
106ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        rect.top = outParcel.readInt32();
107ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        rect.right = outParcel.readInt32();
108ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        rect.bottom = outParcel.readInt32();
109ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    } else {
110ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R        ALOGE("%s: Failed to getVisibleRegion for dpy =%d: err = %d",
111ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R              __FUNCTION__, dpy, err);
112ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    }
113ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R    return err;
114ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R}
115ac5b9f4e6b7dc80e0f91c1581f0bcb4464a48ef4Arun Kumar K.R
1162e11c4c4562da807b35fc0c127a7449edd8aac17Naseer Ahmed}; //namespace
117