Commit Graph

145 Commits

Author SHA1 Message Date
Axel Davy 2203735887 present: Fix Async swap logic
According to the spec, PresentOptionAsync should only
trigger a different behaviour when the target msc has been reached.

In this case if the driver is able to do async swaps, we use
them to avoid a screen copy.

When the target msc hasn't been reached yet, we want to use sync swaps.

v2: Fix indentation and simplify checks for Async flips

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2015-11-09 15:47:01 -05:00
Jammy Zhou 3f35909acb present: Execute right away if target_msc equals current_msc
It is according to the protocol:

"If 'options' contains PresentOptionAsync, and the 'target-msc'
is less than or equal to the current msc for 'window', then
the operation will be performed as soon as possible, not
necessarily waiting for the next vertical blank interval."

Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Axel Davy <axel.davy@ens.fr>
2015-11-09 15:46:48 -05:00
Chris Wilson 413cb2ff1d present: Fix missed notify MSC computation
Only treat divisor==0 as async to immediately report the actual vblank.
If the user species a non-zero divisor, we should compute the missed
vblank properly or else we report too early.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2015-10-21 15:13:41 -04:00
Fredrik Höglund f6ce23fbfc present: Don't stash the MSC value when present_get_ust_msc fails
Otherwise we stash an uninitalized value, and later use it to compute
the msc_offset for the window.  Also initialize ust and crtc_msc so we
never use uninitalized values when present_get_ust_msc fails.

This fixes clients getting stuck waiting indefinitely for an idle
event when a CRTC is turned off.

Signed-off-by: Fredrik Höglund <fredrik@kde.org>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2015-09-30 16:06:26 -04:00
Adam Jackson c732bb2799 present: static cleanup
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2015-07-08 16:40:57 -04:00
Chris Wilson 806470b9f6 present: Copy unflip contents back to the Screen Pixmap
As we unflip after the flip Window no longer passes the pixel ownership
test for the full Screen Pixmap, we can no longer utilize that Window to
copy the contents back to the backing pixmap. To first flip means that
the Window was originally backed by the Screen Pixmap and wholly covered
the Pixmap, thus we need to copy the last frame contents to the Screen
Pixmap when the flip chain is complete.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
2015-05-26 15:09:32 -07:00
Kenneth Graunke b51f804b1c present: If present_queue_vblank() fails, do present_execute().
Previously, if present_queue_vblank() failed, we simply dropped the
present request on the floor, and returned an error.  This was rather
mean to clients - after presenting, they wait for a PresentComplete
event to come back.  But since the present never happens, they end up
waiting forever, and lock up in poll().

This patch falls back to present_execute if present_queue_vblank fails.
We still print a debugging message to warn when queueing fails, which
allows us to continue debugging problems, but makes Present robust
enough to not lock up people's compositing manager when vblank bugs
happen.

v2: Don't do present_queue_vblank() /and/ present_execute() (a bug that
    snuck in during last minute tidying).

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Jason Ekstrand <jason.ekstrand@intel.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-25 13:39:04 -08:00
Alan Coopersmith d155b7a8e3 present: unvalidated lengths in Present extension procs [CVE-2014-8103 2/2]
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Julien Cristau <jcristau@debian.org>
2014-12-08 18:09:48 -08:00
Mario Kleiner aae6460694 present: Fix use of vsynced pageflips and honor PresentOptionAsync. (v4)
Pageflips for Pixmap presents were not synchronized to vblank on
drivers with support for PresentCapabilityAsync, due to some
missing init for vblank->sync_flips. The PresentOptionAsync
flag was completely ignored for pageflipped presents.

Vsynced flips only worked by accident on the intel-ddx, as that
driver doesn't have PresentCapabilityAsync support.

On nouveau-ddx, which supports PresentCapabilityAsync, this
always caused non-vsynced pageflips with pretty ugly tearing.

This patch fixes the problem, as tested on top of XOrg 1.16.2
on nouveau and intel.

v4: Add additional PresentCapabilityAsync caps check, as
suggested by Eric Anholt.

Please also apply to XOrg 1.17 and XOrg 1.16.2 stable.

