windowing/windowserver/tauto/topaquechild.cpp
changeset 116 171fae344dd4
parent 103 2717213c588a
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This file is part of manual test (group\inc113743.mmp) to check Wserv behaviour when
       
    15 // exposing a transparent window that is obscured by some opaque child window above it.
       
    16 // Without the fix, that transparent window will be drawn as opaque window
       
    17 // because its transparent regions is null (not re-created due to its update flag is not
       
    18 // set as it is not traceable via transparent regions linked list of windows above it.
       
    19 // Some illustration when the situation will trigger the defect (side view),
       
    20 // ----       Child (opaque)
       
    21 // ---------- Parent (transparent)
       
    22 // ----       Other transparent window obscured by opaque child
       
    23 // This defect is only reproducable when window shadowing is not used, so it cannot be 
       
    24 // tested from standard Wserv test framework.
       
    25 // @SYMTestCaseID		GRAPHICS-WSERV-0450
       
    26 // @SYMDEF  			INC113743
       
    27 // @SYMTestCaseDesc    Perform test on Wserv behaviour in exposing transparent windows which is obscured indirectly by opaque child window
       
    28 // @SYMTestPriority    High
       
    29 // @SYMTestStatus      Implemented
       
    30 // @SYMTestActions     Create opaque and transparent windows in the following dimension and z-order
       
    31 // ----       opaque child
       
    32 // ---------- transparent parent
       
    33 // ----       other transparent underneath obscured and non traceable via transparent parent iTransparentRegions
       
    34 // and then make transparent parent window invisible
       
    35 // @SYMTestExpectedResults The expected result are: other transparent window underneath is exposed and redrawn properly not becoming opaque
       
    36 // 
       
    37 //
       
    38 
       
    39 #include <e32std.h>
       
    40 #include <w32std.h>
       
    41 #include <fbs.h>
       
    42 
       
    43 #define ENullWsHandle 0xffffffff
       
    44 
       
    45 void MainL()
       
    46 	{
       
    47 	const TSize KTestSize(320,240);
       
    48 	const TSize KHalfSize(160,240);
       
    49 	const TInt KScreenNo = 1;
       
    50 
       
    51 	RRegion shape;
       
    52 	shape.AddRect(TRect(0,0,160,120));
       
    53 	shape.AddRect(TRect(160,120,320,240));
       
    54 	CleanupClosePushL(shape);
       
    55 
       
    56 	RWsSession ws;
       
    57 	User::LeaveIfError(ws.Connect());
       
    58 	CleanupClosePushL(ws);
       
    59 
       
    60 	CWsScreenDevice* scr = new(ELeave) CWsScreenDevice(ws);
       
    61 	CleanupStack::PushL(scr);
       
    62 	User::LeaveIfError(scr->Construct(KScreenNo));
       
    63 	TDisplayMode displayMode = scr->DisplayMode();
       
    64 
       
    65 	CWindowGc* gc = NULL;
       
    66 	User::LeaveIfError(scr->CreateContext(gc));
       
    67 	CleanupStack::PushL(gc);
       
    68 
       
    69 	RWindowGroup group(ws);
       
    70 	User::LeaveIfError(group.Construct(0x0badface, ETrue));
       
    71 	CleanupClosePushL(group);
       
    72 
       
    73 	// create transparent window underneath that will be obscured by some opaque child window above it
       
    74 	RWindow transWinUnderneath(ws);
       
    75 	User::LeaveIfError(transWinUnderneath.Construct(group, ENullWsHandle));
       
    76 	CleanupClosePushL(transWinUnderneath);
       
    77 	transWinUnderneath.SetShadowDisabled(ETrue);
       
    78 	transWinUnderneath.SetExtent(TPoint(0,0),KTestSize/*KHalfSize*/);
       
    79 	transWinUnderneath.SetTransparencyAlphaChannel();
       
    80 	transWinUnderneath.SetRequiredDisplayMode(EColor64K);
       
    81 	transWinUnderneath.SetBackgroundColor(TRgb(255,0,0,128));
       
    82 	transWinUnderneath.SetShape(shape);
       
    83 	transWinUnderneath.Activate();
       
    84 	transWinUnderneath.Invalidate();
       
    85 	transWinUnderneath.BeginRedraw();
       
    86 	transWinUnderneath.EndRedraw();
       
    87 	ws.Flush();
       
    88 
       
    89 	User::After(1*1000*1000);
       
    90 
       
    91 	// save the reference image (semi-transparent red window)
       
    92 	CFbsBitmap* refImage = new(ELeave) CFbsBitmap;
       
    93 	CleanupStack::PushL(refImage);
       
    94 	User::LeaveIfError(refImage->Create(KTestSize, displayMode));
       
    95 	scr->CopyScreenToBitmap(refImage);
       
    96 
       
    97 	// create transparent window parent which will have opaque child
       
    98 	RWindow transWinParent(ws);
       
    99 	User::LeaveIfError(transWinParent.Construct(group, ENullWsHandle));
       
   100 	CleanupClosePushL(transWinParent);
       
   101 	transWinParent.SetShadowDisabled(ETrue);
       
   102 	transWinParent.SetExtent(TPoint(0,0),KTestSize);
       
   103 	transWinParent.SetTransparencyAlphaChannel();
       
   104 	transWinParent.SetRequiredDisplayMode(EColor64K);
       
   105 	transWinParent.SetBackgroundColor(TRgb(255,255,255,0));
       
   106 	transWinParent.Activate();
       
   107 
       
   108 	transWinParent.Invalidate();
       
   109 	transWinParent.BeginRedraw();
       
   110 	transWinParent.EndRedraw();
       
   111 	ws.Flush();
       
   112 		
       
   113 	// create opaque child window that obscure transparent window underneath (not its parent)
       
   114 	RWindow opaqueWinChild(ws);
       
   115 	User::LeaveIfError(opaqueWinChild.Construct(transWinParent, ENullWsHandle));
       
   116 	CleanupClosePushL(opaqueWinChild);
       
   117 	opaqueWinChild.SetExtent(TPoint(0,0),KTestSize/*KHalfSize*/);
       
   118 	opaqueWinChild.SetRequiredDisplayMode(EColor64K);
       
   119 	opaqueWinChild.SetShape(shape);
       
   120 	opaqueWinChild.Activate();
       
   121 	
       
   122 	opaqueWinChild.Invalidate();
       
   123 	opaqueWinChild.BeginRedraw();
       
   124 	gc->Activate(opaqueWinChild);
       
   125 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   126 	gc->SetPenStyle(CGraphicsContext::ENullPen);
       
   127 	gc->SetBrushColor(KRgbGreen);
       
   128 	gc->Clear();
       
   129 	gc->SetBrushColor(KRgbBlue);
       
   130 	gc->DrawEllipse(KTestSize/*KHalfSize*/);
       
   131 	gc->Deactivate();
       
   132 	opaqueWinChild.EndRedraw();
       
   133 	ws.Flush();
       
   134 
       
   135 	User::After(1*1000*1000);
       
   136 
       
   137 	// preform the test by making transparent window parent invisible
       
   138 	transWinParent.SetVisible(EFalse);
       
   139 	ws.Flush();
       
   140 
       
   141 	User::After(2*1000*1000);
       
   142 
       
   143 	// save the test image (without the fix this would be an opaque red window)
       
   144 	CFbsBitmap* testImage = new(ELeave) CFbsBitmap;
       
   145 	CleanupStack::PushL(testImage);
       
   146 	User::LeaveIfError(testImage->Create(KTestSize, displayMode));
       
   147 	scr->CopyScreenToBitmap(testImage);
       
   148 
       
   149 	_LIT(KPanicMsg, "Test Failed");
       
   150 	TInt nbytes = CFbsBitmap::ScanLineLength(KTestSize.iWidth, displayMode)*KTestSize.iHeight;
       
   151 	if (Mem::Compare((TUint8*)testImage->DataAddress(), nbytes, (TUint8*)refImage->DataAddress(), nbytes)!=0)
       
   152 		User::Panic(KPanicMsg, 0);
       
   153 
       
   154 	CleanupStack::PopAndDestroy(10, &shape);
       
   155 	}
       
   156 
       
   157 GLDEF_C TInt E32Main()
       
   158 	{
       
   159 	CTrapCleanup* cs = CTrapCleanup::New();
       
   160 	if (!cs)
       
   161 		return KErrNoMemory;
       
   162 		
       
   163 	TRAPD(err,MainL());
       
   164 
       
   165 	delete cs;
       
   166 	return err;
       
   167 	}