[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#35468: [PATCH] Refactor draw_glyph_string on X and w32
From: |
mituharu |
Subject: |
bug#35468: [PATCH] Refactor draw_glyph_string on X and w32 |
Date: |
Wed, 1 May 2019 09:14:50 +0900 |
User-agent: |
SquirrelMail/1.4.22-5.el6 |
> As for the color manipulation, I went low-level as you said before:
>
> unsigned long foreground, background;
> gdif->get_context_foreground (gc, &foreground);
> gdif->get_context_background (gc, &background);
> gdif->set_context_foreground (gc, background);
> gdif->fill_rectangle (s, gc, x, y, w, h);
> gdif->set_context_foreground (gc, foreground);
>
> which replaces the XGetGCValues section in x_draw_stretch_glyph_string.
> This unfortunately is more work in the w32 case as it manipulates s->gc
> instead of just using the calculated gc->background. I'm not sure how
> one would make a no-op version of setting the context foreground work in
> all fill calls.
>
> If that is unsatisfactory), then instead I could do something like:
>
> gdif->fill_rectangle_with_color (s, gc->background, gc, x, y, w, h);
>
> Which wouldn't touch s->gc for the w32 version and would do the whole
> XGetGCValues dance for the X version.
Unlike the NS port, the terminal code in the Mac port is much like the X11
version.
But there is one notable difference in the above respect.
It defines mac_erase_rectangle, which is like mac_fill_rectangle (the
XFillRectangle counterpart)
but uses the background color of GC and also handles stipples:
/* Mac replacement for XFillRectangle. */
static void
mac_fill_rectangle (struct frame *f, GC gc, int x, int y, int width, int
height)
{
MAC_BEGIN_DRAW_TO_FRAME (f, gc, context);
CGContextSetFillColorWithColor (context, gc->cg_fore_color);
{
CGRect rect = mac_rect_make (f, x, y, width, height);
CGContextFillRects (context, &rect, 1);
}
MAC_END_DRAW_TO_FRAME (f);
}
static void
mac_erase_rectangle (struct frame *f, GC gc, int x, int y,
int width, int height)
{
MAC_BEGIN_DRAW_TO_FRAME (f, gc, context);
{
CGRect rect = mac_rect_make (f, x, y, width, height);
CG_CONTEXT_FILL_RECT_WITH_GC_BACKGROUND (f, context, rect, gc);
if (gc->xgcv.fill_style == FillOpaqueStippled && gc->xgcv.stipple)
{
CGContextClipToRects (context, &rect, 1);
CGContextSetFillColorWithColor (context, gc->cg_fore_color);
int scale = CFArrayGetCount (gc->xgcv.stipple);
if (FRAME_BACKING_SCALE_FACTOR (f) < scale)
scale = FRAME_BACKING_SCALE_FACTOR (f);
CGImageRef image_mask =
(CGImageRef) CFArrayGetValueAtIndex (gc->xgcv.stipple, scale - 1);
rect = CGRectMake (0, 0, CGImageGetWidth (image_mask) / (CGFloat) scale,
CGImageGetHeight (image_mask) / (CGFloat) scale);
CGContextScaleCTM (context, 1, -1);
CGContextSetInterpolationQuality (context, kCGInterpolationNone);
CGContextDrawTiledImage (context, rect, image_mask);
}
}
MAC_END_DRAW_TO_FRAME (f);
}
BTW, the code between MAC_BEGIN_DRAW_TO_FRAME and MAC_END_DRAW_TO_FRAME
is executed in the dedicated drawing thread with the help of Grand Central
Dispatch.
See https://bitbucket.org/mituharu/emacs-mac/src/master/src/macterm.c for
the full source code.
I guess introducing the erase_rectagle handler makes things simpler and
efficient.
YAMAMOTO Mitsuharu
mituharu@math.s.chiba-u.ac.jp