1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \page qt-embedded-architecture.html
|
---|
30 |
|
---|
31 | \title Qt for Embedded Linux Architecture
|
---|
32 | \ingroup qt-embedded-linux
|
---|
33 |
|
---|
34 | A \l{Qt for Embedded Linux} application requires a server
|
---|
35 | application to be running, or to be the server application itself.
|
---|
36 | Any \l{Qt for Embedded Linux} application can act as the server.
|
---|
37 | When more than one application is running, the subsequent
|
---|
38 | applications connect to the existing server application as clients.
|
---|
39 |
|
---|
40 | The server and client processes have different responsibilities:
|
---|
41 | The server process manages pointer handling, character input, and
|
---|
42 | screen output. In addition, the server controls the appearance of
|
---|
43 | the screen cursor and the screen saver. The client process
|
---|
44 | performs all application specific operations.
|
---|
45 |
|
---|
46 | The server application is represented by an instance of the
|
---|
47 | QWSServer class, while the client applications are represented by
|
---|
48 | instances of the QWSClient class. On each side, there are several
|
---|
49 | classes performing the various operations.
|
---|
50 |
|
---|
51 | \image qt-embedded-architecture2.png
|
---|
52 |
|
---|
53 | All system generated events, including keyboard and mouse events,
|
---|
54 | are passed to the server application which then propagates the
|
---|
55 | event to the appropriate client.
|
---|
56 |
|
---|
57 | When rendering, the default behavior is for each client to render
|
---|
58 | its widgets into memory while the server is responsible for
|
---|
59 | putting the contents of the memory onto the screen. But when the
|
---|
60 | hardware is known and well defined, as is often the case with
|
---|
61 | software for embedded devices, it may be useful for the clients to
|
---|
62 | manipulate and control the underlying hardware directly.
|
---|
63 | \l{Qt for Embedded Linux} provides two different approaches to
|
---|
64 | achieve this behavior, see the graphics rendering section below for
|
---|
65 | details.
|
---|
66 |
|
---|
67 | \tableofcontents
|
---|
68 |
|
---|
69 | \section1 Client/Server Communication
|
---|
70 |
|
---|
71 | The running applications continuously alter the appearance of the
|
---|
72 | screen by adding and removing widgets. The server maintains
|
---|
73 | information about each top-level window in a corresponding
|
---|
74 | QWSWindow object.
|
---|
75 |
|
---|
76 | Whenever the server receives an event, it queries its stack of
|
---|
77 | top-level windows to find the window containing the event's
|
---|
78 | position. Each window can identify the client application that
|
---|
79 | created it, and returns its ID to the server upon
|
---|
80 | request. Finally, the server forwards the event, encapsulated by
|
---|
81 | an instance of the QWSEvent class, to the appropriate client.
|
---|
82 |
|
---|
83 | \image qt-embedded-clientservercommunication.png
|
---|
84 |
|
---|
85 | If an input method is installed, it is used as a filter between
|
---|
86 | the server and the client application. Derive from the
|
---|
87 | QWSInputMethod class to implement custom input methods, and use
|
---|
88 | the server's \l {QWSServer::}{setCurrentInputMethod()} function to
|
---|
89 | install it. In addition, it is possible to implement global,
|
---|
90 | low-level filters on key events using the
|
---|
91 | QWSServer::KeyboardFilter class; this can be used to implement
|
---|
92 | things like advanced power management suspended from a button
|
---|
93 | without having to filter for it in all applications.
|
---|
94 |
|
---|
95 | \table 100%
|
---|
96 | \header \o UNIX Domain Socket
|
---|
97 | \row
|
---|
98 | \o
|
---|
99 |
|
---|
100 | \image qt-embedded-client.png
|
---|
101 |
|
---|
102 | The server communicates with the client applications over the UNIX
|
---|
103 | domain socket. You can retrieve direct access to all the events a
|
---|
104 | client receives from the server, by reimplementing QApplication's
|
---|
105 | \l {QApplication::}{qwsEventFilter()} function.
|
---|
106 |
|
---|
107 | \endtable
|
---|
108 |
|
---|
109 | The clients (and the server) communicate with each other using the
|
---|
110 | QCopChannel class. QCOP is a many-to-many communication protocol
|
---|
111 | for transferring messages on various channels. A channel is
|
---|
112 | identified by a name, and anyone who wants to can listen to
|
---|
113 | it. The QCOP protocol allows clients to communicate both within
|
---|
114 | the same address space and between different processes.
|
---|
115 |
|
---|
116 | \section1 Pointer Handling Layer
|
---|
117 |
|
---|
118 | \list
|
---|
119 | \o QWSMouseHandler
|
---|
120 | \o QMouseDriverPlugin
|
---|
121 | \o QMouseDriverFactory
|
---|
122 | \endlist
|
---|
123 |
|
---|
124 | The mouse driver (represented by an instance of the
|
---|
125 | QWSMouseHandler class) is loaded by the server application when it
|
---|
126 | starts running, using Qt's \l {How to Create Qt Plugins}{plugin
|
---|
127 | system}.
|
---|
128 |
|
---|
129 | \image qt-embedded-pointerhandlinglayer.png
|
---|
130 |
|
---|
131 | A mouse driver receives mouse events from the device and
|
---|
132 | encapsulates each event with an instance of the QWSEvent class
|
---|
133 | which it then passes to the server.
|
---|
134 |
|
---|
135 | \l{Qt for Embedded Linux} provides ready-made drivers for several mouse
|
---|
136 | protocols, see the \l{Qt for Embedded Linux Pointer Handling}{pointer
|
---|
137 | handling} documentation for details. Custom mouse drivers can be
|
---|
138 | implemented by subclassing the QWSMouseHandler class and creating
|
---|
139 | a mouse driver plugin. The default implementation of the
|
---|
140 | QMouseDriverFactory class will automatically detect the plugin,
|
---|
141 | loading the driver into the server application at runtime.
|
---|
142 |
|
---|
143 | In addition to the generic mouse handler, \l{Qt for Embedded Linux}
|
---|
144 | provides a calibrated mouse handler. Use the
|
---|
145 | QWSCalibratedMouseHandler class as the base class when the system
|
---|
146 | device does not have a fixed mapping between device and screen
|
---|
147 | coordinates and/or produces noisy events, e.g. a touchscreen.
|
---|
148 |
|
---|
149 | See also: \l{Qt for Embedded Linux Pointer Handling} and
|
---|
150 | \l{How to Create Qt Plugins}.
|
---|
151 |
|
---|
152 | \section1 Character Input Layer
|
---|
153 |
|
---|
154 | \list
|
---|
155 | \o QWSKeyboardHandler
|
---|
156 | \o QKbdDriverPlugin
|
---|
157 | \o QKbdDriverFactory
|
---|
158 | \endlist
|
---|
159 |
|
---|
160 | The keyboard driver (represented by an instance of the
|
---|
161 | QWSKeyboardHandler class) is loaded by the server application when
|
---|
162 | it starts running, using Qt's \l {How to Create Qt Plugins}{plugin
|
---|
163 | system}.
|
---|
164 |
|
---|
165 | \image qt-embedded-characterinputlayer.png
|
---|
166 |
|
---|
167 | A keyboard driver receives keyboard events from the device and
|
---|
168 | encapsulates each event with an instance of the QWSEvent class
|
---|
169 | which it then passes to the server.
|
---|
170 |
|
---|
171 | \l{Qt for Embedded Linux} provides ready-made drivers for several keyboard
|
---|
172 | protocols, see the \l {Qt for Embedded Linux Character Input}{character
|
---|
173 | input} documentation for details. Custom keyboard drivers can be
|
---|
174 | implemented by subclassing the QWSKeyboardHandler class and
|
---|
175 | creating a keyboard driver plugin. The default implementation of the
|
---|
176 | QKbdDriverFactory class will automatically detect the plugin, loading the
|
---|
177 | driver into the server application at run-time.
|
---|
178 |
|
---|
179 | See also: \l{Qt for Embedded Linux Character Input} and \l {How to Create
|
---|
180 | Qt Plugins}.
|
---|
181 |
|
---|
182 | \section1 Graphics Rendering
|
---|
183 |
|
---|
184 | \list
|
---|
185 | \o QApplication
|
---|
186 | \o QDecoration
|
---|
187 | \o QDecorationPlugin
|
---|
188 | \o QDecorationFactory
|
---|
189 | \endlist
|
---|
190 |
|
---|
191 | The default behavior is for each client to render its widgets as well
|
---|
192 | as its decorations into memory, while the server copies the memory content
|
---|
193 | to the device's framebuffer.
|
---|
194 |
|
---|
195 | Whenever a client receives an event that alters any of its
|
---|
196 | widgets, the application updates the relevant parts of its memory
|
---|
197 | buffer:
|
---|
198 |
|
---|
199 | \image qt-embedded-clientrendering.png
|
---|
200 |
|
---|
201 | The decoration is loaded by the client application when it starts
|
---|
202 | running (using Qt's \l {How to Create Qt Plugins}{plugin system}),
|
---|
203 | and can be customized by deriving from the QDecoration class and
|
---|
204 | creating a decoration plugin. The default implementation of
|
---|
205 | the QDecorationFactory class will automatically detect the plugin,
|
---|
206 | loading the decoration into the application at runtime. Call the
|
---|
207 | QApplication::qwsSetDecoration() function to actually apply the
|
---|
208 | given decoration to an application.
|
---|
209 |
|
---|
210 | \table 100%
|
---|
211 | \header \o Direct Painting \target Direct Painting
|
---|
212 | \row
|
---|
213 | \o
|
---|
214 |
|
---|
215 | It is possible for the clients to manipulate and control the
|
---|
216 | underlying hardware directly. There are two ways of achieving
|
---|
217 | this: The first approach is to set the Qt::WA_PaintOnScreen window
|
---|
218 | attribute for each widget, the other is to use the QDirectPainter
|
---|
219 | class to reserve a region of the framebuffer.
|
---|
220 |
|
---|
221 | \image qt-embedded-setwindowattribute.png
|
---|
222 |
|
---|
223 | By setting the Qt::WA_PaintOnScreen attribute, the application
|
---|
224 | renders the widget directly onto the screen and the affected
|
---|
225 | region will not be modified by the screen driver \e unless another
|
---|
226 | window with a higher focus requests (parts of) the same
|
---|
227 | region. Note that if you want to render all of an application's
|
---|
228 | widgets directly on screen, it might be easier to set the
|
---|
229 | QT_ONSCREEN_PAINT environment variable.
|
---|
230 |
|
---|
231 | \image qt-embedded-reserveregion.png
|
---|
232 |
|
---|
233 | Using QDirectPainter, on the other hand, provides a complete
|
---|
234 | control over the reserved region, i.e., the screen driver will
|
---|
235 | never modify the given region.
|
---|
236 |
|
---|
237 | To draw on a region reserved by a QDirectPainter instance, the
|
---|
238 | application must get hold of a pointer to the framebuffer. In
|
---|
239 | general, a pointer to the framebuffer can be retrieved using the
|
---|
240 | QDirectPainter::frameBuffer() function. But note that if the
|
---|
241 | current screen has subscreens, you must query the screen driver
|
---|
242 | instead to identify the correct subscreen. A pointer to the
|
---|
243 | current screen driver can always be retrieved using the static
|
---|
244 | QScreen::instance() function. Then use QScreen's \l
|
---|
245 | {QScreen::}{subScreenIndexAt()} and \l {QScreen::}{subScreens()}
|
---|
246 | functions to access the correct subscreen, and the subscreen's \l
|
---|
247 | {QScreen::}{base()} function to retrieve a pointer to the
|
---|
248 | framebuffer.
|
---|
249 |
|
---|
250 | Note that \l{Qt for Embedded Linux} also provides the QWSEmbedWidget class,
|
---|
251 | making it possible to embed the reserved region (i.e., the
|
---|
252 | QDirectPainter object) in a regular widget.
|
---|
253 |
|
---|
254 | \endtable
|
---|
255 |
|
---|
256 | \section1 Drawing on Screen
|
---|
257 |
|
---|
258 | \list
|
---|
259 | \o QScreen
|
---|
260 | \o QScreenDriverPlugin
|
---|
261 | \o QScreenDriverFactory
|
---|
262 | \endlist
|
---|
263 |
|
---|
264 | When a screen update is required, the server runs through all the
|
---|
265 | top-level windows that intersect with the region that is about to
|
---|
266 | be updated, and ensures that the associated clients have updated
|
---|
267 | their memory buffer. Then the server uses the screen driver
|
---|
268 | (represented by an instance of the QScreen class) to copy the
|
---|
269 | content of the memory to the screen.
|
---|
270 |
|
---|
271 | The screen driver is loaded by the server application when it
|
---|
272 | starts running, using Qt's plugin system. \l{Qt for Embedded Linux}
|
---|
273 | provides ready-made drivers for several screen protocols, see the
|
---|
274 | \l{Qt for Embedded Linux Display Management}{display management}
|
---|
275 | documentation for details. Custom screen drivers can be
|
---|
276 | implemented by subclassing the QScreen class and creating a screen
|
---|
277 | driver plugin. The default implementation of the QScreenDriverFactory
|
---|
278 | class will automatically detect the plugin, loading the driver into
|
---|
279 | the server application at run-time.
|
---|
280 |
|
---|
281 | \image qt-embedded-drawingonscreen.png
|
---|
282 |
|
---|
283 | To locate the relevant parts of memory, the driver is provided
|
---|
284 | with the list of top-level windows that intersect with the given
|
---|
285 | region. Associated with each of the top-level windows there is an
|
---|
286 | instance of the QWSWindowSurface class representing the drawing
|
---|
287 | area of the window. The driver uses these objects to retrieve
|
---|
288 | pointers to the various memory blocks. Finally, the screen driver
|
---|
289 | composes the surface images before copying the updated region to
|
---|
290 | the framebuffer.
|
---|
291 |
|
---|
292 | \table 100%
|
---|
293 | \header \o Accelerated Graphics
|
---|
294 | \row
|
---|
295 | \o
|
---|
296 |
|
---|
297 | In \l{Qt for Embedded Linux}, painting is a pure software implementation,
|
---|
298 | but (starting with Qt 4.2) it is possible to add an accelerated
|
---|
299 | graphics driver to take advantage of available hardware resources.
|
---|
300 |
|
---|
301 | \image qt-embedded-accelerateddriver.png
|
---|
302 |
|
---|
303 | The clients render each window onto a corresponding window surface
|
---|
304 | object using Qt's paint system, and then store the surface in
|
---|
305 | memory. The screen driver accesses the memory and composes the
|
---|
306 | surface images before it copies them to the screen as explained
|
---|
307 | above.
|
---|
308 |
|
---|
309 | To add an accelerated graphics driver you must create a custom
|
---|
310 | screen and implement a custom raster paint engine
|
---|
311 | (\l{Qt for Embedded Linux} uses a raster-based paint engine to
|
---|
312 | implement the painting operations). Then you must create a custom
|
---|
313 | paint device that is aware of your paint engine, a custom window
|
---|
314 | surface that knows about your paint device, and make your screen
|
---|
315 | able to recognize your window surface.
|
---|
316 |
|
---|
317 | See the \l{Adding an Accelerated Graphics Driver to Qt for Embedded Linux}
|
---|
318 | {accelerated graphics driver} documentation for details.
|
---|
319 |
|
---|
320 | \endtable
|
---|
321 |
|
---|
322 | See also: \l{Qt for Embedded Linux Display Management} and
|
---|
323 | \l{How to Create Qt Plugins}.
|
---|
324 | */
|
---|