Nokia N97 SDK
Example Applications Guide

CPickSelectContainer Class Reference

#include <PickSelectContainer.h>

Inheritance diagram for CPickSelectContainer:

List of all members.

Detailed Description

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

Definition at line 29 of file PickSelectContainer.h.


Public Member Functions

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

Static Public Member Functions

static TInt  DrawCallBack (TAny *aInstance)

Public Attributes

CPickSelect *  iPickSelect

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

CPickSelectContainer::~CPickSelectContainer (   )  [virtual]
 

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

Definition at line 182 of file PickSelectContainer.cpp.

References CPickSelect::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iPickSelect.

00183     {
00184     delete iPeriodic;
00185 
00186     if ( iPickSelect )
00187         {
00188         /* AppExit call is made to release
00189            any allocations made in AppInit. */
00190         iPickSelect->AppExit();
00191         delete iPickSelect;
00192         }
00193 
00194     eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
00195     eglDestroySurface( iEglDisplay, iEglSurface );
00196     eglDestroyContext( iEglDisplay, iEglContext );
00197     eglTerminate( iEglDisplay );                   // Release resources associated
00198                                                    // with EGL and OpenGL ES
00199     }


Member Function Documentation

void CPickSelectContainer::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 PickSelectContainer.cpp.

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

Referenced by CPickSelectAppUi::ConstructL().

00025     {
00026     iAppUi = aAppUi;
00027     iOpenGlInitialized = EFalse;
00028 
00029     CreateWindowL();
00030 
00031     // Do not go to full-screen in touch devices.    
00032     if (AknLayoutUtils::PenEnabled())
00033     {
00034         SetRect(aRect);
00035     }
00036     else
00037     {
00038         SetExtentToWholeScreen();                // Take the whole screen into use
00039     }
00040     ActivateL();
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(KGetDisplayFailed, "eglGetDisplay failed");
00060         User::Panic( KGetDisplayFailed, 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     /*
00086        Define properties for the wanted EGLSurface.
00087        We need to choose a 32-bit framebuffer, since the picking
00088        method needs an 8-bit alpha channel.
00089      */
00090 
00091     // Define properties for requesting a full-screen antialiased window surface
00092     const EGLint attrib_list_fsaa[] =
00093         {
00094                                 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
00095         EGL_BUFFER_SIZE,  32,
00096         EGL_DEPTH_SIZE,   16,
00097                                 EGL_SAMPLE_BUFFERS, 1,
00098                                 EGL_SAMPLES,        4,
00099         EGL_NONE
00100         };
00101 
00102     // Define properties for requesting a non-antialiased window surface
00103     const EGLint attrib_list[] =
00104         {
00105                                 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
00106         EGL_BUFFER_SIZE,  32,
00107         EGL_DEPTH_SIZE,   16,
00108         EGL_NONE
00109         };
00110 
00111     // Choose an EGLConfig that best matches to the properties in attrib_list_fsaa
00112     if ( eglChooseConfig( iEglDisplay, attrib_list_fsaa, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00113         {
00114         _LIT( KChooseConfigFailed, "eglChooseConfig failed" );
00115         User::Panic( KChooseConfigFailed, 0 );
00116         }
00117 
00118     // Check if no configurations were found
00119     if ( numOfConfigs == 0 )
00120         {
00121         // No configs with antialising were found. Try to get the non-antialiased config
00122                     if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE )
00123                               {
00124                   _LIT( KChooseConfigFailed, "eglChooseConfig failed" );
00125                   User::Panic( KChooseConfigFailed, 0 );
00126                               }
00127 
00128                     if ( numOfConfigs == 0 )
00129                               {
00130                               // No configs found without antialiasing
00131                   _LIT( KNoConfig, "Can't find the requested config." );
00132                   User::Panic( KNoConfig, 0 );
00133                   }
00134               }
00135 
00136     Config = configList[0];  // Choose the best EGLConfig. EGLConfigs
00137                               // returned by eglChooseConfig are sorted so
00138                               // that the best matching EGLConfig is first in
00139                               // the list.
00140     User::Free( configList ); // Free configList, not used anymore.
00141 
00142     // Create a window where the graphics are blitted
00143     iEglSurface = eglCreateWindowSurface( iEglDisplay, Config, &Window(), NULL );
00144     if ( iEglSurface == NULL )
00145         {
00146         _LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed");
00147         User::Panic( KCreateWindowSurfaceFailed, 0 );
00148         }
00149 
00150     // Create a rendering context
00151     iEglContext = eglCreateContext( iEglDisplay, Config, EGL_NO_CONTEXT, NULL );
00152     if ( iEglContext == NULL )
00153         {
00154         _LIT(KCreateContextFailed, "eglCreateContext failed");
00155         User::Panic( KCreateContextFailed, 0 );
00156         }
00157 
00158     /* Make the context current. Binds context to the current rendering thread
00159        and surface.*/
00160     if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext )
00161         == EGL_FALSE )
00162         {
00163         _LIT(KMakeCurrentFailed, "eglMakeCurrent failed");
00164         User::Panic( KMakeCurrentFailed, 0 );
00165         }
00166 
00167     TSize size;
00168     size = this->Size();
00169 
00170     iPickSelect = CPickSelect::NewL( size.iWidth, size.iHeight ); // Create an instance of PickSelect
00171     iPickSelect->AppInit();                                // Initialize OpenGL ES
00172 
00173     iOpenGlInitialized = ETrue;
00174 
00175     iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); // Create an active object for
00176                                                            // animating the scene
00177     iPeriodic->Start( 100, 100,
00178                       TCallBack( CPickSelectContainer::DrawCallBack, this ) );
00179 }

