Mercurial > MadButterfly
comparison src/graph_engine_openvg.c @ 612:b1d1b6c5af90 openvg
Implements setting pattern matrix for OpenVG
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 07 Jul 2010 18:44:17 +0800 |
parents | e78bff7d23d3 |
children | 6a0be737a3f3 |
comparison
equal
deleted
inserted
replaced
611:38383f5f645d | 612:b1d1b6c5af90 |
---|---|
10 | 10 |
11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ | 11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ |
12 (((int)(0xf * g) & 0xf) << 16) | \ | 12 (((int)(0xf * g) & 0xf) << 16) | \ |
13 (((int)(0xf * b) & 0xf) << 16) | \ | 13 (((int)(0xf * b) & 0xf) << 16) | \ |
14 ((int)(0xf * a) & 0xf)) | 14 ((int)(0xf * a) & 0xf)) |
15 | |
16 #define MK_ID(mtx) \ | |
17 do { \ | |
18 (mtx)[0] = 1; \ | |
19 (mtx)[1] = 0; \ | |
20 (mtx)[2] = 0; \ | |
21 (mtx)[3] = 0; \ | |
22 (mtx)[4] = 1; \ | |
23 (mtx)[5] = 0; \ | |
24 (mtx)[6] = 0; \ | |
25 (mtx)[7] = 0; \ | |
26 (mtx)[8] = 1; \ | |
27 } while(0) | |
15 | 28 |
16 /* | 29 /* |
17 * This implementation supports only from image surface. | 30 * This implementation supports only from image surface. |
18 */ | 31 */ |
19 mbe_pattern_t * | 32 mbe_pattern_t * |
20 mbe_pattern_create_for_surface(mbe_surface_t *surface) { | 33 mbe_pattern_create_for_surface(mbe_surface_t *surface) { |
21 mbe_pattern_t *pattern; | 34 mbe_pattern_t *pattern; |
22 _ge_openvg_img_t *ge_img; | 35 _ge_openvg_img_t *ge_img; |
36 VGfloat *mtx; | |
23 VGPaint paint; | 37 VGPaint paint; |
24 | 38 |
25 /* Support only from image surface */ | 39 /* Support only from image surface */ |
26 if(surface->asso_img == NULL) | 40 if(surface->asso_img == NULL) |
27 return NULL; | 41 return NULL; |
33 ge_img = surface->asso_img; | 47 ge_img = surface->asso_img; |
34 pattern = O_ALLOC(mbe_pattern_t); | 48 pattern = O_ALLOC(mbe_pattern_t); |
35 pattern->asso_img = ge_img; | 49 pattern->asso_img = ge_img; |
36 pattern->paint = paint; | 50 pattern->paint = paint; |
37 | 51 |
52 mtx = pattern->mtx; | |
53 MK_ID(mtx); | |
54 | |
38 return pattern; | 55 return pattern; |
56 } | |
57 | |
58 void | |
59 _mbe_load_pattern_mtx(VGfloat *mtx1, VGfloat *mtx2, int mode) { | |
60 VGfloat affine; | |
61 | |
62 vgSeti(VG_MATRIX_MODE, mode); | |
63 vgLoadMatrix(mtx1); | |
64 if(mtx2) | |
65 vgMultMatrix(mtx2); | |
39 } | 66 } |
40 | 67 |
41 static mbe_pattern_t * | 68 static mbe_pattern_t * |
42 _mbe_pattern_create_gradient(VGfloat *gradient, int grad_len, | 69 _mbe_pattern_create_gradient(VGfloat *gradient, int grad_len, |
43 int grad_type, | 70 int grad_type, |
85 return NULL; | 112 return NULL; |
86 } | 113 } |
87 | 114 |
88 pattern->paint = paint; | 115 pattern->paint = paint; |
89 pattern->asso_img = NULL; | 116 pattern->asso_img = NULL; |
117 | |
118 MK_ID(pattern->mtx); | |
90 | 119 |
91 return pattern; | 120 return pattern; |
92 } | 121 } |
93 | 122 |
94 /* | 123 /* |
170 vgDestroyImage(vg_img); | 199 vgDestroyImage(vg_img); |
171 return NULL; | 200 return NULL; |
172 } | 201 } |
173 | 202 |
174 void | 203 void |
204 mbe_pattern_set_matrix(mbe_pattern_t *ptn, co_aix *mtx) { | |
205 co_aix rev[6]; | |
206 | |
207 compute_reverse(mtx, rev); | |
208 ptn->mtx[0] = rev[0]; | |
209 ptn->mtx[1] = rev[3]; | |
210 ptn->mtx[2] = 0; | |
211 ptn->mtx[3] = rev[1]; | |
212 ptn->mtx[4] = rev[4]; | |
213 ptn->mtx[5] = 0; | |
214 ptn->mtx[6] = rev[2]; | |
215 ptn->mtx[7] = rev[5]; | |
216 ptn->mtx[8] = 1; | |
217 } | |
218 | |
219 void | |
175 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, | 220 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, |
176 co_comp_t b, co_comp_t a) { | 221 co_comp_t b, co_comp_t a) { |
177 VGPaint paint; | 222 VGPaint paint; |
178 VGuint color; | 223 VGuint color; |
179 | 224 |
222 | 267 |
223 static int | 268 static int |
224 _openvg_find_config(mb_img_fmt_t fmt, int w, int h, | 269 _openvg_find_config(mb_img_fmt_t fmt, int w, int h, |
225 EGLConfig *config) { | 270 EGLConfig *config) { |
226 EGLDisplay display; | 271 EGLDisplay display; |
227 EGLint attrib_list[16]; | 272 EGLint attrib_list[32]; |
228 EGLConfig configs[1]; | 273 EGLConfig configs[1]; |
229 EGLint nconfigs; | 274 EGLint nconfigs; |
230 int i = 0; | 275 int i = 0; |
231 EGLBoolean r; | 276 EGLBoolean r; |
232 | 277 |
238 attrib_list[i++] = 8; | 283 attrib_list[i++] = 8; |
239 attrib_list[i++] = EGL_BLUE_SIZE; | 284 attrib_list[i++] = EGL_BLUE_SIZE; |
240 attrib_list[i++] = 8; | 285 attrib_list[i++] = 8; |
241 attrib_list[i++] = EGL_ALPHA_SIZE; | 286 attrib_list[i++] = EGL_ALPHA_SIZE; |
242 attrib_list[i++] = 8; | 287 attrib_list[i++] = 8; |
288 attrib_list[i++] = EGL_ALPHA_MASK_SIZE; | |
289 attrib_list[i++] = 8; | |
243 break; | 290 break; |
244 | 291 |
245 case MB_IFMT_RGB24: | 292 case MB_IFMT_RGB24: |
246 attrib_list[i++] = EGL_RED_SIZE; | 293 attrib_list[i++] = EGL_RED_SIZE; |
247 attrib_list[i++] = 8; | 294 attrib_list[i++] = 8; |
248 attrib_list[i++] = EGL_GREEN_SIZE; | 295 attrib_list[i++] = EGL_GREEN_SIZE; |
249 attrib_list[i++] = 8; | 296 attrib_list[i++] = 8; |
250 attrib_list[i++] = EGL_BLUE_SIZE; | 297 attrib_list[i++] = EGL_BLUE_SIZE; |
251 attrib_list[i++] = 8; | 298 attrib_list[i++] = 8; |
299 attrib_list[i++] = EGL_ALPHA_MASK_SIZE; | |
300 attrib_list[i++] = 8; | |
252 break; | 301 break; |
253 | 302 |
254 case MB_IFMT_A8: | 303 case MB_IFMT_A8: |
255 attrib_list[i++] = EGL_ALPHA_SIZE; | 304 attrib_list[i++] = EGL_ALPHA_SIZE; |
256 attrib_list[i++] = 8; | 305 attrib_list[i++] = 8; |
306 attrib_list[i++] = EGL_ALPHA_MASK_SIZE; | |
307 attrib_list[i++] = 8; | |
257 break; | 308 break; |
258 | 309 |
259 case MB_IFMT_A1: | 310 case MB_IFMT_A1: |
260 attrib_list[i++] = EGL_ALPHA_SIZE; | 311 attrib_list[i++] = EGL_ALPHA_SIZE; |
312 attrib_list[i++] = 1; | |
313 attrib_list[i++] = EGL_ALPHA_MASK_SIZE; | |
261 attrib_list[i++] = 1; | 314 attrib_list[i++] = 1; |
262 break; | 315 break; |
263 | 316 |
264 case MB_IFMT_RGB16_565: | 317 case MB_IFMT_RGB16_565: |
265 attrib_list[i++] = EGL_RED_SIZE; | 318 attrib_list[i++] = EGL_RED_SIZE; |
266 attrib_list[i++] = 5; | 319 attrib_list[i++] = 5; |
267 attrib_list[i++] = EGL_GREEN_SIZE; | 320 attrib_list[i++] = EGL_GREEN_SIZE; |
268 attrib_list[i++] = 6; | 321 attrib_list[i++] = 6; |
269 attrib_list[i++] = EGL_BLUE_SIZE; | 322 attrib_list[i++] = EGL_BLUE_SIZE; |
323 attrib_list[i++] = 5; | |
324 attrib_list[i++] = EGL_ALPHA_MASK_SIZE; | |
270 attrib_list[i++] = 5; | 325 attrib_list[i++] = 5; |
271 break; | 326 break; |
272 | 327 |
273 default: | 328 default: |
274 return -1; | 329 return -1; |
469 eglDestroyContext(display, canvas->ctx); | 524 eglDestroyContext(display, canvas->ctx); |
470 canvas->tgt->asso_mbe = NULL; /* remove association */ | 525 canvas->tgt->asso_mbe = NULL; /* remove association */ |
471 free(canvas); | 526 free(canvas); |
472 } | 527 } |
473 | 528 |
474 /* | |
475 * This implementation support only paint with image paint. OpenVG | |
476 * does not support paint path with an alpha value. But, it supports | |
477 * to draw image with an alpha value. | |
478 */ | |
479 void | 529 void |
480 mbe_paint_with_alpha(mbe_t *canvas, co_comp_t alpha) { | 530 mbe_paint_with_alpha(mbe_t *canvas, co_comp_t alpha) { |
481 VGImage vg_img; | 531 EGLDisplay display; |
482 _ge_openvg_img_t *ge_img; | 532 VGHandle mask; |
533 EGLint w, h; | |
534 EGLBoolean r; | |
483 | 535 |
484 _MK_CURRENT_CTX(canvas); | 536 _MK_CURRENT_CTX(canvas); |
485 | 537 |
486 ASSERT(canvas->src != NULL && canvas->src->asso_img != NULL); | 538 display = _VG_DISPLAY(); |
487 ge_img = canvas->src->asso_img; | 539 |
488 vg_img = ge_img->img; | 540 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w); |
489 | 541 ASSERT(r == EGL_TRUE); |
490 vgDrawImage(vg_img); | 542 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h); |
543 ASSERT(r == EGL_TRUE); | |
544 | |
545 /* enable and fill mask layer with alpha value */ | |
546 vgSeti(VG_MASKING, VG_TRUE); | |
547 mask = vgCreateMaskLayer(w, h); | |
548 ASSERT(mask != VG_INVALID_HANDLE); | |
549 vgFillMaskLayer(mask, 0, 0, w, h, alpha); | |
550 vgMask(mask, VG_SET_MASK, 0, 0, w, h); | |
551 vgDestroyMaskLayer(mask); | |
552 | |
553 mbe_paint(canvas); | |
554 | |
555 vgSeti(VG_MASKING, VG_FALSE); | |
491 } | 556 } |
492 | 557 |
493 void | 558 void |
494 mbe_paint(mbe_t *canvas) { | 559 mbe_paint(mbe_t *canvas) { |
495 EGLDisplay display; | 560 EGLDisplay display; |
497 EGLBoolean r; | 562 EGLBoolean r; |
498 VGPath path; | 563 VGPath path; |
499 | 564 |
500 _MK_CURRENT_CTX(canvas); | 565 _MK_CURRENT_CTX(canvas); |
501 _MK_CURRENT_PAINT(canvas); | 566 _MK_CURRENT_PAINT(canvas); |
567 if(canvas->src) | |
568 _mbe_load_pattern_mtx(canvas->src->mtx, NULL, | |
569 VG_MATRIX_FILL_PAINT_TO_USER); | |
502 | 570 |
503 display = _VG_DISPLAY(); | 571 display = _VG_DISPLAY(); |
504 | 572 |
505 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w); | 573 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w); |
506 ASSERT(r == EGL_TRUE); | 574 ASSERT(r == EGL_TRUE); |
507 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h); | 575 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h); |
508 ASSERT(r == EGL_TRUE); | 576 ASSERT(r == EGL_TRUE); |
509 | 577 |
578 /* disable scissoring and identity transform matrix */ | |
510 vgSeti(VG_SCISSORING, VG_FALSE); | 579 vgSeti(VG_SCISSORING, VG_FALSE); |
580 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE); | |
581 vgLoadIdentity(); | |
511 | 582 |
512 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, | 583 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
513 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); | 584 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
514 vguRect(path, 0, 0, w, h); | 585 vguRect(path, 0, 0, w, h); |
515 vgDrawPath(path, VG_FILL_PATH); | 586 vgDrawPath(path, VG_FILL_PATH); |
516 vgDestroyPath(path); | 587 vgDestroyPath(path); |
517 | 588 |
589 /* re-enable scissoring and restore transform matrix */ | |
590 vgLoadMatrix(canvas->mtx); | |
518 vgSeti(VG_SCISSORING, VG_TRUE); | 591 vgSeti(VG_SCISSORING, VG_TRUE); |
519 } | 592 } |
520 | 593 |
521 void | 594 void |
522 mbe_clear(mbe_t *canvas) { | 595 mbe_clear(mbe_t *canvas) { |