cogl/onscreen: Let swap buffer caller create frame info

We currently have mutter set a global frame counter on the frame info in
the native backend, but in order to do this from clutter, change the
frame info construction from being implicitly done so when swapping
buffers to having the caller create the frame info and passing that to
the swap buffers call.

While this commit doesn't introduce any other changes than the API, the
intention is later to have the caller be able to pass it's own state
(e.g. the global frame count) along with the frame info.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
Jonas Ådahl 2020-05-22 21:52:29 +02:00
parent 31a3b1b4c5
commit 2a6e8bda8d
12 changed files with 72 additions and 43 deletions

View File

@ -369,6 +369,7 @@ swap_framebuffer (ClutterStageWindow *stage_window,
{ {
CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer); CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
int *damage, n_rects, i; int *damage, n_rects, i;
CoglFrameInfo *frame_info;
n_rects = cairo_region_num_rectangles (swap_region); n_rects = cairo_region_num_rectangles (swap_region);
damage = g_newa (int, n_rects * 4); damage = g_newa (int, n_rects * 4);
@ -383,6 +384,8 @@ swap_framebuffer (ClutterStageWindow *stage_window,
damage[i * 4 + 3] = rect.height; damage[i * 4 + 3] = rect.height;
} }
frame_info = cogl_frame_info_new ();
/* push on the screen */ /* push on the screen */
if (n_rects > 0 && !swap_with_damage) if (n_rects > 0 && !swap_with_damage)
{ {
@ -391,7 +394,8 @@ swap_framebuffer (ClutterStageWindow *stage_window,
onscreen); onscreen);
cogl_onscreen_swap_region (onscreen, cogl_onscreen_swap_region (onscreen,
damage, n_rects); damage, n_rects,
frame_info);
return FALSE; return FALSE;
} }
@ -401,7 +405,8 @@ swap_framebuffer (ClutterStageWindow *stage_window,
onscreen); onscreen);
cogl_onscreen_swap_buffers_with_damage (onscreen, cogl_onscreen_swap_buffers_with_damage (onscreen,
damage, n_rects); damage, n_rects,
frame_info);
return TRUE; return TRUE;
} }
@ -747,11 +752,15 @@ clutter_stage_cogl_scanout_view (ClutterStageCogl *stage_cogl,
{ {
CoglFramebuffer *framebuffer = clutter_stage_view_get_framebuffer (view); CoglFramebuffer *framebuffer = clutter_stage_view_get_framebuffer (view);
CoglOnscreen *onscreen; CoglOnscreen *onscreen;
CoglFrameInfo *frame_info;
g_return_if_fail (cogl_is_onscreen (framebuffer)); g_return_if_fail (cogl_is_onscreen (framebuffer));
onscreen = COGL_ONSCREEN (framebuffer); onscreen = COGL_ONSCREEN (framebuffer);
cogl_onscreen_direct_scanout (onscreen, scanout);
frame_info = cogl_frame_info_new ();
cogl_onscreen_direct_scanout (onscreen, scanout, frame_info);
} }
static void static void

View File

@ -45,6 +45,7 @@ struct _CoglFrameInfo
int64_t global_frame_counter; int64_t global_frame_counter;
}; };
CoglFrameInfo *_cogl_frame_info_new (void); COGL_EXPORT
CoglFrameInfo *cogl_frame_info_new (void);
#endif /* __COGL_FRAME_INFO_PRIVATE_H */ #endif /* __COGL_FRAME_INFO_PRIVATE_H */

View File

