Mercurial > MadButterfly
comparison src/graph_engine_skia.cpp @ 822:586e50f82c1f
Unify coding style tag for emacs and vim.
author | Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com> |
---|---|
date | Tue, 14 Sep 2010 01:08:39 +0800 |
parents | 663d361eb3b8 |
children | 7b4e80ab671a |
comparison
equal
deleted
inserted
replaced
821:bfdc82bbd6e4 | 822:586e50f82c1f |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
1 /*! \page ge_layer Graphic Engine Layer | 3 /*! \page ge_layer Graphic Engine Layer |
2 * | 4 * |
3 * Graphic Engine Layer is an abstract of graphic engine; likes Cairo | 5 * Graphic Engine Layer is an abstract of graphic engine; likes Cairo |
4 * and Skia. It provides portability for the rest of MadButterfly. | 6 * and Skia. It provides portability for the rest of MadButterfly. |
5 * | 7 * |
79 struct _mbe_t { | 81 struct _mbe_t { |
80 SkCanvas *canvas; | 82 SkCanvas *canvas; |
81 SkPath *path, *subpath; | 83 SkPath *path, *subpath; |
82 SkPaint *paint; | 84 SkPaint *paint; |
83 SkRegion *saved_region; | 85 SkRegion *saved_region; |
84 | 86 |
85 struct _mbe_states_t *states; | 87 struct _mbe_states_t *states; |
86 }; | 88 }; |
87 | 89 |
88 struct _mbe_states_t { | 90 struct _mbe_states_t { |
89 mbe_pattern_t *ptn; | 91 mbe_pattern_t *ptn; |
133 _prepare_sized_pattern(mbe_t *mbe, mbe_pattern_t *ptn) { | 135 _prepare_sized_pattern(mbe_t *mbe, mbe_pattern_t *ptn) { |
134 SkCanvas *canvas = mbe->canvas; | 136 SkCanvas *canvas = mbe->canvas; |
135 SkPath path; | 137 SkPath path; |
136 co_aix x, y; | 138 co_aix x, y; |
137 co_aix reverse[6]; | 139 co_aix reverse[6]; |
138 | 140 |
139 *mbe->saved_region = canvas->getTotalClip(); | 141 *mbe->saved_region = canvas->getTotalClip(); |
140 | 142 |
141 compute_reverse(ptn->matrix, reverse); | 143 compute_reverse(ptn->matrix, reverse); |
142 x = 0; y = 0; | 144 x = 0; y = 0; |
143 matrix_trans_pos(reverse, &x, &y); | 145 matrix_trans_pos(reverse, &x, &y); |
144 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); | 146 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); |
145 x = 0; y = ptn->h; | 147 x = 0; y = ptn->h; |
147 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); | 149 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); |
148 x = ptn->w; y = ptn->h; | 150 x = ptn->w; y = ptn->h; |
149 matrix_trans_pos(reverse, &x, &y); | 151 matrix_trans_pos(reverse, &x, &y); |
150 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); | 152 path.moveTo(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y)); |
151 path.close(); | 153 path.close(); |
152 | 154 |
153 canvas->clipPath(path, SkRegion::kIntersect_Op); | 155 canvas->clipPath(path, SkRegion::kIntersect_Op); |
154 } | 156 } |
155 | 157 |
156 static void | 158 static void |
157 _finish_sized_pattern(mbe_t *mbe) { | 159 _finish_sized_pattern(mbe_t *mbe) { |
158 SkCanvas *canvas = mbe->canvas; | 160 SkCanvas *canvas = mbe->canvas; |
159 | 161 |
160 canvas->setClipRegion(*mbe->saved_region); | 162 canvas->setClipRegion(*mbe->saved_region); |
161 } | 163 } |
162 | 164 |
163 static void | 165 static void |
164 _canvas_device_region(SkCanvas *canvas, SkRegion *region) { | 166 _canvas_device_region(SkCanvas *canvas, SkRegion *region) { |
178 SkMatrix canvas_matrix; | 180 SkMatrix canvas_matrix; |
179 SkPoint point; | 181 SkPoint point; |
180 | 182 |
181 MB_MATRIX_2_SKMATRIX(canvas_matrix, mbe->states->matrix); | 183 MB_MATRIX_2_SKMATRIX(canvas_matrix, mbe->states->matrix); |
182 path->addPath(*subpath, canvas_matrix); | 184 path->addPath(*subpath, canvas_matrix); |
183 | 185 |
184 subpath->getLastPt(&point); | 186 subpath->getLastPt(&point); |
185 subpath->rewind(); | 187 subpath->rewind(); |
186 subpath->moveTo(point); | 188 subpath->moveTo(point); |
187 } | 189 } |
188 | 190 |
198 SkShader *shader; | 200 SkShader *shader; |
199 co_aix matrix[6]; | 201 co_aix matrix[6]; |
200 SkMatrix skmatrix; | 202 SkMatrix skmatrix; |
201 | 203 |
202 paint->setStyle(style); | 204 paint->setStyle(style); |
203 | 205 |
204 if(ptn != NULL) { | 206 if(ptn != NULL) { |
205 /* Local matrix of SkShader is a mapping from source pattern to | 207 /* Local matrix of SkShader is a mapping from source pattern to |
206 * user space. Unlikely, for Cairo is a mapping from user space | 208 * user space. Unlikely, for Cairo is a mapping from user space |
207 * to source pattern. | 209 * to source pattern. |
208 */ | 210 */ |
221 } | 223 } |
222 | 224 |
223 static void | 225 static void |
224 _finish_paint(mbe_t *mbe) { | 226 _finish_paint(mbe_t *mbe) { |
225 mbe_pattern_t *ptn = mbe->states->ptn; | 227 mbe_pattern_t *ptn = mbe->states->ptn; |
226 | 228 |
227 mbe->paint->reset(); | 229 mbe->paint->reset(); |
228 if(ptn != NULL && ptn->has_size) | 230 if(ptn != NULL && ptn->has_size) |
229 _finish_sized_pattern(mbe); | 231 _finish_sized_pattern(mbe); |
230 } | 232 } |
231 | 233 |
239 SkShader::kClamp_TileMode); | 241 SkShader::kClamp_TileMode); |
240 if(ptn->shader == NULL) { | 242 if(ptn->shader == NULL) { |
241 free(ptn); | 243 free(ptn); |
242 return NULL; | 244 return NULL; |
243 } | 245 } |
244 | 246 |
245 ptn->has_size = 1; | 247 ptn->has_size = 1; |
246 ptn->w = bitmap->width(); | 248 ptn->w = bitmap->width(); |
247 ptn->h = bitmap->height(); | 249 ptn->h = bitmap->height(); |
248 | 250 |
249 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); | 251 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); |
250 | 252 |
251 return ptn; | 253 return ptn; |
252 } | 254 } |
253 | 255 |
254 mbe_pattern_t * | 256 mbe_pattern_t * |
255 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, co_aix radius0, | 257 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, co_aix radius0, |
267 poses = new SkScalar[stop_cnt]; | 269 poses = new SkScalar[stop_cnt]; |
268 if(ptn == NULL || colors == NULL || poses == NULL) | 270 if(ptn == NULL || colors == NULL || poses == NULL) |
269 goto fail; | 271 goto fail; |
270 | 272 |
271 center.set(CO_AIX_2_SKSCALAR(cx1), CO_AIX_2_SKSCALAR(cy1)); | 273 center.set(CO_AIX_2_SKSCALAR(cx1), CO_AIX_2_SKSCALAR(cy1)); |
272 | 274 |
273 stop = stops; | 275 stop = stops; |
274 for(i = 0; i < stop_cnt; i++) { | 276 for(i = 0; i < stop_cnt; i++) { |
275 colors[i] = MBSTOP_2_SKCOLOR(stop); | 277 colors[i] = MBSTOP_2_SKCOLOR(stop); |
276 poses[i] = CO_AIX_2_SKSCALAR(stop->offset); | 278 poses[i] = CO_AIX_2_SKSCALAR(stop->offset); |
277 } | 279 } |
287 SkShader::kClamp_TileMode); | 289 SkShader::kClamp_TileMode); |
288 if(ptn->shader == NULL) | 290 if(ptn->shader == NULL) |
289 goto fail; | 291 goto fail; |
290 | 292 |
291 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); | 293 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); |
292 | 294 |
293 delete colors; | 295 delete colors; |
294 delete poses; | 296 delete poses; |
295 return ptn; | 297 return ptn; |
296 | 298 |
297 fail: | 299 fail: |
298 if(ptn) free(ptn); | 300 if(ptn) free(ptn); |
299 if(colors) delete colors; | 301 if(colors) delete colors; |
300 if(poses) delete poses; | 302 if(poses) delete poses; |
301 return NULL; | 303 return NULL; |
318 if(ptn == NULL || colors == NULL || poses == NULL) | 320 if(ptn == NULL || colors == NULL || poses == NULL) |
319 goto fail; | 321 goto fail; |
320 | 322 |
321 points[0].set(CO_AIX_2_SKSCALAR(x0), CO_AIX_2_SKSCALAR(y0)); | 323 points[0].set(CO_AIX_2_SKSCALAR(x0), CO_AIX_2_SKSCALAR(y0)); |
322 points[1].set(CO_AIX_2_SKSCALAR(x1), CO_AIX_2_SKSCALAR(y1)); | 324 points[1].set(CO_AIX_2_SKSCALAR(x1), CO_AIX_2_SKSCALAR(y1)); |
323 | 325 |
324 stop = stops; | 326 stop = stops; |
325 for(i = 0; i < stop_cnt; i++) { | 327 for(i = 0; i < stop_cnt; i++) { |
326 colors[i] = MBSTOP_2_SKCOLOR(stop); | 328 colors[i] = MBSTOP_2_SKCOLOR(stop); |
327 poses[i] = CO_AIX_2_SKSCALAR(stop->offset); | 329 poses[i] = CO_AIX_2_SKSCALAR(stop->offset); |
328 } | 330 } |
337 SkShader::kClamp_TileMode); | 339 SkShader::kClamp_TileMode); |
338 if(ptn->shader == NULL) | 340 if(ptn->shader == NULL) |
339 goto fail; | 341 goto fail; |
340 | 342 |
341 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); | 343 memcpy(ptn->matrix, id_matrix, sizeof(co_aix) * 6); |
342 | 344 |
343 delete colors; | 345 delete colors; |
344 delete poses; | 346 delete poses; |
345 return ptn; | 347 return ptn; |
346 | 348 |
347 fail: | 349 fail: |
348 if(ptn) free(ptn); | 350 if(ptn) free(ptn); |
349 if(colors) delete colors; | 351 if(colors) delete colors; |
350 if(poses) delete poses; | 352 if(poses) delete poses; |
351 return NULL; | 353 return NULL; |
392 SkBitmap::Config cfg; | 394 SkBitmap::Config cfg; |
393 | 395 |
394 switch(fmt) { | 396 switch(fmt) { |
395 case MB_IFMT_ARGB32: | 397 case MB_IFMT_ARGB32: |
396 cfg = SkBitmap::kARGB_8888_Config; break; | 398 cfg = SkBitmap::kARGB_8888_Config; break; |
397 | 399 |
398 case MB_IFMT_A8: | 400 case MB_IFMT_A8: |
399 cfg = SkBitmap::kA8_Config; break; | 401 cfg = SkBitmap::kA8_Config; break; |
400 | 402 |
401 case MB_IFMT_A1: | 403 case MB_IFMT_A1: |
402 cfg = SkBitmap::kA1_Config; break; | 404 cfg = SkBitmap::kA1_Config; break; |
403 | 405 |
404 case MB_IFMT_RGB16_565: | 406 case MB_IFMT_RGB16_565: |
405 cfg = SkBitmap::kRGB_565_Config; break; | 407 cfg = SkBitmap::kRGB_565_Config; break; |
406 | 408 |
407 case MB_IFMT_RGB24: | 409 case MB_IFMT_RGB24: |
408 default: | 410 default: |
409 return NULL; | 411 return NULL; |
410 } | 412 } |
411 | 413 |
412 bitmap = new SkBitmap(); | 414 bitmap = new SkBitmap(); |
413 if(bitmap == NULL) | 415 if(bitmap == NULL) |
414 return NULL; | 416 return NULL; |
415 | 417 |
416 bitmap->setConfig(cfg, width, height, stride); | 418 bitmap->setConfig(cfg, width, height, stride); |
417 bitmap->setPixels(data); | 419 bitmap->setPixels(data); |
418 | 420 |
419 return (mbe_surface_t *)bitmap; | 421 return (mbe_surface_t *)bitmap; |
420 } | 422 } |
421 | 423 |
422 mb_img_fmt_t mbe_image_surface_get_format(mbe_surface_t *surface) { | 424 mb_img_fmt_t mbe_image_surface_get_format(mbe_surface_t *surface) { |
423 SkBitmap *bitmap = (SkBitmap *)surface; | 425 SkBitmap *bitmap = (SkBitmap *)surface; |
424 mb_img_fmt_t fmt; | 426 mb_img_fmt_t fmt; |
425 SkBitmap::Config cfg; | 427 SkBitmap::Config cfg; |
426 | 428 |
427 cfg = bitmap->getConfig(); | 429 cfg = bitmap->getConfig(); |
428 switch(cfg) { | 430 switch(cfg) { |
429 case SkBitmap::kARGB_8888_Config: | 431 case SkBitmap::kARGB_8888_Config: |
430 fmt = MB_IFMT_ARGB32; break; | 432 fmt = MB_IFMT_ARGB32; break; |
431 | 433 |
451 SkBitmap::Config cfg; | 453 SkBitmap::Config cfg; |
452 | 454 |
453 switch(fmt) { | 455 switch(fmt) { |
454 case MB_IFMT_ARGB32: | 456 case MB_IFMT_ARGB32: |
455 cfg = SkBitmap::kARGB_8888_Config; break; | 457 cfg = SkBitmap::kARGB_8888_Config; break; |
456 | 458 |
457 case MB_IFMT_A8: | 459 case MB_IFMT_A8: |
458 cfg = SkBitmap::kA8_Config; break; | 460 cfg = SkBitmap::kA8_Config; break; |
459 | 461 |
460 case MB_IFMT_A1: | 462 case MB_IFMT_A1: |
461 cfg = SkBitmap::kA1_Config; break; | 463 cfg = SkBitmap::kA1_Config; break; |
462 | 464 |
463 case MB_IFMT_RGB16_565: | 465 case MB_IFMT_RGB16_565: |
464 cfg = SkBitmap::kRGB_565_Config; break; | 466 cfg = SkBitmap::kRGB_565_Config; break; |
465 | 467 |
466 case MB_IFMT_RGB24: | 468 case MB_IFMT_RGB24: |
467 default: | 469 default: |
468 return NULL; | 470 return NULL; |
469 } | 471 } |
470 | 472 |
471 bitmap = new SkBitmap(); | 473 bitmap = new SkBitmap(); |
472 if(bitmap == NULL) | 474 if(bitmap == NULL) |
473 return NULL; | 475 return NULL; |
474 | 476 |
475 bitmap->setConfig(cfg, width, height); | 477 bitmap->setConfig(cfg, width, height); |
476 bitmap->allocPixels(); | 478 bitmap->allocPixels(); |
477 | 479 |
478 return (mbe_surface_t *)bitmap; | 480 return (mbe_surface_t *)bitmap; |
479 } | 481 } |
501 color = ((uint32_t)(alpha * 255)) << 24; | 503 color = ((uint32_t)(alpha * 255)) << 24; |
502 filter = | 504 filter = |
503 SkColorFilter::CreatePorterDuffFilter(color, | 505 SkColorFilter::CreatePorterDuffFilter(color, |
504 SkPorterDuff::kSrcOver_Mode); | 506 SkPorterDuff::kSrcOver_Mode); |
505 mbe_paint(canvas); | 507 mbe_paint(canvas); |
506 | 508 |
507 } | 509 } |
508 | 510 |
509 void mbe_surface_destroy(mbe_surface_t *surface) { | 511 void mbe_surface_destroy(mbe_surface_t *surface) { |
510 SkBitmap *bmap = (SkBitmap *)surface; | 512 SkBitmap *bmap = (SkBitmap *)surface; |
511 | 513 |
512 delete bmap; | 514 delete bmap; |
513 } | 515 } |
514 | 516 |
515 void mbe_set_source_rgba(mbe_t *canvas, | 517 void mbe_set_source_rgba(mbe_t *canvas, |
516 co_aix r, co_aix g, co_aix b, co_aix a) { | 518 co_aix r, co_aix g, co_aix b, co_aix a) { |
542 ASSERT(ptn); | 544 ASSERT(ptn); |
543 ASSERT(path); | 545 ASSERT(path); |
544 | 546 |
545 if(!canvas->subpath->isEmpty()) | 547 if(!canvas->subpath->isEmpty()) |
546 _update_path(canvas); | 548 _update_path(canvas); |
547 | 549 |
548 _prepare_paint(canvas, SkPaint::kFill_Style); | 550 _prepare_paint(canvas, SkPaint::kFill_Style); |
549 | 551 |
550 canvas->canvas->drawPath(*path, *paint); | 552 canvas->canvas->drawPath(*path, *paint); |
551 | 553 |
552 _finish_paint(canvas); | 554 _finish_paint(canvas); |
574 void mbe_text_path(mbe_t *canvas, const char *txt) {} | 576 void mbe_text_path(mbe_t *canvas, const char *txt) {} |
575 | 577 |
576 void mbe_rectangle(mbe_t *canvas, co_aix x, co_aix y, | 578 void mbe_rectangle(mbe_t *canvas, co_aix x, co_aix y, |
577 co_aix width, co_aix height) { | 579 co_aix width, co_aix height) { |
578 SkPath *subpath = canvas->subpath; | 580 SkPath *subpath = canvas->subpath; |
579 | 581 |
580 subpath->addRect(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y), | 582 subpath->addRect(CO_AIX_2_SKSCALAR(x), CO_AIX_2_SKSCALAR(y), |
581 CO_AIX_2_SKSCALAR(x + width), | 583 CO_AIX_2_SKSCALAR(x + width), |
582 CO_AIX_2_SKSCALAR(y + height)); | 584 CO_AIX_2_SKSCALAR(y + height)); |
583 } | 585 } |
584 | 586 |
603 | 605 |
604 void mbe_restore(mbe_t *canvas) { | 606 void mbe_restore(mbe_t *canvas) { |
605 struct _mbe_states_t *states; | 607 struct _mbe_states_t *states; |
606 | 608 |
607 _update_path(canvas); | 609 _update_path(canvas); |
608 | 610 |
609 states = canvas->states; | 611 states = canvas->states; |
610 ASSERT(states->next); | 612 ASSERT(states->next); |
611 canvas->states = states->next; | 613 canvas->states = states->next; |
612 free(states); | 614 free(states); |
613 } | 615 } |
626 SkRegion region, dev_region; | 628 SkRegion region, dev_region; |
627 bool in_fill; | 629 bool in_fill; |
628 | 630 |
629 if(!canvas->subpath->isEmpty()) | 631 if(!canvas->subpath->isEmpty()) |
630 _update_path(canvas); | 632 _update_path(canvas); |
631 | 633 |
632 _canvas_device_region(canvas->canvas, &dev_region); | 634 _canvas_device_region(canvas->canvas, &dev_region); |
633 region.setPath(*canvas->path, dev_region); | 635 region.setPath(*canvas->path, dev_region); |
634 | 636 |
635 in_fill = region.contains(x, y); | 637 in_fill = region.contains(x, y); |
636 | 638 |
637 return in_fill; | 639 return in_fill; |
638 } | 640 } |
639 | 641 |
668 struct _mbe_states_t *states; | 670 struct _mbe_states_t *states; |
669 | 671 |
670 mbe = (mbe_t *)malloc(sizeof(mbe_t)); | 672 mbe = (mbe_t *)malloc(sizeof(mbe_t)); |
671 if(mbe == NULL) | 673 if(mbe == NULL) |
672 return NULL; | 674 return NULL; |
673 | 675 |
674 mbe->states = (struct _mbe_states_t *) | 676 mbe->states = (struct _mbe_states_t *) |
675 malloc(sizeof(struct _mbe_states_t)); | 677 malloc(sizeof(struct _mbe_states_t)); |
676 states = mbe->states; | 678 states = mbe->states; |
677 if(states == NULL) { | 679 if(states == NULL) { |
678 free(mbe); | 680 free(mbe); |
679 return NULL; | 681 return NULL; |
680 } | 682 } |
681 | 683 |
682 canvas->ref(); | 684 canvas->ref(); |
683 mbe->canvas = canvas; | 685 mbe->canvas = canvas; |
684 mbe->path = new SkPath(); | 686 mbe->path = new SkPath(); |
685 mbe->subpath = new SkPath(); | 687 mbe->subpath = new SkPath(); |
686 mbe->saved_region = new SkRegion(); | 688 mbe->saved_region = new SkRegion(); |
694 mbe->subpath == NULL || mbe->paint == NULL || | 696 mbe->subpath == NULL || mbe->paint == NULL || |
695 mbe->saved_region == NULL) | 697 mbe->saved_region == NULL) |
696 goto fail; | 698 goto fail; |
697 | 699 |
698 memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6); | 700 memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6); |
699 | 701 |
700 return mbe; | 702 return mbe; |
701 | 703 |
702 fail: | 704 fail: |
703 canvas->unref(); | 705 canvas->unref(); |
704 if(mbe->path) delete mbe->path; | 706 if(mbe->path) delete mbe->path; |
705 if(mbe->subpath) delete mbe->subpath; | 707 if(mbe->subpath) delete mbe->subpath; |
706 if(mbe->paint) delete mbe->paint; | 708 if(mbe->paint) delete mbe->paint; |
707 if(mbe->saved_region) delete mbe->saved_region; | 709 if(mbe->saved_region) delete mbe->saved_region; |
708 free(states); | 710 free(states); |
709 free(mbe); | 711 free(mbe); |
710 | 712 |
711 return NULL; | 713 return NULL; |
712 } | 714 } |
713 | 715 |
714 mbe_t *mbe_create(mbe_surface_t *target) { | 716 mbe_t *mbe_create(mbe_surface_t *target) { |
715 mbe_t *mbe; | 717 mbe_t *mbe; |
719 canvas = new SkCanvas(*bitmap); | 721 canvas = new SkCanvas(*bitmap); |
720 if(canvas == NULL) { | 722 if(canvas == NULL) { |
721 delete bitmap; | 723 delete bitmap; |
722 return NULL; | 724 return NULL; |
723 } | 725 } |
724 | 726 |
725 mbe = skia_mbe_create_by_canvas(canvas); | 727 mbe = skia_mbe_create_by_canvas(canvas); |
726 canvas->unref(); | 728 canvas->unref(); |
727 | 729 |
728 if(mbe == NULL) { | 730 if(mbe == NULL) { |
729 delete bitmap; | 731 delete bitmap; |
730 } | 732 } |
731 | 733 |
732 return mbe; | 734 return mbe; |
733 } | 735 } |
734 | 736 |
735 void mbe_destroy(mbe_t *canvas) { | 737 void mbe_destroy(mbe_t *canvas) { |
736 struct _mbe_states_t *states; | 738 struct _mbe_states_t *states; |
737 | 739 |
738 canvas->canvas->unref(); | 740 canvas->canvas->unref(); |
739 delete canvas->path; | 741 delete canvas->path; |
740 delete canvas->subpath; | 742 delete canvas->subpath; |
741 delete canvas->paint; | 743 delete canvas->paint; |
742 delete canvas->saved_region; | 744 delete canvas->saved_region; |
743 while(canvas->states) { | 745 while(canvas->states) { |
744 states = canvas->states; | 746 states = canvas->states; |
745 canvas->states = states->next; | 747 canvas->states = states->next; |
746 | 748 |
747 if(states->ptn && states->ptn_owned) | 749 if(states->ptn && states->ptn_owned) |
748 mbe_pattern_destroy(states->ptn); | 750 mbe_pattern_destroy(states->ptn); |
749 free(states); | 751 free(states); |
750 } | 752 } |
751 free(canvas); | 753 free(canvas); |
753 | 755 |
754 void mbe_paint(mbe_t *canvas) { | 756 void mbe_paint(mbe_t *canvas) { |
755 SkPaint *paint = canvas->paint; | 757 SkPaint *paint = canvas->paint; |
756 | 758 |
757 ASSERT(paint); | 759 ASSERT(paint); |
758 | 760 |
759 _prepare_paint(canvas, SkPaint::kFill_Style); | 761 _prepare_paint(canvas, SkPaint::kFill_Style); |
760 | 762 |
761 canvas->canvas->drawPaint(*paint); | 763 canvas->canvas->drawPaint(*paint); |
762 | 764 |
763 _finish_paint(canvas); | 765 _finish_paint(canvas); |
764 } | 766 } |
765 | 767 |
766 void mbe_save(mbe_t *canvas) { | 768 void mbe_save(mbe_t *canvas) { |
767 struct _mbe_states_t *states; | 769 struct _mbe_states_t *states; |
768 | 770 |
769 states = (struct _mbe_states_t *)malloc(sizeof(struct _mbe_states_t)); | 771 states = (struct _mbe_states_t *)malloc(sizeof(struct _mbe_states_t)); |
770 ASSERT(states); | 772 ASSERT(states); |
771 | 773 |
772 memcpy(states, canvas->states, sizeof(struct _mbe_states_t)); | 774 memcpy(states, canvas->states, sizeof(struct _mbe_states_t)); |
773 states->next = canvas->states; | 775 states->next = canvas->states; |
774 canvas->states = states; | 776 canvas->states = states; |
775 } | 777 } |
776 | 778 |
781 } | 783 } |
782 | 784 |
783 void mbe_clip(mbe_t *canvas) { | 785 void mbe_clip(mbe_t *canvas) { |
784 if(!canvas->subpath->isEmpty()) | 786 if(!canvas->subpath->isEmpty()) |
785 _update_path(canvas); | 787 _update_path(canvas); |
786 | 788 |
787 canvas->canvas->clipPath(*canvas->path, SkRegion::kIntersect_Op); | 789 canvas->canvas->clipPath(*canvas->path, SkRegion::kIntersect_Op); |
788 canvas->path->rewind(); | 790 canvas->path->rewind(); |
789 canvas->subpath->rewind(); | 791 canvas->subpath->rewind(); |
790 } | 792 } |
791 | 793 |
808 mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kSrc_Mode); | 810 mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kSrc_Mode); |
809 paint->setXfermode(mode); | 811 paint->setXfermode(mode); |
810 bmap = &src->canvas->getDevice()->accessBitmap(false); | 812 bmap = &src->canvas->getDevice()->accessBitmap(false); |
811 | 813 |
812 dst->canvas->drawBitmap(*bmap, 0, 0, paint); | 814 dst->canvas->drawBitmap(*bmap, 0, 0, paint); |
813 | 815 |
814 paint->reset(); | 816 paint->reset(); |
815 mode->unref(); | 817 mode->unref(); |
816 /* _finish_paint(dst); */ | 818 /* _finish_paint(dst); */ |
817 } | 819 } |
818 | 820 |
819 void mbe_transform(mbe_t *mbe, co_aix matrix[6]) { | 821 void mbe_transform(mbe_t *mbe, co_aix matrix[6]) { |
820 _update_path(mbe); | 822 _update_path(mbe); |
821 | 823 |
822 matrix_mul(matrix, mbe->states->matrix, mbe->states->matrix); | 824 matrix_mul(matrix, mbe->states->matrix, mbe->states->matrix); |
823 } | 825 } |
824 | 826 |
825 void mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius, | 827 void mbe_arc(mbe_t *mbe, co_aix x, co_aix y, co_aix radius, |
826 co_aix angle_start, co_aix angle_stop) { | 828 co_aix angle_start, co_aix angle_stop) { |
836 x0 = point.fX; | 838 x0 = point.fX; |
837 y0 = point.fX; | 839 y0 = point.fX; |
838 r = CO_AIX_2_SKSCALAR(radius); | 840 r = CO_AIX_2_SKSCALAR(radius); |
839 ang_start = CO_AIX_2_SKSCALAR(angle_start * 180 / PI); | 841 ang_start = CO_AIX_2_SKSCALAR(angle_start * 180 / PI); |
840 ang_stop = CO_AIX_2_SKSCALAR(angle_stop * 180 / PI); | 842 ang_stop = CO_AIX_2_SKSCALAR(angle_stop * 180 / PI); |
841 | 843 |
842 /* Skia can only draw an arc in clockwise directly. We negative | 844 /* Skia can only draw an arc in clockwise directly. We negative |
843 * start and stop point to draw the arc in the mirror along x-axis | 845 * start and stop point to draw the arc in the mirror along x-axis |
844 * in a sub-path. Then, the sub-path are reflected along x-axis, | 846 * in a sub-path. Then, the sub-path are reflected along x-axis, |
845 * again. We get a right path, and add it to the path of mbe_t. | 847 * again. We get a right path, and add it to the path of mbe_t. |
846 */ | 848 */ |
847 if(ang_start > ang_stop) { | 849 if(ang_start > ang_stop) { |
848 SkPath tmppath; | 850 SkPath tmppath; |
849 SkMatrix matrix; | 851 SkMatrix matrix; |
850 co_aix reflect[6] = { 1, 0, 0, | 852 co_aix reflect[6] = { 1, 0, 0, |
851 0, -1, 0}; | 853 0, -1, 0}; |
852 | 854 |
853 rect.set(-r, -r, r, r); | 855 rect.set(-r, -r, r, r); |
854 sweep = ang_start - ang_stop; | 856 sweep = ang_start - ang_stop; |
855 tmppath.arcTo(rect, -ang_start, sweep, false); | 857 tmppath.arcTo(rect, -ang_start, sweep, false); |
856 | 858 |
857 reflect[2] = x; | 859 reflect[2] = x; |