comparison src/macterm.c @ 69488:72158718da16

(mac_initialize) [USE_CG_DRAWING]: Call mac_init_fringe. (max_fringe_bmp, fringe_bmp) [USE_CG_DRAWING]: New variables. (mac_define_fringe_bitmap, mac_destroy_fringe_bitmap) (mac_draw_cg_image) [USE_CG_DRAWING]: New functions. (mac_draw_bitmap) [USE_CG_DRAWING]: Remove function. (x_draw_fringe_bitmap) [USE_CG_DRAWING]: Use mac_draw_cg_image instead of mac_draw_bitmap. (x_redisplay_interface) [USE_CG_DRAWING]: Set handlers for define_fringe_bitmap and destroy_fringe_bitmap.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Wed, 15 Mar 2006 07:55:53 +0000
parents a8fd29f179b0
children eafd737138ea
comparison
equal deleted inserted replaced
69487:606d39d5dc60 69488:72158718da16
279 GREEN_FROM_ULONG (color) / 255.0f, \ 279 GREEN_FROM_ULONG (color) / 255.0f, \
280 BLUE_FROM_ULONG (color) / 255.0f, 1.0f) 280 BLUE_FROM_ULONG (color) / 255.0f, 1.0f)
281 #if USE_CG_DRAWING 281 #if USE_CG_DRAWING
282 #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context) 282 #define FRAME_CG_CONTEXT(f) ((f)->output_data.mac->cg_context)
283 283
284 /* Fringe bitmaps. */
285
286 static int max_fringe_bmp = 0;
287 static CGImageRef *fringe_bmp = 0;
288
284 static CGContextRef 289 static CGContextRef
285 mac_begin_cg_clip (f, gc) 290 mac_begin_cg_clip (f, gc)
286 struct frame *f; 291 struct frame *f;
287 GC gc; 292 GC gc;
288 { 293 {
507 } 512 }
508 513
509 514
510 /* Mac replacement for XCopyArea. */ 515 /* Mac replacement for XCopyArea. */
511 516
517 #if USE_CG_DRAWING
518 static void
519 mac_draw_cg_image (image, f, gc, src_x, src_y, width, height,
520 dest_x, dest_y, overlay_p)
521 CGImageRef image;
522 struct frame *f;
523 GC gc;
524 int src_x, src_y;
525 unsigned int width, height;
526 int dest_x, dest_y, overlay_p;
527 {
528 CGContextRef context;
529 float port_height = FRAME_PIXEL_HEIGHT (f);
530 CGRect dest_rect = CGRectMake (dest_x, dest_y, width, height);
531
532 context = mac_begin_cg_clip (f, gc);
533 if (!overlay_p)
534 {
535 CG_SET_FILL_COLOR (context, gc->xgcv.background);
536 CGContextFillRect (context, dest_rect);
537 }
538 CGContextClipToRect (context, dest_rect);
539 CGContextScaleCTM (context, 1, -1);
540 CGContextTranslateCTM (context, 0, -port_height);
541 if (CGImageIsMask (image))
542 CG_SET_FILL_COLOR (context, gc->xgcv.foreground);
543 CGContextDrawImage (context,
544 CGRectMake (dest_x - src_x,
545 port_height - (dest_y - src_y
546 + CGImageGetHeight (image)),
547 CGImageGetWidth (image),
548 CGImageGetHeight (image)),
549 image);
550 mac_end_cg_clip (f);
551 }
552
553 #else /* !USE_CG_DRAWING */
554
512 static void 555 static void
513 mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p) 556 mac_draw_bitmap (f, gc, x, y, width, height, bits, overlay_p)
514 struct frame *f; 557 struct frame *f;
515 GC gc; 558 GC gc;
516 int x, y, width, height; 559 int x, y, width, height;
522 565
523 bitmap.rowBytes = sizeof(unsigned short); 566 bitmap.rowBytes = sizeof(unsigned short);
524 bitmap.baseAddr = (char *)bits; 567 bitmap.baseAddr = (char *)bits;
525 SetRect (&(bitmap.bounds), 0, 0, width, height); 568 SetRect (&(bitmap.bounds), 0, 0, width, height);
526 569
527 #if USE_CG_DRAWING
528 mac_prepare_for_quickdraw (f);
529 #endif
530 SetPortWindowPort (FRAME_MAC_WINDOW (f)); 570 SetPortWindowPort (FRAME_MAC_WINDOW (f));
531 571
532 RGBForeColor (GC_FORE_COLOR (gc)); 572 RGBForeColor (GC_FORE_COLOR (gc));
533 RGBBackColor (GC_BACK_COLOR (gc)); 573 RGBBackColor (GC_BACK_COLOR (gc));
534 SetRect (&r, x, y, x + width, y + height); 574 SetRect (&r, x, y, x + width, y + height);
550 #endif /* not TARGET_API_MAC_CARBON */ 590 #endif /* not TARGET_API_MAC_CARBON */
551 mac_end_clip (gc); 591 mac_end_clip (gc);
552 592
553 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f))); 593 RGBBackColor (GC_BACK_COLOR (FRAME_NORMAL_GC (f)));
554 } 594 }
595 #endif /* !USE_CG_DRAWING */
555 596
556 597
557 /* Mac replacement for XCreateBitmapFromBitmapData. */ 598 /* Mac replacement for XCreateBitmapFromBitmapData. */
558 599
559 static void 600 static void
1999 if (!face->stipple) 2040 if (!face->stipple)
2000 XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground); 2041 XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->foreground);
2001 #endif 2042 #endif
2002 } 2043 }
2003 2044
2004 if (p->which) 2045 if (p->which
2005 { 2046 #if USE_CG_DRAWING
2006 unsigned short *bits = p->bits + p->dh; 2047 && p->which < max_fringe_bmp
2048 #endif
2049 )
2050 {
2007 XGCValues gcv; 2051 XGCValues gcv;
2008 2052
2009 XGetGCValues (display, face->gc, GCForeground, &gcv); 2053 XGetGCValues (display, face->gc, GCForeground, &gcv);
2010 XSetForeground (display, face->gc, 2054 XSetForeground (display, face->gc,
2011 (p->cursor_p 2055 (p->cursor_p
2012 ? (p->overlay_p ? face->background 2056 ? (p->overlay_p ? face->background
2013 : f->output_data.mac->cursor_pixel) 2057 : f->output_data.mac->cursor_pixel)
2014 : face->foreground)); 2058 : face->foreground));
2059 #if USE_CG_DRAWING
2060 mac_draw_cg_image (fringe_bmp[p->which], f, face->gc, 0, p->dh,
2061 p->wd, p->h, p->x, p->y, p->overlay_p);
2062 #else
2015 mac_draw_bitmap (f, face->gc, p->x, p->y, 2063 mac_draw_bitmap (f, face->gc, p->x, p->y,
2016 p->wd, p->h, bits, p->overlay_p); 2064 p->wd, p->h, p->bits + p->dh, p->overlay_p);
2065 #endif
2017 XSetForeground (display, face->gc, gcv.foreground); 2066 XSetForeground (display, face->gc, gcv.foreground);
2018 } 2067 }
2019 2068
2020 mac_reset_clip_rectangles (display, face->gc); 2069 mac_reset_clip_rectangles (display, face->gc);
2021 } 2070 }
2022 2071
2072 #if USE_CG_DRAWING
2073 static void
2074 mac_define_fringe_bitmap (which, bits, h, wd)
2075 int which;
2076 unsigned short *bits;
2077 int h, wd;
2078 {
2079 unsigned short *mask_bits;
2080 int i;
2081 CGDataProviderRef provider;
2082
2083 if (which >= max_fringe_bmp)
2084 {
2085 i = max_fringe_bmp;
2086 max_fringe_bmp = which + 20;
2087 fringe_bmp = (CGImageRef *) xrealloc (fringe_bmp, max_fringe_bmp * sizeof (CGImageRef));
2088 while (i < max_fringe_bmp)
2089 fringe_bmp[i++] = 0;
2090 }
2091
2092 for (i = 0; i < h; i++)
2093 bits[i] = ~bits[i];
2094 provider = CGDataProviderCreateWithData (NULL, bits,
2095 sizeof (unsigned short) * h, NULL);
2096 if (provider)
2097 {
2098 fringe_bmp[which] = CGImageMaskCreate (wd, h, 1, 1,
2099 sizeof (unsigned short),
2100 provider, NULL, 0);
2101 CGDataProviderRelease (provider);
2102 }
2103 }
2104
2105 static void
2106 mac_destroy_fringe_bitmap (which)
2107 int which;
2108 {
2109 if (which >= max_fringe_bmp)
2110 return;
2111
2112 if (fringe_bmp[which])
2113 CGImageRelease (fringe_bmp[which]);
2114 fringe_bmp[which] = 0;
2115 }
2116 #endif
2023 2117
2024 2118
2025 /* This is called when starting Emacs and when restarting after 2119 /* This is called when starting Emacs and when restarting after
2026 suspend. When starting Emacs, no window is mapped. And nothing 2120 suspend. When starting Emacs, no window is mapped. And nothing
2027 must be done to Emacs's own window if it is suspended (though that 2121 must be done to Emacs's own window if it is suspended (though that
10890 0, /* flush_display_optional */ 10984 0, /* flush_display_optional */
10891 x_clear_window_mouse_face, 10985 x_clear_window_mouse_face,
10892 x_get_glyph_overhangs, 10986 x_get_glyph_overhangs,
10893 x_fix_overlapping_area, 10987 x_fix_overlapping_area,
10894 x_draw_fringe_bitmap, 10988 x_draw_fringe_bitmap,
10989 #if USE_CG_DRAWING
10990 mac_define_fringe_bitmap,
10991 mac_destroy_fringe_bitmap,
10992 #else
10895 0, /* define_fringe_bitmap */ 10993 0, /* define_fringe_bitmap */
10896 0, /* destroy_fringe_bitmap */ 10994 0, /* destroy_fringe_bitmap */
10995 #endif
10897 mac_per_char_metric, 10996 mac_per_char_metric,
10898 mac_encode_char, 10997 mac_encode_char,
10899 mac_compute_glyph_string_overhangs, 10998 mac_compute_glyph_string_overhangs,
10900 x_draw_glyph_string, 10999 x_draw_glyph_string,
10901 mac_define_frame_cursor, 11000 mac_define_frame_cursor,
10967 11066
10968 if (!inhibit_window_system) 11067 if (!inhibit_window_system)
10969 MakeMeTheFrontProcess (); 11068 MakeMeTheFrontProcess ();
10970 #endif 11069 #endif
10971 #endif 11070 #endif
11071
11072 #if USE_CG_DRAWING
11073 mac_init_fringe ();
11074 #endif
11075
10972 UNBLOCK_INPUT; 11076 UNBLOCK_INPUT;
10973 } 11077 }
10974 11078
10975 11079
10976 void 11080 void