6.8 Direct Draw
Drawing onto the screen using the window server requires a context
switch, which slows down drawing speed. 要绕开window
server,就要摆脱掉context switch,应用程序可以直接访问屏幕,这被称为direct drawing:
在SymbianOS中,有3个方法可以直接来绘制屏幕:
1、Creating and using CFbsScreenDevice.
2、直接访问屏幕内存区.
3、使用CDirectScreenAccess.
CFbsScreenDevice是一个graphics device,可以直接寻址到一个screen
driver,SCDV.DLL,在为其生成一个CFbsBitGc后,就可以象其他的graphics
device一样使用了。不管怎么说这里可以避开window server直接操作到屏幕上。
更快点的方法是访问屏幕内存地址,并通过一个指针来直接操作:
void CMyGameView::FillScreenDirectly() const
{
TPckgBuf<TScreenInfoV01> infoPckg;
TScreenInfoV01& screenInfo = infoPckg();
UserSvr::ScreenInfo(infoPckg);
TUint16* screenMemory = (TUint16*) screenInfo.iScreenAddress +
16;
for(TInt y = 0; y < screenInfo.iScreenSize.iHeight; y++)
{
for(TInt x = 0; x < screenInfo.iScreenSize.iWidth; x++)
{
*screenMemory++ = 0;
}
}
}
屏幕内存有一个32byte的header,操作时要注意。
尽管直接写屏幕内存比操作CFbsScreenDevice更快点,但具体的功能还因硬件和屏幕
设备的驱动而不同,在有些symbian设备中,当屏幕内存发生变化时就自动更新,有些则需要明确的指出变化。
上面将的屏幕内存地址只有在目标机器才是有效的,因此绘制代码在硬件和模拟器上都是不同的,You can solve this
problem by using a temporary bitmap and its da