[PATCH] input: Precalculate screen dimensions instead of at each event.
Peter Hutterer
peter.hutterer at who-t.net
Tue Sep 6 18:12:41 PDT 2011
Store the desktop dimensions in screenInfo instead of re-calculating them on
each input event.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
This approach seems to work for Xdmx, Xnest and Xorg.
dix/dispatch.c | 2 ++
dix/getevents.c | 29 ++++-------------------------
dix/inpututils.c | 19 +++++++++++++++++++
hw/xfree86/common/xf86Cursor.c | 2 ++
hw/xfree86/common/xf86RandR.c | 3 +++
hw/xfree86/modes/xf86RandR12.c | 2 ++
include/input.h | 1 +
include/scrnintstr.h | 2 ++
8 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 192c8c3..a644c5c 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3911,6 +3911,8 @@ AddScreen(
return -1;
}
+ update_desktop_dimensions();
+
dixRegisterPrivateKey(&cursorScreenDevPriv[i], PRIVATE_CURSOR, 0);
return i;
diff --git a/dix/getevents.c b/dix/getevents.c
index f4b6dca..8fff11c 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -808,21 +808,6 @@ accelPointer(DeviceIntPtr dev, ValuatorMask* valuators, CARD32 ms)
dev->valuator->accelScheme.AccelSchemeProc(dev, valuators, ms);
}
-static void
-get_desktop_dimensions(int *width, int *height)
-{
- int i;
- int w = 0, h = 0;
- for (i = 0; i < screenInfo.numScreens; i++) {
- ScreenPtr screen = screenInfo.screens[i];
- w = max(w, screen->x + screen->width);
- h = max(h, screen->y + screen->height);
- }
-
- *width = w;
- *height = h;
-}
-
/**
* If we have HW cursors, this actually moves the visible sprite. If not, we
* just do all the screen crossing, etc.
@@ -852,14 +837,11 @@ positionSprite(DeviceIntPtr dev, int mode,
ScreenPtr scr, int *screenx, int *screeny, float *screenx_frac, float *screeny_frac)
{
int old_screenx, old_screeny;
- int w, h;
-
- get_desktop_dimensions(&w, &h);
/* scale x&y to whole desktop */
if (dev->valuator && dev->valuator->numAxes > 0) {
*screenx = rescaleValuatorAxis(*x, x_frac, screenx_frac,
- dev->valuator->axes + 0, NULL, w);
+ dev->valuator->axes + 0, NULL, screenInfo.width);
} else {
*screenx = dev->last.valuators[0];
*screenx_frac = dev->last.remainder[0];
@@ -867,7 +849,7 @@ positionSprite(DeviceIntPtr dev, int mode,
if (dev->valuator && dev->valuator->numAxes > 1) {
*screeny = rescaleValuatorAxis(*y, y_frac, screeny_frac,
- dev->valuator->axes + 1, NULL, h);
+ dev->valuator->axes + 1, NULL, screenInfo.height);
} else {
*screeny = dev->last.valuators[1];
*screeny_frac = dev->last.remainder[1];
@@ -1235,9 +1217,6 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
if (flags & POINTER_SCREEN)
{
int scaled;
- int w, h;
-
- get_desktop_dimensions(&w, &h);
if (valuator_mask_isset(&mask, 0))
{
@@ -1246,7 +1225,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
scaled = rescaleValuatorAxis(scaled,
0.0, &x_frac, NULL,
pDev->valuator->axes + 0,
- w);
+ screenInfo.width);
valuator_mask_set(&mask, 0, scaled);
}
if (valuator_mask_isset(&mask, 1))
@@ -1256,7 +1235,7 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, int buttons
scaled = rescaleValuatorAxis(scaled,
0.0, &y_frac, NULL,
pDev->valuator->axes + 1,
- h);
+ screenInfo.height);
valuator_mask_set(&mask, 1, scaled);
}
}
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 0cecc62..803e95e 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -592,3 +592,22 @@ point_on_screen(ScreenPtr pScreen, int x, int y)
return x >= pScreen->x && x < pScreen->x + pScreen->width &&
y >= pScreen->y && y < pScreen->y + pScreen->height;
}
+
+/**
+ * Update desktop dimensions on the screenInfo struct.
+ */
+void
+update_desktop_dimensions(void)
+{
+ int i;
+ int w = 0, h = 0;
+ for (i = 0; i < screenInfo.numScreens; i++) {
+ ScreenPtr screen = screenInfo.screens[i];
+ w = max(w, screen->x + screen->width);
+ h = max(h, screen->y + screen->height);
+ }
+
+ screenInfo.width = w;
+ screenInfo.height = h;
+}
+
diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 929f047..6f5d726 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -838,6 +838,8 @@ xf86InitOrigins(void)
FillOutEdge(pLayout->down, pScreen->width);
}
}
+
+ update_desktop_dimensions();
}
void
diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index 4663d03..d0e4784 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -313,6 +313,9 @@ xf86RandRSetConfig (ScreenPtr pScreen,
return FALSE;
}
+
+ update_desktop_dimensions();
+
/*
* Move the cursor back where it belongs; SwitchMode repositions it
* FIXME: duplicated code, see modes/xf86RandR12.c
diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c
index cb20d1c..d5031a2 100644
--- a/hw/xfree86/modes/xf86RandR12.c
+++ b/hw/xfree86/modes/xf86RandR12.c
@@ -736,6 +736,8 @@ xf86RandR12ScreenSetSize (ScreenPtr pScreen,
xf86SetViewport (pScreen, 0, 0);
finish:
+ update_desktop_dimensions();
+
if (pRoot && pScrn->vtSema)
(*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE);
#if RANDR_12_INTERFACE
diff --git a/include/input.h b/include/input.h
index 858d572..d57abab 100644
--- a/include/input.h
+++ b/include/input.h
@@ -596,5 +596,6 @@ extern _X_EXPORT void valuator_mask_copy(ValuatorMask *dest,
extern _X_EXPORT int valuator_mask_get(const ValuatorMask *mask, int valnum);
extern _X_HIDDEN Bool point_on_screen(ScreenPtr pScreen, int x, int y);
+extern _X_HIDDEN void update_desktop_dimensions(void);
#endif /* INPUT_H */
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index a9357e8..8ac48b7 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -561,6 +561,8 @@ typedef struct _ScreenInfo {
formats[MAXFORMATS];
int numScreens;
ScreenPtr screens[MAXSCREENS];
+ int width; /* total width of all screens together */
+ int height; /* total height of all screens together */
} ScreenInfo;
extern _X_EXPORT ScreenInfo screenInfo;
--
1.7.6
More information about the xorg-devel
mailing list