mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
renderer: replace wlr_texture_get_matrix by wlr_render_texture
This commit is contained in:
parent
1914a1aa2b
commit
876f07e9f1
9 changed files with 34 additions and 72 deletions
|
@ -647,10 +647,8 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output,
|
|||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
float matrix[9];
|
||||
wlr_texture_get_matrix(plane->wlr_tex, matrix, plane->matrix, 0, 0);
|
||||
wlr_render_texture_with_matrix(plane->surf.renderer->wlr_rend, plane->wlr_tex,
|
||||
matrix, 1.0f);
|
||||
wlr_render_texture(plane->surf.renderer->wlr_rend, plane->wlr_tex,
|
||||
plane->matrix, 0, 0, 1.0f);
|
||||
|
||||
glFinish();
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);
|
||||
|
|
|
@ -111,18 +111,14 @@ static void handle_output_frame(struct output_state *output,
|
|||
.width = 128, .height = 128,
|
||||
};
|
||||
if (wlr_output_layout_intersects(sample->layout, output->output, &box)) {
|
||||
float matrix[9];
|
||||
|
||||
// transform global coordinates to local coordinates
|
||||
double local_x = sample->x_offs;
|
||||
double local_y = sample->y_offs;
|
||||
wlr_output_layout_output_coords(sample->layout, output->output,
|
||||
&local_x, &local_y);
|
||||
|
||||
wlr_texture_get_matrix(sample->cat_texture, matrix,
|
||||
wlr_output->transform_matrix, local_x, local_y);
|
||||
wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture,
|
||||
matrix, 1.0f);
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, local_x, local_y, 1.0f);
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
|
|
|
@ -46,13 +46,10 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
|||
wlr_renderer_begin(sample->renderer, wlr_output);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
|
||||
float matrix[9];
|
||||
for (int y = -128 + (int)odata->y_offs; y < height; y += 128) {
|
||||
for (int x = -128 + (int)odata->x_offs; x < width; x += 128) {
|
||||
wlr_texture_get_matrix(sample->cat_texture, matrix,
|
||||
wlr_output->transform_matrix, x, y);
|
||||
wlr_render_texture_with_matrix(sample->renderer,
|
||||
sample->cat_texture, matrix, 1.0f);
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, x, y, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,15 +45,12 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
|
|||
wlr_renderer_begin(sample->renderer, wlr_output);
|
||||
wlr_renderer_clear(sample->renderer, (float[]){0.25f, 0.25f, 0.25f, 1});
|
||||
|
||||
float matrix[9];
|
||||
struct touch_point *p;
|
||||
wl_list_for_each(p, &sample->touch_points, link) {
|
||||
wlr_texture_get_matrix(sample->cat_texture, matrix,
|
||||
wlr_output->transform_matrix,
|
||||
(int)(p->x * width) - sample->cat_texture->width / 2,
|
||||
(int)(p->y * height) - sample->cat_texture->height / 2);
|
||||
wlr_render_texture_with_matrix(sample->renderer, sample->cat_texture,
|
||||
matrix, 1.0f);
|
||||
int x = (int)(p->x * width) - sample->cat_texture->width / 2;
|
||||
int y = (int)(p->y * height) - sample->cat_texture->height / 2;
|
||||
wlr_render_texture(sample->renderer, sample->cat_texture,
|
||||
wlr_output->transform_matrix, x, y, 1.0f);
|
||||
}
|
||||
|
||||
wlr_renderer_end(sample->renderer);
|
||||
|
|
|
@ -25,21 +25,15 @@ void wlr_renderer_scissor(struct wlr_renderer *r, struct wlr_box *box);
|
|||
*/
|
||||
struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r);
|
||||
/**
|
||||
* Renders the requested texture using the provided matrix. A typical texture
|
||||
* rendering goes like so:
|
||||
*
|
||||
* struct wlr_renderer *renderer;
|
||||
* struct wlr_texture *texture;
|
||||
* float projection[9];
|
||||
* float matrix[9];
|
||||
* wlr_texture_get_matrix(texture, matrix, projection, 123, 321);
|
||||
* wlr_render_texture_with_matrix(renderer, texture, matrix, 0.5f);
|
||||
*
|
||||
* This will render the texture at <123, 321> with an alpha channel of 0.5.
|
||||
* Renders the requested texture.
|
||||
*/
|
||||
bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
|
||||
const float projection[static 9], int x, int y, float alpha);
|
||||
/**
|
||||
* Renders the requested texture using the provided matrix.
|
||||
*/
|
||||
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
|
||||
struct wlr_texture *texture, const float matrix[static 9], float alpha);
|
||||
|
||||
/**
|
||||
* Renders a solid quad in the specified color.
|
||||
*/
|
||||
|
@ -95,22 +89,22 @@ struct wlr_texture {
|
|||
* returns.
|
||||
*/
|
||||
bool wlr_texture_upload_pixels(struct wlr_texture *tex,
|
||||
enum wl_shm_format format, int stride, int width, int height,
|
||||
const unsigned char *pixels);
|
||||
enum wl_shm_format format, int stride, int width, int height,
|
||||
const unsigned char *pixels);
|
||||
/**
|
||||
* Copies pixels to this texture. The buffer is not accessed after this function
|
||||
* returns. Under some circumstances, this function may re-upload the entire
|
||||
* buffer - therefore, the entire buffer must be valid.
|
||||
*/
|
||||
bool wlr_texture_update_pixels(struct wlr_texture *surf,
|
||||
enum wl_shm_format format, int stride, int x, int y,
|
||||
int width, int height, const unsigned char *pixels);
|
||||
enum wl_shm_format format, int stride, int x, int y,
|
||||
int width, int height, const unsigned char *pixels);
|
||||
/**
|
||||
* Copies pixels from a wl_shm_buffer into this texture. The buffer is not
|
||||
* accessed after this function returns.
|
||||
*/
|
||||
bool wlr_texture_upload_shm(struct wlr_texture *tex, uint32_t format,
|
||||
struct wl_shm_buffer *shm);
|
||||
struct wl_shm_buffer *shm);
|
||||
|
||||
/**
|
||||
* Attaches the contents from the given wl_drm wl_buffer resource onto the
|
||||
|
@ -132,18 +126,7 @@ bool wlr_texture_upload_dmabuf(struct wlr_texture *tex,
|
|||
* must be valid.
|
||||
*/
|
||||
bool wlr_texture_update_shm(struct wlr_texture *surf, uint32_t format,
|
||||
int x, int y, int width, int height, struct wl_shm_buffer *shm);
|
||||
/**
|
||||
* Prepares a matrix with the appropriate scale for the given texture and
|
||||
* multiplies it with the projection, producing a matrix that the shader can
|
||||
* muptlipy vertex coordinates with to get final screen coordinates.
|
||||
*
|
||||
* The projection matrix is assumed to be an orthographic projection of [0,
|
||||
* width) and [0, height], and the x and y coordinates provided are used as
|
||||
* such.
|
||||
*/
|
||||
void wlr_texture_get_matrix(struct wlr_texture *texture, float mat[static 9],
|
||||
const float projection[static 9], int x, int y);
|
||||
int x, int y, int width, int height, struct wl_shm_buffer *shm);
|
||||
/**
|
||||
* Destroys this wlr_texture.
|
||||
*/
|
||||
|
|
|
@ -62,8 +62,6 @@ struct wlr_texture_impl {
|
|||
uint32_t width, uint32_t height);
|
||||
bool (*upload_dmabuf)(struct wlr_texture *texture,
|
||||
struct wl_resource *dmabuf_resource);
|
||||
void (*get_matrix)(struct wlr_texture *state, float mat[static 9],
|
||||
const float projection[static 9], int x, int y);
|
||||
void (*get_buffer_size)(struct wlr_texture *texture,
|
||||
struct wl_resource *resource, int *width, int *height);
|
||||
void (*bind)(struct wlr_texture *texture);
|
||||
|
|
|
@ -227,7 +227,6 @@ static bool gles2_texture_upload_eglimage(struct wlr_texture *wlr_tex,
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool gles2_texture_upload_dmabuf(struct wlr_texture *_tex,
|
||||
struct wl_resource *dmabuf_resource) {
|
||||
struct wlr_gles2_texture *tex = (struct wlr_gles2_texture *)_tex;
|
||||
|
@ -263,17 +262,6 @@ static bool gles2_texture_upload_dmabuf(struct wlr_texture *_tex,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void gles2_texture_get_matrix(struct wlr_texture *_texture,
|
||||
float mat[static 9], const float projection[static 9], int x, int y) {
|
||||
struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture;
|
||||
wlr_matrix_identity(mat);
|
||||
wlr_matrix_translate(mat, x, y);
|
||||
wlr_matrix_scale(mat, texture->wlr_texture.width,
|
||||
texture->wlr_texture.height);
|
||||
wlr_matrix_multiply(mat, projection, mat);
|
||||
}
|
||||
|
||||
|
||||
static bool gles2_texture_get_dmabuf_size(struct wlr_texture *texture, struct
|
||||
wl_resource *resource, int *width, int *height) {
|
||||
if (!wlr_dmabuf_resource_is_buffer(resource)) {
|
||||
|
@ -287,7 +275,6 @@ static bool gles2_texture_get_dmabuf_size(struct wlr_texture *texture, struct
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void gles2_texture_get_buffer_size(struct wlr_texture *texture, struct
|
||||
wl_resource *resource, int *width, int *height) {
|
||||
struct wl_shm_buffer *buffer = wl_shm_buffer_get(resource);
|
||||
|
@ -344,7 +331,6 @@ static struct wlr_texture_impl wlr_texture_impl = {
|
|||
.upload_drm = gles2_texture_upload_drm,
|
||||
.upload_dmabuf = gles2_texture_upload_dmabuf,
|
||||
.upload_eglimage = gles2_texture_upload_eglimage,
|
||||
.get_matrix = gles2_texture_get_matrix,
|
||||
.get_buffer_size = gles2_texture_get_buffer_size,
|
||||
.bind = gles2_texture_bind,
|
||||
.destroy = gles2_texture_destroy,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/types/wlr_matrix.h>
|
||||
|
||||
void wlr_renderer_init(struct wlr_renderer *renderer,
|
||||
struct wlr_renderer_impl *impl) {
|
||||
|
@ -35,6 +36,17 @@ struct wlr_texture *wlr_render_texture_create(struct wlr_renderer *r) {
|
|||
return r->impl->texture_create(r);
|
||||
}
|
||||
|
||||
bool wlr_render_texture(struct wlr_renderer *r, struct wlr_texture *texture,
|
||||
const float projection[static 9], int x, int y, float alpha) {
|
||||
float mat[9];
|
||||
wlr_matrix_identity(mat);
|
||||
wlr_matrix_translate(mat, x, y);
|
||||
wlr_matrix_scale(mat, texture->width, texture->height);
|
||||
wlr_matrix_multiply(mat, projection, mat);
|
||||
|
||||
return wlr_render_texture_with_matrix(r, texture, mat, alpha);
|
||||
}
|
||||
|
||||
bool wlr_render_texture_with_matrix(struct wlr_renderer *r,
|
||||
struct wlr_texture *texture, const float matrix[static 9],
|
||||
float alpha) {
|
||||
|
|
|
@ -58,11 +58,6 @@ bool wlr_texture_upload_dmabuf(struct wlr_texture *texture,
|
|||
return texture->impl->upload_dmabuf(texture, dmabuf_resource);
|
||||
}
|
||||
|
||||
void wlr_texture_get_matrix(struct wlr_texture *texture,
|
||||
float mat[static 9], const float projection[static 9], int x, int y) {
|
||||
texture->impl->get_matrix(texture, mat, projection, x, y);
|
||||
}
|
||||
|
||||
void wlr_texture_get_buffer_size(struct wlr_texture *texture, struct wl_resource
|
||||
*resource, int *width, int *height) {
|
||||
texture->impl->get_buffer_size(texture, resource, width, height);
|
||||
|
|
Loading…
Reference in a new issue