Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Improve presentation-time API #1919

Merged
merged 4 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions include/wlr/types/wlr_presentation_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#include <time.h>
#include <wayland-server-core.h>

struct wlr_output;
struct wlr_output_event_present;

struct wlr_presentation {
struct wl_global *global;
struct wl_list resources; // wl_resource_get_link
Expand All @@ -28,20 +31,31 @@ struct wlr_presentation {
};

struct wlr_presentation_feedback {
struct wl_resource *resource;
struct wlr_presentation *presentation;
struct wlr_surface *surface;
struct wlr_surface *surface; // NULL if the surface has been destroyed
struct wl_list link; // wlr_presentation::feedbacks

struct wl_list resources; // wl_resource_get_link

// The surface contents were committed.
bool committed;
// The surface contents were sampled by the compositor and are to be
// presented on the next flip. Can become true only after committed becomes
// true.
bool sampled;
bool presented;

// Only when the wlr_presentation_surface_sampled_on_output helper has been
// called
struct wlr_output *output;
bool output_committed;
uint32_t output_commit_seq;

struct wl_listener surface_commit;
struct wl_listener surface_destroy;
struct wl_listener output_commit;
struct wl_listener output_present;
struct wl_listener output_destroy;
};

struct wlr_presentation_event {
Expand All @@ -58,10 +72,43 @@ struct wlr_backend;
struct wlr_presentation *wlr_presentation_create(struct wl_display *display,
struct wlr_backend *backend);
void wlr_presentation_destroy(struct wlr_presentation *presentation);
void wlr_presentation_send_surface_presented(
struct wlr_presentation *presentation, struct wlr_surface *surface,
struct wlr_presentation_event *event);
void wlr_presentation_surface_sampled(
/**
* Mark the current surface's buffer as sampled.
*
* The compositor must call this function when it uses the surface's current
* contents (e.g. when rendering the surface's current texture, when
* referencing its current buffer, or when directly scanning out its current
* buffer). A wlr_presentation_feedback is returned. The compositor should call
* wlr_presentation_feedback_send_presented if this content has been displayed,
* then wlr_presentation_feedback_destroy.
*
* NULL is returned if the client hasn't requested presentation feedback for
* this surface.
*/
struct wlr_presentation_feedback *wlr_presentation_surface_sampled(
struct wlr_presentation *presentation, struct wlr_surface *surface);
void wlr_presentation_feedback_send_presented(
struct wlr_presentation_feedback *feedback,
struct wlr_presentation_event *event);
void wlr_presentation_feedback_destroy(
struct wlr_presentation_feedback *feedback);

/**
* Fill a wlr_presentation_event from a wlr_output_event_present.
*/
void wlr_presentation_event_from_output(struct wlr_presentation_event *event,
const struct wlr_output_event_present *output_event);

/**
* Mark the current surface's buffer as sampled on the given output.
*
* Instead of calling wlr_presentation_surface_sampled and managing the
* wlr_presentation_feedback itself, the compositor can call this function
* before a wlr_output_commit call to indicate that the surface's current
* contents will be displayed on the output.
*/
void wlr_presentation_surface_sampled_on_output(
struct wlr_presentation *presentation, struct wlr_surface *surface,
struct wlr_output *output);

#endif
5 changes: 3 additions & 2 deletions types/wlr_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,14 @@ bool wlr_output_commit(struct wlr_output *output) {
wlr_surface_send_frame_done(cursor->surface, &now);
}

output->commit_seq++;

wlr_signal_emit_safe(&output->events.commit, output);

output->frame_pending = true;
output->needs_frame = false;
output_state_clear(&output->pending);
pixman_region32_clear(&output->damage);
output->commit_seq++;
return true;
}

Expand Down Expand Up @@ -569,7 +570,7 @@ void wlr_output_send_present(struct wlr_output *output,
struct wlr_output_event_present _event = {0};
if (event == NULL) {
event = &_event;
event->commit_seq = output->commit_seq;
event->commit_seq = output->commit_seq + 1;
}

event->output = output;
Expand Down
Loading