|
Nokia N97 SDK Example Applications Guide |
#include <HierarchyContainer.h>
Inheritance diagram for CHierarchyContainer:

Definition at line 28 of file HierarchyContainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CHierarchyContainer () |
Static Public Member Functions |
|
| static int | DrawCallBack (TAny *aInstance) |
Public Attributes |
|
| CHierarchy * | iHierarchy |
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 |
|
|
Destructor. Destroys the CPeriodic, CHierarchy and uninitializes OpenGL ES. Definition at line 204 of file HierarchyContainer.cpp. References CHierarchy::AppExit(), iEglContext, iEglDisplay, iEglSurface, iHierarchy, and iPeriodic. 00205 { 00206 delete iPeriodic; 00207 00208 /* AppExit call is made to release 00209 any allocations made in AppInit. */ 00210 if ( iHierarchy ) 00211 { 00212 iHierarchy->AppExit(); 00213 delete iHierarchy; 00214 } 00215 00216 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00217 eglDestroySurface( iEglDisplay, iEglSurface ); 00218 eglDestroyContext( iEglDisplay, iEglContext ); 00219 eglTerminate( iEglDisplay ); // Release resources associated 00220 // with EGL and OpenGL ES 00221 }
|
|
||||||||||||
|
EPOC default constructor. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 24 of file HierarchyContainer.cpp. References CHierarchy::AppInit(), DrawCallBack(), iAppUi, iEglContext, iEglDisplay, iEglSurface, iFrame, iHierarchy, iOpenGlInitialized, iPeriodic, and CHierarchy::NewL(). Referenced by CHierarchyAppUi::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 /* 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 iHierarchy = CHierarchy::NewL( size.iWidth, size.iHeight ); 00193 iHierarchy->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, 00200 TCallBack( CHierarchyContainer::DrawCallBack, this ) ); 00201 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CHierarchy to do the rendering for each frame.
Definition at line 298 of file HierarchyContainer.cpp. References CHierarchy::AppCycle(), iEglDisplay, iEglSurface, iFrame, and iHierarchy. Referenced by ConstructL(). 00299 { 00300 CHierarchyContainer* instance = (CHierarchyContainer*) aInstance; 00301 instance->iFrame++; 00302 00303 // Call the main OpengGL ES Symbian rendering 'loop' 00304 instance->iHierarchy->AppCycle( instance->iFrame ); 00305 00306 // Call eglSwapBuffers, which blit the graphics to the window 00307 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00308 00309 // To keep the background light on 00310 if ( !(instance->iFrame%100) ) 00311 { 00312 User::ResetInactivityTime(); 00313 } 00314 00315 /* Suspend the current thread for a short while. Give some time 00316 to other threads and AOs, avoids the ViewSrv error in ARMI and 00317 THUMB release builds. One may try to decrease the callback 00318 function instead of this. */ 00319 if ( !(instance->iFrame%50) ) 00320 { 00321 User::After(0); 00322 } 00323 00324 return 0; 00325 }
|
|
|
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 228 of file HierarchyContainer.cpp. References iHierarchy, iOpenGlInitialized, and CHierarchy::SetScreenSize(). 00229 { 00230 if( iOpenGlInitialized && iHierarchy ) 00231 { 00232 TSize size; 00233 size = this->Size(); 00234 00235 iHierarchy->SetScreenSize( size.iWidth, size.iHeight ); 00236 } 00237 }
|
|
|
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.
Definition at line 247 of file HierarchyContainer.cpp. References iAppUi. 00248 { 00249 switch( aType ) 00250 { 00251 case KEikDynamicLayoutVariantSwitch: 00252 // Do not go full-screen in touch devices. 00253 if (AknLayoutUtils::PenEnabled()) 00254 { 00255 SetRect(iAppUi->ClientRect()); 00256 } 00257 else 00258 { 00259 SetExtentToWholeScreen(); // Take the whole screen into use 00260 } 00261 break; 00262 } 00263 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 270 of file HierarchyContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 279 of file HierarchyContainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 288 of file HierarchyContainer.cpp.
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 332 of file HierarchyContainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 98 of file HierarchyContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CHierarchyContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 101 of file HierarchyContainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CHierarchyContainer(). |
|
|
OpenGL ES rendering context. Definition at line 104 of file HierarchyContainer.h. Referenced by ConstructL(), and ~CHierarchyContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 107 of file HierarchyContainer.h. Referenced by ConstructL(), and ~CHierarchyContainer(). |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 113 of file HierarchyContainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Frame counter variable, used in the animation. Definition at line 116 of file HierarchyContainer.h. Referenced by ConstructL(), and DrawCallBack(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 119 of file HierarchyContainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 124 of file HierarchyContainer.h. Referenced by ConstructL(), DrawCallBack(), CHierarchyAppUi::HandleKeyEventL(), SizeChanged(), and ~CHierarchyContainer(). |
|
© Nokia 2009 |