Commit Graph

398 Commits

Author SHA1 Message Date
Łukasz Spintzyk d6c02ffd9c present: fallback get_crtc to return crtc belonging to screen with present extension
Since crtc can belong to secondary output that may not have present
extension enabled we should fallback to first enabled crtc or fake crtc.

Fix for issue xorg/xserver#1195
2021-07-20 08:10:46 +02:00
Michel Dänzer a6d178b6af randr: Bail from RRTellChanged if there's no root window yet
This can happen if RRTellChanged is called during initialization.

Continuing in that case makes no sense conceptually:

* Any event sent over the wire requires a corresponding window.
* No root window probably means there can't be any clients which could
  receive the events.

In practice, it would result in a crash down the road due to
dereferencing the NULL ScreenRec::root pointer.

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
2021-07-09 11:48:15 +02:00
Łukasz Spintzyk d2dce22b67 present: fix msc offset calculation in screen mode
Instead of getting the current msc value from the window crtc,
which not exist take the last saved msc value saved in
the window_priv struct

Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk@synaptics.com>
2021-04-16 10:53:43 +00:00
Jan Beich 376eaadde3 meson: hide C API if Xorg is disabled (like autotools)
When building only Xwayland using Meson some files are always installed.
This causes package conflict if Xwayland is built separately from Xorg.

  include/xorg/compositeext.h
  include/xorg/damage.h
  include/xorg/damagestr.h
  include/xorg/dbestruct.h
  include/xorg/dri3.h
  include/xorg/fb.h
  include/xorg/fboverlay.h
  include/xorg/fbpict.h
  include/xorg/fbrop.h
  include/xorg/geext.h
  include/xorg/geint.h
  include/xorg/glyphstr.h
  include/xorg/mi.h
  include/xorg/micmap.h
  include/xorg/micoord.h
  include/xorg/migc.h
  include/xorg/miline.h
  include/xorg/mioverlay.h
  include/xorg/mipict.h
  include/xorg/mipointer.h
  include/xorg/mipointrst.h
  include/xorg/mistruct.h
  include/xorg/misync.h
  include/xorg/misyncfd.h
  include/xorg/misyncshm.h
  include/xorg/misyncstr.h
  include/xorg/mizerarc.h
  include/xorg/panoramiX.h
  include/xorg/panoramiXsrv.h
  include/xorg/picture.h
  include/xorg/picturestr.h
  include/xorg/present.h
  include/xorg/presentext.h
  include/xorg/randrstr.h
  include/xorg/rrtransform.h
  include/xorg/shadow.h
  include/xorg/shmint.h
  include/xorg/syncsdk.h
  include/xorg/vndserver.h
  include/xorg/wfbrename.h
  include/xorg/xace.h
  include/xorg/xacestr.h
  include/xorg/xorg-server.h
  include/xorg/xvdix.h
  include/xorg/xvmcext.h
  share/aclocal/xorg-server.m4

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2021-03-11 00:22:36 +00:00
Alex Goins 8eeff5d788 randr: Check rrPrivKey in RRHasScanoutPixmap()
RRHasScanoutPixmap() is called from xf86CheckHWCursor(), regardless of whether
or not RandR has been initialized.

As mentioned in commit 4226c6d, it's possible that RandR has not been
initialized if the server is configured with Xinerama and there is more than one
X screen. Calling rrGetScrPriv when RandR isn't initialized causes an assertion
failure that aborts the server:

      Xorg: ../include/privates.h:121: dixGetPrivateAddr: Assertion
      key->initialized' failed.

Just as in commit 4226c6d, fix the problem by checking
dixPrivateKeyRegistered(rrPrivKey) before calling rrGetScrPriv.

Signed-off-by: Alex Goins <agoins@nvidia.com>
2020-07-21 15:53:53 +00:00
Alex Goins 6172bd2b41 randr: Check rrPrivKey before autobinding GPU screens
RRProviderAutoConfigGpuScreen() is called from outside RandR, so there is no
guarantee that RandR has been initialized when it is called.

As mentioned in commit 4226c6d, it's possible that RandR has not been
initialized if the server is configured with Xinerama and there is more than one
X screen. Calling rrGetScrPriv when RandR isn't initialized causes an assertion
failure that aborts the server:

  Xorg: ../include/privates.h:121: dixGetPrivateAddr: Assertion
  key->initialized' failed.

Just as in commit 4226c6d, fix the problem by checking
dixPrivateKeyRegistered(rrPrivKey) before calling rrGetScrPriv.

Signed-off-by: Alex Goins <agoins@nvidia.com>
2020-07-21 15:53:53 +00:00
Dave Airlie ea47af87f6 xserver/output: rename some badly named variables/APIs.
This is an API and ABI break

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-10 06:17:44 +10:00
Alexander Volkov 9937183e4b Fix build with gcc 9.3.0's -Werror=alloc-size-larger-than= 2020-05-01 20:02:29 +00:00
Pekka Paalanen bfb36a5806 randr: auto-bind of GPU is a config change
When a GPU is auto-bound adding more outputs to a screen, that needs to count
as a configuration change on that screen so that a WM listening for
RRScreenChangeNotify gets notified and handles it as a hotplug. This is
particularly for cases where the outputs are already connected. Otherwise
nothing might happen.

