xref: /OK3568_Linux_fs/external/xserver/glamor/glamor_sync.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2014 Keith Packard
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun  * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun  * the above copyright notice appear in all copies and that both that copyright
7*4882a593Smuzhiyun  * notice and this permission notice appear in supporting documentation, and
8*4882a593Smuzhiyun  * that the name of the copyright holders not be used in advertising or
9*4882a593Smuzhiyun  * publicity pertaining to distribution of the software without specific,
10*4882a593Smuzhiyun  * written prior permission.  The copyright holders make no representations
11*4882a593Smuzhiyun  * about the suitability of this software for any purpose.  It is provided "as
12*4882a593Smuzhiyun  * is" without express or implied warranty.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20*4882a593Smuzhiyun  * OF THIS SOFTWARE.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include "glamor_priv.h"
25*4882a593Smuzhiyun #include "misyncshm.h"
26*4882a593Smuzhiyun #include "misyncstr.h"
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #if XSYNC
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun  * This whole file exists to wrap a sync fence trigger operation so
31*4882a593Smuzhiyun  * that we can flush GL to provide serialization between the server
32*4882a593Smuzhiyun  * and the shm fence client
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun static DevPrivateKeyRec glamor_sync_fence_key;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun struct glamor_sync_fence {
38*4882a593Smuzhiyun         SyncFenceSetTriggeredFunc set_triggered;
39*4882a593Smuzhiyun };
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun static inline struct glamor_sync_fence *
glamor_get_sync_fence(SyncFence * fence)42*4882a593Smuzhiyun glamor_get_sync_fence(SyncFence *fence)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun     return (struct glamor_sync_fence *) dixLookupPrivate(&fence->devPrivates, &glamor_sync_fence_key);
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun static void
glamor_sync_fence_set_triggered(SyncFence * fence)48*4882a593Smuzhiyun glamor_sync_fence_set_triggered (SyncFence *fence)
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun 	ScreenPtr screen = fence->pScreen;
51*4882a593Smuzhiyun 	struct glamor_sync_fence *glamor_fence = glamor_get_sync_fence(fence);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	/* Flush pending rendering operations */
54*4882a593Smuzhiyun 	glamor_block_handler(screen);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun 	fence->funcs.SetTriggered = glamor_fence->set_triggered;
57*4882a593Smuzhiyun 	fence->funcs.SetTriggered(fence);
58*4882a593Smuzhiyun 	glamor_fence->set_triggered = fence->funcs.SetTriggered;
59*4882a593Smuzhiyun 	fence->funcs.SetTriggered = glamor_sync_fence_set_triggered;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun static void
glamor_sync_create_fence(ScreenPtr screen,SyncFence * fence,Bool initially_triggered)63*4882a593Smuzhiyun glamor_sync_create_fence(ScreenPtr screen,
64*4882a593Smuzhiyun                         SyncFence *fence,
65*4882a593Smuzhiyun                         Bool initially_triggered)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun 	glamor_screen_private *glamor = glamor_get_screen_private(screen);
68*4882a593Smuzhiyun 	SyncScreenFuncsPtr screen_funcs = miSyncGetScreenFuncs(screen);
69*4882a593Smuzhiyun 	struct glamor_sync_fence *glamor_fence = glamor_get_sync_fence(fence);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	screen_funcs->CreateFence = glamor->saved_procs.sync_screen_funcs.CreateFence;
72*4882a593Smuzhiyun 	screen_funcs->CreateFence(screen, fence, initially_triggered);
73*4882a593Smuzhiyun 	glamor->saved_procs.sync_screen_funcs.CreateFence = screen_funcs->CreateFence;
74*4882a593Smuzhiyun 	screen_funcs->CreateFence = glamor_sync_create_fence;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	glamor_fence->set_triggered = fence->funcs.SetTriggered;
77*4882a593Smuzhiyun 	fence->funcs.SetTriggered = glamor_sync_fence_set_triggered;
78*4882a593Smuzhiyun }
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun Bool
glamor_sync_init(ScreenPtr screen)82*4882a593Smuzhiyun glamor_sync_init(ScreenPtr screen)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun #if XSYNC
85*4882a593Smuzhiyun 	glamor_screen_private   *glamor = glamor_get_screen_private(screen);
86*4882a593Smuzhiyun 	SyncScreenFuncsPtr      screen_funcs;
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	if (!dixPrivateKeyRegistered(&glamor_sync_fence_key)) {
89*4882a593Smuzhiyun 		if (!dixRegisterPrivateKey(&glamor_sync_fence_key,
90*4882a593Smuzhiyun 					   PRIVATE_SYNC_FENCE,
91*4882a593Smuzhiyun 					   sizeof (struct glamor_sync_fence)))
92*4882a593Smuzhiyun 			return FALSE;
93*4882a593Smuzhiyun 	}
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun #ifdef HAVE_XSHMFENCE
96*4882a593Smuzhiyun 	if (!miSyncShmScreenInit(screen))
97*4882a593Smuzhiyun 		return FALSE;
98*4882a593Smuzhiyun #else
99*4882a593Smuzhiyun 	if (!miSyncSetup(screen))
100*4882a593Smuzhiyun 		return FALSE;
101*4882a593Smuzhiyun #endif
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	screen_funcs = miSyncGetScreenFuncs(screen);
104*4882a593Smuzhiyun 	glamor->saved_procs.sync_screen_funcs.CreateFence = screen_funcs->CreateFence;
105*4882a593Smuzhiyun 	screen_funcs->CreateFence = glamor_sync_create_fence;
106*4882a593Smuzhiyun #endif
107*4882a593Smuzhiyun 	return TRUE;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun void
glamor_sync_close(ScreenPtr screen)111*4882a593Smuzhiyun glamor_sync_close(ScreenPtr screen)
112*4882a593Smuzhiyun {
113*4882a593Smuzhiyun #if XSYNC
114*4882a593Smuzhiyun         glamor_screen_private   *glamor = glamor_get_screen_private(screen);
115*4882a593Smuzhiyun         SyncScreenFuncsPtr      screen_funcs = miSyncGetScreenFuncs(screen);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun         if (screen_funcs)
118*4882a593Smuzhiyun                 screen_funcs->CreateFence = glamor->saved_procs.sync_screen_funcs.CreateFence;
119*4882a593Smuzhiyun #endif
120*4882a593Smuzhiyun }
121