quartz: expose only what was invalidated on 10.14+
gdk_quartz_set_use_cocoa_invalidation() and GDK_QUARTZ_COCOA_INVALIDATION switch back to the old behaviour. Taken from Ardour's YTK: - 9efd521e, fe6a635c, 4fbdf0d6 (Paul Davis) - aea9f1b6cf (Paul Davis) and 2d3eb0c6a7 (John Ralls), both GTK 3
This commit is contained in:
parent
e3ed9e0c2a
commit
62a17ef3cb
4 changed files with 125 additions and 16 deletions
|
|
@ -618,6 +618,45 @@
|
|||
[super viewWillDraw];
|
||||
}
|
||||
|
||||
/* What AppKit invalidates goes into GDK's bookkeeping too, so that
|
||||
* drawRect: knows all of it (see _gdk_quartz_use_gdk_invalidation()) */
|
||||
-(void)noteNeedsDisplayInRect: (NSRect)rect
|
||||
{
|
||||
GdkWindowImplQuartz *impl;
|
||||
GdkRectangle gdk_rect;
|
||||
NSRect bounds = [self bounds];
|
||||
|
||||
if (!gdk_window || GDK_WINDOW_DESTROYED (gdk_window) ||
|
||||
!_gdk_quartz_use_gdk_invalidation ())
|
||||
return;
|
||||
|
||||
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (gdk_window)->impl);
|
||||
rect = NSIntersectionRect (rect, bounds);
|
||||
if (NSIsEmptyRect (rect))
|
||||
return;
|
||||
|
||||
gdk_rect.x = floor (rect.origin.x);
|
||||
gdk_rect.y = floor (rect.origin.y);
|
||||
gdk_rect.width = ceil (rect.origin.x + rect.size.width) - gdk_rect.x;
|
||||
gdk_rect.height = ceil (rect.origin.y + rect.size.height) - gdk_rect.y;
|
||||
if (!impl->needs_display_region)
|
||||
impl->needs_display_region = gdk_region_new ();
|
||||
gdk_region_union_with_rect (impl->needs_display_region, &gdk_rect);
|
||||
}
|
||||
|
||||
-(void)setNeedsDisplayInRect: (NSRect)rect
|
||||
{
|
||||
[self noteNeedsDisplayInRect: rect];
|
||||
[super setNeedsDisplayInRect: rect];
|
||||
}
|
||||
|
||||
-(void)setNeedsDisplay: (BOOL)flag
|
||||
{
|
||||
if (flag)
|
||||
[self noteNeedsDisplayInRect: [self bounds]];
|
||||
[super setNeedsDisplay: flag];
|
||||
}
|
||||
|
||||
-(void)drawRect: (NSRect)rect
|
||||
{
|
||||
GdkRectangle gdk_rect;
|
||||
|
|
@ -626,7 +665,7 @@
|
|||
const NSRect *drawn_rects;
|
||||
NSInteger count;
|
||||
int i;
|
||||
GdkRegion *region;
|
||||
GdkRegion *region, *needs;
|
||||
|
||||
if (GDK_WINDOW_DESTROYED (gdk_window))
|
||||
return;
|
||||
|
|
@ -662,25 +701,49 @@
|
|||
return;
|
||||
}
|
||||
|
||||
/* Clear our own bookkeeping of regions that need display */
|
||||
if (impl->needs_display_region)
|
||||
/* Our own bookkeeping of what needs display; taken here, as an
|
||||
* expose may invalidate again */
|
||||
needs = impl->needs_display_region;
|
||||
impl->needs_display_region = NULL;
|
||||
|
||||
if (needs && _gdk_quartz_use_gdk_invalidation () &&
|
||||
!NSContainsRect (rect, [self bounds]))
|
||||
{
|
||||
gdk_region_destroy (impl->needs_display_region);
|
||||
impl->needs_display_region = NULL;
|
||||
/* Layer-backed views (10.14 and newer) merge the invalidated
|
||||
* rects into one, or give the whole view: the windows of two
|
||||
* small meters in opposite corners would expose all between.
|
||||
* What GDK and AppKit invalidated is known here exactly (from
|
||||
* Ardour's YTK). */
|
||||
GdkRegion *drawing;
|
||||
|
||||
gdk_rect.x = rect.origin.x;
|
||||
gdk_rect.y = rect.origin.y;
|
||||
gdk_rect.width = rect.size.width;
|
||||
gdk_rect.height = rect.size.height;
|
||||
drawing = gdk_region_rectangle (&gdk_rect);
|
||||
region = needs;
|
||||
needs = NULL;
|
||||
gdk_region_intersect (region, drawing);
|
||||
gdk_region_destroy (drawing);
|
||||
}
|
||||
else
|
||||
{
|
||||
[self getRectsBeingDrawn: &drawn_rects count: &count];
|
||||
region = gdk_region_new ();
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
gdk_rect.x = drawn_rects[i].origin.x;
|
||||
gdk_rect.y = drawn_rects[i].origin.y;
|
||||
gdk_rect.width = drawn_rects[i].size.width;
|
||||
gdk_rect.height = drawn_rects[i].size.height;
|
||||
|
||||
gdk_region_union_with_rect (region, &gdk_rect);
|
||||
}
|
||||
}
|
||||
|
||||
[self getRectsBeingDrawn: &drawn_rects count: &count];
|
||||
region = gdk_region_new ();
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
gdk_rect.x = drawn_rects[i].origin.x;
|
||||
gdk_rect.y = drawn_rects[i].origin.y;
|
||||
gdk_rect.width = drawn_rects[i].size.width;
|
||||
gdk_rect.height = drawn_rects[i].size.height;
|
||||
|
||||
gdk_region_union_with_rect (region, &gdk_rect);
|
||||
}
|
||||
if (needs)
|
||||
gdk_region_destroy (needs);
|
||||
|
||||
impl->in_paint_rect_count++;
|
||||
_gdk_window_process_updates_recurse (gdk_window, region);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
#include "gdktypes.h"
|
||||
#include "gdkprivate.h"
|
||||
#include "gdkquartz.h"
|
||||
#include "gdkprivate-quartz.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
GdkDisplay *_gdk_display = NULL;
|
||||
GdkScreen *_gdk_screen = NULL;
|
||||
|
|
@ -57,3 +59,43 @@ gdk_quartz_osx_version (void)
|
|||
else
|
||||
return minor;
|
||||
}
|
||||
|
||||
/* -1: not set, GDK_QUARTZ_COCOA_INVALIDATION or the version decide */
|
||||
static gint use_cocoa_invalidation = -1;
|
||||
|
||||
/**
|
||||
* gdk_quartz_set_use_cocoa_invalidation:
|
||||
* @use: %TRUE to expose what AppKit says is being drawn
|
||||
*
|
||||
* From macOS 10.14 GDK exposes exactly what it and AppKit invalidated,
|
||||
* not the merged rectangles of the layer-backed views; %TRUE goes back
|
||||
* to those (as in Ardour's YTK). The environment variable
|
||||
* GDK_QUARTZ_COCOA_INVALIDATION=1 does the same.
|
||||
*/
|
||||
void
|
||||
gdk_quartz_set_use_cocoa_invalidation (gboolean use)
|
||||
{
|
||||
use_cocoa_invalidation = use != FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gdk_quartz_get_use_cocoa_invalidation (void)
|
||||
{
|
||||
return !_gdk_quartz_use_gdk_invalidation ();
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gdk_quartz_use_gdk_invalidation (void)
|
||||
{
|
||||
if (use_cocoa_invalidation < 0)
|
||||
{
|
||||
const gchar *env = g_getenv ("GDK_QUARTZ_COCOA_INVALIDATION");
|
||||
|
||||
if (env && *env)
|
||||
use_cocoa_invalidation = atoi (env) != 0;
|
||||
else
|
||||
use_cocoa_invalidation = gdk_quartz_osx_version () < GDK_OSX_MOJAVE;
|
||||
}
|
||||
|
||||
return !use_cocoa_invalidation;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,4 +219,6 @@ gboolean _gdk_quartz_window_queue_antiexpose (GdkWindow *window,
|
|||
/* Pixmap */
|
||||
CGImageRef _gdk_pixmap_get_cgimage (GdkPixmap *pixmap);
|
||||
|
||||
gboolean _gdk_quartz_use_gdk_invalidation (void);
|
||||
|
||||
#endif /* __GDK_PRIVATE_QUARTZ_H__ */
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ NSImage *gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf
|
|||
id gdk_quartz_drag_context_get_dragging_info_libgtk_only (GdkDragContext *context);
|
||||
NSEvent *gdk_quartz_event_get_nsevent (GdkEvent *event);
|
||||
GdkOSXVersion gdk_quartz_osx_version (void);
|
||||
void gdk_quartz_set_use_cocoa_invalidation (gboolean use);
|
||||
gboolean gdk_quartz_get_use_cocoa_invalidation (void);
|
||||
|
||||
GdkAtom gdk_quartz_pasteboard_type_to_atom_libgtk_only (NSString *type);
|
||||
NSString *gdk_quartz_target_to_pasteboard_type_libgtk_only (const gchar *target);
|
||||
|
|
|
|||
Loading…
Reference in a new issue