PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Stylus input wastes CPU cycles

It appears that stylus input requires a fair amount of CPU processing. In Varium (set to not process any mouse messages), I get the following benchmarks with my iPaq 3630 (not overclocked):

24 FPS: Stylus not touching screen
22 FPS: Stylus touching screen
21 FPS: Stylus in motion

I assume the OS is sucking up cycles generating tons of mouse messages. Any suggestions on reducing this problem, short of writing my own input drivers?

Dan East
Orpe · 26 Feb 2003, 17:39 UTC — Stylus input wastes CPU cycles
Dan East wrote:
In Varium (set to not process any mouse messages)


How has it been set to that?

If you haven't already, I'd suggest using the Remote Spy++ tool too try to see if anything strange seems to be going on with the window messages.

/Orpe
angedelamort · 26 Feb 2003, 17:41 UTC
That's really interesting. Never try to benchmark the stylus input :P

Here an idea instead of writing your own drivers :P
Not sure if it's possible, but maybe you can unactivate some windows messages. I know that on smartphone I was able to activate some key with SendMessage(). Here an example to activate the back key to be able to receive message from it.

Code:

(void)SendMessage
(
gWindow,
SHCMBM_OVERRIDEKEY,
VK_TBACK,
MAKELPARAM
(
SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY
)
);


So, maybe there a way of unactiving some unusefull stylus (mouse) messages.

I don't really have time now to check, but I'll have a closer look when it's possible.
Ran into a similar problem, although it wasn't just framerate. And it wasn't something I looked to the OS to fix, I think the screen has a very small grain so that any movement will set off many of the sensors. How small this actually is I have no idea, but its certainly a whole lot more than your basic touchscreen kiosk.
Anyway, since I was doing drags, every move message would potentially invalidate a part of my window and I got plain old lag with drag actions because of it.

This helped:
Code:

while(PeekMessage(&msg, hwnd, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
;


If you are using the mousemove then the above may help. Also if you aren't actually using drags you can build your own message loop and ignore them. Other things like turning it off are more OS centric and while it may be what you want I have no clue about that.

There are some other things you can do with some of the message functions. I have often needed a function to ignore certain messages completely, but I've yet to find this ability in Windows, although other window libraries I have used allow this, so I assume its possible. You could also try this with a separate thread, a filtering thread which may reduce the impact on your framerate.

HTH
It could be more hardware-related (i.e. the touch-screen is banging out interrupts to the processor at a high rate, asking to be serviced).
Dan East · 26 Feb 2003, 19:12 UTC — Stylus input wastes CPU cycles
Orpe":6fbpcsjv]


I didn't say I'm not receiving the messages. I am simply not processing them. Thus the drop in FPS is not due to any extra work Varium is performing. I don't know how much time is used in the message pump to look at those messages, but I presume more is by the OS to generate them.

I'm going to do a benchmark with the DEXplor task manager. I'll measure CPU times of all processes with a Varium run with and without the stylus touching the screen. If I see a spike in CPU usage by some other process then I'll know the driver or OS is the culprit.

Dan East
I do need stylus input, but I would like to improve the performance in that area.

Sm!rk, I do have my own message pump, and will try not translating and dispatching mouse messages to see if that helps.

Dan East
Kzinti · 26 Feb 2003, 19:26 UTC — Stylus input wastes CPU cycles
Dan East wrote:
It appears that stylus input requires a fair amount of CPU processing.

24 FPS: Stylus not touching screen
22 FPS: Stylus touching screen
21 FPS: Stylus in motion


I've experienced exactly the same problem on both my E-125 and Maestro. Altough I never had the time to investigate, I can confirm you that this is not only happening on one particular device.
Run Remote Spy++ and look at every message that is sent to your window when you perform the various operations with the stylus.

Now use PostMessage to send those same messages to your window in your game. Does it slow down by the same amount? If it does, then changing what messages get sent through your message pump might make a difference (i.e. filtering at PeekMessage time). If it doesn't slow down by the same amount, then the bottleneck is somewhere in the touchscreen driver or interrupt handling used to generate the messages.

I would look closely at those messages that get generated when a stylus moves around the screen. Make sure that no cursor messages or painting messages are being generated. Hopefully, you're handling all the painting messages (either eating them, or doing something smart) and have specified a null brush and null cursor for the window class. Also make sure you aren't specifying things like CS_DOUBLECLICKS in your window class if you can manage that capability yourself.
Maybe hook on the mouse message and then don't pass it on to anyone else? (In case all the other hooks are slowing it down?) ;)

Not sure if you can do that though... just a thought
Also, check the size and position of your main window. If this does not "cover" the screen it is possible that the OS GUI handling stuff gets confused and sends the messages around to other apps even though they are not visible because of fullscreen GAPI etc.
The only odd thing I note about the messages is that I get a WM_SETCURSOR for every WM_MOUSEMOVE.

However, when the stylus is stationary I don't recieve any messages (as expected), but the FPS still drops by 2. That leads me to believe the OS or touchscreen driver is the culprit.

Dan East
I'm getting the same thing here with my Ipaq 3800.

I don't exactly have a good way of measuring it right now, but my average frame time jumps almost 2ms if I'm moving the stylus (and ignoring the messages.) I'm hoping that some of that overhead is my fault.

Manually pumping WM_MOUSEMOVE is not producing an equivalent slowdown with a similar number of messages - so that may add ammo the to OS/Driver slowdown hypothesis.
Just tested it on my Axim 300 with the new game I'm developing, which doesn't use the stylus.

No Stylus: 37-38 FPS
Stylus: 35 FPS
Stylus Moving: 33-34 FPS
Some more data, I didn't see any change in my game using GapiDraw until I opened up the framerate to above 80 fps. Once I did that I saw a sharp decrease to about 76fps, and I then moving the stylus faster saw more of a decrease, to ~73fps, after some more of this I got it down to 67fps (a silly programmer game;) ). When I just held the stylus down I was at 80fps. It does seem to be just touchscreen related.

I see none of this when building on the PC, same code with GapiDraw stays at 99 fps and doesn't change at all, even when my mousemove code is actually running.

In addition I tried SetCapture to avoid the WM_SETCURSOR message but it didn't work, maybe someone else will have some luck here. I also tried to isolate the click from the mousemove, but no matter what I tried I could not get a click without a mousemove, so that thing is very sensitive, or something else...

This was on a ipaq3955. I got the same effect on an NEC p300, only the numbers differ.
I'm sure your computer can handle the few errant mouse commands while maintain a constant 99fps in a PocketPC game.
I used to write driver for touch panel and I would like to share my experience on touch panel.

The following is its mechanism.

1. When the touch panel (TP) is tounched, an interrupt is generated. Disable the interrupt for YP, but it depends on hardware design. If the interrupt is generated by falling/raising edge, it may be not neccessary. If it is generated by low/high, we need to disable the interrupt.

2. The driver has to control the IO to provide a voltage across the Y (can be X if step 3 is Y)panel and start the AD to measure the voltage. It will need to wait for sometime because the mechanism of AD. It is used for get Y coordinate.

3. The driver has to control the IO to provide a voltage across the X (can be Y if step 2 is X) panel and start the AD to measure the voltage. Again,it will need to wait for sometime because the mechanism of AD.It is used for get X coordinate.

4. The step 2 and 3 may be repeated a couple times for taking average. (It is because hardware may not be reliable.)

5. Set the I/O to check if the TP is pressed.

6. If the TP is pressed, the driver has to wait a default period and repeat checking again to generate PEN_MOVE message.

7. If the TP is released, set the interrupt works again.

Factors which eats CPU cycles.

1. If timer is avialable in step 2 and 3, it will save your CPU cycle because the driver designer may use interrupt for checking the reading of AD.

2. If the speed of AD is fast, the driver don't need to spend much time on getting reading.

3. Some driver designer, however, simple use polling to checking the reading. Then your CPU cycle will be wasted.

4. If the TP is pressed, the frequency of checking it by driver is also important.
Correction. It should apply voltage across Y panel to get x coordinate and apply voltage across X panel to get y coordinate.
So if I understand correctly, this is working in a similar way to analog joysticks. In that case, the slow down is easily explained and there isn't much we can do about it.

Thanks for the info Jojo.