tizen 2.4 release
[framework/uifw/xorg/proto/x11proto-present.git] / presentproto.txt
1                         The Present Extension
2                              Version 1.0
3                                2013-6-6
4       
5                             Keith Packard
6                           keithp@keithp.com
7                           Intel Corporation
8
9 1. Introduction
10
11 The Present extension provides a way for applications to update their
12 window contents from a pixmap in a well defined fashion, synchronizing
13 with the display refresh and potentially using a more efficient
14 mechanism than copying the contents of the source pixmap.
15
16 1.1. Acknowledgments
17
18 Eric Anholt <eric@anholt.net>
19 Owen Taylor <otaylor@redhat.com>
20 James Jones <janomes@nvidia.com>
21
22                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
23
24 2. Data Types
25
26 PRESENTEVENTID { XID }
27
28         Defines a unique event delivery target for Present
29         events. Multiple event IDs can be allocated to provide
30         multiple distinct event delivery contexts.
31
32 PRESENTNOTIFY {
33         window: WINDOW
34         serial: CARD32
35         }
36
37         A list of these is passed to PresentPixmap; when the indicated
38         PresentPixmap completes, PresentCompletNotify events will be
39         delivered both to the PresentPixmap window/serial parameter as
40         well as each of the entries in the list of PRESENTNOTIFY parameter.
41
42 PRESENTEVENTTYPE { PresentConfigureNotify,
43                    PresentCompleteNotify,
44                    PresentIdleNotify,
45                    PresentRedirectNotify }
46
47 PRESENTEVENTMASK { PresentConfigureNotifyMask,
48                    PresentCompleteNotifyMask,
49                    PresentIdleNotifyMask,
50                    PresentSubredirectNotifyMask }
51
52 PRESENTOPTION { PresentOptionAsync,
53                 PresentOptionCopy,
54                 PresentOptionUST }
55
56 PRESENTCAPABILITY { PresentCapabilityAsync,
57                     PresentCapabilityFence,
58                     PresentCapabilityUST }
59
60 PRESENTCOMPLETEKIND { PresentCompleteKindPixmap,
61                       PresentCompleteKindMSCNotify }
62
63 PRESENTCOMPLETEMODE { PresentCompleteModeCopy,
64                       PresentCompleteModeFlip,
65                       PresentCompleteModeSkip }
66
67 The Present extension also uses the Sync extension Fence data type to
68 provide synchronization for pixmaps.
69
70                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
71
72 3. Errors
73
74 EventID
75         A value for an EventID argument does not name a defined EventID
76
77                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
78
79 5. Events
80
81 ConfigureNotify events inform clients about window configuration
82 changes which can affect the allocation of window-related buffers.
83
84 CompleteNotify events inform clients about the completion of a pending
85 PresentPixmap request.
86
87 IdleNotify events inform clients when pixmaps are available for re-use.
88
89 RedirectNotify events inform clients about other clients PresentPixmap
90 requests.
91
92                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
93
94 6. Extension Initialization
95
96 The name of this extension is "Present"
97
98 ┌───
99     PresentQueryVersion
100         client-major-version:   CARD32
101         client-minor-version:   CARD32
102       ▶
103         major-version:          CARD32
104         minor-version:          CARD32
105 └───
106
107         The client sends the highest supported version to the server
108         and the server sends the highest version it supports, but no
109         higher than the requested version. Major versions changes can
110         introduce incompatibilities in existing functionality, minor
111         version changes introduce only backward compatible changes.
112         It is the clients responsibility to ensure that the server
113         supports a version which is compatible with its expectations.
114
115         Backwards compatible changes included addition of new
116         requests.
117
118                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
119
120 7. Extension Requests
121
122 ┌───
123     PresentPixmap
124         window: WINDOW
125         pixmap: PIXMAP
126         serial: CARD32
127         valid-area: REGION or None
128         update-area: REGION or None
129         x-off, y-off: INT16
130         target-crtc: CRTC or None
131         wait-fence: FENCE
132         idle-fence: FENCE
133         options: SETofPRESENTOPTION
134         target-msc: CARD64
135         divisor: CARD64
136         remainder: CARD64
137         notifies: LISTofPRESENTNOTIFY
138 └───
139         Errors: Window, Pixmap, Match
140
141         Provides new content for the specified window, to be made
142         visible at the specified time (defined by 'target-msc', 'divisor'
143         and 'remainder'). If the depth of 'pixmap' and 'window' do not
144         match, a Match error will be generated.
145
146         'serial' is an arbitrary client-specified value which will
147         be returned in the associated PresentCompleteNotify event so
148         that the client can associate the event and request.
149
150         'valid-area' defines the portion of 'pixmap' which contains
151         valid window contents, or None if the pixmap contains valid
152         contents for the whole window.
153
154         'update-area' defines the subset of the window to be updated,
155         or None if the whole window is to be updated.
156
157         PresentPixmap may use any region of 'pixmap' which contains
158         'update-area' and which is contained by 'valid-area'. In other
159         words, areas inside 'update-area' will be presented from
160         'pixmap', areas outside 'valid-area' will not be presented
161         from 'pixmap' and areas inside 'valid-area' but outside
162         'update-area' may or may not be presented at the discretion of
163         the X server.
164
165         'x-off' and 'y-off' define the location in the window where
166         the 0,0 location of the pixmap will be presented. valid-area
167         and update-area are relative to the pixmap.
168
169         PresentPixmap will block until 'wait-fence' is triggered.
170         
171         When the X server has finished using 'pixmap' for this
172         operation, it will send a PresentIdleNotify event and arrange
173         for any 'idle-fence' to be triggered. This may be at any time
174         following the PresentPixmap request -- the contents may be
175         immediately copied to another buffer, copied just in time for
176         the vblank interrupt or the pixmap may be used directly for
177         display (in which case it will be busy until some future
178         PresentPixmap operation).
179
180         If 'idle-fence' is not None, then the client guarantees to the
181         X server that it will wait for that fence to be signalled
182         before it uses the pixmap again. If 'idle-fence' is None, then
183         the X server must arrange for the pixmap to be re-usable by
184         the client as soon as the PresentIdleNotify event has been
185         received. Note that if PresentCapabilityFence is set for the
186         associated CRTC, then clients should use fences to improve
187         overall systme performance. If PresentCapabilityFence is not
188         set, then using fences offers no benefit, but also no cost.
189
190         If 'target-msc' is greater than the current msc for 'window',
191         the presentation will occur at (or after) the 'target-msc'
192         field. Otherwise, the presentation will occur after the next
193         field where msc % 'divisor' == 'remainder'.
194         
195         If 'target-crtc' is None, then the X server will choose a
196         suitable CRTC for synchronization.
197         
198         If 'options' contains PresentOptionAsync, and the 'target-msc'
199         is less than or equal to the current msc for 'window', then
200         the operation will be performed as soon as possible, not
201         necessarily waiting for the next vertical blank interval.
202
203         If 'options' contains PresentOptionCopy, then 'pixmap' will be
204         idle, and 'idle-fence' triggered as soon as the operation occurs.
205
206         If 'options' contains PresentOptionUST, then target-msc,
207         divisor and remainder will all be interpreted as UST values
208         instead of MSC values and the frame update will be scheduled
209         for the specified UST time, If the target-crtc supports
210         PresentCapabilityUST, then the swap time will be as close to
211         the target time as the driver can manage. Otherwise, the
212         server will take the target UST time and convert it to a
213         suitable target MSC value.
214
215         After the presentation occurs, a PresentCompleteNotify event
216         with kind PresentCompleteKindPixmap will be generated, both to
217         'window' as well as all members of 'notifies'.
218
219         If 'window' is destroyed before the presentation occurs, then
220         the presentation action will not be completed.
221
222         PresentPixmap holds a reference to 'pixmap' until the
223         presentation occurs, so 'pixmap' may be immediately freed
224         after the request executes, even if that is before the
225         presentation occurs.
226
227         If 'idle-fence' is destroyed before the presentation occurs,
228         then idle-fence will not be signaled but the presentation will
229         occur normally.
230
231         If 'wait-fence' is destroyed before it becomes triggered, then
232         the presentation operation will no longer wait for it and will
233         occur when the other conditions are satisfied.
234
235 ┌───
236     PresentNotifyMSC
237         window: WINDOW
238         serial: CARD32
239         target-msc: CARD64
240         divisor: CARD64
241         remainder: CARD64
242 └───
243         Errors: Window
244
245         Delivers a PresentCompleteNotifyEvent with kind
246         PresentCompleteKindNotifyMSC after the time specified by
247         'target-msc', 'divisor' and 'remainder').
248
249         'serial' is an arbitrary client-specified value which will be
250         returned in the event so that the client can associate the
251         event and request.
252
253         If 'target-msc' is greater than the current msc for 'window',
254         the event will be delivered at (or after) the 'target-msc'
255         field. Otherwise, the event delivery will occur after the next
256         field where msc % 'divisor' == 'remainder'.
257         
258         If 'window' is destroyed before the event is delivered, then
259         the event delivery will not be completed.
260
261 ┌───
262     PresentSelectInput
263         event-id: PRESENTEVENTID
264         window: WINDOW
265         eventMask: SETofPRESENTEVENT
266 └───
267         Errors: Window, Value, Match, IDchoice, Access
268
269         Selects the set of Present events to be delivered for the
270         specified window and event context. PresentSelectInput can
271         create, modifiy or delete event contexts. An event context is
272         associated with a specific window; using an existing event
273         context with a different window generates a Match error.
274
275         If eventContext specifies an existing event context, then if
276         eventMask is empty, PresentSelectInput deletes the specified
277         context, otherwise the specified event context is changed to
278         select a different set of events.
279
280         If eventContext is an unused XID, then if eventMask is empty
281         no operation is performed. Otherwise, a new event context is
282         created selecting the specified events.
283
284         Specifying PresentSubredirectNotify Mask causes PresentPixmap
285         requests on any child of 'window' from other clients to
286         generate PresentRedirectNotify events to 'window' instead of
287         actually performing the operation. However, only one client at
288         a time can select for PresentRedirect on a window. An attempt
289         to violate this restriction results in an Access error.
290
291 ┌───
292     PresentQueryCapabilities
293         target:                 CRTC or WINDOW
294       ▶
295         capabilities:           SETofPRESENTCAPABILITY
296 └───
297         Errors: Window, CRTC
298
299         Returns the supported capabilities for the target CRTC.  If
300         'target' is a CRTC, then it is used as the target CRTC.  If
301         'target' is a WINDOW, then the target CRTC is selected by the
302         X server from among the CRTCs on the screen specified by the window.
303
304         PresentCapabilityAsync means that the target device can flip
305         the scanout buffer mid-frame instead of waiting for a vertical
306         blank interval. The precise latency between the flip request
307         and the actual scanout transition is not defined by this
308         specification, but is intended to be no more than a few
309         scanlines.
310
311         PresentCapabilityFence means that the target device can take
312         advantage of SyncFences in the Present operations to improve
313         GPU throughput. The driver must operate correctly in the
314         absense of fences, but may have reduced performance. Using
315         fences for drivers not advertising this capability should have
316         no performance impact.
317
318         PresentCapabilityUST means that the target device can scanout
319         the image at an arbitrary UST time value, and is not driven by
320         a periodic scanout timer. Applications specifying UST times
321         for PresentPixmap can expect that their image will appear to
322         the user within a short amount of time from that specified in
323         the request. The precise accuracy of the scanout time is not
324         defined by the extension, but is expected to be on the order
325         of milliseconds or less.
326
327                              ❄ ❄ ❄  ❄  ❄ ❄ ❄ 
328
329 8. Extension Events
330
331 ┌───
332     PresentConfigureNotify
333         type: CARD8                     XGE event type (35)
334         extension: CARD8                Present extension request number
335         sequence-number: CARD16
336         length: CARD32                  2
337         evtype: CARD16                  Present_ConfigureNotify
338         eventID: PRESENTEVENTID
339         window: WINDOW
340         x: INT16
341         y: INT16
342         width: CARD16
343         height: CARD16
344         off_x: INT16
345         off_y: INT16
346         pixmap_width: CARD16
347         pixmap_height: CARD16
348         pixmap_flags: CARD32
349 └───
350
351         PresentConfigureNotify events are sent when the window
352         configuration changes if PresentSelectInput has requested
353         it. PresentConfigureNotify events are XGE events and so do not
354         have a unique event type.
355
356         'x' and 'y' are the parent-relative location of 'window'. 
357
358 ┌───
359     PresentCompleteNotify
360         type: CARD8                     XGE event type (35)
361         extension: CARD8                Present extension request number
362         sequence-number: CARD16
363         length: CARD32                  2
364         evtype: PRESENTEVENTTYPE        PresentCompleteNotify
365         eventID: PRESENTEVENTID
366         window: WINDOW
367         kind: PRESENTCOMPLETEKIND
368         mode: PRESENTCOMPLETEMODE
369         serial: CARD32
370         ust: CARD64
371         msc: CARD64
372 └───
373
374         CompleteNotify events are delivered when a PresentPixmap or
375         PresentNotifyMSC operation has completed.
376
377         'kind' is PresentCompleteKindPixmap when generated by a
378         PresentPixmap operation completion or
379         PresentCompleteKindNotifyMsc when generated by a
380         PresentNotifyMSC operation completion.
381
382         'mode' is PresentCompleteModeCopy when the source pixmap
383         contents are taken from the pixmap and the pixmap is idle
384         immediately after the presentation completes. 'mode' is
385         PresentCompleteModeFlip when the pixmap remains in-use even
386         after the presentation completes. It will become idle no later
387         than when the next PresentPixmap operation targeting the same
388         window by any client completes. If the presentation operation
389         was skipped because some later operation made it irrelevant,
390         then 'mode' will be PresentCompleteModeSkip.
391
392         'serial' is the value provided in the generating PresentPixmap
393         request.
394
395         'msc' and 'ust' indicate the frame count and system time when
396         the presentation actually occurred.
397
398 ┌───
399     PresentIdleNotify
400         type: CARD8                     XGE event type (35)
401         extension: CARD8                Present extension request number
402         sequence-number: CARD16
403         length: CARD32                  0
404         evtype: PRESENTEVENTTYPE        PresentIdleNotify
405         eventID: PRESENTEVENTID
406         window: WINDOW
407         serial: CARD32
408         pixmap: PIXMAP
409         idle-fence: FENCE
410 └───
411
412         IdleNotify events are delivered when a pixmap used in a
413         PresentPixmap operation may be re-used by the client.
414
415         'window' is the window from the PresentPixmap to which this
416         event is delivered.
417
418         'serial' is the value provided in the associated PresentPixmap
419         request.
420
421         'pixmap' is the pixmap which is ready for re-use.
422
423         'idle-fence' is the fence which was provided in the
424         originating PresentPixmap request and is used to synchronize
425         rendering between the client and the X server's use of the
426         buffer. If not None, then the client must wait for the fence
427         to be signaled before using the pixmap.
428
429 ┌───
430     PresentRedirectNotify
431         type: CARD8                     XGE event type (35)
432         extension: CARD8                Present extension request number
433         sequence-number: CARD16
434         length: CARD32                  17 + 2 n
435         evtype: CARD16                  Present_RedirectNotify
436         update-window: BOOL
437
438         eventID: PRESENTEVENTID
439         event-window: WINDOW
440         window: WINDOW
441         pixmap: PIXMAP
442         serial: CARD32
443
444         valid-area: REGION
445         update-area: REGION
446         valid-rect: RECTANGLE
447         update-rect: RECTANGLE
448         x-off, y-off: INT16
449         target-crtc: CRTC
450         wait-fence: FENCE
451         idle-fence: FENCE
452         options: SETofPRESENTOPTION
453         target-msc: CARD64
454         divisor: CARD64
455         remainder: CARD64
456         notifies: LISTofPRESENTNOTIFY
457 └───
458
459         RedirectNotify events are delivered when the client has
460         selected for SubredirectNotify the parent of the target
461         window. All of the values provided to the PresentPixmap
462         request are provided. If the client simply passes these
463         parameters back to the X server, the effect will be as if the
464         original client executed the request.
465
466         If 'update-window' is TRUE, then there are clients who have
467         requested composite automatic redirect on the window and who
468         presumably expect the window buffer to eventually contain
469         the application provided contents. The compositing manager
470         should at least occasionally update the window buffer with
471         suitable contents. The precise update interval is left to the
472         discretion of the client receiving this event.
473
474                              ❄ ❄ ❄  ❄  ❄ ❄ ❄
475
476 9. Extension Versioning
477
478         1.0: First published version
479
480                              ❄ ❄ ❄  ❄  ❄ ❄ ❄
481
482
483 10. Relationship with other extensions
484
485 As an extension designed to support other extensions, there is
486 naturally some interactions with other extensions.
487
488 10.1 GLX
489
490 GLX is both an application interface and an X extension. OpenGL
491 applications using the GLX API will use the GLX extension and may use
492 the Present extension to display application contents.
493
494 10.2 DRI3
495
496 The DRI3 extension provides a way to share direct rendered pixel data
497 with the X server as X pixmaps. When used in conjunction with Present,
498 they provide a complete direct rendering solution for OpenGL or other
499 APIs.
500
501 10.3 DRI2
502
503 Present provides similar functionality to the DRI2SwapBuffers and
504 requests, however Present uses X pixmaps to refer to the new window
505 contents instead of the DRI2 buffer attachments.
506
507 Present and DRI3 are designed in conjunction to replace DRI2
508
509 10.4 XvMC / Xv
510
511 It might be nice to be able to use YUV formatted objects as Present
512 sources.
513
514                              ❄ ❄ ❄  ❄  ❄ ❄ ❄
515
516 Appendix A. Protocol Encoding
517
518 Syntactic Conventions
519
520 This document uses the same syntactic conventions as the core X
521 protocol encoding document.
522
523
524 A.1 Common Types
525 ┌───
526     PresentEventType
527         0       PresentConfigureNotify
528         1       PresentCompleteNotify
529         2       PresentIdleNotify
530         3       PresentRedirectNotify
531 └───
532
533 ┌───
534     PresentEventMask
535         1       PresentConfigureNotifyMask
536         2       PresentCompleteNotifyMask
537         4       PresentIdleNotifyMask
538         8       PresentRedirectNotifyMask
539 └───
540
541 ┌───
542     PresentOption
543         1       PresentOptionAsync
544         2       PresentOptionCopy;
545         4       PresentOptionUST
546 └───
547
548 ┌───
549     PresentCapability
550         1       PresentCapabilityAsync
551         2       PresentCapabilityFence
552         4       PresentCapabilityUST
553 └───
554
555 ┌───
556     PresentCompleteKind
557         0       PresentCompleteKindPixmap
558         1       PresentCompleteKindMSCNotify
559 └───
560
561 ┌───
562     PresentCompleteMode
563         0       PresentCompleteModeCopy
564         1       PresentCompleteModeFlip
565         2       PresentCompleteModeSkip
566 └───
567
568 ┌───
569     PresentNotify
570         4       Window                  window
571         4       CARD32                  serial
572 └───
573
574 A.2 Protocol Requests
575
576 ┌───
577     PresentQueryVersion
578         1       CARD8                   major opcode
579         1       0                       Present opcode
580         2       3                       length
581         4       CARD32                  major version
582         4       CARD32                  minor version
583       ▶
584         1       1                       Reply
585         1                               unused
586         2       CARD16                  sequence number
587         4       0                       reply length
588         4       CARD32                  major version
589         4       CARD32                  minor version
590         16                              unused  
591 └───
592
593 ┌───
594     PresentPixmap
595         1       CARD8                   major opcode
596         1       1                       Present opcode
597         2       18+2n                   length
598         4       Window                  window
599         4       Pixmap                  pixmap
600         4       CARD32                  serial
601         4       Region                  valid-area
602         4       Region                  update-area
603         2       INT16                   x-off
604         2       INT16                   y-off
605         4       CRTC                    target-crtc
606         4       SyncFence               wait-fence
607         4       SyncFence               idle-fence
608         4       CARD32                  options
609         4                               unused
610         8       CARD64                  target-msc
611         8       CARD64                  divisor
612         8       CARD64                  remainder
613         8n      LISTofPresentNotify     notifies
614 └───
615
616 ┌───
617     PresentNotifyMSC
618         1       CARD8                   major opcode
619         1       2                       Present opcode
620         2       10                      length
621         4       Window                  window
622         4       CARD32                  serial
623         4                               unused
624         8       CARD64                  target-msc
625         8       CARD64                  divisor
626         8       CARD64                  remainder
627 └───
628
629 ┌───
630     PresentSelectInput
631         1       CARD8                   major opcode
632         1       3                       Present opcode
633         2       4                       length
634         4       EventID                 event-id
635         4       Window                  window
636         4       SETofPRESENTEVENTMASK   event-mask
637 └───
638
639 ┌───
640     PresentQueryCapabilities
641         1       CARD8                   major opcode
642         1       4                       Present opcode
643         2       2                       length
644         4       CRTC or Window          target
645       ▶
646         1       1                       Reply
647         1                               unused
648         2       CARD16                  sequence number
649         4       0                       reply length
650         4       SETofPRESENTCAPABILITY  capabilities
651 └───
652
653 A.3 Protocol Events
654
655 ┌───
656     PresentConfigureNotify
657         1       35                      XGE
658         1       CARD8                   Present extension opcode
659         2       CARD16                  sequence number
660         4       2                       length
661         2       0                       PresentConfigureNotify
662         2                               unused
663         4       CARD32                  event id
664         4       Window                  window
665         2       INT16                   x
666         2       INT16                   y
667         2       CARD16                  width
668         2       CARD16                  height
669         2       INT16                   off x
670         2       INT16                   off y
671
672         2       CARD16                  pixmap width
673         2       CARD16                  pixmap height
674         4       CARD32                  pixmap flags
675 └───
676
677 ┌───
678     PresentCompleteNotify
679         1       35                      XGE
680         1       CARD8                   Present extension opcode
681         2       CARD16                  sequence number
682         4       2                       length
683         2       1                       PresentCompleteNotify
684         1       CARD8                   kind
685         1       CARD8                   mode
686         4       CARD32                  event id
687         4       Window                  window
688         4       CARD32                  serial
689         8       CARD64                  ust
690
691         8       CARD64                  msc
692 └───
693
694 ┌───
695     PresentIdleNotify
696         1       35                      XGE
697         1       CARD8                   Present extension opcode
698         2       CARD16                  sequence number
699         4       0                       length
700         2       2                       PresentIdleNotify
701         2                               unused
702         4       CARD32                  event id
703         4       Window                  window
704         4       CARD32                  serial
705         4       Pixmap                  pixmap
706         4       SyncFence               idle-fence
707 └───
708
709 ┌───
710     PresentRedirectNotify
711         1       35                      XGE
712         1       CARD8                   Present extension opcode
713         2       CARD16                  sequence number
714         4       18+2n                   length
715         2       3                       PresentRedirectNotify
716         1       BOOL                    update-window
717         1                               unused
718         4       CARD32                  event id
719         4       Window                  event-window
720         4       Window                  window
721         4       Pixmap                  pixmap
722         4       CARD32                  serial
723
724         4       Region                  valid-area
725         4       Region                  update-area
726         8       Rectangle               valid-rect
727         8       Rectangle               update-rect
728         2       INT16                   x-off
729         2       INT16                   y-off
730         4       CRTC                    target-crtc
731         4       SyncFence               wait-fence
732         4       SyncFence               idle-fence
733         4       CARD32                  options
734         4                               unused
735         8       CARD64                  target-msc
736         8       CARD64                  divisor
737         8       CARD64                  remainder
738         8n      LISTofPRESENTNOTIFY     notifies
739 └───
740
741 A.4 Protocol Errors
742
743 The DRI3 extension defines no errors.
744
745                              ❄ ❄ ❄  ❄  ❄ ❄ ❄