sl@0: // Copyright (c) 2007-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 sl@0: */ sl@0: sl@0: #include "t_wservintegstepbasic.h" sl@0: #include sl@0: #include //KNullUidValue sl@0: #include sl@0: sl@0: namespace t_wservintegstepbasic sl@0: { sl@0: static const TUint delay=100000; //0.5 sec sl@0: sl@0: const TInt KSurfaceWidth = 50; sl@0: const TInt KSurfaceHeight = 50; sl@0: const TUidPixelFormat KSurfaceFormat = EUidPixelFormatXRGB_8888; sl@0: const TInt KBytesPerPixel = 4; // Four bytes per pixel for the format above. sl@0: sl@0: // Events delivered to this handle are thrown away sl@0: const TUint32 ENullWsHandle = 0xFFFFFFFF; sl@0: _LIT(KT_WServIntegStepBasicTestId,"testid"); sl@0: _LIT(KT_BasicStepPanicTxt, "t_wservintegstepbasic"); sl@0: } sl@0: sl@0: using namespace t_wservintegstepbasic; sl@0: sl@0: CT_WServIntegStepBasic::CT_WServIntegStepBasic() sl@0: { sl@0: SetTestStepName(KT_WServIntegStepBasic); sl@0: } sl@0: sl@0: sl@0: CT_WServIntegStepBasic::~CT_WServIntegStepBasic() sl@0: { sl@0: delete iGc; sl@0: delete iScreen; sl@0: iWinGroup.Close(); sl@0: iWsSession.Flush(); sl@0: iWsSession.Close(); sl@0: } sl@0: sl@0: sl@0: enum TVerdict CT_WServIntegStepBasic::doTestStepPreambleL() sl@0: { sl@0: TVerdict ret=CTestStep::doTestStepPreambleL(); sl@0: sl@0: if ( !GetIntFromConfig( ConfigSection(), KT_WServIntegStepBasicTestId, iTestId ) ) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(iWsSession.Connect()); sl@0: iScreen = new (ELeave) CWsScreenDevice(iWsSession); sl@0: User::LeaveIfError(iScreen->Construct()); sl@0: iWinGroup = RWindowGroup(iWsSession); sl@0: User::LeaveIfError(iWinGroup.Construct(ENullWsHandle) ); sl@0: iWinGroup.AutoForeground(ETrue); sl@0: iGc = new (ELeave) CWindowGc(iScreen); sl@0: User::LeaveIfError(iGc->Construct()); sl@0: iWsSession.Flush(); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: enum TVerdict CT_WServIntegStepBasic::doTestStepPostambleL() sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Starts test step sl@0: More detail on each test step can be sl@0: found in the respective script file. sl@0: @internalComponent sl@0: @return TVerdict pass / fail sl@0: @pre N/A sl@0: @post N/A sl@0: */ sl@0: enum TVerdict CT_WServIntegStepBasic::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: RWindow win; sl@0: RBlankWindow blankWin; sl@0: sl@0: switch( iTestId ) sl@0: { sl@0: case 1: sl@0: Graphics_Wserv_Gce_1L(win); sl@0: break; sl@0: case 2: sl@0: Graphics_Wserv_Gce_2L(blankWin); sl@0: break; sl@0: case 3: sl@0: Graphics_Wserv_Gce_3L(); sl@0: break; sl@0: case 4: sl@0: Graphics_Wserv_Gce_4L(win); sl@0: break; sl@0: case 5: sl@0: Graphics_Wserv_Gce_5L(win); sl@0: break; sl@0: case 6: sl@0: Graphics_Wserv_Gce_6L(win); sl@0: break; sl@0: case 7: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 8: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 9: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 10: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 11: sl@0: Graphics_Wserv_Gce_11L(win); sl@0: break; sl@0: case 12: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 13: sl@0: Graphics_Wserv_Gce_13L(win); sl@0: break; sl@0: case 14: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 15: sl@0: Graphics_Wserv_Gce_15L(win); sl@0: break; sl@0: case 16: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 17: sl@0: Graphics_Wserv_Gce_17L(win); sl@0: break; sl@0: case 18: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 19: sl@0: Graphics_Wserv_Gce_19L(win); sl@0: break; sl@0: case 20: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 21: sl@0: Graphics_Wserv_Gce_21L(win); sl@0: break; sl@0: case 22: sl@0: Graphics_Wserv_Gce_22L(win); sl@0: break; sl@0: case 23: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 24: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 25: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 26: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 27: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 28: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 29: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 30: sl@0: //Test removed in CR1489 sl@0: break; sl@0: case 31: sl@0: Graphics_Wserv_Gce_31L(blankWin); sl@0: break; sl@0: case 32: sl@0: Graphics_Wserv_Gce_32L(win); sl@0: break; sl@0: case 33: sl@0: Graphics_Wserv_Gce_33L(win); sl@0: break; sl@0: case 34: sl@0: Graphics_Wserv_Gce_34L(win); sl@0: break; sl@0: case 35: sl@0: Graphics_Wserv_Gce_35L(win); sl@0: break; sl@0: case 36: sl@0: Graphics_Wserv_Gce_36L(win); sl@0: break; sl@0: case 37: sl@0: //Test removed in CR1489 sl@0: break; sl@0: default: sl@0: User::Panic(KT_BasicStepPanicTxt, KErrNotFound); //Unexpected value! sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: //Test setting a surface as the background of a window sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_1L(RWindow& aWin) sl@0: { sl@0: CreateSurfaceL(iSurfaceId); sl@0: CreateRWindowL(aWin); sl@0: TEST(KErrNone==aWin.SetBackgroundSurface(iSurfaceId)); sl@0: ForceWindowToRedraw(aWin); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: //Test setting a surface as the background of a RBlankWindow sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_2L(RBlankWindow& aBlankWin) sl@0: { sl@0: CreateSurfaceL(iSurfaceId); sl@0: CreateRBlankWindowL(aBlankWin); sl@0: TEST(KErrNone==aBlankWin.SetBackgroundSurface(iSurfaceId)); sl@0: ForceWindowToRedraw(aBlankWin); sl@0: DestroySurface(); sl@0: aBlankWin.Close(); sl@0: } sl@0: sl@0: //Negative test for setting a surface as the background of a RBackedUpWindow sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_3L() sl@0: { sl@0: CreateSurfaceL(iSurfaceId); sl@0: RBackedUpWindow backedUpWindow( iWsSession ); sl@0: CleanupClosePushL( backedUpWindow ); sl@0: User::LeaveIfError( backedUpWindow.Construct( iWinGroup, EColor16MA, ENullWsHandle) ); sl@0: backedUpWindow.SetSizeErr( iScreen->SizeInPixels() ); sl@0: backedUpWindow.SetVisible( ETrue ); sl@0: backedUpWindow.Activate(); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: // Expect a panic here - TClientPanic::EWservPanicDrawable sl@0: backedUpWindow.SetBackgroundSurface( iSurfaceId ); sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy( &backedUpWindow ); sl@0: } sl@0: sl@0: //Test for moving a window with its background set sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_4L(RWindow& aWin) sl@0: { sl@0: // Create window and assign a surface to it sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TSize scrSize(iScreen->SizeInPixels()); sl@0: // move the window around sl@0: aWin.SetPosition( TPoint( (scrSize.iWidth)-KTempWindowWidth, 0) ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: aWin.SetPosition( TPoint(aWin.Position().iX, (scrSize.iHeight)-KTempWindowHeight )); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: aWin.SetPosition( TPoint(0, (scrSize.iHeight)-KTempWindowHeight) ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: aWin.SetPosition(TPoint(0,0)); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test moving a window with its background set partially and wholly offscreen sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_5L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TSize screenSize(iScreen->SizeInPixels()); sl@0: // partially off screen sl@0: TUint xCord=(screenSize.iWidth-KTempWindowWidth)+(KTempWindowWidth/2); sl@0: TUint yCord=(screenSize.iHeight-KTempWindowHeight)+(KTempWindowHeight/2); sl@0: aWin.SetPosition(TPoint(xCord,yCord)); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: // wholly off screen sl@0: aWin.SetPosition( TPoint(screenSize.iWidth, screenSize.iHeight) ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test resizing a window with its background set to a surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_6L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TSize sz(aWin.Size()); sl@0: aWin.SetSize( sz+TPoint(20,0) ); sl@0: iWsSession.Flush(); sl@0: User::After( delay ); sl@0: aWin.SetSize( sz+TPoint(0,20) ); sl@0: iWsSession.Flush(); sl@0: User::After( delay ); sl@0: aWin.SetSize( sz+TPoint(20,20) ); sl@0: iWsSession.Flush(); sl@0: User::After( delay ); sl@0: aWin.SetSize( TSize(KSurfaceWidth, KSurfaceHeight ) ); sl@0: iWsSession.Flush(); sl@0: User::After( delay ); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: sl@0: // Test Opaque drawing in front of a background surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_11L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: // Opaque drawing on bkgd surface sl@0: DrawShape( aWin, 0x0000FF00 ); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test Semi-transparent drawing in front of a background surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_13L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: // semi Transp on bkgd surface sl@0: DrawShape( aWin, 0x8000FF00 ); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that an opaque window can be put in front of an Rwindow with background surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_15L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: CleanupClosePushL(aWin); sl@0: // draw 2nd window partially over the first one sl@0: RWindow win2; sl@0: CreateRWindowL(win2, TPoint(10,10), KRgbGreen ); sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy(&aWin); sl@0: win2.Close(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that a semi-transparent window can be put in front of a Rwindow with surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_17L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: CleanupClosePushL(aWin); sl@0: // draw semi Transp win partially over first win with surface sl@0: RWindow win2; sl@0: CreateRWindowL(win2, TPoint(10,10)); sl@0: INFO_PRINTF1(_L("Destroy Surface")); sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy(&aWin); sl@0: win2.Close(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test updating a background surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_19L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: CleanupClosePushL(aWin); sl@0: // create a 2nd surface sl@0: TSurfaceId surfaceId2; sl@0: CreateSurfaceL(surfaceId2, 0x0000FF00); sl@0: ASSERT_EQUALS( KErrNone, aWin.SetBackgroundSurface(surfaceId2) ); sl@0: ForceWindowToRedraw(aWin); sl@0: TInt ret = iSurfaceManager.CloseSurface(surfaceId2); sl@0: if(ret!=KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Surface manager failed to close surface")); sl@0: } sl@0: // destroys iSurfaceId plus closes iSurfaceUpdateSession,iChunk,iSurfaceManager sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy(&aWin); sl@0: } sl@0: sl@0: //Test shape of a window is applied to window a surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_21L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TRect rc[2] = { TRect(0,0,100,200),TRect(100,120,200,200) }; sl@0: RRegion region(2, rc); sl@0: aWin.SetShape( region ); sl@0: User::After(delay); // For DEBUG sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that a valid key color is returned when a surface sl@0: //has been set as the background of a window sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_22L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TRgb colValue(aWin.KeyColor()); sl@0: if ( aWin.DisplayMode()==EColor16MA || aWin.DisplayMode()==EColor16MAP ) sl@0: { sl@0: TEST(aWin.KeyColor().Internal()==0x00000000); sl@0: } sl@0: else sl@0: { sl@0: TEST(aWin.KeyColor().Alpha()==0xFF); sl@0: } sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that the use of SetColor() i.e. with no parameters removes sl@0: //any surface assigned to the window sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_31L(RBlankWindow& aBlankWin) sl@0: { sl@0: CreateSurfaceL(iSurfaceId); sl@0: CreateRBlankWindowL(aBlankWin); sl@0: ASSERT_EQUALS(KErrNone, aBlankWin.SetBackgroundSurface(iSurfaceId)); sl@0: ForceWindowToRedraw(aBlankWin); sl@0: aBlankWin.SetColor(); sl@0: ForceWindowToRedraw(aBlankWin); sl@0: DestroySurface(); sl@0: aBlankWin.Close(); sl@0: } sl@0: sl@0: //Test that the shaped window maintains the surface when moved sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_32L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TRect rc[2] = { TRect(0,0,100,200),TRect(100,120,200,200) }; sl@0: RRegion region(2, rc); sl@0: aWin.SetShape( region ); sl@0: User::After(delay); sl@0: aWin.SetPosition( TPoint( aWin.Position().iX+10, aWin.Position().iY+10 ) ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that window and surface scale to the new size when a shaped sl@0: //window with surface is resized sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_33L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: TRect rc[2] = { TRect(0,0,100,200),TRect(100,120,200,200) }; sl@0: RRegion region(2, rc); sl@0: aWin.SetShape( region ); sl@0: User::After(delay); sl@0: aWin.SetSize( TSize(200,150) ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: //Test that the background surface blends with the semi transparent window sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_34L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: CleanupClosePushL(aWin); sl@0: ForceWindowToRedraw(aWin); sl@0: RWindow win2; sl@0: CreateRWindowL(win2,TPoint(10,0), 0x80A9B9C9); sl@0: // draw semi Transp on window bkgd sl@0: DrawShape( win2, 0x8000FF00 ); sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy(&aWin); sl@0: win2.Close(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: // Test that the corner style is applied to the window with surface sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_35L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: aWin.SetCornerType( EWindowCorner5 ); sl@0: User::After(delay); sl@0: DestroySurface(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: /*** sl@0: Test that shaped windows with background surfaces arranged such that sl@0: the back window overlaps the front's bounding box, but not its shaped sl@0: region (e.g. the front is L-shaped and the back overlaps the area within sl@0: the 'L'). In this situation, the back window's surface should be visible sl@0: in the overlap area sl@0: */ sl@0: void CT_WServIntegStepBasic::Graphics_Wserv_Gce_36L(RWindow& aWin) sl@0: { sl@0: ASSERT_EQUALS( EPass, SetSurfaceL(aWin,iSurfaceId)); sl@0: CleanupClosePushL(aWin); sl@0: TRect rc1[2] = { TRect(110,20,150,80),TRect(150,60,200,100) }; sl@0: RRegion region1(2, rc1); sl@0: aWin.SetShape( region1 ); sl@0: User::After(delay); sl@0: sl@0: // create a 2nd surface sl@0: TSurfaceId surfaceId2; sl@0: CreateSurfaceL(surfaceId2,0x00ABCDEF); sl@0: RWindow win2; sl@0: CreateRWindowL(win2); sl@0: ASSERT_EQUALS( KErrNone, win2.SetBackgroundSurface(surfaceId2)); sl@0: User::After(delay); sl@0: TRect rc2[2] = { TRect(0,0,100,200),TRect(100,120,200,200) }; sl@0: RRegion region2(2, rc2); sl@0: win2.SetShape( region2 ); sl@0: User::After(delay); sl@0: sl@0: TInt ret = iSurfaceManager.CloseSurface(surfaceId2); sl@0: if(ret!=KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Surface manager failed to close surface")); sl@0: } sl@0: // destroys iSurfaceId plus closes iSurfaceUpdateSession,iChunk,iSurfaceManager sl@0: DestroySurface(); sl@0: CleanupStack::PopAndDestroy(&aWin); sl@0: win2.Close(); sl@0: aWin.Close(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Creates a RWindow sl@0: sl@0: @param aWin The window object sl@0: @param aPos The Position of the window sl@0: @param aBkgdColor The background color of the window sl@0: @param aSize The size of the window sl@0: */ sl@0: void CT_WServIntegStepBasic::CreateRWindowL(RWindow& aWin, const TPoint& aPos, const TRgb& aBkgdColor, const TSize& aWinSize) sl@0: { sl@0: aWin = RWindow( iWsSession ); sl@0: CleanupClosePushL( aWin ); sl@0: User::LeaveIfError( aWin.Construct( iWinGroup, ENullWsHandle ) ); sl@0: CleanupStack::Pop(&aWin); sl@0: aWin.SetExtent(aPos, aWinSize); sl@0: aWin.SetBackgroundColor( aBkgdColor ); sl@0: aWin.Activate(); sl@0: aWin.BeginRedraw(); sl@0: aWin.EndRedraw(); sl@0: aWin.SetVisible( ETrue ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: } sl@0: sl@0: /** sl@0: Creates a RBlankWindow sl@0: sl@0: @param aBlankWin The window object sl@0: */ sl@0: void CT_WServIntegStepBasic::CreateRBlankWindowL(RBlankWindow& aBlankWin) sl@0: { sl@0: aBlankWin = RBlankWindow(iWsSession); sl@0: CleanupClosePushL(aBlankWin); sl@0: User::LeaveIfError(aBlankWin.Construct(iWinGroup, ENullWsHandle) ); sl@0: TSize sz( KTempWindowWidth, KTempWindowHeight ); sl@0: aBlankWin.SetSize(sz); sl@0: aBlankWin.SetColor(TRgb(0x800000FF)); // 0xAABBGGRR sl@0: aBlankWin.Activate(); sl@0: CleanupStack::Pop(&aBlankWin); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: } sl@0: sl@0: void CT_WServIntegStepBasic::ForceWindowToRedraw(RWindowBase& aWin) sl@0: { sl@0: aWin.SetVisible( EFalse ); sl@0: iWsSession.Flush(); sl@0: aWin.SetVisible( ETrue ); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: } sl@0: sl@0: void CT_WServIntegStepBasic::CreateSurfaceManager() sl@0: { sl@0: INFO_PRINTF1(_L("Loading the device driver")); sl@0: TInt ret = iSurfaceManager.Open(); sl@0: if(ret==KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Creating surface manager OK")); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Set up code for creating a surface and fill it with a color sl@0: sl@0: @param aSurfaceId The surface object, to be initialized. sl@0: @param aColorPattern The color to fill the surface with. sl@0: */ sl@0: void CT_WServIntegStepBasic::CreateSurfaceL(TSurfaceId& aSurfaceId, TUint aColorPattern) sl@0: { sl@0: INFO_PRINTF1(_L("Creating a surface manager")); sl@0: CreateSurfaceManager(); sl@0: sl@0: INFO_PRINTF1(_L("Setting up surface attributes")); sl@0: RSurfaceManager::TSurfaceCreationAttributesBuf attribs; sl@0: RSurfaceManager::TSurfaceCreationAttributes& surfaceCreationAtribs=attribs(); sl@0: sl@0: surfaceCreationAtribs.iSize.iWidth = KSurfaceWidth; sl@0: surfaceCreationAtribs.iSize.iHeight = KSurfaceHeight; sl@0: surfaceCreationAtribs.iBuffers = 1; sl@0: surfaceCreationAtribs.iPixelFormat = KSurfaceFormat; sl@0: surfaceCreationAtribs.iStride = KBytesPerPixel*KSurfaceWidth; sl@0: surfaceCreationAtribs.iOffsetToFirstBuffer = 0; sl@0: surfaceCreationAtribs.iAlignment = 4; sl@0: surfaceCreationAtribs.iContiguous = EFalse; sl@0: surfaceCreationAtribs.iMappable = ETrue; sl@0: INFO_PRINTF1(_L("Call to CreateSurfaceL()")); sl@0: TInt err = iSurfaceManager.CreateSurface(attribs, aSurfaceId); sl@0: if (err == KErrNone) sl@0: { sl@0: //we have a surface, so map it in sl@0: INFO_PRINTF1(_L("Surface created ok, mapping to it")); sl@0: TInt err = iSurfaceManager.MapSurface(aSurfaceId, iChunk); sl@0: User::LeaveIfError(err); sl@0: TUint32* surfacePtr = reinterpret_cast(iChunk.Base()); sl@0: TUint32* linePtr = surfacePtr; sl@0: sl@0: // Fill first line sl@0: for (TInt xx = 0; xx < KSurfaceWidth; xx++) sl@0: { sl@0: surfacePtr[xx] = aColorPattern; sl@0: } sl@0: sl@0: // Now copy that to the other lines sl@0: TInt stride = KBytesPerPixel * KSurfaceWidth; sl@0: for (TInt yy = 1; yy < KSurfaceHeight; yy++) sl@0: { sl@0: linePtr += KSurfaceWidth; sl@0: Mem::Move(linePtr, surfacePtr, stride); sl@0: } sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Create Surface update session")); sl@0: CreateSurfaceUpdateSessionL(); sl@0: err = iSurfaceUpdateSession.SubmitUpdate(KAllScreens, aSurfaceId, 0, NULL); sl@0: if (err!=KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Fail in submitting update")); sl@0: } sl@0: } sl@0: sl@0: void CT_WServIntegStepBasic::CreateSurfaceUpdateSessionL() sl@0: { sl@0: TInt ret = iSurfaceUpdateSession.Connect(); sl@0: sl@0: if (ret==KErrAlreadyExists) sl@0: { sl@0: INFO_PRINTF1(_L("Device driver already loaded")); sl@0: } sl@0: else if (ret==KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Connected to surface update server")); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Fatal error connecting to surface update server")); sl@0: User::LeaveIfError(ret); sl@0: } sl@0: } sl@0: sl@0: void CT_WServIntegStepBasic::DestroySurface() sl@0: { sl@0: INFO_PRINTF1(_L("Destroy Surface update session")); sl@0: iSurfaceUpdateSession.Close(); sl@0: sl@0: //close the chunk sl@0: INFO_PRINTF1(_L("Closing chunk")); sl@0: iChunk.Close(); sl@0: sl@0: INFO_PRINTF1(_L("Closing surface")); sl@0: TInt ret = iSurfaceManager.CloseSurface(iSurfaceId); sl@0: if(ret!=KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Surface manager failed to close")); sl@0: } sl@0: sl@0: INFO_PRINTF1(_L("Destroy Surface Manager")); sl@0: iSurfaceManager.Close(); sl@0: } sl@0: sl@0: /** sl@0: Common set up code for assigning a surface to the window. Calls other utility sl@0: functions for creating a window and a surface sl@0: sl@0: @param aWin The window object sl@0: @param aSurfaceId The surface object, to be initialized. sl@0: */ sl@0: TVerdict CT_WServIntegStepBasic::SetSurfaceL(RWindow& aWin, TSurfaceId& aSurfaceId) sl@0: { sl@0: TVerdict verdict=EPass; sl@0: CreateRWindowL(aWin); sl@0: CleanupClosePushL(aWin); sl@0: CreateSurfaceL( aSurfaceId ); sl@0: CleanupStack::Pop(&aWin); sl@0: if ( aWin.SetBackgroundSurface(aSurfaceId)!=KErrNone) sl@0: { sl@0: verdict=EFail; sl@0: } sl@0: iWsSession.Flush(); sl@0: ForceWindowToRedraw(aWin); sl@0: return verdict; sl@0: } sl@0: sl@0: /** sl@0: Draw an Ellipse shape sl@0: sl@0: @param aWin The window object, connected to a session sl@0: @param aColor The (transparent/opaque)color which the shape is filled with sl@0: */ sl@0: void CT_WServIntegStepBasic::DrawShape(RWindow& aWin, const TRgb& aColor) sl@0: { sl@0: iGc->Activate( aWin ); sl@0: iGc->SetBrushColor( aColor ); sl@0: iGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); sl@0: TRect rect(TPoint(0,0), TPoint(aWin.Size().iWidth, aWin.Size().iHeight)); sl@0: iGc->DrawEllipse(rect); sl@0: iWsSession.Flush(); sl@0: User::After(delay); sl@0: iGc->Deactivate(); sl@0: } sl@0: