Subject: bug#51411: NS port cleanups

From: Alan Third <[email-masked]>
Date: Wed, 27 Oct 2021 18:20:34 +0100

On Tue, Oct 26, 2021 at 08:50:52PM +0800, Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote:
> Alan Third <[email-masked]> writes:
> 
> > Is this the code in ns_draw_glyph_string?
> 
> Yes, it is.

That function is a real mess of calls to ns_focus and ns_unfocus. I
think there's no good reason for them to be called as often as they
are, and some related functions (ns_dumpglyphs_stretch) don't need to
call them themselves either.

I think we need to have a rethink of how clipping is handled here. We
don't need to use ns_focus to clip and we repeatedly call ns_focus on
the same rectangle. For a lot of those calls we could replace them
with a single clipping rectangle and adjust it as required for
overhangs or whatever.

I also think you misunderstood what I was saying about the performance
problems with calling saveGraphicsState. Calling it when not required
is frowned upon by Apple as they say it causes performance problems.
Your code is now calling it in ns_focus whether it's required or not.
Ideally we only call it when modifying the clipping rectangle, because
there are times ns_focus is called where we don't modify the clipping
rectangle and therefore we don't need to save the graphics context.

I understand what you did, but I think the better solution is for us
is to try to untangle ns_draw_glyph_string, even if that means saving
the context there directly on occasion.

If you want me to have a look at it let me know, I think I know what
needs to be done, but I probably won't get round to it as soon as you
could.
-- 
Alan Third