File: paint-node-test.c

package info (click to toggle)
weston 14.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,952 kB
  • sloc: ansic: 140,007; xml: 2,480; python: 106; makefile: 34; sh: 33
file content (236 lines) | stat: -rw-r--r-- 7,702 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
 * Copyright © 2016-2023 Collabora, Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <sys/mman.h>

#include "libweston-internal.h"
#include "weston-test-client-helper.h"
#include "weston-test-fixture-compositor.h"

static enum test_result_code
fixture_setup(struct weston_test_harness *harness)
{
	struct compositor_setup setup;

	compositor_setup_defaults(&setup);
	setup.renderer = WESTON_RENDERER_PIXMAN;
	setup.width = 320;
	setup.height = 240;
	setup.shell = SHELL_TEST_DESKTOP;
	setup.logging_scopes = "log,test-harness-plugin";
	setup.refresh = HIGHEST_OUTPUT_REFRESH;

	return weston_test_harness_execute_as_client(harness, &setup);
}
DECLARE_FIXTURE_SETUP(fixture_setup);

static struct buffer *
surface_commit_color(struct client *client, struct wl_surface *surface,
		     pixman_color_t *color, int width, int height)
{
	struct buffer *buf;

	buf = create_shm_buffer_a8r8g8b8(client, width, height);
	fill_image_with_color(buf->image, color);
	wl_surface_attach(surface, buf->proxy, 0, 0);
	wl_surface_damage_buffer(surface, 0, 0, width, height);
	wl_surface_commit(surface);

	return buf;
}

#define DECLARE_LIST_ITERATOR(name, parent, list, child, link)			\
static child *									\
next_##name(parent *from, child *pos)						\
{										\
	struct wl_list *entry = pos ? &pos->link : &from->list;			\
	if (entry->next == &from->list)						\
		return NULL;							\
	return container_of(entry->next, child, link);				\
}

DECLARE_LIST_ITERATOR(output, struct weston_compositor, output_list,
		      struct weston_output, link);
DECLARE_LIST_ITERATOR(pnode_from_z, struct weston_output, paint_node_z_order_list,
		      struct weston_paint_node, z_order_link);

TEST(top_surface_present_in_output_repaint)
{
	struct wet_testsuite_data *suite_data = TEST_GET_SUITE_DATA();
	struct client *client;
	struct buffer *buf;
	pixman_color_t red;

	color_rgb888(&red, 255, 0, 0);

	client = create_client_and_test_surface(100, 50, 100, 100);
	assert(client);

	/* move the pointer clearly away from our screenshooting area */
	weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);

	client_push_breakpoint(client, suite_data,
			       WESTON_TEST_BREAKPOINT_POST_REPAINT,
			       (struct wl_proxy *) client->output->wl_output);

	buf = surface_commit_color(client, client->surface->wl_surface, &red, 100, 100);

	RUN_INSIDE_BREAKPOINT(client, suite_data) {
		struct weston_compositor *compositor;
		struct weston_output *output;
		struct weston_head *head;
		struct weston_paint_node *pnode;
		struct weston_view *view;
		struct weston_surface *surface;
		struct weston_buffer *buffer;

		assert(breakpoint->template_->breakpoint ==
		       WESTON_TEST_BREAKPOINT_POST_REPAINT);
		compositor = breakpoint->compositor;
		head = breakpoint->resource;
		output = next_output(compositor, NULL);
		assert(output == head->output);
		assert(strcmp(output->name, "headless") == 0);
		assert(!next_output(compositor, output));

		/* check that our surface is top of the paint node list */
		pnode = next_pnode_from_z(output, NULL);
		assert(pnode);
		view = pnode->view;
		surface = view->surface;
		buffer = surface->buffer_ref.buffer;
		assert(surface->resource);
		assert(wl_resource_get_client(surface->resource) ==
		       suite_data->wl_client);
		assert(weston_view_is_mapped(view));
		assert(weston_surface_is_mapped(surface));
		assert(surface->width == 100);
		assert(surface->height == 100);
		assert(buffer->width == surface->width);
		assert(buffer->height == surface->height);
		assert(buffer->type == WESTON_BUFFER_SHM);
	}

	buffer_destroy(buf);
	client_destroy(client);
}

TEST(test_surface_unmaps_on_null)
{
	struct wet_testsuite_data *suite_data = TEST_GET_SUITE_DATA();
	struct client *client;
	struct buffer *buf;
	pixman_color_t red;

	color_rgb888(&red, 255, 0, 0);

	client = create_client_and_test_surface(100, 50, 100, 100);
	assert(client);

	/* move the pointer clearly away from our screenshooting area */
	weston_test_move_pointer(client->test->weston_test, 0, 1, 0, 2, 30);

	client_push_breakpoint(client, suite_data,
			       WESTON_TEST_BREAKPOINT_POST_REPAINT,
			       (struct wl_proxy *) client->output->wl_output);

	buf = surface_commit_color(client, client->surface->wl_surface, &red, 100, 100);

	RUN_INSIDE_BREAKPOINT(client, suite_data) {
		struct weston_compositor *compositor;
		struct weston_output *output;
		struct weston_head *head;
		struct weston_paint_node *pnode;
		struct weston_view *view;
		struct weston_surface *surface;
		struct weston_buffer *buffer;

		assert(breakpoint->template_->breakpoint ==
		       WESTON_TEST_BREAKPOINT_POST_REPAINT);
		compositor = breakpoint->compositor;
		head = breakpoint->resource;
		output = next_output(compositor, NULL);
		assert(output == head->output);
		assert(strcmp(output->name, "headless") == 0);
		assert(!next_output(compositor, output));

		/* check that our surface is top of the paint node list */
		pnode = next_pnode_from_z(output, NULL);
		assert(pnode);
		view = pnode->view;
		surface = view->surface;
		buffer = surface->buffer_ref.buffer;
		assert(wl_resource_get_client(surface->resource) ==
		       suite_data->wl_client);
		assert(weston_view_is_mapped(view));
		assert(weston_surface_is_mapped(surface));
		assert(surface->width == 100);
		assert(surface->height == 100);
		assert(buffer->width == surface->width);
		assert(buffer->height == surface->height);
		assert(buffer->type == WESTON_BUFFER_SHM);

		REARM_BREAKPOINT(breakpoint);
	}

	wl_surface_attach(client->surface->wl_surface, NULL, 0, 0);
	wl_surface_commit(client->surface->wl_surface);

	RUN_INSIDE_BREAKPOINT(client, suite_data) {
		struct weston_compositor *compositor;
		struct weston_output *output;
		struct weston_head *head;
		struct weston_paint_node *pnode;
		struct weston_view *view;
		struct weston_surface *surface;
		struct weston_buffer *buffer;

		assert(breakpoint->template_->breakpoint ==
		       WESTON_TEST_BREAKPOINT_POST_REPAINT);
		compositor = breakpoint->compositor;
		head = breakpoint->resource;
		output = next_output(compositor, NULL);
		assert(output == head->output);
		assert(strcmp(output->name, "headless") == 0);
		assert(!next_output(compositor, output));

		/* check that our NULL-buffer commit removed the surface from
		 * view */
		pnode = next_pnode_from_z(output, NULL);
		assert(pnode);
		view = pnode->view;
		surface = view->surface;
		buffer = surface->buffer_ref.buffer;
		assert(!surface->resource);
		assert(buffer->type == WESTON_BUFFER_SOLID);
	}

	buffer_destroy(buf);
	client_destroy(client);
}