Window server applications exist mainly to draw graphics to the screen. They may draw to any RDrawableWindow
— either an RWindow
or an RBackedUpWindow
— via a graphics device, of type CWsScreenDevice
, and a graphics context, of type CWindowGc
. These classes are derived from the CGraphicsDevice
and CGraphicsContext
classes defined by the GDI, so that general drawing functions may be used for drawing to windows, as well as to other graphics
devices. The window server itself does not provide the facilities to draw graphics to a physical device. CWindowGc
functions are not passed to the window server directly. Rather, they are stored in a buffer maintained by the Window Server
Client API. This buffer is flushed to the window server only rarely. By this means the context switching involved in drawing
is minimised, and system performance significantly enhanced.
CWsScreenDevice
encapsulates the device-dependent aspects of graphics operations. Graphics functions are not carried out directly via a CWsScreenDevice
, however, but via a graphics context with which it is associated. The graphics context class, CWindowGC
, provides a rich set of drawing functions, including functions to draw lines, arcs, polygons, text and bitmaps, etc.
A graphics context contains a collection of configurable parameters concerned with graphics, such as pen width, pen colour, brush colour, etc. It is stored in the server, thus reducing the amount of information that has to be sent with each graphics call: the graphics call simply specifies the graphics context it wishes to use, and a single graphics context can be shared between multiple windows.
To draw to a graphics context it must be associated with a window. Typically a graphics context is created when a session
is constructed, and that graphics context is shared between several windows in the application. When the window needs to use
the graphics context it calls CWindowGc::Activate()
. If necessary it can change the graphics context's settings. CWindowGc::Deactivate()
should be called if the graphics context is currently active upon a
window.
Several optimisations are used by the window server to obtain high-performance graphics
each window is associated with an RWsSession
which is in turn associated with a client-side buffer. Instead of implementing graphics operations by a direct client-server
call, which involves expensive context switching, all graphics operations are stored as opcodes in the buffer, and the buffer
is only flushed in certain circumstances
the CFbsBitmap
class allows a bitmap to be shared between all threads in the system, including the client and the window server. This sharing
is mediated by the font and bitmap server. The CWsBitmap
class eliminates further context switches by taking ownership of the handle of the bitmap. Applications may use this class
to more efficiently open, blit-to-screen, and close a series of bitmaps
CWsBitmap
s may also be used to allow applications to use the bitmapped graphics (BITGDI) in their own thread — through a CFbsBitGc
— to construct an image, and then efficiently blit it onto the screen using CWindowGc::DrawBitmap()
. This allows fast animation and flicker-free update
a single graphics context may be used for drawing to many windows — it is not necessary to have one per window. The Activate()
function associates a CWindowGc
with a particular window