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