2

One of the things that I've noticed (at least on Windows anyway), is that the mouse cursor is drawn with much less latency than even standard Windows elements.

A good example of this would be to start dragging on the desktop. You can easily notice that the drag rectangle is lagging significantly behind the cursor.

My first question is: why is this the case?

I can't imagine drawing a rectangle being so much more expensive than drawing the cursor. Certainly not by a frame or two.

And my second question is, would it ever be possible to match one's application rendering 1:1 with cursor input?

A good use case for this would be either this selection rectangle, or drag previews for draggable items. Both of which lag behind quite significantly from the OS mouse pointer (independent of any framework or library used).

Riho
  • 43
  • 6
  • 1
    [What is hardware cursor and how does it work?](https://stackoverflow.com/q/6957039/7571258) – zett42 Feb 16 '18 at 19:29

1 Answers1

3

Selecting icons on the desktop with the selection rectangle is not that slow on my system (DWM on), it is lagging a little bit but not enough for me to really care.

The "Show Window Contents while Dragging" option has always been rather slow which is why it was not on by default in older Windows versions.

The mouse cursor on the other hand can be rendered directly by your hardware. That is, Windows sends the cursor image to your graphics card and after that Windows only has to tell the graphics card the cursor position and this is much faster than all the messages and user/kernel context switches involved when you resize and paint a window. The mouse driver probably uses hardware interrupts/timers with a higher priority than your normal software as well.

You can try to disable hardware cursors with a registry hack but the HID/mouse driver and the raw input thread in win32k will still have a higher priority than your application.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • 1
    Also, windows are not drawn directly onto the screen buffer, but first onto a backbuffer which is only copied to the screen after a delay of 1/MonitorRefreshRate (this is also called a swap chain). In contrast, the mouse cursor is immediately drawn as an overlay by the graphics card. So this 1/MonitorRefreshRate lag will always be there even if the overhead of Windows messages and so on would be neglible. – zett42 Feb 16 '18 at 19:54