📄 snowcontainer.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include "SnowContainer.h"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CSnowContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSnowContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetExtentToWholeScreen(); // Take the whole screen into use
ActivateL();
iFrame = 0; // Initialize frame counter
EGLConfig config; // Describes the format, type and
// size of the color buffers and
// ancillary buffers for EGLSurface
/* Get the display for drawing graphics*/
iEglDisplay = eglGetDisplay( NULL );
if ( iEglDisplay == NULL )
{
_LIT(KGetDisplayFailed, "eglGetDisplay failed");
User::Panic( KGetDisplayFailed, 0 );
}
/* Initialize display */
if ( eglInitialize( iEglDisplay, NULL, NULL ) == EGL_FALSE )
{
_LIT(KInitializeFailed, "eglInitialize failed");
User::Panic( KInitializeFailed, 0 );
}
EGLConfig *configList = NULL; // Pointer for EGLConfigs
EGLint numOfConfigs = 0;
EGLint configSize = 0;
/* Get the number of possible EGLConfigs */
if ( eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs ) == EGL_FALSE )
{
_LIT(KGetConfigsFailed, "eglGetConfigs failed");
User::Panic( KGetConfigsFailed, 0 );
}
configSize = numOfConfigs;
/* Allocate memory for the configList */
configList = (EGLConfig*) User::Alloc( sizeof(EGLConfig)*configSize );
if ( configList == NULL )
{
_LIT(KConfigAllocFailed, "config alloc failed");
User::Panic( KConfigAllocFailed, 0 );
}
/* Define properties for the wanted EGLSurface.
To get the best possible performance, choose
an EGLConfig with a buffersize matching
the current window's display mode*/
TDisplayMode DMode = Window().DisplayMode();
TInt BufferSize = 0;
switch(DMode)
{
case(EColor4K):
BufferSize = 12;
break;
case(EColor64K):
BufferSize = 16;
break;
case(EColor16M):
BufferSize = 24;
break;
case(EColor16MU):
BufferSize = 18;
break;
default:
_LIT(KDModeError, "unsupported displaymode");
User::Panic( KDModeError, 0 );
break;
}
const EGLint attrib_list[] =
{
EGL_BUFFER_SIZE, BufferSize,
EGL_DEPTH_SIZE, 16,
EGL_NONE
};
/* Choose an EGLConfig that best matches to the properties in attrib_list */
if ( eglChooseConfig( iEglDisplay, attrib_list, configList, configSize, &numOfConfigs ) == EGL_FALSE )
{
_LIT(KChooseConfigFailed, "eglChooseConfig failed");
User::Panic( KChooseConfigFailed, 0 );
}
if ( numOfConfigs == 0 )
{
_LIT(KNoConfig, "Can't find the requested config.");
User::Panic( KNoConfig, 0 );
}
config = configList[0]; // Choose the best EGLConfig. EGLConfigs
// returned by eglChooseConfig are sorted so
// that the best matching EGLConfig is first in
// the list.
User::Free( configList ); // Free configList, not used anymore.
/* Create a window where the graphics are blitted */
iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(), NULL );
if ( iEglSurface == NULL )
{
_LIT(KCreateWindowSurfaceFailed, "eglCreateWindowSurface failed");
User::Panic( KCreateWindowSurfaceFailed, 0 );
}
/* Create a rendering context */
iEglContext = eglCreateContext( iEglDisplay, config, NULL, NULL );
if ( iEglContext == NULL )
{
_LIT(KCreateContextFailed, "eglCreateContext failed");
User::Panic( KCreateContextFailed, 0 );
}
/* Make the context current. Binds context to the current rendering thread
and surface.*/
if ( eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext ) == EGL_FALSE )
{
_LIT(KMakeCurrentFailed, "eglMakeCurrent failed");
User::Panic( KMakeCurrentFailed, 0 );
}
iSnow = CSnow::NewL( aRect.Width(), aRect.Height());
iSnow->AppInitL();
iPeriodic = CPeriodic::NewL( -100 ); // Create an active object for
// animating the scene
iPeriodic->Start( 100, 100, TCallBack( CSnowContainer::DrawCallBack, this ) );
}
// Destructor
CSnowContainer::~CSnowContainer()
{
delete iPeriodic;
/* AppExit call is made to release any allocations made in AppInit.
This call has to be made here before we destroy the rendering context. */
if ( iSnow )
{
iSnow->AppExit();
delete iSnow;
}
eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
eglDestroySurface( iEglDisplay, iEglSurface );
eglDestroyContext( iEglDisplay, iEglContext );
eglTerminate( iEglDisplay ); // Release resources associated
}
// ---------------------------------------------------------
// CSnowContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSnowContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
}
// ---------------------------------------------------------
// CSnowContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSnowContainer::CountComponentControls() const
{
return 0; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSnowContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSnowContainer::ComponentControl(TInt /*aIndex*/) const
{
return NULL;
}
// ---------------------------------------------------------
// CSnowContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSnowContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear( aRect );
if ( iSnow->GetState() == CSnow::ELoadingTextures )
{
_LIT(KLoading, "Loading...");
Utils::OutputText(SystemGc(), KLoading, TPoint(70, 105), KRgbBlack );
}
}
// ---------------------------------------------------------
// CSnowContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSnowContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
// ---------------------------------------------------------
// CSnowContainer::DrawCallBack( TAny* aInstance )
// Called by the CPeriodic in order to draw the graphics
// ---------------------------------------------------------
//
TInt CSnowContainer::DrawCallBack( TAny* aInstance )
{
CSnowContainer* instance = (CSnowContainer*) aInstance;
if ( instance->iSnow->GetState() == CSnow::ERunning )
{
instance->iFrame++;
/* Call the main OpenGL ES Symbian rendering 'loop' */
instance->iSnow->AppCycle( instance->iFrame );
/* Call eglSwapBuffers, which blit the graphics to the window */
eglSwapBuffers( instance->iEglDisplay, instance->iEglSurface );
/* To keep the background light on */
User::ResetInactivityTime();
/* Suspend the current thread for a short while. Give some time
to other threads and AOs, avoids the ViewSrv error in ARMI and
THUMB release builds. One may try to decrease the callback
function instead of this. */
if ( !(instance->iFrame % 50) )
{
User::After(0);
}
}
return 0;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -