summaryrefslogtreecommitdiff
path: root/tests/spec/gl-1.0/front-invalidate-back.c
blob: cdfb8e791ea3b270448cb87748594df0262c0d7d (plain)
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
/*
 * Copyright © 2013 Intel Corporation
 *
 * 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.
 */

/** @file fbo-front-invalidate-back.c
 *
 * This test validates a corner case in the Intel mesa driver: if GL
 * calls that require access to the front buffer are followed by GL
 * calls that don't require access to the front buffer, and an
 * invalidate event is received from the server in between, then
 * before the driver responds to the invalidate event by requesting a
 * new back buffer, it needs to flush the pending front buffer
 * rendering.  Otherwise the front buffer rendering will be lost.
 *
 * Unfortunately, we can't force the server to send an invalidate
 * event to the driver at a specific time; however, thanks to a quirk
 * in the driver, we can simulate one using a sequence of
 * glDrawBuffer() calls.
 */

#include "piglit-util-gl.h"

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.supports_gl_compat_version = 10;
	config.requires_displayed_window = true;
	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;

PIGLIT_GL_TEST_CONFIG_END

void
piglit_init(int argc, char **argv)
{
}

enum piglit_result
piglit_display(void)
{
	const float green[] = {0.0f, 1.0f, 0.0f};
	bool pass;

	/* Do some rendering that requires access to the front buffer
	 * (clear it to green).
	 */
	glDrawBuffer(GL_FRONT);
	glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Simulate an invalidate event using a sequence of
	 * glDrawBuffer() calls.  This takes advantage of a quirk of
	 * the Intel driver: when glDrawBuffer() is used to switch
	 * from back buffer to front buffer rendering, the driver acts
	 * as though a buffer invalidate event has occurred, so that
	 * when the next draw operation occurs, it will be sure to
	 * pick up a valid front buffer.  Therefore, we can simulate
	 * an invalidate event by switching to GL_BACK and then to
	 * GL_FRONT again.
	 */
	glDrawBuffer(GL_BACK);
	glDrawBuffer(GL_FRONT);

	/* Do some rendering that doesn't require access to the front
	 * buffer (clear the back buffer to red).  Note:
	 * gl_ReadBuffer(GL_BACK) ensures that the driver doesn't try
	 * to maintain access to the front buffer.
	 */
	glReadBuffer(GL_BACK);
	glDrawBuffer(GL_BACK);
	glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT);

	/* Check that the front buffer rendering was not lost. */
	glReadBuffer(GL_FRONT);
	pass = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height,
				     green);

	/* Since we don't do a buffer swap, flush to make sure
	 * rendering gets to the screen.
	 */
	glFlush();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}