@ -39,7 +39,7 @@ COGL_OBJECT_DEFINE (FrameInfo, frame_info);
COGL_GTYPE_DEFINE_CLASS (FrameInfo, frame_info); COGL_GTYPE_DEFINE_CLASS (FrameInfo, frame_info);
CoglFrameInfo * CoglFrameInfo *
_cogl_frame_info_new (void) cogl_frame_info_new (void)
{ {
CoglFrameInfo *info; CoglFrameInfo *info;

View File

@ -45,6 +45,11 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* CoglFrameInfo:
*
* Frame information.
*/
typedef struct _CoglFrameInfo CoglFrameInfo; typedef struct _CoglFrameInfo CoglFrameInfo;
#define COGL_FRAME_INFO(X) ((CoglFrameInfo *)(X)) #define COGL_FRAME_INFO(X) ((CoglFrameInfo *)(X))

View File

@ -293,15 +293,14 @@ _cogl_onscreen_queue_event (CoglOnscreen *onscreen,
void void
cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
CoglFrameInfo *info;
g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN); g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
info = _cogl_frame_info_new ();
info->frame_counter = onscreen->frame_counter; info->frame_counter = onscreen->frame_counter;
g_queue_push_tail (&onscreen->pending_frame_infos, info); g_queue_push_tail (&onscreen->pending_frame_infos, info);
@ -310,7 +309,8 @@ cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
winsys = _cogl_framebuffer_get_winsys (framebuffer); winsys = _cogl_framebuffer_get_winsys (framebuffer);
winsys->onscreen_swap_buffers_with_damage (onscreen, winsys->onscreen_swap_buffers_with_damage (onscreen,
rectangles, n_rectangles); rectangles, n_rectangles,
info);
cogl_framebuffer_discard_buffers (framebuffer, cogl_framebuffer_discard_buffers (framebuffer,
COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_COLOR |
COGL_BUFFER_BIT_DEPTH | COGL_BUFFER_BIT_DEPTH |
@ -334,23 +334,23 @@ cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
} }
void void
cogl_onscreen_swap_buffers (CoglOnscreen *onscreen) cogl_onscreen_swap_buffers (CoglOnscreen *onscreen,
CoglFrameInfo *info)
{ {
cogl_onscreen_swap_buffers_with_damage (onscreen, NULL, 0); cogl_onscreen_swap_buffers_with_damage (onscreen, NULL, 0, info);
} }
void void
cogl_onscreen_swap_region (CoglOnscreen *onscreen, cogl_onscreen_swap_region (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
CoglFrameInfo *info;
g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN); g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
info = _cogl_frame_info_new ();
info->frame_counter = onscreen->frame_counter; info->frame_counter = onscreen->frame_counter;
g_queue_push_tail (&onscreen->pending_frame_infos, info); g_queue_push_tail (&onscreen->pending_frame_infos, info);
@ -365,7 +365,8 @@ cogl_onscreen_swap_region (CoglOnscreen *onscreen,
winsys->onscreen_swap_region (COGL_ONSCREEN (framebuffer), winsys->onscreen_swap_region (COGL_ONSCREEN (framebuffer),
rectangles, rectangles,
n_rectangles); n_rectangles,
info);
cogl_framebuffer_discard_buffers (framebuffer, cogl_framebuffer_discard_buffers (framebuffer,
COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_COLOR |
@ -406,22 +407,21 @@ cogl_onscreen_get_buffer_age (CoglOnscreen *onscreen)
} }
void void
cogl_onscreen_direct_scanout (CoglOnscreen *onscreen, cogl_onscreen_direct_scanout (CoglOnscreen *onscreen,
CoglScanout *scanout) CoglScanout *scanout,
CoglFrameInfo *info)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
const CoglWinsysVtable *winsys; const CoglWinsysVtable *winsys;
CoglFrameInfo *info;
g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN); g_return_if_fail (framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN);
g_return_if_fail (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT)); g_return_if_fail (_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_SYNC_AND_COMPLETE_EVENT));
info = _cogl_frame_info_new ();
info->frame_counter = onscreen->frame_counter; info->frame_counter = onscreen->frame_counter;
g_queue_push_tail (&onscreen->pending_frame_infos, info); g_queue_push_tail (&onscreen->pending_frame_infos, info);
winsys = _cogl_framebuffer_get_winsys (framebuffer); winsys = _cogl_framebuffer_get_winsys (framebuffer);
winsys->onscreen_direct_scanout (onscreen, scanout); winsys->onscreen_direct_scanout (onscreen, scanout, info);
onscreen->frame_counter++; onscreen->frame_counter++;
} }

View File

