Move rendering calls into frame-capture

shader-damage-experiments
Andri Yngvason 2020-03-28 11:44:40 +00:00
parent c91816f247
commit 7f5431d922
5 changed files with 56 additions and 33 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2019 Andri Yngvason * Copyright (c) 2019 - 2020 Andri Yngvason
* *
* Permission to use, copy, modify, and/or distribute this software for any * Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -20,6 +20,8 @@
#include <stdbool.h> #include <stdbool.h>
struct wl_output; struct wl_output;
struct nvnc_fb;
struct renderer;
enum frame_capture_status { enum frame_capture_status {
CAPTURE_STOPPED = 0, CAPTURE_STOPPED = 0,
@ -53,6 +55,8 @@ struct frame_capture {
} damage_hint; } damage_hint;
struct { struct {
void (*render)(struct frame_capture*, struct renderer*,
struct nvnc_fb* fb);
int (*start)(struct frame_capture*); int (*start)(struct frame_capture*);
void (*stop)(struct frame_capture*); void (*stop)(struct frame_capture*);
} backend; } backend;
@ -67,3 +71,10 @@ static inline void frame_capture_stop(struct frame_capture* self)
{ {
self->backend.stop(self); self->backend.stop(self);
} }
static inline void frame_capture_render(struct frame_capture* self,
struct renderer* renderer,
struct nvnc_fb* fb)
{
return self->backend.render(self, renderer, fb);
}

View File

@ -1,3 +1,19 @@
/*
* Copyright (c) 2019 - 2020 Andri Yngvason
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
@ -12,6 +28,7 @@ struct wl_output;
struct wl_buffer; struct wl_buffer;
struct wl_shm; struct wl_shm;
struct aml_timer; struct aml_timer;
struct renderer;
enum screencopy_status { enum screencopy_status {
SCREENCOPY_STATUS_CAPTURING = 0, SCREENCOPY_STATUS_CAPTURING = 0,

View File

@ -26,6 +26,7 @@
#include "dmabuf.h" #include "dmabuf.h"
#include "wlr-export-dmabuf-unstable-v1.h" #include "wlr-export-dmabuf-unstable-v1.h"
#include "time-util.h" #include "time-util.h"
#include "render.h"
#define RATE_LIMIT 20.0 // Hz #define RATE_LIMIT 20.0 // Hz
@ -187,6 +188,13 @@ static int dmabuf_capture_start(struct frame_capture* fc)
return 0; return 0;
} }
static void dmabuf_capture_render(struct frame_capture* fc,
struct renderer* render, struct nvnc_fb* fb)
{
struct dmabuf_capture* self = (void*)fc;
render_dmabuf(render, &self->frame);
}
void dmabuf_capture_init(struct dmabuf_capture* self) void dmabuf_capture_init(struct dmabuf_capture* self)
{ {
self->timer = aml_timer_new(0, dmabuf_timer_ready, self, NULL); self->timer = aml_timer_new(0, dmabuf_timer_ready, self, NULL);
@ -194,4 +202,5 @@ void dmabuf_capture_init(struct dmabuf_capture* self)
self->fc.backend.start = dmabuf_capture_start; self->fc.backend.start = dmabuf_capture_start;
self->fc.backend.stop = dmabuf_capture_stop; self->fc.backend.stop = dmabuf_capture_stop;
self->fc.backend.render = dmabuf_capture_render;
} }

View File

@ -508,40 +508,14 @@ void wayvnc_update_vnc(struct wayvnc* self, struct nvnc_fb* fb)
void wayvnc_process_frame(struct wayvnc* self) void wayvnc_process_frame(struct wayvnc* self)
{ {
uint32_t format = fourcc_from_gl_format(self->renderer.read_format); uint32_t format = fourcc_from_gl_format(self->renderer.read_format);
struct dmabuf_frame* frame = &self->dmabuf_backend.frame;
uint32_t fb_width = output_get_transformed_width(self->selected_output); uint32_t fb_width = output_get_transformed_width(self->selected_output);
uint32_t fb_height = uint32_t fb_height =
output_get_transformed_height(self->selected_output); output_get_transformed_height(self->selected_output);
struct nvnc_fb* fb = nvnc_fb_new(fb_width, fb_height, format); struct nvnc_fb* fb = nvnc_fb_new(fb_width, fb_height, format);
void* addr = nvnc_fb_get_addr(fb); void* addr = nvnc_fb_get_addr(fb);
render_dmabuf(&self->renderer, frame); frame_capture_render(self->capture_backend, &self->renderer, fb);
renderer_read_frame(&self->renderer, addr, 0, fb_height);
wayvnc_update_vnc(self, fb);
}
void wayvnc_process_screen(struct wayvnc* self)
{
uint32_t renderer_format =
fourcc_from_gl_format(self->renderer.read_format);
void* pixels = self->screencopy_backend.pixels;
uint32_t width = self->capture_backend->frame_info.width;
uint32_t height = self->capture_backend->frame_info.height;
uint32_t stride = self->capture_backend->frame_info.stride;
uint32_t frame_format = self->capture_backend->frame_info.fourcc_format;
uint32_t fb_width = output_get_transformed_width(self->selected_output);
uint32_t fb_height =
output_get_transformed_height(self->selected_output);
struct nvnc_fb* fb = nvnc_fb_new(fb_width, fb_height, renderer_format);
void* addr = nvnc_fb_get_addr(fb);
render_framebuffer(&self->renderer, pixels, frame_format, width, height,
stride);
renderer_read_frame(&self->renderer, addr, 0, fb_height); renderer_read_frame(&self->renderer, addr, 0, fb_height);
wayvnc_update_vnc(self, fb); wayvnc_update_vnc(self, fb);
@ -567,10 +541,7 @@ void on_capture_done(struct frame_capture* capture)
} }
break; break;
case CAPTURE_DONE: case CAPTURE_DONE:
if (self->capture_backend == (struct frame_capture*)&self->screencopy_backend) wayvnc_process_frame(self);
wayvnc_process_screen(self);
else
wayvnc_process_frame(self);
break; break;
} }
} }

View File

@ -28,6 +28,7 @@
#include "screencopy.h" #include "screencopy.h"
#include "smooth.h" #include "smooth.h"
#include "time-util.h" #include "time-util.h"
#include "render.h"
#define RATE_LIMIT 20.0 // Hz #define RATE_LIMIT 20.0 // Hz
#define DELAY_SMOOTHER_TIME_CONSTANT 0.5 // s #define DELAY_SMOOTHER_TIME_CONSTANT 0.5 // s
@ -228,6 +229,19 @@ static int screencopy_start(struct frame_capture* fc)
return screencopy__start_capture(fc); return screencopy__start_capture(fc);
} }
static void screencopy_render(struct frame_capture* fc,
struct renderer* renderer, struct nvnc_fb* fb)
{
struct screencopy* self = (void*)fc;
uint32_t width = fc->frame_info.width;
uint32_t height = fc->frame_info.height;
uint32_t stride = fc->frame_info.stride;
uint32_t format = fc->frame_info.fourcc_format;
render_framebuffer(renderer, self->pixels, format, width, height, stride);
}
void screencopy_init(struct screencopy* self) void screencopy_init(struct screencopy* self)
{ {
self->timer = aml_timer_new(0, screencopy__poll, self, NULL); self->timer = aml_timer_new(0, screencopy__poll, self, NULL);
@ -237,6 +251,7 @@ void screencopy_init(struct screencopy* self)
self->frame_capture.backend.start = screencopy_start; self->frame_capture.backend.start = screencopy_start;
self->frame_capture.backend.stop = screencopy_stop; self->frame_capture.backend.stop = screencopy_stop;
self->frame_capture.backend.render = screencopy_render;
} }
void screencopy_destroy(struct screencopy* self) void screencopy_destroy(struct screencopy* self)