Commit Graph

538 Commits

Author SHA1 Message Date
Olivier Fourdan
7eba412072 xfree86: Move xf86CVTMode() function
The xf86CVTMode() was implemented in a standalone source file because it
was being used for both the xfree86 API and the standalone cvt utility.

Now that the cvt utility is removed (as part of libxcvt) we can move the
small xf86CVTMode() function with the rest of the xf86Modes sources.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
2021-08-06 11:29:29 +00:00
Olivier Fourdan
f788289bdc xfree86: Use libxcvt
Replace the local implementation of the VESA CVT standard timing
modelines generator with the one from libxct to avoid code duplication.

Closes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1142
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
2021-08-06 11:29:29 +00:00
Daniel Strnad
05b3c681ea hw/xfree86: Propagate physical dimensions from DRM connector
Physical dimmension of display can be obtained not just by configuration or
DDC, but also directly from kernel via drmModeGetConnector(). Until now
xserver silently discarded these values even when no configuration nor EDID
were present and fallbacked to default DPI.
2021-06-15 13:21:11 +00:00
Alex Goins
495bf63a7d randr: Re-add removed NULL checks to xf86RandR12.c
Commit 1e3f9ea1 removed some NULL checks from xf86RandR12.c, on the premise that
they can't be reached unless RandR has already been initialized. For threesuch
calls, that's not true:

xf86Crtc.c::xf86CrtcScreenInit():

    if (c == config->num_crtc) {
        xf86RandR12SetRotations(screen, RR_Rotate_0 | RR_Rotate_90 |
                                RR_Rotate_180 | RR_Rotate_270 |
                                RR_Reflect_X | RR_Reflect_Y);
        xf86RandR12SetTransformSupport(screen, TRUE);
    }
    else {
        xf86RandR12SetRotations(screen, RR_Rotate_0);
        xf86RandR12SetTransformSupport(screen, FALSE);
    }

xf86Crtc.c::xf86CrtcCloseScreen():

    xf86RandR12CloseScreen(screen);

This change adds checks back to xf86RandR12Set{Rotations,TransformSupport}() and
xf86RandR12CloseScreen(), checking that xf86RandR12KeyRec has been registered.
Without this, X will hit an assert that causes it to abort.

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
Alan Coopersmith
23e83724df Fix spelling/wording issues
Most (but not all) of these were found by using
  codespell --builtin clear,rare,usage,informal,code,names
but not everything reported by that was fixed.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2020-07-05 13:07:33 -07:00
Aaron Ma
6a79a737e2 xfree86: add drm modes on non-GTF panels
EDID1.4 replaced GTF Bit with Continuous or Non-Continuous Frequency Display.

Check the "Display Range Limits Descriptor" for GTF support.
If panel doesn't support GTF, then add gtf modes.

Otherwise X will only show the modes in "Detailed Timing Descriptor".

V2: Coding style changes.
V3: Coding style changes, remove unused variate.
V4: remove unused variate.

BugLink: https://gitlab.freedesktop.org/drm/intel/issues/313
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2020-06-23 13:09:20 +08:00
Michel Dänzer
6a5e47c57d xfree86/modes: Bail from xf86RotateRedisplay if pScreen->root is NULL
Avoids a crash in xf86RotatePrepare -> DamageRegister during
CreateScreenResources if rotation or another transform is configured for
any connected RandR output in xorg.conf. The generic rotation/transform
code generally can't work without the root window currently.

Closes: https://gitlab.freedesktop.org/xorg/xserver/issues/969
Fixes: 094f42cdfe "xfree86/modes: Call xf86RotateRedisplay from
                     xf86CrtcRotate"
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2020-01-30 17:53:12 +01:00
Michel Dänzer
327df450ff xfree86/modes: Call xf86RotateRedisplay from xf86CrtcRotate
If a new rotate buffer was allocated. This makes sure the new buffer
has valid transformed contents when it starts being displayed.

