From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: mituharu@math.s.chiba-u.ac.jp Newsgroups: gmane.emacs.bugs Subject: bug#35468: [PATCH] Refactor draw_glyph_string on X and w32 Date: Wed, 1 May 2019 09:14:50 +0900 Message-ID: References: <877ebeor2d.fsf@gmail.com> <83tveit5ph.fsf@gnu.org> <87pnp5oqu1.fsf@gmail.com> <877ebcogg4.fsf@gmail.com> <83sgu0rsue.fsf@gnu.org> <8736lznzjf.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain;charset=iso-2022-jp Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="39408"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: SquirrelMail/1.4.22-5.el6 Cc: 35468@debbugs.gnu.org To: "Alex Gramiak" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed May 01 02:16:25 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLcvB-000A3T-Hk for geb-bug-gnu-emacs@m.gmane.org; Wed, 01 May 2019 02:16:25 +0200 Original-Received: from localhost ([127.0.0.1]:56120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLcvA-0003dJ-I0 for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Apr 2019 20:16:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:45251) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLcty-0002Ol-Q6 for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2019 20:15:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLctr-0005b8-5P for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2019 20:15:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57512) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hLctq-0005ZZ-8d for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2019 20:15:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hLctp-0000Q7-VZ for bug-gnu-emacs@gnu.org; Tue, 30 Apr 2019 20:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: mituharu@math.s.chiba-u.ac.jp Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 May 2019 00:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35468 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35468-submit@debbugs.gnu.org id=B35468.15566696951590 (code B ref 35468); Wed, 01 May 2019 00:15:01 +0000 Original-Received: (at 35468) by debbugs.gnu.org; 1 May 2019 00:14:55 +0000 Original-Received: from localhost ([127.0.0.1]:42823 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLcti-0000PZ-CI for submit@debbugs.gnu.org; Tue, 30 Apr 2019 20:14:55 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:64464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLctf-0000PO-JW for 35468@debbugs.gnu.org; Tue, 30 Apr 2019 20:14:52 -0400 Original-Received: from weber.math.s.chiba-u.ac.jp (weber [192.168.32.4]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id 5C3ACF08EE; Wed, 1 May 2019 09:14:50 +0900 (JST) (envelope-from mituharu@math.s.chiba-u.ac.jp) Original-Received: from 180.3.209.86 (SquirrelMail authenticated user mituharu) by weber.math.s.chiba-u.ac.jp with HTTP; Wed, 1 May 2019 09:14:50 +0900 In-Reply-To: <8736lznzjf.fsf@gmail.com> X-Priority: 3 (Normal) Importance: Normal X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:158558 Archived-At: > 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