Skip to content

Some explanations of how xschem handles selection and redrawing of objects.

StefanSchippers edited this page Sep 26, 2023 · 1 revision

The main problem is that if you select some objects xschem draws them in grey. When unselecting the grey areas must be restored. There are many approaches to do this.

  1. redraw the whole screen when user unselects objects. This very inefficient, expecially is user selects only a small amount of the whole circuit.
  2. Redraw only the screen rectangle that contains the selection. This is better, than 1. however if user selects one object in the lower right corner and one in the upper left corner you are back in the same situation of point 1.
  3. Redraw many screen rectangles each containing one selected object.
  4. Redraw only the selected objects using an offscreen save buffer as the fill pattern. This requires redrawing only the selected objects instead of entire portions of the screen. This is the approach used by xschem and explained below.

Xschem uses a double buffering technique. Drawing is done in an offscreen pixmap (think of it as a canvas that is not displayed in any window, it sits just in main /GPU memory) Image below shows the situation. xschem window with some objects selected (left) and a representation of the offscreen pixmap (right). when image in the pixmap is finished it is copied in the main window. If the main window gets obscured and then brought back to front xschem restores the content by copying the pixmap (or a portion) to it

1

Now, if user clicks an empty area in the window, objects get unselected, xschem redraws the grey objects using the pixmap on the right as the color for every pixel. This way xschem only needs to draw 4 rectangles, one circle and 3 lines and the image is restored. Note that if there are overlapping objects (as in the example image) you can not redraw the objects with their normal color, as this will erase parts of the overlapped objects.

This technique of using a secondary pixmap as the fill pattern is standard in X11, and for vector graphics it is often more efficient than blitting a big rectangular area, expecially on UHD graphics. If you have a 1920x1080 fullscreen xschem window and select a diagonal line from (0,0) to (1919, 1079) when unselecting xschem redraws just one line with each pixel colored using the corresponding pixel color in the save pixmap. Game over.

Restoring by bit blitting requires to draw the whole screen (blit areas must be rectangular) so some MB of memory must be moved either in the GPU or in main RAM. In either case drawing a ~2200 pixel line using the secondary pixmap as the "pen" is often faster than copying ~8MB of video memory (in 32 bit /pixel a full HD screen requires ~ 8MB) even with accelerated GPUs.

The problem with some modern video cards is that the drawing operations using pixmap as draw/fill patterns are often not implemented correctly. Modern programmers no more do care about efficiency, they have more powerful hardware and use brute force.

As another example, when you select objects and press the 'm' (move) key, every time you move the mouse xschem does:

  1. draw the selected objects using the secondary pixmap as fill/color for every grey pixel shown. This will clear the selection and restore the drawing (in the example the black background and the grey grid points are restored).
  2. move the objects according to the mouse position
  3. draw the grey selection to screen again.

the save pixmap is not changed and contains the xschem drawing. The pixmap is regenerated when the move operation is finished by the user. It will be used to restore window in following operations.

1

What I plan to do is to use the above option 3. as an alternate drawing method. This will however take some time.