8cca61c8e000fcb965f16c60f0ddde1cc9d3e61f
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos.git] / libfimg4x / FimgApi.cpp
1 /*
2 **
3 ** Copyright 2009 Samsung Electronics Co, Ltd.
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 **
17 **
18 */
19
20 #define LOG_NDEBUG 0
21 #define LOG_TAG "SKIA"
22 #include <utils/Log.h>
23
24 #include "FimgApi.h"
25
26 struct blit_op_table optbl[] = {
27 { (int)BLIT_OP_SOLID_FILL, "FILL" },
28 { (int)BLIT_OP_CLR, "CLR" },
29 { (int)BLIT_OP_SRC, "SRC" },
30 { (int)BLIT_OP_DST, "DST" },
31 { (int)BLIT_OP_SRC_OVER, "SRC_OVER" },
32 { (int)BLIT_OP_DST_OVER, "DST_OVER" },
33 { (int)BLIT_OP_SRC_IN, "SRC_IN" },
34 { (int)BLIT_OP_DST_IN, "DST_IN" },
35 { (int)BLIT_OP_SRC_OUT, "SRC_OUT" },
36 { (int)BLIT_OP_DST_OUT, "DST_OUT" },
37 { (int)BLIT_OP_SRC_ATOP, "SRC_ATOP" },
38 { (int)BLIT_OP_DST_ATOP, "DST_ATOP" },
39 { (int)BLIT_OP_XOR, "XOR" },
40 { (int)BLIT_OP_ADD, "ADD" },
41 { (int)BLIT_OP_MULTIPLY, "MULTIPLY" },
42 { (int)BLIT_OP_SCREEN, "SCREEN" },
43 { (int)BLIT_OP_DARKEN, "DARKEN" },
44 { (int)BLIT_OP_LIGHTEN, "LIGHTEN" },
45 { (int)BLIT_OP_DISJ_SRC_OVER, "DISJ_SRC_OVER" },
46 { (int)BLIT_OP_DISJ_DST_OVER, "DISJ_DST_OVER" },
47 { (int)BLIT_OP_DISJ_SRC_IN, "DISJ_SRC_IN" },
48 { (int)BLIT_OP_DISJ_DST_IN, "DISJ_DST_IN" },
49 { (int)BLIT_OP_DISJ_SRC_OUT, "DISJ_SRC_OUT" },
50 { (int)BLIT_OP_DISJ_DST_OUT, "DISJ_DST_OUT" },
51 { (int)BLIT_OP_DISJ_SRC_ATOP, "DISJ_SRC_ATOP" },
52 { (int)BLIT_OP_DISJ_DST_ATOP, "DISJ_DST_ATOP" },
53 { (int)BLIT_OP_DISJ_XOR, "DISJ_XOR" },
54 { (int)BLIT_OP_CONJ_SRC_OVER, "CONJ_SRC_OVER" },
55 { (int)BLIT_OP_CONJ_DST_OVER, "CONJ_DST_OVER" },
56 { (int)BLIT_OP_CONJ_SRC_IN, "CONJ_SRC_IN" },
57 { (int)BLIT_OP_CONJ_DST_IN, "CONJ_DST_IN" },
58 { (int)BLIT_OP_CONJ_SRC_OUT, "CONJ_SRC_OUT" },
59 { (int)BLIT_OP_CONJ_DST_OUT, "CONJ_DST_OUT" },
60 { (int)BLIT_OP_CONJ_SRC_ATOP, "CONJ_SRC_ATOP" },
61 { (int)BLIT_OP_CONJ_DST_ATOP, "CONJ_DST_ATOP" },
62 { (int)BLIT_OP_CONJ_XOR, "CONJ_XOR" },
63 { (int)BLIT_OP_USER_COEFF, "USER_COEFF" },
64 { (int)BLIT_OP_END, "" },
65 };
66
67 #ifndef REAL_DEBUG
68 void VOID_FUNC(const char *format, ...)
69 {}
70 #endif
71
72 FimgApi::FimgApi()
73 {
74 m_flagCreate = false;
75 }
76
77 FimgApi::~FimgApi()
78 {
79 if (m_flagCreate == true)
80 PRINT("%s::this is not Destroyed fail\n", __func__);
81 }
82
83 bool FimgApi::Create(void)
84 {
85 bool ret = false;
86
87 if (t_Lock() == false) {
88 PRINT("%s::t_Lock() fail\n", __func__);
89 goto CREATE_DONE;
90 }
91
92 if (m_flagCreate == true) {
93 PRINT("%s::Already Created fail\n", __func__);
94 goto CREATE_DONE;
95 }
96
97 if (t_Create() == false) {
98 PRINT("%s::t_Create() fail\n", __func__);
99 goto CREATE_DONE;
100 }
101
102 m_flagCreate = true;
103
104 ret = true;
105
106 CREATE_DONE :
107
108 t_UnLock();
109
110 return ret;
111 }
112
113 bool FimgApi::Destroy(void)
114 {
115 bool ret = false;
116
117 if (t_Lock() == false) {
118 PRINT("%s::t_Lock() fail\n", __func__);
119 goto DESTROY_DONE;
120 }
121
122 if (m_flagCreate == false) {
123 PRINT("%s::Already Destroyed fail\n", __func__);
124 goto DESTROY_DONE;
125 }
126
127 if (t_Destroy() == false) {
128 PRINT("%s::t_Destroy() fail\n", __func__);
129 goto DESTROY_DONE;
130 }
131
132 m_flagCreate = false;
133
134 ret = true;
135
136 DESTROY_DONE :
137
138 t_UnLock();
139
140 return ret;
141 }
142
143 bool FimgApi::Stretch(struct fimg2d_blit *cmd)
144 {
145 bool ret = false;
146
147 if (t_Lock() == false) {
148 PRINT("%s::t_Lock() fail\n", __func__);
149 goto STRETCH_DONE;
150 }
151
152 if (m_flagCreate == false) {
153 PRINT("%s::This is not Created fail\n", __func__);
154 goto STRETCH_DONE;
155 }
156
157 if (t_Stretch(cmd) == false) {
158 goto STRETCH_DONE;
159 }
160
161 ret = true;
162
163 STRETCH_DONE :
164
165 t_UnLock();
166
167 return ret;
168 }
169
170 bool FimgApi::Sync(void)
171 {
172 bool ret = false;
173
174 if (m_flagCreate == false) {
175 PRINT("%s::This is not Created fail\n", __func__);
176 goto SYNC_DONE;
177 }
178
179 if (t_Sync() == false)
180 goto SYNC_DONE;
181
182 ret = true;
183
184 SYNC_DONE :
185
186 return ret;
187 }
188
189 bool FimgApi::t_Create(void)
190 {
191 PRINT("%s::This is empty virtual function fail\n", __func__);
192 return false;
193 }
194
195 bool FimgApi::t_Destroy(void)
196 {
197 PRINT("%s::This is empty virtual function fail\n", __func__);
198 return false;
199 }
200
201 bool FimgApi::t_Stretch(struct fimg2d_blit *cmd)
202 {
203 PRINT("%s::This is empty virtual function fail\n", __func__);
204 return false;
205 }
206
207 bool FimgApi::t_Sync(void)
208 {
209 PRINT("%s::This is empty virtual function fail\n", __func__);
210 return false;
211 }
212
213 bool FimgApi::t_Lock(void)
214 {
215 PRINT("%s::This is empty virtual function fail\n", __func__);
216 return false;
217 }
218
219 bool FimgApi::t_UnLock(void)
220 {
221 PRINT("%s::This is empty virtual function fail\n", __func__);
222 return false;
223 }
224
225 //---------------------------------------------------------------------------//
226 // extern function
227 //---------------------------------------------------------------------------//
228 extern "C" int stretchFimgApi(struct fimg2d_blit *cmd)
229 {
230 FimgApi * fimgApi = createFimgApi();
231
232 if (fimgApi == NULL) {
233 PRINT("%s::createFimgApi() fail\n", __func__);
234 return -1;
235 }
236
237 if (fimgApi->Stretch(cmd) == false) {
238 if (fimgApi != NULL)
239 destroyFimgApi(fimgApi);
240
241 return -1;
242 }
243
244 if (fimgApi != NULL)
245 destroyFimgApi(fimgApi);
246
247 return 0;
248 }
249
250 extern "C" int SyncFimgApi(void)
251 {
252 FimgApi * fimgApi = createFimgApi();
253 if (fimgApi == NULL) {
254 PRINT("%s::createFimgApi() fail\n", __func__);
255 return -1;
256 }
257
258 if (fimgApi->Sync() == false) {
259 if (fimgApi != NULL)
260 destroyFimgApi(fimgApi);
261
262 return -1;
263 }
264
265 if (fimgApi != NULL)
266 destroyFimgApi(fimgApi);
267
268 return 0;
269 }
270
271 void printDataBlit(char *title, struct fimg2d_blit *cmd)
272 {
273 SLOGI("%s\n", title);
274
275 SLOGI(" sequence_no. = %u\n", cmd->seq_no);
276 SLOGI(" blit_op = %d(%s)\n", cmd->op, optbl[cmd->op].str);
277 SLOGI(" fill_color = %X\n", cmd->param.solid_color);
278 SLOGI(" global_alpha = %u\n", (unsigned int)cmd->param.g_alpha);
279 SLOGI(" PREMULT = %s\n", cmd->param.premult == PREMULTIPLIED ? "PREMULTIPLIED" : "NON-PREMULTIPLIED");
280 SLOGI(" do_dither = %s\n", cmd->param.dither == true ? "dither" : "no-dither");
281
282 printDataBlitRotate(cmd->param.rotate);
283
284 printDataBlitScale(&cmd->param.scaling);
285
286 printDataBlitImage("SRC", cmd->src);
287 printDataBlitImage("DST", cmd->dst);
288 printDataBlitImage("MSK", cmd->msk);
289
290 printDataBlitRect("SRC", &cmd->src->rect);
291 printDataBlitRect("DST", &cmd->dst->rect);
292 printDataBlitRect("MSK", &cmd->msk->rect);
293 }
294
295 void printDataBlitImage(char *title, struct fimg2d_image *image)
296 {
297 if (NULL != image) {
298 SLOGI(" Image_%s\n", title);
299 SLOGI(" addr = %X\n", image->addr.start);
300 SLOGI(" format = %d\n", image->fmt);
301 } else
302 SLOGI(" Image_%s : NULL\n", title);
303 }
304
305 void printDataBlitRect(char *title, struct fimg2d_rect *rect)
306 {
307 if (NULL != rect) {
308 SLOGI(" RECT_%s\n", title);
309 SLOGI(" (x1, y1) = (%d, %d)\n", rect->x1, rect->y1);
310 SLOGI(" (x2, y2) = (%d, %d)\n", rect->x2, rect->y2);
311 SLOGI(" (width, height) = (%d, %d)\n", rect->x2 - rect->x1, rect->y2 - rect->y1);
312 } else
313 SLOGI(" RECT_%s : NULL\n", title);
314 }
315
316 void printDataBlitRotate(int rotate)
317 {
318 SLOGI(" ROTATE : %d\n", rotate);
319 }
320
321 void printDataBlitScale(struct fimg2d_scale *scaling)
322 {
323 SLOGI(" SCALING\n");
324 SLOGI(" scale_mode : %s\n", scaling->mode == 0 ?
325 "NO_SCALING" :
326 (scaling->mode == 1 ? "SCALING_NEAREST" : "SCALING_BILINEAR"));
327 SLOGI(" src : (src_w, src_h) = (%d, %d)\n", scaling->src_w, scaling->src_h);
328 SLOGI(" dst : (dst_w, dst_h) = (%d, %d)\n", scaling->dst_w, scaling->dst_h);
329 SLOGI(" scaling_factor : (scale_w, scale_y) = (%3.2f, %3.2f)\n", (double)scaling->dst_w / scaling->src_w, (double)scaling->dst_h / scaling->src_h);
330 }