Applying on top of XOrg 1.16.2 requires cherry-picking
commit 2051514652
which trivially fixes lack of support for protocol option
PresentOptionCopy - get two bug fixes for the price of one!

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-08 16:38:17 -08:00
Mario Kleiner 32d3100bd7 present: Avoid crashes in DebugPresent(), a bit more info.
DebugPresent() crashed the server when a dri3 drawable
was closed while a pageflipped present was still pending,
due to vblank->window-> Null-Ptr deref, so debug builds
caused new problems to debug.

E.g.,

glXSwapBuffers(...);
glXDestroyWindow(...);
-> Pageflip for non-existent window completes -> boom.

Also often happens when switching desktop compositor on/off
due to Present unflips, or when logging out of session.

Also add info if a Present is queued for copyswap or pageflip,
if the present is vsynced, and the serial no of the Present
request, to aid debugging of pageflip and vsync issues. The
serial number is useful as Mesa's dri3/present backend encodes
its sendSBC in the serial number, so one can easily correlate
server debug output with Mesa and with the SBC values returned
to actual OpenGL client applications via OML_sync_control and
INTEL_swap_events extension, makes debugging quite a bit more
easy.

Please also cherry-pick this for a 1.16.x stable update.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-08 16:38:15 -08:00
Keith Packard ec0ac8970b Merge remote-tracking branch 'whot/for-keith' 2014-11-24 15:39:51 -08:00
Peter Hutterer 732fd7e571 Drop trailing whitespaces
sed -i "s/[ ]\+$//g" **/*.(c|h)

happy reviewing...
git diff -w is an empty diff.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2014-11-12 10:25:00 +10:00
Axel Davy 882f2d10d9 Fix present_notify to return right away when querying current or past msc.
When the target msc is past or is the current one, we want to get immediate
feedback. This patch fixes this behaviour.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-10-30 14:37:15 -07:00
Axel Davy 9bc01dfc70 Fix present_pixmap when using present_notify_msc
Calling present_notify_msc could cancel a pending pixmap presentation.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-10-02 10:22:46 -07:00
Keith Packard ea7357de90 present: Clear pending flip pixmaps at CloseScreen
If a flip is active at server reset time, the associated window will
get destroyed which will queue an unflip operation. If that isn't
synchronous, then it won't have finished by the time CloseScreen is
called.

Calling present_flip_idle will signal the fence and remove the
reference to the fence and pixmap, freeing these in the X server and
allowing a DRM client to clean up as well.

This also rewords other comments in present_flip_destroy, removing
scary words about needing synchronous operation (everything in this
function is synchronous now) and describing what effect we actually
need from present_set_abort_flip.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2014-09-18 15:32:56 -07:00
Keith Packard 2051514652 present: Support PresentOptionCopy
We added this option to the present protocol before 1.0 but somehow
never implemented it in the server. It's pretty simple; just don't
ever do flips if the application specifies Copy.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2014-09-18 15:31:37 -07:00
Keith Packard bf338efc67 glx/present: Only send GLX_BufferSwapComplete for PresentCompleteKindPixmap
Present didn't provide the 'kind' argument to the
present_complete_notify hook that GLX uses to construct
GLX_BufferSwapComplete events, so GLX was reporting events for
PresentCompleteKindMSC notifications, which resulted in duplicate
GLX_BufferSwapComplete events and crashes in clutter.

See the gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=733282

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2014-09-11 18:19:41 -07:00
Keith Packard 40dc81154a present: Avoid crash at server shutdown
When a present flip operation is still in process during server reset,
the call to present_set_abort_flip may not happen until the screen is
being closed, at which point there is no root window to set pixmaps
for. Check to make sure there's a window before resetting window pixmaps.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2014-07-31 00:03:55 -07:00
Keith Packard 627bce8089 present: Make window MSC offset 0 initially
The MSC offset used by a window is adjusted as the window moves
between screens, and between shown/unshown. The value shouldn't
matter, but it's helpful for debugging to have window MSC values be
the same as the CRTC MSC at first.

This patch introduces a unique CRTC value so that Present can detect
the first time a window is a PresentPixmap destination and set the MSC
offset to zero, rather than using the fake MSC value as the previous
window MSC.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2014-07-31 00:03:53 -07:00
Axel Davy ce581ac3fa present: fix bad logic in cancelling scheduled operations.
If we present several pixmaps in advance for different msc, the later one
shouldn't cancel the previous ones.

This reverts a change made by commit
e6f5d9d7b7

Without this fix, vblank_mode=0 glxgears doesn't update
with the present fallback.

Signed-off-by: Axel Davy <axel.davy@ens.fr>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-06-23 14:15:48 -07:00
Frank Binns 334faabe68 present: restore screen pixmap when aborting a flip
If a 2D application is started on top of a fullscreen 3D application, which
is flipping, then we need to stop flipping and restore the root window, and
possibly the flip window, to using the screen pixmap. Normally this would
be done as part of an unflip. However, in the case that there is a pending
flip there is no mechanism to abort so the unflip is deferred until the
pending flip completes. This provides a window of opportunity for the 2D
application to draw to the wrong pixmap.

Restore the screen pixmap at the point a pending flip is marked as aborted,
thus avoiding this issue.

Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Frank Binns <frank.binns@imgtec.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-06-23 13:48:20 -07:00
Keith Packard 382ff4a306 present: Remove executing vblank from window list. Bug# 79709.
Once the vblank is actually getting executed, it's lifetime is no
longer tied to the window, and so it shouldn't be controlled by window
destruction. In particular, if the vblank is queued for flip, it will
get stored in the flip_pending field, and will be correctly destroyed
when the flip completes.

Signed-off-by: Keith Packard <keithp@keithp.com>
2014-06-17 15:53:41 -07:00
Keith Packard e6f5d9d7b7 present: Queue flips for later execution
When a flip (or unflip) is pending and a flip request comes in, leave
it queued until the pending flip completes and then execute it.

This fixes a bug where an application submitting back-to-back
present_pixmap requests for sequential frames would alternate between
flipping and copying as the pending flip would cause the new
present_pixmap request to not use a flip.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Tested-by: Frank Binns <frank.binns@imgtec.com>
2014-06-04 22:03:35 -07:00
Keith Packard 60014a4a98 Replace 'pointer' type with 'void *'
This lets us stop using the 'pointer' typedef in Xdefs.h as 'pointer'
is used throughout the X server for other things, and having duplicate
names generates compiler warnings.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2014-01-12 10:24:11 -08:00
Keith Packard 2eb9915eea present: Set complete notify mode to Skip as needed
Skipped present pixmap calls were not setting the mode to
PresentCompleteModeSkip for skipped operations.

Signed-off-by: Keith Packard <keithp@keithp.com>
2013-12-20 12:28:00 -08:00
Keith Packard e487babd52 present: Don't abandon presents which are already queued for flip
Presents which are not marked 'queued' and are in the window present
list are waiting for the flip event; discarding those won't work very
well (it'll end up trashing displayed content for the next frame), so
skip over those when looking for duplicate frame presents

Signed-off-by: Keith Packard <keithp@keithp.com>
2013-12-20 12:28:00 -08:00
Keith Packard ca3a5b2a8f present: Handle PresentOptionAsync for copy mode
Check for Async flag and execute immediately if set, otherwise wait
for the next appropriate vblank before copying.

Signed-off-by: Keith Packard <keithp@keithp.com>
2013-12-20 12:28:00 -08:00
Adam Jackson 128449dd64 present: Don't use the major/minor version from the protocol headers
We want to advertise the version we implement, not the version the
protocol headers happen to describe.

Reviewed-by: Jasper St. Pierre <<jstpierre@mecheye.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-12-13 14:59:04 -05:00
Keith Packard fe07ec19e2 present: recursively set window pixmaps on flip
Newly created windows inherit the pixmap of their parent, similarly,
reparenting a tree inherits the pixmap of the destination tree.

Making present preserve the invariant that unredirected windows always
have the same pixmap as their parent ensures that the above cases work
correctly.

v2: name the recursive function to 'set_tree_pixmap' instead of 'set_window_pixmap'

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-10 14:16:42 -08:00
Adam Jackson 2bf9210829 present: Disable when Xinerama is active
Among much else Present depends on RANDR types, and RANDR isn't properly
Xinerama-aware yet anyway.

Reviewed-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2013-12-09 13:20:36 -05:00
Keith Packard 653d33941b present: Report damage when flipping
Limit damage to the 'update' region.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:51:00 -08:00
Keith Packard 5cf12c9569 present: Also set the root window pixmap when flipping
This makes sure that things like software cursors continue to work
while the screen is flipped.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:51:00 -08:00
Keith Packard 4aa77378de present: Clear target_crtc if driver lacks Present support
If the driver doesn't have the necessary hooks for Present, then the
target_crtc needs to be set to NULL to make sure the extension uses
the present_fake code.

Signed-off-by: Keith Packard <keithp@keithp.com>
Tested-by: Fredrik Höglund <fredrik@kde.org>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:51:00 -08:00
Keith Packard 3dd5bfe540 present: Send GLX_BufferSwapComplete events from present extension
This allows GL to support the GLX_INTEL_swap_event extension.

v2: Return GLX_BLIT_COMPLETE_INTEL for unknown swap types

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:51:00 -08:00
Keith Packard cde86e68fc present: Set window pixmap to flipped pixmap
This makes other drawing to the window appear on the screen.

Note that no child windows can be affected because only full-screen
windows are eligible for flipping, and so we only need to set pixmap
for the window itself.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:48:38 -08:00
Keith Packard 04e138846e present: Leave vblank on window list until flip complete
If the window is destroyed, then we've got cleanup work to do, even if
the vblank has already been executed -- we need to clear the window
pointer so that we don't try to deliver events to it.

Leaving it on the window list meant that when walking that list, we
need to know whether the vblank is waiting to be executed or waiting
for the flip to complete, so a new 'queued' flag was added to the
vblank to distinguish between the two states.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:48:36 -08:00
Keith Packard b121d62acc present: Add a debug output line when skipping a pending present
When an application provides two pixmaps for the same MSC, the
previous one is skipped. This just dumps out some information at that point

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-12-05 09:48:02 -08:00
Keith Packard 6403cbb143 present: When unflipping, copy to flip window rather than screen
unflip happens after the clip lists have been updated, so instead of
smashing the whole screen and drawing over other windows, just draw to
the original flip window; it'll have the right clip list and so the
copy will work just fine.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-20 13:12:33 -08:00
Keith Packard 8bdd2ccc77 present: Block for wait_fence in present_execute
Pend presentation until wait_fence is also triggered by having the
SyncFence trigger invoke present_execute once triggered.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-20 13:12:30 -08:00
Keith Packard e5a188cb91 present: Signal destroyed flip window with vblank->window == NULL
This eliminates dereferencing freed window pointers when there is a
flip for that window in progress. The flip will complete, and then
immediately get undone (as we can't stop an in-progress flip).

Remove the vblank->window_destroyed field as we can signal this with
vblank->window == NULL instead.

Change check to vblank->window == NULL in:

	present_flip_notify

Add check for vblank->window == NULL in:
	present_vblank_notify
	present_execute

present_flip_notify was also using vblank->window->drawable.pScreen,
so stop doing that and use vblank->screen instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-20 13:12:27 -08:00
Keith Packard a5bcc4f7b9 present: Ignore event_id 0 from driver vblank notify
We use event_id 0 to mean 'no such event'; if a driver sends us that
event_id, make sure we don't accidentally match it.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-20 13:12:25 -08:00
Keith Packard 4f3c37a1f1 present: Round fake MSC computations intead of truncating
If the timer fired too early, we'd sometimes mis-compute the MSC for
fake vblanks. Rounding the computation to the nearest MSC fixes this nicely.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-20 13:12:22 -08:00
Keith Packard 0822a23e04 present: Change debug output a bit to help diagnose missing vblank signals
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-11 15:16:38 -08:00
Keith Packard 20bb49ae9b Present: Check for window/fence destroyed when idling pixmaps
A client destroying objects in the middle of an unflip can end up
having the screen flip window or fence set to NULL in the unflip
notify path. Check for these and don't try to use those objects.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-11-11 15:16:15 -08:00
Keith Packard 5c5c1b7798 present: Add Present extension
Provides both a software implementation using timers and driver hooks
to base everything on vblank intervals.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2013-10-31 16:59:18 -07:00