Issue #909 describes a real world case where plugging in a DisplayLink dock
with a monitor already connected is sometimes left inactive by GNOME. That
issue is a race, and requires adding a sleep(5); as the first thing in
NewGPUDeviceRequest() to reproduce reliably. With the sleep, the monitor in the
dock will never activate automatically. Add this fix over the sleep, and the
issue is gone.

This fix was originally developed on a branch replicating Ubuntu 19.04 patch
set based on xserver 1.20.4. Testing on master branch was impossible due to
xorg/xserver#910.

Closes: https://gitlab.freedesktop.org/xorg/xserver/issues/909

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2020-02-10 16:07:41 +01:00
Alex Goins c82f814313 randr: Fix RRCrtcDetachScanoutPixmap() segfault during server teardown
During server teardown, mrootdraw is NULL, which can cause segfaults if
master->Stop{,Flipping}PixmapTracking() don't do NULL checking. In this case we
shouldn't need to do master->Stop{,Flipping}PixmapTracking() anyway, so just
skip it.

Signed-off-by: Alex Goins <agoins@nvidia.com>
2019-11-11 14:35:57 -08:00
Dave Airlie 078277e4d9 xf86: autobind GPUs to the screen
This is a modified version of a patch we've been carry-ing in Fedora and
RHEL for years now. This patch automatically adds secondary GPUs to the
master as output sink / offload source making e.g. the use of
slave-outputs just work, with requiring the user to manually run
"xrandr --setprovideroutputsource" before he can hookup an external
monitor to his hybrid graphics laptop.

There is one problem with this patch, which is why it was not upstreamed
before. What to do when a secondary GPU gets detected really is a policy
decission (e.g. one may want to autobind PCI GPUs but not USB ones) and
as such should be under control of the Desktop Environment.

Unconditionally adding autobinding support to the xserver will result
in races between the DE dealing with the hotplug of a secondary GPU
and the server itself dealing with it.

However we've waited for years for any Desktop Environments to actually
start doing some sort of autoconfiguration of secondary GPUs and there
is still not a single DE dealing with this, so I believe that it is
time to upstream this now.

To avoid potential future problems if any DEs get support for doing
secondary GPU configuration themselves, the new autobind functionality
is made optional. Since no DEs currently support doing this themselves it
is enabled by default. When DEs grow support for doing this themselves
they can disable the servers autobinding through the servers cmdline or a
xorg.conf snippet.

Signed-off-by: Dave Airlie <airlied@gmail.com>
[hdegoede@redhat.com: Make configurable, fix with nvidia, submit upstream]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
---
Changes in v2:
-Make the default enabled instead of installing a xorg.conf
 snippet which enables it unconditionally

Changes in v3:
-Handle GPUScreen autoconfig in randr/rrprovider.c, looking at
 rrScrPriv->provider, rather then in hw/xfree86/modes/xf86Crtc.c
 looking at xf86CrtcConfig->provider. This fixes the autoconfig not
 working with the nvidia binary driver
2019-08-07 12:26:59 +02:00
Alex Goins a90f33721e randr: rrCheckPixmapBounding should only increase screen size
The purpose of rrCheckPixmapBounding() is to make sure that the fb is large
enough to accommodate the region scanned out by a GPU screen. Currently, however,
it will actually shrink the fb if it's larger than it needs to be.

This is a problem when combining PRIME output slaving with arbitrary transforms
with xrandr.

