sl@0: // Copyright (c) 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: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include "tflipframerate.h" sl@0: sl@0: #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: const TInt KWindowGroupHandle = 1; sl@0: const TInt KWindowHandle = 2; sl@0: sl@0: const TInt KTextPhraseFontSize = 40; sl@0: const TReal KTextPhraseSpeed = 200.f; sl@0: sl@0: const TRgb KBackgroundColour = TRgb(255, 127, 0); // Orange sl@0: const TRgb KBrushColour = TRgb(255, 255, 0); // Yellow sl@0: const TRgb KPenColour = TRgb(0, 0, 255, 255); // Blue sl@0: sl@0: const TUint KMinFrames = 51;// uibench, needs more than 50 results for the trimmed mean sl@0: sl@0: _LIT(KTextPhrase, "Flip Performance"); sl@0: sl@0: TVerdict CTFlipFramerate::doTestStepPreambleL() sl@0: { sl@0: // Window related Setup sl@0: // Connect to windows server session sl@0: TESTL(KErrNone==iWs.Connect()); sl@0: sl@0: // Make device for this session sl@0: iScreenDev = new (ELeave) CWsScreenDevice(iWs); sl@0: TESTL(KErrNone==iScreenDev->Construct(KSgScreenIdMain)); sl@0: sl@0: // Create a window group sl@0: iWinGroup = RWindowGroup(iWs); sl@0: TESTL(KErrNone==iWinGroup.Construct(KWindowGroupHandle)); sl@0: sl@0: // Create a window with the window group as a parent sl@0: iWindow = RWindow(iWs); sl@0: TESTL(KErrNone==iWindow.Construct(iWinGroup, KWindowHandle)); sl@0: sl@0: // Activate window and set visible sl@0: iWindow.Activate(); sl@0: iWindow.SetVisible(ETrue); sl@0: sl@0: // Connect to surface update session sl@0: TESTL(KErrNone==iUpdateSession.Connect()); sl@0: CTDirectGdiTestBase::doTestStepPreambleL(); sl@0: iContext = CDirectGdiContext::NewL(*iDGdiDriver); sl@0: sl@0: // Image Related Setup sl@0: // Setup off screen image sl@0: iSurfaceSize=iWindow.Size(); sl@0: iImageInfo.iSizeInPixels = iSurfaceSize; sl@0: iImageInfo.iPixelFormat = EUidPixelFormatXRGB_8888; sl@0: iImageInfo.iCpuAccess = ESgCpuAccessNone; sl@0: iImageInfo.iUsage = ESgUsageOpenGlesTarget| ESgUsageDirectGdiSource | ESgUsageDirectGdiTarget; sl@0: iImageInfo.iShareable = ETrue; sl@0: iImageInfo.iScreenId = iScreenDev->GetScreenNumber(); sl@0: sl@0: TESTL(KErrNone==iImgCol.Create(iImageInfo, 1)); sl@0: TESTL(KErrNone==iImgCol.OpenImage(0, iImage)); sl@0: sl@0: TESTL(KErrNone==iDGdiImageTarget->Create(iImage)); sl@0: sl@0: TESTL(KErrNone==iSurfaceConfiguration.SetSurfaceId(iImgCol.SurfaceId())); sl@0: TESTL(KErrNone==iSurfaceConfiguration.SetExtent(iWindow.Size())); sl@0: sl@0: GetFontL(); sl@0: sl@0: TInt fastCounterFrequency; sl@0: TESTL(KErrNone==HAL::Get(HALData::EFastCounterFrequency, fastCounterFrequency)); sl@0: sl@0: // Initialise text scrolling variables sl@0: iTextPhraseSpeed = KTextPhraseSpeed / fastCounterFrequency; sl@0: iLastFrameTime = User::FastCounter(); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TVerdict CTFlipFramerate::doTestStepPostambleL() sl@0: { sl@0: iImage.Close(); sl@0: iImgCol.Close(); sl@0: sl@0: CTDirectGdiTestBase::doTestStepPostambleL(); sl@0: sl@0: delete iContext; sl@0: iWindow.Close(); sl@0: iWinGroup.Close(); sl@0: sl@0: iUpdateSession.Close(); sl@0: delete iScreenDev; sl@0: iWs.Close(); sl@0: sl@0: iTsStore->ReleaseFont(iFont); sl@0: delete iTsStore; sl@0: iTsStore = NULL; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Set-up a font to be used in the rendering sl@0: */ sl@0: void CTFlipFramerate::GetFontL() sl@0: { sl@0: _LIT(KFontFamily, "NewCourier"); sl@0: iTsStore = CFbsTypefaceStore::NewL(NULL); sl@0: TFontSpec spec(KFontFamily, KTextPhraseFontSize); sl@0: spec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); sl@0: spec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: TESTL(KErrNone==iTsStore->GetNearestFontInPixels(iFont, spec)); sl@0: sl@0: iTextPhraseLength = iFont->MeasureText(KTextPhrase, NULL, NULL); sl@0: } sl@0: sl@0: /** sl@0: Draw some content sl@0: */ sl@0: void CTFlipFramerate::RenderL() sl@0: { sl@0: iContext->Activate(*iDGdiImageTarget); sl@0: iContext->SetBrushColor(KBackgroundColour); sl@0: iContext->Clear(); sl@0: sl@0: // Draw Text sl@0: iContext->SetFont(iFont); sl@0: iContext->SetBrushStyle(DirectGdi::ENullBrush); sl@0: TPoint textPos(iTextPos,iSurfaceSize.iHeight/2); sl@0: sl@0: TReal fastCounter = User::FastCounter(); sl@0: sl@0: if(fastCounter(KMaxTUint) + fastCounter; sl@0: iTextPos+=(iTextPhraseSpeed * (actualCount-iLastFrameTime)); sl@0: } sl@0: else sl@0: { sl@0: iTextPos+=(iTextPhraseSpeed * (fastCounter-iLastFrameTime)); sl@0: } sl@0: sl@0: iContext->SetBrushColor(KBrushColour); sl@0: iContext->SetPenColor(KPenColour); sl@0: iContext->DrawText(KTextPhrase,NULL, textPos); sl@0: sl@0: // Update the last frame time, used to animate that which is drawn in RenderL() sl@0: iLastFrameTime = User::FastCounter(); sl@0: sl@0: iDGdiDriver->Finish(); sl@0: } sl@0: sl@0: /* sl@0: Set the size of the displayed window as a fraction of the screens size. sl@0: sl@0: @param aWindowSizeDivisor Controls the displayed window size sl@0: */ sl@0: void CTFlipFramerate::SetSizeL(const TScreenSizeDivisors aWindowSizeDivisor) sl@0: { sl@0: TSize size = iScreenDev->SizeInPixels(); sl@0: size.iHeight/=aWindowSizeDivisor; sl@0: size.iWidth/=aWindowSizeDivisor; sl@0: iWindow.SetSize(size); sl@0: iImageInfo.iSizeInPixels = size; sl@0: TESTL(KErrNone==iSurfaceConfiguration.SetExtent(size)); sl@0: } sl@0: sl@0: /* sl@0: Time how long it takes to display a submitted update sl@0: sl@0: @param aIsFlipped Whether or not the surface is to be vertically flipped before it it displayed sl@0: @param aWindowSizeDivisor Controls the displayed window size to be tested sl@0: @param aOrientation The surface rotation to be tested sl@0: @param aStepName The name of the test, for logging. sl@0: */ sl@0: void CTFlipFramerate::TestFramerateOrientationL( const TFlipped aIsFlipped, sl@0: const TScreenSizeDivisors aWindowSizeDivisor, sl@0: const CFbsBitGc::TGraphicsOrientation aOrientation) sl@0: { sl@0: // Simulate small sized window (e.g. like video call) and implicitly disable fast pathing. sl@0: SetSizeL(aWindowSizeDivisor); sl@0: sl@0: // Set-up the timer sl@0: iProfiler->InitResults(); sl@0: sl@0: TESTL(KErrNone==iSurfaceConfiguration.SetOrientation(aOrientation)); sl@0: TESTL(KErrNone==iSurfaceConfiguration.SetFlip(aIsFlipped)); sl@0: TESTL(KErrNone==iWindow.SetBackgroundSurface(iSurfaceConfiguration, ETrue)); sl@0: sl@0: TRequestStatus availabilityStatus; sl@0: TRequestStatus displayedStatus; sl@0: TTimeStamp dummyTimeStamp; sl@0: TInt framesDone=0; sl@0: sl@0: iUpdateSession.NotifyWhenAvailable(availabilityStatus); sl@0: TESTL(KErrNone==iUpdateSession.SubmitUpdate(KAllScreens, iImgCol.SurfaceId(), 0)); sl@0: sl@0: // uibench, needs more than 50 results for the trimmed mean, so repeat as required. sl@0: while(framesDone < KMinFrames) sl@0: { sl@0: iTextPos = -iTextPhraseLength; // enter stage left sl@0: sl@0: // scroll the text from left to right across the surface. sl@0: while(iTextPos<=iSurfaceSize.iWidth) sl@0: { sl@0: User::WaitForRequest(availabilityStatus); sl@0: // Draw something sl@0: RenderL(); sl@0: sl@0: // Request Notifications sl@0: iUpdateSession.NotifyWhenAvailable(availabilityStatus); sl@0: iUpdateSession.NotifyWhenDisplayed(displayedStatus, dummyTimeStamp); sl@0: sl@0: // Start Timer & Submit Update sl@0: iProfiler->StartTimer(); sl@0: TESTL(KErrNone==iUpdateSession.SubmitUpdate(KAllScreens, iImgCol.SurfaceId(), 0)); sl@0: sl@0: // Wait for the update to have been displayed and stop the timer sl@0: User::WaitForRequest(displayedStatus); sl@0: iProfiler->MarkResultSetL(); sl@0: framesDone++; sl@0: } sl@0: } sl@0: iProfiler->ResultsAnalysis(KTFlipFramerate,aOrientation,ENone,iScreenDev->CurrentScreenMode(),framesDone); sl@0: } sl@0: sl@0: void CTFlipFramerate::TestStepFramerateL( const TFlipped aIsFlipped, sl@0: const TScreenSizeDivisors aWindowSizeDivisor, sl@0: const TDesC& aStepName) sl@0: { sl@0: SetTestStepID(aStepName); sl@0: TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationNormal); sl@0: TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated90); sl@0: TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated180); sl@0: TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated270); sl@0: RecordTestResultL(); sl@0: } sl@0: #endif sl@0: sl@0: TVerdict CTFlipFramerate::doTestStepL() sl@0: { sl@0: #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: INFO_PRINTF1(_L("CTBitBltPerfDirectGdi can only be run with RSgImage legacy")); sl@0: return TestStepResult(); sl@0: #else sl@0: // Test to allow comparison between flipped and non-flipped performance sl@0: // This is because camera data needs to be flipped abuot vertical axis to show the user what they expect, sl@0: // e.g. during a voice call. sl@0: // No API exists for a flip about a vertical axis so this is achieved by a flip about horizontal axis, sl@0: // and a 180degree rotation. sl@0: // Therefore this test generates results for flipped and non-flipped performance at all four orientations. sl@0: // Additionally it tests at both full screen and quarter screen. It does this for two reasons :- sl@0: // 1) Full screen, non-flipped, non-rotated can be (and at the time of writing is) fast-pathed. sl@0: // This makes it awkward to use as a comparison. sl@0: // 2) Some use-cases are likely to use a non-fullscreen window, e.g. voice call. sl@0: #ifdef __WINS__ sl@0: INFO_PRINTF1(_L("Fullscreen, NotFlipped")); sl@0: TestStepFramerateL(ENotFlipped,EScreensizeFull,_L("GRAPHICS-UI-BENCH-0173")); sl@0: INFO_PRINTF1(_L("Fullscreen, Flipped")); sl@0: TestStepFramerateL(EFlipped,EScreensizeFull,_L("GRAPHICS-UI-BENCH-0174")); sl@0: INFO_PRINTF1(_L("Quarterscreen, NotFlipped")); sl@0: TestStepFramerateL(ENotFlipped,EScreenSizeQuarter,_L("GRAPHICS-UI-BENCH-0175")); sl@0: INFO_PRINTF1(_L("Quarterscreen, Flipped")); sl@0: TestStepFramerateL(EFlipped,EScreenSizeQuarter,_L("GRAPHICS-UI-BENCH-0176")); sl@0: sl@0: CloseTMSGraphicsStep(); sl@0: return TestStepResult(); sl@0: #else sl@0: INFO_PRINTF1(_L("Flip tests are running on emulator only, tests skipped.")); sl@0: return TestStepResult(); sl@0: #endif sl@0: #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE sl@0: } sl@0: