2 * Copyright © 2013 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 #ifdef HAVE_XORG_CONFIG_H
24 #include <xorg-config.h>
27 #include "present_priv.h"
30 #include <misyncstr.h>
33 * Wraps SyncFence objects so we can add a SyncTrigger to find out
34 * when the SyncFence gets destroyed and clean up appropriately
37 struct present_fence
{
40 void (*callback
)(void *param
);
45 * SyncTrigger callbacks
48 present_fence_sync_check_trigger(SyncTrigger
*trigger
, XSyncValue oldval
)
50 struct present_fence
*present_fence
= container_of(trigger
, struct present_fence
, trigger
);
52 return present_fence
->callback
!= NULL
;
56 present_fence_sync_trigger_fired(SyncTrigger
*trigger
)
58 struct present_fence
*present_fence
= container_of(trigger
, struct present_fence
, trigger
);
60 if (present_fence
->callback
)
61 (*present_fence
->callback
)(present_fence
->param
);
65 present_fence_sync_counter_destroyed(SyncTrigger
*trigger
)
67 struct present_fence
*present_fence
= container_of(trigger
, struct present_fence
, trigger
);
69 present_fence
->fence
= NULL
;
72 struct present_fence
*
73 present_fence_create(SyncFence
*fence
)
75 struct present_fence
*present_fence
;
77 present_fence
= calloc (1, sizeof (struct present_fence
));
81 present_fence
->fence
= fence
;
82 present_fence
->trigger
.pSync
= (SyncObject
*) fence
;
83 present_fence
->trigger
.CheckTrigger
= present_fence_sync_check_trigger
;
84 present_fence
->trigger
.TriggerFired
= present_fence_sync_trigger_fired
;
85 present_fence
->trigger
.CounterDestroyed
= present_fence_sync_counter_destroyed
;
87 if (SyncAddTriggerToSyncObject(&present_fence
->trigger
) != Success
) {
95 present_fence_destroy(struct present_fence
*present_fence
)
98 if (present_fence
->fence
)
99 SyncDeleteTriggerFromSyncObject(&present_fence
->trigger
);
105 present_fence_set_triggered(struct present_fence
*present_fence
)
108 if (present_fence
->fence
)
109 (*present_fence
->fence
->funcs
.SetTriggered
) (present_fence
->fence
);
113 present_fence_check_triggered(struct present_fence
*present_fence
)
117 if (!present_fence
->fence
)
119 return (*present_fence
->fence
->funcs
.CheckTriggered
)(present_fence
->fence
);
123 present_fence_set_callback(struct present_fence
*present_fence
,
124 void (*callback
) (void *param
),
127 present_fence
->callback
= callback
;
128 present_fence
->param
= param
;
132 present_fence_id(struct present_fence
*present_fence
)
136 if (!present_fence
->fence
)
138 return present_fence
->fence
->sync
.id
;