Nokia N97 SDK
Example Applications Guide

CShadowsContainer Class Reference

#include <ShadowsContainer.h>

Inheritance diagram for CShadowsContainer:

List of all members.

Detailed Description

Container control class that handles the OpenGL ES initialization and deinitializations. Also uses the CShadow class to do the actual OpenGL ES rendering.

Definition at line 29 of file ShadowsContainer.h.


Public Member Functions

void  ConstructL (const TRect &aRect, CAknAppUi *aAppUi)
virtual  ~CShadowsContainer ()

Static Public Member Functions

static int  DrawCallBack (TAny *aInstance)

Public Attributes

CShadows *  iShadows

Private Member Functions

void  SizeChanged ()
void  HandleResourceChange (TInt aType)
TInt  CountComponentControls () const
CCoeControl *  ComponentControl (TInt aIndex) const
void  Draw (const TRect &aRect) const
void  HandleControlEventL (CCoeControl *aControl, TCoeEvent aEventType)

Private Attributes

EGLDisplay  iEglDisplay
EGLSurface  iEglSurface
EGLContext  iEglContext
CPeriodic *  iPeriodic
TBool  iOpenGlInitialized
TInt  iFrame
CAknAppUi *  iAppUi


Constructor & Destructor Documentation

CShadowsContainer::~CShadowsContainer (   )  [virtual]
 

Destructor. Destroys the CPeriodic, CShadow and uninitializes OpenGL ES.

Definition at line 203 of file ShadowsContainer.cpp.

References CShadows::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iShadows.

00204     {
00205     delete iPeriodic;
00206 
00207     /* AppExit call is made to release
00208        any allocations made in AppInit. */
00209     if ( iShadows )
00210         {
00211         iShadows->AppExit();
00212         delete iShadows;
00213         }
00214 
00215     eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
00216     eglDestroySurface( iEglDisplay, iEglSurface );
00217     eglDestroyContext( iEglDisplay, iEglContext );
00218     eglTerminate( iEglDisplay );                   // Release resources associated
00219                                                    // with EGL and OpenGL ES
00220     }


Member Function Documentation

void CShadowsContainer::ConstructL (  const TRect &  aRect,
CAknAppUi *  aAppUi
) 
 

EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.

Parameters:
aRect  Screen rectangle for container.

Definition at line 24 of file ShadowsContainer.cpp.

References CShadows::AppInit(), DrawCallBack(), iAppUi, iEglContext, iEglDisplay, iEglSurface, iFrame, iOpenGlInitialized, iPeriodic, iShadows, and CShadows::NewL().

Referenced by CShadowsAppUi::ConstructL().

