dri3_priv.h revision 848b8605
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/* This file was derived from dri2_priv.h which carries the following
24 * copyright:
25 *
26 * Copyright © 2008 Red Hat, Inc.
27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a
29 * copy of this software and associated documentation files (the "Soft-
30 * ware"), to deal in the Software without restriction, including without
31 * limitation the rights to use, copy, modify, merge, publish, distribute,
32 * and/or sell copies of the Software, and to permit persons to whom the
33 * Software is furnished to do so, provided that the above copyright
34 * notice(s) and this permission notice appear in all copies of the Soft-
35 * ware and that both the above copyright notice(s) and this permission
36 * notice appear in supporting documentation.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
39 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
40 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
41 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
42 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
43 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
44 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
45 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
46 * MANCE OF THIS SOFTWARE.
47 *
48 * Except as contained in this notice, the name of a copyright holder shall
49 * not be used in advertising or otherwise to promote the sale, use or
50 * other dealings in this Software without prior written authorization of
51 * the copyright holder.
52 *
53 * Authors:
54 *   Kristian Høgsberg (krh@redhat.com)
55 */
56
57#include <xcb/xcb.h>
58#include <xcb/dri3.h>
59#include <xcb/present.h>
60#include <xcb/sync.h>
61
62/* From xmlpool/options.h, user exposed so should be stable */
63#define DRI_CONF_VBLANK_NEVER 0
64#define DRI_CONF_VBLANK_DEF_INTERVAL_0 1
65#define DRI_CONF_VBLANK_DEF_INTERVAL_1 2
66#define DRI_CONF_VBLANK_ALWAYS_SYNC 3
67
68enum dri3_buffer_type {
69   dri3_buffer_back = 0,
70   dri3_buffer_front = 1
71};
72
73struct dri3_buffer {
74   __DRIimage   *image;
75   __DRIimage   *linear_buffer;
76   uint32_t     pixmap;
77
78   /* Synchronization between the client and X server is done using an
79    * xshmfence that is mapped into an X server SyncFence. This lets the
80    * client check whether the X server is done using a buffer with a simple
81    * xshmfence call, rather than going to read X events from the wire.
82    *
83    * However, we can only wait for one xshmfence to be triggered at a time,
84    * so we need to know *which* buffer is going to be idle next. We do that
85    * by waiting for a PresentIdleNotify event. When that event arrives, the
86    * 'busy' flag gets cleared and the client knows that the fence has been
87    * triggered, and that the wait call will not block.
88    */
89
90   uint32_t     sync_fence;     /* XID of X SyncFence object */
91   struct xshmfence *shm_fence; /* pointer to xshmfence object */
92   GLboolean    busy;           /* Set on swap, cleared on IdleNotify */
93   GLboolean    own_pixmap;     /* We allocated the pixmap ID, free on destroy */
94   void         *driverPrivate;
95
96   uint32_t     size;
97   uint32_t     pitch;
98   uint32_t     cpp;
99   uint32_t     flags;
100   uint32_t     width, height;
101   uint64_t     last_swap;
102
103   enum dri3_buffer_type        buffer_type;
104};
105
106struct dri3_display
107{
108   __GLXDRIdisplay base;
109
110   const __DRIextension **loader_extensions;
111
112   /* DRI3 bits */
113   int dri3Major;
114   int dri3Minor;
115
116   /* Present bits */
117   int hasPresent;
118   int presentMajor;
119   int presentMinor;
120};
121
122struct dri3_screen {
123   struct glx_screen base;
124
125   __DRIscreen *driScreen;
126   __GLXDRIscreen vtable;
127
128   const __DRIimageExtension *image;
129   const __DRIimageDriverExtension *image_driver;
130   const __DRIcoreExtension *core;
131   const __DRI2flushExtension *f;
132   const __DRI2configQueryExtension *config;
133   const __DRItexBufferExtension *texBuffer;
134   const __DRI2rendererQueryExtension *rendererQuery;
135   const __DRIconfig **driver_configs;
136
137   void *driver;
138   int fd;
139   int is_different_gpu;
140
141   Bool show_fps;
142};
143
144struct dri3_context
145{
146   struct glx_context base;
147   __DRIcontext *driContext;
148};
149
150#define DRI3_MAX_BACK   3
151#define DRI3_BACK_ID(i) (i)
152#define DRI3_FRONT_ID   (DRI3_MAX_BACK)
153
154static inline int
155dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type)
156{
157   if (buffer_type == dri3_buffer_back)
158      return DRI3_BACK_ID(0);
159   else
160      return DRI3_FRONT_ID;
161}
162
163#define DRI3_NUM_BUFFERS        (1 + DRI3_MAX_BACK)
164
165struct dri3_drawable {
166   __GLXDRIdrawable base;
167   __DRIdrawable *driDrawable;
168   int width, height, depth;
169   int swap_interval;
170   uint8_t have_back;
171   uint8_t have_fake_front;
172   uint8_t is_pixmap;
173   uint8_t flipping;
174
175   /* SBC numbers are tracked by using the serial numbers
176    * in the present request and complete events
177    */
178   uint64_t send_sbc;
179   uint64_t recv_sbc;
180
181   /* Last received UST/MSC values */
182   uint64_t ust, msc;
183
184   /* Serial numbers for tracking wait_for_msc events */
185   uint32_t send_msc_serial;
186   uint32_t recv_msc_serial;
187
188   struct dri3_buffer *buffers[DRI3_NUM_BUFFERS];
189   int cur_back;
190   int num_back;
191
192   uint32_t *stamp;
193
194   xcb_present_event_t eid;
195   xcb_gcontext_t gc;
196   xcb_special_event_t *special_event;
197};
198