QPainter::drawImage 在 Mac OS X 和 Windows 上的性能差异很大
目前,我正在将 Windows 上用 Qt 4.8 编写的应用程序移植到 Mac OS X 中。我发现 QPainter::drawImage
的性能在 Mac OS X 和 Windows 上有很大差异。
在我用 google 搜索了一堆文章并在 Mac OS X 上分析了我的 Qt 应用程序后,我发现原因是 Mac 版本的 drawImage
是通过调用 Quartz 函数 CGContextDrawImage 实现的,因此调用了 argb32_sample_argb32
代码>. argb32_sample_argb32
浪费了大部分 CPU 周期。
最有可能的是,Mac OS X 在 API CGContextDrawImage 中将通用颜色空间转换为设备相关的颜色空间。不过我修改了QT 4.8的源代码,直接获取系统显示色彩空间。
结果还是不好。我的 mac 版本应用程序比 Windows 版本慢得多。
谁能告诉我为什么?
/// QT 4.8's source code modified by me
CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace()
{
#if 0
if (!m_genericColorSpace) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
m_genericColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
} else
#endif
{
m_genericColorSpace = CGColorSpaceCreateDeviceRGB();
}
if (!m_postRoutineRegistered) {
m_postRoutineRegistered = true;
qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces);
}
}
return m_genericColorSpace;
#else
// Just return the main display colorspace for the moment.
// return macDisplayColorSpace();
return CreateSystemColorSpace();
#endif
}
CGColorSpaceRef CreateSystemColorSpace () {
CMProfileRef sysprof = NULL;
CGColorSpaceRef dispColorSpace = NULL;
// Get the Systems Profile for the main display
if (CMGetSystemProfile(&sysprof) == noErr)
{
// Create a colorspace with the systems profile
dispColorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof);
// Close the profile
CMCloseProfile(sysprof);
}
return dispColorSpace;
}
Currently I'm porting an application written with Qt 4.8 on Windows into Mac OS X. I found the performance of QPainter::drawImage
differs dramatically on Mac OS X and Windows.
After I googled a bunch of articles and profile my Qt application on Mac OS X, I found the reason is that the Mac version drawImage
was implemented by calling Quartz function CGContextDrawImage which consequently calls argb32_sample_argb32
. argb32_sample_argb32
wastes most of the cpu cycles.
Most probably, Mac OS X converts generic color space into device-dependent color space in the API CGContextDrawImage. However I modified the source code of QT 4.8 the obtain the system display color space directly.
The result is still not good. My mac version app is significantly slower than Windows version.
Anyone can tell me why?
/// QT 4.8's source code modified by me
CGColorSpaceRef QCoreGraphicsPaintEngine::macGenericColorSpace()
{
#if 0
if (!m_genericColorSpace) {
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) {
m_genericColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
} else
#endif
{
m_genericColorSpace = CGColorSpaceCreateDeviceRGB();
}
if (!m_postRoutineRegistered) {
m_postRoutineRegistered = true;
qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces);
}
}
return m_genericColorSpace;
#else
// Just return the main display colorspace for the moment.
// return macDisplayColorSpace();
return CreateSystemColorSpace();
#endif
}
CGColorSpaceRef CreateSystemColorSpace () {
CMProfileRef sysprof = NULL;
CGColorSpaceRef dispColorSpace = NULL;
// Get the Systems Profile for the main display
if (CMGetSystemProfile(&sysprof) == noErr)
{
// Create a colorspace with the systems profile
dispColorSpace = CGColorSpaceCreateWithPlatformColorSpace(sysprof);
// Close the profile
CMCloseProfile(sysprof);
}
return dispColorSpace;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论