Reviewed-by: Adam Jackson <ajax@redhat.com>
2019-11-25 18:46:31 +01:00
Adam Jackson
ff310903f3 mi: Add a default no-op miSourceValidate
Slightly simplifies the callers since they don't need to check for
non-NULL anymore.

I do extremely hate the workarounds here to suppress misprite taking the
cursor down though. Surely there's a better way.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-10-30 16:26:01 +00:00
Andres Rodriguez
cca4bc342c xf86: Disable unused crtc functions when a lease is revoked
This fixes 'non-desktop' displays staying powered on after their lease
has been revoked.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111620
Cc: Keith Packard <keithp@keithp.com>
Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
2019-09-23 16:01:27 +00:00
Dave Airlie
8ab80fd505 xf86: set status to connected for monitors enabled in conf
If the user sets Option "Enable" "TRUE" for a monitor, the X
server will connect the connector a crtc but tell the user it
is disconnected.

However the user in this case is mutter, when it gets it's view
of the output configuration it sees the output is disconnected
and never sets it up again, which seems like the right thing to do.

If we let the user enable a monitor, lets just set it as always
connected.

Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2019-04-02 19:20:07 +00:00
Andy Ritger
e51ebc18a7 xfree86/modes: Add "NoOutputInitialSize" option
Normally, the X server infers the initial screen size based on any
connected outputs.  However, if no outputs are connected, the X server
picks a default screen size of 1024 x 768.  This option overrides the
default screen size to use when no outputs are connected.  In contrast
to the "Virtual" Display SubSection entry, which applies unconditionally,
"NoOutputInitialSize" is only used if no outputs are detected when the
X server starts.

Parse this option in the new exported helper function
xf86AssignNoOutputInitialSize(), so that other XFree86 loadable drivers
can use it, even if they don't use xf86InitialConfiguration().

Signed-off-by: Andy Ritger <aritger@nvidia.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2019-03-06 11:33:29 -05:00
Adam Jackson
1e3f9ea14c randr: Remove funky indirection around the xf86 screen private key
All of the null checks here are redundant, you can't get to those paths
unless RANDR's already been initialized. Delete them, and remove the
pointer too.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2019-01-11 18:14:34 +00:00
Michel Dänzer
30044b2253 xfree86/modes: Don't clobber gamma LUT of compatibility output's CRTC
If the driver calls xf86HandleColormaps, CMapChangeGamma updates the HW
gamma LUT of all CRTCs via xf86RandR12LoadPalette. However,
xf86RandR12ChangeGamma was then clobbering the gamma LUT of the RandR
1.2 compatibility output's CRTC with the gamma curves computed from the
screen's global gamma values.

Fix this by bailing if xf86RandR12LoadPalette is installed.

Fixes: 02ff0a5d7e "xf86RandR12: Fix XF86VidModeSetGamma triggering a
                     BadImplementation error"
2019-01-11 16:25:42 +00:00
Keith Packard
2faf4cef8b xfree86: Wrap RRCrtcIsLeased and RROutputIsLeased to check for DIX structures
Before DIX structures are allocated for crtcs and outputs, we don't
want to call DIX randr code with NULL pointers. This can happen if the
driver sets video modes early in server initialization, which Nouveau
does in zaphod mode.

Cc: thellstrom@vmware.com
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=106772
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=106960
Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2018-07-02 19:34:50 -04:00
Keith Packard
c55a44a9a8 xfree86: Reset randr_crtc and randr_output early in xf86CrtcCloseScreen
The DIX crtc and output structures are freed when their resources are
destroyed, which happens before CloseScreen is called. As a result, we
know these pointers are invalid and referencing them during any of the
remaining CloseScreen sequence will be bad.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
Cc: thellstrom@vmware.com
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=106960
2018-07-02 19:34:34 -04: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
fabbaa8d62 xfree86/modes: Check for non-desktop monitors during PreInit [v2]
At startup, we want to ignore non-desktop monitors unless we don't
find any desktop monitors. Because there are no DIX RandR resources
allocated, let the driver store this information in a new field in the
xf86Output structure and then use that value to help decide whether to
include an output as part of the default configuration.

