xref: /OK3568_Linux_fs/external/xserver/present/present_execute.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2013 Keith Packard
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_XORG_CONFIG_H
24*4882a593Smuzhiyun #include <xorg-config.h>
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #include "present_priv.h"
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun /*
30*4882a593Smuzhiyun  * Called when the wait fence is triggered; just gets the current msc/ust and
31*4882a593Smuzhiyun  * calls the proper execute again. That will re-check the fence and pend the
32*4882a593Smuzhiyun  * request again if it's still not actually ready
33*4882a593Smuzhiyun  */
34*4882a593Smuzhiyun static void
present_wait_fence_triggered(void * param)35*4882a593Smuzhiyun present_wait_fence_triggered(void *param)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun     present_vblank_ptr      vblank = param;
38*4882a593Smuzhiyun     ScreenPtr               screen = vblank->screen;
39*4882a593Smuzhiyun     present_screen_priv_ptr screen_priv = present_screen_priv(screen);
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun     screen_priv->re_execute(vblank);
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun Bool
present_execute_wait(present_vblank_ptr vblank,uint64_t crtc_msc)45*4882a593Smuzhiyun present_execute_wait(present_vblank_ptr vblank, uint64_t crtc_msc)
46*4882a593Smuzhiyun {
47*4882a593Smuzhiyun     WindowPtr                   window = vblank->window;
48*4882a593Smuzhiyun     ScreenPtr                   screen = window->drawable.pScreen;
49*4882a593Smuzhiyun     present_screen_priv_ptr screen_priv = present_screen_priv(screen);
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun     /* We may have to requeue for the next MSC if check_flip_window prevented
52*4882a593Smuzhiyun      * using a flip.
53*4882a593Smuzhiyun      */
54*4882a593Smuzhiyun     if (vblank->exec_msc == crtc_msc + 1 &&
55*4882a593Smuzhiyun         screen_priv->queue_vblank(screen, window, vblank->crtc, vblank->event_id,
56*4882a593Smuzhiyun                                   vblank->exec_msc) == Success)
57*4882a593Smuzhiyun         return TRUE;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun     if (vblank->wait_fence) {
60*4882a593Smuzhiyun         if (!present_fence_check_triggered(vblank->wait_fence)) {
61*4882a593Smuzhiyun             present_fence_set_callback(vblank->wait_fence, present_wait_fence_triggered, vblank);
62*4882a593Smuzhiyun             return TRUE;
63*4882a593Smuzhiyun         }
64*4882a593Smuzhiyun     }
65*4882a593Smuzhiyun     return FALSE;
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun void
present_execute_copy(present_vblank_ptr vblank,uint64_t crtc_msc)69*4882a593Smuzhiyun present_execute_copy(present_vblank_ptr vblank, uint64_t crtc_msc)
70*4882a593Smuzhiyun {
71*4882a593Smuzhiyun     WindowPtr                   window = vblank->window;
72*4882a593Smuzhiyun     ScreenPtr                   screen = window->drawable.pScreen;
73*4882a593Smuzhiyun     present_screen_priv_ptr screen_priv = present_screen_priv(screen);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun     /* If present_flip failed, we may have to requeue for the next MSC */
76*4882a593Smuzhiyun     if (vblank->exec_msc == crtc_msc + 1 &&
77*4882a593Smuzhiyun         Success == screen_priv->queue_vblank(screen,
78*4882a593Smuzhiyun                                              window,
79*4882a593Smuzhiyun                                              vblank->crtc,
80*4882a593Smuzhiyun                                              vblank->event_id,
81*4882a593Smuzhiyun                                              vblank->exec_msc)) {
82*4882a593Smuzhiyun         vblank->queued = TRUE;
83*4882a593Smuzhiyun         return;
84*4882a593Smuzhiyun     }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun     present_copy_region(&window->drawable, vblank->pixmap, vblank->update, vblank->x_off, vblank->y_off);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun     /* present_copy_region sticks the region into a scratch GC,
89*4882a593Smuzhiyun      * which is then freed, freeing the region
90*4882a593Smuzhiyun      */
91*4882a593Smuzhiyun     vblank->update = NULL;
92*4882a593Smuzhiyun     screen_priv->flush(window);
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun     present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun void
present_execute_post(present_vblank_ptr vblank,uint64_t ust,uint64_t crtc_msc)98*4882a593Smuzhiyun present_execute_post(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun     uint8_t mode;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun     /* Compute correct CompleteMode
103*4882a593Smuzhiyun      */
104*4882a593Smuzhiyun     if (vblank->kind == PresentCompleteKindPixmap) {
105*4882a593Smuzhiyun         if (vblank->pixmap && vblank->window) {
106*4882a593Smuzhiyun             if (vblank->has_suboptimal && vblank->reason == PRESENT_FLIP_REASON_BUFFER_FORMAT)
107*4882a593Smuzhiyun                 mode = PresentCompleteModeSuboptimalCopy;
108*4882a593Smuzhiyun             else
109*4882a593Smuzhiyun                 mode = PresentCompleteModeCopy;
110*4882a593Smuzhiyun         } else {
111*4882a593Smuzhiyun             mode = PresentCompleteModeSkip;
112*4882a593Smuzhiyun         }
113*4882a593Smuzhiyun     }
114*4882a593Smuzhiyun     else
115*4882a593Smuzhiyun         mode = PresentCompleteModeCopy;
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun     present_vblank_notify(vblank, vblank->kind, mode, ust, crtc_msc);
118*4882a593Smuzhiyun     present_vblank_destroy(vblank);
119*4882a593Smuzhiyun }
120