mirror of
https://github.com/swaywm/sway.git
synced 2026-04-22 06:46:27 -04:00
begin replace wlr_renderer with fx_renderer
This commit is contained in:
parent
0aa5c4f65d
commit
ea33d37362
7 changed files with 204 additions and 91 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
#define _SWAY_OPENGL_H
|
#define _SWAY_OPENGL_H
|
||||||
|
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
|
#include "sway/server.h"
|
||||||
|
|
||||||
struct gles2_tex_shader {
|
struct gles2_tex_shader {
|
||||||
GLuint program;
|
GLuint program;
|
||||||
|
|
@ -13,12 +14,14 @@ struct gles2_tex_shader {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fx_renderer {
|
struct fx_renderer {
|
||||||
|
// for simple rendering
|
||||||
|
struct wlr_renderer* wlr_renderer;
|
||||||
|
|
||||||
struct wlr_egl *egl;
|
struct wlr_egl *egl;
|
||||||
|
|
||||||
float projection[9];
|
float projection[9];
|
||||||
|
|
||||||
uint32_t viewport_width;
|
struct sway_output *current;
|
||||||
uint32_t viewport_height;
|
|
||||||
|
|
||||||
// Shaders
|
// Shaders
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -34,7 +37,19 @@ struct fx_renderer {
|
||||||
} shaders;
|
} shaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fx_renderer *fx_renderer_create(struct wlr_egl *egl);
|
struct fx_renderer *fx_renderer_create(struct sway_server *server);
|
||||||
|
|
||||||
|
void fx_renderer_begin(struct fx_renderer *renderer, struct sway_output *output);
|
||||||
|
|
||||||
|
void fx_renderer_end(struct fx_renderer *renderer, pixman_region32_t* damage, struct sway_output* output);
|
||||||
|
|
||||||
|
void fx_renderer_scissor(struct wlr_box *box);
|
||||||
|
|
||||||
|
bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer,
|
||||||
|
struct wlr_texture *wlr_texture, const struct wlr_fbox *box,
|
||||||
|
const float matrix[static 9], float alpha);
|
||||||
|
|
||||||
|
bool fx_render_texture_with_matrix(struct fx_renderer *renderer,
|
||||||
|
struct wlr_texture *wlr_texture, const float matrix[static 9], float alpha);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
#include <wlr/backend.h>
|
#include <wlr/backend.h>
|
||||||
#include <wlr/backend/session.h>
|
#include <wlr/backend/session.h>
|
||||||
#include <wlr/render/allocator.h>
|
#include <wlr/render/allocator.h>
|
||||||
#include <wlr/render/wlr_renderer.h>
|
|
||||||
#include <wlr/types/wlr_compositor.h>
|
#include <wlr/types/wlr_compositor.h>
|
||||||
#include <wlr/types/wlr_data_device.h>
|
#include <wlr/types/wlr_data_device.h>
|
||||||
#include <wlr/types/wlr_input_method_v2.h>
|
#include <wlr/types/wlr_input_method_v2.h>
|
||||||
|
|
@ -35,8 +34,7 @@ struct sway_server {
|
||||||
struct wlr_backend *backend;
|
struct wlr_backend *backend;
|
||||||
// secondary headless backend used for creating virtual outputs on-the-fly
|
// secondary headless backend used for creating virtual outputs on-the-fly
|
||||||
struct wlr_backend *headless_backend;
|
struct wlr_backend *headless_backend;
|
||||||
struct wlr_renderer *renderer;
|
struct fx_renderer *renderer;
|
||||||
struct fx_renderer *fx_renderer;
|
|
||||||
struct wlr_allocator *allocator;
|
struct wlr_allocator *allocator;
|
||||||
|
|
||||||
struct wlr_compositor *compositor;
|
struct wlr_compositor *compositor;
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,15 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <GLES2/gl2.h>
|
#include <GLES2/gl2.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <wlr/render/gles2.h>
|
||||||
#include <wlr/render/egl.h>
|
#include <wlr/render/egl.h>
|
||||||
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include <wlr/types/wlr_matrix.h>
|
#include <wlr/types/wlr_matrix.h>
|
||||||
#include <wlr/util/box.h>
|
#include <wlr/util/box.h>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "sway/desktop/fx_renderer.h"
|
#include "sway/desktop/fx_renderer.h"
|
||||||
|
#include "sway/output.h"
|
||||||
|
#include "sway/server.h"
|
||||||
|
|
||||||
// TODO: update to hyprland shaders (add sup for rounded corners + add blur shaders)
|
// TODO: update to hyprland shaders (add sup for rounded corners + add blur shaders)
|
||||||
|
|
||||||
|
|
@ -96,6 +100,7 @@ static const GLfloat flip_180[] = {
|
||||||
0.0f, -1.0f, 0.0f,
|
0.0f, -1.0f, 0.0f,
|
||||||
0.0f, 0.0f, 1.0f,
|
0.0f, 0.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
static const GLfloat verts[] = {
|
static const GLfloat verts[] = {
|
||||||
1, 0, // top right
|
1, 0, // top right
|
||||||
|
|
@ -103,7 +108,7 @@ static const GLfloat verts[] = {
|
||||||
1, 1, // bottom right
|
1, 1, // bottom right
|
||||||
0, 1, // bottom left
|
0, 1, // bottom left
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
/************************
|
/************************
|
||||||
General Functions
|
General Functions
|
||||||
*************************/
|
*************************/
|
||||||
|
|
@ -158,20 +163,30 @@ error:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) {
|
// TODO: Hyprland way?
|
||||||
// TODO: Hyprland way?
|
struct fx_renderer *fx_renderer_create(struct sway_server *server) {
|
||||||
// TODO: handle case of no drm_fd?
|
struct fx_renderer *renderer = calloc(1, sizeof(struct fx_renderer));
|
||||||
//struct wlr_egl *egl = wlr_egl_create_with_drm_fd(drm_fd);
|
if (renderer == NULL) {
|
||||||
//struct wlr_egl *egl = wlr_egl_create_with_context(${1:EGLDisplay display}, ${2:EGLContext context});
|
|
||||||
|
|
||||||
if (egl == NULL) {
|
|
||||||
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not initialize EGL");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
renderer->current = NULL;
|
||||||
|
|
||||||
|
renderer->wlr_renderer = wlr_renderer_autocreate(server->backend);
|
||||||
|
|
||||||
|
renderer->wlr_renderer = wlr_renderer_autocreate(server->backend);
|
||||||
|
assert(renderer->wlr_renderer);
|
||||||
|
// TODO: needed?
|
||||||
|
wlr_renderer_init_wl_display(renderer->wlr_renderer, server->wl_display);
|
||||||
|
|
||||||
|
struct wlr_egl *egl = wlr_gles2_renderer_get_egl(renderer->wlr_renderer);
|
||||||
|
// TODO: wlr_egl_make_current or eglMakeCurrent?
|
||||||
|
// TODO: assert instead of conditional statement?
|
||||||
if (!wlr_egl_make_current(egl)) {
|
if (!wlr_egl_make_current(egl)) {
|
||||||
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current");
|
sway_log(SWAY_ERROR, "GLES2 RENDERER: Could not make EGL current");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
// TODO: needed?
|
||||||
|
renderer->egl = egl;
|
||||||
|
|
||||||
// get extensions
|
// get extensions
|
||||||
const char *exts_str = (const char *)glGetString(GL_EXTENSIONS);
|
const char *exts_str = (const char *)glGetString(GL_EXTENSIONS);
|
||||||
|
|
@ -180,15 +195,7 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct fx_renderer *renderer = calloc(1, sizeof(struct fx_renderer));
|
sway_log(SWAY_INFO, "Creating swayfx GLES2 renderer");
|
||||||
if (renderer == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: needed?
|
|
||||||
renderer->egl = egl;
|
|
||||||
|
|
||||||
sway_log(SWAY_INFO, "Creating GLES2 renderer");
|
|
||||||
sway_log(SWAY_INFO, "Using %s", glGetString(GL_VERSION));
|
sway_log(SWAY_INFO, "Using %s", glGetString(GL_VERSION));
|
||||||
sway_log(SWAY_INFO, "GL vendor: %s", glGetString(GL_VENDOR));
|
sway_log(SWAY_INFO, "GL vendor: %s", glGetString(GL_VENDOR));
|
||||||
sway_log(SWAY_INFO, "GL renderer: %s", glGetString(GL_RENDERER));
|
sway_log(SWAY_INFO, "GL renderer: %s", glGetString(GL_RENDERER));
|
||||||
|
|
@ -241,6 +248,7 @@ struct fx_renderer *fx_renderer_create(struct wlr_egl *egl) {
|
||||||
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
renderer->shaders.tex_ext.pos_attrib = glGetAttribLocation(prog, "pos");
|
||||||
renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
renderer->shaders.tex_ext.tex_attrib = glGetAttribLocation(prog, "texcoord");
|
||||||
|
|
||||||
|
// TODO: if remove renderer->egl, replace below with r->egl
|
||||||
wlr_egl_unset_current(renderer->egl);
|
wlr_egl_unset_current(renderer->egl);
|
||||||
|
|
||||||
sway_log(SWAY_INFO, "GLES2 RENDERER: Shaders Initialized Successfully");
|
sway_log(SWAY_INFO, "GLES2 RENDERER: Shaders Initialized Successfully");
|
||||||
|
|
@ -254,32 +262,36 @@ error:
|
||||||
|
|
||||||
wlr_egl_unset_current(renderer->egl);
|
wlr_egl_unset_current(renderer->egl);
|
||||||
|
|
||||||
|
// TODO: more freeing?
|
||||||
free(renderer);
|
free(renderer);
|
||||||
|
|
||||||
sway_log(SWAY_ERROR, "GLES2 RENDERER: Error Initializing Shaders");
|
sway_log(SWAY_ERROR, "GLES2 RENDERER: Error Initializing Shaders");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// TODO: handle without wlr_renderer?
|
||||||
|
void fx_renderer_begin(struct fx_renderer *renderer, struct sway_output *output) {
|
||||||
// TODO: is gles2_get_renderer_in_context(wlr_renderer) implementation needed?
|
wlr_renderer_begin(renderer->wlr_renderer, output->wlr_output->width, output->wlr_output->height);
|
||||||
static void fx_begin(struct fx_renderer *renderer, uint32_t width,
|
renderer->current = output;
|
||||||
uint32_t height) { glViewport(0, 0, width, height); renderer->viewport_width =
|
|
||||||
width; renderer->viewport_height = height;
|
|
||||||
|
|
||||||
// refresh projection matrix
|
|
||||||
wlr_matrix_projection(renderer->projection, width, height,
|
|
||||||
WL_OUTPUT_TRANSFORM_NORMAL);
|
|
||||||
|
|
||||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: handle without wlr_renderer?
|
||||||
|
void fx_renderer_end(struct fx_renderer *renderer, pixman_region32_t* damage, struct sway_output* output) {
|
||||||
|
wlr_renderer_scissor(renderer->wlr_renderer, NULL);
|
||||||
|
wlr_output_render_software_cursors(output->wlr_output, damage);
|
||||||
|
wlr_renderer_end(renderer->wlr_renderer);
|
||||||
|
|
||||||
|
renderer->current = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static void gles2_clear(const float color[static 4]) {
|
static void gles2_clear(const float color[static 4]) {
|
||||||
glClearColor(color[0], color[1], color[2], color[3]);
|
glClearColor(color[0], color[1], color[2], color[3]);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static void gles2_scissor(struct wlr_box *box) {
|
void fx_renderer_scissor(struct wlr_box *box) {
|
||||||
if (box) {
|
if (box) {
|
||||||
glScissor(box->x, box->y, box->width, box->height);
|
glScissor(box->x, box->y, box->width, box->height);
|
||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
|
@ -288,27 +300,26 @@ static void gles2_scissor(struct wlr_box *box) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
Rendering Functions
|
Rendering Functions
|
||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
static void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *box, const float color[static 4], const float projection[static 9]) {
|
static void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box
|
||||||
if (box->width == 0 || box->height == 0) {
|
*box, const float color[static 4], const float projection[static 9]) { if
|
||||||
return;
|
(box->width == 0 || box->height == 0) { return;
|
||||||
}
|
}
|
||||||
assert(box->width > 0 && box->height > 0);
|
assert(box->width > 0 && box->height > 0);
|
||||||
float matrix[9];
|
float matrix[9];
|
||||||
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0, projection);
|
wlr_matrix_project_box(matrix, box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
|
||||||
|
projection);
|
||||||
|
|
||||||
float gl_matrix[9];
|
float gl_matrix[9];
|
||||||
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
|
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
|
||||||
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
|
wlr_matrix_multiply(gl_matrix, flip_180, gl_matrix);
|
||||||
|
|
||||||
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set to GL_FALSE
|
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be
|
||||||
wlr_matrix_transpose(gl_matrix, gl_matrix);
|
set to GL_FALSE wlr_matrix_transpose(gl_matrix, gl_matrix);
|
||||||
|
|
||||||
if (color[3] == 1.0) {
|
if (color[3] == 1.0) {
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
|
@ -319,9 +330,11 @@ static void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *b
|
||||||
glUseProgram(renderer->shaders.quad.program);
|
glUseProgram(renderer->shaders.quad.program);
|
||||||
|
|
||||||
glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, gl_matrix);
|
glUniformMatrix3fv(renderer->shaders.quad.proj, 1, GL_FALSE, gl_matrix);
|
||||||
glUniform4f(renderer->shaders.quad.color, color[0], color[1], color[2], color[3]);
|
glUniform4f(renderer->shaders.quad.color, color[0], color[1], color[2],
|
||||||
|
color[3]);
|
||||||
|
|
||||||
glVertexAttribPointer(renderer->shaders.quad.pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
|
glVertexAttribPointer(renderer->shaders.quad.pos_attrib, 2, GL_FLOAT,
|
||||||
|
GL_FALSE, 0, verts);
|
||||||
|
|
||||||
glEnableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
glEnableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
||||||
|
|
||||||
|
|
@ -329,5 +342,104 @@ static void fx_render_rect(struct fx_renderer *renderer, const struct wlr_box *b
|
||||||
|
|
||||||
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
glDisableVertexAttribArray(renderer->shaders.quad.pos_attrib);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool fx_render_subtexture_with_matrix(struct fx_renderer *renderer,
|
||||||
|
struct wlr_texture *wlr_texture, const struct wlr_fbox *box,
|
||||||
|
const float matrix[static 9], float alpha) {
|
||||||
|
|
||||||
|
assert(wlr_texture_is_gles2(wlr_texture));
|
||||||
|
struct wlr_gles2_texture_attribs texture_attrs;
|
||||||
|
wlr_gles2_texture_get_attribs(wlr_texture, &texture_attrs);
|
||||||
|
|
||||||
|
struct gles2_tex_shader *shader = NULL;
|
||||||
|
|
||||||
|
switch (texture_attrs.target) {
|
||||||
|
case GL_TEXTURE_2D:
|
||||||
|
if (texture_attrs.has_alpha) {
|
||||||
|
shader = &renderer->shaders.tex_rgba;
|
||||||
|
} else {
|
||||||
|
shader = &renderer->shaders.tex_rgbx;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// TODO?
|
||||||
|
/*
|
||||||
|
case GL_TEXTURE_EXTERNAL_OES:
|
||||||
|
shader = &renderer->shaders.tex_ext;
|
||||||
|
|
||||||
|
// TODO: ADD ME ONCE EXTS ADDED TO RENDERER
|
||||||
|
if (!renderer->exts.OES_egl_image_external) {
|
||||||
|
sway_log(SWAY_ERROR, "Failed to render texture: "
|
||||||
|
"GL_TEXTURE_EXTERNAL_OES not supported");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
float gl_matrix[9];
|
||||||
|
wlr_matrix_multiply(gl_matrix, renderer->projection, matrix);
|
||||||
|
|
||||||
|
// OpenGL ES 2 requires the glUniformMatrix3fv transpose parameter to be set
|
||||||
|
// to GL_FALSE
|
||||||
|
wlr_matrix_transpose(gl_matrix, gl_matrix);
|
||||||
|
|
||||||
|
// push_gles2_debug(renderer);
|
||||||
|
|
||||||
|
if (!texture_attrs.has_alpha && alpha == 1.0) {
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
} else {
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(texture_attrs.target, texture_attrs.tex);
|
||||||
|
|
||||||
|
glTexParameteri(texture_attrs.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
glUseProgram(shader->program);
|
||||||
|
|
||||||
|
glUniformMatrix3fv(shader->proj, 1, GL_FALSE, gl_matrix);
|
||||||
|
glUniform1i(shader->tex, 0);
|
||||||
|
glUniform1f(shader->alpha, alpha);
|
||||||
|
|
||||||
|
const GLfloat x1 = box->x / wlr_texture->width;
|
||||||
|
const GLfloat y1 = box->y / wlr_texture->height;
|
||||||
|
const GLfloat x2 = (box->x + box->width) / wlr_texture->width;
|
||||||
|
const GLfloat y2 = (box->y + box->height) / wlr_texture->height;
|
||||||
|
const GLfloat texcoord[] = {
|
||||||
|
x2, y1, // top right
|
||||||
|
x1, y1, // top left
|
||||||
|
x2, y2, // bottom right
|
||||||
|
x1, y2, // bottom left
|
||||||
|
};
|
||||||
|
|
||||||
|
glVertexAttribPointer(shader->pos_attrib, 2, GL_FLOAT, GL_FALSE, 0, verts);
|
||||||
|
glVertexAttribPointer(shader->tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, texcoord);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(shader->pos_attrib);
|
||||||
|
glEnableVertexAttribArray(shader->tex_attrib);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
|
glDisableVertexAttribArray(shader->pos_attrib);
|
||||||
|
glDisableVertexAttribArray(shader->tex_attrib);
|
||||||
|
|
||||||
|
glBindTexture(texture_attrs.target, 0);
|
||||||
|
|
||||||
|
// pop_gles2_debug(renderer);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fx_render_texture_with_matrix(struct fx_renderer *renderer,
|
||||||
|
struct wlr_texture *wlr_texture, const float matrix[static 9], float alpha) {
|
||||||
|
struct wlr_fbox box = {
|
||||||
|
.x = 0,
|
||||||
|
.y = 0,
|
||||||
|
.width = wlr_texture->width,
|
||||||
|
.height = wlr_texture->height,
|
||||||
|
};
|
||||||
|
return fx_render_subtexture_with_matrix(renderer, wlr_texture, &box, matrix, alpha);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/backend/drm.h>
|
#include <wlr/backend/drm.h>
|
||||||
#include <wlr/backend/headless.h>
|
#include <wlr/backend/headless.h>
|
||||||
#include <wlr/render/gles2.h> // TODO: remove if no egl needed to init custom renderer
|
|
||||||
#include <wlr/render/wlr_renderer.h>
|
|
||||||
#include <wlr/types/wlr_buffer.h>
|
#include <wlr/types/wlr_buffer.h>
|
||||||
#include <wlr/types/wlr_drm_lease_v1.h>
|
#include <wlr/types/wlr_drm_lease_v1.h>
|
||||||
#include <wlr/types/wlr_matrix.h>
|
#include <wlr/types/wlr_matrix.h>
|
||||||
|
|
@ -873,20 +871,11 @@ void handle_new_output(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wlr_output_init_render(wlr_output, server->allocator,
|
if (!wlr_output_init_render(wlr_output, server->allocator,
|
||||||
server->renderer)) {
|
server->renderer->wlr_renderer)) {
|
||||||
sway_log(SWAY_ERROR, "Failed to init output render");
|
sway_log(SWAY_ERROR, "Failed to init output render");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: need different egl?
|
|
||||||
// TODO: init fx_renderer same way as wlr_renderer?
|
|
||||||
// TODO: reference wlroots render/wlr_renderer.c: wlr_renderer_autocreate
|
|
||||||
struct wlr_egl *egl = wlr_gles2_renderer_get_egl(server->renderer);
|
|
||||||
server->fx_renderer = fx_renderer_create(egl);
|
|
||||||
if (!server->fx_renderer) {
|
|
||||||
printf("fx_renderer is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sway_output *output = output_create(wlr_output);
|
struct sway_output *output = output_create(wlr_output);
|
||||||
if (!output) {
|
if (!output) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,8 @@ static int scale_length(int length, int offset, float scale) {
|
||||||
|
|
||||||
static void scissor_output(struct wlr_output *wlr_output,
|
static void scissor_output(struct wlr_output *wlr_output,
|
||||||
pixman_box32_t *rect) {
|
pixman_box32_t *rect) {
|
||||||
struct wlr_renderer *renderer = wlr_output->renderer;
|
struct sway_output *output = wlr_output->data;
|
||||||
|
struct fx_renderer *renderer = output->server->renderer;
|
||||||
assert(renderer);
|
assert(renderer);
|
||||||
|
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
|
|
@ -70,7 +71,7 @@ static void scissor_output(struct wlr_output *wlr_output,
|
||||||
wlr_output_transform_invert(wlr_output->transform);
|
wlr_output_transform_invert(wlr_output->transform);
|
||||||
wlr_box_transform(&box, &box, transform, ow, oh);
|
wlr_box_transform(&box, &box, transform, ow, oh);
|
||||||
|
|
||||||
wlr_renderer_scissor(renderer, &box);
|
fx_renderer_scissor(&box);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_scale_filter(struct wlr_output *wlr_output,
|
static void set_scale_filter(struct wlr_output *wlr_output,
|
||||||
|
|
@ -101,8 +102,8 @@ static void render_texture(struct wlr_output *wlr_output,
|
||||||
pixman_region32_t *output_damage, struct wlr_texture *texture,
|
pixman_region32_t *output_damage, struct wlr_texture *texture,
|
||||||
const struct wlr_fbox *src_box, const struct wlr_box *dst_box,
|
const struct wlr_fbox *src_box, const struct wlr_box *dst_box,
|
||||||
const float matrix[static 9], float alpha) {
|
const float matrix[static 9], float alpha) {
|
||||||
struct wlr_renderer *renderer = wlr_output->renderer;
|
|
||||||
struct sway_output *output = wlr_output->data;
|
struct sway_output *output = wlr_output->data;
|
||||||
|
struct fx_renderer *renderer = output->server->renderer;
|
||||||
|
|
||||||
pixman_region32_t damage;
|
pixman_region32_t damage;
|
||||||
pixman_region32_init(&damage);
|
pixman_region32_init(&damage);
|
||||||
|
|
@ -120,9 +121,9 @@ static void render_texture(struct wlr_output *wlr_output,
|
||||||
scissor_output(wlr_output, &rects[i]);
|
scissor_output(wlr_output, &rects[i]);
|
||||||
set_scale_filter(wlr_output, texture, output->scale_filter);
|
set_scale_filter(wlr_output, texture, output->scale_filter);
|
||||||
if (src_box != NULL) {
|
if (src_box != NULL) {
|
||||||
wlr_render_subtexture_with_matrix(renderer, texture, src_box, matrix, alpha);
|
fx_render_subtexture_with_matrix(renderer, texture, src_box, matrix, alpha);
|
||||||
} else {
|
} else {
|
||||||
wlr_render_texture_with_matrix(renderer, texture, matrix, alpha);
|
fx_render_texture_with_matrix(renderer, texture, matrix, alpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,8 +164,9 @@ static void render_surface_iterator(struct sway_output *output,
|
||||||
}
|
}
|
||||||
scale_box(&dst_box, wlr_output->scale);
|
scale_box(&dst_box, wlr_output->scale);
|
||||||
|
|
||||||
render_texture(wlr_output, output_damage, texture,
|
render_texture(wlr_output, output_damage, texture, &src_box, &dst_box, matrix, alpha);
|
||||||
&src_box, &dst_box, matrix, alpha);
|
//render_texture(wlr_output, output_damage, texture,
|
||||||
|
// &src_box, &dst_box, matrix, alpha);
|
||||||
|
|
||||||
wlr_presentation_surface_sampled_on_output(server.presentation, surface,
|
wlr_presentation_surface_sampled_on_output(server.presentation, surface,
|
||||||
wlr_output);
|
wlr_output);
|
||||||
|
|
@ -1028,13 +1030,7 @@ static void render_seatops(struct sway_output *output,
|
||||||
void output_render(struct sway_output *output, struct timespec *when,
|
void output_render(struct sway_output *output, struct timespec *when,
|
||||||
pixman_region32_t *damage) {
|
pixman_region32_t *damage) {
|
||||||
struct wlr_output *wlr_output = output->wlr_output;
|
struct wlr_output *wlr_output = output->wlr_output;
|
||||||
// TODO: replace with swayfx_renderer
|
struct wlr_renderer *renderer = output->server->renderer->wlr_renderer;
|
||||||
struct wlr_renderer *renderer = output->server->renderer;
|
|
||||||
struct fx_renderer *fx_renderer = output->server->fx_renderer;
|
|
||||||
// TODO: remove this check
|
|
||||||
if (!fx_renderer) {
|
|
||||||
printf("swayfx_renderer is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sway_workspace *workspace = output->current.active_workspace;
|
struct sway_workspace *workspace = output->current.active_workspace;
|
||||||
if (workspace == NULL) {
|
if (workspace == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
|
#include "sway/desktop/fx_renderer.h"
|
||||||
#include "sway/desktop/idle_inhibit_v1.h"
|
#include "sway/desktop/idle_inhibit_v1.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
|
|
@ -75,29 +76,29 @@ static void handle_drm_lease_request(struct wl_listener *listener, void *data) {
|
||||||
bool server_init(struct sway_server *server) {
|
bool server_init(struct sway_server *server) {
|
||||||
sway_log(SWAY_DEBUG, "Initializing Wayland server");
|
sway_log(SWAY_DEBUG, "Initializing Wayland server");
|
||||||
|
|
||||||
server->renderer = wlr_renderer_autocreate(server->backend);
|
server->renderer = fx_renderer_create(server);
|
||||||
if (!server->renderer) {
|
if (!server->renderer) {
|
||||||
sway_log(SWAY_ERROR, "Failed to create renderer");
|
sway_log(SWAY_ERROR, "Failed to create renderer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wlr_renderer_init_wl_shm(server->renderer, server->wl_display);
|
wlr_renderer_init_wl_shm(server->renderer->wlr_renderer, server->wl_display);
|
||||||
|
|
||||||
if (wlr_renderer_get_dmabuf_texture_formats(server->renderer) != NULL) {
|
if (wlr_renderer_get_dmabuf_texture_formats(server->renderer->wlr_renderer) != NULL) {
|
||||||
wlr_drm_create(server->wl_display, server->renderer);
|
wlr_drm_create(server->wl_display, server->renderer->wlr_renderer);
|
||||||
server->linux_dmabuf_v1 =
|
server->linux_dmabuf_v1 =
|
||||||
wlr_linux_dmabuf_v1_create(server->wl_display, server->renderer);
|
wlr_linux_dmabuf_v1_create(server->wl_display, server->renderer->wlr_renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
server->allocator = wlr_allocator_autocreate(server->backend,
|
server->allocator = wlr_allocator_autocreate(server->backend,
|
||||||
server->renderer);
|
server->renderer->wlr_renderer);
|
||||||
if (!server->allocator) {
|
if (!server->allocator) {
|
||||||
sway_log(SWAY_ERROR, "Failed to create allocator");
|
sway_log(SWAY_ERROR, "Failed to create allocator");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
server->compositor = wlr_compositor_create(server->wl_display,
|
server->compositor = wlr_compositor_create(server->wl_display,
|
||||||
server->renderer);
|
server->renderer->wlr_renderer);
|
||||||
server->compositor_new_surface.notify = handle_compositor_new_surface;
|
server->compositor_new_surface.notify = handle_compositor_new_surface;
|
||||||
wl_signal_add(&server->compositor->events.new_surface,
|
wl_signal_add(&server->compositor->events.new_surface,
|
||||||
&server->compositor_new_surface);
|
&server->compositor_new_surface);
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
#include <wlr/types/wlr_subcompositor.h>
|
#include <wlr/types/wlr_subcompositor.h>
|
||||||
#include <wlr/render/drm_format_set.h>
|
#include <wlr/render/drm_format_set.h>
|
||||||
|
#include <wlr/render/wlr_renderer.h>
|
||||||
#include "linux-dmabuf-unstable-v1-protocol.h"
|
#include "linux-dmabuf-unstable-v1-protocol.h"
|
||||||
#include "cairo_util.h"
|
#include "cairo_util.h"
|
||||||
#include "pango.h"
|
#include "pango.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "sway/desktop.h"
|
#include "sway/desktop.h"
|
||||||
|
#include "sway/desktop/fx_renderer.h"
|
||||||
#include "sway/desktop/transaction.h"
|
#include "sway/desktop/transaction.h"
|
||||||
#include "sway/input/input-manager.h"
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/input/seat.h"
|
#include "sway/input/seat.h"
|
||||||
|
|
@ -1103,10 +1105,10 @@ static void set_fullscreen(struct sway_container *con, bool enable) {
|
||||||
// TODO: add wlroots helpers for all of this stuff
|
// TODO: add wlroots helpers for all of this stuff
|
||||||
|
|
||||||
const struct wlr_drm_format_set *renderer_formats =
|
const struct wlr_drm_format_set *renderer_formats =
|
||||||
wlr_renderer_get_dmabuf_texture_formats(server.renderer);
|
wlr_renderer_get_dmabuf_texture_formats(server.renderer->wlr_renderer);
|
||||||
assert(renderer_formats);
|
assert(renderer_formats);
|
||||||
|
|
||||||
int renderer_drm_fd = wlr_renderer_get_drm_fd(server.renderer);
|
int renderer_drm_fd = wlr_renderer_get_drm_fd(server.renderer->wlr_renderer);
|
||||||
int backend_drm_fd = wlr_backend_get_drm_fd(wlr_output->backend);
|
int backend_drm_fd = wlr_backend_get_drm_fd(wlr_output->backend);
|
||||||
if (renderer_drm_fd < 0 || backend_drm_fd < 0) {
|
if (renderer_drm_fd < 0 || backend_drm_fd < 0) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue