codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 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 | |
Daniel Hillenbrand | 353fecb | 2012-07-22 16:14:08 +0200 | [diff] [blame] | 20 | #define LOG_NDEBUG 0 |
| 21 | #define LOG_TAG "SKIA" |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 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 | { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 273 | ALOGI("%s\n", title); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 274 | |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 275 | ALOGI(" sequence_no. = %u\n", cmd->seq_no); |
| 276 | ALOGI(" blit_op = %d(%s)\n", cmd->op, optbl[cmd->op].str); |
| 277 | ALOGI(" fill_color = %X\n", cmd->solid_color); |
| 278 | ALOGI(" global_alpha = %u\n", (unsigned int)cmd->g_alpha); |
| 279 | ALOGI(" PREMULT = %s\n", cmd->premult == PREMULTIPLIED ? "PREMULTIPLIED" : "NON-PREMULTIPLIED"); |
| 280 | ALOGI(" do_dither = %s\n", cmd->dither == true ? "dither" : "no-dither"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 281 | |
| 282 | printDataBlitRotate(cmd->rotate); |
| 283 | |
| 284 | printDataBlitScale(cmd->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 | printDataBlitClip(cmd->clipping); |
| 295 | } |
| 296 | |
| 297 | void printDataBlitImage(char *title, struct fimg2d_image *image) |
| 298 | { |
| 299 | if (NULL != image) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 300 | ALOGI(" Image_%s\n", title); |
| 301 | ALOGI(" addr = %X\n", image->addr.start); |
| 302 | ALOGI(" size = %u\n", image->addr.size); |
| 303 | ALOGI(" (width, height) = (%d, %d)\n", image->width, image->height); |
| 304 | ALOGI(" format = %d\n", image->fmt); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 305 | } else |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 306 | ALOGI(" Image_%s : NULL\n", title); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | void printDataBlitRect(char *title, struct fimg2d_rect *rect) |
| 310 | { |
| 311 | if (NULL != rect) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 312 | ALOGI(" RECT_%s\n", title); |
| 313 | ALOGI(" (x1, y1) = (%d, %d)\n", rect->x1, rect->y1); |
| 314 | ALOGI(" (x2, y2) = (%d, %d)\n", rect->x2, rect->y2); |
| 315 | ALOGI(" (width, height) = (%d, %d)\n", rect->x2 - rect->x1, rect->y2 - rect->y1); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 316 | } else |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 317 | ALOGI(" RECT_%s : NULL\n", title); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void printDataBlitRotate(enum rotation rotate) |
| 321 | { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 322 | ALOGI(" ROTATE : %d\n", rotate); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | void printDataBlitClip(struct fimg2d_clip *clip) |
| 326 | { |
| 327 | if (NULL != clip) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 328 | ALOGI(" CLIP\n"); |
| 329 | ALOGI(" clip %s\n", clip->enable == true ? "enabled" : "disabled"); |
| 330 | ALOGI(" (x1, y1) = (%d, %d)\n", clip->x1, clip->y1); |
| 331 | ALOGI(" (x2, y2) = (%d, %d)\n", clip->x2, clip->y2); |
| 332 | ALOGI(" (width, hight) = (%d, %d)\n", clip->x2 - clip->x1, clip->y2 - clip->y1); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 333 | } else |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 334 | ALOGI(" CLIP : NULL\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void printDataBlitScale(struct fimg2d_scale *scaling) |
| 338 | { |
| 339 | if (NULL != scaling) { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 340 | ALOGI(" SCALING\n"); |
| 341 | ALOGI(" scale_mode : %s\n", scaling->mode == 0 ? |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 342 | "NO_SCALING" : |
| 343 | (scaling->mode == 1 ? "SCALING_NEAREST" : "SCALING_BILINEAR")); |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 344 | ALOGI(" scaling_factor_unit : %s\n", scaling->factor == 0 ? "PERCENT" : "PIXEL"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 345 | |
| 346 | if (scaling->factor == 0) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 347 | ALOGI(" scaling_factor : (scale_w, scale_y) = (%d, %d)\n", scaling->scale_w, scaling->scale_h); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 348 | else { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 349 | ALOGI(" src : (src_w, src_h) = (%d, %d)\n", scaling->src_w, scaling->src_h); |
| 350 | ALOGI(" dst : (dst_w, dst_h) = (%d, %d)\n", scaling->dst_w, scaling->dst_h); |
| 351 | ALOGI(" 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); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 352 | } |
| 353 | } else |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 354 | ALOGI(" SCALING : NULL(NO SCALE MODE)\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 355 | |
| 356 | } |
| 357 | |
| 358 | void printDataMatrix(int matrixType) |
| 359 | { |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 360 | ALOGI(" MATRIX\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 361 | |
| 362 | if (matrixType & SkMatrix::kIdentity_Mask) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 363 | ALOGI(" Matrix_type : Identity_Mask\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 364 | |
| 365 | if (matrixType & SkMatrix::kTranslate_Mask) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 366 | ALOGI(" Matrix_type : Translate_Mask(the matrix has translation)\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 367 | |
| 368 | if (matrixType & SkMatrix::kScale_Mask) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 369 | ALOGI(" Matrix_type : Scale_Mask(the matrix has X or Y scale)\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 370 | |
| 371 | if (matrixType & SkMatrix::kAffine_Mask) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 372 | ALOGI(" Matrix_type : Affine_Mask(the matrix skews or rotates)\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 373 | |
| 374 | if (matrixType & SkMatrix::kPerspective_Mask) |
Daniel Hillenbrand | 0fdadca | 2012-07-22 15:45:33 +0200 | [diff] [blame] | 375 | ALOGI(" Matrix_type : Perspective_Mask(the matrix is in perspective)\n"); |
codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 376 | } |