This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch up/6b-viewporter
in repository enlightenment.
View the commit online.
commit dfea014bea6a38dba86eb6d2ea44c09c26f49bcf
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 27 21:59:20 2026 -0600
e_comp_wl - honour wl_surface.set_buffer_scale
A client on a HiDPI output draws a buffer N times larger than its
surface and says so with set_buffer_scale. E dropped the request, so
such a buffer came out N times too big.
The scale is double buffered and latched at commit, and the surface
size is the buffer size divided by it. A commit that only changes the
scale resizes the window with no new buffer, so the commit path now
also resizes when the size it works out differs from the last
commit's. It compares with its own last answer, not with ec->client,
which E changes itself (maximize) before the client catches up.
_e_comp_intercept_resize() clamps a window to its pixmap, which would
undo the scale. The comp object now knows the size a Wayland surface
is shown at and clamps to that; on X11 it is never set and nothing
changes there.
wl_surface.damage is in surface-local units and damage_buffer in
buffer pixels, so they are kept in two lists until the commit knows
the scale, sync subsurfaces included. E redraws the whole surface on
every commit, so no test can see the difference; it is converted
because that is what the protocol says. The opaque region scales the
same way, since evas counts its border in buffer pixels.
wl_test gets get_pixel (version 9), so that a test can check what was
drawn and not only its size. wl-buffer-scale checks a quadrant buffer
at scale 2 pixel by pixel, a scale change without a new buffer, and
that a scale of 0 is a protocol error. It fails without each part:
the size, the clamp, and the resize without a buffer.
The output scale is still 1, so no client is asked for a scaled
buffer yet.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_object.c | 16 +++
src/bin/e_comp_object.h | 1 +
src/bin/e_comp_wl.c | 98 ++++++++++++++----
src/bin/e_comp_wl.h | 9 +-
src/modules/wl_test/e_mod_main.c | 18 +++-
src/protocol/wl-test.xml | 18 +++-
src/tests/wayland/meson.build | 1 +
src/tests/wayland/test_buffer_scale.c | 187 ++++++++++++++++++++++++++++++++++
8 files changed, 327 insertions(+), 21 deletions(-)
diff --git a/src/bin/e_comp_object.c b/src/bin/e_comp_object.c
index 652947042..b08b79b16 100644
--- a/src/bin/e_comp_object.c
+++ b/src/bin/e_comp_object.c
@@ -72,6 +72,10 @@ typedef struct _E_Comp_Object
int bx, by, bxx, byy, w, h;
} border;
+ /* The size a Wayland surface is shown at, which a buffer scale makes
+ * differ from its buffer; 0x0 is the pixmap size. */
+ int content_w, content_h;
+
Eina_Stringshare *frame_theme;
Eina_Stringshare *frame_name;
Eina_Stringshare *visibility_effect; //effect when toggling visibility
@@ -1240,6 +1244,8 @@ _e_comp_intercept_resize(void *data, Evas_Object *obj, int w, int h)
e_comp_object_redirected_set(obj, 1);
return;
}
+ if (cw->content_w > 0)
+ pw = cw->content_w, ph = cw->content_h;
prev_w = cw->w, prev_h = cw->h;
e_comp_object_frame_wh_adjust(obj, 0, 0, &fw, &fh);
/* During an interactive resize of a wayland client the frame leads and
@@ -2636,6 +2642,8 @@ _e_comp_smart_resize(Evas_Object *obj, int w, int h)
/* verify pixmap:object size */
if (e_pixmap_size_get(cw->ec->pixmap, &pw, &ph) && (!cw->ec->override))
{
+ if (cw->content_w > 0)
+ pw = cw->content_w, ph = cw->content_h;
//INF("CW RSZ: %dx%d PIX(%dx%d)", w, h, pw, ph);
//if (cw->obj)
//{
@@ -4176,6 +4184,14 @@ e_comp_object_blank(Evas_Object *obj, Eina_Bool set)
e_comp_object_damage(obj, 0, 0, cw->w, cw->h);
}
+EINTERN void
+e_comp_object_content_size_set(Evas_Object *obj, int w, int h)
+{
+ API_ENTRY;
+ cw->content_w = w;
+ cw->content_h = h;
+}
+
/* mark an object as dirty and setup damages */
E_API void
e_comp_object_dirty(Evas_Object *obj)
diff --git a/src/bin/e_comp_object.h b/src/bin/e_comp_object.h
index ac582bfde..111c3e11f 100644
--- a/src/bin/e_comp_object.h
+++ b/src/bin/e_comp_object.h
@@ -89,6 +89,7 @@ E_API void e_comp_object_native_surface_override(Evas_Object *obj, Evas_Native_S
E_API Evas_Object *e_comp_object_agent_add(Evas_Object *obj);
E_API void e_comp_object_blank(Evas_Object *obj, Eina_Bool set);
E_API void e_comp_object_dirty(Evas_Object *obj);
+EINTERN void e_comp_object_content_size_set(Evas_Object *obj, int w, int h);
E_API Eina_Bool e_comp_object_render(Evas_Object *obj);
E_API Eina_Bool e_comp_object_effect_allowed_get(Evas_Object *obj);
E_API Eina_Bool e_comp_object_effect_set(Evas_Object *obj, const char *effect);
diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 9a3ff0ece..acc68347a 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -1510,8 +1510,9 @@ _e_comp_wl_surface_state_size_update(E_Client *ec, E_Comp_Wl_Surface_State *stat
/* } */
if (!e_pixmap_size_get(ec->pixmap, &state->bw, &state->bh)) return;
- state->bw *= e_comp_wl_client_scale_get(ec);
- state->bh *= e_comp_wl_client_scale_get(ec);
+ state->bw = (state->bw / ec->comp_data->buffer_scale) * e_comp_wl_client_scale_get(ec);
+ state->bh = (state->bh / ec->comp_data->buffer_scale) * e_comp_wl_client_scale_get(ec);
+ e_comp_object_content_size_set(ec->frame, state->bw, state->bh);
if (e_client_has_xwindow(ec) || e_comp_object_frame_exists(ec->frame)) return;
window = &ec->comp_data->shell.window;
if (window->x || window->y || window->w || window->h)
@@ -1545,6 +1546,7 @@ _e_comp_wl_surface_state_init(E_Comp_Wl_Surface_State *state)
state->buffer_destroy_listener.notify =
_e_comp_wl_surface_state_cb_buffer_destroy;
state->sx = state->sy = 0;
+ state->buffer_scale = 1;
state->input = NULL;
@@ -1569,6 +1571,8 @@ _e_comp_wl_surface_state_finish(E_Comp_Wl_Surface_State *state)
EINA_LIST_FREE(state->damages, dmg)
eina_rectangle_free(dmg);
+ EINA_LIST_FREE(state->buffer_damages, dmg)
+ eina_rectangle_free(dmg);
if (state->opaque) eina_tiler_free(state->opaque);
state->opaque = NULL;
@@ -1644,9 +1648,9 @@ _e_comp_wl_surface_input_passthrough_update(E_Client *ec, Eina_Bool parent_unmap
static void
_e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
{
- Eina_Bool first = EINA_FALSE;
+ Eina_Bool first = EINA_FALSE, resize;
Eina_Rectangle *dmg;
- int x = 0, y = 0, w, h;
+ int x = 0, y = 0, w, h, prev_w, prev_h;
first = !e_pixmap_usable_get(ec->pixmap);
#ifndef HAVE_WAYLAND_ONLY
@@ -1663,6 +1667,7 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
}
ec->comp_data->in_commit = 1;
+ ec->comp_data->buffer_scale = state->buffer_scale;
if (ec->ignored && ec->comp_data->shell.surface)
{
EC_CHANGED(ec);
@@ -1741,7 +1746,14 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
ec->comp_data->shell.set.unmaximize =
ec->comp_data->shell.set.minimize = 0;
}
+ prev_w = ec->comp_data->surface_w, prev_h = ec->comp_data->surface_h;
_e_comp_wl_surface_state_size_update(ec, state);
+ ec->comp_data->surface_w = state->bw, ec->comp_data->surface_h = state->bh;
+ /* A commit can change the size without attaching a buffer. Compared
+ * with the size the last commit worked out, not with ec->client, which
+ * E changes itself (maximize) before the client catches up. */
+ resize = (!state->new_attach) && e_pixmap_usable_get(ec->pixmap) &&
+ ((state->bw != prev_w) || (state->bh != prev_h));
if (state->new_attach)
{
@@ -1785,6 +1797,14 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
ec->comp_data->need_center = 0;
}
}
+ else if (resize)
+ {
+ x = ec->client.x, y = ec->client.y;
+ w = ec->client.w = state->bw;
+ h = ec->client.h = state->bh;
+ if (!ec->changes.size)
+ e_comp_object_frame_wh_adjust(ec->frame, w, h, &ec->w, &ec->h);
+ }
else
w = state->bw, h = state->bh;
if (!e_pixmap_usable_get(ec->pixmap))
@@ -1894,6 +1914,14 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
ec->want_focus |= ec->icccm.accepts_focus && (!ec->override);
}
}
+ else if (resize)
+ {
+ if ((ec->comp_data->shell.surface) && (ec->comp_data->shell.configure))
+ ec->comp_data->shell.configure(ec->comp_data->shell.surface,
+ x, y, state->bw, state->bh);
+ else
+ e_client_util_move_resize_without_frame(ec, x, y, w, h);
+ }
else if (ec->comp_data->need_xdg_configure && ec->comp_data->shell.surface && !ec->iconic)
_e_comp_wl_configure_send(ec, 0, EINA_FALSE);
@@ -1913,11 +1941,19 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
/* put state damages into surface */
if ((!e_comp->nocomp) && (ec->frame))
{
- EINA_LIST_FREE(state->damages, dmg)
+ int scale = ec->comp_data->buffer_scale;
+
+ EINA_LIST_FREE(state->buffer_damages, dmg)
{
e_comp_object_damage(ec->frame, dmg->x, dmg->y, dmg->w, dmg->h);
eina_rectangle_free(dmg);
}
+ EINA_LIST_FREE(state->damages, dmg)
+ {
+ e_comp_object_damage(ec->frame, dmg->x * scale, dmg->y * scale,
+ dmg->w * scale, dmg->h * scale);
+ eina_rectangle_free(dmg);
+ }
}
/* put state opaque into surface */
@@ -1927,18 +1963,24 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
{
Eina_Rectangle *rect;
Eina_Iterator *itr;
+ int scale = ec->comp_data->buffer_scale, pw = 0, ph = 0;
/* This is seriously wrong and results in only the first
* rectangle in the region being set, but in the usual
* case there's only one rectangle.
+ *
+ * It ends up in evas_object_image_border_set(), which counts
+ * in buffer pixels.
*/
+ e_pixmap_size_get(ec->pixmap, &pw, &ph);
itr = eina_tiler_iterator_new(state->opaque);
EINA_ITERATOR_FOREACH(itr, rect)
{
Eina_Rectangle r;
- EINA_RECTANGLE_SET(&r, rect->x, rect->y, rect->w, rect->h);
- E_RECTS_CLIP_TO_RECT(r.x, r.y, r.w, r.h, 0, 0, state->bw, state->bh);
+ EINA_RECTANGLE_SET(&r, rect->x * scale, rect->y * scale,
+ rect->w * scale, rect->h * scale);
+ E_RECTS_CLIP_TO_RECT(r.x, r.y, r.w, r.h, 0, 0, pw, ph);
e_pixmap_image_opaque_set(ec->pixmap, r.x, r.y, r.w, r.h);
break;
}
@@ -2086,19 +2128,23 @@ _e_comp_wl_surface_cb_damage_buffer(struct wl_client *client EINA_UNUSED, struct
if (!(dmg = eina_rectangle_new(x, y, w, h))) return;
- ec->comp_data->pending.damages =
- eina_list_append(ec->comp_data->pending.damages, dmg);
+ ec->comp_data->pending.buffer_damages =
+ eina_list_append(ec->comp_data->pending.buffer_damages, dmg);
}
-/*
- * Currently damage and damage_buffer are the same because we don't support
- * buffer_scale, transform, or viewport. Once we support those we'll have
- * to make surface_cb_damage handle damage in surface co-ordinates.
- */
static void
-_e_comp_wl_surface_cb_damage(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h)
+_e_comp_wl_surface_cb_damage(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y, int32_t w, int32_t h)
{
- _e_comp_wl_surface_cb_damage_buffer(client, resource, x, y, w, h);
+ E_Client *ec;
+ Eina_Rectangle *dmg = NULL;
+
+ if (!(ec = wl_resource_get_user_data(resource))) return;
+ if (e_object_is_del(E_OBJECT(ec))) return;
+
+ if (!(dmg = eina_rectangle_new(x, y, w, h))) return;
+
+ ec->comp_data->pending.damages =
+ eina_list_append(ec->comp_data->pending.damages, dmg);
}
static void
@@ -2250,9 +2296,20 @@ _e_comp_wl_surface_cb_buffer_transform_set(struct wl_client *client EINA_UNUSED,
}
static void
-_e_comp_wl_surface_cb_buffer_scale_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource EINA_UNUSED, int32_t scale EINA_UNUSED)
+_e_comp_wl_surface_cb_buffer_scale_set(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t scale)
{
- /* DBG("Surface Buffer Scale: %d", wl_resource_get_id(resource)); */
+ E_Client *ec;
+
+ if (!(ec = wl_resource_get_user_data(resource))) return;
+ if (e_object_is_del(E_OBJECT(ec))) return;
+
+ if (scale < 1)
+ {
+ wl_resource_post_error(resource, WL_SURFACE_ERROR_INVALID_SCALE,
+ "buffer scale %d is not positive", scale);
+ return;
+ }
+ ec->comp_data->pending.buffer_scale = scale;
}
static const struct wl_surface_interface _e_surface_interface =
@@ -2560,6 +2617,10 @@ _e_comp_wl_subsurface_commit_to_cache(E_Client *ec)
sdata->cached.damages = eina_list_merge(sdata->cached.damages,
cdata->pending.damages);
cdata->pending.damages = NULL;
+ sdata->cached.buffer_damages = eina_list_merge(sdata->cached.buffer_damages,
+ cdata->pending.buffer_damages);
+ cdata->pending.buffer_damages = NULL;
+ sdata->cached.buffer_scale = cdata->pending.buffer_scale;
if (cdata->pending.new_attach)
{
@@ -2984,6 +3045,7 @@ _e_comp_wl_client_cb_new(void *data EINA_UNUSED, E_Client *ec)
wl_signal_init(&ec->comp_data->destroy_signal);
_e_comp_wl_surface_state_init(&ec->comp_data->pending);
+ ec->comp_data->buffer_scale = 1;
/* set initial client properties */
ec->argb = EINA_TRUE;
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 25de3decf..0df451123 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -80,9 +80,12 @@ struct _E_Comp_Wl_Surface_State
int bw, bh;
E_Comp_Wl_Buffer *buffer;
struct wl_listener buffer_destroy_listener;
- Eina_List *damages, *frames;
+ /* wl_surface.damage is surface-local and damage_buffer is in buffer
+ * pixels: they only meet at commit, once the buffer scale is known. */
+ Eina_List *damages, *buffer_damages, *frames;
Eina_List *presentation_feedbacks;
Eina_Tiler *input, *opaque;
+ int buffer_scale;
Eina_Bool new_attach E_BITFIELD;
Eina_Bool has_data E_BITFIELD;
};
@@ -373,6 +376,10 @@ struct _E_Comp_Wl_Client_Data
} shell;
E_Comp_Wl_Surface_State pending;
+ /* The wl_surface.set_buffer_scale in effect, and the surface size the
+ * last commit worked out, in canvas pixels. */
+ int buffer_scale;
+ int surface_w, surface_h;
Eina_List *frames;
/* wp_presentation_feedback of the committed content, which is waiting
diff --git a/src/modules/wl_test/e_mod_main.c b/src/modules/wl_test/e_mod_main.c
index 982d3be42..9de6494b9 100644
--- a/src/modules/wl_test/e_mod_main.c
+++ b/src/modules/wl_test/e_mod_main.c
@@ -340,6 +340,21 @@ _wl_test_cb_key_modified(struct wl_client *client EINA_UNUSED, struct wl_resourc
e_comp_wl_input_keyboard_event_generate(keyname, modifiers, !pressed);
}
+static void
+_wl_test_cb_get_pixel(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y)
+{
+ const unsigned int *pixels = NULL;
+ unsigned int argb = 0;
+ int w, h;
+
+ ecore_evas_geometry_get(e_comp->ee, NULL, NULL, &w, &h);
+ if (!strcmp(ecore_evas_engine_name_get(e_comp->ee), "buffer"))
+ pixels = ecore_evas_buffer_pixels_get(e_comp->ee);
+ if (pixels && (x >= 0) && (y >= 0) && (x < w) && (y < h))
+ argb = pixels[(y * w) + x];
+ wl_test_send_pixel(resource, x, y, argb);
+}
+
static void
_wl_test_cb_get_screensaver(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
{
@@ -626,6 +641,7 @@ static const struct wl_test_interface _wl_test_implementation =
_wl_test_cb_screensaver_configure,
_wl_test_cb_get_screensaver,
_wl_test_cb_key_modified,
+ _wl_test_cb_get_pixel,
};
static void
@@ -659,7 +675,7 @@ e_modapi_init(E_Module *m)
return NULL;
}
- _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 8,
+ _wl_test_global = wl_global_create(e_comp_wl->wl.disp, &wl_test_interface, 9,
NULL, _wl_test_cb_bind);
if (!_wl_test_global)
{
diff --git a/src/protocol/wl-test.xml b/src/protocol/wl-test.xml
index 50e0659e2..f1049d1fe 100644
--- a/src/protocol/wl-test.xml
+++ b/src/protocol/wl-test.xml
@@ -23,7 +23,7 @@
DEALINGS IN THE SOFTWARE.
</copyright>
- <interface name="wl_test" version="8">
+ <interface name="wl_test" version="9">
<description summary="private interface for the compositor test suite">
A back door into the compositor for its own test suite. It exposes
internal state and synthesises input, so it is only built with
@@ -346,5 +346,21 @@
<entry name="alt" value="0x4"/>
<entry name="win" value="0x8"/>
</enum>
+
+ <request name="get_pixel" since="9">
+ <description summary="read a pixel of the composited screen">
+ Renders the canvas and answers with a pixel event, so that a test
+ can check what E drew and not only where. Only the buffer backend
+ has pixels to read; elsewhere the answer is 0.
+ </description>
+ <arg name="x" type="int"/>
+ <arg name="y" type="int"/>
+ </request>
+
+ <event name="pixel" since="9">
+ <arg name="x" type="int"/>
+ <arg name="y" type="int"/>
+ <arg name="argb" type="uint"/>
+ </event>
</interface>
</protocol>
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index fd161142e..41b8f5fa3 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -88,6 +88,7 @@ wl_protocol_tests = [
['xdg-decoration', 'test_xdg_decoration.c'],
['shm-truncate', 'test_shm_truncate.c'],
['output', 'test_output.c'],
+ ['buffer-scale', 'test_buffer_scale.c'],
['activation', 'test_activation.c'],
['activation-expiry', 'test_activation.c',
{'E_TEST_ACTIVATION_TOKEN_LIFETIME': '1'}],
diff --git a/src/tests/wayland/test_buffer_scale.c b/src/tests/wayland/test_buffer_scale.c
new file mode 100644
index 000000000..64d11d254
--- /dev/null
+++ b/src/tests/wayland/test_buffer_scale.c
@@ -0,0 +1,187 @@
+/* wl_surface.set_buffer_scale: a buffer of scale N is drawn N times
+ * smaller. */
+#define _GNU_SOURCE 1
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <time.h>
+
+#include "e_wl_testkit.h"
+
+#define PROG "test-buffer-scale"
+#define APP_ID "e.test.buffer-scale"
+
+#define TL 0xffff0000
+#define TR 0xff00ff00
+#define BL 0xff0000ff
+#define BR 0xffffff00
+
+typedef struct
+{
+ Tk *tk;
+ struct wl_test *tester;
+ struct wl_shm *shm;
+ int configured;
+ unsigned int argb;
+ int answered;
+} Ctx;
+
+static void
+_pixel(void *data, struct wl_test *t __attribute__((unused)),
+ int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+ uint32_t argb)
+{
+ Ctx *ctx = data;
+
+ ctx->argb = argb;
+ ctx->answered = 1;
+}
+
+/* Only the requests this test sends are answered on its own wl_test. */
+static const struct wl_test_listener _tester_listener =
+{
+ .pixel = _pixel
+};
+
+static void
+_configure(void *data, struct xdg_surface *xdg_surface, uint32_t serial)
+{
+ Ctx *ctx = data;
+
+ xdg_surface_ack_configure(xdg_surface, serial);
+ ctx->configured = 1;
+}
+
+static const struct xdg_surface_listener _xdg_surface_listener =
+{
+ _configure
+};
+
+/* A buffer of four solid quadrants. */
+static struct wl_buffer *
+_buffer(Ctx *ctx, int w, int h)
+{
+ uint32_t colors[4] = { TL, TR, BL, BR };
+ struct wl_shm_pool *pool;
+ struct wl_buffer *buffer;
+ uint32_t *pixels;
+ int fd, x, y;
+
+ fd = memfd_create(PROG, MFD_CLOEXEC);
+ if ((fd < 0) || (ftruncate(fd, w * h * 4) < 0))
+ tk_fail(ctx->tk, "cannot make a %dx%d buffer", w, h);
+ pixels = mmap(NULL, w * h * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ if (pixels == MAP_FAILED) tk_fail(ctx->tk, "cannot map a buffer");
+ for (y = 0; y < h; y++)
+ for (x = 0; x < w; x++)
+ pixels[(y * w) + x] = colors[((y >= h / 2) * 2) + (x >= w / 2)];
+ munmap(pixels, w * h * 4);
+ pool = wl_shm_create_pool(ctx->shm, fd, w * h * 4);
+ buffer = wl_shm_pool_create_buffer(pool, 0, w, h, w * 4,
+ WL_SHM_FORMAT_ARGB8888);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+ return buffer;
+}
+
+static unsigned int
+_pixel_get(Ctx *ctx, int x, int y)
+{
+ ctx->answered = 0;
+ wl_test_get_pixel(ctx->tester, x, y);
+ tk_sync(ctx->tk);
+ if (!ctx->answered) tk_fail(ctx->tk, "no answer to get_pixel");
+ return ctx->argb;
+}
+
+/* The theme animates a window being shown. */
+static void
+_pixel_wait(Ctx *ctx, int x, int y, unsigned int want, const char *what)
+{
+ struct timespec step = { 0, 50000000 };
+ unsigned int argb = 0;
+ int i;
+
+ for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
+ {
+ argb = _pixel_get(ctx, x, y);
+ if (argb == want) return;
+ nanosleep(&step, NULL);
+ }
+ tk_fail(ctx->tk, "%s: pixel %d,%d is %#x, wanted %#x", what, x, y,
+ argb, want);
+}
+
+static void
+_size_check(Ctx *ctx, struct wl_surface *surface, int w, int h,
+ const char *what)
+{
+ int sw, sh;
+
+ tk_surface_geometry(ctx->tk, surface, NULL, NULL, &sw, &sh);
+ if ((sw != w) || (sh != h))
+ tk_fail(ctx->tk, "%s: the window is %dx%d, wanted %dx%d", what, sw, sh,
+ w, h);
+}
+
+int
+main(void)
+{
+ struct xdg_surface *xdg_surface;
+ struct xdg_toplevel *toplevel;
+ struct wl_surface *surface;
+ Ctx ctx = { 0 };
+ int x, y;
+
+ ctx.tk = tk_connect(PROG);
+ ctx.tester = tk_bind(ctx.tk, &wl_test_interface, 9);
+ ctx.shm = tk_bind(ctx.tk, &wl_shm_interface, 1);
+ if (!ctx.tester) tk_fail(ctx.tk, "no wl_test version 9");
+ wl_test_add_listener(ctx.tester, &_tester_listener, &ctx);
+
+ surface = tk_surface_new(ctx.tk);
+ xdg_surface = xdg_wm_base_get_xdg_surface(tk_wm_base(ctx.tk), surface);
+ xdg_surface_add_listener(xdg_surface, &_xdg_surface_listener, &ctx);
+ toplevel = xdg_surface_get_toplevel(xdg_surface);
+ xdg_toplevel_set_app_id(toplevel, APP_ID);
+ wl_surface_commit(surface);
+ while (!ctx.configured)
+ wl_display_dispatch(tk_display(ctx.tk));
+
+ wl_surface_set_buffer_scale(surface, 2);
+ wl_surface_attach(surface, _buffer(&ctx, 200, 200), 0, 0);
+ wl_surface_damage_buffer(surface, 0, 0, 200, 200);
+ wl_surface_commit(surface);
+ tk_settle(ctx.tk);
+ tk_expect(ctx.tk, APP_ID);
+ _size_check(&ctx, surface, 100, 100, "a 200x200 buffer at scale 2");
+
+ /* The cursor is drawn on the same canvas. */
+ tk_pointer_warp(ctx.tk, 1023, 767);
+ tk_surface_geometry(ctx.tk, surface, &x, &y, NULL, NULL);
+ _pixel_wait(&ctx, x + 25, y + 25, TL, "top left quadrant");
+ _pixel_wait(&ctx, x + 75, y + 25, TR, "top right quadrant");
+ _pixel_wait(&ctx, x + 25, y + 75, BL, "bottom left quadrant");
+ _pixel_wait(&ctx, x + 75, y + 75, BR, "bottom right quadrant");
+
+ /* A new scale resizes the window without a new buffer. */
+ wl_surface_set_buffer_scale(surface, 1);
+ wl_surface_commit(surface);
+ tk_settle(ctx.tk);
+ _size_check(&ctx, surface, 200, 200,
+ "the same buffer at scale 1, without a new attach");
+ _pixel_wait(&ctx, x + 150, y + 150, BR, "bottom right quadrant at scale 1");
+
+ wl_surface_set_buffer_scale(surface, 0);
+ if (tk_protocol_error(ctx.tk, NULL) != WL_SURFACE_ERROR_INVALID_SCALE)
+ {
+ fprintf(stderr, PROG ": a buffer scale of 0 was accepted\n");
+ return 1;
+ }
+
+ tk_disconnect(ctx.tk);
+ printf(PROG ": ok\n");
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.