From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arash Esbati Newsgroups: gmane.emacs.bugs Subject: bug#73384: [PATCH] Draw coloured stipples on NS Date: Tue, 29 Oct 2024 11:31:49 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15225"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= , 73384@debbugs.gnu.org, JD Smith , Ben Simms To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 29 11:33:22 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t5jXL-0003lw-Fa for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Oct 2024 11:33:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5jX8-0006nu-Vv; Tue, 29 Oct 2024 06:33:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5jX4-0006k7-Nb for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2024 06:33:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t5jX4-0004Ki-EL for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2024 06:33:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=QDdYdjs6y/WovgHLrDlQlVhcF18xiuFSFrIUFKpws+E=; b=pkvZeOXwB+KCnK3F9CQ9VYC/S6cQwo6s6AnYrZuoBvGaIBfOKN0g9SuBd1uq4ffcwZTABTVYpahxCxQ5dps2zjYsUl9qbVqCeFwKEZvxaWEpxkAUp1+HOIhbDWs5ZeB8lUnwO74ON0P9phcRoj31DU+hqUJGfxiSf8XHyuYRDhqp4cKD2rMPApsj06sVC47cper9z29FK0Hx1Q75mowqUMINbuTekC2JXwybUAPuopf4FIQ7OC9d3Fr7daMaeJiNxhksfNFakKj5q8GHEQswVeYADxXQ3cw4cLNxGhv6ku7cx5sm5qz9aa4Q9N3P2RrxfmSXfDa1J9NTrJQj22qcdw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t5jX4-0007qj-7R for bug-gnu-emacs@gnu.org; Tue, 29 Oct 2024 06:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Arash Esbati Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Oct 2024 10:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73384 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73384-submit@debbugs.gnu.org id=B73384.173019794930160 (code B ref 73384); Tue, 29 Oct 2024 10:33:02 +0000 Original-Received: (at 73384) by debbugs.gnu.org; 29 Oct 2024 10:32:29 +0000 Original-Received: from localhost ([127.0.0.1]:56124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5jWW-0007qO-PU for submit@debbugs.gnu.org; Tue, 29 Oct 2024 06:32:29 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:57680) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5jWT-0007qD-CE for 73384@debbugs.gnu.org; Tue, 29 Oct 2024 06:32:27 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t5jWM-0004Fu-ST; Tue, 29 Oct 2024 06:32:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=QDdYdjs6y/WovgHLrDlQlVhcF18xiuFSFrIUFKpws+E=; b=P634uT4Q8+rLgpY2YVU7 IxWPml1PM4OnYy5+GMfcY1PJKFYUbXKtBPdCx+EN6KiP6dtAfmKr+R8/OXHY5BEbOPeeIh44XAIk0 5YdSyPknn2uXCPT9hnnwnSkCI7mRx39RtrB7q/2M6NEXP/Xeqo2lLnuMkjLj2P+/IAsAr2h797Rlk RFhsEWMycC/K2kYjIKtwc9AVg4GAd0ZnalWJHRkeO6Zk3al6BDBye9JKOhUQXVrFvtHx+MeK6wGtw IkYrZnUEDWM4J6YizfFUlur8f87Po/7/sQwwA3db54v2qcllMUlUyvbA6XYbKwpD/TAKEF0rWyAN4 rqMv1cXmimV3GQ==; In-Reply-To: (Arash Esbati's message of "Mon, 21 Oct 2024 21:26:52 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:294477 Archived-At: --=-=-= Content-Type: text/plain Arash Esbati writes: > I'd say it works. What do others think? Many thanks for this. Stefan, did you have a chance to look at this again? I'm attaching the patch Ben sent me off-list. Maybe you can advise how to proceed and get this installed. TIA. Best, Arash --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Use-masked-coregraphics-images-on-cocoa-NS.patch >From 1c4b8efb82bd0e35c91d98f2759217702f3a7c65 Mon Sep 17 00:00:00 2001 From: Ben Simms Date: Mon, 14 Oct 2024 19:32:53 +0100 Subject: [PATCH] Use masked coregraphics images on cocoa NS --- src/nsimage.m | 31 +++++++++++++++++++++++++++++++ src/nsterm.h | 8 ++++++++ src/nsterm.m | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/nsimage.m b/src/nsimage.m index ee72d6e0ea1..e36cbe5dc87 100644 --- a/src/nsimage.m +++ b/src/nsimage.m @@ -35,6 +35,9 @@ Updated by Christian Limpach (chris@nice.ch) #include "frame.h" #include "coding.h" +#ifdef NS_IMPL_COCOA +#include +#endif #if defined (NS_IMPL_GNUSTEP) || MAC_OS_X_VERSION_MAX_ALLOWED < 1070 # define COLORSPACE_NAME NSCalibratedRGBColorSpace @@ -289,7 +292,11 @@ + (instancetype)allocInitFromFile: (Lisp_Object)file - (void)dealloc { +#ifdef NS_IMPL_COCOA + CGImageRelease(stippleMask); +#else [stippleMask release]; +#endif [bmRep release]; [transform release]; [super dealloc]; @@ -300,7 +307,11 @@ - (id)copyWithZone:(NSZone *)zone { EmacsImage *copy = [super copyWithZone:zone]; +#ifdef NS_IMPL_COCOA + copy->stippleMask = CGImageCreateCopy(stippleMask); +#else copy->stippleMask = [stippleMask copyWithZone:zone]; +#endif /* NS_IMPL_COCOA */ copy->bmRep = [bmRep copyWithZone:zone]; copy->transform = [transform copyWithZone:zone]; @@ -509,6 +520,25 @@ - (void) setAlphaAtX: (int) x Y: (int) y to: (unsigned char) a } } +#ifdef NS_IMPL_COCOA +/* Returns a cached CGImageMask of the stipple pattern */ +- (CGImageRef)stippleMask +{ + if (stippleMask == nil) { + CGDataProviderRef provider = CGDataProviderCreateWithData (NULL, [bmRep bitmapData], + [self sizeInBytes], NULL); + CGImageRef mask = CGImageMaskCreate( + [self size].width, + [self size].height, + 8, 8, [self size].width, + provider, NULL, 0); + + CGDataProviderRelease(provider); + stippleMask = CGImageRetain(mask); + } + return stippleMask; +} +#else /* Returns a pattern color, which is cached here. */ - (NSColor *)stippleMask { @@ -516,6 +546,7 @@ - (NSColor *)stippleMask stippleMask = [[NSColor colorWithPatternImage: self] retain]; return stippleMask; } +#endif /* NS_IMPL_COCOA */ /* Find the first NSBitmapImageRep which has multiple frames. */ - (NSBitmapImageRep *)getAnimatedBitmapImageRep diff --git a/src/nsterm.h b/src/nsterm.h index 6c67653705e..2370f6ea3fb 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -671,7 +671,11 @@ #define NSTRACE_UNSILENCE() { NSBitmapImageRep *bmRep; /* used for accessing pixel data */ unsigned char *pixmapData[5]; /* shortcut to access pixel data */ +#ifdef NS_IMPL_COCOA + CGImageRef stippleMask; +#else NSColor *stippleMask; +#endif // NS_IMPL_COCOA @public NSAffineTransform *transform; BOOL smoothing; @@ -688,7 +692,11 @@ #define NSTRACE_UNSILENCE() green: (unsigned char)g blue: (unsigned char)b alpha:(unsigned char)a; - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a; +#ifdef NS_IMPL_COCOA +- (CGImageRef)stippleMask; +#else - (NSColor *)stippleMask; +#endif // NS_IMPL_COCOA - (Lisp_Object)getMetadata; - (BOOL)setFrame: (unsigned int) index; - (void)setTransform: (double[3][3]) m; diff --git a/src/nsterm.m b/src/nsterm.m index f68a22d9fbc..a617669cb4d 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -3823,8 +3823,31 @@ Function modeled after x_draw_glyph_string_box (). if (s->stippled_p) { struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (s->f); +#ifdef NS_IMPL_COCOA + [[NSColor colorWithUnsignedLong:face->background] set]; + r = NSMakeRect (s->x, s->y + box_line_width, + s->background_width, + s->height - 2 * box_line_width); + NSRectFill (r); + s->background_filled_p = 1; + CGImageRef mask = [dpyinfo->bitmaps[face->stipple - 1].img stippleMask]; + CGRect bounds = CGRectMake (s->x, s->y + box_line_width, + s->background_width, + s->height - 2 * box_line_width); + NSGraphicsContext *ctx = [NSGraphicsContext currentContext]; + [ctx saveGraphicsState]; + CGContextRef context = [ctx CGContext]; + CGContextClipToRect (context, bounds); + CGContextScaleCTM (context, 1, -1); + [[NSColor colorWithUnsignedLong:face->foreground] set]; + CGRect imageSize = CGRectMake (0, 0, CGImageGetWidth (mask), CGImageGetHeight (mask)); + CGContextDrawTiledImage (context, imageSize, mask); + [[NSGraphicsContext currentContext] restoreGraphicsState]; +#else [[dpyinfo->bitmaps[face->stipple-1].img stippleMask] set]; goto fill; +#endif /* NS_IMPL_COCOA */ + } else if (FONT_HEIGHT (s->font) < s->height - 2 * box_line_width /* When xdisp.c ignores FONT_HEIGHT, we cannot trust font @@ -3847,7 +3870,9 @@ Function modeled after x_draw_glyph_string_box (). else [FRAME_CURSOR_COLOR (s->f) set]; +#ifndef NS_IMPL_COCOA fill: +#endif /* !NS_IMPL_COCOA */ r = NSMakeRect (s->x, s->y + box_line_width, s->background_width, s->height - 2 * box_line_width); @@ -4171,8 +4196,26 @@ Function modeled after x_draw_glyph_string_box (). dpyinfo = FRAME_DISPLAY_INFO (s->f); if (s->hl == DRAW_CURSOR) [FRAME_CURSOR_COLOR (s->f) set]; - else if (s->stippled_p) - [[dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask] set]; + else if (s->stippled_p) { +#ifdef NS_IMPL_COCOA + [[NSColor colorWithUnsignedLong:s->face->background] set]; + NSRectFill (NSMakeRect (x, s->y, background_width, s->height)); + CGImageRef mask = [dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask]; + CGRect bounds = CGRectMake (s->x, s->y, s->background_width, s->height); + NSGraphicsContext *ctx = [NSGraphicsContext currentContext]; + [ctx saveGraphicsState]; + CGContextRef context = [ctx CGContext]; + CGContextClipToRect(context, bounds); + CGContextScaleCTM (context, 1, -1); + [[NSColor colorWithUnsignedLong:s->face->foreground] set]; + CGRect imageSize = CGRectMake (0, 0, CGImageGetWidth (mask), + CGImageGetHeight (mask)); + CGContextDrawTiledImage (context, imageSize, mask); + [[NSGraphicsContext currentContext] restoreGraphicsState]; +#else + [[dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask] set]; +#endif /* NS_IMPL_COCOA */ + } else [[NSColor colorWithUnsignedLong: s->face->background] set]; -- 2.46.0 --=-=-=--