03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Default settings are assured here: the original call to ActivateGc()set default settings for<br />

the window-owning control that was drawn first; later calls to ResetGc() ensure that<br />

components are drawn with default settings also.<br />

The loop above doesn't need to draw window-owning components of the window-owning<br />

control that received the original redraw request. This is because the window server will<br />

send a redraw message to such controls in any case, in due time.<br />

You can see again here how lodger components promote system efficiency. For each<br />

component that is a lodger (instead of a window- owning control), you avoid the client-server<br />

message and the 'activate' and 'begin-redraw' brackets. All you need is a single<br />

ResetGc(),which occupies a single byte in the window server's client-side buffer.<br />

Support for flicker-free drawing<br />

As an application programmer, you should be aware of two aspects of the window server<br />

that promote flicker-free drawing.<br />

Firstly, the window server clips drawing down to the intersection of the invalid region and the<br />

begin-redraw region, so if your drawing code tends to flicker, the effect will be confined to the<br />

area being necessarily redrawn.<br />

You can exploit this in some draw-now situations. Imagine that I wanted to implement a<br />

cursor-movement function, but didn't want to alter my DrawTiles() function. I could write a<br />

DrawTwoTilesNow()function that accepted the (x, y) coordinates of two tiles to be drawn,<br />

enabling me to calculate and invalidate only those two rectangles. I could then activate a GC<br />

and begin-redraw the whole tiled area, calling DrawTiles() to do so. The window server<br />

would clip drawing activity to the two tiles affected, eliminating flicker anywhere else. It's a<br />

poor man's flicker-free solution, but in some cases, it might just make the difference.<br />

Secondly, the window server's client-side buffer provides useful flicker- free support. For a<br />

start, it improves overall system efficiency so that everything works faster and flickers are<br />

therefore shorter. Also, it causes drawing commands to be batched up and executed rapidly<br />

by the window server using the BITGDI and a constant clipping region. In practice, this<br />

means that some sequences of draw commands are executed so fast that, even if your<br />

coding flickers by nature, no one will ever see the problem, especially on high-persistence<br />

LCD displays. The key here is to confine sequences that cause flicker to only a few<br />

consecutive draw commands so that they all get executed as part of a single window server<br />

buffer.<br />

Finally, and most obviously, the use of lodger controls helps here too because it means the<br />

window server buffer contains only a single ResetGc() command between controls, rather<br />

than a whole end bracket for redraw and GC deactivation, followed by a begin bracket for<br />

GC activation and redraw.<br />

11.5.5 Backed-up Windows<br />

In the window server, a standard window is represented by information about its position,<br />

size, visible region, and invalid region – and that's about all. In particular, no memory is set<br />

aside for the drawn content of the window, which is why the window server has to ask the<br />

application to redraw when a region is invalid.<br />

But in some cases, it's impractical for the application to redraw the window, for instance, if<br />

it's:<br />

� an old-style program that's not structured for event handling, and so can't redraw;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!