sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "subtitlegraphicteststep.h" sl@0: #include "subtitlecommonutils.h" sl@0: sl@0: _LIT(KTestBitmap1, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata.png"); sl@0: _LIT(KTestBitmap2, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata2.png"); sl@0: _LIT(KTestBitmap3, "c:\\mm\\mmf\\testfiles\\subtitlegraphic\\subtitletestdata3.png"); sl@0: sl@0: const TInt KTestBitmap1XSize(200); sl@0: const TInt KTestBitmap1YSize(151); sl@0: sl@0: const TInt KTestBitmap2XSize(193); sl@0: const TInt KTestBitmap2YSize(151); sl@0: sl@0: const TInt KTestBitmap3XSize(32); sl@0: const TInt KTestBitmap3YSize(32); sl@0: sl@0: const TInt KSubtitleRegionXPos(0); sl@0: const TInt KSubtitleRegionYPos(50); sl@0: sl@0: // Enable to draw a crosshatch over the main window. sl@0: //#define DEBUG_MARK_WINDOW 1 sl@0: sl@0: RSubtitleGraphicTestStep::RSubtitleGraphicTestStep(const TDesC& aStepName) : sl@0: iCRPId(TWsGraphicId::EUninitialized) sl@0: { sl@0: iTestStepName = aStepName; sl@0: } sl@0: sl@0: TVerdict RSubtitleGraphicTestStep::DoTestStepPreambleL() sl@0: { sl@0: User::LeaveIfError(iFs.Connect()); sl@0: sl@0: // Install the Active Scheduler sl@0: iActiveScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iActiveScheduler); sl@0: iActiveSchedulerStarted = EFalse; sl@0: sl@0: InitWservL(); sl@0: sl@0: InitCrpL(); sl@0: sl@0: User::LeaveIfError(RFbsSession::Connect()); sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: TVerdict RSubtitleGraphicTestStep::DoTestStepPostambleL() sl@0: { sl@0: RFbsSession::Disconnect(); sl@0: sl@0: iFs.Close(); sl@0: sl@0: // Destroy Window server objects sl@0: DeInitWserv(); sl@0: sl@0: DestroyBitmap1(); sl@0: DestroyBitmap2(); sl@0: DestroyBitmap3(); sl@0: DestroyCrp(); sl@0: sl@0: CActiveScheduler::Install(NULL); sl@0: delete iActiveScheduler; sl@0: iActiveScheduler = NULL; sl@0: sl@0: return EPass; sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::InitWservL() sl@0: { sl@0: TInt err = iWs.Connect(); sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: // Access violation if ws is null sl@0: ERR_PRINTF1(_L("Cannot test, no window server available")); sl@0: User::Leave(err); sl@0: } sl@0: sl@0: iScreen = new (ELeave) CWsScreenDevice(iWs); // make device for this session sl@0: User::LeaveIfError(iScreen->Construct()); // and complete its construction sl@0: sl@0: iRootWindow = RWindowGroup(iWs); sl@0: User::LeaveIfError(iRootWindow.Construct((TUint32)this, ETrue)); sl@0: sl@0: iWindow = new(ELeave) RWindow(iWs); sl@0: User::LeaveIfError(((RWindow*)iWindow)->Construct(iRootWindow,((TUint32)(this)) + 1)); sl@0: iWindow->SetExtent(TPoint(0,0), iScreen->SizeInPixels()); sl@0: iWindow->SetVisible(ETrue); sl@0: iWindow->SetRequiredDisplayMode(EColor16MA); sl@0: sl@0: // Setup transparency sl@0: TInt errorCode = iWindow->SetTransparencyAlphaChannel(); sl@0: TRgb backgroundColour = TRgb(0, 255, 255); sl@0: backgroundColour.SetAlpha(0); sl@0: iWindow->SetBackgroundColor(backgroundColour); sl@0: sl@0: iGc=new(ELeave) CWindowGc(iScreen); sl@0: User::LeaveIfError(iGc->Construct()); sl@0: sl@0: iWindow->Activate(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::DeInitWserv() sl@0: { sl@0: if (iWindow) sl@0: { sl@0: iWindow->Close(); sl@0: delete iWindow; sl@0: iWindow = NULL; sl@0: } sl@0: sl@0: iRootWindow.Close(); sl@0: delete iScreen; sl@0: iScreen = NULL; sl@0: sl@0: delete iGc; sl@0: iGc = NULL; sl@0: sl@0: iWs.Flush(); sl@0: iWs.Close(); sl@0: } sl@0: sl@0: TVerdict RSubtitleGraphicTestStep::StartCrpDrawL() sl@0: { sl@0: PrepGc(); sl@0: sl@0: // Draw the CRP sl@0: TPoint regionTl(KSubtitleRegionXPos,KSubtitleRegionYPos); sl@0: TPoint regionBr(iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight); sl@0: sl@0: iGc->DrawWsGraphic(iCRPGraphic->Id(), TRect(regionTl, regionBr)); sl@0: sl@0: TInt width=iScreen->SizeInPixels().iWidth; sl@0: TInt height=iScreen->SizeInPixels().iHeight; sl@0: sl@0: #ifdef DEBUG_MARK_WINDOW sl@0: // Draw a square border sl@0: iGc->SetPenColor(TRgb(255,0,0)); sl@0: iGc->DrawLine(TPoint(0,0),TPoint(0,height-1)); sl@0: iGc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1)); sl@0: iGc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0)); sl@0: iGc->DrawLine (TPoint (width-1, 0), TPoint (0, 0)); sl@0: sl@0: // Draw a line between the corners of the window sl@0: iGc->DrawLine(TPoint(0,0),TPoint(width, height)); sl@0: iGc->DrawLine (TPoint (0, height), TPoint (width, 0)); sl@0: #endif sl@0: sl@0: // Draw a box around the display region sl@0: iGc->SetPenColor(TRgb(255,0,0)); sl@0: iGc->DrawLine(regionTl, TPoint(width, height)); sl@0: sl@0: iGc->DrawLine(TPoint(KSubtitleRegionXPos, height), TPoint(width, KSubtitleRegionYPos)); sl@0: sl@0: RetireGc(); sl@0: sl@0: return iTestStepResult; sl@0: } sl@0: sl@0: // sl@0: // CWsGraphicBase::PrepGc sl@0: // activate a gc & clear the two rects sl@0: // sl@0: void RSubtitleGraphicTestStep::PrepGc() sl@0: { sl@0: iGc->Activate(*iWindow); sl@0: iWindow->Invalidate(); sl@0: iWindow->BeginRedraw(); sl@0: iGc->Clear(TRect(iScreen->SizeInPixels())); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: // sl@0: // CWsGraphicBase::RetireGc sl@0: // deactivate a gc & flush any outstanding RWindow requests sl@0: void RSubtitleGraphicTestStep::RetireGc() sl@0: { sl@0: iGc->Deactivate(); sl@0: iWindow->EndRedraw(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::InitCrpL() sl@0: { sl@0: iCRPGraphic = CMMFSubtitleGraphic::NewL(); sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::DestroyCrp() sl@0: { sl@0: delete iCRPGraphic; sl@0: iCRPGraphic = NULL; sl@0: } sl@0: sl@0: TBool RSubtitleGraphicTestStep::CreateBitmap1L() sl@0: { sl@0: if ( iBitmap1 ) sl@0: { sl@0: User::Invariant(); sl@0: } sl@0: sl@0: iBitmap1 = new (ELeave) CFbsBitmap(); sl@0: TSize testBitmap1Size(KTestBitmap1XSize, KTestBitmap1YSize); sl@0: sl@0: // Load test bitmap data sl@0: TInt err = iBitmap1->Create(testBitmap1Size, EColor16MA); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on iBitmap1->Create(KTestBitmap1Size, EColor16MA) error code %d"), err); sl@0: delete iBitmap1; sl@0: iBitmap1=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1)); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap1) error code %d"), err); sl@0: delete iBitmap1; sl@0: iBitmap1=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool RSubtitleGraphicTestStep::CreateBitmap2L() sl@0: { sl@0: if ( iBitmap2 ) sl@0: { sl@0: User::Invariant(); sl@0: } sl@0: sl@0: iBitmap2 = new (ELeave) CFbsBitmap(); sl@0: TSize testBitmap2Size(KTestBitmap2XSize, KTestBitmap2YSize); sl@0: sl@0: // Load test bitmap data sl@0: TInt err = iBitmap2->Create(testBitmap2Size, EColor16MA); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on iBitmap2->Create(KTestBitmap2Size, EColor16MA) error code %d"), err); sl@0: delete iBitmap2; sl@0: iBitmap2=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap2, *iBitmap2)); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap1, *iBitmap2) error code %d"), err); sl@0: delete iBitmap2; sl@0: iBitmap2=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: TBool RSubtitleGraphicTestStep::CreateBitmap3L() sl@0: { sl@0: if ( iBitmap3 ) sl@0: { sl@0: User::Invariant(); sl@0: } sl@0: sl@0: iBitmap3 = new (ELeave) CFbsBitmap(); sl@0: TSize testBitmap3Size(KTestBitmap3XSize, KTestBitmap3YSize); sl@0: sl@0: // Load test bitmap data sl@0: TInt err = iBitmap3->Create(testBitmap3Size, EColor16MA); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on iBitmap3->Create(KTestBitmap3Size, EColor16MA) error code %d"), err); sl@0: delete iBitmap3; sl@0: iBitmap3=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: TRAP(err, SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3)); sl@0: sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2(_L("Failed on SubtitleCommonUtils::Png2BmpL(iFs, KTestBitmap3, *iBitmap3) error code %d"), err); sl@0: delete iBitmap3; sl@0: iBitmap3=NULL; sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::DestroyBitmap1() sl@0: { sl@0: delete iBitmap1; sl@0: iBitmap1 = NULL; sl@0: } sl@0: sl@0: sl@0: void RSubtitleGraphicTestStep::DestroyBitmap2() sl@0: { sl@0: delete iBitmap2; sl@0: iBitmap2 = NULL; sl@0: } sl@0: sl@0: void RSubtitleGraphicTestStep::DestroyBitmap3() sl@0: { sl@0: delete iBitmap3; sl@0: iBitmap3 = NULL; sl@0: }