compositor: Support output/buffer scaling
If you specify e.g. scale=2 in weston.ini an output section for the
X11 backend we automatically upscale all normal surfaces by this
amount. Additionally we respect a buffer_scale set on the buffer to
mean that the buffer is already in a scaled form.
This works with both the gl and the pixman renderer. The non-X
backends compile and work, but don't support changing the output
scale (they do downscale as needed due to buffer_scale though).
This also sends the new "scale" and "done" events on wl_output,
making clients aware of the scale.
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index be74eba..52d15e0 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -68,6 +68,7 @@
struct weston_buffer_reference buffer_ref;
int pitch; /* in pixels */
+ int height; /* in pixels */
};
struct gl_renderer {
@@ -552,17 +553,7 @@
vtxcnt = wl_array_add(&gr->vtxcnt, nrects * nsurf * sizeof *vtxcnt);
inv_width = 1.0 / gs->pitch;
-
- switch (es->buffer_transform) {
- case WL_OUTPUT_TRANSFORM_90:
- case WL_OUTPUT_TRANSFORM_270:
- case WL_OUTPUT_TRANSFORM_FLIPPED_90:
- case WL_OUTPUT_TRANSFORM_FLIPPED_270:
- inv_height = 1.0 / es->geometry.width;
- break;
- default:
- inv_height = 1.0 / es->geometry.height;
- }
+ inv_height = 1.0 / gs->height;
for (i = 0; i < nrects; i++) {
pixman_box32_t *rect = &rects[i];
@@ -791,7 +782,7 @@
use_shader(gr, gs->shader);
shader_uniforms(gs->shader, es, output);
- if (es->transform.enabled || output->zoom.active)
+ if (es->transform.enabled || output->zoom.active || output->scale != es->buffer_scale)
filter = GL_LINEAR;
else
filter = GL_NEAREST;
@@ -1023,9 +1014,9 @@
int32_t width, height;
pixman_region32_t buffer_damage, total_damage;
- width = output->current->width +
+ width = output->current->width * output->scale +
output->border.left + output->border.right;
- height = output->current->height +
+ height = output->current->height * output->scale +
output->border.top + output->border.bottom;
glViewport(0, 0, width, height);
@@ -1214,6 +1205,7 @@
if (wl_buffer_is_shm(buffer)) {
gs->pitch = wl_shm_buffer_get_stride(buffer) / 4;
+ gs->height = wl_shm_buffer_get_height(buffer);
gs->target = GL_TEXTURE_2D;
ensure_textures(gs, 1);
@@ -1279,6 +1271,7 @@
}
gs->pitch = buffer->width;
+ gs->height = buffer->height;
} else {
weston_log("unhandled buffer type!\n");
weston_buffer_reference(&gs->buffer_ref, NULL);