present_priv.h revision 1b5d61b8
1/*
2 * Copyright © 2013 Keith Packard
3 *
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.
13 *
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
20 * OF THIS SOFTWARE.
21 */
22
23#ifndef _PRESENT_PRIV_H_
24#define _PRESENT_PRIV_H_
25
26#include <X11/X.h>
27#include "scrnintstr.h"
28#include "misc.h"
29#include "list.h"
30#include "windowstr.h"
31#include "dixstruct.h"
32#include "present.h"
33#include <syncsdk.h>
34#include <syncsrv.h>
35#include <xfixes.h>
36#include <randrstr.h>
37
38#if 0
39#define DebugPresent(x) ErrorF x
40#else
41#define DebugPresent(x)
42#endif
43
44extern int present_request;
45
46extern DevPrivateKeyRec present_screen_private_key;
47
48typedef struct present_fence *present_fence_ptr;
49
50typedef struct present_notify present_notify_rec, *present_notify_ptr;
51
52struct present_notify {
53    struct xorg_list    window_list;
54    WindowPtr           window;
55    CARD32              serial;
56};
57
58struct present_vblank {
59    struct xorg_list    window_list;
60    struct xorg_list    event_queue;
61    ScreenPtr           screen;
62    WindowPtr           window;
63    PixmapPtr           pixmap;
64    RegionPtr           valid;
65    RegionPtr           update;
66    RRCrtcPtr           crtc;
67    uint32_t            serial;
68    int16_t             x_off;
69    int16_t             y_off;
70    CARD16              kind;
71    uint64_t            event_id;
72    uint64_t            target_msc;
73    uint64_t            msc_offset;
74    present_fence_ptr   idle_fence;
75    present_fence_ptr   wait_fence;
76    present_notify_ptr  notifies;
77    int                 num_notifies;
78    Bool                queued;         /* on present_exec_queue */
79    Bool                requeue;        /* on queue, but target_msc has changed */
80    Bool                flip;           /* planning on using flip */
81    Bool                flip_ready;     /* wants to flip, but waiting for previous flip or unflip */
82    Bool                flip_idler;     /* driver explicitly permitted idling */
83    Bool                sync_flip;      /* do flip synchronous to vblank */
84    Bool                abort_flip;     /* aborting this flip */
85    PresentFlipReason   reason;         /* reason for which flip is not possible */
86    Bool                has_suboptimal; /* whether client can support SuboptimalCopy mode */
87};
88
89typedef struct present_screen_priv present_screen_priv_rec, *present_screen_priv_ptr;
90typedef struct present_window_priv present_window_priv_rec, *present_window_priv_ptr;
91
92/*
93 * Mode hooks
94 */
95typedef uint32_t (*present_priv_query_capabilities_ptr)(present_screen_priv_ptr screen_priv);
96typedef RRCrtcPtr (*present_priv_get_crtc_ptr)(present_screen_priv_ptr screen_priv,
97                                               WindowPtr window);
98
99typedef Bool (*present_priv_check_flip_ptr)(RRCrtcPtr crtc,
100                                            WindowPtr window,
101                                            PixmapPtr pixmap,
102                                            Bool sync_flip,
103                                            RegionPtr valid,
104                                            int16_t x_off,
105                                            int16_t y_off,
106                                            PresentFlipReason *reason);
107typedef void (*present_priv_check_flip_window_ptr)(WindowPtr window);
108typedef Bool (*present_priv_can_window_flip_ptr)(WindowPtr window);
109
110typedef int (*present_priv_pixmap_ptr)(WindowPtr window,
111                                       PixmapPtr pixmap,
112                                       CARD32 serial,
113                                       RegionPtr valid,
114                                       RegionPtr update,
115                                       int16_t x_off,
116                                       int16_t y_off,
117                                       RRCrtcPtr target_crtc,
118                                       SyncFence *wait_fence,
119                                       SyncFence *idle_fence,
120                                       uint32_t options,
121                                       uint64_t window_msc,
122                                       uint64_t divisor,
123                                       uint64_t remainder,
124                                       present_notify_ptr notifies,
125                                       int num_notifies);
126
127typedef void (*present_priv_create_event_id_ptr)(present_window_priv_ptr window_priv,
128                                                 present_vblank_ptr vblank);
129
130typedef int (*present_priv_queue_vblank_ptr)(ScreenPtr screen,
131                                             WindowPtr window,
132                                             RRCrtcPtr crtc,
133                                             uint64_t event_id,
134                                             uint64_t msc);
135typedef void (*present_priv_flush_ptr)(WindowPtr window);
136typedef void (*present_priv_re_execute_ptr)(present_vblank_ptr vblank);
137
138typedef void (*present_priv_abort_vblank_ptr)(ScreenPtr screen,
139                                              WindowPtr window,
140                                              RRCrtcPtr crtc,
141                                              uint64_t event_id,
142                                              uint64_t msc);
143typedef void (*present_priv_flip_destroy_ptr)(ScreenPtr screen);
144
145struct present_screen_priv {
146    CloseScreenProcPtr          CloseScreen;
147    ConfigNotifyProcPtr         ConfigNotify;
148    DestroyWindowProcPtr        DestroyWindow;
149    ClipNotifyProcPtr           ClipNotify;
150
151    present_vblank_ptr          flip_pending;
152    uint64_t                    unflip_event_id;
153
154    uint32_t                    fake_interval;
155
156    /* Currently active flipped pixmap and fence */
157    RRCrtcPtr                   flip_crtc;
158    WindowPtr                   flip_window;
159    uint32_t                    flip_serial;
160    PixmapPtr                   flip_pixmap;
161    present_fence_ptr           flip_idle_fence;
162    Bool                        flip_sync;
163
164    present_screen_info_ptr     info;
165    present_wnmd_info_ptr       wnmd_info;
166
167    /* Mode hooks */
168    present_priv_query_capabilities_ptr query_capabilities;
169    present_priv_get_crtc_ptr           get_crtc;
170
171    present_priv_check_flip_ptr         check_flip;
172    present_priv_check_flip_window_ptr  check_flip_window;
173    present_priv_can_window_flip_ptr    can_window_flip;
174
175    present_priv_pixmap_ptr             present_pixmap;
176    present_priv_create_event_id_ptr    create_event_id;
177
178    present_priv_queue_vblank_ptr       queue_vblank;
179    present_priv_flush_ptr              flush;
180    present_priv_re_execute_ptr         re_execute;
181
182    present_priv_abort_vblank_ptr       abort_vblank;
183    present_priv_flip_destroy_ptr       flip_destroy;
184};
185
186#define wrap(priv,real,mem,func) {\
187    priv->mem = real->mem; \
188    real->mem = func; \
189}
190
191#define unwrap(priv,real,mem) {\
192    real->mem = priv->mem; \
193}
194
195static inline present_screen_priv_ptr
196present_screen_priv(ScreenPtr screen)
197{
198    return (present_screen_priv_ptr)dixLookupPrivate(&(screen)->devPrivates, &present_screen_private_key);
199}
200
201/*
202 * Each window has a list of clients and event masks
203 */
204typedef struct present_event *present_event_ptr;
205
206typedef struct present_event {
207    present_event_ptr next;
208    ClientPtr client;
209    WindowPtr window;
210    XID id;
211    int mask;
212} present_event_rec;
213
214struct present_window_priv {
215    WindowPtr              window;
216    present_event_ptr      events;
217    RRCrtcPtr              crtc;        /* Last reported CRTC from get_ust_msc */
218    uint64_t               msc_offset;
219    uint64_t               msc;         /* Last reported MSC from the current crtc */
220    struct xorg_list       vblank;
221    struct xorg_list       notifies;
222
223    /* Used for window flips */
224    uint64_t               event_id;
225    struct xorg_list       exec_queue;
226    struct xorg_list       flip_queue;
227    struct xorg_list       idle_queue;
228
229    present_vblank_ptr     flip_pending;
230    present_vblank_ptr     flip_active;
231};
232
233#define PresentCrtcNeverSet     ((RRCrtcPtr) 1)
234
235extern DevPrivateKeyRec present_window_private_key;
236
237static inline present_window_priv_ptr
238present_window_priv(WindowPtr window)
239{
240    return (present_window_priv_ptr)dixGetPrivate(&(window)->devPrivates, &present_window_private_key);
241}
242
243present_window_priv_ptr
244present_get_window_priv(WindowPtr window, Bool create);
245
246/*
247 * Returns:
248 * TRUE if the first MSC value is after the second one
249 * FALSE if the first MSC value is equal to or before the second one
250 */
251static inline Bool
252msc_is_after(uint64_t test, uint64_t reference)
253{
254    return (int64_t)(test - reference) > 0;
255}
256
257/*
258 * present.c
259 */
260uint32_t
261present_query_capabilities(RRCrtcPtr crtc);
262
263RRCrtcPtr
264present_get_crtc(WindowPtr window);
265
266void
267present_copy_region(DrawablePtr drawable,
268                    PixmapPtr pixmap,
269                    RegionPtr update,
270                    int16_t x_off,
271                    int16_t y_off);
272
273void
274present_pixmap_idle(PixmapPtr pixmap, WindowPtr window, CARD32 serial, struct present_fence *present_fence);
275
276void
277present_set_tree_pixmap(WindowPtr window,
278                        PixmapPtr expected,
279                        PixmapPtr pixmap);
280
281void
282present_adjust_timings(uint32_t options,
283                       uint64_t *crtc_msc,
284                       uint64_t *target_msc,
285                       uint64_t divisor,
286                       uint64_t remainder);
287
288int
289present_pixmap(WindowPtr window,
290               PixmapPtr pixmap,
291               CARD32 serial,
292               RegionPtr valid,
293               RegionPtr update,
294               int16_t x_off,
295               int16_t y_off,
296               RRCrtcPtr target_crtc,
297               SyncFence *wait_fence,
298               SyncFence *idle_fence,
299               uint32_t options,
300               uint64_t target_msc,
301               uint64_t divisor,
302               uint64_t remainder,
303               present_notify_ptr notifies,
304               int num_notifies);
305
306int
307present_notify_msc(WindowPtr window,
308                   CARD32 serial,
309                   uint64_t target_msc,
310                   uint64_t divisor,
311                   uint64_t remainder);
312
313/*
314 * present_event.c
315 */
316
317void
318present_free_events(WindowPtr window);
319
320void
321present_send_config_notify(WindowPtr window, int x, int y, int w, int h, int bw, WindowPtr sibling);
322
323void
324present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 serial, uint64_t ust, uint64_t msc);
325
326void
327present_send_idle_notify(WindowPtr window, CARD32 serial, PixmapPtr pixmap, present_fence_ptr idle_fence);
328
329int
330present_select_input(ClientPtr client,
331                     CARD32 eid,
332                     WindowPtr window,
333                     CARD32 event_mask);
334
335Bool
336present_event_init(void);
337
338/*
339 * present_execute.c
340 */
341Bool
342present_execute_wait(present_vblank_ptr vblank, uint64_t crtc_msc);
343
344void
345present_execute_copy(present_vblank_ptr vblank, uint64_t crtc_msc);
346
347void
348present_execute_post(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc);
349
350/*
351 * present_fake.c
352 */
353int
354present_fake_get_ust_msc(ScreenPtr screen, uint64_t *ust, uint64_t *msc);
355
356int
357present_fake_queue_vblank(ScreenPtr screen, uint64_t event_id, uint64_t msc);
358
359void
360present_fake_abort_vblank(ScreenPtr screen, uint64_t event_id, uint64_t msc);
361
362void
363present_fake_screen_init(ScreenPtr screen);
364
365void
366present_fake_queue_init(void);
367
368/*
369 * present_fence.c
370 */
371struct present_fence *
372present_fence_create(SyncFence *sync_fence);
373
374void
375present_fence_destroy(struct present_fence *present_fence);
376
377void
378present_fence_set_triggered(struct present_fence *present_fence);
379
380Bool
381present_fence_check_triggered(struct present_fence *present_fence);
382
383void
384present_fence_set_callback(struct present_fence *present_fence,
385                           void (*callback)(void *param),
386                           void *param);
387
388XID
389present_fence_id(struct present_fence *present_fence);
390
391/*
392 * present_notify.c
393 */
394void
395present_clear_window_notifies(WindowPtr window);
396
397void
398present_free_window_notify(present_notify_ptr notify);
399
400int
401present_add_window_notify(present_notify_ptr notify);
402
403int
404present_create_notifies(ClientPtr client, int num_notifies, xPresentNotify *x_notifies, present_notify_ptr *p_notifies);
405
406void
407present_destroy_notifies(present_notify_ptr notifies, int num_notifies);
408
409/*
410 * present_redirect.c
411 */
412
413WindowPtr
414present_redirect(ClientPtr client, WindowPtr target);
415
416/*
417 * present_request.c
418 */
419int
420proc_present_dispatch(ClientPtr client);
421
422int
423sproc_present_dispatch(ClientPtr client);
424
425/*
426 * present_scmd.c
427 */
428void
429present_abort_vblank(ScreenPtr screen, RRCrtcPtr crtc, uint64_t event_id, uint64_t msc);
430
431void
432present_flip_destroy(ScreenPtr screen);
433
434void
435present_restore_screen_pixmap(ScreenPtr screen);
436
437void
438present_set_abort_flip(ScreenPtr screen);
439
440Bool
441present_init(void);
442
443void
444present_scmd_init_mode_hooks(present_screen_priv_ptr screen_priv);
445
446/*
447 * present_screen.c
448 */
449
450/*
451 * present_vblank.c
452 */
453void
454present_vblank_notify(present_vblank_ptr vblank, CARD8 kind, CARD8 mode, uint64_t ust, uint64_t crtc_msc);
455
456present_vblank_ptr
457present_vblank_create(WindowPtr window,
458                      PixmapPtr pixmap,
459                      CARD32 serial,
460                      RegionPtr valid,
461                      RegionPtr update,
462                      int16_t x_off,
463                      int16_t y_off,
464                      RRCrtcPtr target_crtc,
465                      SyncFence *wait_fence,
466                      SyncFence *idle_fence,
467                      uint32_t options,
468                      const uint32_t *capabilities,
469                      present_notify_ptr notifies,
470                      int num_notifies,
471                      uint64_t *target_msc,
472                      uint64_t crtc_msc);
473
474void
475present_vblank_scrap(present_vblank_ptr vblank);
476
477void
478present_vblank_destroy(present_vblank_ptr vblank);
479
480/*
481 * present_wnmd.c
482 */
483void
484present_wnmd_set_abort_flip(WindowPtr window);
485
486void
487present_wnmd_init_mode_hooks(present_screen_priv_ptr screen_priv);
488
489#endif /*  _PRESENT_PRIV_H_ */
490