[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/ns/refactor 361d043 11/12: Convert fringe bitmaps to vectors on
From: |
Alan Third |
Subject: |
scratch/ns/refactor 361d043 11/12: Convert fringe bitmaps to vectors on NS port |
Date: |
Sat, 24 Jul 2021 11:40:05 -0400 (EDT) |
branch: scratch/ns/refactor
commit 361d0438681565249132fd74932dd1783bccb978
Author: Alan Third <alan@idiocy.org>
Commit: Alan Third <alan@idiocy.org>
Convert fringe bitmaps to vectors on NS port
Unfortunately *step doesn't support masks for bitmap images so
changing the colors of fringe bitmaps is awkward. We can work around
this by converting the bitmap into an NSBezierPath and drawing it in
the required color.
* src/nsterm.m (ns_define_fringe_bitmap):
(ns_destroy_fringe_bitmap): New functions
(ns_draw_fringe_bitmap): Display the NSBezierPath.
* src/nsimage.m
([EmacsImage initFromXBM:width:height:fg:bg:reverseBytes:]): Remove
variable that's there to allow us to easily modify the XBM colors.
([EmacsImage setXBMColor:]): Remove method.
---
src/nsimage.m | 41 -------------------
src/nsterm.h | 2 -
src/nsterm.m | 125 ++++++++++++++++++++++++++--------------------------------
3 files changed, 55 insertions(+), 113 deletions(-)
diff --git a/src/nsimage.m b/src/nsimage.m
index 3c16cd3..bd01a51 100644
--- a/src/nsimage.m
+++ b/src/nsimage.m
@@ -381,51 +381,10 @@ ns_image_size_in_bytes (void *img)
}
}
- xbm_fg = fg;
[self addRepresentation: bmRep];
return self;
}
-/* Set color for a bitmap image. */
-- (instancetype)setXBMColor: (NSColor *)color
-{
- NSSize s = [self size];
- unsigned char *planes[5];
- EmacsCGFloat r, g, b, a;
- NSColor *rgbColor;
-
- if (bmRep == nil || color == nil)
- return self;
-
- if ([color colorSpace] != [NSColorSpace genericRGBColorSpace])
- rgbColor = [color colorUsingColorSpace:[NSColorSpace
genericRGBColorSpace]];
- else
- rgbColor = color;
-
- [rgbColor getRed: &r green: &g blue: &b alpha: &a];
-
- [bmRep getBitmapDataPlanes: planes];
-
- {
- int i, len = s.width*s.height;
- int rr = r * 0xff, gg = g * 0xff, bb = b * 0xff;
- unsigned char fgr = (xbm_fg >> 16) & 0xff;
- unsigned char fgg = (xbm_fg >> 8) & 0xff;
- unsigned char fgb = xbm_fg & 0xff;
-
- for (i = 0; i < len; ++i)
- if (planes[0][i] == fgr && planes[1][i] == fgg && planes[2][i] == fgb)
- {
- planes[0][i] = rr;
- planes[1][i] = gg;
- planes[2][i] = bb;
- }
- xbm_fg = ((rr << 16) & 0xff0000) + ((gg << 8) & 0xff00) + (bb & 0xff);
- }
-
- return self;
-}
-
- (instancetype)initForXPMWithDepth: (int)depth width: (int)width height:
(int)height
{
diff --git a/src/nsterm.h b/src/nsterm.h
index b55dc53..404c714 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -627,7 +627,6 @@ typedef id instancetype;
NSBitmapImageRep *bmRep; /* used for accessing pixel data */
unsigned char *pixmapData[5]; /* shortcut to access pixel data */
NSColor *stippleMask;
- unsigned long xbm_fg;
@public
NSAffineTransform *transform;
BOOL smoothing;
@@ -637,7 +636,6 @@ typedef id instancetype;
- (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
fg: (unsigned long)fg bg: (unsigned long)bg
reverseBytes: (BOOL)reverse;
-- (instancetype)setXBMColor: (NSColor *)color;
- (instancetype)initForXPMWithDepth: (int)depth width: (int)width height:
(int)height;
- (void)setPixmapData;
- (unsigned long)getPixelAtX: (int)x Y: (int)y;
diff --git a/src/nsterm.m b/src/nsterm.m
index bb18959..70ab338 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2895,6 +2895,36 @@ ns_compute_glyph_string_overhangs (struct glyph_string
*s)
==========================================================================
*/
+static NSMutableDictionary *fringe_bmp;
+
+static void
+ns_define_fringe_bitmap (int which, unsigned short *bits, int h, int w)
+{
+ NSBezierPath *p = [NSBezierPath bezierPath];
+
+ if (!fringe_bmp)
+ fringe_bmp = [[NSMutableDictionary alloc] initWithCapacity:1];
+
+ [p moveToPoint:NSMakePoint (0, 0)];
+
+ for (int y = 0 ; y < h ; y++)
+ for (int x = 0 ; x < w ; x++)
+ {
+ bool bit = bits[x/8 + y*w/8] & 0x80 >> x%8;
+ if (bit)
+ [p appendBezierPathWithRect:NSMakeRect (x, y, 1, 1)];
+ }
+
+ [fringe_bmp setObject:p forKey:[NSNumber numberWithInt:which]];
+}
+
+
+static void
+ns_destroy_fringe_bitmap (int which)
+{
+ [fringe_bmp removeObjectForKey:[NSNumber numberWithInt:which]];
+}
+
extern int max_used_fringe_bitmap;
static void
@@ -2922,41 +2952,18 @@ ns_draw_fringe_bitmap (struct window *w, struct
glyph_row *row,
struct frame *f = XFRAME (WINDOW_FRAME (w));
struct face *face = p->face;
- static EmacsImage **bimgs = NULL;
- static int nBimgs = 0;
NSRect clearRect = NSZeroRect;
- NSRect imageRect = NSZeroRect;
NSRect rowRect = ns_row_rect (w, row, ANY_AREA);
NSTRACE_WHEN (NSTRACE_GROUP_FRINGE, "ns_draw_fringe_bitmap");
NSTRACE_MSG ("which:%d cursor:%d overlay:%d width:%d height:%d period:%d",
p->which, p->cursor_p, p->overlay_p, p->wd, p->h, p->dh);
- /* grow bimgs if needed */
- if (nBimgs < max_used_fringe_bitmap)
- {
- bimgs = xrealloc (bimgs, max_used_fringe_bitmap * sizeof *bimgs);
- memset (bimgs + nBimgs, 0,
- (max_used_fringe_bitmap - nBimgs) * sizeof *bimgs);
- nBimgs = max_used_fringe_bitmap;
- }
-
- /* Work out the rectangle we will composite into. */
- if (p->which)
- imageRect = NSMakeRect (p->x, p->y, p->wd, p->h);
+ /* Work out the rectangle we will need to clear. */
+ clearRect = NSMakeRect (p->x, p->y, p->wd, p->h);
- /* Work out the rectangle we will need to clear. Because we're
- compositing rather than blitting, we need to clear the area under
- the image regardless of anything else. */
if (p->bx >= 0 && !p->overlay_p)
- {
- clearRect = NSMakeRect (p->bx, p->by, p->nx, p->ny);
- clearRect = NSUnionRect (clearRect, imageRect);
- }
- else
- {
- clearRect = imageRect;
- }
+ clearRect = NSUnionRect (clearRect, NSMakeRect (p->bx, p->by, p->nx,
p->ny));
/* Handle partially visible rows. */
clearRect = NSIntersectionRect (clearRect, rowRect);
@@ -2972,53 +2979,29 @@ ns_draw_fringe_bitmap (struct window *w, struct
glyph_row *row,
NSRectFill (clearRect);
}
- if (p->which)
+ NSBezierPath *bmp = [fringe_bmp objectForKey:[NSNumber
numberWithInt:p->which]];
+ if (bmp)
{
- EmacsImage *img = bimgs[p->which - 1];
-
- if (!img)
- {
- // Note: For "periodic" images, allocate one EmacsImage for
- // the base image, and use it for all dh:s.
- unsigned short *bits = p->bits;
- int full_height = p->h + p->dh;
- int i;
- unsigned char *cbits = xmalloc (full_height);
-
- for (i = 0; i < full_height; i++)
- cbits[i] = bits[i];
- img = [[EmacsImage alloc] initFromXBM: cbits width: 8
- height: full_height
- fg: 0 bg: 0
- reverseBytes: NO];
- bimgs[p->which - 1] = img;
- xfree (cbits);
- }
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ NSColor *bm_color;
+ /* Because the image is defined at (0, 0) we need to take a copy
+ and then transform that copy to the new origin. */
+ bmp = [bmp copy];
+ [transform translateXBy:p->x yBy:p->y - p->dh];
+ [bmp transformUsingAffineTransform:transform];
- {
- NSColor *bm_color;
- if (!p->cursor_p)
- bm_color = ns_lookup_indexed_color(face->foreground, f);
- else if (p->overlay_p)
- bm_color = ns_lookup_indexed_color(face->background, f);
- else
- bm_color = f->output_data.ns->cursor_color;
- [img setXBMColor: bm_color];
- }
-
- // Note: For periodic images, the full image height is "h + hd".
- // By using the height h, a suitable part of the image is used.
- NSRect fromRect = NSMakeRect(0, 0, p->wd, p->h);
+ if (!p->cursor_p)
+ bm_color = ns_lookup_indexed_color(face->foreground, f);
+ else if (p->overlay_p)
+ bm_color = ns_lookup_indexed_color(face->background, f);
+ else
+ bm_color = f->output_data.ns->cursor_color;
- NSTRACE_RECT ("fromRect", fromRect);
+ [bm_color set];
+ [bmp fill];
- [img drawInRect: imageRect
- fromRect: fromRect
- operation: NSCompositingOperationSourceOver
- fraction: 1.0
- respectFlipped: YES
- hints: nil];
+ [bmp release];
}
ns_unfocus (f);
}
@@ -4990,8 +4973,8 @@ static struct redisplay_interface ns_redisplay_interface =
gui_get_glyph_overhangs,
gui_fix_overlapping_area,
ns_draw_fringe_bitmap,
- 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
- 0, /* destroy_fringe_bitmap */
+ ns_define_fringe_bitmap,
+ ns_destroy_fringe_bitmap,
ns_compute_glyph_string_overhangs,
ns_draw_glyph_string,
ns_define_frame_cursor,
@@ -5177,6 +5160,8 @@ ns_term_init (Lisp_Object display_name)
terminal->name = xlispstrdup (display_name);
+ gui_init_fringe (terminal->rif);
+
unblock_input ();
if (!inhibit_x_resources)
- branch scratch/ns/refactor created (now 0132e0a), Alan Third, 2021/07/24
- scratch/ns/refactor db055f9 01/12: Simplify macOS drawing code, Alan Third, 2021/07/24
- scratch/ns/refactor 361d043 11/12: Convert fringe bitmaps to vectors on NS port,
Alan Third <=
- scratch/ns/refactor 7b255dc 07/12: Fix some macOS problems, Alan Third, 2021/07/24
- scratch/ns/refactor dee3be7 08/12: * src/nsterm.m (ns_set_frame_alpha): Enable alpha on GNUstep., Alan Third, 2021/07/24
- scratch/ns/refactor d9fd86c2 02/12: Tidy up NS port OS window handling, Alan Third, 2021/07/24
- scratch/ns/refactor 94b4470 06/12: Move parent frame setting code into EmacsWindow, Alan Third, 2021/07/24
- scratch/ns/refactor 8d0fb51 04/12: Fix macOS live resize drawing, Alan Third, 2021/07/24
- scratch/ns/refactor df9a612 03/12: Change NS port resize detection, Alan Third, 2021/07/24
- scratch/ns/refactor 0132e0a 12/12: Fix image crash on macOS (bug#49688), Alan Third, 2021/07/24
- scratch/ns/refactor 93b18cc 09/12: Simplify NS sizing and positioning code, Alan Third, 2021/07/24
- scratch/ns/refactor 6f4f66d 05/12: Move NS port toolbar handling to the window, Alan Third, 2021/07/24
- scratch/ns/refactor 8d34954 10/12: Fix NS inset rectangle corners, Alan Third, 2021/07/24