2 * Copyright © 2013 Keith Packard
3 * Copyright © 2015 Boyan Ding
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 #ifndef LOADER_DRI3_HEADER_H
25 #define LOADER_DRI3_HEADER_H
32 #include <xcb/present.h>
35 #include <GL/internal/dri_interface.h>
37 enum loader_dri3_buffer_type
{
38 loader_dri3_buffer_back
= 0,
39 loader_dri3_buffer_front
= 1
42 struct loader_dri3_buffer
{
44 __DRIimage
*linear_buffer
;
47 /* Synchronization between the client and X server is done using an
48 * xshmfence that is mapped into an X server SyncFence. This lets the
49 * client check whether the X server is done using a buffer with a simple
50 * xshmfence call, rather than going to read X events from the wire.
52 * However, we can only wait for one xshmfence to be triggered at a time,
53 * so we need to know *which* buffer is going to be idle next. We do that
54 * by waiting for a PresentIdleNotify event. When that event arrives, the
55 * 'busy' flag gets cleared and the client knows that the fence has been
56 * triggered, and that the wait call will not block.
59 uint32_t sync_fence
; /* XID of X SyncFence object */
60 struct xshmfence
*shm_fence
; /* pointer to xshmfence object */
61 bool busy
; /* Set on swap, cleared on IdleNotify */
62 bool own_pixmap
; /* We allocated the pixmap ID, free on destroy */
68 uint32_t width
, height
;
71 enum loader_dri3_buffer_type buffer_type
;
75 #define LOADER_DRI3_MAX_BACK 4
76 #define LOADER_DRI3_BACK_ID(i) (i)
77 #define LOADER_DRI3_FRONT_ID (LOADER_DRI3_MAX_BACK)
80 loader_dri3_pixmap_buf_id(enum loader_dri3_buffer_type buffer_type
)
82 if (buffer_type
== loader_dri3_buffer_back
)
83 return LOADER_DRI3_BACK_ID(0);
85 return LOADER_DRI3_FRONT_ID
;
88 struct loader_dri3_extensions
{
89 const __DRIcoreExtension
*core
;
90 const __DRIimageDriverExtension
*image_driver
;
91 const __DRI2flushExtension
*flush
;
92 const __DRI2configQueryExtension
*config
;
93 const __DRItexBufferExtension
*tex_buffer
;
94 const __DRIimageExtension
*image
;
97 struct loader_dri3_drawable
;
99 struct loader_dri3_vtable
{
100 int (*get_swap_interval
)(struct loader_dri3_drawable
*);
101 int (*clamp_swap_interval
)(struct loader_dri3_drawable
*, int);
102 void (*set_swap_interval
)(struct loader_dri3_drawable
*, int);
103 void (*set_drawable_size
)(struct loader_dri3_drawable
*, int, int);
104 bool (*in_current_context
)(struct loader_dri3_drawable
*);
105 __DRIcontext
*(*get_dri_context
)(struct loader_dri3_drawable
*);
106 __DRIscreen
*(*get_dri_screen
)(struct loader_dri3_drawable
*);
107 void (*flush_drawable
)(struct loader_dri3_drawable
*, unsigned);
108 void (*show_fps
)(struct loader_dri3_drawable
*, uint64_t);
111 #define LOADER_DRI3_NUM_BUFFERS (1 + LOADER_DRI3_MAX_BACK)
113 struct loader_dri3_drawable
{
114 xcb_connection_t
*conn
;
115 __DRIdrawable
*dri_drawable
;
116 xcb_drawable_t drawable
;
121 uint8_t have_fake_front
;
125 /* Information about the GPU owning the buffer */
126 __DRIscreen
*dri_screen
;
127 bool is_different_gpu
;
129 /* Present extension capabilities
131 uint32_t present_capabilities
;
133 /* SBC numbers are tracked by using the serial numbers
134 * in the present request and complete events
139 /* Last received UST/MSC values for pixmap present complete */
142 /* Last received UST/MSC values from present notify msc event */
143 uint64_t notify_ust
, notify_msc
;
145 /* Serial numbers for tracking wait_for_msc events */
146 uint32_t send_msc_serial
;
147 uint32_t recv_msc_serial
;
149 struct loader_dri3_buffer
*buffers
[LOADER_DRI3_NUM_BUFFERS
];
155 xcb_present_event_t eid
;
157 xcb_special_event_t
*special_event
;
161 struct loader_dri3_extensions
*ext
;
162 const struct loader_dri3_vtable
*vtable
;
166 loader_dri3_set_swap_interval(struct loader_dri3_drawable
*draw
,
170 loader_dri3_drawable_fini(struct loader_dri3_drawable
*draw
);
173 loader_dri3_drawable_init(xcb_connection_t
*conn
,
174 xcb_drawable_t drawable
,
175 __DRIscreen
*dri_screen
,
176 bool is_different_gpu
,
177 const __DRIconfig
*dri_config
,
178 struct loader_dri3_extensions
*ext
,
179 const struct loader_dri3_vtable
*vtable
,
180 struct loader_dri3_drawable
*);
182 bool loader_dri3_wait_for_msc(struct loader_dri3_drawable
*draw
,
184 int64_t divisor
, int64_t remainder
,
185 int64_t *ust
, int64_t *msc
, int64_t *sbc
);
188 loader_dri3_swap_buffers_msc(struct loader_dri3_drawable
*draw
,
189 int64_t target_msc
, int64_t divisor
,
190 int64_t remainder
, unsigned flush_flags
,
194 loader_dri3_wait_for_sbc(struct loader_dri3_drawable
*draw
,
195 int64_t target_sbc
, int64_t *ust
,
196 int64_t *msc
, int64_t *sbc
);
198 int loader_dri3_query_buffer_age(struct loader_dri3_drawable
*draw
);
201 loader_dri3_flush(struct loader_dri3_drawable
*draw
,
203 enum __DRI2throttleReason throttle_reason
);
206 loader_dri3_copy_sub_buffer(struct loader_dri3_drawable
*draw
,
208 int width
, int height
,
212 loader_dri3_copy_drawable(struct loader_dri3_drawable
*draw
,
217 loader_dri3_wait_x(struct loader_dri3_drawable
*draw
);
220 loader_dri3_wait_gl(struct loader_dri3_drawable
*draw
);
222 int loader_dri3_open(xcb_connection_t
*conn
,
227 loader_dri3_create_image(xcb_connection_t
*c
,
228 xcb_dri3_buffer_from_pixmap_reply_t
*bp_reply
,
230 __DRIscreen
*dri_screen
,
231 const __DRIimageExtension
*image
,
232 void *loaderPrivate
);
235 loader_dri3_get_buffers(__DRIdrawable
*driDrawable
,
239 uint32_t buffer_mask
,
240 struct __DRIimageList
*buffers
);