codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** Copyright 2010, Samsung Electronics Co. LTD |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | ** |
| 21 | ** @author Taikyung, Yu(taikyung.yu@samsung.com) |
| 22 | ** @date 2011-07-06 |
| 23 | */ |
| 24 | |
| 25 | #ifndef SECTVOUTSERVICE_H |
| 26 | #define SECTVOUTSERVICE_H |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <binder/Parcel.h> |
| 31 | #include <utils/KeyedVector.h> |
| 32 | |
| 33 | #include "ISecTVOut.h" |
| 34 | #include "SecHdmi.h" |
| 35 | #include "sec_format.h" |
| 36 | #include "sec_utils.h" |
| 37 | #include "MessageQueue.h" |
| 38 | |
| 39 | namespace android { |
| 40 | //#define CHECK_VIDEO_TIME |
| 41 | //#define CHECK_UI_TIME |
| 42 | |
| 43 | class SecTVOutService : public BBinder |
| 44 | { |
| 45 | public : |
| 46 | enum { |
| 47 | HDMI_MODE_NONE = 0, |
| 48 | HDMI_MODE_UI, |
| 49 | HDMI_MODE_VIDEO, |
| 50 | }; |
| 51 | |
| 52 | mutable Mutex mLock; |
| 53 | |
| 54 | class HDMIFlushThread : public Thread { |
| 55 | SecTVOutService *mTVOutService; |
| 56 | public: |
| 57 | HDMIFlushThread(SecTVOutService *service): |
| 58 | Thread(false), |
| 59 | mTVOutService(service) { } |
| 60 | virtual void onFirstRef() { |
| 61 | run("HDMIFlushThread", PRIORITY_URGENT_DISPLAY); |
| 62 | } |
| 63 | virtual bool threadLoop() { |
| 64 | mTVOutService->HdmiFlushThread(); |
| 65 | return false; |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | sp<HDMIFlushThread> mHdmiFlushThread; |
| 70 | int HdmiFlushThread(); |
| 71 | |
| 72 | mutable MessageQueue mHdmiEventQueue; |
| 73 | bool mExitHdmiFlushThread; |
| 74 | |
| 75 | SecTVOutService(); |
| 76 | static int instantiate (); |
| 77 | virtual status_t onTransact(uint32_t, const Parcel &, Parcel *, uint32_t); |
| 78 | virtual ~SecTVOutService (); |
| 79 | |
| 80 | virtual void setHdmiStatus(uint32_t status); |
| 81 | virtual void setHdmiMode(uint32_t mode); |
| 82 | virtual void setHdmiResolution(uint32_t resolution); |
| 83 | virtual void setHdmiHdcp(uint32_t enHdcp); |
| 84 | virtual void setHdmiRotate(uint32_t rotVal, uint32_t hwcLayer); |
| 85 | virtual void setHdmiHwcLayer(uint32_t hwcLayer); |
| 86 | virtual void blit2Hdmi(uint32_t w, uint32_t h, |
| 87 | uint32_t colorFormat, |
| 88 | uint32_t pPhyYAddr, uint32_t pPhyCbAddr, uint32_t pPhyCrAddr, |
| 89 | uint32_t dstX, uint32_t dstY, |
| 90 | uint32_t hdmiMode, uint32_t num_of_hwc_layer); |
| 91 | bool hdmiCableInserted(void); |
| 92 | void setLCDsize(void); |
| 93 | |
| 94 | private: |
| 95 | SecHdmi mSecHdmi; |
| 96 | bool mHdmiCableInserted; |
| 97 | int mUILayerMode; |
| 98 | uint32_t mLCD_width, mLCD_height; |
| 99 | uint32_t mHwcLayer; |
| 100 | }; |
| 101 | |
| 102 | class SecHdmiEventMsg : public MessageBase { |
| 103 | public: |
| 104 | enum { |
| 105 | HDMI_MODE_NONE = 0, |
| 106 | HDMI_MODE_UI, |
| 107 | HDMI_MODE_VIDEO, |
| 108 | }; |
| 109 | |
| 110 | mutable Mutex mBlitLock; |
| 111 | |
| 112 | SecHdmi *pSecHdmi; |
| 113 | uint32_t mSrcWidth, mSrcHeight; |
| 114 | uint32_t mSrcColorFormat; |
| 115 | uint32_t mSrcYAddr, mSrcCbAddr, mSrcCrAddr; |
| 116 | uint32_t mDstX, mDstY; |
| 117 | uint32_t mHdmiMode; |
| 118 | uint32_t mHdmiLayer, mHwcLayer; |
| 119 | |
| 120 | SecHdmiEventMsg(SecHdmi *SecHdmi, uint32_t srcWidth, uint32_t srcHeight, uint32_t srcColorFormat, |
| 121 | uint32_t srcYAddr, uint32_t srcCbAddr, uint32_t srcCrAddr, |
| 122 | uint32_t dstX, uint32_t dstY, uint32_t hdmiLayer, uint32_t hwcLayer, uint32_t hdmiMode) |
| 123 | : pSecHdmi(SecHdmi), mSrcWidth(srcWidth), mSrcHeight(srcHeight), mSrcColorFormat(srcColorFormat), |
| 124 | mSrcYAddr(srcYAddr), mSrcCbAddr(srcCbAddr), mSrcCrAddr(srcCrAddr), |
| 125 | mDstX(dstX), mDstY(dstY), mHdmiLayer(hdmiLayer), mHwcLayer(hwcLayer), mHdmiMode(hdmiMode) { |
| 126 | } |
| 127 | |
| 128 | virtual bool handler() { |
| 129 | Mutex::Autolock _l(mBlitLock); |
| 130 | bool ret = true; |
| 131 | #if defined(CHECK_UI_TIME) || defined(CHECK_VIDEO_TIME) |
| 132 | nsecs_t start, end; |
| 133 | #endif |
| 134 | |
| 135 | switch (mHdmiMode) { |
| 136 | case HDMI_MODE_UI: |
| 137 | #ifdef CHECK_UI_TIME |
| 138 | start = systemTime(); |
| 139 | #endif |
| 140 | if (pSecHdmi->flush(mSrcWidth, mSrcHeight, mSrcColorFormat, mSrcYAddr, mSrcCbAddr, mSrcCrAddr, |
| 141 | mDstX, mDstY, mHdmiLayer, mHwcLayer) == false) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame^] | 142 | ALOGE("%s::pSecHdmi->flush() fail on HDMI_MODE_UI", __func__); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 143 | ret = false; |
| 144 | } |
| 145 | #ifdef CHECK_UI_TIME |
| 146 | end = systemTime(); |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame^] | 147 | ALOGD("[UI] pSecHdmi->flush[end-start] = %ld ms", long(ns2ms(end)) - long(ns2ms(start))); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 148 | #endif |
| 149 | break; |
| 150 | case HDMI_MODE_VIDEO: |
| 151 | #ifdef CHECK_VIDEO_TIME |
| 152 | start = systemTime(); |
| 153 | #endif |
| 154 | if (pSecHdmi->flush(mSrcWidth, mSrcHeight, mSrcColorFormat, mSrcYAddr, mSrcCbAddr, mSrcCrAddr, |
| 155 | mDstX, mDstY, mHdmiLayer, mHwcLayer) == false) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame^] | 156 | ALOGE("%s::pSecHdmi->flush() fail on HDMI_MODE_VIDEO", __func__); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 157 | ret = false; |
| 158 | } |
| 159 | #ifdef CHECK_VIDEO_TIME |
| 160 | end = systemTime(); |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame^] | 161 | ALOGD("[VIDEO] pSecHdmi->flush[end-start] = %ld ms", long(ns2ms(end)) - long(ns2ms(start))); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 162 | #endif |
| 163 | break; |
| 164 | default: |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame^] | 165 | ALOGE("Undefined HDMI_MODE"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 166 | ret = false; |
| 167 | break; |
| 168 | } |
| 169 | return ret; |
| 170 | } |
| 171 | }; |
| 172 | |
| 173 | }; |
| 174 | #endif |