KiCad Graphics Abstraction Layer
Description
Introduction of the Graphics Abstraction Layer has the 3 main purposes:
- decouple drawing from editing tools
- allow to change a backend depending on the necessity
- speed up of rendering process
Currently the burden of managing redraws in KiCad falls on editing
tools. For example, while routing a track, the tool code must take care
of erasing the old trace, painting over the new one and making sure that
there will be no rubbish on the screen when the view is panned or
zoomed. This may introduce some difficulties in bug fixing or creating
new code, as the developer has to think of drawing routines instead of
focusing on the tool functionality.
Splitting drawing functionality into a few abstraction layers has a few
advantages. One class (PAINTER) takes the responsibility for drawing
items using a basic command set. For example, to draw a via you need to
draw two circles: first makes for a via itself and second represents its
hole. The PAINTER gets information about an item (like diameters of via
& its hole) and uses the backend (the GAL class and its derivatives) to
draw it. That means that you can use any library to do the drawing tasks
and the result should always look exactly the same.
This kind of a division of tasks makes it easy to add new rendering
backends. Right now, there is a plan to use two types of backends. The
Cairo backend is going to be used for drawing vector graphics, which is
very useful in creating documents, but at the cost of performance. In
that case usually it does not matter if it takes a few milliseconds or a
few seconds to prepare a document. The second backend is going to be
based on OpenGL. Its main purpose is to boost the rendering speed, so
even quite complex board can be rendered without a performance drop. It
can take an advantage of commonly available modern graphic cards, in
opposite to the default KiCad software rendering engine relying only on
CPU speed.
Another change introduced by the GAL engine is a different method of
drawing layers. Previously it was done by simply XORing colors of items,
which is fast but does not look very natural. Modern CAD programs use
blending and semitransparent layers for multilayer display. The
difference you may see on pictures below (click to zoom; the left
picture is the default KiCad rendering, the right one shows the OpenGL
GAL rendering
backend):
What is done?*
- the View component is integrated in the pcbnew with a non-editable view
- the backends are switchable during the runtime, using menu or hot keys
- 2 functional rendering backends are available: Cairo and OpenGL with shaders
- blending of semitransparent layers using OpenGL backend
- dynamic drawing of netnames on pads & tracks depending on the zoom
- toggling displayed layers
- control of zoom & grid settings using the default user interface
- switching display modes for zones
What has to be done?*
- high contrast & outline modes needs some fixing
- obeying the display settings for showing netnames (on tracks & pads)
- allow users to select own layer transparency, drawing order
- editable view requires implementation of the tool framework
Preview version
There is a demo version of KiCad non-editable View component (also known
as KiCad GAL), which is available to browse & download at
https://code.launchpad.net/~cern-kicad/kicad/kicad-gal.
It is a good idea to use the most complex board available to test it out
and see the performance difference. If you want, you may try it out with
a 12 copper layers
PCB
(please do not pay attention to the wrongly placed labels, the plugin we
used to import the board is incomplete).
You may switch the backends anytime, using the View menu or hot keys
Alt+F9 (standard KiCad rendering), Alt+F11 (OpenGL with shaders) and
Alt+F12 (Cairo).
Linux
The build instructions in Linux environment are pretty the same as in
the KiCad master branch:
bzr branch lp:~cern-kicad/kicad/kicad-gal mkdir build cd build cmake -DKICAD_TESTING_VERSION=ON -DCMAKE_BUILD_TYPE=RELEASE .. make
In the case you want to try out the newest version under Ubuntu and skip the build steps you may use the PPA prepared by Adam Wolf.
Windows
If you would like to cross compile KiCad GAL branch for Windows, you may find useful these instructions.