@ -178,7 +178,8 @@ cogl_onscreen_hide (CoglOnscreen *onscreen);
* Stability: unstable * Stability: unstable
*/ */
COGL_EXPORT void COGL_EXPORT void
cogl_onscreen_swap_buffers (CoglOnscreen *onscreen); cogl_onscreen_swap_buffers (CoglOnscreen *onscreen,
CoglFrameInfo *frame_info);
/** /**
@ -284,14 +285,16 @@ cogl_onscreen_get_buffer_age (CoglOnscreen *onscreen);
COGL_EXPORT void COGL_EXPORT void
cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, cogl_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles); int n_rectangles,
CoglFrameInfo *info);
/** /**
* cogl_onscreen_direct_scanout: (skip) * cogl_onscreen_direct_scanout: (skip)
*/ */
COGL_EXPORT void COGL_EXPORT void
cogl_onscreen_direct_scanout (CoglOnscreen *onscreen, cogl_onscreen_direct_scanout (CoglOnscreen *onscreen,
CoglScanout *scanout); CoglScanout *scanout,
CoglFrameInfo *info);
/** /**
* cogl_onscreen_swap_region: * cogl_onscreen_swap_region:
@ -316,7 +319,8 @@ cogl_onscreen_direct_scanout (CoglOnscreen *onscreen,
COGL_EXPORT void COGL_EXPORT void
cogl_onscreen_swap_region (CoglOnscreen *onscreen, cogl_onscreen_swap_region (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles); int n_rectangles,
CoglFrameInfo *info);
/** /**
* CoglFrameEvent: * CoglFrameEvent:

View File

@ -77,6 +77,7 @@ cogl_headers = [
'cogl-bitmap.h', 'cogl-bitmap.h',
'cogl-color.h', 'cogl-color.h',
'cogl-context.h', 'cogl-context.h',
'cogl-frame-info.h',
'cogl-framebuffer.h', 'cogl-framebuffer.h',
'cogl-matrix.h', 'cogl-matrix.h',
'cogl-object.h', 'cogl-object.h',
@ -106,7 +107,6 @@ cogl_nonintrospected_headers = [
'cogl-indices.h', 'cogl-indices.h',
'cogl-attribute.h', 'cogl-attribute.h',
'cogl-primitive.h', 'cogl-primitive.h',
'cogl-frame-info.h',
'cogl-output.h', 'cogl-output.h',
'cogl-matrix-stack.h', 'cogl-matrix-stack.h',
'cogl-poll.h', 'cogl-poll.h',

View File

@ -726,7 +726,8 @@ _cogl_winsys_onscreen_get_buffer_age (CoglOnscreen *onscreen)
static void static void
_cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen, _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
const int *user_rectangles, const int *user_rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRenderer *renderer = context->display->renderer; CoglRenderer *renderer = context->display->renderer;
@ -765,7 +766,8 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
static void static void
_cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, _cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *context = COGL_FRAMEBUFFER (onscreen)->context;
CoglRenderer *renderer = context->display->renderer; CoglRenderer *renderer = context->display->renderer;

View File

@ -1673,7 +1673,8 @@ set_frame_info_output (CoglOnscreen *onscreen,
static void static void
_cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen, _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
const int *user_rectangles, const int *user_rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = framebuffer->context; CoglContext *context = framebuffer->context;
@ -1879,7 +1880,8 @@ _cogl_winsys_onscreen_swap_region (CoglOnscreen *onscreen,
static void static void
_cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen, _cogl_winsys_onscreen_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *info)
{ {
CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
CoglContext *context = framebuffer->context; CoglContext *context = framebuffer->context;

View File

@ -116,11 +116,13 @@ typedef struct _CoglWinsysVtable
void void
(*onscreen_swap_buffers_with_damage) (CoglOnscreen *onscreen, (*onscreen_swap_buffers_with_damage) (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles); int n_rectangles,
CoglFrameInfo *info);
void void
(*onscreen_direct_scanout) (CoglOnscreen *onscreen, (*onscreen_direct_scanout) (CoglOnscreen *onscreen,
CoglScanout *scanout); CoglScanout *scanout,
CoglFrameInfo *info);
void void
(*onscreen_set_visibility) (CoglOnscreen *onscreen, (*onscreen_set_visibility) (CoglOnscreen *onscreen,
@ -134,7 +136,8 @@ typedef struct _CoglWinsysVtable
void void
(*onscreen_swap_region) (CoglOnscreen *onscreen, (*onscreen_swap_region) (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles); int n_rectangles,
CoglFrameInfo *info);
void void
(*onscreen_set_resizable) (CoglOnscreen *onscreen, gboolean resizable); (*onscreen_set_resizable) (CoglOnscreen *onscreen, gboolean resizable);

View File

@ -2067,9 +2067,10 @@ ensure_crtc_modes (CoglOnscreen *onscreen,
} }
static void static void
meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen, meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
const int *rectangles, const int *rectangles,
int n_rectangles) int n_rectangles,
CoglFrameInfo *frame_info)
{ {
CoglContext *cogl_context = COGL_FRAMEBUFFER (onscreen)->context; CoglContext *cogl_context = COGL_FRAMEBUFFER (onscreen)->context;
CoglDisplay *cogl_display = cogl_context_get_display (cogl_context); CoglDisplay *cogl_display = cogl_context_get_display (cogl_context);
@ -2084,7 +2085,6 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
CoglOnscreenEGL *onscreen_egl = onscreen->winsys; CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
MetaOnscreenNative *onscreen_native = onscreen_egl->platform; MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
MetaGpuKms *render_gpu = onscreen_native->render_gpu; MetaGpuKms *render_gpu = onscreen_native->render_gpu;
CoglFrameInfo *frame_info;
gboolean egl_context_changed = FALSE; gboolean egl_context_changed = FALSE;
MetaKmsUpdate *kms_update; MetaKmsUpdate *kms_update;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
@ -2112,7 +2112,8 @@ meta_onscreen_native_swap_buffers_with_damage (CoglOnscreen *onscreen,
parent_vtable->onscreen_swap_buffers_with_damage (onscreen, parent_vtable->onscreen_swap_buffers_with_damage (onscreen,
rectangles, rectangles,
n_rectangles); n_rectangles,
frame_info);
renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native, renderer_gpu_data = meta_renderer_native_get_gpu_data (renderer_native,
render_gpu); render_gpu);
@ -2296,8 +2297,9 @@ meta_onscreen_native_is_buffer_scanout_compatible (CoglOnscreen *onscreen,
} }
static void static void
meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen, meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen,
CoglScanout *scanout) CoglScanout *scanout,
CoglFrameInfo *frame_info)
{ {
CoglOnscreenEGL *onscreen_egl = onscreen->winsys; CoglOnscreenEGL *onscreen_egl = onscreen->winsys;
MetaOnscreenNative *onscreen_native = onscreen_egl->platform; MetaOnscreenNative *onscreen_native = onscreen_egl->platform;
@ -2311,7 +2313,6 @@ meta_onscreen_native_direct_scanout (CoglOnscreen *onscreen,
MetaBackend *backend = meta_renderer_get_backend (renderer); MetaBackend *backend = meta_renderer_get_backend (renderer);
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend); MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
MetaKms *kms = meta_backend_native_get_kms (backend_native); MetaKms *kms = meta_backend_native_get_kms (backend_native);
CoglFrameInfo *frame_info;
MetaKmsUpdate *kms_update; MetaKmsUpdate *kms_update;
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;

View File

@ -168,6 +168,7 @@ meta_stage_x11_nested_finish_frame (ClutterStageWindow *stage_window)
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglFramebuffer *onscreen = COGL_FRAMEBUFFER (stage_x11->onscreen); CoglFramebuffer *onscreen = COGL_FRAMEBUFFER (stage_x11->onscreen);
GList *l; GList *l;
CoglFrameInfo *frame_info;
if (!stage_nested->pipeline) if (!stage_nested->pipeline)
stage_nested->pipeline = cogl_pipeline_new (clutter_backend->cogl_context); stage_nested->pipeline = cogl_pipeline_new (clutter_backend->cogl_context);
@ -193,7 +194,8 @@ meta_stage_x11_nested_finish_frame (ClutterStageWindow *stage_window)
draw_view (stage_nested, renderer_view, texture); draw_view (stage_nested, renderer_view, texture);
} }
cogl_onscreen_swap_buffers (stage_x11->onscreen); frame_info = cogl_frame_info_new ();
cogl_onscreen_swap_buffers (stage_x11->onscreen, frame_info);
} }
static void static void