klayout icon indicating copy to clipboard operation
klayout copied to clipboard

What is the drawing mechanism and method of klayout?

Open libaineu2004 opened this issue 1 year ago • 8 comments

What is the drawing mechanism and method of klayout? I found that the software's drawing efficiency is very high, drawing tens of millions of lines is also very smooth, no delay. Is it drawn by the native qt (QGraphicsScene+QGraphicsView)? Are you using any third-party libraries or other optimization methods?

libaineu2004 avatar Nov 20 '23 03:11 libaineu2004

No, KLayout uses a custom renderer which is based on monochrome bitmaps that are combined into a RGB image separately. Drawing on a monochrome image is very fast as drawing small objects is a matter of setting a single bit.

In addition, KLayout has multiple levels of optimizations such as using the box tree and layer specific cell bounding box information for short-cutting the drawing process. It also uses a rendering cache for cells so that drawing the same cell multiple times is a matter of a bitmap copy.

klayoutmatthias avatar Nov 25 '23 15:11 klayoutmatthias

No, KLayout uses a custom renderer which is based on monochrome bitmaps that are combined into a RGB image separately. Drawing on a monochrome image is very fast as drawing small objects is a matter of setting a single bit.

In addition, KLayout has multiple levels of optimizations such as using the box tree and layer specific cell bounding box information for short-cutting the drawing process. It also uses a rendering cache for cells so that drawing the same cell multiple times is a matter of a bitmap copy.

Wow, you are amazing! What are the source files related to drawing?

libaineu2004 avatar Nov 27 '23 01:11 libaineu2004

There was a similar question a couple of month ago. https://github.com/KLayout/klayout/issues/1424 Do a debug build, use valgrind’s callgrind and visualize the results with [kq]cachegrind. I found this to be a very efficient way to look at other peoples open source code.

stefanottili avatar Nov 27 '23 01:11 stefanottili

how does monochrome bitmaps and antialiasing go together?

olisnr avatar Nov 29 '23 12:11 olisnr

@olisnr You mean oversampling? This feature simply draws on a 2 or 3 times larger bitmap and the downsamples the resulting RGB image.

Matthias

klayoutmatthias avatar Nov 29 '23 21:11 klayoutmatthias

that means You do very optimized 4 or 9 times larger bitmaps, merge it into RGB and then do a 2D lowpass over it? its a luck GPUs are already invented :)

olisnr avatar Nov 29 '23 22:11 olisnr

Well, basically yes. But it is a simple downscaling (pixel averaging) on a single RGB image. No lowpass involved and it does not require a GPU. I plain CPU is good enough.

Matthias

klayoutmatthias avatar Nov 30 '23 18:11 klayoutmatthias

it looks very nice and response fast with my layouts. KLayout is very nice.

olisnr avatar Dec 01 '23 12:12 olisnr