macos: use display id when creating CVDisplayLink

Currently we're using a display link that is for all active displays which
is just the display server trying to find some timings that try to overlap
as many as possible.

That was fine for a prototype, but we really need to do better for
situations with mixed frame rate (such as 60hz and 120hz promotion
displays). Additionally, the 144hz external monitor I have will never
reach 144hz using the current design.

This is just the first step in changing this, but the goal is to have
one of these attached to each GdkMacosMonitor which we can then use to
thaw surfaces specific to that monitor.
This commit is contained in:
Christian Hergert 2022-02-25 13:09:31 -08:00
parent 92a7c7cdc3
commit 4404c43cd3
3 changed files with 16 additions and 16 deletions

View File

@ -147,6 +147,7 @@ gdk_display_link_source_frame_cb (CVDisplayLinkRef display_link,
/**
* gdk_display_link_source_new:
* @display_id: the identifier of the monitor
*
* Creates a new `GSource` that will activate the dispatch function upon
* notification from a CVDisplayLink that a new frame should be drawn.
@ -159,7 +160,7 @@ gdk_display_link_source_frame_cb (CVDisplayLinkRef display_link,
* Returns: (transfer full): A newly created `GSource`
*/
GSource *
gdk_display_link_source_new (void)
gdk_display_link_source_new (CGDirectDisplayID display_id)
{
GdkDisplayLinkSource *impl;
GSource *source;
@ -168,15 +169,13 @@ gdk_display_link_source_new (void)
source = g_source_new (&gdk_display_link_source_funcs, sizeof *impl);
impl = (GdkDisplayLinkSource *)source;
impl->display_id = display_id;
/*
* Create our link based on currently connected displays.
* If there are multiple displays, this will be something that tries
* to work for all of them. In the future, we may want to explore multiple
* links based on the connected displays.
/* Create DisplayLink for timing information for the display in
* question so that we can produce graphics for that display at whatever
* rate it can provide.
*/
ret = CVDisplayLinkCreateWithActiveCGDisplays (&impl->display_link);
if (ret != kCVReturnSuccess)
if (CVDisplayLinkCreateWithCGDisplay (display_id, &impl->display_link) != kCVReturnSuccess)
{
g_warning ("Failed to initialize CVDisplayLink!");
return source;

View File

@ -30,17 +30,18 @@ G_BEGIN_DECLS
typedef struct
{
GSource source;
GSource source;
CVDisplayLinkRef display_link;
gint64 refresh_interval;
guint refresh_rate;
CGDirectDisplayID display_id;
CVDisplayLinkRef display_link;
gint64 refresh_interval;
guint refresh_rate;
volatile gint64 presentation_time;
volatile guint needs_dispatch;
volatile gint64 presentation_time;
volatile guint needs_dispatch;
} GdkDisplayLinkSource;
GSource *gdk_display_link_source_new (void);
GSource *gdk_display_link_source_new (CGDirectDisplayID display_id);
void gdk_display_link_source_pause (GdkDisplayLinkSource *source);
void gdk_display_link_source_unpause (GdkDisplayLinkSource *source);

View File

@ -273,7 +273,7 @@ gdk_macos_display_frame_cb (gpointer data)
static void
gdk_macos_display_load_display_link (GdkMacosDisplay *self)
{
self->frame_source = gdk_display_link_source_new ();
self->frame_source = gdk_display_link_source_new (CGMainDisplayID ());
g_source_set_callback (self->frame_source,
gdk_macos_display_frame_cb,
self,