Although arbitrary transforms are not supposed to constrain the size of the fb
(https://lists.freedesktop.org/archives/xorg-devel/2018-January/055563.html),
xrandr will use RRSetScreenSize to resize the desktop to accommodate scaling
transforms, e.g. scaling a 1920x1080 display to 3840x2160 will result in a
desktop size of 3840x2160.

In the case of PRIME, rrCheckPixmapBounding() will be called after
RRSetScreenSize() and it will resize the fb back down to what it would be
without the scaling transform, e.g. 1920x1080. This represents divergence in
behavior between PRIME and non-PRIME outputs.

I had originally made rrCheckPixmapBounding() account for arbitrary transforms,
but realized that the fb being large enough to accommodate arbitrary transforms
is not a hard requirement enforced in the server. Instead, this change simply
makes it so that rrCheckPixmapBounding() will only resize the fb to be larger
than it already is, preventing it from stepping on prior requests to increase
the size of the fb.

Signed-off-by: Alex Goins <agoins@nvidia.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2018-08-24 09:55:48 +02:00
Keith Packard 1ef7aed3e2 During reset/shutdown, clean up leases in DIX instead of each driver
Instead of having every video driver loop over any pending leases to
free them during CloseScreen, do this up in the DIX layer by
terminating leases when a leased CRTC or Output is destroyed and
(just to make sure), also terminating leases in RRCloseScreen. The
latter should "never" get invoked as any lease should be associated
with a resource which was destroyed.

This is required as by the time the driver's CloseScreen function is
invoked, we've already freed all of the DIX randr structures and no
longer have any way to reference the leases

Signed-off-by: Keith Packard <keithp@keithp.com>
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=106960
Cc: Thomas Hellstrom <thellstrom@vmware.com>
2018-08-02 10:15:26 -04:00
Lyude Paul dc90b1c3c3 randr: Scream when creating a shared pixmap fails
This seems like a problem worth screaming about.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2018-06-27 15:08:55 -04:00
Eric Anholt 4ec02b573e randr: Fix a compiler warning on 32-bit.
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-05-08 11:59:31 -04:00
Chris Wilson d7297b0044 randr: Account for panning and transforms when constraining the cursor
commit 56c90e29f0 [1.10.99.901]
Author: Adam Jackson <ajax@redhat.com>
Date:   Mon Nov 15 14:29:14 2010 -0500

    randr: Add RRConstrainCursorHarder

introduced a regression as it ignored the effect of panning and
transforms upon the crtc bounds. The result was that the cursor would be
constrained to the visible area even though the panning arena was much
bigger, or the cursor was constrained to a region that did not even
match the visible area when the output was transformed or reflected.

This supercedes the hack introduced by
commit 1bf81af4a6 [1.12.99.904]
Author: Rui Matos <tiagomatos@gmail.com>
Date:   Mon Jul 30 14:32:12 2012 -0400

    xf86RandR12: Don't call ConstrainCursorHarder() if panning is enabled
which disabled the cursor constraints if a panning mode was active, but
did not fix the regression with arbitrary output transforms.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=39949
Reviewed-by: Adam Jackson <ajax@redhat.com>
Cc: Rui Matos <tiagomatos@gmail.com>
2018-05-02 12:20:01 -04:00
Thierry Reding 88c7b8bf4b meson: Distribute more SDK headers
Install missing headers to the SDK directory to allow external modules
to properly build against the SDK. After this commit, the list of files
installed in the SDK include directory is the same as the list of files
installed by the autotools-based build.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2018-04-02 13:42:08 -04:00
Michel Dänzer 17d30369f4 randr: Initialize RROuptutRec::nonDesktop
Flagged by valgrind:

==13695== Conditional jump or move depends on uninitialised value(s)
==13695==    at 0x22461C: RRNoticePropertyChange (rrproperty.c:150)
==13695==    by 0x22461C: RRChangeOutputProperty (rrproperty.c:263)
==13695==    by 0x222FC4: RROutputSetNonDesktop (rroutput.c:333)
==13695==    by 0x22319C: RROutputCreate (rroutput.c:122)
==13695==    by 0x1E1CE9: xf86RandR12CreateObjects12 (xf86RandR12.c:1734)
==13695==    by 0x1E1CE9: xf86RandR12Init12 (xf86RandR12.c:2375)
==13695==    by 0x1E1CE9: xf86RandR12Init (xf86RandR12.c:895)
==13695==    by 0x1D469B: xf86CrtcScreenInit (xf86Crtc.c:778)
==13695==    by 0xC095A54: RADEONScreenInit_KMS (radeon_kms.c:2436)
==13695==    by 0x161444: AddGPUScreen (dispatch.c:3966)
==13695==    by 0x1A3E46: InitOutput (xf86Init.c:763)
==13695==    by 0x1654A7: dix_main (main.c:193)
==13695==    by 0x7041A86: (below main) (libc-start.c:310)
==13695==  Uninitialised value was created by a heap allocation
==13695==    at 0x4C2CB8F: malloc (vg_replace_malloc.c:299)
==13695==    by 0x223083: RROutputCreate (rroutput.c:83)
==13695==    by 0x1E1CE9: xf86RandR12CreateObjects12 (xf86RandR12.c:1734)
==13695==    by 0x1E1CE9: xf86RandR12Init12 (xf86RandR12.c:2375)
==13695==    by 0x1E1CE9: xf86RandR12Init (xf86RandR12.c:895)
==13695==    by 0x1D469B: xf86CrtcScreenInit (xf86Crtc.c:778)
==13695==    by 0xC095A54: RADEONScreenInit_KMS (radeon_kms.c:2436)
==13695==    by 0x161444: AddGPUScreen (dispatch.c:3966)
==13695==    by 0x1A3E46: InitOutput (xf86Init.c:763)
==13695==    by 0x1654A7: dix_main (main.c:193)
==13695==    by 0x7041A86: (below main) (libc-start.c:310)

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2018-03-14 10:20:47 -07:00
Adam Jackson 2af0a50a4b randr: Fix a crash on initialization with GPU screens
RRSetChanged (immediately above) was immune to screens with no master,
but RRTellChanged was not:

    Thread 1 "X" received signal SIGSEGV, Segmentation fault.
    RRTellChanged (pScreen=<optimized out>) at ../../randr/randr.c:576
    576             mastersp = rrGetScrPriv(master);
    (gdb) bt
    #0  RRTellChanged (pScreen=<optimized out>) at ../../randr/randr.c:576
    #1  0x000055555566f1e9 in RRNoticePropertyChange (value=0x555555bfbf28, property=70, output=0x555555bfef10) at ../../randr/rrproperty.c:153
    #2  RRChangeOutputProperty (output=output@entry=0x555555bfef10, property=<optimized out>, type=type@entry=19, format=format@entry=32, mode=<optimized out>, mode@entry=0, len=len@entry=1, value=0x7fffffffe77c, sendevent=1, pending=0)
        at ../../randr/rrproperty.c:263
    #3  0x000055555566dba5 in RROutputSetNonDesktop (output=output@entry=0x555555bfef10, nonDesktop=nonDesktop@entry=0) at ../../randr/rroutput.c:333
    ...

Reported-by: Michel Dänzer <michel@daenzer.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-03-01 11:33:29 -05:00
Keith Packard e4e3447603 Add RandR leases with modesetting driver support [v6]
This adds support for RandR CRTC/Output leases through the modesetting
driver, creating a lease using new kernel infrastructure and returning
that to a client through an fd which will have access to only those
resources.

v2:	Restore CRTC mode when leases terminate

	When a lease terminates for a crtc we have saved data for, go
	ahead and restore the saved mode.

v3:	Report RR_Rotate_0 rotations for leased crtcs.

	Ignore leased CRTCs when selecting screen size.

	Stop leasing encoders, the kernel doesn't do that anymore.

	Turn off crtc->enabled while leased so that modesetting
	ignores them.

	Check lease status before calling any driver mode functions

	When starting a lease, mark leased CRTCs as disabled and hide
	their cursors. Also, check to see if there are other
	non-leased CRTCs which are driving leased Outputs and mark
	them as disabled as well. Sometimes an application will lease
	an idle crtc instead of the one already associated with the
	leased output.

	When terminating a lease, reset any CRTCs which are driving
	outputs that are no longer leased so that they start working
	again.

	This required splitting the DIX level lease termination code
	into two pieces, one to remove the lease from the system
	(RRLeaseTerminated) and a new function that frees the lease
	data structure (RRLeaseFree).

v4:	Report RR_Rotate_0 rotation for leased crtcs.

v5: Terminate all leases on server reset.

	Leases hang around after the associated client exits so that
	the client doesn't need to occupy an X server client slot and
	consume a file descriptor once it has gotten the output
	resources necessary.

	Any leases still hanging around when the X server resets or
	shuts down need to be cleaned up by calling the kernel to
	terminate the lease and freeing any DIX structures.

	Note that we cannot simply use the existing
	drmmode_terminate_lease function on each lease as that wants
	to also reset the video mode, and during server shut down that

   modesetting: Validate leases on VT enter

	The kernel doesn't allow any master ioctls to run when another
	VT is active, including simple things like listing the active
	leases. To deal with that, we check the list of leases
	whenever the X server VT is activated.

   xfree86: hide disabled cursors when resetting after lease termination

	The lessee may well have played with cursors and left one
	active on our screen. Just tell the kernel to turn it off.

v6:	Add meson build infrastructure

[Also bumped libdrm requirement - ajax]

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-02-27 12:39:50 -05:00
Keith Packard 3957360505 randr: Support "non-desktop" property
Tracks changes to the non-desktop property so that when non-zero,
outputs will always appear to be disconnected.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@nwnk.net>
2018-02-27 12:34:26 -05:00
Alex Goins 6b26a7bda9 randr: Fix rotation check in ProcRRSetScreenSize()
ProcRRSetScreenSize() does bounds checking to ensure that none of the CRTCs have
a viewport that extends beyond the new screen size. In doing so, it accounts for
if the CRTC is rotated 90 or 270 degrees, swapping width and height.

However, it does so by testing if crtc->rotation is equal to RR_Rotate_90 or
RR_Rotate_270. crtc->rotation is a bit mask, and it includes reflection as well
as rotation. If a CRTC is reflected as well as rotated, it will incorrectly fail
this test, resulting in incorrect dimensions being used to verify the validity
of the new screen size. In some cases, this can cause valid uses of
ProcRRSetScreenSize() to fail with BadMatch.

This patch fixes the issue by testing that the bits RR_Rotate_90 or
RR_Rotate_270 are set, rather than testing for equality.

Signed-off-by: Alex Goins <agoins@nvidia.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2018-02-01 16:36:59 -05:00
Giuseppe Bilotta 94e7ca6a56 rrmonitor: allocate using the correct type
Monitor outputs are of type RROutput, not RRCrtc.

(Which are both XID, so this makes no difference in practice, other than
being technically correct.)

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-31 14:43:56 -05:00
Keith Packard 29f79bedf2 randr: Declare incoming property values const
RRChangeOutputProperty and RRConfigureOutputProperty should not modify
their parameters, and callers may want to pass pointers to fixed data,
so declare the value pointers as const in both cases.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2018-01-22 17:22:21 -05:00
Giuseppe Bilotta fc7fb5bbe1 randr: free crtc->outputs on destroy
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
2017-11-20 16:13:28 -05:00
Giuseppe Bilotta 16381d186e randr: always realloc crtcs and outputs
When the last crtc (resp. output) is destroyed, the rrScrPriv crtcs
(resp. outputs) fields do not get cleared, which can lead to a situation
where the private's numCrtcs (resp. numOutputs) field is zero, but the
associated memory is still allocated. Just checking if numCrtcs (resp.
numOutputs) is zero is thus not a good criteria to determine whetehr to
use a realloc or a malloc.

Since crtcs (resp. outputs) are NULL-initialized anyway, relying on
numCrtcs (resp. numOutputs) is actually unnecessary, because
reallocation of a NULL ptr is equivalent to a malloc anyway.

Therefore, just use realloc() unconditionally, and ensure that the
fields are properly initialized.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
2017-11-20 16:13:20 -05:00
Giuseppe Bilotta fb5ee77b91 randr: rrGetScreenResources: initialize memory
Similarly to bb766ef112, ensure that the
extra padding is set to 0.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
2017-11-20 16:13:17 -05:00
Giuseppe Bilotta bb766ef112 randr: ProcRRGetOutputInfo: initialize memory
Running Xephyr under valgrind reveals that we're sending some
uninitialized memory over the wire (particularly, the leftover padding
that comes from rounding extraLen to the next 32-bit multiple).

Solve by calloc()ing the memory instead of malloc()ing (the alternative
would be to memset just the padding, but I'm not sure it's more
convenient.)

Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-11-06 16:54:22 -05:00
Michel Dänzer 8e3b26ceaa Make PixmapDirtyUpdateRec::src a DrawablePtr
This allows making the master screen's pixmap_dirty_list entries
explicitly reflect that we're now tracking the root window instead of
the screen pixmap, in order to allow Present page flipping on master
outputs while there are active slave outputs.

Define HAS_DIRTYTRACKING_DRAWABLE_SRC for drivers to check, but leave
HAS_DIRTYTRACKING_ROTATION defined as well to make things slightly
easier for drivers.

Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-08-15 17:01:39 +09:00
Aaron Plattner 091af80be4 randr: Use RRTransformEqual in RRCrtcPendingTransform
Currently, RRCrtcPendingTransform returns false unless the
transformation matrix itself is changing. This makes RRCrtcSet skip
doing anything if the only thing that is changing is the transform
filter.

There's already a function for comparing RRTransformPtrs, so use that
instead.

Tested by running

  xrandr --output DP-1 --mode 1920x1080 --rate 144 --scale 0.5x0.5 --filter nearest

follwed by

  xrandr --output DP-1 --mode 1920x1080 --rate 144 --scale 0.5x0.5 --filter bilinear

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
2017-06-19 17:49:41 +09:00
Eric Anholt 1549e30372 Add a Meson build system alongside autotools.
This is a work in progress that builds Xvfb, Xephyr, Xwayland, Xnest,
and Xdmx so far.  The outline of Xquartz/Xwin support is in tree, but
hasn't been built yet.  The unit tests are also not done.

The intent is to build this as a complete replacement for the
autotools system, then eventually replace autotools.  meson is faster
to generate the build, faster to run the bulid, shorter to write the
build files in, and less error-prone than autotools.

v2: Fix indentation nits, move version declaration to project(), use
    existing meson_options for version-config.h's vendor name/web.

Signed-off-by: Eric Anholt <eric@anholt.net>
Acked-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-26 15:25:27 -07:00
Adam Jackson dc7ceda90f dispatch: Mark swapped dispatch as _X_COLD
This touches everything that ends up in the Xorg binary; the big missing
part is GLX since that's all generated code. Cuts about 14k from the
binary on amd64.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-03-01 10:16:20 -05:00
Qiang Yu 555e0a42d1 randr: fix xserver crash when xrandr setprovideroutputsource
xrandr --setprovideroutputsource <screen> <gpu screen>
Xorg: ../../../xserver/dix/dispatch.c:4018: AttachOutputGPU:
Assertion `new->isGPU' failed.

GPUScreen is not allowed to be sink output.

Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-11 11:13:45 +10:00
Michal Srb c96c860b64 xinerama: Swap the response in RRXineramaWriteMonitor
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-01-02 13:39:07 -05:00
Hans de Goede a46afee84d randr: rrCheckPixmapBounding: do not shrink the screen_pixmap
The purpose of rrCheckPixmapBounding is to make sure that the
screen_pixmap is *large* enough for the slave-output which crtc is
being configured.

However until now rrCheckPixmapBounding would also shrink the
screen_pixmap in certain scenarios leading to various problems.

For example: Take a laptop with its internalscreen on a slave-output and
currently disabled and an external monitor at 1920x1080+0+0.
Now lets say that we want to drive the external monitor at its native
resolution of 2560x1440 and have the internal screen mirror the top left
part of the external monitor, so we run:

  $ xrandr --output eDP --mode 1920x1080 --pos 0x0 --output HDMI \
  --mode 2560x1440 --pos 0x0

Here xrandr utility first calls RRSetScreenSize to 2560x1440, then it
calls RRSetCrtc 1920x1080+0+0 on the eDP, since this is a slave output,
rrCheckPixmapBounding gets called and resizes the screen_pixmap to
1920x1080, undoing the RRSetScreenSize. Then RRSetCrtc 2560x1440+0+0
gets called on the HDMI, depending on crtc->transforms this will
either result in a BadValue error from ProcRRSetCrtcConfig; or
it will succeed, but the monitor ends up running at 2560x1440
while showing a 1920x1080 screen_pixmap + black borders on the right
and bottom. Neither of which is what we want.

This commit removes the troublesome shrinking behavior, fixing this.

Note:

1) One could argue that this will leave us with a too large screen_pixmap
in some cases, but rrCheckPixmapBounding only gets called for slave
outputs, so xrandr clients already must manually shrink the screen_pixmap
after disabling crtcs in normal setups.

2) An alternative approach would be to also call rrCheckPixmapBounding
on RRSetCrtc on normal (non-slave) outputs, but that would result in
2 unnecessary resizes of the screen_pixmap in the above example, which
seems undesirable.

Cc: Nikhil Mahale <nmahale@nvidia.com>
Cc: Dave Airlie <airlied@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2016-12-05 11:21:49 +01:00
Hans de Goede 3b624aa9a9 randr: rrCheckPixmapBounding: Do not substract crtc non 0 x,y from screen size
The purpose of rrCheckPixmapBounding is to make sure that the
screen_pixmap is large enough for the slave-output which crtc is
being configured.

This should include crtc->x and crtc->y, otherwise the crtc might
still end up scanning out an area outside of the screen-pixmap.

For example: Take a laptop with an external monitor on a slave-output at
1920x1080+0+0 and its internal-screen at 3840x2160+1920+0 and in
gnome-settings-daemon move the external monitor to be on the ri ght of
the internal screen rather then on the left. First g-s-d will do a
RRSetScreenSize to 5760*2160 (which is a nop), then it calls RRSetCrtc
to move the slave output to 1920x1080+3840+0, since this is a slave
output, rrCheckPixmapBounding gets called, since the 2 crtcs now overlap
the code before this commit would shrinks the screen_pixmap to 3180*2160.
Then g-s-d calls RRSetCrtc to move the internal screen to 3180*2160+0+0.

And we end up with the slave-output configured to scan-out an area
which completely falls outside of the screen-pixmap (and end up with
a black display on the external monitor).

This commit fixes this by not substracting the x1 and y1 coordinates
of the union-ed region when determining the new screen_pixmap size.

Cc: Nikhil Mahale <nmahale@nvidia.com>
Cc: Dave Airlie <airlied@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2016-12-05 11:21:48 +01:00
Hans de Goede 35c4e96ed1 randr: Fix crtc_bounds when using rotation combined with reflection
Before this commit crtc_bounds() did not take reflection into account,
when using reflection with 0 / 180 degree rotation this was not an
issue because of the default in the switch-case doing the right thing.

But when using 90 / 270 degree rotation we would also end up in the
default which is wrong in this case. This would lead to the cursor
being constrained to a height x height area of the monitor.

This commit masks out the reflection bits for the switch-case,
making crtc_bounds return the correct bounds and fixing the
problematic cursor constraining.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-13 10:27:30 +02:00
Hans de Goede 2eefb53f58 randr: Add RRHasScanoutPixmap helper function
This is a preparation patch for adding prime hw-cursor support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-13 10:26:47 +02:00
agoins df8e86931e randr: Add ability to turn PRIME sync off
Adds an output parameter to disable PRIME synchronization.

Output parameter is created when the user calls 'xrandr
--setprovideroutputsource <sink> <source>' to prevent polluting output
parameters of non-PRIME configurations.

Defaults to on, so if the user wants PRIME synchronization they don't need
to do anything.

If the user wishes to disable PRIME synchronization when they first set up
PRIME, they can run 'xrandr --output <output> --set "PRIME Synchronization"
0' after running 'xrandr --setprovideroutputsource <sink> <source>', but
before 'xrandr --auto'.

If the user wishes to enable or disable PRIME synchronization after PRIME has
already been set up, they can run 'xrandr --output <output> --set "PRIME
Synchronization" <0 or 1>' at any time, xrandr will trigger a modeset, which
will tear down and setup PRIME in the configuration they requested on CRTCs
associated with that output.

randrstr.h:
    Add central definition of the output property name.

rrcrtc.c:
    Add function rrGetPixmapSharingSyncProp() to query the status of the
    output property.

    Add function rrSetPixmapSharingSyncProp() to set the output property.

    Add 'sync' parameter to rrSetupPixmapSharing(), which when false will
    use single buffering even if the required ABI functions are supported.
    Changes rrSetupPixmapSharing() to only report an error if falling back
    to single buffering when the user requested synchronization.

    Change RRCrtcSet() to use rrPixmapSharingSyncProp() to query the status
    of the output property and feed it into rrSetupPixmapSharing() using
    the 'sync' parameter.

rrprovider.c:
    Add RR(Init/Fini)PrimeSyncProps(), functions to create and destroy the
    PRIME synchronization output property.

    Add a call to RRInitPrimeSyncProps() in
    ProcRRSetProviderOutputSource(), such that the output property is
    created when the user requests PRIME.

    Add a call to RRFiniPrimeSyncProps() in RRProviderDestroy().

v1: Initial commit
v2: Unchanged
v3: Add /* TODO */ for handling different sources with different outputs
    Make rrSetupPixmapSharing() set the output property to 0 if it has to fall
    back, to avoid user confusion.
    Make rr(Get)PixmapSharingSyncProp() check the current value if there isn't a
    pending value
v4: Unchanged
v5: Unchanged
v6: Rebase onto ToT
v7: Unchanged

Signed-off-by: Alex Goins <agoins@nvidia.com>
2016-07-05 14:30:27 -04:00
Alex Goins 1bdbc7e764 randr/xf86: Add PRIME Synchronization / Double Buffer
Changes PRIME to use double buffering and synchronization if all required
driver functions are available.

rrcrtc.c:
    Changes rrSetupPixmapSharing() to use double buffering and
    synchronization in the case that all required driver functions are
    available. Otherwise, falls back to unsynchronized single buffer.

    Changes RRCrtcDetachScanoutPixmap() to properly clean up in the case of
    double buffering.

    Moves StopPixmapTracking() from rrDestroySharedPixmap() to
    RRCrtcDetachScanoutPixmap().

    Changes RRReplaceScanoutPixmap() to fail if we are using double buffering,
    as it would need a second ppix parameter to function with double buffering,
    and AFAICT no driver I've implemented double buffered source support in uses
    RRReplaceScanoutPixmap().

randrstr.h:
    Adds scanout_pixmap_back to struct _rrCrtc to facilitate PRIME
    double buffering.

xf86Crtc.h:
    Adds current_scanout_back to _xf86Crtc to facilitate detection
    of changes to it in xf86RandR12CrtcSet().

xf86RandR12.c:
    Changes xf86RandR12CrtcSet() to detect changes in
    scanout_pixmap_back.

    Adds scanout_pixmap_back to struct _rrCrtc to facilitate PRIME double
    buffering.

v1: Initial commit
v2: Rename PresentTrackedFlippingPixmap to PresentSharedPixmap
v3: Refactor to accomodate moving (rr)StartFlippingPixmapTracking and
    (rr)(Enable/Disable)SharedPixmapFlipping to rrScrPrivRec from ScreenRec
    Add fallback if flipping funcs fail
v4: Detach scanout pixmap when destroying scanout_pixmap_back, to avoid
    dangling pointers in some drivers
v5: Disable RRReplaceScanoutPixmap for double-buffered PRIME, it would need an
    ABI change with support for 2 pixmaps if it were to be supported, but AFAICT
    no driver that actually supports double-buffered PRIME uses it.
    Refactor to use rrEnableSharedPixmapFlipping() as a substitute for
    rrCrtcSetScanoutPixmap() in the flipping case.
    Remove extraneous pSlaveScrPriv from DetachScanoutPixmap()
    Remove extraneous protopix and pScrPriv from rrSetupPixmapSharing()
v6: Rebase onto ToT
v7: Unchanged

Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Alex Goins <agoins@nvidia.com>
2016-06-28 12:56:17 -04:00
Alex Goins b601f96a59 xf86: Add PRIME flipping functions to Screen
Adds typedefs for (*RRStartFlippingPixmapTrackingProcPtr),
(*RREnableSharedPixmapFlippingProcPtr),
and (*RRDisableSharedPixmapFlippingProcPtr) in randrstr.h.

Adds typedefs for (*PresentSharedPixmapProcPtr),
(*SharedPixmapNotifyDamageProcPtr),
(*RequestSharedPixmapNotifyDamageProcPtr), and
(*StopFlippingPixmapTrackingProcPtr) in scrnintstr.h.

Adds RR(Enable/Disable)SharedPixmapFlipping, and
RRStartFlippingPixmapTracking to rrScrnPrivRec.

Adds StopFlippingPixmapTracking, PresentSharedPixmap,
SharedPixmapNotifyDamage, and RequestSharedPixmapNotifyDamage to ScreenRec.

rrScrnPrivRec used for functions that use RandR-private data types, and
ScreenRec used for the rest.

RREnableSharedPixmapFlipping will allow the sink driver to setup for
flipping between two shared pixmaps.

RRDisableSharedPixmapFlipping will allow the sink driver to do teardown
associated with flipping between two shared pixmaps.

(RRStart/Stop)FlippingPixmapTracking are merely the double-buffered
equivalents of (Start/Stop)PixmapTracking, allowing the source driver to do
whatever setup and teardown necessary for presenting on the two shared
pixmaps.

PresentSharedPixmap is a function exposed by the source driver for the X
server or sink driver to call to request a present on a given shared
pixmap.  This way, presents can be driven by the sink's vblank instead of a
timer or similar mechanism.

SharedPixmapNotifyDamage and RequestSharedPixmapNotifyDamage are OPTIONAL
(even for double-buffered PRIME) functions exposed by the sink driver and
the source driver, respectively. By calling
master->RequestSharedPixmapNotifyDamage(ppix), the sink driver can request
for the source driver to call slave->SharedPixmapNotifyDamage(ppix) in
response to damage on the master screen pixmap tracked by ppix.

v1: Initial commit
v2: Rename PresentTrackedFlippingPixmap to PresentSharedPixmap
    Add SharedPixmapNotifyDamage / RequestSharedPixmapNotifyDamage
v3: Add RRCrtcPtr as a parameter to StartFlippingPixmapTracking
    Move functions that use RandR-private data types to rrScrnPrivRec.
v4: Unchanged
v5: Add front and back parameters to RREnableSharedPixmapFlippingProcPtr
v6: Rebase onto ToT
v7: Unchanged

Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Alex Goins <agoins@nvidia.com>
2016-06-28 12:55:56 -04:00
Nikhil Mahale 15595d29c2 randr: Adjust master's last set time with slaves
In prime configurations master's last set time may not be latest
and greatest, adjust it with slaves last set time, pick up greatest
one. Otherwise xserver may end with events which has
lastSetTime < lastConfigTime even if that's not
the case and confuse xrandr client.

[hdegoede: rebase on "xrandrprovider: Do not use separate lists for unbound /
 source / offload slaves"]
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-06-17 11:38:13 +02:00
Hans de Goede 5c7af02b10 xrandrprovider: Do not use separate lists for unbound / source / offload slaves
A single provider can be both a offload and source slave at the same time,
the use of seperate lists breaks in this case e.g. :

xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x7b cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 2 associated providers: 0 name:modesetting
Provider 1: id: 0x46 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 2 outputs: 5 associated providers: 0 name:modesetting

xrandr --setprovideroutputsource 1 0x7b
xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x7b cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 2 associated providers: 1 name:modesetting
Provider 1: id: 0x46 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 2 outputs: 5 associated providers: 1 name:modesetting

xrandr --setprovideroffloadsink 1 0x7b
xrandr --listproviders
Providers: number : 3
Provider 0: id: 0x7b cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 3 outputs: 2 associated providers: 2 name:modesetting
Provider 1: id: 0x46 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 2 outputs: 5 associated providers: 2 name:modesetting
Provider 2: id: 0x46 cap: 0xf, Source Output, Sink Output, Source Offload, Sink Offload crtcs: 2 outputs: 5 associated providers: 2 name:modesetting

Not good. The problem is that the provider with id 0x46 now is on both
the output_slave_list and the offload_slave_list of the master screen.

This commit fixes this by unifying all 3 lists into a single slaves list.

Note that this does change the struct _Screen definition, so this is an ABI
break. I do not expect any of the drivers to actually use the removed / changed
fields so a recompile should suffice.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2016-06-17 11:35:58 +02:00
Olivier Fourdan 941aeb3b92 randr: Do not update ConnectionInfo if NULL
RRScreenSizeNotify() will update the connection information block, but
if this occurs during initialization before ConnectionInfo is even
initialized, this will lead to a crash.

Simply check for ConnectionInfo prior to update it to avoid the crash.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=95337
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2016-06-13 16:06:05 -04:00
Dave Airlie a6b6e8ba02 prime: clean up slave bo properly. (v3)
This is an ABI break, in that we now pass NULL to a function that hasn't
accepted it before.

Alex Goins had a different patch for this but it wasn't symmetrical, it
freed something in a very different place than it allocated it, this
attempts to retain symmetry in the releasing of the backing bo.

v2: use a new toplevel API, though it still passes NULL to something
that wasn't expecting it.
v3: pass -1 instead of 0.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Alex Goins <agoins at nvidia.com>
2016-06-08 12:51:51 -04:00
Dave Airlie fc1f61b75c randr/provider: only allow slave gpu to be offload sources.
The other way around makes no sense.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2016-05-04 15:33:10 -04:00
Adam Jackson 137ac094e7 dix: Push UpdateCurrentTimeIf down out of the main loop
This was added in:

    commit 312910b4e3
    Author: Chase Douglas <chase.douglas@canonical.com>
    Date:   Wed Apr 18 11:15:40 2012 -0700

        Update currentTime in dispatch loop

Unfortunately this is equivalent to calling GetTimeInMillis() once per
request. In the absolute best case (as on Linux) you're only hitting the
vDSO; on other platforms that's a syscall. Either way it puts a pretty
hard ceiling on request throughput.

Instead, push the call down to the requests that need it; basically,
grab processing and event generation.

Cc: Chase Douglas <chase.douglas@canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2016-05-04 10:58:01 -04:00
Keith Packard dbe8d03c42 randr: Send ConfigNotify when manual monitor list changes
This lets clients know that the layout of the monitors on the screen
has changed so they can adapt appropriately.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2016-02-16 20:56:39 -08:00
Jan Burgmeier 7bb64d8c1d Fix XineramaQueryScreens for reverse prime
Make sure we account for slave CRTCs when building the monitor list,
since that's what rrxinerama uses to fake Xinerama geometry.

[ajax: Slightly more informative commit message.]

Bugzilla: https://bugs.freedesktop.org/92313
Reviewed-by: Dave Airlie <airlied@redhat.com>
2016-02-08 17:22:34 -05:00
Adam Jackson e98b36bc69 randr: Silence unused variable warning
Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2015-12-09 09:33:56 -05:00