v2:
  Suggested-by: Michel Dänzer <michel@daenzer.net>

  Bump XF86_CRTC_VERSION from 7 to 8. This will let out-of-tree
  drivers know whether this field is available.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@nwnk.net>
2018-02-27 12:03:55 -05:00
Mario Kleiner
b5f9fcd50a xfree86/modes: Adapt xf86Randr12CrtcComputeGamma() for depth 30. (v2)
At screen depths > 24 bit, the color palettes passed into
xf86Randr12CrtcComputeGamma() can have a larger number of slots
than the crtc's hardware lut. E.g., at depth 30, 1024 palette
slots vs. 256 hw lut slots. This palette size > crtc gamma size
case is not handled yet and leads to silent failure, so gamma
table updates do not happen.

Add a new subsampling path for this case.

This makes lut updates work again, as tested with the xgamma
utility (uses XF86VidMode extension) and some RandR based
gamma ramp animation.

v2: Better resampling when subsampling the palette, as
    proposed by Ville. Now reaches the max index of the
    palette and deals with non-power-of-two sizes. Thanks.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Reviewed-by: Antoine Martin <antoine@nagafix.co.uk> (v1)
Cc: <ville.syrjala@linux.intel.com>
2018-02-27 10:18:07 -05:00
Jeff Smith
9b7b8720eb edid: use value returned from pruning duplicate modes
xf86PruneDuplicateModes is passed a linked list of modes, and after
pruning the duplicate nodes, the new head of the list is returned.  If
the first element is removed, the head of the list will change and the
returned value needs to be assigned.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103722
Thanks: John Lumby <johnlumby@hotmail.com>
Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-29 14:38:12 -05:00
Adam Jackson
dd00e5466a xfree86: Remove broken RANDR disabling logic (v4)
The only way to get at xf86Info.disableRandR from configuration is
Option "RANDR" "foo" in ServerFlags, which probably nobody is using
seeing as it's not documented. The other way it could be set is if a
screen supports RANDR 1.2, in which case we set it to avoid trying to
use the RANDR 1.1 compat code. If the second screen is not 1.2-aware
then this would mean we don't do RANDR setup on the second screen at
all, which would almost certainly crash the first time you try to do
RANDR operations on the second screen.

Fix that all by deletion, and just check whether the screen already has
RANDR initialized before installing the stub support. If you want to
disable RANDR, use the Extensions section of xorg.conf instead.

v2: Also remove a now entirely pointless log message, telling you to
ignore a line we will no longer print.

v3: Explain the fallback path in InitOutput. (Keith Packard)

v4: Check whether the RANDR private key is initialized before trying to
use it to look up the screen private.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2018-01-29 14:31:34 -05:00
Adam Jackson
5cb330cd5d Revert "xfree86: Remove broken RANDR disabling logic (v3)"
Tsk. This broke vesa for me, the rrGetScrPriv in InitOutput will crash
if randr's screen private key hasn't been initialized yet. That seems
dumb, but let's not leave it broken.

This reverts commit c08d7c1cdd.
2018-01-24 15:24:00 -05:00
Adam Jackson
c08d7c1cdd xfree86: Remove broken RANDR disabling logic (v3)
The only way to get at xf86Info.disableRandR from configuration is
Option "RANDR" "foo" in ServerFlags, which probably nobody is using
seeing as it's not documented. The other way it could be set is if a
screen supports RANDR 1.2, in which case we set it to avoid trying to
use the RANDR 1.1 compat code. If the second screen is not 1.2-aware
then this would mean we don't do RANDR setup on the second screen at
all, which would almost certainly crash the first time you try to do
RANDR operations on the second screen.

Fix that all by deletion, and just check whether the screen already has
RANDR initialized before installing the stub support. If you want to
disable RANDR, use the Extensions section of xorg.conf instead.

v2: Also remove a now entirely pointless log message, telling you to
ignore a line we will no longer print.