00025     {
00026     iAppUi = aAppUi;
00027     iOpenGlInitialized = EFalse;
00028     CreateWindowL();
00029 
00030     // Do not go to full-screen in touch devices.    
00031     if (AknLayoutUtils::PenEnabled())
00032     {
00033         SetRect(aRect);
00034     }
00035     else
00036     {
00037         SetExtentToWholeScreen();                // Take the whole screen into use
00038     }
00039     ActivateL();
00040 
00041 
00042     iFrame = 0;                              // Frame counter
00043 
00044     EGLConfig Config;                        // Describes the format, type and
00045                                              // size of the color buffers and
00046                                              // ancillary buffers for EGLSurface
00047 
00048     // Get the display for drawing graphics
00049     iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
00050     if ( iEglDisplay == NULL )
00051         {
00052         _LIT(KGetDisplayFailed, "eglGetDisplay failed");
00053         User::Panic( KGetDisplayFailed, 0 );
00054         }
00055 
00056     // Initialize display
00057     if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE )
00058         {
00059         _LIT(KInitializeFailed, "eglInitialize failed");
00060         User::Panic( KInitializeFailed, 0 );
00061         }
00062 
00063     EGLConfig *configList = NULL;            // Pointer for EGLConfigs
00064     EGLint numOfConfigs = 0;
00065     EGLint configSize   = 0;
00066 
00067     // Get the number of possible EGLConfigs
00068     if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs )
00069         == EGL_FALSE )
00070         {
00071         _LIT(KGetConfigsFailed, "eglGetConfigs failed");
00072         User::Panic( KGetConfigsFailed, 0 );
00073         }
00074 
00075     configSize = numOfConfigs;
00076 
00077     // Allocate memory for the configList
00078     configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize );
00079     if ( configList == NULL )
00080         {
00081         _LIT(KConfigAllocFailed, "config alloc failed");
00082         User::Panic( KConfigAllocFailed, 0 );
00083         }
00084 
00085     /* Define properties for the wanted EGLSurface.
00086        To get the best possible performance, choose
00087        an EGLConfig with a buffersize matching
00088        the current window's display mode*/
00089     TDisplayMode DMode = Window().DisplayMode();
00090     TInt BufferSize = 0;
00091 
00092     switch ( DMode )
00093          {
00094          case(EColor4K):
00095              BufferSize = 12;
00096              break;
00097          case(EColor64K):
00098              BufferSize = 16;
00099              break;
00100          case(EColor16M):
00101              BufferSize = 24;
00102              break;
00103          case(EColor16MU):
00104                      case(EColor16MA):
00105              BufferSize = 32;
00106              break;
00107          default:
00108              _LIT(KDModeError,       "unsupported displaymode");
00109              User::Panic( KDModeError, 0 );
00110              break;
00111          }
00112 
00113     // Define properties for requesting a full-screen antialiased window surface
00114     const EGLint attrib_list_fsaa[] =
00115         {
00116                                 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
00117         EGL_BUFFER_SIZE,  BufferSize,
00118         EGL_DEPTH_SIZE,   16,
00119                                 EGL_SAMPLE_BUFFERS, 1,
00120                                 EGL_SAMPLES,        4,
00121         EGL_NONE
00122         };
00123 
00124     // Define properties for requesting a non-antialiased window surface
00125     const EGLint attrib_list[] =
00126         {
00127                                 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
00128         EGL_BUFFER_SIZE,  BufferSize,
00129         EGL_DEPTH_SIZE,   16,
00130         EGL_NONE
00131         };
00132 
00133     // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa
00134     if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00135         {
00136         _LIT( KChooseConfigFailed, "eglChooseConfig failed" );
00137         User::Panic( KChooseConfigFailed, 0 );
00138         }
00139 
00140     // Check if no configurations were found
00141     if ( numOfConfigs == 0 )
00142         {
00143         // No configs with antialising were found. Try to get the non-antialiased config
00144                     if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00145                               {
00146                   _LIT( KChooseConfigFailed, "eglChooseConfig failed" );
00147                   User::Panic( KChooseConfigFailed, 0 );
00148                               }
00149 
00150                     if ( numOfConfigs == 0 )
00151                               {
00152                               // No configs found without antialiasing
00153                   _LIT( KNoConfig, "Can't find the requested config." );
00154                   User::Panic( KNoConfig, 0 );
00155                   }
00156               }
00157 
00158     Config = configList[0];   // Choose the best EGLConfig. EGLConfigs
00159                               // returned by eglChooseConfig are sorted so
00160                               // that the best matching EGLConfig is first in
00161                               // the list.
00162     User::Free( configList ); // Free configList, not used anymore.
00163 
00164     // Create a window where the graphics are blitted
00165     iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL );
00166     if ( iEglSurface == NULL )
00167         {
00168         _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed");
00169         User::Panic( KCreateWindowSurfaceFailed, 0 );
00170         }
00171 
00172     // Create a rendering context
00173     iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL );
00174     if ( iEglContext == NULL )
00175         {
00176         _LIT(KCreateContextFailed, "eglCreateContext failed");
00177         User::Panic( KCreateContextFailed, 0 );
00178         }
00179 
00180     /* Make the context current. Binds context to the current rendering thread
00181        and surface.*/
00182     if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext )
00183         == EGL_FALSE )
00184         {
00185         _LIT(KMakeCurrentFailed, "eglMakeCurrent failed");
00186         User::Panic( KMakeCurrentFailed, 0 );
00187         }
00188 
00189     TSize size;
00190     size = this->Size();
00191 
00192     iShadows = CShadows::NewL( size.iWidth, size.iHeight );
00193     iShadows->AppInit();
00194 
00195     iOpenGlInitialized = ETrue;
00196 
00197     iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for
00198                                                            // animating the scene
00199     iPeriodic->Start( 100, 100, TCallBack( DrawCallBack, this ) );
00200 }

int CShadowsContainer::DrawCallBack (  TAny *  aInstance  )  [static]
 

Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CShadow to do the rendering for each frame.

Parameters:
aInstance  Pointer to this instance of CShadowsContainer.

Definition at line 296 of file ShadowsContainer.cpp.

References CShadows::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iShadows.

Referenced by ConstructL().

00297     {
00298     CShadowsContainer* instance = (CShadowsContainer*) aInstance;
00299     instance->iFrame++;
00300 
00301     // Call the main OpenGL ES Symbian rendering 'loop'
00302     instance->iShadows->AppCycle( instance->iFrame );
00303 
00304     // Call eglSwapBuffers, which blit the graphics to the window
00305     eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface );
00306 
00307     // To keep the background light on
00308     if ( !(instance->iFrame%100) )
00309         {
00310         User::ResetInactivityTime();
00311         }
00312 
00313     /* Suspend the current thread for a short while. Give some time
00314        to other threads and AOs, avoids the ViewSrv error in ARMI and
00315        THUMB release builds. One may try to decrease the callback
00316        function instead of this. */
00317     if ( !(instance->iFrame%50) )
00318         {
00319         User::After(0);
00320         }
00321     return 0;
00322     }

