User:Klange/Room-full-of-painters

From OSDev Wiki
Jump to navigation Jump to search

The room-full-of-painters is an explanation for how compositing window managers operate. Particularly, the form of the explanation below covers a simple, naïve compositor. It is not a coincidence that the metaphor resembles the process of an animation house, as many of the terms used in compositing are derived from animation.

The Room

Imagine, if you will, a room full of people. Now, imagine that one of these people has a large canvas in front of him; we will call him the Master Artist. Many of the other people in the room also have their own, smaller canvases and various painting tools; we will refer to them as painters. There is also a man standing near the door of the room, looking very auspicious - he is the Curator.

The Master Artist has many tools, but they may seem peculiar for a painter: a scanner/copier, a small knife, some glue, and a box of little stickers shaped variously as hands and arrows and I-bars. He also keeps a notebook, filled with tables listing coordinates and the names of his apprentice painters.

The painters have their small canvases, and each has a box of painter tools containing whatever they please.

The painters take their canvases and draw whatever they like on them. They then give the canvases to the Master Artist, who places each canvas into the copier and produces a copy. He then takes the copies and places them upon his canvas, gluing each into place as it should be from his notebook, in order as prescribed in the same. When a copy extends beyond his canvas, he takes the knife and cuts off the excess. Content with his work, he then takes a sticker from his box and places it on top, as also prescribed by his notebook. The Master Artist then takes his completed canvas and gives it another person, the Curator, who promptly gives the master a new canvas. The Master Artist then returns all of his apprentices' canvas to the various painters, and the process repeats.

Now while all of this is happening, the Master Artist has some assistants running around. One of them, Assistant A, runs in and out of the room, brushing dangerously close to the Curator. When he returns, he always goes straight to the Master Artist and gives him a note. Scrawled on it are such things as "left 1mm" and "key 12 down". The Master Artist looks at the note, then looks at his notebook, does some quick math, jots down a note of his own, and calls upon Assistant B. Assistant B takes the note and runs off to one of the apprentice painters to deliver it. The painter then does as he pleases with it and Assistant B returns to his post.

Sometimes, a painter will decide that he is done painting, or that he would like a larger canvas (or perhaps another canvas!). When this happens, the painter jots down a note and runs off to the Master Artist to deliver it. The Master Artist can then do what was asked, or refuse. If the painter says he is done, the Master Artist will throw that painter's canvas in the garbage and erase the line in his notebook for it. If the painter would like an additional canvas, the Master Artist can give them one, or refuse.

Additionally, sometimes a new painter will enter the room, or perhaps another one of the people in the room (who was not previously a painter) will pull out a brush and request a canvas from the Master Artist.

Explanation

The people represent programs. The Master Artist represents the compositor and the various painters represent graphical applications. The Master Artist's canvas represents the framebuffer, on the computer. The Curator represents the graphics card, and each canvas brought to them is shown on screen. Since graphical applications may have multiple windows, painters may have multiple canvases, which they draw on together. The process by which the Master Artist uses his copier and knives and glue sums up bit-blitting windows to the framebuffer. The Master Arist's assistants represent communication, A representing messages from input drivers - such as the mouse and keyboard - and B representing messages from the compositor to graphical applications, particularly input events; the lack of an assistant passing messages from the painters to the Master Artist is representative of the common synchronous nature of messages from graphical apps back to the compositor (and saves the need for having many assistants to run messages for all of the various painters). The Master Artist's notebook represents the compositor's internal memory of where windows should be, as well as where things like the pointer should be. The Master Artist's box of stickers represents mouse cursors, which are usually drawn by the compositor itself, though they could simply be yet another canvas drawn by an application.

Supplement

Double Buffering

Each painter, including the Master Artist, has two canvases instead of just the one. This is true for each canvas that has been requested. Whenever the Master Artist collects one canvas, the painter continues drawing on the other.

Damage Regions / Masking

Involves more creative uses of the knife, and usually also involves keeping the canvas instead of giving it to the Curator. When the Master Artist collects the canvases, he copies only the updated portions (which are noted on a slip of paper accompanying the canvas), cutting off the rest, and places the new scraps atop their older counterparts.