Mercurial > MadButterfly
comparison src/graph_engine_skia.cpp @ 512:d186d1e24458 Android_Skia
Change prototype of mbe_copy_source().
- To make mbe_copy_source more portable, user of mbe_copy_source()
should specify source and destinate canvas for copying.
- Export a new function for Skia graphic engine, for Android JNI.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 01 Dec 2009 22:55:27 +0800 |
parents | caa087976b17 |
children | 6394a1e33b2f |
comparison
equal
deleted
inserted
replaced
511:caa087976b17 | 512:d186d1e24458 |
---|---|
513 co_aix r, co_aix g, co_aix b, co_aix a) { | 513 co_aix r, co_aix g, co_aix b, co_aix a) { |
514 canvas->paint->setARGB(MB_CO_COMP_2_SK(a), | 514 canvas->paint->setARGB(MB_CO_COMP_2_SK(a), |
515 MB_CO_COMP_2_SK(r), | 515 MB_CO_COMP_2_SK(r), |
516 MB_CO_COMP_2_SK(g), | 516 MB_CO_COMP_2_SK(g), |
517 MB_CO_COMP_2_SK(b)); | 517 MB_CO_COMP_2_SK(b)); |
518 canvas->paint->ptn = NULL; | 518 canvas->states->ptn = NULL; |
519 } | 519 } |
520 | 520 |
521 void mbe_set_scaled_font(mbe_t *canvas, | 521 void mbe_set_scaled_font(mbe_t *canvas, |
522 const mbe_scaled_font_t *scaled) {} | 522 const mbe_scaled_font_t *scaled) {} |
523 void mbe_set_source_rgb(mbe_t *canvas, co_aix r, co_aix g, co_aix b) {} | 523 void mbe_set_source_rgb(mbe_t *canvas, co_aix r, co_aix g, co_aix b) {} |
651 _finish_paint(canvas); | 651 _finish_paint(canvas); |
652 | 652 |
653 path->reset(); | 653 path->reset(); |
654 } | 654 } |
655 | 655 |
656 mbe_t *mbe_create(mbe_surface_t *target) { | 656 /*! \brief Create a mbe from a SkCanvas. |
657 * | |
658 * It is only used for Android JNI. It is used to create mbe_t from a | |
659 * SkCanvas created by Canvas class of Android Java application. | |
660 */ | |
661 mbe_t *skia_mbe_create_by_canvas(SkCanvas *canvas) { | |
657 mbe_t *mbe; | 662 mbe_t *mbe; |
658 struct _mbe_states_t *states; | 663 struct _mbe_states_t *states; |
659 SkBitmap *bitmap = (SkBitmap *)target; | |
660 | 664 |
661 mbe = (mbe_t *)malloc(sizeof(mbe_t)); | 665 mbe = (mbe_t *)malloc(sizeof(mbe_t)); |
662 if(mbe == NULL) | 666 if(mbe == NULL) |
663 return NULL; | 667 return NULL; |
664 | 668 |
668 if(states == NULL) { | 672 if(states == NULL) { |
669 free(mbe); | 673 free(mbe); |
670 return NULL; | 674 return NULL; |
671 } | 675 } |
672 | 676 |
673 mbe->canvas = new SkCanvas(*bitmap); | 677 canvas->ref(); |
678 mbe->canvas = canvas; | |
674 mbe->path = new SkPath(); | 679 mbe->path = new SkPath(); |
675 mbe->subpath = new SkPath(); | 680 mbe->subpath = new SkPath(); |
676 mbe->saved_region = new SkRegion(); | 681 mbe->saved_region = new SkRegion(); |
677 mbe->paint = new SkPaint(); | 682 mbe->paint = new SkPaint(); |
678 states->ptn = NULL; | 683 states->ptn = NULL; |
679 states->ptn_owned = 0; | 684 states->ptn_owned = 0; |
680 states->line_width = 0; | 685 states->line_width = 0; |
681 states->next = NULL; | 686 states->next = NULL; |
682 | 687 |
683 if(mbe->canvas == NULL || mbe->path == NULL || | 688 if(mbe->path == NULL || |
684 mbe->subpath == NULL || mbe->paint == NULL || | 689 mbe->subpath == NULL || mbe->paint == NULL || |
685 mbe->saved_region == NULL) | 690 mbe->saved_region == NULL) |
686 goto fail; | 691 goto fail; |
687 | 692 |
688 memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6); | 693 memcpy(states->matrix, id_matrix, sizeof(co_aix) * 6); |
689 | 694 |
690 return mbe; | 695 return mbe; |
691 | 696 |
692 fail: | 697 fail: |
693 if(mbe->canvas) delete mbe->canvas; | 698 canvas->unref(); |
694 if(mbe->path) delete mbe->path; | 699 if(mbe->path) delete mbe->path; |
695 if(mbe->subpath) delete mbe->subpath; | 700 if(mbe->subpath) delete mbe->subpath; |
696 if(mbe->paint) delete mbe->paint; | 701 if(mbe->paint) delete mbe->paint; |
697 if(mbe->saved_region) delete mbe->saved_region; | 702 if(mbe->saved_region) delete mbe->saved_region; |
698 free(states); | 703 free(states); |
699 free(mbe); | 704 free(mbe); |
700 | 705 |
701 return NULL; | 706 return NULL; |
702 } | 707 } |
703 | 708 |
709 mbe_t *mbe_create(mbe_surface_t *target) { | |
710 mbe_t *mbe; | |
711 SkBitmap *bitmap = (SkBitmap *)target; | |
712 SkCanvas *canvas; | |
713 | |
714 canvas = new SkCanvas(*bitmap); | |
715 if(canvas == NULL) { | |
716 delete bitmap; | |
717 return NULL; | |
718 } | |
719 | |
720 mbe = skia_mbe_create_by_canvas(canvas); | |
721 canvas->unref(); | |
722 | |
723 if(mbe == NULL) { | |
724 delete bitmap; | |
725 } | |
726 | |
727 return mbe; | |
728 } | |
729 | |
704 void mbe_destroy(mbe_t *canvas) { | 730 void mbe_destroy(mbe_t *canvas) { |
705 struct _mbe_states_t *states; | 731 struct _mbe_states_t *states; |
706 | 732 |
707 delete canvas->canvas; | 733 canvas->canvas->unref(); |
708 delete canvas->path; | 734 delete canvas->path; |
709 delete canvas->subpath; | 735 delete canvas->subpath; |
710 delete canvas->paint; | 736 delete canvas->paint; |
711 delete canvas->saved_region; | 737 delete canvas->saved_region; |
712 while(canvas->states) { | 738 while(canvas->states) { |
764 SkColor color = 0; | 790 SkColor color = 0; |
765 | 791 |
766 canvas->canvas->drawColor(color, SkPorterDuff::kClear_Mode); | 792 canvas->canvas->drawColor(color, SkPorterDuff::kClear_Mode); |
767 } | 793 } |
768 | 794 |
769 void mbe_copy_source(mbe_t *canvas) { | 795 void mbe_copy_source(mbe_t *src, mbe_t *dst) { |
770 SkPaint *paint = canvas->paint; | 796 SkPaint *paint = dst->paint; |
797 SkShader *shader; | |
798 SkBitmap *bmap; | |
771 SkXfermode *mode; | 799 SkXfermode *mode; |
772 | 800 |
773 _prepare_paint(canvas, SkPaint::kFill_Style); | 801 _prepare_paint(dst, SkPaint::kFill_Style); |
774 mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kSrc_Mode); | 802 mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kSrc_Mode); |
775 paint->setXfermode(mode); | 803 paint->setXfermode(mode); |
776 /* mode->unref(); */ | 804 mode->unref(); |
777 | 805 bmap = &src->canvas->getDevice()->accessBitmap(false); |
778 canvas->canvas->drawPaint(*paint); | 806 shader = SkShader::CreateBitmapShader(*bmap, |
779 | 807 SkShader::kClamp_TileMode , |
808 SkShader::kClamp_TileMode); | |
809 paint->setShader(shader); | |
810 shader->unref(); | |
811 | |
812 dst->canvas->drawPaint(*paint); | |
813 | |
780 _finish_paint(canvas); | 814 _finish_paint(canvas); |
781 } | 815 } |
782 | 816 |
783 void mbe_transform(mbe_t *mbe, co_aix matrix[6]) { | 817 void mbe_transform(mbe_t *mbe, co_aix matrix[6]) { |
784 _update_path(mbe); | 818 _update_path(mbe); |