void CShadowsContainer::SizeChanged (   )  [private]
 

Method from CoeControl that gets called when the display size changes. If OpenGL has been initialized, notifies the renderer class that the screen size has changed.

Definition at line 227 of file ShadowsContainer.cpp.

References iOpenGlInitialized, iShadows, and CShadows::SetScreenSize().

00228     {
00229     if( iOpenGlInitialized && iShadows )
00230         {
00231         TSize size;
00232         size = this->Size();
00233 
00234         iShadows->SetScreenSize( size.iWidth, size.iHeight );
00235         }
00236     }

void CShadowsContainer::HandleResourceChange (  TInt  aType  )  [private]
 

Handles a change to the control's resources. This method reacts to the KEikDynamicLayoutVariantSwitch event (that notifies of screen size change) by calling the SetExtentToWholeScreen() again so that this control fills the new screen size. This will then trigger a call to the SizeChanged() method.

Parameters:
aType  Message UID value, only KEikDynamicLayoutVariantSwitch is handled by this method.

Definition at line 246 of file ShadowsContainer.cpp.

References iAppUi.

00247     {
00248         switch( aType )
00249         {
00250             case KEikDynamicLayoutVariantSwitch:
00251                 // Do not go full-screen in touch devices.    
00252             if (AknLayoutUtils::PenEnabled())
00253             {
00254                 SetRect(iAppUi->ClientRect());
00255             }
00256             else
00257             {
00258                 SetExtentToWholeScreen();                // Take the whole screen into use
00259             }
00260                 break;
00261             }
00262     }

TInt CShadowsContainer::CountComponentControls (   )  const [private]
 

Method from CoeControl. Does nothing in this implementation.

Definition at line 268 of file ShadowsContainer.cpp.

00269     {
00270     return 0; // return nbr of controls inside this container
00271     }

CCoeControl * CShadowsContainer::ComponentControl (  TInt  aIndex  )  const [private]
 

Method from CCoeControl. Does nothing in this implementation.

Definition at line 277 of file ShadowsContainer.cpp.

00278     {
00279     return NULL;
00280     }

void CShadowsContainer::Draw (  const TRect &  aRect  )  const [private]
 

Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method.

Definition at line 286 of file ShadowsContainer.cpp.

00287     {
00288     // No need to implement anything here!
00289     }

void CShadowsContainer::HandleControlEventL (  CCoeControl *  aControl,
TCoeEvent  aEventType
)  [private]
 

Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.

Parameters:
aControl  Control changing its state.
aEventType  Type of the control event.

Definition at line 328 of file ShadowsContainer.cpp.

00330     {
00331     }


Member Data Documentation

EGLDisplay CShadowsContainer::iEglDisplay [private]
 

Display where the OpenGL ES window surface resides.

Definition at line 99 of file ShadowsContainer.h.

Referenced by ConstructL(), DrawCallBack(), and ~CShadowsContainer().

EGLSurface CShadowsContainer::iEglSurface [private]
 

Window surface where the OpenGL ES rendering is blitted to.

Definition at line 102 of file ShadowsContainer.h.

Referenced by ConstructL(), DrawCallBack(), and ~CShadowsContainer().

EGLContext CShadowsContainer::iEglContext [private]
 

OpenGL ES rendering context.

Definition at line 105 of file ShadowsContainer.h.

Referenced by ConstructL(), and ~CShadowsContainer().

CPeriodic* CShadowsContainer::iPeriodic [private]
 

Active object that is the timing source for the animation.

Definition at line 108 of file ShadowsContainer.h.

Referenced by ConstructL(), and ~CShadowsContainer().

TBool CShadowsContainer::iOpenGlInitialized [private]
 

Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications.

Definition at line 114 of file ShadowsContainer.h.

Referenced by ConstructL(), and SizeChanged().

TInt CShadowsContainer::iFrame [private]
 

Frame counter variable, used in the animation.

Definition at line 117 of file ShadowsContainer.h.

Referenced by ConstructL(), and DrawCallBack().

CAknAppUi* CShadowsContainer::iAppUi [private]
 

Application UI class for querying the client rectangle size.

Definition at line 120 of file ShadowsContainer.h.

Referenced by ConstructL(), and HandleResourceChange().

CShadows* CShadowsContainer::iShadows
 

Used in DrawCallBack() method to do the actual OpenGL ES rendering.

Definition at line 125 of file ShadowsContainer.h.

Referenced by ConstructL(), DrawCallBack(), CShadowsAppUi::HandleKeyEventL(), SizeChanged(), and ~CShadowsContainer().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top