Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108449
  • 博文数量: 39
  • 博客积分: 2032
  • 博客等级: 大尉
  • 技术积分: 330
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-09 10:21
文章分类
文章存档

2011年(2)

2010年(22)

2009年(15)

我的朋友

分类: LINUX

2010-08-28 17:12:38

这次的问题是在MeeGo环境下对Graphics的优化部分,使用Webkit编译的QtLauncher默认情况下绘图性能非常差,和Chrome的差距不是一点半点,当时阅读源代码的时候就发现在qpaintengine_x11.cpp中的代码其实组织的比较差,很多地方性能非常低,通过缓存+快路径的方式实施了几个补丁之后性能通常能有数倍至数百倍的提升,但是总体效果仍然不理想。

在调试一个rotation后背景显示的bug时突然意外发现,命令行中使用 -graphicssystem raster 时该bug不存在,再将之前的testcase都运行之后发现qpaintengine_raster的效率非常高,这才注意到,Qt在painting这一部分的优化工作其实都已经做了很多了,针对不同的应用情境Qt提供了很多的paintengine, 具体可见Qt文档。(下面英文部分)

当时看的不仔细,看的时候也不太理解,现在才明白了如此多的engine都是干什么用的了。

Performance

QPainter is a rich framework that allows developers to do a great variety of graphical operations, such as gradients, composition modes and vector graphics. And QPainter can do this across a variety of different hardware and software stacks. Naturally the underlying combination of hardware and software has some implications for performance, and ensuring that every single operation is fast in combination with all the various combinations of composition modes, brushes, clipping, transformation, etc, is close to an impossible task because of the number of permutations. As a compromise we have selected a subset of the QPainter API and backends, where performance is guaranteed to be as good as we can sensibly get it for the given combination of hardware and software.

The backends we focus on as high-performance engines are:

  • Raster - This backend implements all rendering in pure software and is always used to render into QImages. For optimal performance only use the format typesQImage::Format_ARGB32_PremultipliedQImage::Format_RGB32 or QImage::Format_RGB16. Any other format, including QImage::Format_ARGB32, has significantly worse performance. This engine is also used by default on Windows and on QWS. It can be used as default graphics system on any OS/hardware/software combination by passing -graphicssystem raster on the command line
  • OpenGL 2.0 (ES) - This backend is the primary backend for hardware accelerated graphics. It can be run on desktop machines and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0 specification. This includes most graphics chips produced in the last couple of years. The engine can be enabled by using QPainter onto a or by passing -graphicssystem opengl on the command line when the underlying system supports it.
  • OpenVG - This backend implements the Khronos standard for 2D and Vector Graphics. It is primarily for embedded devices with hardware support for OpenVG. The engine can be enabled by passing -graphicssystem openvg on the command line when the underlying system supports it.

These operations are:

  • Simple transformations, meaning translation and scaling, pluss 0, 90, 180, 270 degree rotations.
  • drawPixmap() in combination with simple transformations and opacity with non-smooth transformation mode (QPainter::SmoothPixmapTransform not enabled as a render hint).
  • Rectangle fills with solid color, two-color linear gradients and simple transforms.
  • Rectangular clipping with simple transformations and intersect clip.
  • Composition Modes QPainter::CompositionMode_Source and 
  • Rounded rectangle filling using solid color and two-color linear gradients fills.
  • 3x3 patched pixmaps, via qDrawBorderPixmap.

This list gives an indication of which features to safely use in an application where performance is critical. For certain setups, other operations may be fast too, but before making extensive use of them, it is recommended to benchmark and verify them on the system where the software will run in the end. There are also cases where expensive operations are ok to use, for instance when the result is cached in a .

See also QPaintDevice, , , , and .

阅读(884) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-08-30 21:42:41

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com