1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 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:LGPL$
|
---|
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
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \page openvg.html
|
---|
44 | \title OpenVG Rendering in Qt
|
---|
45 | \since 4.6
|
---|
46 | \ingroup best-practices
|
---|
47 |
|
---|
48 | \brief Efficient rendering on embedded devices with OpenVG
|
---|
49 |
|
---|
50 | OpenVG is a standard API from the
|
---|
51 | \l{http://www.khronos.org/openvg}{Khronos Group} for accelerated
|
---|
52 | 2D vector graphics that is appearing in an increasing number of
|
---|
53 | embedded devices. The QtOpenVG plugin provides support for OpenVG
|
---|
54 | painting.
|
---|
55 |
|
---|
56 | OpenVG is optimized for 2D vector operations, and closely matches
|
---|
57 | the functionality in QPainter. It can therefore be an excellent
|
---|
58 | substitute for the default raster-based QPaintEngine on hardware
|
---|
59 | that supports OpenVG.
|
---|
60 |
|
---|
61 | \tableofcontents
|
---|
62 |
|
---|
63 | \section1 Building Qt with OpenVG support
|
---|
64 |
|
---|
65 | OpenVG support can be enabled by passing the \c{-openvg} option
|
---|
66 | to configure. It is assumed that the following qmake variables
|
---|
67 | are set to appropriate values in the qmake.conf file for your
|
---|
68 | platform:
|
---|
69 |
|
---|
70 | \list
|
---|
71 | \o QMAKE_INCDIR_OPENVG
|
---|
72 | \o QMAKE_LIBDIR_OPENVG
|
---|
73 | \o QMAKE_LIBS_OPENVG
|
---|
74 | \endlist
|
---|
75 |
|
---|
76 | Most OpenVG implementations are based on EGL, so the following
|
---|
77 | variables may also need to be set:
|
---|
78 |
|
---|
79 | \list
|
---|
80 | \o QMAKE_INCDIR_EGL
|
---|
81 | \o QMAKE_LIBDIR_EGL
|
---|
82 | \o QMAKE_LIBS_EGL
|
---|
83 | \endlist
|
---|
84 |
|
---|
85 | See \l{qmake Variable Reference} for more information on these variables.
|
---|
86 |
|
---|
87 | Two kinds of OpenVG engines are currently supported: EGL based,
|
---|
88 | and engines built on top of OpenGL such as
|
---|
89 | \l{http://sourceforge.net/projects/shivavg}{ShivaVG}.
|
---|
90 | EGL based engines are preferred.
|
---|
91 |
|
---|
92 | It is assumed that the EGL implementation has some way to turn a
|
---|
93 | QWidget::winId() into an EGL rendering surface with
|
---|
94 | \c{eglCreateWindowSurface()}. If this is not the case, then
|
---|
95 | modifications may be needed to the code under \c{src/gui/egl} and
|
---|
96 | \c{src/plugins/graphicssystems/openvg} to accomodate the EGL
|
---|
97 | implementation.
|
---|
98 |
|
---|
99 | The ShivaVG graphics system under \c{src/plugins/graphicssystems/shivavg}
|
---|
100 | is an example of how to integrate a non-EGL implementation of
|
---|
101 | OpenVG into Qt. It is currently only supported with Qt/X11
|
---|
102 | and being an example only, the resulting screen output may not
|
---|
103 | be as good as with other OpenVG engines.
|
---|
104 |
|
---|
105 | \section1 Using the OpenVG graphics system
|
---|
106 |
|
---|
107 | Once the graphics system plugin has been built and installed,
|
---|
108 | applications can be run as follows to use the plugin:
|
---|
109 |
|
---|
110 | \code
|
---|
111 | app -graphicssystem OpenVG
|
---|
112 | \endcode
|
---|
113 |
|
---|
114 | If ShivaVG is being used, then substitute \c ShivaVG instead of
|
---|
115 | \c OpenVG in the line above.
|
---|
116 |
|
---|
117 | If the plugin fails to load, try setting the \c QT_DEBUG_PLUGINS
|
---|
118 | environment variable to 1 and try again. Usually the plugin
|
---|
119 | cannot be loaded because Qt cannot locate it in the directory
|
---|
120 | \c{plugins/graphicssystems} within the Qt installation, or the
|
---|
121 | dynamic library path does not include the directory containing
|
---|
122 | the system's \c libOpenVG.so library.
|
---|
123 |
|
---|
124 | \section1 Supported features
|
---|
125 |
|
---|
126 | \section2 Context modes
|
---|
127 |
|
---|
128 | The default configuration is "single-context" mode, where a single
|
---|
129 | EGLContext object is used for all drawing, regardless of the surface.
|
---|
130 | Multiple EGLSurfaces are created, one for each window surface or pixmap.
|
---|
131 | eglMakeCurrent() is called with the same EGLContext every time, but a
|
---|
132 | different EGLSurface.
|
---|
133 |
|
---|
134 | Single-context mode is necessary for QPixmapData to be implemented in
|
---|
135 | terms of a VGImage. If single-context mode is not enabled, then QPixmapData
|
---|
136 | will use the fallback QRasterPixmapData implementation, which is less
|
---|
137 | efficient performance-wise.
|
---|
138 |
|
---|
139 | Single-context mode can be disabled with the QVG_NO_SINGLE_CONTEXT define
|
---|
140 | if the OpenVG engine does not support one context with multiple surfaces.
|
---|
141 |
|
---|
142 | \section2 Transformation matrices
|
---|
143 |
|
---|
144 | All affine and projective transformation matrices are supported.
|
---|
145 |
|
---|
146 | QVGPaintEngine will use the engine to accelerate affine transformation
|
---|
147 | matrices only. When a projective transformation matrix is used,
|
---|
148 | QVGPaintEngine will transform the coordinates before passing them
|
---|
149 | to the engine. This will probably incur a performance penalty.
|
---|
150 |
|
---|
151 | Pixmaps and images are always transformed by the engine, because
|
---|
152 | OpenVG specifies that projective transformations must work for images.
|
---|
153 |
|
---|
154 | It is recommended that client applications should avoid using projective
|
---|
155 | transformations for non-image elements in performance critical code.
|
---|
156 |
|
---|
157 | \section2 Composition modes
|
---|
158 |
|
---|
159 | The following composition modes are supported:
|
---|
160 |
|
---|
161 | \list
|
---|
162 | \o QPainter::CompositionMode_SourceOver
|
---|
163 | \o QPainter::CompositionMode_DestinationOver
|
---|
164 | \o QPainter::CompositionMode_Source
|
---|
165 | \o QPainter::CompositionMode_SourceIn
|
---|
166 | \o QPainter::CompositionMode_DestinationIn
|
---|
167 | \o QPainter::CompositionMode_Plus
|
---|
168 | \o QPainter::CompositionMode_Multiply
|
---|
169 | \o QPainter::CompositionMode_Screen
|
---|
170 | \o QPainter::CompositionMode_Darken
|
---|
171 | \o QPainter::CompositionMode_Lighten
|
---|
172 | \endlist
|
---|
173 |
|
---|
174 | The other members of QPainter::CompositionMode are not supported
|
---|
175 | unless the \c{VG_KHR_advanced_blending} extension is present,
|
---|
176 | in which case the following additional modes are supported:
|
---|
177 |
|
---|
178 | \list
|
---|
179 | \o QPainter::CompositionMode_Overlay
|
---|
180 | \o QPainter::CompositionMode_ColorDodge
|
---|
181 | \o QPainter::CompositionMode_ColorBurn
|
---|
182 | \o QPainter::CompositionMode_HardLight
|
---|
183 | \o QPainter::CompositionMode_SoftLight
|
---|
184 | \o QPainter::CompositionMode_Difference
|
---|
185 | \o QPainter::CompositionMode_Exclusion
|
---|
186 | \o QPainter::CompositionMode_SourceOut
|
---|
187 | \o QPainter::CompositionMode_DestinationOut
|
---|
188 | \o QPainter::CompositionMode_SourceAtop
|
---|
189 | \o QPainter::CompositionMode_DestinationAtop
|
---|
190 | \o QPainter::CompositionMode_Xor
|
---|
191 | \endlist
|
---|
192 |
|
---|
193 | Any attempt to set an unsupported mode will result in
|
---|
194 | the actual mode being set to QPainter::CompositionMode_SourceOver.
|
---|
195 | Client applications should avoid using unsupported modes.
|
---|
196 |
|
---|
197 | \section2 Pens and brushes
|
---|
198 |
|
---|
199 | All pen styles are supported, including cosmetic pens.
|
---|
200 |
|
---|
201 | All brush styles are supported except for conical gradients, which are
|
---|
202 | not supported by OpenVG 1.1. Conical gradients will be converted into a
|
---|
203 | solid color brush corresponding to the first color in the gradient's
|
---|
204 | color ramp.
|
---|
205 |
|
---|
206 | Affine matrices are supported for brush transforms, but not projective
|
---|
207 | matrices.
|
---|
208 |
|
---|
209 | \section2 Rectangles, lines, and points
|
---|
210 |
|
---|
211 | Rectangles, lines, and rounded rectangles use cached VGPath objects
|
---|
212 | to try to accelerate drawing operations. vgModifyPathCoords() is used
|
---|
213 | to modify the co-ordinates in the cached VGPath object each time
|
---|
214 | fillRect(), drawRects(), drawLines(), or drawRoundedRect() is called.
|
---|
215 |
|
---|
216 | If the engine does not implement vgModifyPathCoords() properly, then the
|
---|
217 | QVG_NO_MODIFY_PATH define can be set to disable path caching. This will
|
---|
218 | incur a performance penalty.
|
---|
219 |
|
---|
220 | Points are implemented as lines from the point to itself. The cached
|
---|
221 | line drawing VGPath object is used when drawing points.
|
---|
222 |
|
---|
223 | \section2 Polygons and Ellipses
|
---|
224 |
|
---|
225 | Polygon and ellipse drawing creates a new VGPath object every time
|
---|
226 | drawPolygon() or drawEllipse() is called. If the client application is
|
---|
227 | making heavy use of these functions, the constant creation and destruction
|
---|
228 | of VGPath objects could have an impact on performance.
|
---|
229 |
|
---|
230 | If a projective transformation is active, ellipses are converted into
|
---|
231 | cubic curves prior to transformation, which may further impact performance.
|
---|
232 |
|
---|
233 | Client applications should avoid polygon and ellipse drawing in performance
|
---|
234 | critical code if possible.
|
---|
235 |
|
---|
236 | \section2 Other Objects
|
---|
237 |
|
---|
238 | Most other objects (arcs, pies, etc) use drawPath(), which takes a
|
---|
239 | QPainterPath argument. The default implementation in QPainterEngineEx
|
---|
240 | converts the QPainterPath into a QVectorPath and then calls draw(),
|
---|
241 | which in turn converts the QVectorPath into a VGPath for drawing.
|
---|
242 |
|
---|
243 | To reduce the overhead, we have overridden drawPath() in QVGPaintEngine
|
---|
244 | to convert QPainterPath's directly into VGPath's. This should help improve
|
---|
245 | performance compared to the default implementation.
|
---|
246 |
|
---|
247 | Client applications should try to avoid these types of objects in
|
---|
248 | performance critical code because of the QPainterPath to VGPath
|
---|
249 | conversion cost.
|
---|
250 |
|
---|
251 | \section2 Clipping
|
---|
252 |
|
---|
253 | Clipping with QRect, QRectF, and QRegion objects is supported on all
|
---|
254 | OpenVG engines with vgMask() if the transformation matrix is the identity
|
---|
255 | or a simple origin translation.
|
---|
256 |
|
---|
257 | Clipping with an arbitrary QPainterPath, or setting the clip region when
|
---|
258 | the transformation matrix is simple, is supported only if the OpenVG engine
|
---|
259 | has the vgRenderToMask() function (OpenVG 1.1 and higher).
|
---|
260 |
|
---|
261 | The QVG_NO_RENDER_TO_MASK define will disable the use of vgRenderToMask().
|
---|
262 |
|
---|
263 | The QVG_SCISSOR_CLIP define will disable clipping with vgMask() or
|
---|
264 | vgRenderToMask() and instead use the scissor rectangle list to perform
|
---|
265 | clipping. Clipping with an arbitrary QPainterPath will not be supported.
|
---|
266 | The QVG_SCISSOR_CLIP define should only be used if the OpenVG engine
|
---|
267 | does not support vgMask() or vgRenderToMask().
|
---|
268 |
|
---|
269 | \section2 Opacity
|
---|
270 |
|
---|
271 | Opacity is supported for all drawing operations. Solid color pens,
|
---|
272 | solid color brushes, gradient brushes, and image drawing with drawPixmap()
|
---|
273 | and drawImage() will probably have the best performance compared to
|
---|
274 | other kinds of pens and brushes.
|
---|
275 |
|
---|
276 | \section2 Text Drawing
|
---|
277 |
|
---|
278 | If OpenVG 1.1 is used, the paint engine will use VG fonts to cache glyphs
|
---|
279 | while drawing. If the engine does not support VG fonts correctly,
|
---|
280 | QVG_NO_DRAW_GLYPHS can be defined to disable this mode. Text drawing
|
---|
281 | performance will suffer if VG fonts are not used.
|
---|
282 |
|
---|
283 | By default, image-based glyphs are used. If QVG_NO_IMAGE_GLYPHS is defined,
|
---|
284 | then path-based glyphs will be used instead. QVG_NO_IMAGE_GLYPHS is ignored
|
---|
285 | if QVG_NO_DRAW_GLYPHS is defined.
|
---|
286 |
|
---|
287 | If path-based glyphs are used, then the OpenVG engine will need to
|
---|
288 | support hinting to render text with good results. Image-based glyphs
|
---|
289 | avoids the need for hinting and will usually give better results than
|
---|
290 | path-based glyphs.
|
---|
291 |
|
---|
292 | \section2 Pixmaps
|
---|
293 |
|
---|
294 | In single-context mode, pixmaps will be implemented using VGImage
|
---|
295 | unless QVG_NO_PIXMAP_DATA is defined.
|
---|
296 |
|
---|
297 | QVGPixmapData will convert QImage's into VGImage's when the application
|
---|
298 | calls drawPixmap(), and the pixmap will be kept in VGImage form for the
|
---|
299 | lifetime of the QVGPixmapData object. When the application tries to paint
|
---|
300 | into a QPixmap with QPainter, the data will be converted back into a
|
---|
301 | QImage and the raster paint engine will be used to render into the QImage.
|
---|
302 |
|
---|
303 | This arrangement optimizes for the case of drawing the same static pixmap
|
---|
304 | over and over (e.g. for icons), but does not optimize the case of drawing
|
---|
305 | into pixmaps.
|
---|
306 |
|
---|
307 | Bitmaps must use QRasterPixmapData. They are not accelerated with
|
---|
308 | VGImage at present.
|
---|
309 |
|
---|
310 | \section2 Pixmap filters
|
---|
311 |
|
---|
312 | Convolution, colorize, drop shadow, and blur filters are accelerated
|
---|
313 | using OpenVG operations.
|
---|
314 |
|
---|
315 | \section2 Scrolling
|
---|
316 |
|
---|
317 | By default, accelerated scrolling is not enabled because the impact on
|
---|
318 | performance is very much tied to the hardware platform. To enable
|
---|
319 | accelerated scrolling, you should ensure that QVG_BUFFER_SCROLLING is
|
---|
320 | defined when compiling the QtOpenVG module.
|
---|
321 |
|
---|
322 | You should only enable this feature if vgCopyPixels() is known to be
|
---|
323 | efficient on your hardware platform.
|
---|
324 |
|
---|
325 | \section1 Known issues
|
---|
326 |
|
---|
327 | Performance of copying the contents of an OpenVG-rendered window to the
|
---|
328 | screen needs platform-specific work in the QVGWindowSurface class.
|
---|
329 |
|
---|
330 | Clipping with arbitrary non-rectangular paths only works on engines
|
---|
331 | that support vgRenderToMask(). Simple rectangular paths are supported
|
---|
332 | on all engines that correctly implement vgMask().
|
---|
333 |
|
---|
334 | The paint engine is not yet thread-safe, so it is not recommended for
|
---|
335 | use in threaded Qt applications that draw from multiple threads.
|
---|
336 | Drawing should be limited to the main GUI thread.
|
---|
337 |
|
---|
338 | Performance of projective matrices for non-image drawing is not as good
|
---|
339 | as for affine matrices.
|
---|
340 |
|
---|
341 | QPixmap's are implemented as VGImage objects so that they can be quickly
|
---|
342 | rendered with drawPixmap(). Rendering into a QPixmap using QPainter
|
---|
343 | will use the default Qt raster paint engine on a QImage copy of the
|
---|
344 | QPixmap, and will not be accelerated. This issue may be addressed in
|
---|
345 | a future version of the engine.
|
---|
346 |
|
---|
347 | ShivaVG support is highly experimental and limited to Qt/X11. It is
|
---|
348 | provided as an example of how to integrate a non-EGL engine.
|
---|
349 | */
|
---|