bool
CVideoSettingsForm::SetVideoOptions( const CORE::CVideoOptions& options )
{GUCE_TRACE;

    m_videoOptions = options;
    
    if ( NULL != m_resolutionCombobox )
    {
        m_resolutionCombobox->ClearList();
        
        const CORE::CVideoOptions::TDisplayModeVector& modes = options.GetDisplayModes();
        GUCEF::GUI::CCombobox::TStringVector resList;
        for ( UInt32 i=0; i<modes.size(); ++i )
        {
            const CORE::CVideoOptions::TDisplayMode& displayMode = modes[ i ];
            resList.push_back( ParseDisplayMode( displayMode ) );
        }
        
        if ( m_resolutionCombobox->SetListItems( resList ) )
        {
            return true;
        }
    }
    
    return false;
}
bool
CVideoSettingsForm::SetVideoSettings( const CORE::CVideoSettings& settings )
{GUCE_TRACE;
    
    if ( NULL != m_fullscreenCheckbox ) 
    {
        m_fullscreenCheckbox->SetCheckedState( settings.GetFullscreenState() );
    }
    if ( NULL != m_vSyncCheckbox )
    {
        m_vSyncCheckbox->SetCheckedState( settings.GetVSyncState() );
    }
    if ( NULL != m_antiAliasingCombobox )
    {
        m_antiAliasingCombobox->SetText( GUCEF::CORE::UInt32ToString( settings.GetAntiAliasingFactor() ) );
    }
    if ( NULL != m_resolutionCombobox )
    {
        TDisplayMode displayMode;
        settings.GetDisplayMode( displayMode );
        m_resolutionCombobox->SetText( ParseDisplayMode( displayMode ) );
    }
    return true;
}
void CFbRenderStage::ConstructL(MWsGraphicDrawerEnvironment * aEnv,MWsScreen * aScreen, MWsScreenRedraw* /*aScreenRedraw*/, CWsRenderStage* aNextStage)
	{
	BaseConstructL();
	iNextScreenDevice = aNextStage->ObjectInterface<MWsScreenDevice>();
	STD_ASSERT_ALWAYS(iNextScreenDevice, EPluginPanicScreenDeviceMissing);
	iNextScene = aNextStage->ObjectInterface<MWsScene>();
	STD_ASSERT_ALWAYS(iNextScene, EPluginPanicSceneMissing);
	iDisplayControl = aNextStage->ObjectInterface<MWsDisplayControl>();	//can be NULL
	iDisplayMapping = aNextStage->ObjectInterface<MWsDisplayMapping>();	//can be NULL
	MWsIniFile* iniFile = aEnv->ObjectInterface<MWsIniFile>();
	STD_ASSERT_ALWAYS(iniFile, EPluginPanicIniFileMissing);

	//initialize render target
	_LIT(KFlickerBufferMode,"FLICKERBUFFERMODE");
	TPtrC flickerBufferModeName;
	TDisplayMode displayMode = ENone;
	if (iniFile->FindVar(iNextScreenDevice->ScreenNumber(), KFlickerBufferMode, flickerBufferModeName))
		displayMode = ParseDisplayMode(flickerBufferModeName);
	if (displayMode == ENone)
		{
		// Display render stage MWsScreenDevice::DisplayMode now reports the supported screendriver display mode in 32bpp. 
		// It is necessary in order to maintain BC with 3rd party apps and DSA framework.
		// The reported display mode may be different from the actual UI surface pixel format, so flicker buffer
	    // must not rely on DisplayMode() to determine pixel format for its rendering target.
		//
		MWsUiBuffer* uiBuf = aNextStage->ObjectInterface<MWsUiBuffer>();
		if (uiBuf)
			{
			displayMode = SgUtils::PixelFormatToDisplayMode(uiBuf->PixelFormat());
			}
		}
	STD_ASSERT_DEBUG(displayMode!=ENone, EPluginPanicNoDisplayModeFound);
	
	const TUint32 usage = ESgUsageDirectGdiTarget | ESgUsageWindowGcSource;
	const TSgCpuAccess cpuAccess = ESgCpuAccessReadWrite;
	TSize size;
	if (iDisplayControl)
		{
		iDisplayPolicy = CDisplayPolicy::NewL(aEnv,aScreen,iNextScreenDevice->ScreenNumber());
		
		//calculate min UI buffer size depending on physical resolutions
		TInt ret = iDisplayControl->NumberOfResolutions();
		RArray<MDisplayControlBase::TResolution> resolutions;
		CleanupClosePushL(resolutions);
		if(ret > 0)
			{
			User::LeaveIfError(resolutions.Reserve(ret));
			User::LeaveIfError(iDisplayControl->GetResolutions(resolutions));
			}
		iDisplayPolicy->CalculateMinBufferSize(resolutions, ret);				
		CleanupStack::PopAndDestroy(&resolutions);
		
		if (iDisplayPolicy->PolicyEnabled())
			{
			iDisplayPolicy->AdjustStageBufferSize(TSize(0,0),size);
			}
		else
			{
			size = iNextScreenDevice->SizeInPixels();
			}
		}
	else
		{
		size = iNextScreenDevice->SizeInPixels();
		}

	iRenderTarget = CRenderTarget::NewL(iniFile, usage, cpuAccess, displayMode, size, iNextScreenDevice->ScreenNumber());
	
	//initialize drawable sources
	MWsGraphicsContext* gc = aNextStage->ObjectInterface<MWsGraphicsContext>();
	STD_ASSERT_ALWAYS(gc, EPluginPanicNoContext);
	iDrawableSourceProvider = gc->ObjectInterface<MWsDrawableSourceProvider>();
	STD_ASSERT_ALWAYS(iDrawableSourceProvider, EPluginPanicNoDrawableSourceProvider);

	for(TInt i = 0; i < CRenderTarget::EAspectRatioCount; i++)
		{
		CRenderTarget::TAspectRatio aspectRatio = (CRenderTarget::TAspectRatio)i;
		const TInt err = iDrawableSourceProvider->CreateDrawableSource(iRenderTarget->ImageId(aspectRatio), iDrawableSources[aspectRatio]);
		STD_ASSERT_ALWAYS(err == KErrNone, EPluginPanicDrawableSourceInitializationFailed);
		}
	
	iController = CRenderStageController::NewL(this);
	
	// Pre-allocate update region buffers. 
	const TInt KUpdateRegionPreAllocationBufferLen = 8;
	TRect* rectangleList = (TRect*) (User::Alloc(KUpdateRegionPreAllocationBufferLen * sizeof(TRect)));
	if (rectangleList)
		{
		CleanupStack::PushL(rectangleList);
		iUpdateRegion = new (ELeave) RRegion(KUpdateRegionPreAllocationBufferLen, rectangleList);
		CleanupStack::Pop(rectangleList);
		}
	else
		{
		iUpdateRegion = new (ELeave) RRegion();
		}

	//
	SetNext(aNextStage);
	}