2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 /** @file waitformsc.c
30 * Test that glXWaitForMscOML() waits until both it and
31 * glXGetSyncValuesOML() return a an msc that meet the target.
34 #include "piglit-util-gl.h"
35 #include "piglit-glx-util.h"
38 int piglit_width
= 50, piglit_height
= 50;
43 /* Fill the variables that will be returned as out values with
44 * junk to better detect failure there.
46 int64_t start_ust
= 0xd0, start_msc
= 0xd0, start_sbc
= 0xd0;
47 int64_t wait_ust
= 0xd0, wait_msc
= 0xd0, wait_sbc
= 0xd0;
48 int64_t current_ust
= 0xd0, current_msc
= 0xd0, current_sbc
= 0xd0;
50 bool already_wrapped
= false;
52 piglit_set_timeout(5, PIGLIT_FAIL
);
55 glXGetSyncValuesOML(dpy
, win
, &start_ust
, &start_msc
, &start_sbc
);
57 /* Wait for the MSC to be at least equal to target,
58 * with no divisor trickery.
60 target_msc
= start_msc
+ 5;
61 glXWaitForMscOML(dpy
, win
, target_msc
, 0, 0,
62 &wait_ust
, &wait_msc
, &wait_sbc
);
64 glXGetSyncValuesOML(dpy
, win
,
65 ¤t_ust
, ¤t_msc
, ¤t_sbc
);
67 if (current_msc
< target_msc
) {
68 /* The clock may have actually wrapped, in which case
69 * we need to try again because we're not doing
70 * wrapping math here for simplicity.
72 if (!already_wrapped
) {
73 already_wrapped
= true;
78 "glXGetSyncValuesOML() returned msc of %lld, "
80 (long long)current_msc
,
81 (long long)target_msc
);
84 if (wait_msc
< target_msc
) {
86 "glXWaitForMscOML() returned msc of %lld, "
89 (long long)target_msc
);
92 piglit_report_result(PIGLIT_PASS
);
99 main(int argc
, char **argv
)
101 for (int i
= 1; i
< argc
; i
++) {
102 if (!strcmp(argv
[i
], "-auto"))
103 piglit_automatic
= 1;
105 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
108 piglit_oml_sync_control_test_run(false, draw
);