output: add wlr_output_preferred_read_format()

The read format is dependent on the output, so we first need to make it
current. This fixes a race condition in wlr-screencopy-v1 where a dmabuf
client would cause EGL_NO_SURFACE to be bound at the time when
screencopy needs to query for the preferred format, causing GL errors.
This commit is contained in:
Ilia Bozhinov 2018-11-23 21:20:57 +01:00
parent c70b8f64b7
commit fb5691b6cc
5 changed files with 22 additions and 15 deletions

View file

@ -6,6 +6,7 @@
#include <time.h>
#include <wayland-server.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_matrix.h>
@ -339,6 +340,20 @@ bool wlr_output_make_current(struct wlr_output *output, int *buffer_age) {
return output->impl->make_current(output, buffer_age);
}
bool wlr_output_preferred_read_format(struct wlr_output *output,
enum wl_shm_format *fmt) {
if (!wlr_output_make_current(output, NULL)) {
return false;
}
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
if (!renderer->impl->preferred_read_format || !renderer->impl->read_pixels) {
return false;
}
*fmt = renderer->impl->preferred_read_format(renderer);
return true;
}
bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when,
pixman_region32_t *damage) {
if (output->frame_pending) {

View file

@ -219,7 +219,7 @@ static void capture_output(struct wl_client *client,
struct wlr_renderer *renderer = wlr_backend_get_renderer(output->backend);
assert(renderer);
if (!wlr_renderer_preferred_read_format(renderer, &frame->format)) {
if (!wlr_output_preferred_read_format(frame->output, &frame->format)) {
wlr_log(WLR_ERROR,
"Failed to capture output: no read format supported by renderer");
goto error;