Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to draw and update the screen directly by accessing the screen memory

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: mudhalvan (28 Jun 2007)
Last edited: hamishwillee (18 Sep 2012)

There are 3 ways of bypassing the window server and drawing to the screen directly( which is called Direct drawing ). This makes the drawing process to be faster which is commonly used in Gaming applications. One among the 3 ways of direct drawing is, accessing the screen memory directly and drawing to the screen by editing the memory address.

The UserSvr::ScreenInfo() API provides the screen address in the form of TScreenInfoV01 package. Here is the code snippet for getting the screen memory address and draw a simple rectangle directly to the screen.

          TPckgBuf<TScreenInfoV01> infoPckg;
          TScreenInfoV01& screenInfo = infoPckg();
          UserSvr::ScreenInfo(infoPckg);
          TUint16* screenMemory = (TUint16*) screenInfo.iScreenAddress + 16;
          for (int j = 80; j < 140; j++)
          { 
             for (int i = 0; i < 176; i++)
                { 
                   *(screenMemory + 2*(16 + i + j*176)) = i/8 + j; 
                }
          }

Once when the drawing is completed, the screen should be updated such that the changes made to the screen memory will be reflected on the screen. The general way of doing this is by adding a redraw event( TRawEvent::ERedraw ) to the system queue using UserSvr::AddEvent() API, which updates the screen immediately. The code snippet for doing this is as follows:

          TRawEvent redraw;
          redraw.Set(TRawEvent::ERedraw);
          UserSvr::AddEvent(redraw);

But the TRawEvent::ERedraw is a event generated by the host OS ( typically by WM_PAINT ) which is meant for emulator environment( as per the S60 SDK help document ). However on S60 2nd edition devices, the screen gets updated properly by adding this event to the system queue. But S60 3rd Edition devices does not have any immediate effect after the Redraw event is added to the system queue. The screen is updated only after notifying the screen device about the out of date region(s), which is a known issue.

Also accessing the display memory with UserSvr::ScreenInfo() is deprecated from S60 3rd Edition onwards.

As a workaround solution, it is still possible to use the old drawing method and force the screen to update itself by specifying the out of date region using CFbsScreenDevice's Update() API. The code snippet for doing the same is as follows:

          CFbsScreenDevice* iMyScreenDev = CFbsScreenDevice::NewL(0 ,EColor64K); 
          // the screennumber will be 0 if phone supports single screen where as the 
          // displaymode can be as per your choice
          RRegion iMyregion;
          iMyregion.AddRect(TRect(0,0,240,320)); // the out of date rect region.
          iMyScreenDev->Update(iMyregion);
          iMyregion.Close();
This page was last modified on 18 September 2012, at 05:13.
69 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×