v3: Explain the fallback path in InitOutput. (Keith Packard)

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2018-01-24 11:39:31 -05:00
Keith Packard
4d5aab66c0 xfree86: Disable cursor whenever turning off CRTC during modeset
This makes sure the CRTC's cursor is hidden before we hand the CRTC
over to some other application.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2018-01-22 17:22:21 -05:00
Adam Jackson
4ed8d5c946 ddc: Port some paranoia from drm_edid.c
Avoid adding a "standard" mode timing if we've already got a matching
detailed timing. To help with that, parse CEA blocks for detailed
timings before doing standard or established timings.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-01-08 16:24:59 -05:00
Hector Martin
68556d74b4 edid: fix off-by-one error in CEA mode numbering
The CEA extension short video descriptors contain the VIC, which starts
at 1, not 0.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hector Martin <marcan@marcan.st>
2017-11-14 15:52:25 -05:00
Daniel Martin
d5379b350f Use ARRAY_SIZE all over the tree
Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-30 13:45:20 -04:00
Adam Jackson
147b4602f9 xfree86: Hush some warnings when Xv is disabled
Spotted by Appveyor:

xf86Crtc.c:3281:1: warning: ‘xf86_crtc_box_area’ defined but not used [-Wunused-function]
 xf86_crtc_box_area(BoxPtr box)
 ^~~~~~~~~~~~~~~~~~
xf86Crtc.c:3268:1: warning: ‘x86_crtc_box’ defined but not used [-Wunused-function]
 x86_crtc_box(xf86CrtcPtr crtc, BoxPtr crtc_box)
 ^~~~~~~~~~~~
xf86Crtc.c:3256:1: warning: ‘x86_crtc_box_intersect’ defined but not used [-Wunused-function]
 x86_crtc_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b)
 ^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-09-26 10:42:55 -04:00
Michel Dänzer
4212c884c4 xfree86/modes: Use RRTransformEqual in xf86RandR12CrtcSet
The memcmp didn't catch when e.g. only the filter changed. Tested by
alternately running

xrandr --output DVI-I-0 --scale-from 3840x2160 --filter bilinear
xrandr --output DVI-I-0 --scale-from 3840x2160 --filter nearest

Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
2017-06-20 12:40:18 +09:00
Michel Dänzer
d164c10850 xfree86: Add Option "PreferCloneMode"
When the default behaviour was changed from clone mode to horizontal
extended layout, a boolean ScrnInfoRec member preferClone was introduced
to choose the old default behaviour. Option "PreferCloneMode" allows
setting this preferClone member.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-06-05 18:18:53 +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
Michel Dänzer
41dafcc2a2 xfree86/modes: Make colormap/gamma glue code work with RandR disabled
E.g. because Xinerama is enabled.

Fixes crash on startup and wrong colours in that case.

