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