codeworkx | f1be2fe | 2012-03-24 17:38:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** Copyright 2009 Samsung Electronics Co, Ltd. All Rights Reserved. |
| 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 | #ifndef FIMG_C210_H |
| 22 | #define FIMG_C210_H |
| 23 | |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | |
| 29 | #include <fcntl.h> |
| 30 | #include <unistd.h> |
| 31 | #include <errno.h> |
| 32 | #include <signal.h> |
| 33 | #include <sys/mman.h> |
| 34 | #include <sys/time.h> |
| 35 | #include <sys/ioctl.h> |
| 36 | #include <sys/poll.h> |
| 37 | #include <sys/stat.h> |
| 38 | |
| 39 | #include <linux/android_pmem.h> |
| 40 | #include <utils/threads.h> |
| 41 | #include <utils/StopWatch.h> |
| 42 | |
| 43 | #include "FimgApi.h" |
| 44 | //#include "FimgMem.h" |
| 45 | |
| 46 | #include "sec_g2d.h" |
| 47 | |
| 48 | //-----------------------------------------------------------------// |
| 49 | |
| 50 | namespace android |
| 51 | { |
| 52 | |
| 53 | //#define CHECK_FIMGC210_PERFORMANCE |
| 54 | //#define CHECK_FIMGC210_CRITICAL_PERFORMANCE |
| 55 | #define NUMBER_FIMG_LIST (1) // kcoolsw : because of pmem |
| 56 | //#define G2D_NONE_BLOCKING_MODE // Not supported yet. because of sysMMU Page fault |
| 57 | #define GET_RECT_SIZE(rect) ((rect->full_w) * (rect->h) * (rect->bytes_per_pixel)) |
| 58 | #define GET_REAL_SIZE(rect) ((rect->full_w) * (rect->h) * (rect->bytes_per_pixel)) |
| 59 | #define GET_START_ADDR(rect) (rect->virt_addr + ((rect->y * rect->full_w) * rect->bytes_per_pixel)) |
| 60 | |
| 61 | |
| 62 | //---------------------------------------------------------------------------// |
| 63 | // class FimgC210 : public FimgBase |
| 64 | //---------------------------------------------------------------------------// |
| 65 | class FimgC210 : public FimgApi |
| 66 | { |
| 67 | private : |
| 68 | int m_g2dFd; |
| 69 | |
| 70 | unsigned char * m_g2dVirtAddr; |
| 71 | unsigned int m_g2dSize; |
| 72 | unsigned char * m_g2dSrcVirtAddr; |
| 73 | unsigned int m_g2dSrcSize; |
| 74 | unsigned char * m_g2dDstVirtAddr; |
| 75 | unsigned int m_g2dDstSize; |
| 76 | struct pollfd m_g2dPoll; |
| 77 | |
| 78 | Mutex * m_lock; |
| 79 | |
| 80 | static Mutex m_instanceLock; |
| 81 | static int m_curFimgC210Index; |
| 82 | static int m_numOfInstance; |
| 83 | |
| 84 | static FimgApi * m_ptrFimgApiList[NUMBER_FIMG_LIST]; |
| 85 | |
| 86 | |
| 87 | protected : |
| 88 | FimgC210(); |
| 89 | virtual ~FimgC210(); |
| 90 | |
| 91 | public: |
| 92 | static FimgApi * CreateInstance(); |
| 93 | static void DestroyInstance(FimgApi * ptrFimgApi); |
| 94 | static void DestroyAllInstance(void); |
| 95 | |
| 96 | protected: |
| 97 | virtual bool t_Create(void); |
| 98 | virtual bool t_Destroy(void); |
| 99 | virtual bool t_Stretch(FimgRect * src, FimgRect * dst, FimgClip * clip, FimgFlag * flag); |
| 100 | virtual bool t_Sync(void); |
| 101 | virtual bool t_Lock(void); |
| 102 | virtual bool t_UnLock(void); |
| 103 | |
| 104 | private: |
| 105 | bool m_CreateG2D(void); |
| 106 | bool m_DestroyG2D(void); |
| 107 | bool SetClipRectl(FimgRect * dst, FimgClip * clip, FimgClip * clipTempMidRect); |
| 108 | |
| 109 | bool m_DoG2D(FimgRect * src, FimgRect * dst, FimgClip * clip, FimgFlag * flag); |
| 110 | |
| 111 | inline bool m_PollG2D(struct pollfd * events); |
| 112 | |
| 113 | inline bool m_CleanG2D (unsigned int addr, unsigned int size); |
| 114 | inline bool m_FlushG2D (unsigned int addr, unsigned int size); |
| 115 | |
| 116 | inline int m_ColorFormatFimgApi2FimgHw(int colorFormat); |
| 117 | inline int m_RotateValueFimgApi2FimgHw(int rotateValue); |
| 118 | |
| 119 | #ifdef CHECK_FIMGC210_PERFORMANCE |
| 120 | void m_PrintFimgC210Performance(FimgRect * src, |
| 121 | FimgRect * dst, |
| 122 | int stopWatchIndex, |
| 123 | const char * stopWatchName[], |
| 124 | nsecs_t stopWatchTime[]); |
| 125 | #endif // CHECK_FIMGC210_PERFORMANCE |
| 126 | }; |
| 127 | |
| 128 | //---------------------------------------------------------------------------// |
| 129 | // class FimgApiAutoFreeThread : public Thread |
| 130 | //---------------------------------------------------------------------------// |
| 131 | class FimgApiAutoFreeThread; |
| 132 | |
| 133 | static sp<FimgApiAutoFreeThread> fimgApiAutoFreeThread = 0; |
| 134 | |
| 135 | class FimgApiAutoFreeThread : public Thread |
| 136 | { |
| 137 | private: |
| 138 | bool mOneMoreSleep; |
| 139 | bool mDestroyed; |
| 140 | |
| 141 | public: |
| 142 | FimgApiAutoFreeThread(void): |
| 143 | //Thread(true), |
| 144 | Thread(false), |
| 145 | mOneMoreSleep(true), |
| 146 | mDestroyed(false) |
| 147 | { } |
| 148 | ~FimgApiAutoFreeThread(void) |
| 149 | { |
| 150 | if(mDestroyed == false) |
| 151 | { |
| 152 | FimgC210::DestroyAllInstance(); |
| 153 | mDestroyed = true; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | virtual void onFirstRef() |
| 158 | { |
| 159 | run("FimgApiAutoFreeThread", PRIORITY_BACKGROUND); |
| 160 | } |
| 161 | |
| 162 | virtual bool threadLoop() |
| 163 | { |
| 164 | //#define SLEEP_TIME (10000000) // 10 sec |
| 165 | #define SLEEP_TIME (3000000) // 3 sec |
| 166 | //#define SLEEP_TIME (1000000) // 1 sec |
| 167 | |
| 168 | if(mOneMoreSleep == true) |
| 169 | { |
| 170 | mOneMoreSleep = false; |
| 171 | usleep(SLEEP_TIME); |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | if(mDestroyed == false) |
| 178 | { |
| 179 | FimgC210::DestroyAllInstance(); |
| 180 | mDestroyed = true; |
| 181 | } |
| 182 | |
| 183 | fimgApiAutoFreeThread = 0; |
| 184 | |
| 185 | return false; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void SetOneMoreSleep(void) |
| 190 | { |
| 191 | mOneMoreSleep = true; |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | }; // namespace android |
| 196 | |
| 197 | #endif // FIMG_C210_H |