TInt CPickSelectContainer::DrawCallBack (  TAny *  aInstance  )  [static]
 

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

Parameters:
aInstance  Pointer to this instance of CPickSelectContainer.

Definition at line 275 of file PickSelectContainer.cpp.

References CPickSelect::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iPickSelect.

Referenced by ConstructL().

00276     {
00277     CPickSelectContainer* instance = (CPickSelectContainer*) aInstance;
00278     instance->iFrame++;
00279 
00280     // Call the main OpenGL ES Symbian rendering 'loop'
00281     instance->iPickSelect->AppCycle( instance->iFrame );
00282 
00283     // Call eglSwapBuffers, which blit the graphics to the window
00284     eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface );
00285 
00286     // To keep the background light on
00287     if ( !(instance->iFrame%100) )
00288         {
00289         User::ResetInactivityTime();
00290         }
00291 
00292     /* Suspend the current thread for a short while. Give some time
00293        to other threads and AOs, avoids the ViewSrv error in ARMI and
00294        THUMB release builds. One may try to decrease the callback
00295        function instead of this. */
00296     if ( !(instance->iFrame%50) )
00297         {
00298         User::After(0);
00299         }
00300 
00301     return 0;
00302     }

void CPickSelectContainer::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 206 of file PickSelectContainer.cpp.

References iOpenGlInitialized, iPickSelect, and CPickSelect::SetScreenSize().

00207     {
00208     if( iOpenGlInitialized && iPickSelect )
00209         {
00210         TSize size;
00211         size = this->Size();
00212 
00213         iPickSelect->SetScreenSize( size.iWidth, size.iHeight );
00214         }
00215     }

void CPickSelectContainer::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 225 of file PickSelectContainer.cpp.

References iAppUi.

00226     {
00227         switch( aType )
00228         {
00229             case KEikDynamicLayoutVariantSwitch:
00230                 // Do not go full-screen in touch devices.    
00231             if (AknLayoutUtils::PenEnabled())
00232             {
00233                 SetRect(iAppUi->ClientRect());
00234             }
00235             else
00236             {
00237                 SetExtentToWholeScreen();                // Take the whole screen into use
00238             }
00239                 break;
00240             }
00241     }

TInt CPickSelectContainer::CountComponentControls (   )  const [private]
 

Method from CoeControl. Does nothing in this implementation.

Definition at line 247 of file PickSelectContainer.cpp.

00248     {
00249     return 0;
00250     }

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

Method from CCoeControl. Does nothing in this implementation.

Definition at line 256 of file PickSelectContainer.cpp.

00257     {
00258     return NULL;
00259     }

void CPickSelectContainer::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 265 of file PickSelectContainer.cpp.

00266     {
00267     // No need to implement anything here!
00268     }

void CPickSelectContainer::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 308 of file PickSelectContainer.cpp.

00310     {
00311     }


Member Data Documentation

EGLDisplay CPickSelectContainer::iEglDisplay [private]
 

Display where the OpenGL ES window surface resides.

Definition at line 99 of file PickSelectContainer.h.

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

EGLSurface CPickSelectContainer::iEglSurface [private]
 

Window surface where the OpenGL ES rendering is blitted to.

Definition at line 102 of file PickSelectContainer.h.

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

EGLContext CPickSelectContainer::iEglContext [private]
 

OpenGL ES rendering context.

Definition at line 105 of file PickSelectContainer.h.

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

CPeriodic* CPickSelectContainer::iPeriodic [private]
 

Active object that is the timing source for the animation.

Definition at line 108 of file PickSelectContainer.h.

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

TBool CPickSelectContainer::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 PickSelectContainer.h.

Referenced by ConstructL(), and SizeChanged().

TInt CPickSelectContainer::iFrame [private]
 

Frame counter variable, used in the animation.

Definition at line 117 of file PickSelectContainer.h.

Referenced by ConstructL(), and DrawCallBack().

CAknAppUi* CPickSelectContainer::iAppUi [private]
 

Application UI class for querying the client rectangle size.

Definition at line 120 of file PickSelectContainer.h.

Referenced by ConstructL(), and HandleResourceChange().

CPickSelect* CPickSelectContainer::iPickSelect
 

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

Definition at line 125 of file PickSelectContainer.h.

Referenced by ConstructL(), DrawCallBack(), CPickSelectAppUi::HandleCommandL(), CPickSelectAppUi::HandleKeyEventL(), SizeChanged(), and ~CPickSelectContainer().


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

© Nokia 2009

Back to top