Home | History | Annotate | Download | only in android
      1 /*
      2  * Copyright (c) 2011 Intel Corporation. All Rights Reserved.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the
      6  * "Software"), to deal in the Software without restriction, including
      7  * without limitation the rights to use, copy, modify, merge, publish,
      8  * distribute, sub license, and/or sell copies of the Software, and to
      9  * permit persons to whom the Software is furnished to do so, subject to
     10  * the following conditions:
     11  *
     12  * The above copyright notice and this permission notice (including the
     13  * next paragraph) shall be included in all copies or substantial portions
     14  * of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
     20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  *
     24  * Authors:
     25  *    Zhaohan Ren  <zhaohan.ren (at) intel.com>
     26  *    Jiang Fei  <jiang.fei (at) intel.com>
     27  *    Binglin Chen <binglin.chen (at) intel.com>
     28  *
     29  */
     30 
     31 #include <binder/IPCThreadState.h>
     32 #include <binder/ProcessState.h>
     33 #include <binder/IServiceManager.h>
     34 #include <gui/Surface.h>
     35 #include <gui/SurfaceComposerClient.h>
     36 #include <gui/ISurfaceComposer.h>
     37 #include <binder/MemoryHeapBase.h>
     38 #include "psb_android_glue.h"
     39 #include "psb_output_android.h"
     40 #include <cutils/log.h>
     41 #include <ui/Rect.h>
     42 #include <system/window.h>
     43 #include <system/graphics.h>
     44 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
     45 #include "psb_mds.h"
     46 #endif
     47 #if defined (PSBVIDEO_MRFL_VPP_SETTING) && !defined (TARGET_HAS_MULTIPLE_DISPLAY)
     48 #include <VPPSetting.h>
     49 #endif
     50 
     51 #ifdef  LOG_TAG
     52 #undef  LOG_TAG
     53 #endif
     54 
     55 #define LOG_TAG "pvr_drv_video"
     56 
     57 using namespace android;
     58 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
     59 using namespace android::intel;
     60 #endif
     61 
     62 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
     63 
     64 void init_mds_listener(void* output) {
     65     psb_android_output_p aoutput = (psb_android_output_p)output;
     66     if (aoutput == NULL) {
     67         ALOGE("Invalid input parameter");
     68         return;
     69     }
     70     if (aoutput->mds == NULL)
     71         aoutput->mds = new psbMultiDisplayListener();
     72 }
     73 
     74 void deinit_mds_listener(void* output) {
     75     psb_android_output_p aoutput = (psb_android_output_p)output;
     76     if (aoutput == NULL) {
     77         ALOGE("Invalid input parameter");
     78         return;
     79     }
     80     if (aoutput->mds != NULL) {
     81         delete (psbMultiDisplayListener*)(aoutput->mds);
     82         aoutput->mds = NULL;
     83     }
     84 }
     85 
     86 int psb_android_get_mds_mode(void* output) {
     87     if (output == NULL)
     88         return MDS_INIT_VALUE;
     89     psb_android_output_p aoutput = (psb_android_output_p)output;
     90     if (aoutput->mds == NULL)
     91         init_mds_listener(aoutput);
     92     psbMultiDisplayListener* mds =
     93         static_cast<psbMultiDisplayListener*>(aoutput->mds);
     94     if (mds == NULL)
     95         return MDS_INIT_VALUE;
     96     return mds->getMode();
     97 }
     98 
     99 int psb_android_get_mds_decoder_output_resolution(void* output,
    100         int* width, int* height,
    101         int* offX, int* offY,
    102         int* bufW, int* bufH) {
    103     if (output == NULL ||
    104             width == NULL || height == NULL ||
    105             offX  == NULL || offY == NULL ||
    106             bufW  == NULL || bufH == NULL)
    107         return 0;
    108     psb_android_output_p aoutput = (psb_android_output_p)output;
    109     if (aoutput->mds == NULL)
    110         init_mds_listener(aoutput);
    111     psbMultiDisplayListener* mds =
    112         static_cast<psbMultiDisplayListener*>(aoutput->mds);
    113     if (mds == NULL)
    114         return 0;
    115     bool ret = mds->getDecoderOutputResolution(width, height, offX, offY, bufW, bufH);
    116     return (ret ? 1 : 0);
    117 }
    118 
    119 int psb_android_get_mds_vpp_state(void* output) {
    120     bool ret = false;
    121     if (output == NULL) {
    122         sp<IServiceManager> sm = defaultServiceManager();
    123         if (sm == NULL)
    124             return 0;
    125         sp<IMDService> imds = interface_cast<IMDService>(
    126                 sm->getService(String16(INTEL_MDS_SERVICE_NAME)));
    127         if (imds == NULL)
    128             return 0;
    129         sp<IMultiDisplayInfoProvider> mds = imds->getInfoProvider();
    130         if (mds != NULL) {
    131             ret = mds->getVppState();
    132         }
    133         mds = NULL;
    134         return (ret ? 1 : 0);
    135     }
    136     psb_android_output_p aoutput = (psb_android_output_p)output;
    137     if (aoutput->mds == NULL)
    138         init_mds_listener(aoutput);
    139     psbMultiDisplayListener* mds =
    140         static_cast<psbMultiDisplayListener*>(aoutput->mds);
    141     ret = mds->getVppState();
    142     if (mds == NULL)
    143         return 0;
    144     return (ret ? 1 : 0);
    145 }
    146 
    147 #else //TARGET_HAS_MULTIPLE_DISPLAY
    148 
    149 #ifdef PSBVIDEO_MRFL_VPP
    150 
    151 int psb_android_get_vpp_state() {
    152 #ifdef PSBVIDEO_MRFL_VPP_SETTING
    153     bool ret = VPPSetting::isVppOn();
    154     return (ret ? 1 : 0);
    155 #else
    156     return 0;
    157 #endif
    158 }
    159 
    160 #endif
    161 #endif
    162 
    163 unsigned int update_forced;
    164 
    165 int psb_android_surfaceflinger_rotate(void* native_window, int *rotation)
    166 {
    167     sp<ANativeWindow> mNativeWindow = static_cast<ANativeWindow*>(native_window);
    168     int err, transform_hint;
    169 
    170     if (mNativeWindow.get()) {
    171         err = mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_TRANSFORM_HINT, &transform_hint);
    172         if (err != 0) {
    173             ALOGE("%s: NATIVE_WINDOW_TRANSFORM_HINT query failed", __func__);
    174             return -1;
    175         }
    176         switch (transform_hint) {
    177         case HAL_TRANSFORM_ROT_90:
    178             *rotation = 1;
    179             break;
    180         case HAL_TRANSFORM_ROT_180:
    181             *rotation = 2;
    182             break;
    183         case HAL_TRANSFORM_ROT_270:
    184             *rotation = 3;
    185             break;
    186         default:
    187             *rotation = 0;
    188         }
    189     }
    190     return 0;
    191 }
    192