Bugzilla: https://bugs.freedesktop.org/100293
Bugzilla: https://bugs.freedesktop.org/100294
Fixes: 62f4405257 ("xfree86/modes: Move gamma initialization to
                      xf86RandR12Init12 v2")
Tested-by: Mariusz Bialonczyk <manio@skyboo.net>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2017-04-17 16:12:32 +09:00
Eric Anholt
e2e50c5097 xserver: Unifdef HAVE_CONFIG_H
The X Server never generates a global config.h, and instead all these
paths are including dix-config.h or xorg-config.h.

Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
2017-03-23 13:19:51 -04:00
Michel Dänzer
fdc79fe72b edid: Prune duplicates after adding modes from DDC
Multiple calls to xf86EdidMonitorSet (which can be triggered e.g. by
running xrandr) would potentially keep adding the same modes, causing
the Monitor->Modes list to keep growing larger and using up more memory.

Fix this by calling xf86PruneDuplicateModes after adding the modes
returned by xf86DDCGetModes. This makes sure there's only one instance
of each unique mode in the list.

v2:
* Replace semicolon with {} for empty for loop (Emil Velikov)
* Slightly tweak commit log to avoid minor inaccuracy about what
  xf86PruneDuplicateModes does

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=99521
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2017-03-21 12:31:16 -04:00
Michael Thayer
c02f6a687c xfree86: Immediately handle failure to set HW cursor, v5
Based on v4 by Alexandre Courbot <acourbot@nvidia.com>

There is currently no reliable way to report failure to set a HW
cursor. Still such failures can happen if e.g. the MODE_CURSOR DRM
ioctl fails (which currently happens at least with modesetting on Tegra
for format incompatibility reasons).

As failures are currently handled by setting the HW cursor size to
(0,0), the fallback to SW cursor will not happen until the next time the
cursor changes and xf86CursorSetCursor() is called again. In the
meantime, the cursor will be invisible to the user.

This patch addresses that by adding _xf86CrtcFuncs::set_cursor_check and
_xf86CursorInfoRec::ShowCursorCheck hook variants that return booleans.
This allows to propagate errors up to xf86CursorSetCursor(), which can
then fall back to using the SW cursor immediately.

v5: Updated the patch to apply to current git HEAD, split up into two
patches (server and modesetting driver) and adjusted the code slightly
to match surrounding code.  I also removed the new exported function
ShowCursorCheck(), as instead just changing ShowCursor() to return Bool
should not affect its current callers.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Michael Thayer <michael.thayer@oracle.com>
2017-02-08 12:04:42 -05:00
Kai-Heng Feng
9874f73e88 edid: Add quirk for ADA 1024x600 7" display.
Detailed mode reports 108 mm x 68 mm which is for smaller display.
Maximum image size reports 15 cm x 10 cm which aligns with its physical
size, use this size instead.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
2017-01-02 14:42:45 -05:00
Hans de Goede
02ff0a5d7e xf86RandR12: Fix XF86VidModeSetGamma triggering a BadImplementation error
Commit b4e46c0444 ("xfree86: Hook up colormaps and RandR 1.2 gamma code")
dropped the providing of a pScrn->ChangeGamma callback from the xf86RandR12
code. Leaving pScrn->ChangeGamma NULL in most cases.

This triggers the BadImplementation error in xf86ChangeGamma() :

    if (pScrn->ChangeGamma)
        return (*pScrn->ChangeGamma) (pScrn, gamma);

    return BadImplementation;

Which causes X-apps using XF86VidModeSetGamma to crash with a
X protocol error.

This commit fixes this by re-introducing the xf86RandR12ChangeGamma
helper removed by the commit and adjusting it to work with the new
combined palette / gamma code.

Fixes: b4e46c0444 ("xfree86: Hook up colormaps and RandR 1.2 gamma code")
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-09-28 14:53:39 -04:00
Hans de Goede
a58dd678bf xf86RandR12: Move calculating of shift inside init_one_component
This is a preparation patch to allow easier usage of init_one_component
outside of xf86RandR12CrtcInitGamma.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-09-28 14:53:39 -04:00
Michel Dänzer
5b9f3ea250 xfree86/modes: Set RandR primary output from CreateScreenResources
Fixes XRRGetOutputPrimary and xrandr not reporting a primary output after
startup. This was especially confusing when an output was explicitly
marked as primary using Option "Primary" in Section "Monitor".

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2016-09-16 10:00:08 -07:00
Hans de Goede
df88008f92 xf86Cursor: Deal with rotation on GPU screens using a hw-cursor
When a slave-output is rotated the transformation is done on the blit
from master to slave GPU, so crtc->transform_in_use is not set, but we
still need to adjust the mouse position for things to work.

This commit modifies xf86_crtc_transform_cursor_position to not rely
on crtc->f_framebuffer_to_crtc, so that it can be used with GPU screens
too and always calls it for crtcs with any form of rotation.

Note not using crtc->f_framebuffer_to_crtc means that crtc->transform
will not be taken into account, that is ok, because when we've a transform
active hw-cursors are not used and xf86_crtc_transform_cursor_position
will never get called.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-13 10:27:12 +02:00
Hans de Goede
f82fd47016 xf86Cursor: Fix xf86_crtc_rotate_coord using width/height wrongly
xf86_crtc_rotate_coord should be the exact inverse operation of
xf86_crtc_rotate_coord_back, but when calculating x / y for 90 / 270
degrees rotation it was using height to calculate x / width to calculate y,
instead of the otherway around.

This was likely not noticed before since xf86_crtc_rotate_coord
until now was only used with cursor_info->MaxWidth and
cursor_info->MaxHeight, which are usally the same.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-13 10:27:07 +02:00
Michel Dänzer
a446ff84de xfree86/modes: Handle no palette case better in xf86RandR12CrtcSetGamma
Just use the RandR gamma ramp directly.

Fixes random on-monitor colours with drivers which don't call
xf86HandleColormaps, e.g. modesetting.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97154

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
2016-08-10 16:56:09 +09:00
Michel Dänzer
b4e46c0444 xfree86: Hook up colormaps and RandR 1.2 gamma code v6
Instead of breaking the former when the driver supports the latter,
hook them up so that the hardware LUTs reflect the combination of the
current colourmap and gamma states. I.e. combine the colourmap, the
global gamma value/ramp and the RandR 1.2 per-CRTC gamma ramps into one
combined LUT per CRTC.

Fixes e.g. gamma sliders not working in games.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27222

v2:
* Initialize palette_size and palette struct members, fixes crash on
  server startup.
v3:
* Free randrp->palette in xf86RandR12CloseScreen, fixes memory leak.
v4:
* Call CMapUnwrapScreen if xf86RandR12InitGamma fails (Emil Velikov).
* Still allow xf86HandleColormaps to be called with a NULL loadPalette
  parameter in the xf86_crtc_supports_gamma case.
v5:
* Clean up inner loops in xf86RandR12CrtcComputeGamma (Keith Packard)
* Move palette update out of per-CRTC loop in xf86RandR12LoadPalette
  (Keith Packard)
v6:
* Handle reallocarray failure in xf86RandR12LoadPalette (Keith Packard)

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-28 10:12:05 +09:00
Michel Dänzer
17213b74fd xfree86/modes: Remove xf86RandR12CrtcGetGamma
This would normally return the same values the core RandR code passed to
xf86RandR12CrtcSetGamma before, which is rather pointless. The only
possible exception would be if a driver tried initializing
crtc->gamma_red/green/blue to reflect the hardware LUT state on startup,
but that can't work correctly if whatever set the LUT before the server
started was running at a different depth.

Even the pointless round-trip case will no longer work with the
following change.

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-28 10:11:14 +09:00
Michel Dänzer
62f4405257 xfree86/modes: Move gamma initialization to xf86RandR12Init12 v2
RRCrtcGammaSetSize cannot be used yet in xf86InitialConfiguration,
because randr_crtc isn't allocated yet at that point, but a following
change will require RRCrtcGammaSetSize to be called from
xf86RandR12CrtcInitGamma.

v2:
* Bail from xf86RandR12CrtcInitGamma if !crtc->funcs->gamma_set (Keith
  Packard)

Reviewed-by: Keith Packard <keithp@keithp.com>
2016-07-27 17:49:39 +09:00
Keith Packard
fb0802113b Remove readmask from screen block/wakeup handler
With no users of the interface needing the readmask anymore, we can
remove it from the argument passed to these functions.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-07-18 15:27:51 -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
Michel Dänzer
263c5333a5 xfree86/modes: Simplify in_range logic in xf86_crtc_set_cursor_position
Consolidate to a single if/else statement and eliminate the redundant
local variable in_range and assignments to x/y.

Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-06-21 10:40:05 +09:00
Michel Dänzer
a991b1ec30 xfree86/modes: Disambiguate driverIsPerformingTransform
The driver can now specify exactly which aspects of the transform it
wants to handle via XF86DriverTransform* flags.

Since the driver can now choose whether it wants to receive transformed
or untransformed cursor coordinates, xf86CrtcTransformCursorPos no
longer needs to be available to drivers, so make it static.

Reviewed-by: Adam Jackson <ajax@redhat.com>
2016-06-21 10:39:13 +09:00