diff options
Diffstat (limited to 'xorg-server/hw/xfree86/modes')
-rw-r--r-- | xorg-server/hw/xfree86/modes/xf86Crtc.h | 1944 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/modes/xf86Cursors.c | 1376 | ||||
-rw-r--r-- | xorg-server/hw/xfree86/modes/xf86Rotate.c | 1050 |
3 files changed, 2185 insertions, 2185 deletions
diff --git a/xorg-server/hw/xfree86/modes/xf86Crtc.h b/xorg-server/hw/xfree86/modes/xf86Crtc.h index 68a968cc2..5dfcec280 100644 --- a/xorg-server/hw/xfree86/modes/xf86Crtc.h +++ b/xorg-server/hw/xfree86/modes/xf86Crtc.h @@ -1,972 +1,972 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -#ifndef _XF86CRTC_H_ -#define _XF86CRTC_H_ - -#include <edid.h> -#include "randrstr.h" -#if XF86_MODES_RENAME -#include "xf86Rename.h" -#endif -#include "xf86Modes.h" -#include "xf86Cursor.h" -#include "xf86i2c.h" -#include "damage.h" -#include "picturestr.h" - -/* Compat definitions for older X Servers. */ -#ifndef M_T_PREFERRED -#define M_T_PREFERRED 0x08 -#endif -#ifndef M_T_DRIVER -#define M_T_DRIVER 0x40 -#endif -#ifndef M_T_USERPREF -#define M_T_USERPREF 0x80 -#endif -#ifndef HARDWARE_CURSOR_ARGB -#define HARDWARE_CURSOR_ARGB 0x00004000 -#endif - -typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr; -typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr; - -/* define a standard for connector types */ -typedef enum _xf86ConnectorType { - XF86ConnectorNone, - XF86ConnectorVGA, - XF86ConnectorDVI_I, - XF86ConnectorDVI_D, - XF86ConnectorDVI_A, - XF86ConnectorComposite, - XF86ConnectorSvideo, - XF86ConnectorComponent, - XF86ConnectorLFP, - XF86ConnectorProprietary, - XF86ConnectorHDMI, - XF86ConnectorDisplayPort, -} xf86ConnectorType; - -typedef enum _xf86OutputStatus { - XF86OutputStatusConnected, - XF86OutputStatusDisconnected, - XF86OutputStatusUnknown -} xf86OutputStatus; - -typedef struct _xf86CrtcFuncs { - /** - * Turns the crtc on/off, or sets intermediate power levels if available. - * - * Unsupported intermediate modes drop to the lower power setting. If the - * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to - * be safe to call mode_set. - */ - void - (*dpms)(xf86CrtcPtr crtc, - int mode); - - /** - * Saves the crtc's state for restoration on VT switch. - */ - void - (*save)(xf86CrtcPtr crtc); - - /** - * Restore's the crtc's state at VT switch. - */ - void - (*restore)(xf86CrtcPtr crtc); - - /** - * Lock CRTC prior to mode setting, mostly for DRI. - * Returns whether unlock is needed - */ - Bool - (*lock) (xf86CrtcPtr crtc); - - /** - * Unlock CRTC after mode setting, mostly for DRI - */ - void - (*unlock) (xf86CrtcPtr crtc); - - /** - * Callback to adjust the mode to be set in the CRTC. - * - * This allows a CRTC to adjust the clock or even the entire set of - * timings, which is used for panels with fixed timings or for - * buses with clock limitations. - */ - Bool - (*mode_fixup)(xf86CrtcPtr crtc, - DisplayModePtr mode, - DisplayModePtr adjusted_mode); - - /** - * Prepare CRTC for an upcoming mode set. - */ - void - (*prepare)(xf86CrtcPtr crtc); - - /** - * Callback for setting up a video mode after fixups have been made. - */ - void - (*mode_set)(xf86CrtcPtr crtc, - DisplayModePtr mode, - DisplayModePtr adjusted_mode, - int x, int y); - - /** - * Commit mode changes to a CRTC - */ - void - (*commit)(xf86CrtcPtr crtc); - - /* Set the color ramps for the CRTC to the given values. */ - void - (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue, - int size); - - /** - * Allocate the shadow area, delay the pixmap creation until needed - */ - void * - (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height); - - /** - * Create shadow pixmap for rotation support - */ - PixmapPtr - (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height); - - /** - * Destroy shadow pixmap - */ - void - (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data); - - /** - * Set cursor colors - */ - void - (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg); - - /** - * Set cursor position - */ - void - (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y); - - /** - * Show cursor - */ - void - (*show_cursor) (xf86CrtcPtr crtc); - - /** - * Hide cursor - */ - void - (*hide_cursor) (xf86CrtcPtr crtc); - - /** - * Load monochrome image - */ - void - (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image); - - /** - * Load ARGB image - */ - void - (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image); - - /** - * Clean up driver-specific bits of the crtc - */ - void - (*destroy) (xf86CrtcPtr crtc); - - /** - * Less fine-grained mode setting entry point for kernel modesetting - */ - Bool - (*set_mode_major)(xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, int x, int y); - - /** - * Callback for panning. Doesn't change the mode. - * Added in ABI version 2 - */ - void - (*set_origin)(xf86CrtcPtr crtc, int x, int y); - -} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr; - -#define XF86_CRTC_VERSION 3 - -struct _xf86Crtc { - /** - * ABI versioning - */ - int version; - - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Desired state of this CRTC - * - * Set when this CRTC should be driving one or more outputs - */ - Bool enabled; - - /** - * Active mode - * - * This reflects the mode as set in the CRTC currently - * It will be cleared when the VT is not active or - * during server startup - */ - DisplayModeRec mode; - Rotation rotation; - PixmapPtr rotatedPixmap; - void *rotatedData; - - /** - * Position on screen - * - * Locates this CRTC within the frame buffer - */ - int x, y; - - /** - * Desired mode - * - * This is set to the requested mode, independent of - * whether the VT is active. In particular, it receives - * the startup configured mode and saves the active mode - * on VT switch. - */ - DisplayModeRec desiredMode; - Rotation desiredRotation; - int desiredX, desiredY; - - /** crtc-specific functions */ - const xf86CrtcFuncsRec *funcs; - - /** - * Driver private - * - * Holds driver-private information - */ - void *driver_private; - -#ifdef RANDR_12_INTERFACE - /** - * RandR crtc - * - * When RandR 1.2 is available, this - * points at the associated crtc object - */ - RRCrtcPtr randr_crtc; -#else - void *randr_crtc; -#endif - - /** - * Current cursor is ARGB - */ - Bool cursor_argb; - /** - * Track whether cursor is within CRTC range - */ - Bool cursor_in_range; - /** - * Track state of cursor associated with this CRTC - */ - Bool cursor_shown; - - /** - * Current transformation matrix - */ - PictTransform crtc_to_framebuffer; - /* framebuffer_to_crtc was removed in ABI 2 */ - struct pict_f_transform f_crtc_to_framebuffer; /* ABI 2 */ - struct pict_f_transform f_framebuffer_to_crtc; /* ABI 2 */ - PictFilterPtr filter; /* ABI 2 */ - xFixed *params; /* ABI 2 */ - int nparams; /* ABI 2 */ - int filter_width; /* ABI 2 */ - int filter_height; /* ABI 2 */ - Bool transform_in_use; - RRTransformRec transform; /* ABI 2 */ - Bool transformPresent; /* ABI 2 */ - RRTransformRec desiredTransform; /* ABI 2 */ - Bool desiredTransformPresent; /* ABI 2 */ - /** - * Bounding box in screen space - */ - BoxRec bounds; - /** - * Panning: - * TotalArea: total panning area, larger than CRTC's size - * TrackingArea: Area of the pointer for which the CRTC is panned - * border: Borders of the displayed CRTC area which induces panning if the pointer reaches them - * Added in ABI version 2 - */ - BoxRec panningTotalArea; - BoxRec panningTrackingArea; - INT16 panningBorder[4]; - - /** - * Current gamma, especially useful after initial config. - * Added in ABI version 3 - */ - CARD16 *gamma_red; - CARD16 *gamma_green; - CARD16 *gamma_blue; - int gamma_size; - - /** - * Actual state of this CRTC - * - * Set to TRUE after modesetting, set to FALSE if no outputs are connected - * Added in ABI version 3 - */ - Bool active; - /** - * Clear the shadow - */ - Bool shadowClear; -}; - -typedef struct _xf86OutputFuncs { - /** - * Called to allow the output a chance to create properties after the - * RandR objects have been created. - */ - void - (*create_resources)(xf86OutputPtr output); - - /** - * Turns the output on/off, or sets intermediate power levels if available. - * - * Unsupported intermediate modes drop to the lower power setting. If the - * mode is DPMSModeOff, the output must be disabled, as the DPLL may be - * disabled afterwards. - */ - void - (*dpms)(xf86OutputPtr output, - int mode); - - /** - * Saves the output's state for restoration on VT switch. - */ - void - (*save)(xf86OutputPtr output); - - /** - * Restore's the output's state at VT switch. - */ - void - (*restore)(xf86OutputPtr output); - - /** - * Callback for testing a video mode for a given output. - * - * This function should only check for cases where a mode can't be supported - * on the output specifically, and not represent generic CRTC limitations. - * - * \return MODE_OK if the mode is valid, or another MODE_* otherwise. - */ - int - (*mode_valid)(xf86OutputPtr output, - DisplayModePtr pMode); - - /** - * Callback to adjust the mode to be set in the CRTC. - * - * This allows an output to adjust the clock or even the entire set of - * timings, which is used for panels with fixed timings or for - * buses with clock limitations. - */ - Bool - (*mode_fixup)(xf86OutputPtr output, - DisplayModePtr mode, - DisplayModePtr adjusted_mode); - - /** - * Callback for preparing mode changes on an output - */ - void - (*prepare)(xf86OutputPtr output); - - /** - * Callback for committing mode changes on an output - */ - void - (*commit)(xf86OutputPtr output); - - /** - * Callback for setting up a video mode after fixups have been made. - * - * This is only called while the output is disabled. The dpms callback - * must be all that's necessary for the output, to turn the output on - * after this function is called. - */ - void - (*mode_set)(xf86OutputPtr output, - DisplayModePtr mode, - DisplayModePtr adjusted_mode); - - /** - * Probe for a connected output, and return detect_status. - */ - xf86OutputStatus - (*detect)(xf86OutputPtr output); - - /** - * Query the device for the modes it provides. - * - * This function may also update MonInfo, mm_width, and mm_height. - * - * \return singly-linked list of modes or NULL if no modes found. - */ - DisplayModePtr - (*get_modes)(xf86OutputPtr output); - -#ifdef RANDR_12_INTERFACE - /** - * Callback when an output's property has changed. - */ - Bool - (*set_property)(xf86OutputPtr output, - Atom property, - RRPropertyValuePtr value); -#endif -#ifdef RANDR_13_INTERFACE - /** - * Callback to get an updated property value - */ - Bool - (*get_property)(xf86OutputPtr output, - Atom property); -#endif -#ifdef RANDR_GET_CRTC_INTERFACE - /** - * Callback to get current CRTC for a given output - */ - xf86CrtcPtr - (*get_crtc)(xf86OutputPtr output); -#endif - /** - * Clean up driver-specific bits of the output - */ - void - (*destroy) (xf86OutputPtr output); -} xf86OutputFuncsRec, *xf86OutputFuncsPtr; - - -#define XF86_OUTPUT_VERSION 2 - -struct _xf86Output { - /** - * ABI versioning - */ - int version; - - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Currently connected crtc (if any) - * - * If this output is not in use, this field will be NULL. - */ - xf86CrtcPtr crtc; - - /** - * Possible CRTCs for this output as a mask of crtc indices - */ - CARD32 possible_crtcs; - - /** - * Possible outputs to share the same CRTC as a mask of output indices - */ - CARD32 possible_clones; - - /** - * Whether this output can support interlaced modes - */ - Bool interlaceAllowed; - - /** - * Whether this output can support double scan modes - */ - Bool doubleScanAllowed; - - /** - * List of available modes on this output. - * - * This should be the list from get_modes(), plus perhaps additional - * compatible modes added later. - */ - DisplayModePtr probed_modes; - - /** - * Options parsed from the related monitor section - */ - OptionInfoPtr options; - - /** - * Configured monitor section - */ - XF86ConfMonitorPtr conf_monitor; - - /** - * Desired initial position - */ - int initial_x, initial_y; - - /** - * Desired initial rotation - */ - Rotation initial_rotation; - - /** - * Current connection status - * - * This indicates whether a monitor is known to be connected - * to this output or not, or whether there is no way to tell - */ - xf86OutputStatus status; - - /** EDID monitor information */ - xf86MonPtr MonInfo; - - /** subpixel order */ - int subpixel_order; - - /** Physical size of the currently attached output device. */ - int mm_width, mm_height; - - /** Output name */ - char *name; - - /** output-specific functions */ - const xf86OutputFuncsRec *funcs; - - /** driver private information */ - void *driver_private; - - /** Whether to use the old per-screen Monitor config section */ - Bool use_screen_monitor; - -#ifdef RANDR_12_INTERFACE - /** - * RandR 1.2 output structure. - * - * When RandR 1.2 is available, this points at the associated - * RandR output structure and is created when this output is created - */ - RROutputPtr randr_output; -#else - void *randr_output; -#endif - /** - * Desired initial panning - * Added in ABI version 2 - */ - BoxRec initialTotalArea; - BoxRec initialTrackingArea; - INT16 initialBorder[4]; -}; - -typedef struct _xf86CrtcConfigFuncs { - /** - * Requests that the driver resize the screen. - * - * The driver is responsible for updating scrn->virtualX and scrn->virtualY. - * If the requested size cannot be set, the driver should leave those values - * alone and return FALSE. - * - * A naive driver that cannot reallocate the screen may simply change - * virtual[XY]. A more advanced driver will want to also change the - * devPrivate.ptr and devKind of the screen pixmap, update any offscreen - * pixmaps it may have moved, and change pScrn->displayWidth. - */ - Bool - (*resize)(ScrnInfoPtr scrn, - int width, - int height); -} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr; - -typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen); - -typedef struct _xf86CrtcConfig { - int num_output; - xf86OutputPtr *output; - /** - * compat_output is used whenever we deal - * with legacy code that only understands a single - * output. pScrn->modes will be loaded from this output, - * adjust frame will whack this output, etc. - */ - int compat_output; - - int num_crtc; - xf86CrtcPtr *crtc; - - int minWidth, minHeight; - int maxWidth, maxHeight; - - /* For crtc-based rotation */ - DamagePtr rotation_damage; - Bool rotation_damage_registered; - - /* DGA */ - unsigned int dga_flags; - unsigned long dga_address; - DGAModePtr dga_modes; - int dga_nmode; - int dga_width, dga_height, dga_stride; - DisplayModePtr dga_save_mode; - - const xf86CrtcConfigFuncsRec *funcs; - - CreateScreenResourcesProcPtr CreateScreenResources; - - CloseScreenProcPtr CloseScreen; - - /* Cursor information */ - xf86CursorInfoPtr cursor_info; - CursorPtr cursor; - CARD8 *cursor_image; - Bool cursor_on; - CARD32 cursor_fg, cursor_bg; - - /** - * Options parsed from the related device section - */ - OptionInfoPtr options; - - Bool debug_modes; - - /* wrap screen BlockHandler for rotation */ - ScreenBlockHandlerProcPtr BlockHandler; - - /* callback when crtc configuration changes */ - xf86_crtc_notify_proc_ptr xf86_crtc_notify; - -} xf86CrtcConfigRec, *xf86CrtcConfigPtr; - -extern _X_EXPORT int xf86CrtcConfigPrivateIndex; - -#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr)) - -static _X_INLINE xf86OutputPtr -xf86CompatOutput(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - return config->output[config->compat_output]; -} - -static _X_INLINE xf86CrtcPtr -xf86CompatCrtc(ScrnInfoPtr pScrn) -{ - xf86OutputPtr compat_output = xf86CompatOutput(pScrn); - if (!compat_output) - return NULL; - return compat_output->crtc; -} - -static _X_INLINE RRCrtcPtr -xf86CompatRRCrtc(ScrnInfoPtr pScrn) -{ - xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn); - if (!compat_crtc) - return NULL; - return compat_crtc->randr_crtc; -} - - -/* - * Initialize xf86CrtcConfig structure - */ - -extern _X_EXPORT void -xf86CrtcConfigInit (ScrnInfoPtr scrn, - const xf86CrtcConfigFuncsRec *funcs); - -extern _X_EXPORT void -xf86CrtcSetSizeRange (ScrnInfoPtr scrn, - int minWidth, int minHeight, - int maxWidth, int maxHeight); - -/* - * Crtc functions - */ -extern _X_EXPORT xf86CrtcPtr -xf86CrtcCreate (ScrnInfoPtr scrn, - const xf86CrtcFuncsRec *funcs); - -extern _X_EXPORT void -xf86CrtcDestroy (xf86CrtcPtr crtc); - - -/** - * Sets the given video mode on the given crtc - */ - -extern _X_EXPORT Bool -xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, - RRTransformPtr transform, int x, int y); - -extern _X_EXPORT Bool -xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, - int x, int y); - -extern _X_EXPORT void -xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y); - -/* - * Assign crtc rotation during mode set - */ -extern _X_EXPORT Bool -xf86CrtcRotate (xf86CrtcPtr crtc); - -/* - * Clean up any rotation data, used when a crtc is turned off - * as well as when rotation is disabled. - */ -extern _X_EXPORT void -xf86RotateDestroy (xf86CrtcPtr crtc); - -/* - * free shadow memory allocated for all crtcs - */ -extern _X_EXPORT void -xf86RotateFreeShadow(ScrnInfoPtr pScrn); - -/* - * Clean up rotation during CloseScreen - */ -extern _X_EXPORT void -xf86RotateCloseScreen (ScreenPtr pScreen); - -/** - * Return whether any output is assigned to the crtc - */ -extern _X_EXPORT Bool -xf86CrtcInUse (xf86CrtcPtr crtc); - -/* - * Output functions - */ -extern _X_EXPORT xf86OutputPtr -xf86OutputCreate (ScrnInfoPtr scrn, - const xf86OutputFuncsRec *funcs, - const char *name); - -extern _X_EXPORT void -xf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor); - -extern _X_EXPORT Bool -xf86OutputRename (xf86OutputPtr output, const char *name); - -extern _X_EXPORT void -xf86OutputDestroy (xf86OutputPtr output); - -extern _X_EXPORT void -xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY); - -extern _X_EXPORT void -xf86SetScrnInfoModes (ScrnInfoPtr pScrn); - -#ifdef RANDR_13_INTERFACE -# define ScreenInitRetType int -#else -# define ScreenInitRetType Bool -#endif - -extern _X_EXPORT ScreenInitRetType -xf86CrtcScreenInit (ScreenPtr pScreen); - -extern _X_EXPORT Bool -xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow); - -extern _X_EXPORT void -xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags); - -extern _X_EXPORT Bool -xf86SaveScreen(ScreenPtr pScreen, int mode); - -extern _X_EXPORT void -xf86DisableUnusedFunctions(ScrnInfoPtr pScrn); - -extern _X_EXPORT DisplayModePtr -xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired); - -extern _X_EXPORT Bool -xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation); - -/** - * Set the EDID information for the specified output - */ -extern _X_EXPORT void -xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon); - -/** - * Return the list of modes supported by the EDID information - * stored in 'output' - */ -extern _X_EXPORT DisplayModePtr -xf86OutputGetEDIDModes (xf86OutputPtr output); - -extern _X_EXPORT xf86MonPtr -xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus); - -/** - * Initialize dga for this screen - */ - -#ifdef XFreeXDGA -extern _X_EXPORT Bool -xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address); - -/* this is the real function, used only internally */ -_X_INTERNAL Bool -_xf86_di_dga_init_internal (ScreenPtr pScreen); - -/** - * Re-initialize dga for this screen (as when the set of modes changes) - */ - -extern _X_EXPORT Bool -xf86DiDGAReInit (ScreenPtr pScreen); -#endif - -/* This is the real function, used only internally */ -_X_INTERNAL Bool -_xf86_di_dga_reinit_internal (ScreenPtr pScreen); - -/* - * Set the subpixel order reported for the screen using - * the information from the outputs - */ - -extern _X_EXPORT void -xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen); - -/* - * Get a standard string name for a connector type - */ -extern _X_EXPORT char * -xf86ConnectorGetName(xf86ConnectorType connector); - -/* - * Using the desired mode information in each crtc, set - * modes (used in EnterVT functions, or at server startup) - */ - -extern _X_EXPORT Bool -xf86SetDesiredModes (ScrnInfoPtr pScrn); - -/** - * Initialize the CRTC-based cursor code. CRTC function vectors must - * contain relevant cursor setting functions. - * - * Driver should call this from ScreenInit function - */ -extern _X_EXPORT Bool -xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags); - -/** - * Called when anything on the screen is reconfigured. - * - * Reloads cursor images as needed, then adjusts cursor positions. - * - * Driver should call this from crtc commit function. - */ -extern _X_EXPORT void -xf86_reload_cursors (ScreenPtr screen); - -/** - * Called from EnterVT to turn the cursors back on - */ -extern _X_EXPORT void -xf86_show_cursors (ScrnInfoPtr scrn); - -/** - * Called by the driver to turn cursors off - */ -extern _X_EXPORT void -xf86_hide_cursors (ScrnInfoPtr scrn); - -/** - * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time. - */ -extern _X_EXPORT void -xf86_cursors_fini (ScreenPtr screen); - -/* - * For overlay video, compute the relevant CRTC and - * clip video to that. - * wraps xf86XVClipVideoHelper() - */ - -extern _X_EXPORT Bool -xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn, - xf86CrtcPtr *crtc_ret, - xf86CrtcPtr desired_crtc, - BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, - RegionPtr reg, - INT32 width, - INT32 height); - -extern _X_EXPORT xf86_crtc_notify_proc_ptr -xf86_wrap_crtc_notify (ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new); - -extern _X_EXPORT void -xf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old); - -extern _X_EXPORT void -xf86_crtc_notify(ScreenPtr pScreen); - -/** - * Gamma - */ - -extern _X_EXPORT Bool -xf86_crtc_supports_gamma(ScrnInfoPtr pScrn); - -#endif /* _XF86CRTC_H_ */ +/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+#ifndef _XF86CRTC_H_
+#define _XF86CRTC_H_
+
+#include <edid.h>
+#include "randrstr.h"
+#if XF86_MODES_RENAME
+#include "xf86Rename.h"
+#endif
+#include "xf86Modes.h"
+#include "xf86Cursor.h"
+#include "xf86i2c.h"
+#include "damage.h"
+#include "picturestr.h"
+
+/* Compat definitions for older X Servers. */
+#ifndef M_T_PREFERRED
+#define M_T_PREFERRED 0x08
+#endif
+#ifndef M_T_DRIVER
+#define M_T_DRIVER 0x40
+#endif
+#ifndef M_T_USERPREF
+#define M_T_USERPREF 0x80
+#endif
+#ifndef HARDWARE_CURSOR_ARGB
+#define HARDWARE_CURSOR_ARGB 0x00004000
+#endif
+
+typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
+typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
+
+/* define a standard for connector types */
+typedef enum _xf86ConnectorType {
+ XF86ConnectorNone,
+ XF86ConnectorVGA,
+ XF86ConnectorDVI_I,
+ XF86ConnectorDVI_D,
+ XF86ConnectorDVI_A,
+ XF86ConnectorComposite,
+ XF86ConnectorSvideo,
+ XF86ConnectorComponent,
+ XF86ConnectorLFP,
+ XF86ConnectorProprietary,
+ XF86ConnectorHDMI,
+ XF86ConnectorDisplayPort,
+} xf86ConnectorType;
+
+typedef enum _xf86OutputStatus {
+ XF86OutputStatusConnected,
+ XF86OutputStatusDisconnected,
+ XF86OutputStatusUnknown
+} xf86OutputStatus;
+
+typedef struct _xf86CrtcFuncs {
+ /**
+ * Turns the crtc on/off, or sets intermediate power levels if available.
+ *
+ * Unsupported intermediate modes drop to the lower power setting. If the
+ * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to
+ * be safe to call mode_set.
+ */
+ void
+ (*dpms)(xf86CrtcPtr crtc,
+ int mode);
+
+ /**
+ * Saves the crtc's state for restoration on VT switch.
+ */
+ void
+ (*save)(xf86CrtcPtr crtc);
+
+ /**
+ * Restore's the crtc's state at VT switch.
+ */
+ void
+ (*restore)(xf86CrtcPtr crtc);
+
+ /**
+ * Lock CRTC prior to mode setting, mostly for DRI.
+ * Returns whether unlock is needed
+ */
+ Bool
+ (*lock) (xf86CrtcPtr crtc);
+
+ /**
+ * Unlock CRTC after mode setting, mostly for DRI
+ */
+ void
+ (*unlock) (xf86CrtcPtr crtc);
+
+ /**
+ * Callback to adjust the mode to be set in the CRTC.
+ *
+ * This allows a CRTC to adjust the clock or even the entire set of
+ * timings, which is used for panels with fixed timings or for
+ * buses with clock limitations.
+ */
+ Bool
+ (*mode_fixup)(xf86CrtcPtr crtc,
+ DisplayModePtr mode,
+ DisplayModePtr adjusted_mode);
+
+ /**
+ * Prepare CRTC for an upcoming mode set.
+ */
+ void
+ (*prepare)(xf86CrtcPtr crtc);
+
+ /**
+ * Callback for setting up a video mode after fixups have been made.
+ */
+ void
+ (*mode_set)(xf86CrtcPtr crtc,
+ DisplayModePtr mode,
+ DisplayModePtr adjusted_mode,
+ int x, int y);
+
+ /**
+ * Commit mode changes to a CRTC
+ */
+ void
+ (*commit)(xf86CrtcPtr crtc);
+
+ /* Set the color ramps for the CRTC to the given values. */
+ void
+ (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
+ int size);
+
+ /**
+ * Allocate the shadow area, delay the pixmap creation until needed
+ */
+ void *
+ (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height);
+
+ /**
+ * Create shadow pixmap for rotation support
+ */
+ PixmapPtr
+ (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height);
+
+ /**
+ * Destroy shadow pixmap
+ */
+ void
+ (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
+
+ /**
+ * Set cursor colors
+ */
+ void
+ (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg);
+
+ /**
+ * Set cursor position
+ */
+ void
+ (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y);
+
+ /**
+ * Show cursor
+ */
+ void
+ (*show_cursor) (xf86CrtcPtr crtc);
+
+ /**
+ * Hide cursor
+ */
+ void
+ (*hide_cursor) (xf86CrtcPtr crtc);
+
+ /**
+ * Load monochrome image
+ */
+ void
+ (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image);
+
+ /**
+ * Load ARGB image
+ */
+ void
+ (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image);
+
+ /**
+ * Clean up driver-specific bits of the crtc
+ */
+ void
+ (*destroy) (xf86CrtcPtr crtc);
+
+ /**
+ * Less fine-grained mode setting entry point for kernel modesetting
+ */
+ Bool
+ (*set_mode_major)(xf86CrtcPtr crtc, DisplayModePtr mode,
+ Rotation rotation, int x, int y);
+
+ /**
+ * Callback for panning. Doesn't change the mode.
+ * Added in ABI version 2
+ */
+ void
+ (*set_origin)(xf86CrtcPtr crtc, int x, int y);
+
+} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
+
+#define XF86_CRTC_VERSION 3
+
+struct _xf86Crtc {
+ /**
+ * ABI versioning
+ */
+ int version;
+
+ /**
+ * Associated ScrnInfo
+ */
+ ScrnInfoPtr scrn;
+
+ /**
+ * Desired state of this CRTC
+ *
+ * Set when this CRTC should be driving one or more outputs
+ */
+ Bool enabled;
+
+ /**
+ * Active mode
+ *
+ * This reflects the mode as set in the CRTC currently
+ * It will be cleared when the VT is not active or
+ * during server startup
+ */
+ DisplayModeRec mode;
+ Rotation rotation;
+ PixmapPtr rotatedPixmap;
+ void *rotatedData;
+
+ /**
+ * Position on screen
+ *
+ * Locates this CRTC within the frame buffer
+ */
+ int x, y;
+
+ /**
+ * Desired mode
+ *
+ * This is set to the requested mode, independent of
+ * whether the VT is active. In particular, it receives
+ * the startup configured mode and saves the active mode
+ * on VT switch.
+ */
+ DisplayModeRec desiredMode;
+ Rotation desiredRotation;
+ int desiredX, desiredY;
+
+ /** crtc-specific functions */
+ const xf86CrtcFuncsRec *funcs;
+
+ /**
+ * Driver private
+ *
+ * Holds driver-private information
+ */
+ void *driver_private;
+
+#ifdef RANDR_12_INTERFACE
+ /**
+ * RandR crtc
+ *
+ * When RandR 1.2 is available, this
+ * points at the associated crtc object
+ */
+ RRCrtcPtr randr_crtc;
+#else
+ void *randr_crtc;
+#endif
+
+ /**
+ * Current cursor is ARGB
+ */
+ Bool cursor_argb;
+ /**
+ * Track whether cursor is within CRTC range
+ */
+ Bool cursor_in_range;
+ /**
+ * Track state of cursor associated with this CRTC
+ */
+ Bool cursor_shown;
+
+ /**
+ * Current transformation matrix
+ */
+ PictTransform crtc_to_framebuffer;
+ /* framebuffer_to_crtc was removed in ABI 2 */
+ struct pict_f_transform f_crtc_to_framebuffer; /* ABI 2 */
+ struct pict_f_transform f_framebuffer_to_crtc; /* ABI 2 */
+ PictFilterPtr filter; /* ABI 2 */
+ xFixed *params; /* ABI 2 */
+ int nparams; /* ABI 2 */
+ int filter_width; /* ABI 2 */
+ int filter_height; /* ABI 2 */
+ Bool transform_in_use;
+ RRTransformRec transform; /* ABI 2 */
+ Bool transformPresent; /* ABI 2 */
+ RRTransformRec desiredTransform; /* ABI 2 */
+ Bool desiredTransformPresent; /* ABI 2 */
+ /**
+ * Bounding box in screen space
+ */
+ BoxRec bounds;
+ /**
+ * Panning:
+ * TotalArea: total panning area, larger than CRTC's size
+ * TrackingArea: Area of the pointer for which the CRTC is panned
+ * border: Borders of the displayed CRTC area which induces panning if the pointer reaches them
+ * Added in ABI version 2
+ */
+ BoxRec panningTotalArea;
+ BoxRec panningTrackingArea;
+ INT16 panningBorder[4];
+
+ /**
+ * Current gamma, especially useful after initial config.
+ * Added in ABI version 3
+ */
+ CARD16 *gamma_red;
+ CARD16 *gamma_green;
+ CARD16 *gamma_blue;
+ int gamma_size;
+
+ /**
+ * Actual state of this CRTC
+ *
+ * Set to TRUE after modesetting, set to FALSE if no outputs are connected
+ * Added in ABI version 3
+ */
+ Bool active;
+ /**
+ * Clear the shadow
+ */
+ Bool shadowClear;
+};
+
+typedef struct _xf86OutputFuncs {
+ /**
+ * Called to allow the output a chance to create properties after the
+ * RandR objects have been created.
+ */
+ void
+ (*create_resources)(xf86OutputPtr output);
+
+ /**
+ * Turns the output on/off, or sets intermediate power levels if available.
+ *
+ * Unsupported intermediate modes drop to the lower power setting. If the
+ * mode is DPMSModeOff, the output must be disabled, as the DPLL may be
+ * disabled afterwards.
+ */
+ void
+ (*dpms)(xf86OutputPtr output,
+ int mode);
+
+ /**
+ * Saves the output's state for restoration on VT switch.
+ */
+ void
+ (*save)(xf86OutputPtr output);
+
+ /**
+ * Restore's the output's state at VT switch.
+ */
+ void
+ (*restore)(xf86OutputPtr output);
+
+ /**
+ * Callback for testing a video mode for a given output.
+ *
+ * This function should only check for cases where a mode can't be supported
+ * on the output specifically, and not represent generic CRTC limitations.
+ *
+ * \return MODE_OK if the mode is valid, or another MODE_* otherwise.
+ */
+ int
+ (*mode_valid)(xf86OutputPtr output,
+ DisplayModePtr pMode);
+
+ /**
+ * Callback to adjust the mode to be set in the CRTC.
+ *
+ * This allows an output to adjust the clock or even the entire set of
+ * timings, which is used for panels with fixed timings or for
+ * buses with clock limitations.
+ */
+ Bool
+ (*mode_fixup)(xf86OutputPtr output,
+ DisplayModePtr mode,
+ DisplayModePtr adjusted_mode);
+
+ /**
+ * Callback for preparing mode changes on an output
+ */
+ void
+ (*prepare)(xf86OutputPtr output);
+
+ /**
+ * Callback for committing mode changes on an output
+ */
+ void
+ (*commit)(xf86OutputPtr output);
+
+ /**
+ * Callback for setting up a video mode after fixups have been made.
+ *
+ * This is only called while the output is disabled. The dpms callback
+ * must be all that's necessary for the output, to turn the output on
+ * after this function is called.
+ */
+ void
+ (*mode_set)(xf86OutputPtr output,
+ DisplayModePtr mode,
+ DisplayModePtr adjusted_mode);
+
+ /**
+ * Probe for a connected output, and return detect_status.
+ */
+ xf86OutputStatus
+ (*detect)(xf86OutputPtr output);
+
+ /**
+ * Query the device for the modes it provides.
+ *
+ * This function may also update MonInfo, mm_width, and mm_height.
+ *
+ * \return singly-linked list of modes or NULL if no modes found.
+ */
+ DisplayModePtr
+ (*get_modes)(xf86OutputPtr output);
+
+#ifdef RANDR_12_INTERFACE
+ /**
+ * Callback when an output's property has changed.
+ */
+ Bool
+ (*set_property)(xf86OutputPtr output,
+ Atom property,
+ RRPropertyValuePtr value);
+#endif
+#ifdef RANDR_13_INTERFACE
+ /**
+ * Callback to get an updated property value
+ */
+ Bool
+ (*get_property)(xf86OutputPtr output,
+ Atom property);
+#endif
+#ifdef RANDR_GET_CRTC_INTERFACE
+ /**
+ * Callback to get current CRTC for a given output
+ */
+ xf86CrtcPtr
+ (*get_crtc)(xf86OutputPtr output);
+#endif
+ /**
+ * Clean up driver-specific bits of the output
+ */
+ void
+ (*destroy) (xf86OutputPtr output);
+} xf86OutputFuncsRec, *xf86OutputFuncsPtr;
+
+
+#define XF86_OUTPUT_VERSION 2
+
+struct _xf86Output {
+ /**
+ * ABI versioning
+ */
+ int version;
+
+ /**
+ * Associated ScrnInfo
+ */
+ ScrnInfoPtr scrn;
+
+ /**
+ * Currently connected crtc (if any)
+ *
+ * If this output is not in use, this field will be NULL.
+ */
+ xf86CrtcPtr crtc;
+
+ /**
+ * Possible CRTCs for this output as a mask of crtc indices
+ */
+ CARD32 possible_crtcs;
+
+ /**
+ * Possible outputs to share the same CRTC as a mask of output indices
+ */
+ CARD32 possible_clones;
+
+ /**
+ * Whether this output can support interlaced modes
+ */
+ Bool interlaceAllowed;
+
+ /**
+ * Whether this output can support double scan modes
+ */
+ Bool doubleScanAllowed;
+
+ /**
+ * List of available modes on this output.
+ *
+ * This should be the list from get_modes(), plus perhaps additional
+ * compatible modes added later.
+ */
+ DisplayModePtr probed_modes;
+
+ /**
+ * Options parsed from the related monitor section
+ */
+ OptionInfoPtr options;
+
+ /**
+ * Configured monitor section
+ */
+ XF86ConfMonitorPtr conf_monitor;
+
+ /**
+ * Desired initial position
+ */
+ int initial_x, initial_y;
+
+ /**
+ * Desired initial rotation
+ */
+ Rotation initial_rotation;
+
+ /**
+ * Current connection status
+ *
+ * This indicates whether a monitor is known to be connected
+ * to this output or not, or whether there is no way to tell
+ */
+ xf86OutputStatus status;
+
+ /** EDID monitor information */
+ xf86MonPtr MonInfo;
+
+ /** subpixel order */
+ int subpixel_order;
+
+ /** Physical size of the currently attached output device. */
+ int mm_width, mm_height;
+
+ /** Output name */
+ char *name;
+
+ /** output-specific functions */
+ const xf86OutputFuncsRec *funcs;
+
+ /** driver private information */
+ void *driver_private;
+
+ /** Whether to use the old per-screen Monitor config section */
+ Bool use_screen_monitor;
+
+#ifdef RANDR_12_INTERFACE
+ /**
+ * RandR 1.2 output structure.
+ *
+ * When RandR 1.2 is available, this points at the associated
+ * RandR output structure and is created when this output is created
+ */
+ RROutputPtr randr_output;
+#else
+ void *randr_output;
+#endif
+ /**
+ * Desired initial panning
+ * Added in ABI version 2
+ */
+ BoxRec initialTotalArea;
+ BoxRec initialTrackingArea;
+ INT16 initialBorder[4];
+};
+
+typedef struct _xf86CrtcConfigFuncs {
+ /**
+ * Requests that the driver resize the screen.
+ *
+ * The driver is responsible for updating scrn->virtualX and scrn->virtualY.
+ * If the requested size cannot be set, the driver should leave those values
+ * alone and return FALSE.
+ *
+ * A naive driver that cannot reallocate the screen may simply change
+ * virtual[XY]. A more advanced driver will want to also change the
+ * devPrivate.ptr and devKind of the screen pixmap, update any offscreen
+ * pixmaps it may have moved, and change pScrn->displayWidth.
+ */
+ Bool
+ (*resize)(ScrnInfoPtr scrn,
+ int width,
+ int height);
+} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
+
+typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
+
+typedef struct _xf86CrtcConfig {
+ int num_output;
+ xf86OutputPtr *output;
+ /**
+ * compat_output is used whenever we deal
+ * with legacy code that only understands a single
+ * output. pScrn->modes will be loaded from this output,
+ * adjust frame will whack this output, etc.
+ */
+ int compat_output;
+
+ int num_crtc;
+ xf86CrtcPtr *crtc;
+
+ int minWidth, minHeight;
+ int maxWidth, maxHeight;
+
+ /* For crtc-based rotation */
+ DamagePtr rotation_damage;
+ Bool rotation_damage_registered;
+
+ /* DGA */
+ unsigned int dga_flags;
+ unsigned long dga_address;
+ DGAModePtr dga_modes;
+ int dga_nmode;
+ int dga_width, dga_height, dga_stride;
+ DisplayModePtr dga_save_mode;
+
+ const xf86CrtcConfigFuncsRec *funcs;
+
+ CreateScreenResourcesProcPtr CreateScreenResources;
+
+ CloseScreenProcPtr CloseScreen;
+
+ /* Cursor information */
+ xf86CursorInfoPtr cursor_info;
+ CursorPtr cursor;
+ CARD8 *cursor_image;
+ Bool cursor_on;
+ CARD32 cursor_fg, cursor_bg;
+
+ /**
+ * Options parsed from the related device section
+ */
+ OptionInfoPtr options;
+
+ Bool debug_modes;
+
+ /* wrap screen BlockHandler for rotation */
+ ScreenBlockHandlerProcPtr BlockHandler;
+
+ /* callback when crtc configuration changes */
+ xf86_crtc_notify_proc_ptr xf86_crtc_notify;
+
+} xf86CrtcConfigRec, *xf86CrtcConfigPtr;
+
+extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
+
+#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
+
+static _X_INLINE xf86OutputPtr
+xf86CompatOutput(ScrnInfoPtr pScrn)
+{
+ xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+ return config->output[config->compat_output];
+}
+
+static _X_INLINE xf86CrtcPtr
+xf86CompatCrtc(ScrnInfoPtr pScrn)
+{
+ xf86OutputPtr compat_output = xf86CompatOutput(pScrn);
+ if (!compat_output)
+ return NULL;
+ return compat_output->crtc;
+}
+
+static _X_INLINE RRCrtcPtr
+xf86CompatRRCrtc(ScrnInfoPtr pScrn)
+{
+ xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn);
+ if (!compat_crtc)
+ return NULL;
+ return compat_crtc->randr_crtc;
+}
+
+
+/*
+ * Initialize xf86CrtcConfig structure
+ */
+
+extern _X_EXPORT void
+xf86CrtcConfigInit (ScrnInfoPtr scrn,
+ const xf86CrtcConfigFuncsRec *funcs);
+
+extern _X_EXPORT void
+xf86CrtcSetSizeRange (ScrnInfoPtr scrn,
+ int minWidth, int minHeight,
+ int maxWidth, int maxHeight);
+
+/*
+ * Crtc functions
+ */
+extern _X_EXPORT xf86CrtcPtr
+xf86CrtcCreate (ScrnInfoPtr scrn,
+ const xf86CrtcFuncsRec *funcs);
+
+extern _X_EXPORT void
+xf86CrtcDestroy (xf86CrtcPtr crtc);
+
+
+/**
+ * Sets the given video mode on the given crtc
+ */
+
+extern _X_EXPORT Bool
+xf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
+ RRTransformPtr transform, int x, int y);
+
+extern _X_EXPORT Bool
+xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
+ int x, int y);
+
+extern _X_EXPORT void
+xf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y);
+
+/*
+ * Assign crtc rotation during mode set
+ */
+extern _X_EXPORT Bool
+xf86CrtcRotate (xf86CrtcPtr crtc);
+
+/*
+ * Clean up any rotation data, used when a crtc is turned off
+ * as well as when rotation is disabled.
+ */
+extern _X_EXPORT void
+xf86RotateDestroy (xf86CrtcPtr crtc);
+
+/*
+ * free shadow memory allocated for all crtcs
+ */
+extern _X_EXPORT void
+xf86RotateFreeShadow(ScrnInfoPtr pScrn);
+
+/*
+ * Clean up rotation during CloseScreen
+ */
+extern _X_EXPORT void
+xf86RotateCloseScreen (ScreenPtr pScreen);
+
+/**
+ * Return whether any output is assigned to the crtc
+ */
+extern _X_EXPORT Bool
+xf86CrtcInUse (xf86CrtcPtr crtc);
+
+/*
+ * Output functions
+ */
+extern _X_EXPORT xf86OutputPtr
+xf86OutputCreate (ScrnInfoPtr scrn,
+ const xf86OutputFuncsRec *funcs,
+ const char *name);
+
+extern _X_EXPORT void
+xf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor);
+
+extern _X_EXPORT Bool
+xf86OutputRename (xf86OutputPtr output, const char *name);
+
+extern _X_EXPORT void
+xf86OutputDestroy (xf86OutputPtr output);
+
+extern _X_EXPORT void
+xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY);
+
+extern _X_EXPORT void
+xf86SetScrnInfoModes (ScrnInfoPtr pScrn);
+
+#ifdef RANDR_13_INTERFACE
+# define ScreenInitRetType int
+#else
+# define ScreenInitRetType Bool
+#endif
+
+extern _X_EXPORT ScreenInitRetType
+xf86CrtcScreenInit (ScreenPtr pScreen);
+
+extern _X_EXPORT Bool
+xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow);
+
+extern _X_EXPORT void
+xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
+
+extern _X_EXPORT Bool
+xf86SaveScreen(ScreenPtr pScreen, int mode);
+
+extern _X_EXPORT void
+xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
+
+extern _X_EXPORT DisplayModePtr
+xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired);
+
+extern _X_EXPORT Bool
+xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
+
+/**
+ * Set the EDID information for the specified output
+ */
+extern _X_EXPORT void
+xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon);
+
+/**
+ * Return the list of modes supported by the EDID information
+ * stored in 'output'
+ */
+extern _X_EXPORT DisplayModePtr
+xf86OutputGetEDIDModes (xf86OutputPtr output);
+
+extern _X_EXPORT xf86MonPtr
+xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus);
+
+/**
+ * Initialize dga for this screen
+ */
+
+#ifdef XFreeXDGA
+extern _X_EXPORT Bool
+xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address);
+
+/* this is the real function, used only internally */
+_X_INTERNAL Bool
+_xf86_di_dga_init_internal (ScreenPtr pScreen);
+
+/**
+ * Re-initialize dga for this screen (as when the set of modes changes)
+ */
+
+extern _X_EXPORT Bool
+xf86DiDGAReInit (ScreenPtr pScreen);
+#endif
+
+/* This is the real function, used only internally */
+_X_INTERNAL Bool
+_xf86_di_dga_reinit_internal (ScreenPtr pScreen);
+
+/*
+ * Set the subpixel order reported for the screen using
+ * the information from the outputs
+ */
+
+extern _X_EXPORT void
+xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen);
+
+/*
+ * Get a standard string name for a connector type
+ */
+extern _X_EXPORT char *
+xf86ConnectorGetName(xf86ConnectorType connector);
+
+/*
+ * Using the desired mode information in each crtc, set
+ * modes (used in EnterVT functions, or at server startup)
+ */
+
+extern _X_EXPORT Bool
+xf86SetDesiredModes (ScrnInfoPtr pScrn);
+
+/**
+ * Initialize the CRTC-based cursor code. CRTC function vectors must
+ * contain relevant cursor setting functions.
+ *
+ * Driver should call this from ScreenInit function
+ */
+extern _X_EXPORT Bool
+xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags);
+
+/**
+ * Called when anything on the screen is reconfigured.
+ *
+ * Reloads cursor images as needed, then adjusts cursor positions.
+ *
+ * Driver should call this from crtc commit function.
+ */
+extern _X_EXPORT void
+xf86_reload_cursors (ScreenPtr screen);
+
+/**
+ * Called from EnterVT to turn the cursors back on
+ */
+extern _X_EXPORT void
+xf86_show_cursors (ScrnInfoPtr scrn);
+
+/**
+ * Called by the driver to turn cursors off
+ */
+extern _X_EXPORT void
+xf86_hide_cursors (ScrnInfoPtr scrn);
+
+/**
+ * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
+ */
+extern _X_EXPORT void
+xf86_cursors_fini (ScreenPtr screen);
+
+/*
+ * For overlay video, compute the relevant CRTC and
+ * clip video to that.
+ * wraps xf86XVClipVideoHelper()
+ */
+
+extern _X_EXPORT Bool
+xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
+ xf86CrtcPtr *crtc_ret,
+ xf86CrtcPtr desired_crtc,
+ BoxPtr dst,
+ INT32 *xa,
+ INT32 *xb,
+ INT32 *ya,
+ INT32 *yb,
+ RegionPtr reg,
+ INT32 width,
+ INT32 height);
+
+extern _X_EXPORT xf86_crtc_notify_proc_ptr
+xf86_wrap_crtc_notify (ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new);
+
+extern _X_EXPORT void
+xf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old);
+
+extern _X_EXPORT void
+xf86_crtc_notify(ScreenPtr pScreen);
+
+/**
+ * Gamma
+ */
+
+extern _X_EXPORT Bool
+xf86_crtc_supports_gamma(ScrnInfoPtr pScrn);
+
+#endif /* _XF86CRTC_H_ */
diff --git a/xorg-server/hw/xfree86/modes/xf86Cursors.c b/xorg-server/hw/xfree86/modes/xf86Cursors.c index 066744744..5562f29cc 100644 --- a/xorg-server/hw/xfree86/modes/xf86Cursors.c +++ b/xorg-server/hw/xfree86/modes/xf86Cursors.c @@ -1,688 +1,688 @@ -/* - * Copyright © 2007 Keith Packard - * Copyright © 2010 Aaron Plattner - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include <xorg-config.h> -#else -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#endif - -#include <stddef.h> -#include <string.h> -#include <stdio.h> - -#include "xf86.h" -#include "xf86DDC.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86RandR12.h" -#include "xf86CursorPriv.h" -#include "X11/extensions/render.h" -#include "X11/extensions/dpmsconst.h" -#include "X11/Xatom.h" -#include "picturestr.h" -#include "cursorstr.h" -#include "inputstr.h" - -/* - * Given a screen coordinate, rotate back to a cursor source coordinate - */ -static void -xf86_crtc_rotate_coord (Rotation rotation, - int width, - int height, - int x_dst, - int y_dst, - int *x_src, - int *y_src) -{ - int t; - - switch (rotation & 0xf) { - case RR_Rotate_0: - break; - case RR_Rotate_90: - t = x_dst; - x_dst = height - y_dst - 1; - y_dst = t; - break; - case RR_Rotate_180: - x_dst = width - x_dst - 1; - y_dst = height - y_dst - 1; - break; - case RR_Rotate_270: - t = x_dst; - x_dst = y_dst; - y_dst = width - t - 1; - break; - } - if (rotation & RR_Reflect_X) - x_dst = width - x_dst - 1; - if (rotation & RR_Reflect_Y) - y_dst = height - y_dst - 1; - *x_src = x_dst; - *y_src = y_dst; -} - -/* - * Given a cursor source coordinate, rotate to a screen coordinate - */ -static void -xf86_crtc_rotate_coord_back (Rotation rotation, - int width, - int height, - int x_dst, - int y_dst, - int *x_src, - int *y_src) -{ - int t; - - if (rotation & RR_Reflect_X) - x_dst = width - x_dst - 1; - if (rotation & RR_Reflect_Y) - y_dst = height - y_dst - 1; - - switch (rotation & 0xf) { - case RR_Rotate_0: - break; - case RR_Rotate_90: - t = x_dst; - x_dst = y_dst; - y_dst = width - t - 1; - break; - case RR_Rotate_180: - x_dst = width - x_dst - 1; - y_dst = height - y_dst - 1; - break; - case RR_Rotate_270: - t = x_dst; - x_dst = height - y_dst - 1; - y_dst = t; - break; - } - *x_src = x_dst; - *y_src = y_dst; -} - -struct cursor_bit { - CARD8 *byte; - char bitpos; -}; - -/* - * Convert an x coordinate to a position within the cursor bitmap - */ -static struct cursor_bit -cursor_bitpos (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, - Bool mask) -{ - const int flags = cursor_info->Flags; - const Bool interleaved = - !!(flags & (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64)); - const int width = cursor_info->MaxWidth; - const int height = cursor_info->MaxHeight; - const int stride = interleaved ? width / 4 : width / 8; - - struct cursor_bit ret; - - image += y * stride; - - if (flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK) - mask = !mask; - if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED) - x = (x & ~3) | (3 - (x & 3)); - if (((flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) == 0) == - (X_BYTE_ORDER == X_BIG_ENDIAN)) - x = (x & ~7) | (7 - (x & 7)); - if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1) - x = (x << 1) + mask; - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8) - x = ((x & ~7) << 1) | (mask << 3) | (x & 7); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16) - x = ((x & ~15) << 1) | (mask << 4) | (x & 15); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32) - x = ((x & ~31) << 1) | (mask << 5) | (x & 31); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64) - x = ((x & ~63) << 1) | (mask << 6) | (x & 63); - else if (mask) - image += stride * height; - - ret.byte = image + (x / 8); - ret.bitpos = x & 7; - - return ret; -} - -/* - * Fetch one bit from a cursor bitmap - */ -static CARD8 -get_bit (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask) -{ - struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask); - return (*bit.byte >> bit.bitpos) & 1; -} - -/* - * Set one bit in a cursor bitmap - */ -static void -set_bit (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask) -{ - struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask); - *bit.byte |= 1 << bit.bitpos; -} - -/* - * Load a two color cursor into a driver that supports only ARGB cursors - */ -static void -xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; - int x, y; - int xin, yin; - int flags = cursor_info->Flags; - CARD32 bits; - -#ifdef ARGB_CURSOR - crtc->cursor_argb = FALSE; -#endif - - for (y = 0; y < cursor_info->MaxHeight; y++) - for (x = 0; x < cursor_info->MaxWidth; x++) - { - xf86_crtc_rotate_coord (crtc->rotation, - cursor_info->MaxWidth, - cursor_info->MaxHeight, - x, y, &xin, &yin); - if (get_bit (src, cursor_info, xin, yin, TRUE) == - ((flags & HARDWARE_CURSOR_INVERT_MASK) == 0)) - { - if (get_bit (src, cursor_info, xin, yin, FALSE)) - bits = xf86_config->cursor_fg; - else - bits = xf86_config->cursor_bg; - } - else - bits = 0; - cursor_image[y * cursor_info->MaxWidth + x] = bits; - } - crtc->funcs->load_cursor_argb (crtc, cursor_image); -} - -/* - * Set the colors for a two-color cursor (ignore for ARGB cursors) - */ -static void -xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg) -{ - ScreenPtr screen = scrn->pScreen; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - CursorPtr cursor = xf86_config->cursor; - int c; - CARD8 *bits = cursor ? - dixLookupPrivate(&cursor->devPrivates, CursorScreenKey(screen)) - : NULL; - - /* Save ARGB versions of these colors */ - xf86_config->cursor_fg = (CARD32) fg | 0xff000000; - xf86_config->cursor_bg = (CARD32) bg | 0xff000000; - - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled && !crtc->cursor_argb) - { - if (crtc->funcs->load_cursor_image) - crtc->funcs->set_cursor_colors (crtc, bg, fg); - else if (bits) - xf86_crtc_convert_cursor_to_argb (crtc, bits); - } - } -} - -static void -xf86_crtc_hide_cursor (xf86CrtcPtr crtc) -{ - if (crtc->cursor_shown) - { - crtc->funcs->hide_cursor (crtc); - crtc->cursor_shown = FALSE; - } -} - -void -xf86_hide_cursors (ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor_on = FALSE; - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_hide_cursor (crtc); - } -} - -static void -xf86_crtc_show_cursor (xf86CrtcPtr crtc) -{ - if (!crtc->cursor_shown && crtc->cursor_in_range) - { - crtc->funcs->show_cursor (crtc); - crtc->cursor_shown = TRUE; - } -} - -void -xf86_show_cursors (ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor_on = TRUE; - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_show_cursor (crtc); - } -} - -static void -xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - DisplayModePtr mode = &crtc->mode; - Bool in_range; - int dx, dy; - - /* - * Transform position of cursor on screen - */ - if (crtc->transform_in_use) - { - ScreenPtr screen = scrn->pScreen; - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr)dixLookupPrivate(&screen->devPrivates, - xf86CursorScreenKey); - struct pict_f_vector v; - - v.v[0] = (x + ScreenPriv->HotX) + 0.5; - v.v[1] = (y + ScreenPriv->HotY) + 0.5; - v.v[2] = 1; - pixman_f_transform_point (&crtc->f_framebuffer_to_crtc, &v); - /* cursor will have 0.5 added to it already so floor is sufficent */ - x = floor (v.v[0]); - y = floor (v.v[1]); - /* - * Transform position of cursor upper left corner - */ - xf86_crtc_rotate_coord_back (crtc->rotation, - cursor_info->MaxWidth, - cursor_info->MaxHeight, - ScreenPriv->HotX, ScreenPriv->HotY, &dx, &dy); - x -= dx; - y -= dy; - } - else - { - x -= crtc->x; - y -= crtc->y; - } - - /* - * Disable the cursor when it is outside the viewport - */ - in_range = TRUE; - if (x >= mode->HDisplay || y >= mode->VDisplay || - x <= -cursor_info->MaxWidth || y <= -cursor_info->MaxHeight) - { - in_range = FALSE; - x = 0; - y = 0; - } - - crtc->cursor_in_range = in_range; - - if (in_range) - { - crtc->funcs->set_cursor_position (crtc, x, y); - xf86_crtc_show_cursor (crtc); - } - else - xf86_crtc_hide_cursor (crtc); -} - -static void -xf86_set_cursor_position (ScrnInfoPtr scrn, int x, int y) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - /* undo what xf86HWCurs did to the coordinates */ - x += scrn->frameX0; - y += scrn->frameY0; - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_set_cursor_position (crtc, x, y); - } -} - -/* - * Load a two-color cursor into a crtc, performing rotation as needed - */ -static void -xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD8 *cursor_image; - -#ifdef ARGB_CURSOR - crtc->cursor_argb = FALSE; -#endif - - if (crtc->rotation == RR_Rotate_0) - cursor_image = src; - else - { - int x, y; - int xin, yin; - int stride = cursor_info->MaxWidth >> 2; - - cursor_image = xf86_config->cursor_image; - memset(cursor_image, 0, cursor_info->MaxHeight * stride); - - for (y = 0; y < cursor_info->MaxHeight; y++) - for (x = 0; x < cursor_info->MaxWidth; x++) - { - xf86_crtc_rotate_coord (crtc->rotation, - cursor_info->MaxWidth, - cursor_info->MaxHeight, - x, y, &xin, &yin); - if (get_bit(src, cursor_info, xin, yin, FALSE)) - set_bit(cursor_image, cursor_info, x, y, FALSE); - if (get_bit(src, cursor_info, xin, yin, TRUE)) - set_bit(cursor_image, cursor_info, x, y, TRUE); - } - } - crtc->funcs->load_cursor_image (crtc, cursor_image); -} - -/* - * Load a cursor image into all active CRTCs - */ -static void -xf86_load_cursor_image (ScrnInfoPtr scrn, unsigned char *src) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - { - if (crtc->funcs->load_cursor_image) - xf86_crtc_load_cursor_image (crtc, src); - else if (crtc->funcs->load_cursor_argb) - xf86_crtc_convert_cursor_to_argb (crtc, src); - } - } -} - -static Bool -xf86_use_hw_cursor (ScreenPtr screen, CursorPtr cursor) -{ - ScrnInfoPtr scrn = xf86Screens[screen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - - ++cursor->refcnt; - if (xf86_config->cursor) - FreeCursor (xf86_config->cursor, None); - xf86_config->cursor = cursor; - - if (cursor->bits->width > cursor_info->MaxWidth || - cursor->bits->height> cursor_info->MaxHeight) - return FALSE; - - return TRUE; -} - -static Bool -xf86_use_hw_cursor_argb (ScreenPtr screen, CursorPtr cursor) -{ - ScrnInfoPtr scrn = xf86Screens[screen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - - ++cursor->refcnt; - if (xf86_config->cursor) - FreeCursor (xf86_config->cursor, None); - xf86_config->cursor = cursor; - - /* Make sure ARGB support is available */ - if ((cursor_info->Flags & HARDWARE_CURSOR_ARGB) == 0) - return FALSE; - - if (cursor->bits->width > cursor_info->MaxWidth || - cursor->bits->height> cursor_info->MaxHeight) - return FALSE; - - return TRUE; -} - -static void -xf86_crtc_load_cursor_argb (xf86CrtcPtr crtc, CursorPtr cursor) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; - CARD32 *cursor_source = (CARD32 *) cursor->bits->argb; - int x, y; - int xin, yin; - CARD32 bits; - int source_width = cursor->bits->width; - int source_height = cursor->bits->height; - int image_width = cursor_info->MaxWidth; - int image_height = cursor_info->MaxHeight; - - for (y = 0; y < image_height; y++) - for (x = 0; x < image_width; x++) - { - xf86_crtc_rotate_coord (crtc->rotation, image_width, image_height, - x, y, &xin, &yin); - if (xin < source_width && yin < source_height) - bits = cursor_source[yin * source_width + xin]; - else - bits = 0; - cursor_image[y * image_width + x] = bits; - } - - crtc->funcs->load_cursor_argb (crtc, cursor_image); -} - -static void -xf86_load_cursor_argb (ScrnInfoPtr scrn, CursorPtr cursor) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_load_cursor_argb (crtc, cursor); - } -} - -Bool -xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags) -{ - ScrnInfoPtr scrn = xf86Screens[screen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info; - - cursor_info = xf86CreateCursorInfoRec(); - if (!cursor_info) - return FALSE; - - xf86_config->cursor_image = malloc(max_width * max_height * 4); - - if (!xf86_config->cursor_image) - { - xf86DestroyCursorInfoRec (cursor_info); - return FALSE; - } - - xf86_config->cursor_info = cursor_info; - - cursor_info->MaxWidth = max_width; - cursor_info->MaxHeight = max_height; - cursor_info->Flags = flags; - - cursor_info->SetCursorColors = xf86_set_cursor_colors; - cursor_info->SetCursorPosition = xf86_set_cursor_position; - cursor_info->LoadCursorImage = xf86_load_cursor_image; - cursor_info->HideCursor = xf86_hide_cursors; - cursor_info->ShowCursor = xf86_show_cursors; - cursor_info->UseHWCursor = xf86_use_hw_cursor; -#ifdef ARGB_CURSOR - if (flags & HARDWARE_CURSOR_ARGB) - { - cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb; - cursor_info->LoadCursorARGB = xf86_load_cursor_argb; - } -#endif - - xf86_config->cursor = NULL; - xf86_hide_cursors (scrn); - - return xf86InitCursor (screen, cursor_info); -} - -/** - * Called when anything on the screen is reconfigured. - * - * Reloads cursor images as needed, then adjusts cursor positions - */ - -void -xf86_reload_cursors (ScreenPtr screen) -{ - ScrnInfoPtr scrn; - xf86CrtcConfigPtr xf86_config; - xf86CursorInfoPtr cursor_info; - CursorPtr cursor; - int x, y; - xf86CursorScreenPtr cursor_screen_priv; - - /* initial mode setting will not have set a screen yet. - May be called before the devices are initialised. - */ - if (!screen || !inputInfo.pointer) - return; - cursor_screen_priv = dixLookupPrivate(&screen->devPrivates, - xf86CursorScreenKey); - /* return if HW cursor is inactive, to avoid displaying two cursors */ - if (!cursor_screen_priv || !cursor_screen_priv->isUp) - return; - - scrn = xf86Screens[screen->myNum]; - xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - /* make sure the cursor code has been initialized */ - cursor_info = xf86_config->cursor_info; - if (!cursor_info) - return; - - cursor = xf86_config->cursor; - GetSpritePosition (inputInfo.pointer, &x, &y); - if (!(cursor_info->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN)) - (*cursor_info->HideCursor)(scrn); - - if (cursor) - { - void *src = dixLookupPrivate(&cursor->devPrivates, CursorScreenKey(screen)); -#ifdef ARGB_CURSOR - if (cursor->bits->argb && cursor_info->LoadCursorARGB) - (*cursor_info->LoadCursorARGB) (scrn, cursor); - else if (src) -#endif - (*cursor_info->LoadCursorImage)(scrn, src); - - x += scrn->frameX0 + cursor_screen_priv->HotX; - y += scrn->frameY0 + cursor_screen_priv->HotY; - (*cursor_info->SetCursorPosition)(scrn, x, y); - } -} - -/** - * Clean up CRTC-based cursor code - */ -void -xf86_cursors_fini (ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86Screens[screen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - if (xf86_config->cursor_info) - { - xf86DestroyCursorInfoRec (xf86_config->cursor_info); - xf86_config->cursor_info = NULL; - } - free(xf86_config->cursor_image); - xf86_config->cursor_image = NULL; - if (xf86_config->cursor) - { - FreeCursor (xf86_config->cursor, None); - xf86_config->cursor = NULL; - } -} +/*
+ * Copyright © 2007 Keith Packard
+ * Copyright © 2010 Aaron Plattner
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "xf86RandR12.h"
+#include "xf86CursorPriv.h"
+#include "X11/extensions/render.h"
+#include "X11/extensions/dpmsconst.h"
+#include "X11/Xatom.h"
+#include "picturestr.h"
+#include "cursorstr.h"
+#include "inputstr.h"
+
+/*
+ * Given a screen coordinate, rotate back to a cursor source coordinate
+ */
+static void
+xf86_crtc_rotate_coord (Rotation rotation,
+ int width,
+ int height,
+ int x_dst,
+ int y_dst,
+ int *x_src,
+ int *y_src)
+{
+ int t;
+
+ switch (rotation & 0xf) {
+ case RR_Rotate_0:
+ break;
+ case RR_Rotate_90:
+ t = x_dst;
+ x_dst = height - y_dst - 1;
+ y_dst = t;
+ break;
+ case RR_Rotate_180:
+ x_dst = width - x_dst - 1;
+ y_dst = height - y_dst - 1;
+ break;
+ case RR_Rotate_270:
+ t = x_dst;
+ x_dst = y_dst;
+ y_dst = width - t - 1;
+ break;
+ }
+ if (rotation & RR_Reflect_X)
+ x_dst = width - x_dst - 1;
+ if (rotation & RR_Reflect_Y)
+ y_dst = height - y_dst - 1;
+ *x_src = x_dst;
+ *y_src = y_dst;
+}
+
+/*
+ * Given a cursor source coordinate, rotate to a screen coordinate
+ */
+static void
+xf86_crtc_rotate_coord_back (Rotation rotation,
+ int width,
+ int height,
+ int x_dst,
+ int y_dst,
+ int *x_src,
+ int *y_src)
+{
+ int t;
+
+ if (rotation & RR_Reflect_X)
+ x_dst = width - x_dst - 1;
+ if (rotation & RR_Reflect_Y)
+ y_dst = height - y_dst - 1;
+
+ switch (rotation & 0xf) {
+ case RR_Rotate_0:
+ break;
+ case RR_Rotate_90:
+ t = x_dst;
+ x_dst = y_dst;
+ y_dst = width - t - 1;
+ break;
+ case RR_Rotate_180:
+ x_dst = width - x_dst - 1;
+ y_dst = height - y_dst - 1;
+ break;
+ case RR_Rotate_270:
+ t = x_dst;
+ x_dst = height - y_dst - 1;
+ y_dst = t;
+ break;
+ }
+ *x_src = x_dst;
+ *y_src = y_dst;
+}
+
+struct cursor_bit {
+ CARD8 *byte;
+ char bitpos;
+};
+
+/*
+ * Convert an x coordinate to a position within the cursor bitmap
+ */
+static struct cursor_bit
+cursor_bitpos (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y,
+ Bool mask)
+{
+ const int flags = cursor_info->Flags;
+ const Bool interleaved =
+ !!(flags & (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 |
+ HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 |
+ HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 |
+ HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 |
+ HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64));
+ const int width = cursor_info->MaxWidth;
+ const int height = cursor_info->MaxHeight;
+ const int stride = interleaved ? width / 4 : width / 8;
+
+ struct cursor_bit ret;
+
+ image += y * stride;
+
+ if (flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK)
+ mask = !mask;
+ if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED)
+ x = (x & ~3) | (3 - (x & 3));
+ if (((flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) == 0) ==
+ (X_BYTE_ORDER == X_BIG_ENDIAN))
+ x = (x & ~7) | (7 - (x & 7));
+ if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1)
+ x = (x << 1) + mask;
+ else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8)
+ x = ((x & ~7) << 1) | (mask << 3) | (x & 7);
+ else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16)
+ x = ((x & ~15) << 1) | (mask << 4) | (x & 15);
+ else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32)
+ x = ((x & ~31) << 1) | (mask << 5) | (x & 31);
+ else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64)
+ x = ((x & ~63) << 1) | (mask << 6) | (x & 63);
+ else if (mask)
+ image += stride * height;
+
+ ret.byte = image + (x / 8);
+ ret.bitpos = x & 7;
+
+ return ret;
+}
+
+/*
+ * Fetch one bit from a cursor bitmap
+ */
+static CARD8
+get_bit (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask)
+{
+ struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask);
+ return (*bit.byte >> bit.bitpos) & 1;
+}
+
+/*
+ * Set one bit in a cursor bitmap
+ */
+static void
+set_bit (CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask)
+{
+ struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask);
+ *bit.byte |= 1 << bit.bitpos;
+}
+
+/*
+ * Load a two color cursor into a driver that supports only ARGB cursors
+ */
+static void
+xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src)
+{
+ ScrnInfoPtr scrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+ CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image;
+ int x, y;
+ int xin, yin;
+ int flags = cursor_info->Flags;
+ CARD32 bits;
+
+#ifdef ARGB_CURSOR
+ crtc->cursor_argb = FALSE;
+#endif
+
+ for (y = 0; y < cursor_info->MaxHeight; y++)
+ for (x = 0; x < cursor_info->MaxWidth; x++)
+ {
+ xf86_crtc_rotate_coord (crtc->rotation,
+ cursor_info->MaxWidth,
+ cursor_info->MaxHeight,
+ x, y, &xin, &yin);
+ if (get_bit (src, cursor_info, xin, yin, TRUE) ==
+ ((flags & HARDWARE_CURSOR_INVERT_MASK) == 0))
+ {
+ if (get_bit (src, cursor_info, xin, yin, FALSE))
+ bits = xf86_config->cursor_fg;
+ else
+ bits = xf86_config->cursor_bg;
+ }
+ else
+ bits = 0;
+ cursor_image[y * cursor_info->MaxWidth + x] = bits;
+ }
+ crtc->funcs->load_cursor_argb (crtc, cursor_image);
+}
+
+/*
+ * Set the colors for a two-color cursor (ignore for ARGB cursors)
+ */
+static void
+xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg)
+{
+ ScreenPtr screen = scrn->pScreen;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ CursorPtr cursor = xf86_config->cursor;
+ int c;
+ CARD8 *bits = cursor ?
+ dixLookupPrivate(&cursor->devPrivates, CursorScreenKey(screen))
+ : NULL;
+
+ /* Save ARGB versions of these colors */
+ xf86_config->cursor_fg = (CARD32) fg | 0xff000000;
+ xf86_config->cursor_bg = (CARD32) bg | 0xff000000;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled && !crtc->cursor_argb)
+ {
+ if (crtc->funcs->load_cursor_image)
+ crtc->funcs->set_cursor_colors (crtc, bg, fg);
+ else if (bits)
+ xf86_crtc_convert_cursor_to_argb (crtc, bits);
+ }
+ }
+}
+
+static void
+xf86_crtc_hide_cursor (xf86CrtcPtr crtc)
+{
+ if (crtc->cursor_shown)
+ {
+ crtc->funcs->hide_cursor (crtc);
+ crtc->cursor_shown = FALSE;
+ }
+}
+
+void
+xf86_hide_cursors (ScrnInfoPtr scrn)
+{
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ xf86_config->cursor_on = FALSE;
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled)
+ xf86_crtc_hide_cursor (crtc);
+ }
+}
+
+static void
+xf86_crtc_show_cursor (xf86CrtcPtr crtc)
+{
+ if (!crtc->cursor_shown && crtc->cursor_in_range)
+ {
+ crtc->funcs->show_cursor (crtc);
+ crtc->cursor_shown = TRUE;
+ }
+}
+
+void
+xf86_show_cursors (ScrnInfoPtr scrn)
+{
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ xf86_config->cursor_on = TRUE;
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled)
+ xf86_crtc_show_cursor (crtc);
+ }
+}
+
+static void
+xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+ ScrnInfoPtr scrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+ DisplayModePtr mode = &crtc->mode;
+ Bool in_range;
+ int dx, dy;
+
+ /*
+ * Transform position of cursor on screen
+ */
+ if (crtc->transform_in_use)
+ {
+ ScreenPtr screen = scrn->pScreen;
+ xf86CursorScreenPtr ScreenPriv =
+ (xf86CursorScreenPtr)dixLookupPrivate(&screen->devPrivates,
+ xf86CursorScreenKey);
+ struct pict_f_vector v;
+
+ v.v[0] = (x + ScreenPriv->HotX) + 0.5;
+ v.v[1] = (y + ScreenPriv->HotY) + 0.5;
+ v.v[2] = 1;
+ pixman_f_transform_point (&crtc->f_framebuffer_to_crtc, &v);
+ /* cursor will have 0.5 added to it already so floor is sufficent */
+ x = floor (v.v[0]);
+ y = floor (v.v[1]);
+ /*
+ * Transform position of cursor upper left corner
+ */
+ xf86_crtc_rotate_coord_back (crtc->rotation,
+ cursor_info->MaxWidth,
+ cursor_info->MaxHeight,
+ ScreenPriv->HotX, ScreenPriv->HotY, &dx, &dy);
+ x -= dx;
+ y -= dy;
+ }
+ else
+ {
+ x -= crtc->x;
+ y -= crtc->y;
+ }
+
+ /*
+ * Disable the cursor when it is outside the viewport
+ */
+ in_range = TRUE;
+ if (x >= mode->HDisplay || y >= mode->VDisplay ||
+ x <= -cursor_info->MaxWidth || y <= -cursor_info->MaxHeight)
+ {
+ in_range = FALSE;
+ x = 0;
+ y = 0;
+ }
+
+ crtc->cursor_in_range = in_range;
+
+ if (in_range)
+ {
+ crtc->funcs->set_cursor_position (crtc, x, y);
+ xf86_crtc_show_cursor (crtc);
+ }
+ else
+ xf86_crtc_hide_cursor (crtc);
+}
+
+static void
+xf86_set_cursor_position (ScrnInfoPtr scrn, int x, int y)
+{
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ /* undo what xf86HWCurs did to the coordinates */
+ x += scrn->frameX0;
+ y += scrn->frameY0;
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled)
+ xf86_crtc_set_cursor_position (crtc, x, y);
+ }
+}
+
+/*
+ * Load a two-color cursor into a crtc, performing rotation as needed
+ */
+static void
+xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src)
+{
+ ScrnInfoPtr scrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+ CARD8 *cursor_image;
+
+#ifdef ARGB_CURSOR
+ crtc->cursor_argb = FALSE;
+#endif
+
+ if (crtc->rotation == RR_Rotate_0)
+ cursor_image = src;
+ else
+ {
+ int x, y;
+ int xin, yin;
+ int stride = cursor_info->MaxWidth >> 2;
+
+ cursor_image = xf86_config->cursor_image;
+ memset(cursor_image, 0, cursor_info->MaxHeight * stride);
+
+ for (y = 0; y < cursor_info->MaxHeight; y++)
+ for (x = 0; x < cursor_info->MaxWidth; x++)
+ {
+ xf86_crtc_rotate_coord (crtc->rotation,
+ cursor_info->MaxWidth,
+ cursor_info->MaxHeight,
+ x, y, &xin, &yin);
+ if (get_bit(src, cursor_info, xin, yin, FALSE))
+ set_bit(cursor_image, cursor_info, x, y, FALSE);
+ if (get_bit(src, cursor_info, xin, yin, TRUE))
+ set_bit(cursor_image, cursor_info, x, y, TRUE);
+ }
+ }
+ crtc->funcs->load_cursor_image (crtc, cursor_image);
+}
+
+/*
+ * Load a cursor image into all active CRTCs
+ */
+static void
+xf86_load_cursor_image (ScrnInfoPtr scrn, unsigned char *src)
+{
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled)
+ {
+ if (crtc->funcs->load_cursor_image)
+ xf86_crtc_load_cursor_image (crtc, src);
+ else if (crtc->funcs->load_cursor_argb)
+ xf86_crtc_convert_cursor_to_argb (crtc, src);
+ }
+ }
+}
+
+static Bool
+xf86_use_hw_cursor (ScreenPtr screen, CursorPtr cursor)
+{
+ ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+
+ ++cursor->refcnt;
+ if (xf86_config->cursor)
+ FreeCursor (xf86_config->cursor, None);
+ xf86_config->cursor = cursor;
+
+ if (cursor->bits->width > cursor_info->MaxWidth ||
+ cursor->bits->height> cursor_info->MaxHeight)
+ return FALSE;
+
+ return TRUE;
+}
+
+static Bool
+xf86_use_hw_cursor_argb (ScreenPtr screen, CursorPtr cursor)
+{
+ ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+
+ ++cursor->refcnt;
+ if (xf86_config->cursor)
+ FreeCursor (xf86_config->cursor, None);
+ xf86_config->cursor = cursor;
+
+ /* Make sure ARGB support is available */
+ if ((cursor_info->Flags & HARDWARE_CURSOR_ARGB) == 0)
+ return FALSE;
+
+ if (cursor->bits->width > cursor_info->MaxWidth ||
+ cursor->bits->height> cursor_info->MaxHeight)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void
+xf86_crtc_load_cursor_argb (xf86CrtcPtr crtc, CursorPtr cursor)
+{
+ ScrnInfoPtr scrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+ CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image;
+ CARD32 *cursor_source = (CARD32 *) cursor->bits->argb;
+ int x, y;
+ int xin, yin;
+ CARD32 bits;
+ int source_width = cursor->bits->width;
+ int source_height = cursor->bits->height;
+ int image_width = cursor_info->MaxWidth;
+ int image_height = cursor_info->MaxHeight;
+
+ for (y = 0; y < image_height; y++)
+ for (x = 0; x < image_width; x++)
+ {
+ xf86_crtc_rotate_coord (crtc->rotation, image_width, image_height,
+ x, y, &xin, &yin);
+ if (xin < source_width && yin < source_height)
+ bits = cursor_source[yin * source_width + xin];
+ else
+ bits = 0;
+ cursor_image[y * image_width + x] = bits;
+ }
+
+ crtc->funcs->load_cursor_argb (crtc, cursor_image);
+}
+
+static void
+xf86_load_cursor_argb (ScrnInfoPtr scrn, CursorPtr cursor)
+{
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->enabled)
+ xf86_crtc_load_cursor_argb (crtc, cursor);
+ }
+}
+
+Bool
+xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags)
+{
+ ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ xf86CursorInfoPtr cursor_info;
+
+ cursor_info = xf86CreateCursorInfoRec();
+ if (!cursor_info)
+ return FALSE;
+
+ xf86_config->cursor_image = malloc(max_width * max_height * 4);
+
+ if (!xf86_config->cursor_image)
+ {
+ xf86DestroyCursorInfoRec (cursor_info);
+ return FALSE;
+ }
+
+ xf86_config->cursor_info = cursor_info;
+
+ cursor_info->MaxWidth = max_width;
+ cursor_info->MaxHeight = max_height;
+ cursor_info->Flags = flags;
+
+ cursor_info->SetCursorColors = xf86_set_cursor_colors;
+ cursor_info->SetCursorPosition = xf86_set_cursor_position;
+ cursor_info->LoadCursorImage = xf86_load_cursor_image;
+ cursor_info->HideCursor = xf86_hide_cursors;
+ cursor_info->ShowCursor = xf86_show_cursors;
+ cursor_info->UseHWCursor = xf86_use_hw_cursor;
+#ifdef ARGB_CURSOR
+ if (flags & HARDWARE_CURSOR_ARGB)
+ {
+ cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb;
+ cursor_info->LoadCursorARGB = xf86_load_cursor_argb;
+ }
+#endif
+
+ xf86_config->cursor = NULL;
+ xf86_hide_cursors (scrn);
+
+ return xf86InitCursor (screen, cursor_info);
+}
+
+/**
+ * Called when anything on the screen is reconfigured.
+ *
+ * Reloads cursor images as needed, then adjusts cursor positions
+ */
+
+void
+xf86_reload_cursors (ScreenPtr screen)
+{
+ ScrnInfoPtr scrn;
+ xf86CrtcConfigPtr xf86_config;
+ xf86CursorInfoPtr cursor_info;
+ CursorPtr cursor;
+ int x, y;
+ xf86CursorScreenPtr cursor_screen_priv;
+
+ /* initial mode setting will not have set a screen yet.
+ May be called before the devices are initialised.
+ */
+ if (!screen || !inputInfo.pointer)
+ return;
+ cursor_screen_priv = dixLookupPrivate(&screen->devPrivates,
+ xf86CursorScreenKey);
+ /* return if HW cursor is inactive, to avoid displaying two cursors */
+ if (!cursor_screen_priv || !cursor_screen_priv->isUp)
+ return;
+
+ scrn = xf86Screens[screen->myNum];
+ xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+ /* make sure the cursor code has been initialized */
+ cursor_info = xf86_config->cursor_info;
+ if (!cursor_info)
+ return;
+
+ cursor = xf86_config->cursor;
+ GetSpritePosition (inputInfo.pointer, &x, &y);
+ if (!(cursor_info->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN))
+ (*cursor_info->HideCursor)(scrn);
+
+ if (cursor)
+ {
+ void *src = dixLookupPrivate(&cursor->devPrivates, CursorScreenKey(screen));
+#ifdef ARGB_CURSOR
+ if (cursor->bits->argb && cursor_info->LoadCursorARGB)
+ (*cursor_info->LoadCursorARGB) (scrn, cursor);
+ else if (src)
+#endif
+ (*cursor_info->LoadCursorImage)(scrn, src);
+
+ x += scrn->frameX0 + cursor_screen_priv->HotX;
+ y += scrn->frameY0 + cursor_screen_priv->HotY;
+ (*cursor_info->SetCursorPosition)(scrn, x, y);
+ }
+}
+
+/**
+ * Clean up CRTC-based cursor code
+ */
+void
+xf86_cursors_fini (ScreenPtr screen)
+{
+ ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+ if (xf86_config->cursor_info)
+ {
+ xf86DestroyCursorInfoRec (xf86_config->cursor_info);
+ xf86_config->cursor_info = NULL;
+ }
+ free(xf86_config->cursor_image);
+ xf86_config->cursor_image = NULL;
+ if (xf86_config->cursor)
+ {
+ FreeCursor (xf86_config->cursor, None);
+ xf86_config->cursor = NULL;
+ }
+}
diff --git a/xorg-server/hw/xfree86/modes/xf86Rotate.c b/xorg-server/hw/xfree86/modes/xf86Rotate.c index 57c3499ac..655857597 100644 --- a/xorg-server/hw/xfree86/modes/xf86Rotate.c +++ b/xorg-server/hw/xfree86/modes/xf86Rotate.c @@ -1,525 +1,525 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include <xorg-config.h> -#else -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#endif - -#include <stddef.h> -#include <string.h> -#include <stdio.h> - -#include "xf86.h" -#include "xf86DDC.h" -#include "fb.h" -#include "windowstr.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86RandR12.h" -#include "X11/extensions/render.h" -#include "X11/extensions/dpmsconst.h" -#include "X11/Xatom.h" - -/* borrowed from composite extension, move to Render and publish? */ - -static VisualPtr -compGetWindowVisual (WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - VisualID vid = wVisual (pWin); - int i; - - for (i = 0; i < pScreen->numVisuals; i++) - if (pScreen->visuals[i].vid == vid) - return &pScreen->visuals[i]; - return 0; -} - -static PictFormatPtr -compWindowFormat (WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - - return PictureMatchVisual (pScreen, pWin->drawable.depth, - compGetWindowVisual (pWin)); -} - -#define F(x) IntToxFixed(x) - -#define toF(x) ((float) (x) / 65536.0f) - -static void -xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region) -{ - ScrnInfoPtr scrn = crtc->scrn; - ScreenPtr screen = scrn->pScreen; - WindowPtr root = screen->root; - PixmapPtr dst_pixmap = crtc->rotatedPixmap; - PictFormatPtr format = compWindowFormat (screen->root); - int error; - PicturePtr src, dst; - int n = RegionNumRects(region); - BoxPtr b = RegionRects(region); - XID include_inferiors = IncludeInferiors; - - src = CreatePicture (None, - &root->drawable, - format, - CPSubwindowMode, - &include_inferiors, - serverClient, - &error); - if (!src) - return; - - dst = CreatePicture (None, - &dst_pixmap->drawable, - format, - 0L, - NULL, - serverClient, - &error); - if (!dst) - return; - - error = SetPictureTransform (src, &crtc->crtc_to_framebuffer); - if (error) - return; - if (crtc->transform_in_use && crtc->filter) - SetPicturePictFilter (src, crtc->filter, - crtc->params, crtc->nparams); - - if (crtc->shadowClear) - { - CompositePicture (PictOpSrc, - src, NULL, dst, - 0, 0, 0, 0, 0, 0, - crtc->mode.HDisplay, crtc->mode.VDisplay); - crtc->shadowClear = FALSE; - } - else - { - while (n--) - { - BoxRec dst_box; - - dst_box = *b; - dst_box.x1 -= crtc->filter_width >> 1; - dst_box.x2 += crtc->filter_width >> 1; - dst_box.y1 -= crtc->filter_height >> 1; - dst_box.y2 += crtc->filter_height >> 1; - pixman_f_transform_bounds (&crtc->f_framebuffer_to_crtc, &dst_box); - CompositePicture (PictOpSrc, - src, NULL, dst, - dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, dst_box.y1, - dst_box.x2 - dst_box.x1, - dst_box.y2 - dst_box.y1); - b++; - } - } - FreePicture (src, None); - FreePicture (dst, None); -} - -static void -xf86CrtcDamageShadow (xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - BoxRec damage_box; - RegionRec damage_region; - ScreenPtr pScreen = pScrn->pScreen; - - damage_box.x1 = 0; - damage_box.x2 = crtc->mode.HDisplay; - damage_box.y1 = 0; - damage_box.y2 = crtc->mode.VDisplay; - if (!pixman_transform_bounds (&crtc->crtc_to_framebuffer, &damage_box)) - { - damage_box.x1 = 0; - damage_box.y1 = 0; - damage_box.x2 = pScreen->width; - damage_box.y2 = pScreen->height; - } - if (damage_box.x1 < 0) damage_box.x1 = 0; - if (damage_box.y1 < 0) damage_box.y1 = 0; - if (damage_box.x2 > pScreen->width) damage_box.x2 = pScreen->width; - if (damage_box.y2 > pScreen->height) damage_box.y2 = pScreen->height; - RegionInit(&damage_region, &damage_box, 1); - DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, - &damage_region); - RegionUninit(&damage_region); - crtc->shadowClear = TRUE; -} - -static void -xf86RotatePrepare (ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->rotatedData && !crtc->rotatedPixmap) - { - crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc, - crtc->rotatedData, - crtc->mode.HDisplay, - crtc->mode.VDisplay); - if (!xf86_config->rotation_damage_registered) - { - /* Hook damage to screen pixmap */ - DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, - xf86_config->rotation_damage); - xf86_config->rotation_damage_registered = TRUE; - EnableLimitedSchedulingLatency(); - } - - xf86CrtcDamageShadow (crtc); - } - } -} - -static Bool -xf86RotateRedisplay(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - DamagePtr damage = xf86_config->rotation_damage; - RegionPtr region; - - if (!damage) - return FALSE; - xf86RotatePrepare (pScreen); - region = DamageRegion(damage); - if (RegionNotEmpty(region)) - { - int c; - SourceValidateProcPtr SourceValidate; - - /* - * SourceValidate is used by the software cursor code - * to pull the cursor off of the screen when reading - * bits from the frame buffer. Bypassing this function - * leaves the software cursor in place - */ - SourceValidate = pScreen->SourceValidate; - pScreen->SourceValidate = NULL; - - for (c = 0; c < xf86_config->num_crtc; c++) - { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->transform_in_use && crtc->enabled) - { - RegionRec crtc_damage; - - /* compute portion of damage that overlaps crtc */ - RegionInit(&crtc_damage, &crtc->bounds, 1); - RegionIntersect(&crtc_damage, &crtc_damage, region); - - /* update damaged region */ - if (RegionNotEmpty(&crtc_damage)) - xf86RotateCrtcRedisplay (crtc, &crtc_damage); - - RegionUninit(&crtc_damage); - } - } - pScreen->SourceValidate = SourceValidate; - DamageEmpty(damage); - } - return TRUE; -} - -static void -xf86RotateBlockHandler(int screenNum, pointer blockData, - pointer pTimeout, pointer pReadmask) -{ - ScreenPtr pScreen = screenInfo.screens[screenNum]; - ScrnInfoPtr pScrn = xf86Screens[screenNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - Bool rotation_active; - - rotation_active = xf86RotateRedisplay(pScreen); - pScreen->BlockHandler = xf86_config->BlockHandler; - (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask); - /* cannot avoid re-wrapping until all wrapping is audited */ - xf86_config->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = xf86RotateBlockHandler; -} - -void -xf86RotateDestroy (xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - ScreenPtr pScreen = pScrn->pScreen; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - /* Free memory from rotation */ - if (crtc->rotatedPixmap || crtc->rotatedData) - { - crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - - for (c = 0; c < xf86_config->num_crtc; c++) - if (xf86_config->crtc[c]->transform_in_use) - return; - - /* - * Clean up damage structures when no crtcs are rotated - */ - if (xf86_config->rotation_damage) - { - /* Free damage structure */ - if (xf86_config->rotation_damage_registered) - { - DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, - xf86_config->rotation_damage); - xf86_config->rotation_damage_registered = FALSE; - DisableLimitedSchedulingLatency(); - } - DamageDestroy (xf86_config->rotation_damage); - xf86_config->rotation_damage = NULL; - } -} - -void -xf86RotateFreeShadow(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - if (crtc->rotatedPixmap || crtc->rotatedData) { - crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, - crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - } -} - -void -xf86RotateCloseScreen (ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86Screens[screen->myNum]; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) - xf86RotateDestroy (xf86_config->crtc[c]); -} - -static Bool -xf86CrtcFitsScreen (xf86CrtcPtr crtc, struct pict_f_transform *crtc_to_fb) -{ - ScrnInfoPtr pScrn = crtc->scrn; - BoxRec b; - - /* When called before PreInit, the driver is - * presumably doing load detect - */ - if (pScrn->virtualX == 0 || pScrn->virtualY == 0) - return TRUE; - - b.x1 = 0; - b.y1 = 0; - b.x2 = crtc->mode.HDisplay; - b.y2 = crtc->mode.VDisplay; - if (crtc_to_fb) - pixman_f_transform_bounds (crtc_to_fb, &b); - else { - b.x1 += crtc->x; - b.y1 += crtc->y; - b.x2 += crtc->x; - b.y2 += crtc->y; - } - - return (0 <= b.x1 && b.x2 <= pScrn->virtualX && - 0 <= b.y1 && b.y2 <= pScrn->virtualY); -} - -Bool -xf86CrtcRotate (xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */ - ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex]; - PictTransform crtc_to_fb; - struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc; - xFixed *new_params = NULL; - int new_nparams = 0; - PictFilterPtr new_filter = NULL; - int new_width = 0; - int new_height = 0; - RRTransformPtr transform = NULL; - Bool damage = FALSE; - - if (crtc->transformPresent) - transform = &crtc->transform; - - if (!RRTransformCompute (crtc->x, crtc->y, - crtc->mode.HDisplay, crtc->mode.VDisplay, - crtc->rotation, - transform, - - &crtc_to_fb, - &f_crtc_to_fb, - &f_fb_to_crtc) && - xf86CrtcFitsScreen (crtc, &f_crtc_to_fb)) - { - /* - * If the untranslated transformation is the identity, - * disable the shadow buffer - */ - xf86RotateDestroy (crtc); - crtc->transform_in_use = FALSE; - free(new_params); - new_params = NULL; - new_nparams = 0; - new_filter = NULL; - new_width = 0; - new_height = 0; - } - else - { - /* - * these are the size of the shadow pixmap, which - * matches the mode, not the pre-rotated copy in the - * frame buffer - */ - int width = crtc->mode.HDisplay; - int height = crtc->mode.VDisplay; - void *shadowData = crtc->rotatedData; - PixmapPtr shadow = crtc->rotatedPixmap; - int old_width = shadow ? shadow->drawable.width : 0; - int old_height = shadow ? shadow->drawable.height : 0; - - /* Allocate memory for rotation */ - if (old_width != width || old_height != height) - { - if (shadow || shadowData) - { - crtc->funcs->shadow_destroy (crtc, shadow, shadowData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - shadowData = crtc->funcs->shadow_allocate (crtc, width, height); - if (!shadowData) - goto bail1; - crtc->rotatedData = shadowData; - /* shadow will be damaged in xf86RotatePrepare */ - } - else - { - /* mark shadowed area as damaged so it will be repainted */ - damage = TRUE; - } - - if (!xf86_config->rotation_damage) - { - /* Create damage structure */ - xf86_config->rotation_damage = DamageCreate (NULL, NULL, - DamageReportNone, - TRUE, pScreen, pScreen); - if (!xf86_config->rotation_damage) - goto bail2; - - /* Wrap block handler */ - if (!xf86_config->BlockHandler) { - xf86_config->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = xf86RotateBlockHandler; - } - } -#ifdef RANDR_12_INTERFACE - if (transform) - { - if (transform->nparams) { - new_params = malloc(transform->nparams * sizeof (xFixed)); - if (new_params) { - memcpy (new_params, transform->params, - transform->nparams * sizeof (xFixed)); - new_nparams = transform->nparams; - new_filter = transform->filter; - } - } else - new_filter = transform->filter; - if (new_filter) - { - new_width = new_filter->width; - new_height = new_filter->height; - } - } -#endif - - if (0) - { - bail2: - if (shadow || shadowData) - { - crtc->funcs->shadow_destroy (crtc, shadow, shadowData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - bail1: - if (old_width && old_height) - crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc, - NULL, - old_width, - old_height); - return FALSE; - } - crtc->transform_in_use = TRUE; - } - crtc->crtc_to_framebuffer = crtc_to_fb; - crtc->f_crtc_to_framebuffer = f_crtc_to_fb; - crtc->f_framebuffer_to_crtc = f_fb_to_crtc; - free(crtc->params); - crtc->params = new_params; - crtc->nparams = new_nparams; - crtc->filter = new_filter; - crtc->filter_width = new_width; - crtc->filter_height = new_height; - crtc->bounds.x1 = 0; - crtc->bounds.x2 = crtc->mode.HDisplay; - crtc->bounds.y1 = 0; - crtc->bounds.y2 = crtc->mode.VDisplay; - pixman_f_transform_bounds (&f_crtc_to_fb, &crtc->bounds); - - if (damage) - xf86CrtcDamageShadow (crtc); - - /* All done */ - return TRUE; -} +/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_XORG_CONFIG_H
+#include <xorg-config.h>
+#else
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#endif
+
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "xf86.h"
+#include "xf86DDC.h"
+#include "fb.h"
+#include "windowstr.h"
+#include "xf86Crtc.h"
+#include "xf86Modes.h"
+#include "xf86RandR12.h"
+#include "X11/extensions/render.h"
+#include "X11/extensions/dpmsconst.h"
+#include "X11/Xatom.h"
+
+/* borrowed from composite extension, move to Render and publish? */
+
+static VisualPtr
+compGetWindowVisual (WindowPtr pWin)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ VisualID vid = wVisual (pWin);
+ int i;
+
+ for (i = 0; i < pScreen->numVisuals; i++)
+ if (pScreen->visuals[i].vid == vid)
+ return &pScreen->visuals[i];
+ return 0;
+}
+
+static PictFormatPtr
+compWindowFormat (WindowPtr pWin)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+
+ return PictureMatchVisual (pScreen, pWin->drawable.depth,
+ compGetWindowVisual (pWin));
+}
+
+#define F(x) IntToxFixed(x)
+
+#define toF(x) ((float) (x) / 65536.0f)
+
+static void
+xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region)
+{
+ ScrnInfoPtr scrn = crtc->scrn;
+ ScreenPtr screen = scrn->pScreen;
+ WindowPtr root = screen->root;
+ PixmapPtr dst_pixmap = crtc->rotatedPixmap;
+ PictFormatPtr format = compWindowFormat (screen->root);
+ int error;
+ PicturePtr src, dst;
+ int n = RegionNumRects(region);
+ BoxPtr b = RegionRects(region);
+ XID include_inferiors = IncludeInferiors;
+
+ src = CreatePicture (None,
+ &root->drawable,
+ format,
+ CPSubwindowMode,
+ &include_inferiors,
+ serverClient,
+ &error);
+ if (!src)
+ return;
+
+ dst = CreatePicture (None,
+ &dst_pixmap->drawable,
+ format,
+ 0L,
+ NULL,
+ serverClient,
+ &error);
+ if (!dst)
+ return;
+
+ error = SetPictureTransform (src, &crtc->crtc_to_framebuffer);
+ if (error)
+ return;
+ if (crtc->transform_in_use && crtc->filter)
+ SetPicturePictFilter (src, crtc->filter,
+ crtc->params, crtc->nparams);
+
+ if (crtc->shadowClear)
+ {
+ CompositePicture (PictOpSrc,
+ src, NULL, dst,
+ 0, 0, 0, 0, 0, 0,
+ crtc->mode.HDisplay, crtc->mode.VDisplay);
+ crtc->shadowClear = FALSE;
+ }
+ else
+ {
+ while (n--)
+ {
+ BoxRec dst_box;
+
+ dst_box = *b;
+ dst_box.x1 -= crtc->filter_width >> 1;
+ dst_box.x2 += crtc->filter_width >> 1;
+ dst_box.y1 -= crtc->filter_height >> 1;
+ dst_box.y2 += crtc->filter_height >> 1;
+ pixman_f_transform_bounds (&crtc->f_framebuffer_to_crtc, &dst_box);
+ CompositePicture (PictOpSrc,
+ src, NULL, dst,
+ dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, dst_box.y1,
+ dst_box.x2 - dst_box.x1,
+ dst_box.y2 - dst_box.y1);
+ b++;
+ }
+ }
+ FreePicture (src, None);
+ FreePicture (dst, None);
+}
+
+static void
+xf86CrtcDamageShadow (xf86CrtcPtr crtc)
+{
+ ScrnInfoPtr pScrn = crtc->scrn;
+ BoxRec damage_box;
+ RegionRec damage_region;
+ ScreenPtr pScreen = pScrn->pScreen;
+
+ damage_box.x1 = 0;
+ damage_box.x2 = crtc->mode.HDisplay;
+ damage_box.y1 = 0;
+ damage_box.y2 = crtc->mode.VDisplay;
+ if (!pixman_transform_bounds (&crtc->crtc_to_framebuffer, &damage_box))
+ {
+ damage_box.x1 = 0;
+ damage_box.y1 = 0;
+ damage_box.x2 = pScreen->width;
+ damage_box.y2 = pScreen->height;
+ }
+ if (damage_box.x1 < 0) damage_box.x1 = 0;
+ if (damage_box.y1 < 0) damage_box.y1 = 0;
+ if (damage_box.x2 > pScreen->width) damage_box.x2 = pScreen->width;
+ if (damage_box.y2 > pScreen->height) damage_box.y2 = pScreen->height;
+ RegionInit(&damage_region, &damage_box, 1);
+ DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+ &damage_region);
+ RegionUninit(&damage_region);
+ crtc->shadowClear = TRUE;
+}
+
+static void
+xf86RotatePrepare (ScreenPtr pScreen)
+{
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+ int c;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->rotatedData && !crtc->rotatedPixmap)
+ {
+ crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
+ crtc->rotatedData,
+ crtc->mode.HDisplay,
+ crtc->mode.VDisplay);
+ if (!xf86_config->rotation_damage_registered)
+ {
+ /* Hook damage to screen pixmap */
+ DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+ xf86_config->rotation_damage);
+ xf86_config->rotation_damage_registered = TRUE;
+ EnableLimitedSchedulingLatency();
+ }
+
+ xf86CrtcDamageShadow (crtc);
+ }
+ }
+}
+
+static Bool
+xf86RotateRedisplay(ScreenPtr pScreen)
+{
+ ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+ DamagePtr damage = xf86_config->rotation_damage;
+ RegionPtr region;
+
+ if (!damage)
+ return FALSE;
+ xf86RotatePrepare (pScreen);
+ region = DamageRegion(damage);
+ if (RegionNotEmpty(region))
+ {
+ int c;
+ SourceValidateProcPtr SourceValidate;
+
+ /*
+ * SourceValidate is used by the software cursor code
+ * to pull the cursor off of the screen when reading
+ * bits from the frame buffer. Bypassing this function
+ * leaves the software cursor in place
+ */
+ SourceValidate = pScreen->SourceValidate;
+ pScreen->SourceValidate = NULL;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ {
+ xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+ if (crtc->transform_in_use && crtc->enabled)
+ {
+ RegionRec crtc_damage;
+
+ /* compute portion of damage that overlaps crtc */
+ RegionInit(&crtc_damage, &crtc->bounds, 1);
+ RegionIntersect(&crtc_damage, &crtc_damage, region);
+
+ /* update damaged region */
+ if (RegionNotEmpty(&crtc_damage))
+ xf86RotateCrtcRedisplay (crtc, &crtc_damage);
+
+ RegionUninit(&crtc_damage);
+ }
+ }
+ pScreen->SourceValidate = SourceValidate;
+ DamageEmpty(damage);
+ }
+ return TRUE;
+}
+
+static void
+xf86RotateBlockHandler(int screenNum, pointer blockData,
+ pointer pTimeout, pointer pReadmask)
+{
+ ScreenPtr pScreen = screenInfo.screens[screenNum];
+ ScrnInfoPtr pScrn = xf86Screens[screenNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+ Bool rotation_active;
+
+ rotation_active = xf86RotateRedisplay(pScreen);
+ pScreen->BlockHandler = xf86_config->BlockHandler;
+ (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask);
+ /* cannot avoid re-wrapping until all wrapping is audited */
+ xf86_config->BlockHandler = pScreen->BlockHandler;
+ pScreen->BlockHandler = xf86RotateBlockHandler;
+}
+
+void
+xf86RotateDestroy (xf86CrtcPtr crtc)
+{
+ ScrnInfoPtr pScrn = crtc->scrn;
+ ScreenPtr pScreen = pScrn->pScreen;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+ int c;
+
+ /* Free memory from rotation */
+ if (crtc->rotatedPixmap || crtc->rotatedData)
+ {
+ crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData);
+ crtc->rotatedPixmap = NULL;
+ crtc->rotatedData = NULL;
+ }
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ if (xf86_config->crtc[c]->transform_in_use)
+ return;
+
+ /*
+ * Clean up damage structures when no crtcs are rotated
+ */
+ if (xf86_config->rotation_damage)
+ {
+ /* Free damage structure */
+ if (xf86_config->rotation_damage_registered)
+ {
+ DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable,
+ xf86_config->rotation_damage);
+ xf86_config->rotation_damage_registered = FALSE;
+ DisableLimitedSchedulingLatency();
+ }
+ DamageDestroy (xf86_config->rotation_damage);
+ xf86_config->rotation_damage = NULL;
+ }
+}
+
+void
+xf86RotateFreeShadow(ScrnInfoPtr pScrn)
+{
+ xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+ int c;
+
+ for (c = 0; c < config->num_crtc; c++) {
+ xf86CrtcPtr crtc = config->crtc[c];
+
+ if (crtc->rotatedPixmap || crtc->rotatedData) {
+ crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+ crtc->rotatedData);
+ crtc->rotatedPixmap = NULL;
+ crtc->rotatedData = NULL;
+ }
+ }
+}
+
+void
+xf86RotateCloseScreen (ScreenPtr screen)
+{
+ ScrnInfoPtr scrn = xf86Screens[screen->myNum];
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+ int c;
+
+ for (c = 0; c < xf86_config->num_crtc; c++)
+ xf86RotateDestroy (xf86_config->crtc[c]);
+}
+
+static Bool
+xf86CrtcFitsScreen (xf86CrtcPtr crtc, struct pict_f_transform *crtc_to_fb)
+{
+ ScrnInfoPtr pScrn = crtc->scrn;
+ BoxRec b;
+
+ /* When called before PreInit, the driver is
+ * presumably doing load detect
+ */
+ if (pScrn->virtualX == 0 || pScrn->virtualY == 0)
+ return TRUE;
+
+ b.x1 = 0;
+ b.y1 = 0;
+ b.x2 = crtc->mode.HDisplay;
+ b.y2 = crtc->mode.VDisplay;
+ if (crtc_to_fb)
+ pixman_f_transform_bounds (crtc_to_fb, &b);
+ else {
+ b.x1 += crtc->x;
+ b.y1 += crtc->y;
+ b.x2 += crtc->x;
+ b.y2 += crtc->y;
+ }
+
+ return (0 <= b.x1 && b.x2 <= pScrn->virtualX &&
+ 0 <= b.y1 && b.y2 <= pScrn->virtualY);
+}
+
+Bool
+xf86CrtcRotate (xf86CrtcPtr crtc)
+{
+ ScrnInfoPtr pScrn = crtc->scrn;
+ xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+ /* if this is called during ScreenInit() we don't have pScrn->pScreen yet */
+ ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex];
+ PictTransform crtc_to_fb;
+ struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc;
+ xFixed *new_params = NULL;
+ int new_nparams = 0;
+ PictFilterPtr new_filter = NULL;
+ int new_width = 0;
+ int new_height = 0;
+ RRTransformPtr transform = NULL;
+ Bool damage = FALSE;
+
+ if (crtc->transformPresent)
+ transform = &crtc->transform;
+
+ if (!RRTransformCompute (crtc->x, crtc->y,
+ crtc->mode.HDisplay, crtc->mode.VDisplay,
+ crtc->rotation,
+ transform,
+
+ &crtc_to_fb,
+ &f_crtc_to_fb,
+ &f_fb_to_crtc) &&
+ xf86CrtcFitsScreen (crtc, &f_crtc_to_fb))
+ {
+ /*
+ * If the untranslated transformation is the identity,
+ * disable the shadow buffer
+ */
+ xf86RotateDestroy (crtc);
+ crtc->transform_in_use = FALSE;
+ free(new_params);
+ new_params = NULL;
+ new_nparams = 0;
+ new_filter = NULL;
+ new_width = 0;
+ new_height = 0;
+ }
+ else
+ {
+ /*
+ * these are the size of the shadow pixmap, which
+ * matches the mode, not the pre-rotated copy in the
+ * frame buffer
+ */
+ int width = crtc->mode.HDisplay;
+ int height = crtc->mode.VDisplay;
+ void *shadowData = crtc->rotatedData;
+ PixmapPtr shadow = crtc->rotatedPixmap;
+ int old_width = shadow ? shadow->drawable.width : 0;
+ int old_height = shadow ? shadow->drawable.height : 0;
+
+ /* Allocate memory for rotation */
+ if (old_width != width || old_height != height)
+ {
+ if (shadow || shadowData)
+ {
+ crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
+ crtc->rotatedPixmap = NULL;
+ crtc->rotatedData = NULL;
+ }
+ shadowData = crtc->funcs->shadow_allocate (crtc, width, height);
+ if (!shadowData)
+ goto bail1;
+ crtc->rotatedData = shadowData;
+ /* shadow will be damaged in xf86RotatePrepare */
+ }
+ else
+ {
+ /* mark shadowed area as damaged so it will be repainted */
+ damage = TRUE;
+ }
+
+ if (!xf86_config->rotation_damage)
+ {
+ /* Create damage structure */
+ xf86_config->rotation_damage = DamageCreate (NULL, NULL,
+ DamageReportNone,
+ TRUE, pScreen, pScreen);
+ if (!xf86_config->rotation_damage)
+ goto bail2;
+
+ /* Wrap block handler */
+ if (!xf86_config->BlockHandler) {
+ xf86_config->BlockHandler = pScreen->BlockHandler;
+ pScreen->BlockHandler = xf86RotateBlockHandler;
+ }
+ }
+#ifdef RANDR_12_INTERFACE
+ if (transform)
+ {
+ if (transform->nparams) {
+ new_params = malloc(transform->nparams * sizeof (xFixed));
+ if (new_params) {
+ memcpy (new_params, transform->params,
+ transform->nparams * sizeof (xFixed));
+ new_nparams = transform->nparams;
+ new_filter = transform->filter;
+ }
+ } else
+ new_filter = transform->filter;
+ if (new_filter)
+ {
+ new_width = new_filter->width;
+ new_height = new_filter->height;
+ }
+ }
+#endif
+
+ if (0)
+ {
+ bail2:
+ if (shadow || shadowData)
+ {
+ crtc->funcs->shadow_destroy (crtc, shadow, shadowData);
+ crtc->rotatedPixmap = NULL;
+ crtc->rotatedData = NULL;
+ }
+ bail1:
+ if (old_width && old_height)
+ crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc,
+ NULL,
+ old_width,
+ old_height);
+ return FALSE;
+ }
+ crtc->transform_in_use = TRUE;
+ }
+ crtc->crtc_to_framebuffer = crtc_to_fb;
+ crtc->f_crtc_to_framebuffer = f_crtc_to_fb;
+ crtc->f_framebuffer_to_crtc = f_fb_to_crtc;
+ free(crtc->params);
+ crtc->params = new_params;
+ crtc->nparams = new_nparams;
+ crtc->filter = new_filter;
+ crtc->filter_width = new_width;
+ crtc->filter_height = new_height;
+ crtc->bounds.x1 = 0;
+ crtc->bounds.x2 = crtc->mode.HDisplay;
+ crtc->bounds.y1 = 0;
+ crtc->bounds.y2 = crtc->mode.VDisplay;
+ pixman_f_transform_bounds (&f_crtc_to_fb, &crtc->bounds);
+
+ if (damage)
+ xf86CrtcDamageShadow (crtc);
+
+ /* All done */
+ return TRUE;
+}
|