Rename wlr_surface -> wlr_texture; attach -> upload

This commit is contained in:
nyorain 2017-08-08 18:02:14 +02:00
parent afd058b754
commit e167f41fde
20 changed files with 233 additions and 233 deletions

View file

@ -224,8 +224,8 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
gbm_surface_destroy(plane->gbm);
}
if (plane->wlr_surf) {
wlr_surface_destroy(plane->wlr_surf);
if (plane->wlr_tex) {
wlr_texture_destroy(plane->wlr_tex);
}
if (plane->wlr_rend) {
wlr_renderer_destroy(plane->wlr_rend);
@ -241,7 +241,7 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
plane->front = NULL;
plane->back = NULL;
plane->wlr_rend = NULL;
plane->wlr_surf = NULL;
plane->wlr_tex = NULL;
plane->cursor_bo = NULL;
}
@ -605,7 +605,7 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
// OpenGL will read the pixels out upside down,
// so we need to flip the image vertically
wlr_matrix_surface(plane->matrix, plane->width, plane->height,
wlr_matrix_texture(plane->matrix, plane->width, plane->height,
output->base->transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180);
plane->wlr_rend = wlr_gles2_renderer_init();
@ -613,8 +613,8 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
return false;
}
plane->wlr_surf = wlr_render_surface_init(plane->wlr_rend);
if (!plane->wlr_surf) {
plane->wlr_tex = wlr_render_texture_init(plane->wlr_rend);
if (!plane->wlr_tex) {
return false;
}
}
@ -633,7 +633,7 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
wlr_drm_plane_make_current(renderer, plane);
wlr_surface_attach_pixels(plane->wlr_surf, WL_SHM_FORMAT_ARGB8888,
wlr_texture_upload_pixels(plane->wlr_tex, WL_SHM_FORMAT_ARGB8888,
stride, width, height, buf);
glViewport(0, 0, plane->width, plane->height);
@ -641,8 +641,8 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
glClear(GL_COLOR_BUFFER_BIT);
float matrix[16];
wlr_surface_get_matrix(plane->wlr_surf, &matrix, &plane->matrix, 0, 0);
wlr_render_with_matrix(plane->wlr_rend, plane->wlr_surf, &matrix);
wlr_texture_get_matrix(plane->wlr_tex, &matrix, &plane->matrix, 0, 0);
wlr_render_with_matrix(plane->wlr_rend, plane->wlr_tex, &matrix);
glFinish();
glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, bo_stride);

View file

@ -32,11 +32,11 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) {
struct wl_resource *_res;
float matrix[16];
wl_list_for_each(_res, &sample->compositor.surfaces, link) {
struct wlr_surface *surface = wl_resource_get_user_data(_res);
if (surface->valid) {
wlr_surface_get_matrix(surface, &matrix,
struct wlr_texture *texture = wl_resource_get_user_data(_res);
if (texture->valid) {
wlr_texture_get_matrix(texture, &matrix,
&wlr_output->transform_matrix, 200, 200);
wlr_render_with_matrix(sample->renderer, surface, &matrix);
wlr_render_with_matrix(sample->renderer, texture, &matrix);
}
}

View file

@ -10,10 +10,10 @@ static void surface_destroy(struct wl_client *client, struct wl_resource *resour
static void surface_attach(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *buffer_resource, int32_t sx, int32_t sy) {
struct wlr_surface *surface = wl_resource_get_user_data(resource);
struct wlr_texture *texture = wl_resource_get_user_data(resource);
struct wl_shm_buffer *buffer = wl_shm_buffer_get(buffer_resource);
uint32_t format = wl_shm_buffer_get_format(buffer);
wlr_surface_attach_shm(surface, format, buffer);
wlr_texture_upload_shm(texture, format, buffer);
}
static void surface_damage(struct wl_client *client,
@ -78,13 +78,13 @@ struct wl_surface_interface surface_interface = {
};
static void destroy_surface(struct wl_resource *resource) {
struct wlr_surface *surface = wl_resource_get_user_data(resource);
wlr_surface_destroy(surface);
struct wlr_texture *surface = wl_resource_get_user_data(resource);
wlr_texture_destroy(surface);
}
static void destroy_surface_listener(struct wl_listener *listener, void *data) {
struct wl_compositor_state *state;
struct wlr_surface *surface = data;
struct wlr_texture *surface = data;
state = wl_container_of(listener, state, destroy_surface_listener);
struct wl_resource *res = NULL;
@ -101,13 +101,13 @@ static void wl_compositor_create_surface(struct wl_client *client,
struct wl_compositor_state *state = wl_resource_get_user_data(resource);
struct wl_resource *surface_resource = wl_resource_create(client,
&wl_surface_interface, wl_resource_get_version(resource), id);
struct wlr_surface *surface = wlr_render_surface_init(state->renderer);
surface->resource = surface_resource;
struct wlr_texture *texture = wlr_render_texture_init(state->renderer);
texture->resource = surface_resource;
wl_resource_set_implementation(surface_resource, &surface_interface,
surface, destroy_surface);
wl_resource_set_user_data(surface_resource, surface);
texture, destroy_surface);
wl_resource_set_user_data(surface_resource, texture);
wl_list_insert(&state->surfaces, wl_resource_get_link(surface_resource));
wl_signal_add(&surface->destroy_signal, &state->destroy_surface_listener);
wl_signal_add(&texture->destroy_signal, &state->destroy_surface_listener);
}
static void wl_compositor_create_region(struct wl_client *client,

View file

@ -23,7 +23,7 @@
struct sample_state {
struct wl_list config;
struct wlr_renderer *renderer;
struct wlr_surface *cat_texture;
struct wlr_texture *cat_texture;
};
struct output_data {
@ -52,7 +52,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
float matrix[16];
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_surface_get_matrix(sample->cat_texture, &matrix,
wlr_texture_get_matrix(sample->cat_texture, &matrix,
&wlr_output->transform_matrix, x, y);
wlr_render_with_matrix(sample->renderer,
sample->cat_texture, &matrix);
@ -205,13 +205,13 @@ int main(int argc, char *argv[]) {
compositor_init(&compositor);
state.renderer = wlr_gles2_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
wlr_surface_attach_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888,
state.cat_texture = wlr_render_texture_init(state.renderer);
wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888,
cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
compositor_run(&compositor);
wlr_surface_destroy(state.cat_texture);
wlr_texture_destroy(state.cat_texture);
wlr_renderer_destroy(state.renderer);
struct output_config *ptr, *tmp;

View file

@ -22,7 +22,7 @@
struct sample_state {
struct wlr_renderer *renderer;
struct wlr_surface *cat_texture;
struct wlr_texture *cat_texture;
list_t *touch_points;
};
@ -45,7 +45,7 @@ static void handle_output_frame(struct output_state *output, struct timespec *ts
float matrix[16];
for (size_t i = 0; i < sample->touch_points->length; ++i) {
struct touch_point *p = sample->touch_points->items[i];
wlr_surface_get_matrix(sample->cat_texture, &matrix,
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);
@ -105,12 +105,12 @@ int main(int argc, char *argv[]) {
compositor_init(&compositor);
state.renderer = wlr_gles2_renderer_init();
state.cat_texture = wlr_render_surface_init(state.renderer);
wlr_surface_attach_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888,
state.cat_texture = wlr_render_texture_init(state.renderer);
wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888,
cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data);
compositor_run(&compositor);
wlr_surface_destroy(state.cat_texture);
wlr_texture_destroy(state.cat_texture);
wlr_renderer_destroy(state.renderer);
}

View file

@ -35,7 +35,7 @@ struct wlr_drm_plane {
// Only used by cursor
float matrix[16];
struct wlr_renderer *wlr_rend;
struct wlr_surface *wlr_surf;
struct wlr_texture *wlr_tex;
struct gbm_bo *cursor_bo;
union wlr_drm_plane_props props;

View file

@ -14,8 +14,8 @@ struct pixel_format {
GLuint *shader;
};
struct wlr_surface_state {
struct wlr_surface *wlr_surface;
struct wlr_texture_state {
struct wlr_texture *wlr_texture;
GLuint tex_id;
const struct pixel_format *pixel_format;
};
@ -31,7 +31,7 @@ extern struct shaders shaders;
const struct pixel_format *gl_format_for_wl_format(enum wl_shm_format fmt);
struct wlr_surface *gles2_surface_init();
struct wlr_texture *gles2_texture_init();
extern const GLchar quad_vertex_src[];
extern const GLchar quad_fragment_src[];

View file

@ -4,30 +4,30 @@
#include <wayland-server-protocol.h>
#include <wlr/types/wlr_output.h>
struct wlr_surface;
struct wlr_texture;
struct wlr_renderer;
void wlr_renderer_begin(struct wlr_renderer *r, struct wlr_output *output);
void wlr_renderer_end(struct wlr_renderer *r);
/**
* Requests a surface handle from this renderer.
* Requests a texture handle from this renderer.
*/
struct wlr_surface *wlr_render_surface_init(struct wlr_renderer *r);
struct wlr_texture *wlr_render_texture_init(struct wlr_renderer *r);
/**
* Renders the requested surface using the provided matrix. A typical surface
* Renders the requested texture using the provided matrix. A typical texture
* rendering goes like so:
*
* struct wlr_renderer *renderer;
* struct wlr_surface *surface;
* struct wlr_texture *texture;
* float projection[16];
* float matrix[16];
* wlr_surface_get_matrix(surface, &matrix, &projection, 123, 321);
* wlr_render_with_matrix(renderer, surface, &matrix);
* wlr_texture_get_matrix(texture, &matrix, &projection, 123, 321);
* wlr_render_with_matrix(renderer, texture, &matrix);
*
* This will render the surface at <123, 321>.
* This will render the texture at <123, 321>.
*/
bool wlr_render_with_matrix(struct wlr_renderer *r,
struct wlr_surface *surface, const float (*matrix)[16]);
struct wlr_texture *texture, const float (*matrix)[16]);
/**
* Renders a solid quad in the specified color.
*/
@ -44,16 +44,16 @@ void wlr_render_colored_ellipse(struct wlr_renderer *r,
const enum wl_shm_format *wlr_renderer_get_formats(
struct wlr_renderer *r, size_t *len);
/**
* Destroys this wlr_renderer. Surfaces must be destroyed separately.
* Destroys this wlr_renderer. Textures must be destroyed separately.
*/
void wlr_renderer_destroy(struct wlr_renderer *renderer);
struct wlr_surface_impl;
struct wlr_surface_state;
struct wlr_texture_impl;
struct wlr_texture_state;
struct wlr_surface {
struct wlr_surface_impl *impl;
struct wlr_surface_state *state;
struct wlr_texture {
struct wlr_texture_impl *impl;
struct wlr_texture_state *state;
bool valid;
uint32_t format;
int width, height;
@ -62,32 +62,32 @@ struct wlr_surface {
};
/**
* Attaches a pixel buffer to this surface. The buffer may be discarded after
* Uploads a pixel buffer to this texture. The buffer may be discarded after
* calling this function.
*/
bool wlr_surface_attach_pixels(struct wlr_surface *surf,
bool wlr_texture_upload_pixels(struct wlr_texture *surf,
enum wl_shm_format format, int stride, int width, int height,
const unsigned char *pixels);
/**
* Attaches pixels from a wl_shm_buffer to this surface. The shm buffer may be
* Uploads pixels from a wl_shm_buffer to this texture. The shm buffer may be
* invalidated after calling this function.
*/
bool wlr_surface_attach_shm(struct wlr_surface *surf, uint32_t format,
bool wlr_texture_upload_shm(struct wlr_texture *surf, uint32_t format,
struct wl_shm_buffer *shm);
/**
* Prepares a matrix with the appropriate scale for the given surface and
* 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_surface_get_matrix(struct wlr_surface *surface,
void wlr_texture_get_matrix(struct wlr_texture *texture,
float (*matrix)[16], const float (*projection)[16], int x, int y);
/**
* Destroys this wlr_surface.
* Destroys this wlr_texture.
*/
void wlr_surface_destroy(struct wlr_surface *tex);
void wlr_texture_destroy(struct wlr_texture *texture);
#endif

View file

@ -16,9 +16,9 @@ struct wlr_renderer {
struct wlr_renderer_impl {
void (*begin)(struct wlr_renderer_state *state, struct wlr_output *output);
void (*end)(struct wlr_renderer_state *state);
struct wlr_surface *(*surface_init)(struct wlr_renderer_state *state);
struct wlr_texture *(*texture_init)(struct wlr_renderer_state *state);
bool (*render_with_matrix)(struct wlr_renderer_state *state,
struct wlr_surface *surface, const float (*matrix)[16]);
struct wlr_texture *texture, const float (*matrix)[16]);
void (*render_quad)(struct wlr_renderer_state *state,
const float (*color)[4], const float (*matrix)[16]);
void (*render_ellipse)(struct wlr_renderer_state *state,
@ -31,20 +31,20 @@ struct wlr_renderer_impl {
struct wlr_renderer *wlr_renderer_init(struct wlr_renderer_state *state,
struct wlr_renderer_impl *impl);
struct wlr_surface_impl {
bool (*attach_pixels)(struct wlr_surface_state *state,
struct wlr_texture_impl {
bool (*upload_pixels)(struct wlr_texture_state *state,
enum wl_shm_format format, int stride, int width, int height,
const unsigned char *pixels);
bool (*attach_shm)(struct wlr_surface_state *state, uint32_t format,
bool (*upload_shm)(struct wlr_texture_state *state, uint32_t format,
struct wl_shm_buffer *shm);
// TODO: egl
void (*get_matrix)(struct wlr_surface_state *state,
void (*get_matrix)(struct wlr_texture_state *state,
float (*matrix)[16], const float (*projection)[16], int x, int y);
void (*bind)(struct wlr_surface_state *state);
void (*destroy)(struct wlr_surface_state *state);
void (*bind)(struct wlr_texture_state *state);
void (*destroy)(struct wlr_texture_state *state);
};
struct wlr_surface *wlr_surface_init();
void wlr_surface_bind(struct wlr_surface *surface);
struct wlr_texture *wlr_texture_init();
void wlr_texture_bind(struct wlr_texture *texture);
#endif

View file

@ -10,7 +10,7 @@ void wlr_matrix_rotate(float (*output)[16], float radians);
void wlr_matrix_mul(const float (*x)[16], const float (*y)[16], float (*product)[16]);
enum wl_output_transform;
void wlr_matrix_surface(float mat[static 16], int32_t width, int32_t height,
void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
enum wl_output_transform transform);
#endif

View file

@ -49,7 +49,7 @@ struct wlr_output {
int32_t x, y;
uint32_t width, height;
struct wlr_renderer *renderer;
struct wlr_surface *texture;
struct wlr_texture *texture;
} cursor;
};

View file

@ -91,8 +91,8 @@ static void wlr_gles2_end(struct wlr_renderer_state *state) {
// no-op
}
static struct wlr_surface *wlr_gles2_surface_init(struct wlr_renderer_state *state) {
return gles2_surface_init();
static struct wlr_texture *wlr_gles2_texture_init(struct wlr_renderer_state *state) {
return gles2_texture_init();
}
static void draw_quad() {
@ -121,14 +121,14 @@ static void draw_quad() {
GL_CALL(glDisableVertexAttribArray(1));
}
static bool wlr_gles2_render_surface(struct wlr_renderer_state *state,
struct wlr_surface *surface, const float (*matrix)[16]) {
if(!surface || !surface->valid) {
wlr_log(L_ERROR, "attempt to render invalid surface");
static bool wlr_gles2_render_texture(struct wlr_renderer_state *state,
struct wlr_texture *texture, const float (*matrix)[16]) {
if(!texture || !texture->valid) {
wlr_log(L_ERROR, "attempt to render invalid texture");
return false;
}
wlr_surface_bind(surface);
wlr_texture_bind(texture);
GL_CALL(glUniformMatrix4fv(0, 1, GL_FALSE, *matrix));
// TODO: source alpha from somewhere else I guess
GL_CALL(glUniform1f(2, 1.0f));
@ -171,8 +171,8 @@ static void wlr_gles2_destroy(struct wlr_renderer_state *state) {
static struct wlr_renderer_impl wlr_renderer_impl = {
.begin = wlr_gles2_begin,
.end = wlr_gles2_end,
.surface_init = wlr_gles2_surface_init,
.render_with_matrix = wlr_gles2_render_surface,
.texture_init = wlr_gles2_texture_init,
.render_with_matrix = wlr_gles2_render_texture,
.render_quad = wlr_gles2_render_quad,
.render_ellipse = wlr_gles2_render_ellipse,
.formats = wlr_gles2_formats,

View file

@ -1,104 +0,0 @@
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <wayland-util.h>
#include <wayland-server-protocol.h>
#include <wlr/render.h>
#include <wlr/render/interface.h>
#include <wlr/render/matrix.h>
#include <wlr/util/log.h>
#include "render/gles2.h"
static bool gles2_surface_attach_pixels(struct wlr_surface_state *surface,
enum wl_shm_format format, int stride, int width, int height,
const unsigned char *pixels) {
assert(surface);
const struct pixel_format *fmt = gl_format_for_wl_format(format);
if (!fmt || !fmt->gl_format) {
wlr_log(L_ERROR, "No supported pixel format for this surface");
return false;
}
surface->wlr_surface->width = width;
surface->wlr_surface->height = height;
surface->wlr_surface->format = format;
surface->pixel_format = fmt;
GL_CALL(glGenTextures(1, &surface->tex_id));
GL_CALL(glBindTexture(GL_TEXTURE_2D, surface->tex_id));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
fmt->gl_format, fmt->gl_type, pixels));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
surface->wlr_surface->valid = true;
return true;
}
static bool gles2_surface_attach_shm(struct wlr_surface_state *surface,
uint32_t format, struct wl_shm_buffer *buffer) {
const struct pixel_format *fmt = gl_format_for_wl_format(format);
if (!fmt || !fmt->gl_format) {
wlr_log(L_ERROR, "No supported pixel format for this surface");
return false;
}
wl_shm_buffer_begin_access(buffer);
uint8_t *pixels = wl_shm_buffer_get_data(buffer);
int width = wl_shm_buffer_get_width(buffer);
int height = wl_shm_buffer_get_height(buffer);
int pitch = wl_shm_buffer_get_stride(buffer) / (fmt->bpp / 8);
surface->wlr_surface->width = width;
surface->wlr_surface->height = height;
surface->wlr_surface->format = format;
surface->pixel_format = fmt;
GL_CALL(glGenTextures(1, &surface->tex_id));
GL_CALL(glBindTexture(GL_TEXTURE_2D, surface->tex_id));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, pitch));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
fmt->gl_format, fmt->gl_type, pixels));
surface->wlr_surface->valid = true;
wl_shm_buffer_end_access(buffer);
return true;
}
static void gles2_surface_get_matrix(struct wlr_surface_state *surface,
float (*matrix)[16], const float (*projection)[16], int x, int y) {
struct wlr_surface *_surface = surface->wlr_surface;
float world[16];
wlr_matrix_identity(matrix);
wlr_matrix_translate(&world, x, y, 0);
wlr_matrix_mul(matrix, &world, matrix);
wlr_matrix_scale(&world, _surface->width, _surface->height, 1);
wlr_matrix_mul(matrix, &world, matrix);
wlr_matrix_mul(projection, matrix, matrix);
}
static void gles2_surface_bind(struct wlr_surface_state *surface) {
GL_CALL(glBindTexture(GL_TEXTURE_2D, surface->tex_id));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CALL(glUseProgram(*surface->pixel_format->shader));
}
static void gles2_surface_destroy(struct wlr_surface_state *surface) {
wl_signal_emit(&surface->wlr_surface->destroy_signal, surface->wlr_surface);
GL_CALL(glDeleteTextures(1, &surface->tex_id));
free(surface);
}
static struct wlr_surface_impl wlr_surface_impl = {
.attach_pixels = gles2_surface_attach_pixels,
.attach_shm = gles2_surface_attach_shm,
.get_matrix = gles2_surface_get_matrix,
.bind = gles2_surface_bind,
.destroy = gles2_surface_destroy,
};
struct wlr_surface *gles2_surface_init() {
struct wlr_surface_state *state = calloc(sizeof(struct wlr_surface_state), 1);
struct wlr_surface *surface = wlr_surface_init(state, &wlr_surface_impl);
state->wlr_surface = surface;
wl_signal_init(&surface->destroy_signal);
return surface;
}

104
render/gles2/texture.c Normal file
View file

@ -0,0 +1,104 @@
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <wayland-util.h>
#include <wayland-server-protocol.h>
#include <wlr/render.h>
#include <wlr/render/interface.h>
#include <wlr/render/matrix.h>
#include <wlr/util/log.h>
#include "render/gles2.h"
static bool gles2_texture_upload_pixels(struct wlr_texture_state *texture,
enum wl_shm_format format, int stride, int width, int height,
const unsigned char *pixels) {
assert(texture);
const struct pixel_format *fmt = gl_format_for_wl_format(format);
if (!fmt || !fmt->gl_format) {
wlr_log(L_ERROR, "No supported pixel format for this texture");
return false;
}
texture->wlr_texture->width = width;
texture->wlr_texture->height = height;
texture->wlr_texture->format = format;
texture->pixel_format = fmt;
GL_CALL(glGenTextures(1, &texture->tex_id));
GL_CALL(glBindTexture(GL_TEXTURE_2D, texture->tex_id));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, stride));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
fmt->gl_format, fmt->gl_type, pixels));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, 0));
texture->wlr_texture->valid = true;
return true;
}
static bool gles2_texture_upload_shm(struct wlr_texture_state *texture,
uint32_t format, struct wl_shm_buffer *buffer) {
const struct pixel_format *fmt = gl_format_for_wl_format(format);
if (!fmt || !fmt->gl_format) {
wlr_log(L_ERROR, "No supported pixel format for this texture");
return false;
}
wl_shm_buffer_begin_access(buffer);
uint8_t *pixels = wl_shm_buffer_get_data(buffer);
int width = wl_shm_buffer_get_width(buffer);
int height = wl_shm_buffer_get_height(buffer);
int pitch = wl_shm_buffer_get_stride(buffer) / (fmt->bpp / 8);
texture->wlr_texture->width = width;
texture->wlr_texture->height = height;
texture->wlr_texture->format = format;
texture->pixel_format = fmt;
GL_CALL(glGenTextures(1, &texture->tex_id));
GL_CALL(glBindTexture(GL_TEXTURE_2D, texture->tex_id));
GL_CALL(glPixelStorei(GL_UNPACK_ROW_LENGTH_EXT, pitch));
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, fmt->gl_format, width, height, 0,
fmt->gl_format, fmt->gl_type, pixels));
texture->wlr_texture->valid = true;
wl_shm_buffer_end_access(buffer);
return true;
}
static void gles2_texture_get_matrix(struct wlr_texture_state *texture,
float (*matrix)[16], const float (*projection)[16], int x, int y) {
struct wlr_texture *_texture = texture->wlr_texture;
float world[16];
wlr_matrix_identity(matrix);
wlr_matrix_translate(&world, x, y, 0);
wlr_matrix_mul(matrix, &world, matrix);
wlr_matrix_scale(&world, _texture->width, _texture->height, 1);
wlr_matrix_mul(matrix, &world, matrix);
wlr_matrix_mul(projection, matrix, matrix);
}
static void gles2_texture_bind(struct wlr_texture_state *texture) {
GL_CALL(glBindTexture(GL_TEXTURE_2D, texture->tex_id));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL_CALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL_CALL(glUseProgram(*texture->pixel_format->shader));
}
static void gles2_texture_destroy(struct wlr_texture_state *texture) {
wl_signal_emit(&texture->wlr_texture->destroy_signal, texture->wlr_texture);
GL_CALL(glDeleteTextures(1, &texture->tex_id));
free(texture);
}
static struct wlr_texture_impl wlr_texture_impl = {
.upload_pixels = gles2_texture_upload_pixels,
.upload_shm = gles2_texture_upload_shm,
.get_matrix = gles2_texture_get_matrix,
.bind = gles2_texture_bind,
.destroy = gles2_texture_destroy,
};
struct wlr_texture *gles2_texture_init() {
struct wlr_texture_state *state = calloc(sizeof(struct wlr_texture_state), 1);
struct wlr_texture *texture = wlr_texture_init(state, &wlr_texture_impl);
state->wlr_texture = texture;
wl_signal_init(&texture->destroy_signal);
return texture;
}

View file

@ -119,7 +119,7 @@ static const float transforms[][4] = {
};
// Equivilent to glOrtho(0, width, 0, height, 1, -1) with the transform applied
void wlr_matrix_surface(float mat[static 16], int32_t width, int32_t height,
void wlr_matrix_texture(float mat[static 16], int32_t width, int32_t height,
enum wl_output_transform transform) {
memset(mat, 0, sizeof(*mat) * 16);

View file

@ -1,10 +1,10 @@
wlr_files += files(
'matrix.c',
'wlr_renderer.c',
'wlr_surface.c',
'wlr_texture.c',
'gles2/pixel_format.c',
'gles2/renderer.c',
'gles2/shaders.c',
'gles2/surface.c',
'gles2/texture.c',
'gles2/util.c',
)

View file

@ -23,13 +23,13 @@ void wlr_renderer_end(struct wlr_renderer *r) {
r->impl->end(r->state);
}
struct wlr_surface *wlr_render_surface_init(struct wlr_renderer *r) {
return r->impl->surface_init(r->state);
struct wlr_texture *wlr_render_texture_init(struct wlr_renderer *r) {
return r->impl->texture_init(r->state);
}
bool wlr_render_with_matrix(struct wlr_renderer *r,
struct wlr_surface *surface, const float (*matrix)[16]) {
return r->impl->render_with_matrix(r->state, surface, matrix);
struct wlr_texture *texture, const float (*matrix)[16]) {
return r->impl->render_with_matrix(r->state, texture, matrix);
}
void wlr_render_colored_quad(struct wlr_renderer *r,

View file

@ -1,36 +0,0 @@
#include <stdlib.h>
#include <stdbool.h>
#include <wlr/render/interface.h>
struct wlr_surface *wlr_surface_init(struct wlr_surface_state *state,
struct wlr_surface_impl *impl) {
struct wlr_surface *s = calloc(sizeof(struct wlr_surface), 1);
s->state = state;
s->impl = impl;
return s;
}
void wlr_surface_destroy(struct wlr_surface *surface) {
surface->impl->destroy(surface->state);
free(surface);
}
void wlr_surface_bind(struct wlr_surface *surface) {
surface->impl->bind(surface->state);
}
bool wlr_surface_attach_pixels(struct wlr_surface *surface, uint32_t format,
int stride, int width, int height, const unsigned char *pixels) {
return surface->impl->attach_pixels(surface->state,
format, stride, width, height, pixels);
}
bool wlr_surface_attach_shm(struct wlr_surface *surface, uint32_t format,
struct wl_shm_buffer *shm) {
return surface->impl->attach_shm(surface->state, format, shm);
}
void wlr_surface_get_matrix(struct wlr_surface *surface,
float (*matrix)[16], const float (*projection)[16], int x, int y) {
surface->impl->get_matrix(surface->state, matrix, projection, x, y);
}

36
render/wlr_texture.c Normal file
View file

@ -0,0 +1,36 @@
#include <stdlib.h>
#include <stdbool.h>
#include <wlr/render/interface.h>
struct wlr_texture *wlr_texture_init(struct wlr_texture_state *state,
struct wlr_texture_impl *impl) {
struct wlr_texture *t = calloc(sizeof(struct wlr_texture), 1);
t->state = state;
t->impl = impl;
return t;
}
void wlr_texture_destroy(struct wlr_texture *texture) {
texture->impl->destroy(texture->state);
free(texture);
}
void wlr_texture_bind(struct wlr_texture *texture) {
texture->impl->bind(texture->state);
}
bool wlr_texture_upload_pixels(struct wlr_texture *texture, uint32_t format,
int stride, int width, int height, const unsigned char *pixels) {
return texture->impl->upload_pixels(texture->state,
format, stride, width, height, pixels);
}
bool wlr_texture_upload_shm(struct wlr_texture *texture, uint32_t format,
struct wl_shm_buffer *shm) {
return texture->impl->upload_shm(texture->state, format, shm);
}
void wlr_texture_get_matrix(struct wlr_texture *texture,
float (*matrix)[16], const float (*projection)[16], int x, int y) {
texture->impl->get_matrix(texture->state, matrix, projection, x, y);
}

View file

@ -89,7 +89,7 @@ struct wl_global *wlr_output_create_global(
}
void wlr_output_update_matrix(struct wlr_output *output) {
wlr_matrix_surface(output->transform_matrix, output->width, output->height, output->transform);
wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform);
}
struct wlr_output *wlr_output_create(struct wlr_output_impl *impl,
@ -144,10 +144,10 @@ bool wlr_output_set_cursor(struct wlr_output *output,
}
if (!output->cursor.texture) {
output->cursor.texture = wlr_render_surface_init(output->cursor.renderer);
output->cursor.texture = wlr_render_texture_init(output->cursor.renderer);
}
wlr_surface_attach_pixels(output->cursor.texture, WL_SHM_FORMAT_ARGB8888,
wlr_texture_upload_pixels(output->cursor.texture, WL_SHM_FORMAT_ARGB8888,
stride, width, height, buf);
return true;
@ -200,7 +200,7 @@ void wlr_output_swap_buffers(struct wlr_output *output) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float matrix[16];
wlr_surface_get_matrix(output->cursor.texture, &matrix, &output->transform_matrix,
wlr_texture_get_matrix(output->cursor.texture, &matrix, &output->transform_matrix,
output->cursor.x, output->cursor.y);
wlr_render_with_matrix(output->cursor.renderer, output->cursor.texture, &matrix);
}