libweston: change read_format to struct pixel_format_info

Everywhere we are standardising to drm_fourcc.h pixel format codes, and
using struct pixel_format_info as a general handle that allows us to
access the equivalent format in various APIs. In the name of
standardisation, convert weston_compositor::read_format to
pixel_format_info.

Pixman formats are defined CPU-endian, while DRM formats are defined
always little-endian. OpenGL has various definitions. Correctly mapping
between these when the CPU is big-endian is an extra chore we can
hopefully offload to pixel-formats.c.

GL-renderer read_format is still defined based on Pixman format, because
of the pecualiar way OpenGL defines a pixel format with
GL_UNSIGNED_BYTE. That matches the same Pixman format on big-endian but
not the same drm_fourcc.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Pekka Paalanen
2022-08-01 13:31:27 +03:00
committed by Marius Vlad
parent 03c229f4ce
commit b966fd07ea
7 changed files with 32 additions and 23 deletions
+3 -3
View File
@@ -47,9 +47,9 @@
struct weston_renderer {
int (*read_pixels)(struct weston_output *output,
pixman_format_code_t format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height);
const struct pixel_format_info *format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height);
void (*repaint_output)(struct weston_output *output,
pixman_region32_t *output_damage);
void (*flush_damage)(struct weston_surface *surface,
+3 -3
View File
@@ -38,9 +38,9 @@ struct noop_renderer {
static int
noop_renderer_read_pixels(struct weston_output *output,
pixman_format_code_t format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
const struct pixel_format_info *format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
{
return 0;
}
+9 -6
View File
@@ -94,9 +94,9 @@ get_renderer(struct weston_compositor *ec)
static int
pixman_renderer_read_pixels(struct weston_output *output,
pixman_format_code_t format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
const struct pixel_format_info *format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
{
struct pixman_output_state *po = get_output_state(output);
pixman_image_t *out_buf;
@@ -106,11 +106,11 @@ pixman_renderer_read_pixels(struct weston_output *output,
return -1;
}
out_buf = pixman_image_create_bits(format,
out_buf = pixman_image_create_bits(format->pixman_format,
width,
height,
pixels,
(PIXMAN_FORMAT_BPP(format) / 8) * width);
(PIXMAN_FORMAT_BPP(format->pixman_format) / 8) * width);
pixman_image_composite32(PIXMAN_OP_SRC,
po->hw_buffer, /* src */
@@ -914,13 +914,16 @@ pixman_renderer_output_set_buffer(struct weston_output *output,
pixman_image_t *buffer)
{
struct pixman_output_state *po = get_output_state(output);
pixman_format_code_t pixman_format;
if (po->hw_buffer)
pixman_image_unref(po->hw_buffer);
po->hw_buffer = buffer;
if (po->hw_buffer) {
output->compositor->read_format = pixman_image_get_format(po->hw_buffer);
pixman_format = pixman_image_get_format(po->hw_buffer);
output->compositor->read_format =
pixel_format_get_info_by_pixman(pixman_format);
pixman_image_ref(po->hw_buffer);
}
}
+5 -5
View File
@@ -1748,7 +1748,7 @@ gl_renderer_repaint_output(struct weston_output *output,
static int
gl_renderer_read_pixels(struct weston_output *output,
pixman_format_code_t format, void *pixels,
const struct pixel_format_info *format, void *pixels,
uint32_t x, uint32_t y,
uint32_t width, uint32_t height)
{
@@ -1758,7 +1758,7 @@ gl_renderer_read_pixels(struct weston_output *output,
x += go->borders[GL_RENDERER_BORDER_LEFT].width;
y += go->borders[GL_RENDERER_BORDER_BOTTOM].height;
switch (format) {
switch (format->pixman_format) {
case PIXMAN_a8r8g8b8:
gl_format = GL_BGRA_EXT;
break;
@@ -3883,9 +3883,9 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
}
if (weston_check_egl_extension(extensions, "GL_EXT_read_format_bgra"))
ec->read_format = PIXMAN_a8r8g8b8;
ec->read_format = pixel_format_get_info_by_pixman(PIXMAN_a8r8g8b8);
else
ec->read_format = PIXMAN_a8b8g8r8;
ec->read_format = pixel_format_get_info_by_pixman(PIXMAN_a8b8g8r8);
if (gr->gl_version < gr_gl_version(3, 0) &&
!weston_check_egl_extension(extensions, "GL_EXT_unpack_subimage")) {
@@ -3935,7 +3935,7 @@ gl_renderer_setup(struct weston_compositor *ec, EGLSurface egl_surface)
gr_gl_version_major(gr->gl_version),
gr_gl_version_minor(gr->gl_version));
weston_log_continue(STAMP_SPACE "read-back format: %s\n",
ec->read_format == PIXMAN_a8r8g8b8 ? "BGRA" : "RGBA");
ec->read_format->drm_format_name);
weston_log_continue(STAMP_SPACE "wl_shm 10 bpc formats: %s\n",
yesno(gr->has_texture_type_2_10_10_10_rev));
weston_log_continue(STAMP_SPACE "wl_shm 16 bpc formats: %s\n",
+6 -3
View File
@@ -40,6 +40,7 @@
#include "shared/timespec-util.h"
#include "backend.h"
#include "libweston-internal.h"
#include "pixel-formats.h"
#include "wcap/wcap-decode.h"
@@ -122,12 +123,14 @@ screenshooter_frame_notify(struct wl_listener *listener, void *data)
struct screenshooter_frame_listener, listener);
struct weston_output *output = l->output;
struct weston_compositor *compositor = output->compositor;
const pixman_format_code_t pixman_format =
compositor->read_format->pixman_format;
int32_t stride;
uint8_t *pixels, *d, *s;
weston_output_disable_planes_decr(output);
wl_list_remove(&listener->link);
stride = l->buffer->width * (PIXMAN_FORMAT_BPP(compositor->read_format) / 8);
stride = l->buffer->width * (PIXMAN_FORMAT_BPP(pixman_format) / 8);
pixels = malloc(stride * l->buffer->height);
if (pixels == NULL) {
@@ -148,7 +151,7 @@ screenshooter_frame_notify(struct wl_listener *listener, void *data)
wl_shm_buffer_begin_access(l->buffer->shm_buffer);
switch (compositor->read_format) {
switch (pixman_format) {
case PIXMAN_a8r8g8b8:
case PIXMAN_x8r8g8b8:
if (compositor->capabilities & WESTON_CAP_CAPTURE_YFLIP)
@@ -414,7 +417,7 @@ weston_recorder_create(struct weston_output *output, const char *filename)
header.magic = WCAP_HEADER_MAGIC;
switch (compositor->read_format) {
switch (compositor->read_format->pixman_format) {
case PIXMAN_x8r8g8b8:
case PIXMAN_a8r8g8b8:
header.format = WCAP_FORMAT_XRGB8888;