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

Definition at line 29 of file Slideshowcontainer.h.
Public Member Functions |
|
| void | ConstructL (const TRect &aRect, CAknAppUi *aAppUi) |
| virtual | ~CSlideshowContainer () |
Static Public Member Functions |
|
| static TInt | DrawCallBack (TAny *aInstance) |
| static TTime | GetTimeTick () |
Public Attributes |
|
| CSlideshow * | iSlideshow |
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 |
| TUint32 | iStartTimeTicks |
| TUint32 | iLastFrameTimeSecs |
| TReal | iSecondsPerFrame |
| TInt | iFrame |
| CAknAppUi * | iAppUi |
|
|
Destructor. Destroys the CPeriodic, CSlideshow and uninitializes OpenGL ES. Definition at line 188 of file Slideshowcontainer.cpp. References CSlideshow::AppExit(), iEglContext, iEglDisplay, iEglSurface, iPeriodic, and iSlideshow. 00189 { 00190 delete iPeriodic; 00191 00192 /* AppExit call is made to release any allocations made in AppInit. 00193 This call has to be made here before we destroy the rendering context. */ 00194 if ( iSlideshow ) 00195 { 00196 iSlideshow->AppExit(); 00197 delete iSlideshow; 00198 } 00199 00200 eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); 00201 eglDestroySurface( iEglDisplay, iEglSurface ); 00202 eglDestroyContext( iEglDisplay, iEglContext ); 00203 eglTerminate( iEglDisplay ); 00204 }
|
|
||||||||||||
|
Second phase constructor that can call methods that may leave. Initializes the OpenGL ES for rendering to the window surface.
Definition at line 24 of file Slideshowcontainer.cpp. References iAppUi, iEglDisplay, and iOpenGlInitialized. Referenced by CSlideshowAppUi::ConstructL(). 00025 { 00026 iAppUi = aAppUi; 00027 // Open GL hasn't been initialized 00028 iOpenGlInitialized = EFalse; 00029 00030 // Create the native window 00031 CreateWindowL(); 00032 00033 // Do not go to full-screen in touch devices. 00034 if (AknLayoutUtils::PenEnabled()) 00035 { 00036 SetRect(aRect); 00037 } 00038 else 00039 { 00040 SetExtentToWholeScreen(); // Take the whole screen into use 00041 } 00042 ActivateL(); 00043 00044 // Describes the format, type and size of the color buffers and 00045 // ancillary buffers for EGLSurface 00046 EGLConfig config; 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 // Pointer for EGLConfigs 00064 EGLConfig *configList = NULL; 00065 EGLint numOfConfigs = 0; 00066 EGLint configSize = 0; 00067 00068 // Get the number of possible EGLConfigs 00069 if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == 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. To get the best possible 00086 // performance, choose an EGLConfig with a buffersize matching the current 00087 // window's display mode 00088 TDisplayMode DMode = Window().DisplayMode(); 00089 TInt BufferSize = 0; 00090 00091 switch(DMode) 00092 { 00093 case(EColor4K): 00094 BufferSize = 12; 00095 break; 00096 case(EColor64K): 00097 BufferSize = 16; 00098 break; 00099 case(EColor16M): 00100 BufferSize = 24; 00101 break; 00102 case(EColor16MU): 00103 case(EColor16MA): 00104 BufferSize = 32; 00105 break; 00106 default: 00107 _LIT(KDModeError, "unsupported displaymode"); 00108 User::Panic( KDModeError, 0 ); 00109 break; 00110 } 00111 00112 // Define properties for the wanted EGLSurface 00113 const EGLint attrib_list[] = 00114 { 00115 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 00116 EGL_BUFFER_SIZE, BufferSize, 00117 EGL_DEPTH_SIZE, 16, 00118 EGL_NONE 00119 }; 00120 00121 // Choose an EGLConfig that best matches to the properties in attrib_list 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 // Check if no configurations were found 00129 if ( numOfConfigs == 0 ) 00130 { 00131 _LIT(KNoConfig, "Can't find the requested config."); 00132 User::Panic( KNoConfig, 0 ); 00133 } 00134 00135 // Choose the best EGLConfig. EGLConfigs returned by eglChooseConfig are 00136 // sorted so that the best matching EGLConfig is first in the list. 00137 config = configList[0]; 00138 00139 // Free configList, as it's not used anymore. 00140 User::Free( configList ); 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 ) == EGL_FALSE ) 00161 { 00162 _LIT(KMakeCurrentFailed, "eglMakeCurrent failed"); 00163 User::Panic( KMakeCurrentFailed, 0 ); 00164 } 00165 00166 00167 TSize size; 00168 size = this->Size(); 00169 iSlideshow = CSlideshow::NewL( size.iWidth, size.iHeight ); 00170 iSlideshow->AppInitL(); 00171 00172 iOpenGlInitialized = ETrue; 00173 00174 // Reset counters 00175 iFrame = 0; 00176 iStartTimeTicks = User::NTickCount(); 00177 00178 // Create an active object for animating the scene 00179 iPeriodic = CPeriodic::NewL( CActive::EPriorityIdle ); 00180 iPeriodic->Start( 100, 100, TCallBack( CSlideshowContainer::DrawCallBack, this ) ); 00181 }
|
|
|
Callback function for the CPeriodic. Calculates the current frame, keeps the background light from turning off and orders the CSlideshow to do the rendering for each frame.
Definition at line 312 of file Slideshowcontainer.cpp. References CSlideshow::AppCycle(), iEglDisplay, iEglSurface, iFrame, iLastFrameTimeSecs, iSlideshow, and iStartTimeTicks. 00313 { 00314 CSlideshowContainer* instance = (CSlideshowContainer*) aInstance; 00315 // Update the frame counts 00316 instance->iFrame++; 00317 00318 // Compute the elapsed time in seconds since the startup of the example 00319 #ifdef __WINS__ 00320 00321 // In the emulator the tickcount runs at 200Hz 00322 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 200.f; 00323 00324 #else 00325 00326 // In the device the tickcount runs at 1000hz (as intended) 00327 GLfloat timeSecs = ( (GLfloat) ( User::NTickCount() - instance->iStartTimeTicks ) ) / 1000.f; 00328 00329 #endif 00330 00331 // Compute the elapsed time since last frame was drawn. Note that due to the 00332 // resolution of the system timer this value can be 0.0 even though new frames are being rendered. 00333 // This applies especially when running the emulator on a PC. 00334 GLfloat deltaTimeSecs = instance->iLastFrameTimeSecs - timeSecs; 00335 00336 // Set the current time to be the last frame time for the upcoming frame 00337 instance->iLastFrameTimeSecs = timeSecs; 00338 00339 if ( instance->iSlideshow->GetState() == CSlideshow::ERunning ) 00340 { 00341 // Call the main OpenGL ES Symbian rendering 'loop' 00342 instance->iSlideshow->AppCycle( instance->iFrame, timeSecs, deltaTimeSecs ); 00343 00344 // Call eglSwapBuffers, which blit the graphics to the window 00345 eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface ); 00346 00347 // Suspend the current thread for a short while. Give some time 00348 // to other threads and AOs, avoids the ViewSrv error in ARMI and 00349 // THUMB release builds. One may try to decrease the callback 00350 // function instead of this. 00351 if ( !(instance->iFrame % 50) ) 00352 { 00353 // Reset inactivity timer to keep the background light on 00354 User::ResetInactivityTime(); 00355 00356 User::After(0); 00357 } 00358 } 00359 00360 return 0; 00361 }
|
|
|
Returns the current system time.
Definition at line 299 of file Slideshowcontainer.cpp.
|
|
|
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 211 of file Slideshowcontainer.cpp. References iOpenGlInitialized, iSlideshow, and CSlideshow::SetScreenSize(). 00212 { 00213 if( iOpenGlInitialized && iSlideshow ) 00214 { 00215 TSize size; 00216 size = this->Size(); 00217 00218 iSlideshow->SetScreenSize( size.iWidth, size.iHeight ); 00219 } 00220 }
|
|
|
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 230 of file Slideshowcontainer.cpp. References iAppUi. 00231 { 00232 switch( aType ) 00233 { 00234 case KEikDynamicLayoutVariantSwitch: 00235 // Do not go full-screen in touch devices. 00236 if (AknLayoutUtils::PenEnabled()) 00237 { 00238 SetRect(iAppUi->ClientRect()); 00239 } 00240 else 00241 { 00242 SetExtentToWholeScreen(); // Take the whole screen into use 00243 } 00244 break; 00245 } 00246 }
|
|
|
Method from CoeControl. Does nothing in this implementation. Definition at line 253 of file Slideshowcontainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. Definition at line 262 of file Slideshowcontainer.cpp.
|
|
|
Method from CCoeControl. Does nothing in this implementation. All rendering is done in the DrawCallBack() method. Definition at line 271 of file Slideshowcontainer.cpp. References iSlideshow. 00272 { 00273 CWindowGc& gc = SystemGc(); 00274 gc.Clear( aRect ); 00275 00276 if ( iSlideshow->GetState() == CSlideshow::ELoadingTextures ) 00277 { 00278 _LIT(KLoading, "Loading..."); 00279 utilOutputText(SystemGc(), KLoading, TPoint(Size().iWidth / 2, Size().iHeight / 2), KRgbBlack ); 00280 } 00281 }
|
|
||||||||||||
|
Method from MCoeControlObserver that handles an event from the observed control. Does nothing in this implementation.
Definition at line 288 of file Slideshowcontainer.cpp.
|
|
|
Display where the OpenGL ES window surface resides. Definition at line 106 of file Slideshowcontainer.h. Referenced by ConstructL(), DrawCallBack(), and ~CSlideshowContainer(). |
|
|
Window surface where the OpenGL ES rendering is blitted to. Definition at line 108 of file Slideshowcontainer.h. Referenced by DrawCallBack(), and ~CSlideshowContainer(). |
|
|
OpenGL ES rendering context. Definition at line 110 of file Slideshowcontainer.h. Referenced by ~CSlideshowContainer(). |
|
|
Active object that is the timing source for the animation. Definition at line 112 of file Slideshowcontainer.h. Referenced by ~CSlideshowContainer(). |
|
|
Flag that indicates if OpenGL ES has been initialized or not. Used to check if SizeChanged() can react to incoming notifications. Definition at line 117 of file Slideshowcontainer.h. Referenced by ConstructL(), and SizeChanged(). |
|
|
Time when the example started running (rendering frames). Definition at line 120 of file Slideshowcontainer.h. Referenced by DrawCallBack(). |
|
|
Time when the previous frame was rendered. Definition at line 122 of file Slideshowcontainer.h. Referenced by DrawCallBack(). |
|
|
Current average seconds per frame. Used to interpolated during frames when the internal clock hasn't updated. Definition at line 124 of file Slideshowcontainer.h. |
|
|
Counts the number of frames rendered. Definition at line 126 of file Slideshowcontainer.h. Referenced by DrawCallBack(). |
|
|
Application UI class for querying the client rectangle size. Definition at line 129 of file Slideshowcontainer.h. Referenced by ConstructL(), and HandleResourceChange(). |
|
|
Used in DrawCallBack() method to do the actual OpenGL ES rendering. Definition at line 134 of file Slideshowcontainer.h. Referenced by Draw(), DrawCallBack(), CSlideshowAppUi::HandleKeyEventL(), SizeChanged(), and ~CSlideshowContainer(). |
|
© Nokia 2009 |