1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2014 Intel Corporation
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun * the above copyright notice appear in all copies and that both that copyright
7*4882a593Smuzhiyun * notice and this permission notice appear in supporting documentation, and
8*4882a593Smuzhiyun * that the name of the copyright holders not be used in advertising or
9*4882a593Smuzhiyun * publicity pertaining to distribution of the software without specific,
10*4882a593Smuzhiyun * written prior permission. The copyright holders make no representations
11*4882a593Smuzhiyun * about the suitability of this software for any purpose. It is provided "as
12*4882a593Smuzhiyun * is" without express or implied warranty.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20*4882a593Smuzhiyun * OF THIS SOFTWARE.
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
24*4882a593Smuzhiyun #include "dix-config.h"
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #include <xserver_poll.h>
28*4882a593Smuzhiyun #include <xf86drm.h>
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun #include <sys/time.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #include "driver.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun * Flush the DRM event queue when full; makes space for new events.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * Returns a negative value on error, 0 if there was nothing to process,
38*4882a593Smuzhiyun * or 1 if we handled any events.
39*4882a593Smuzhiyun */
40*4882a593Smuzhiyun int
ms_flush_drm_events(ScreenPtr screen)41*4882a593Smuzhiyun ms_flush_drm_events(ScreenPtr screen)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
44*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun struct pollfd p = { .fd = ms->fd, .events = POLLIN };
47*4882a593Smuzhiyun int r;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun do {
50*4882a593Smuzhiyun r = xserver_poll(&p, 1, 0);
51*4882a593Smuzhiyun } while (r == -1 && (errno == EINTR || errno == EAGAIN));
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* If there was an error, r will be < 0. Return that. If there was
54*4882a593Smuzhiyun * nothing to process, r == 0. Return that.
55*4882a593Smuzhiyun */
56*4882a593Smuzhiyun if (r <= 0)
57*4882a593Smuzhiyun return r;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun /* Try to handle the event. If there was an error, return it. */
60*4882a593Smuzhiyun r = drmHandleEvent(ms->fd, &ms->event_context);
61*4882a593Smuzhiyun if (r < 0)
62*4882a593Smuzhiyun return r;
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Otherwise return 1 to indicate that we handled an event. */
65*4882a593Smuzhiyun return 1;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun /*
69*4882a593Smuzhiyun * Event data for an in progress flip.
70*4882a593Smuzhiyun * This contains a pointer to the vblank event,
71*4882a593Smuzhiyun * and information about the flip in progress.
72*4882a593Smuzhiyun * a reference to this is stored in the per-crtc
73*4882a593Smuzhiyun * flips.
74*4882a593Smuzhiyun */
75*4882a593Smuzhiyun struct ms_flipdata {
76*4882a593Smuzhiyun ScreenPtr screen;
77*4882a593Smuzhiyun void *event;
78*4882a593Smuzhiyun ms_pageflip_handler_proc event_handler;
79*4882a593Smuzhiyun ms_pageflip_abort_proc abort_handler;
80*4882a593Smuzhiyun /* number of CRTC events referencing this */
81*4882a593Smuzhiyun int flip_count;
82*4882a593Smuzhiyun uint64_t fe_msc;
83*4882a593Smuzhiyun uint64_t fe_usec;
84*4882a593Smuzhiyun uint32_t old_fb_id;
85*4882a593Smuzhiyun uint32_t *fb_id;
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun /*
89*4882a593Smuzhiyun * Per crtc pageflipping infomation,
90*4882a593Smuzhiyun * These are submitted to the queuing code
91*4882a593Smuzhiyun * one of them per crtc per flip.
92*4882a593Smuzhiyun */
93*4882a593Smuzhiyun struct ms_crtc_pageflip {
94*4882a593Smuzhiyun Bool on_reference_crtc;
95*4882a593Smuzhiyun /* reference to the ms_flipdata */
96*4882a593Smuzhiyun struct ms_flipdata *flipdata;
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /**
100*4882a593Smuzhiyun * Free an ms_crtc_pageflip.
101*4882a593Smuzhiyun *
102*4882a593Smuzhiyun * Drops the reference count on the flipdata.
103*4882a593Smuzhiyun */
104*4882a593Smuzhiyun static void
ms_pageflip_free(struct ms_crtc_pageflip * flip)105*4882a593Smuzhiyun ms_pageflip_free(struct ms_crtc_pageflip *flip)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun struct ms_flipdata *flipdata = flip->flipdata;
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun free(flip);
110*4882a593Smuzhiyun if (--flipdata->flip_count > 0)
111*4882a593Smuzhiyun return;
112*4882a593Smuzhiyun free(flipdata);
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /**
116*4882a593Smuzhiyun * Callback for the DRM event queue when a single flip has completed
117*4882a593Smuzhiyun *
118*4882a593Smuzhiyun * Once the flip has been completed on all pipes, notify the
119*4882a593Smuzhiyun * extension code telling it when that happened
120*4882a593Smuzhiyun */
121*4882a593Smuzhiyun static void
ms_pageflip_handler(uint64_t msc,uint64_t ust,void * data)122*4882a593Smuzhiyun ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun struct ms_crtc_pageflip *flip = data;
125*4882a593Smuzhiyun struct ms_flipdata *flipdata = flip->flipdata;
126*4882a593Smuzhiyun ScreenPtr screen = flipdata->screen;
127*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
128*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun if (flip->on_reference_crtc) {
131*4882a593Smuzhiyun flipdata->fe_msc = msc;
132*4882a593Smuzhiyun flipdata->fe_usec = ust;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun if (flipdata->flip_count == 1) {
136*4882a593Smuzhiyun flipdata->event_handler(ms, flipdata->fe_msc,
137*4882a593Smuzhiyun flipdata->fe_usec,
138*4882a593Smuzhiyun flipdata->event);
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun drmModeRmFB(ms->fd, flipdata->old_fb_id);
141*4882a593Smuzhiyun }
142*4882a593Smuzhiyun ms_pageflip_free(flip);
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*
146*4882a593Smuzhiyun * Callback for the DRM queue abort code. A flip has been aborted.
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun static void
ms_pageflip_abort(void * data)149*4882a593Smuzhiyun ms_pageflip_abort(void *data)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun struct ms_crtc_pageflip *flip = data;
152*4882a593Smuzhiyun struct ms_flipdata *flipdata = flip->flipdata;
153*4882a593Smuzhiyun ScreenPtr screen = flipdata->screen;
154*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
155*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun if (flipdata->flip_count == 1) {
158*4882a593Smuzhiyun flipdata->abort_handler(ms, flipdata->event);
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun drmModeRmFB(ms->fd, flipdata->old_fb_id);
161*4882a593Smuzhiyun }
162*4882a593Smuzhiyun ms_pageflip_free(flip);
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun static Bool
do_queue_flip_on_crtc(modesettingPtr ms,xf86CrtcPtr crtc,uint32_t flags,uint32_t seq,unsigned fb_id)166*4882a593Smuzhiyun do_queue_flip_on_crtc(modesettingPtr ms, xf86CrtcPtr crtc,
167*4882a593Smuzhiyun uint32_t flags, uint32_t seq, unsigned fb_id)
168*4882a593Smuzhiyun {
169*4882a593Smuzhiyun return drmmode_crtc_flip(crtc, fb_id, flags,
170*4882a593Smuzhiyun (void *) (uintptr_t) seq);
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun static Bool
queue_flip_on_crtc(ScreenPtr screen,xf86CrtcPtr crtc,struct ms_flipdata * flipdata,int ref_crtc_vblank_pipe,uint32_t flags)174*4882a593Smuzhiyun queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,
175*4882a593Smuzhiyun struct ms_flipdata *flipdata,
176*4882a593Smuzhiyun int ref_crtc_vblank_pipe, uint32_t flags)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
179*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
180*4882a593Smuzhiyun drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
181*4882a593Smuzhiyun struct ms_crtc_pageflip *flip;
182*4882a593Smuzhiyun uint32_t seq;
183*4882a593Smuzhiyun int err;
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun flip = calloc(1, sizeof(struct ms_crtc_pageflip));
186*4882a593Smuzhiyun if (flip == NULL) {
187*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_WARNING,
188*4882a593Smuzhiyun "flip queue: carrier alloc failed.\n");
189*4882a593Smuzhiyun return FALSE;
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun /* Only the reference crtc will finally deliver its page flip
193*4882a593Smuzhiyun * completion event. All other crtc's events will be discarded.
194*4882a593Smuzhiyun */
195*4882a593Smuzhiyun flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == ref_crtc_vblank_pipe);
196*4882a593Smuzhiyun flip->flipdata = flipdata;
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun seq = ms_drm_queue_alloc(crtc, flip, ms_pageflip_handler, ms_pageflip_abort);
199*4882a593Smuzhiyun if (!seq) {
200*4882a593Smuzhiyun free(flip);
201*4882a593Smuzhiyun return FALSE;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun /* take a reference on flipdata for use in flip */
205*4882a593Smuzhiyun flipdata->flip_count++;
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun while (do_queue_flip_on_crtc(ms, crtc, flags, seq, *flipdata->fb_id)) {
208*4882a593Smuzhiyun err = errno;
209*4882a593Smuzhiyun /* We may have failed because the event queue was full. Flush it
210*4882a593Smuzhiyun * and retry. If there was nothing to flush, then we failed for
211*4882a593Smuzhiyun * some other reason and should just return an error.
212*4882a593Smuzhiyun */
213*4882a593Smuzhiyun if (ms_flush_drm_events(screen) <= 0) {
214*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_WARNING,
215*4882a593Smuzhiyun "flip queue failed: %s\n", strerror(err));
216*4882a593Smuzhiyun /* Aborting will also decrement flip_count and free(flip). */
217*4882a593Smuzhiyun ms_drm_abort_seq(scrn, seq);
218*4882a593Smuzhiyun return FALSE;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun /* We flushed some events, so try again. */
222*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_WARNING, "flip queue retry\n");
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* The page flip succeded. */
226*4882a593Smuzhiyun return TRUE;
227*4882a593Smuzhiyun }
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun Bool
ms_do_pageflip_bo(ScreenPtr screen,drmmode_bo * new_front_bo,void * event,int ref_crtc_vblank_pipe,xf86CrtcPtr target_crtc,Bool async,ms_pageflip_handler_proc pageflip_handler,ms_pageflip_abort_proc pageflip_abort)230*4882a593Smuzhiyun ms_do_pageflip_bo(ScreenPtr screen,
231*4882a593Smuzhiyun drmmode_bo *new_front_bo,
232*4882a593Smuzhiyun void *event,
233*4882a593Smuzhiyun int ref_crtc_vblank_pipe,
234*4882a593Smuzhiyun xf86CrtcPtr target_crtc,
235*4882a593Smuzhiyun Bool async,
236*4882a593Smuzhiyun ms_pageflip_handler_proc pageflip_handler,
237*4882a593Smuzhiyun ms_pageflip_abort_proc pageflip_abort)
238*4882a593Smuzhiyun {
239*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
240*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
241*4882a593Smuzhiyun xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn);
242*4882a593Smuzhiyun drmmode_crtc_private_ptr drmmode_crtc;
243*4882a593Smuzhiyun uint32_t flags;
244*4882a593Smuzhiyun int i;
245*4882a593Smuzhiyun struct ms_flipdata *flipdata;
246*4882a593Smuzhiyun struct timeval tv;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun flipdata = calloc(1, sizeof(struct ms_flipdata));
249*4882a593Smuzhiyun if (!flipdata) {
250*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_ERROR,
251*4882a593Smuzhiyun "Failed to allocate flipdata.\n");
252*4882a593Smuzhiyun return FALSE;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun if (target_crtc) {
256*4882a593Smuzhiyun drmmode_crtc = target_crtc->driver_private;
257*4882a593Smuzhiyun flipdata->fb_id = &drmmode_crtc->fb_id;
258*4882a593Smuzhiyun } else {
259*4882a593Smuzhiyun flipdata->fb_id = &ms->drmmode.fb_id;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun flipdata->event = event;
263*4882a593Smuzhiyun flipdata->screen = screen;
264*4882a593Smuzhiyun flipdata->event_handler = pageflip_handler;
265*4882a593Smuzhiyun flipdata->abort_handler = pageflip_abort;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun /*
268*4882a593Smuzhiyun * Take a local reference on flipdata.
269*4882a593Smuzhiyun * if the first flip fails, the sequence abort
270*4882a593Smuzhiyun * code will free the crtc flip data, and drop
271*4882a593Smuzhiyun * it's reference which would cause this to be
272*4882a593Smuzhiyun * freed when we still required it.
273*4882a593Smuzhiyun */
274*4882a593Smuzhiyun flipdata->flip_count++;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun /* Create a new handle for the back buffer */
277*4882a593Smuzhiyun flipdata->old_fb_id = *flipdata->fb_id;
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun if (drmmode_bo_import(&ms->drmmode, new_front_bo,
280*4882a593Smuzhiyun flipdata->fb_id))
281*4882a593Smuzhiyun goto error_out;
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun flags = DRM_MODE_PAGE_FLIP_EVENT;
284*4882a593Smuzhiyun if (async && ms->async_pageflip)
285*4882a593Smuzhiyun flags |= DRM_MODE_PAGE_FLIP_ASYNC;
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun /* Queue flips on all enabled CRTCs.
288*4882a593Smuzhiyun *
289*4882a593Smuzhiyun * Note that if/when we get per-CRTC buffers, we'll have to update this.
290*4882a593Smuzhiyun * Right now it assumes a single shared fb across all CRTCs, with the
291*4882a593Smuzhiyun * kernel fixing up the offset of each CRTC as necessary.
292*4882a593Smuzhiyun *
293*4882a593Smuzhiyun * Also, flips queued on disabled or incorrectly configured displays
294*4882a593Smuzhiyun * may never complete; this is a configuration error.
295*4882a593Smuzhiyun */
296*4882a593Smuzhiyun for (i = 0; i < config->num_crtc; i++) {
297*4882a593Smuzhiyun xf86CrtcPtr crtc = config->crtc[i];
298*4882a593Smuzhiyun
299*4882a593Smuzhiyun if (!ms_crtc_on(crtc))
300*4882a593Smuzhiyun continue;
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun if (target_crtc && crtc != target_crtc)
303*4882a593Smuzhiyun continue;
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun if (!queue_flip_on_crtc(screen, crtc, flipdata,
306*4882a593Smuzhiyun ref_crtc_vblank_pipe,
307*4882a593Smuzhiyun flags)) {
308*4882a593Smuzhiyun goto error_undo;
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun gettimeofday(&tv, NULL);
312*4882a593Smuzhiyun drmmode_crtc = crtc->driver_private;
313*4882a593Smuzhiyun drmmode_crtc->flipping_time_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun /*
317*4882a593Smuzhiyun * Do we have more than our local reference,
318*4882a593Smuzhiyun * if so and no errors, then drop our local
319*4882a593Smuzhiyun * reference and return now.
320*4882a593Smuzhiyun */
321*4882a593Smuzhiyun if (flipdata->flip_count > 1) {
322*4882a593Smuzhiyun flipdata->flip_count--;
323*4882a593Smuzhiyun return TRUE;
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun error_undo:
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun /*
329*4882a593Smuzhiyun * Have we just got the local reference?
330*4882a593Smuzhiyun * free the framebuffer if so since nobody successfully
331*4882a593Smuzhiyun * submitted anything
332*4882a593Smuzhiyun */
333*4882a593Smuzhiyun if (flipdata->flip_count == 1) {
334*4882a593Smuzhiyun drmModeRmFB(ms->fd, *flipdata->fb_id);
335*4882a593Smuzhiyun *flipdata->fb_id = flipdata->old_fb_id;
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun error_out:
339*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_WARNING, "Page flip failed: %s\n",
340*4882a593Smuzhiyun strerror(errno));
341*4882a593Smuzhiyun /* if only the local reference - free the structure,
342*4882a593Smuzhiyun * else drop the local reference and return */
343*4882a593Smuzhiyun if (flipdata->flip_count == 1)
344*4882a593Smuzhiyun free(flipdata);
345*4882a593Smuzhiyun else
346*4882a593Smuzhiyun flipdata->flip_count--;
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun return FALSE;
349*4882a593Smuzhiyun }
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun Bool
ms_do_pageflip(ScreenPtr screen,PixmapPtr new_front,void * event,int ref_crtc_vblank_pipe,Bool async,ms_pageflip_handler_proc pageflip_handler,ms_pageflip_abort_proc pageflip_abort)352*4882a593Smuzhiyun ms_do_pageflip(ScreenPtr screen,
353*4882a593Smuzhiyun PixmapPtr new_front,
354*4882a593Smuzhiyun void *event,
355*4882a593Smuzhiyun int ref_crtc_vblank_pipe,
356*4882a593Smuzhiyun Bool async,
357*4882a593Smuzhiyun ms_pageflip_handler_proc pageflip_handler,
358*4882a593Smuzhiyun ms_pageflip_abort_proc pageflip_abort)
359*4882a593Smuzhiyun {
360*4882a593Smuzhiyun ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
361*4882a593Smuzhiyun modesettingPtr ms = modesettingPTR(scrn);
362*4882a593Smuzhiyun drmmode_bo new_front_bo = {0};
363*4882a593Smuzhiyun Bool ret;
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
366*4882a593Smuzhiyun if (ms->drmmode.glamor) {
367*4882a593Smuzhiyun new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
368*4882a593Smuzhiyun if (!new_front_bo.gbm) {
369*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_ERROR,
370*4882a593Smuzhiyun "Failed to get GBM bo for flip to new front.\n");
371*4882a593Smuzhiyun return FALSE;
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun glamor_block_handler(screen);
375*4882a593Smuzhiyun } else
376*4882a593Smuzhiyun #endif
377*4882a593Smuzhiyun if (ms->drmmode.exa) {
378*4882a593Smuzhiyun new_front_bo.dumb = ms_exa_bo_from_pixmap(screen, new_front);
379*4882a593Smuzhiyun if (!new_front_bo.dumb) {
380*4882a593Smuzhiyun xf86DrvMsg(scrn->scrnIndex, X_ERROR,
381*4882a593Smuzhiyun "Failed to get dumb bo for flip to new front.\n");
382*4882a593Smuzhiyun return FALSE;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun } else {
385*4882a593Smuzhiyun return FALSE;
386*4882a593Smuzhiyun }
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun new_front_bo.width = new_front->drawable.width;
389*4882a593Smuzhiyun new_front_bo.height = new_front->drawable.height;
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun ret = ms_do_pageflip_bo(screen, &new_front_bo, event,
392*4882a593Smuzhiyun ref_crtc_vblank_pipe, NULL, async,
393*4882a593Smuzhiyun pageflip_handler, pageflip_abort);
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun #ifdef GLAMOR_HAS_GBM
396*4882a593Smuzhiyun new_front_bo.gbm = NULL;
397*4882a593Smuzhiyun #endif
398*4882a593Smuzhiyun new_front_bo.dumb = NULL;
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun drmmode_bo_destroy(&ms->drmmode, &new_front_bo);
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun return ret;
403*4882a593Smuzhiyun }
404