libhwjpeg: resolve compilation errors
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos.git] / libfimg5x / FimgExynos5.h
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_EXYNOS5_H
22 #define FIMG_EXYNOS5_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
38 #include <utils/threads.h>
39 #include <utils/StopWatch.h>
40
41 #include "FimgApi.h"
42
43 #include "sec_g2d_5x.h"
44
45 namespace android
46 {
47
48 #define NUMBER_FIMG_LIST (1)
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 (100000) // 100 msec
53
54 int compare_size[][4] = { {160, 97, 240, 146} };
55
56 //---------------------------------------------------------------------------//
57 // class FimgV4x : public FimgBase
58 //---------------------------------------------------------------------------//
59 class FimgV4x : public FimgApi
60 {
61 private :
62 int m_g2dFd;
63
64 unsigned char *m_g2dVirtAddr;
65 unsigned int m_g2dSize;
66 unsigned char *m_g2dSrcVirtAddr;
67 unsigned int m_g2dSrcSize;
68 unsigned char *m_g2dDstVirtAddr;
69 unsigned int m_g2dDstSize;
70 struct pollfd m_g2dPoll;
71
72 Mutex m_lock;
73
74 static unsigned m_curFimgV4xIndex;
75 static int m_numOfInstance;
76
77 static FimgApi *m_ptrFimgApiList[NUMBER_FIMG_LIST];
78
79 protected :
80 FimgV4x();
81 virtual ~FimgV4x();
82
83 public:
84 static FimgApi *CreateInstance();
85 static void DestroyInstance(FimgApi *ptrFimgApi);
86 static void DestroyAllInstance(void);
87
88 protected:
89 virtual bool t_Create(void);
90 virtual bool t_Destroy(void);
91 virtual bool t_Stretch(struct fimg2d_blit *cmd);
92 #ifdef FIMG2D_USE_M2M1SHOT2
93 virtual bool t_Stretch_v5(struct m2m1shot2 *cmd);
94 #endif
95 virtual bool t_Sync(void);
96 virtual bool t_Lock(void);
97 virtual bool t_UnLock(void);
98
99 private:
100 bool m_CreateG2D(void);
101 bool m_DestroyG2D(void);
102
103 bool m_DoG2D(struct fimg2d_blit *cmd);
104 #ifdef FIMG2D_USE_M2M1SHOT2
105 bool m_DoG2D_v5(struct m2m1shot2 *cmd);
106 #endif
107 inline bool m_PollG2D(struct pollfd *events);
108
109 inline int m_ColorFormatFimgApi2FimgHw(int colorFormat);
110 };
111
112 class FimgApiAutoFreeThread;
113
114 static sp<FimgApiAutoFreeThread> fimgApiAutoFreeThread = 0;
115
116 class FimgApiAutoFreeThread : public Thread
117 {
118 private:
119 bool mOneMoreSleep;
120 bool mDestroyed;
121
122 public:
123 FimgApiAutoFreeThread(void):
124 Thread(false),
125 mOneMoreSleep(true),
126 mDestroyed(false)
127 { }
128 ~FimgApiAutoFreeThread(void)
129 {
130 if (mDestroyed == false) {
131 FimgV4x::DestroyAllInstance();
132 mDestroyed = true;
133 }
134 }
135
136 virtual void onFirstRef()
137 {
138 run("FimgApiAutoFreeThread", PRIORITY_BACKGROUND);
139 }
140
141 virtual bool threadLoop()
142 {
143
144 if (mOneMoreSleep == true) {
145 mOneMoreSleep = false;
146 usleep(SLEEP_TIME);
147
148 return true;
149 }
150 else {
151 if (mDestroyed == false) {
152 FimgV4x::DestroyAllInstance();
153 mDestroyed = true;
154 }
155
156 fimgApiAutoFreeThread = 0;
157
158 return false;
159 }
160 }
161
162 void SetOneMoreSleep(void)
163 {
164 mOneMoreSleep = true;
165 }
166 };
167
168 }; // namespace android
169
170 #endif // FIMG_EXYNOS5_H