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@intel.com>
26  *    Jiang Fei  <jiang.fei@intel.com>
27  *    Binglin Chen <binglin.chen@intel.com>
28  *
29  */
30 
31 #include <binder/IPCThreadState.h>
32 #include <binder/ProcessState.h>
33 #include <binder/IServiceManager.h>
34 #include <binder/MemoryHeapBase.h>
35 #include "psb_android_glue.h"
36 #include "psb_output_android.h"
37 #include <cutils/log.h>
38 #include <system/window.h>
39 #include <system/graphics.h>
40 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
41 #include "psb_mds.h"
42 #endif
43 
44 #ifdef  LOG_TAG
45 #undef  LOG_TAG
46 #endif
47 
48 #define LOG_TAG "pvr_drv_video"
49 
50 using namespace android;
51 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
52 using namespace android::intel;
53 #endif
54 
55 #ifdef TARGET_HAS_MULTIPLE_DISPLAY
56 
init_mds_listener(void * output)57 void init_mds_listener(void* output) {
58     psb_android_output_p aoutput = (psb_android_output_p)output;
59     if (aoutput == NULL) {
60         ALOGE("Invalid input parameter");
61         return;
62     }
63     if (aoutput->mds == NULL)
64         aoutput->mds = new psbMultiDisplayListener();
65 }
66 
deinit_mds_listener(void * output)67 void deinit_mds_listener(void* output) {
68     psb_android_output_p aoutput = (psb_android_output_p)output;
69     if (aoutput == NULL) {
70         ALOGE("Invalid input parameter");
71         return;
72     }
73     if (aoutput->mds != NULL) {
74         delete (psbMultiDisplayListener*)(aoutput->mds);
75         aoutput->mds = NULL;
76     }
77 }
78 
psb_android_get_mds_mode(void * output)79 int psb_android_get_mds_mode(void* output) {
80     if (output == NULL)
81         return MDS_INIT_VALUE;
82     psb_android_output_p aoutput = (psb_android_output_p)output;
83     if (aoutput->mds == NULL)
84         init_mds_listener(aoutput);
85     psbMultiDisplayListener* mds =
86         static_cast<psbMultiDisplayListener*>(aoutput->mds);
87     if (mds == NULL)
88         return MDS_INIT_VALUE;
89     return mds->getMode();
90 }
91 
psb_android_get_mds_decoder_output_resolution(void * output,int * width,int * height,int * offX,int * offY,int * bufW,int * bufH)92 int psb_android_get_mds_decoder_output_resolution(void* output,
93         int* width, int* height,
94         int* offX, int* offY,
95         int* bufW, int* bufH) {
96     if (output == NULL ||
97             width == NULL || height == NULL ||
98             offX  == NULL || offY == NULL ||
99             bufW  == NULL || bufH == NULL)
100         return 0;
101     psb_android_output_p aoutput = (psb_android_output_p)output;
102     if (aoutput->mds == NULL)
103         init_mds_listener(aoutput);
104     psbMultiDisplayListener* mds =
105         static_cast<psbMultiDisplayListener*>(aoutput->mds);
106     if (mds == NULL)
107         return 0;
108     bool ret = mds->getDecoderOutputResolution(width, height, offX, offY, bufW, bufH);
109     return (ret ? 1 : 0);
110 }
111 
psb_android_get_mds_vpp_state(void * output)112 int psb_android_get_mds_vpp_state(void* output) {
113     bool ret = false;
114     if (output == NULL) {
115         sp<IServiceManager> sm = defaultServiceManager();
116         if (sm == NULL)
117             return 0;
118         sp<IMDService> imds = interface_cast<IMDService>(
119                 sm->getService(String16(INTEL_MDS_SERVICE_NAME)));
120         if (imds == NULL)
121             return 0;
122         sp<IMultiDisplayInfoProvider> mds = imds->getInfoProvider();
123         if (mds != NULL) {
124             ret = mds->getVppState();
125         }
126         mds = NULL;
127         return (ret ? 1 : 0);
128     }
129     psb_android_output_p aoutput = (psb_android_output_p)output;
130     if (aoutput->mds == NULL)
131         init_mds_listener(aoutput);
132     psbMultiDisplayListener* mds =
133         static_cast<psbMultiDisplayListener*>(aoutput->mds);
134     ret = mds->getVppState();
135     if (mds == NULL)
136         return 0;
137     return (ret ? 1 : 0);
138 }
139 
140 #else //TARGET_HAS_MULTIPLE_DISPLAY
141 
142 #ifdef PSBVIDEO_MRFL_VPP
143 /* VPP is always enabled. It disables decoder rotate.
144  * TODO: remove the dependency the on libVPP. Get it form ISB configure
145  */
psb_android_get_vpp_state()146 int psb_android_get_vpp_state() {
147     return 1;
148 }
149 
150 #endif
151 #endif
152 
153 unsigned int update_forced;
154 
psb_android_surfaceflinger_rotate(void * native_window,int * rotation)155 int psb_android_surfaceflinger_rotate(void* native_window, int *rotation)
156 {
157     sp<ANativeWindow> mNativeWindow = static_cast<ANativeWindow*>(native_window);
158     int err, transform_hint;
159 
160     if (mNativeWindow.get()) {
161         err = mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_TRANSFORM_HINT, &transform_hint);
162         if (err != 0) {
163             ALOGE("%s: NATIVE_WINDOW_TRANSFORM_HINT query failed", __func__);
164             return -1;
165         }
166         switch (transform_hint) {
167         case HAL_TRANSFORM_ROT_90:
168             *rotation = 1;
169             break;
170         case HAL_TRANSFORM_ROT_180:
171             *rotation = 2;
172             break;
173         case HAL_TRANSFORM_ROT_270:
174             *rotation = 3;
175             break;
176         default:
177             *rotation = 0;
178         }
179     }
180     return 0;
181 }
182