diff options
Diffstat (limited to 'src/macterm.c')
| -rw-r--r-- | src/macterm.c | 99 |
1 files changed, 98 insertions, 1 deletions
diff --git a/src/macterm.c b/src/macterm.c index b458444f977..671ac1010d2 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -335,7 +335,7 @@ static struct terminal *mac_create_terminal P_ ((struct mac_display_info *dpyinf | |||
| 335 | static int max_fringe_bmp = 0; | 335 | static int max_fringe_bmp = 0; |
| 336 | static CGImageRef *fringe_bmp = 0; | 336 | static CGImageRef *fringe_bmp = 0; |
| 337 | 337 | ||
| 338 | static CGColorSpaceRef mac_cg_color_space_rgb; | 338 | CGColorSpaceRef mac_cg_color_space_rgb; |
| 339 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 | 339 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 |
| 340 | static CGColorRef mac_cg_color_black; | 340 | static CGColorRef mac_cg_color_black; |
| 341 | #endif | 341 | #endif |
| @@ -508,6 +508,48 @@ XDrawLine (display, p, gc, x1, y1, x2, y2) | |||
| 508 | GC gc; | 508 | GC gc; |
| 509 | int x1, y1, x2, y2; | 509 | int x1, y1, x2, y2; |
| 510 | { | 510 | { |
| 511 | #if USE_MAC_IMAGE_IO | ||
| 512 | CGContextRef context; | ||
| 513 | XImagePtr ximg = p; | ||
| 514 | CGColorSpaceRef color_space; | ||
| 515 | CGImageAlphaInfo alpha_info; | ||
| 516 | CGFloat gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2; | ||
| 517 | |||
| 518 | if (y1 != y2) | ||
| 519 | gx1 += 0.5f, gx2 += 0.5f; | ||
| 520 | if (x1 != x2) | ||
| 521 | gy1 += 0.5f, gy2 += 0.5f; | ||
| 522 | |||
| 523 | if (ximg->bits_per_pixel == 32) | ||
| 524 | { | ||
| 525 | color_space = mac_cg_color_space_rgb; | ||
| 526 | alpha_info = (kCGImageAlphaNoneSkipFirst | ||
| 527 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 | ||
| 528 | | kCGBitmapByteOrder32Host | ||
| 529 | #endif | ||
| 530 | ); | ||
| 531 | } | ||
| 532 | else | ||
| 533 | { | ||
| 534 | color_space = NULL; | ||
| 535 | alpha_info = kCGImageAlphaOnly; | ||
| 536 | } | ||
| 537 | if (color_space == NULL) | ||
| 538 | return; | ||
| 539 | context = CGBitmapContextCreate (ximg->data, ximg->width, | ||
| 540 | ximg->height, 8, | ||
| 541 | ximg->bytes_per_line, color_space, | ||
| 542 | alpha_info); | ||
| 543 | if (ximg->bits_per_pixel == 32) | ||
| 544 | CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context, gc); | ||
| 545 | else | ||
| 546 | CGContextSetGrayStrokeColor (context, gc->xgcv.foreground / 255.0f, 1.0); | ||
| 547 | CGContextMoveToPoint (context, gx1, gy1); | ||
| 548 | CGContextAddLineToPoint (context, gx2, gy2); | ||
| 549 | CGContextClosePath (context); | ||
| 550 | CGContextStrokePath (context); | ||
| 551 | CGContextRelease (context); | ||
| 552 | #else | ||
| 511 | CGrafPtr old_port; | 553 | CGrafPtr old_port; |
| 512 | GDHandle old_gdh; | 554 | GDHandle old_gdh; |
| 513 | 555 | ||
| @@ -537,6 +579,7 @@ XDrawLine (display, p, gc, x1, y1, x2, y2) | |||
| 537 | UnlockPixels (GetGWorldPixMap (p)); | 579 | UnlockPixels (GetGWorldPixMap (p)); |
| 538 | 580 | ||
| 539 | SetGWorld (old_port, old_gdh); | 581 | SetGWorld (old_port, old_gdh); |
| 582 | #endif | ||
| 540 | } | 583 | } |
| 541 | 584 | ||
| 542 | 585 | ||
| @@ -748,6 +791,17 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 748 | unsigned int width, height; | 791 | unsigned int width, height; |
| 749 | unsigned int depth; | 792 | unsigned int depth; |
| 750 | { | 793 | { |
| 794 | #if USE_MAC_IMAGE_IO | ||
| 795 | XImagePtr ximg; | ||
| 796 | |||
| 797 | ximg = xmalloc (sizeof (*ximg)); | ||
| 798 | ximg->width = width; | ||
| 799 | ximg->height = height; | ||
| 800 | ximg->bits_per_pixel = depth == 1 ? 8 : 32; | ||
| 801 | ximg->bytes_per_line = width * (ximg->bits_per_pixel / 8); | ||
| 802 | ximg->data = xmalloc (ximg->bytes_per_line * height); | ||
| 803 | return ximg; | ||
| 804 | #else | ||
| 751 | Pixmap pixmap; | 805 | Pixmap pixmap; |
| 752 | Rect r; | 806 | Rect r; |
| 753 | QDErr err; | 807 | QDErr err; |
| @@ -768,6 +822,7 @@ XCreatePixmap (display, w, width, height, depth) | |||
| 768 | if (err != noErr) | 822 | if (err != noErr) |
| 769 | return NULL; | 823 | return NULL; |
| 770 | return pixmap; | 824 | return pixmap; |
| 825 | #endif | ||
| 771 | } | 826 | } |
| 772 | 827 | ||
| 773 | 828 | ||
| @@ -782,6 +837,38 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 782 | { | 837 | { |
| 783 | Pixmap pixmap; | 838 | Pixmap pixmap; |
| 784 | BitMap bitmap; | 839 | BitMap bitmap; |
| 840 | #if USE_MAC_IMAGE_IO | ||
| 841 | CGDataProviderRef provider; | ||
| 842 | CGImageRef image_mask; | ||
| 843 | CGContextRef context; | ||
| 844 | |||
| 845 | pixmap = XCreatePixmap (display, w, width, height, depth); | ||
| 846 | if (pixmap == NULL) | ||
| 847 | return NULL; | ||
| 848 | |||
| 849 | mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height); | ||
| 850 | provider = CGDataProviderCreateWithData (NULL, bitmap.baseAddr, | ||
| 851 | bitmap.rowBytes * height, NULL); | ||
| 852 | image_mask = CGImageMaskCreate (width, height, 1, 1, bitmap.rowBytes, | ||
| 853 | provider, NULL, 0); | ||
| 854 | CGDataProviderRelease (provider); | ||
| 855 | |||
| 856 | context = CGBitmapContextCreate (pixmap->data, width, height, 8, | ||
| 857 | pixmap->bytes_per_line, | ||
| 858 | mac_cg_color_space_rgb, | ||
| 859 | kCGImageAlphaNoneSkipFirst | ||
| 860 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 | ||
| 861 | | kCGBitmapByteOrder32Host | ||
| 862 | #endif | ||
| 863 | ); | ||
| 864 | |||
| 865 | CG_SET_FILL_COLOR (context, fg); | ||
| 866 | CGContextFillRect (context, CGRectMake (0, 0, width, height)); | ||
| 867 | CG_SET_FILL_COLOR (context, bg); | ||
| 868 | CGContextDrawImage (context, CGRectMake (0, 0, width, height), image_mask); | ||
| 869 | CGContextRelease (context); | ||
| 870 | CGImageRelease (image_mask); | ||
| 871 | #else | ||
| 785 | CGrafPtr old_port; | 872 | CGrafPtr old_port; |
| 786 | GDHandle old_gdh; | 873 | GDHandle old_gdh; |
| 787 | static GC gc = NULL; | 874 | static GC gc = NULL; |
| @@ -810,6 +897,7 @@ XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth) | |||
| 810 | #endif /* not TARGET_API_MAC_CARBON */ | 897 | #endif /* not TARGET_API_MAC_CARBON */ |
| 811 | UnlockPixels (GetGWorldPixMap (pixmap)); | 898 | UnlockPixels (GetGWorldPixMap (pixmap)); |
| 812 | SetGWorld (old_port, old_gdh); | 899 | SetGWorld (old_port, old_gdh); |
| 900 | #endif | ||
| 813 | mac_free_bitmap (&bitmap); | 901 | mac_free_bitmap (&bitmap); |
| 814 | 902 | ||
| 815 | return pixmap; | 903 | return pixmap; |
| @@ -821,7 +909,16 @@ XFreePixmap (display, pixmap) | |||
| 821 | Display *display; | 909 | Display *display; |
| 822 | Pixmap pixmap; | 910 | Pixmap pixmap; |
| 823 | { | 911 | { |
| 912 | #if USE_MAC_IMAGE_IO | ||
| 913 | if (pixmap) | ||
| 914 | { | ||
| 915 | if (pixmap->data) | ||
| 916 | xfree (pixmap->data); | ||
| 917 | xfree (pixmap); | ||
| 918 | } | ||
| 919 | #else | ||
| 824 | DisposeGWorld (pixmap); | 920 | DisposeGWorld (pixmap); |
| 921 | #endif | ||
| 825 | } | 922 | } |
| 826 | 923 | ||
| 827 | 924 | ||