codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [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_EXYNOS4_H |
| 22 | #define FIMG_EXYNOS4_H |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | |
| 28 | #include <fcntl.h> |
| 29 | #include <unistd.h> |
| 30 | #include <errno.h> |
| 31 | #include <signal.h> |
| 32 | #include <sys/mman.h> |
| 33 | #include <sys/time.h> |
| 34 | #include <sys/ioctl.h> |
| 35 | #include <sys/poll.h> |
| 36 | #include <sys/stat.h> |
| 37 | |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 38 | #include <utils/threads.h> |
| 39 | #include <utils/StopWatch.h> |
| 40 | |
| 41 | #include "FimgApi.h" |
| 42 | |
| 43 | #include "sec_g2d_4x.h" |
| 44 | |
| 45 | namespace android |
| 46 | { |
| 47 | |
Daniel Hillenbrand | 09e7e82 | 2013-06-14 16:18:47 +0200 | [diff] [blame] | 48 | #define NUMBER_FIMG_LIST (1) |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 49 | #define GET_RECT_SIZE(rect) ((rect->full_w) * (rect->h) * (rect->bytes_per_pixel)) |
| 50 | #define GET_REAL_SIZE(rect) ((rect->full_w) * (rect->h) * (rect->bytes_per_pixel)) |
| 51 | #define GET_START_ADDR(rect) (rect->virt_addr + ((rect->y * rect->full_w) * rect->bytes_per_pixel)) |
| 52 | #define SLEEP_TIME (3000000) // 3 sec |
| 53 | |
| 54 | //---------------------------------------------------------------------------// |
| 55 | // class FimgV4x : public FimgBase |
| 56 | //---------------------------------------------------------------------------// |
| 57 | class FimgV4x : public FimgApi |
| 58 | { |
| 59 | private : |
| 60 | int m_g2dFd; |
| 61 | |
| 62 | unsigned char *m_g2dVirtAddr; |
| 63 | unsigned int m_g2dSize; |
| 64 | unsigned char *m_g2dSrcVirtAddr; |
| 65 | unsigned int m_g2dSrcSize; |
| 66 | unsigned char *m_g2dDstVirtAddr; |
| 67 | unsigned int m_g2dDstSize; |
| 68 | struct pollfd m_g2dPoll; |
| 69 | |
| 70 | Mutex *m_lock; |
| 71 | |
| 72 | static Mutex m_instanceLock; |
| 73 | static unsigned m_curFimgV4xIndex; |
| 74 | static int m_numOfInstance; |
| 75 | |
| 76 | static FimgApi *m_ptrFimgApiList[NUMBER_FIMG_LIST]; |
| 77 | |
| 78 | protected : |
| 79 | FimgV4x(); |
| 80 | virtual ~FimgV4x(); |
| 81 | |
| 82 | public: |
| 83 | static FimgApi *CreateInstance(); |
| 84 | static void DestroyInstance(FimgApi *ptrFimgApi); |
| 85 | static void DestroyAllInstance(void); |
| 86 | |
| 87 | protected: |
| 88 | virtual bool t_Create(void); |
| 89 | virtual bool t_Destroy(void); |
| 90 | virtual bool t_Stretch(struct fimg2d_blit *cmd); |
| 91 | virtual bool t_Sync(void); |
| 92 | virtual bool t_Lock(void); |
| 93 | virtual bool t_UnLock(void); |
| 94 | |
| 95 | private: |
| 96 | bool m_CreateG2D(void); |
| 97 | bool m_DestroyG2D(void); |
| 98 | |
| 99 | bool m_DoG2D(struct fimg2d_blit *cmd); |
| 100 | |
| 101 | inline bool m_PollG2D(struct pollfd *events); |
| 102 | |
| 103 | inline int m_ColorFormatFimgApi2FimgHw(int colorFormat); |
| 104 | }; |
| 105 | |
| 106 | class FimgApiAutoFreeThread; |
| 107 | |
| 108 | static sp<FimgApiAutoFreeThread> fimgApiAutoFreeThread = 0; |
| 109 | |
| 110 | class FimgApiAutoFreeThread : public Thread |
| 111 | { |
| 112 | private: |
| 113 | bool mOneMoreSleep; |
| 114 | bool mDestroyed; |
| 115 | |
| 116 | public: |
| 117 | FimgApiAutoFreeThread(void): |
| 118 | Thread(false), |
| 119 | mOneMoreSleep(true), |
| 120 | mDestroyed(false) |
| 121 | { } |
| 122 | ~FimgApiAutoFreeThread(void) |
| 123 | { |
| 124 | if (mDestroyed == false) |
| 125 | { |
| 126 | FimgV4x::DestroyAllInstance(); |
| 127 | mDestroyed = true; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | virtual void onFirstRef() |
| 132 | { |
| 133 | run("FimgApiAutoFreeThread", PRIORITY_BACKGROUND); |
| 134 | } |
| 135 | |
| 136 | virtual bool threadLoop() |
| 137 | { |
| 138 | |
| 139 | if (mOneMoreSleep == true) |
| 140 | { |
| 141 | mOneMoreSleep = false; |
| 142 | usleep(SLEEP_TIME); |
| 143 | |
| 144 | return true; |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | if (mDestroyed == false) |
| 149 | { |
| 150 | FimgV4x::DestroyAllInstance(); |
| 151 | mDestroyed = true; |
| 152 | } |
| 153 | |
| 154 | fimgApiAutoFreeThread = 0; |
| 155 | |
| 156 | return false; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | void SetOneMoreSleep(void) |
| 161 | { |
| 162 | mOneMoreSleep = true; |
| 163 | } |
| 164 | }; |
| 165 | |
| 166 | }; // namespace android |
| 167 | |
| 168 | #endif // FIMG_EXYNOS4_H |