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