os/graphics/windowing/windowserver/test/tauto/topaquechild.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/topaquechild.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,167 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This file is part of manual test (group\inc113743.mmp) to check Wserv behaviour when
    1.18 +// exposing a transparent window that is obscured by some opaque child window above it.
    1.19 +// Without the fix, that transparent window will be drawn as opaque window
    1.20 +// because its transparent regions is null (not re-created due to its update flag is not
    1.21 +// set as it is not traceable via transparent regions linked list of windows above it.
    1.22 +// Some illustration when the situation will trigger the defect (side view),
    1.23 +// ----       Child (opaque)
    1.24 +// ---------- Parent (transparent)
    1.25 +// ----       Other transparent window obscured by opaque child
    1.26 +// This defect is only reproducable when window shadowing is not used, so it cannot be 
    1.27 +// tested from standard Wserv test framework.
    1.28 +// @SYMTestCaseID		GRAPHICS-WSERV-0450
    1.29 +// @SYMDEF  			INC113743
    1.30 +// @SYMTestCaseDesc    Perform test on Wserv behaviour in exposing transparent windows which is obscured indirectly by opaque child window
    1.31 +// @SYMTestPriority    High
    1.32 +// @SYMTestStatus      Implemented
    1.33 +// @SYMTestActions     Create opaque and transparent windows in the following dimension and z-order
    1.34 +// ----       opaque child
    1.35 +// ---------- transparent parent
    1.36 +// ----       other transparent underneath obscured and non traceable via transparent parent iTransparentRegions
    1.37 +// and then make transparent parent window invisible
    1.38 +// @SYMTestExpectedResults The expected result are: other transparent window underneath is exposed and redrawn properly not becoming opaque
    1.39 +// 
    1.40 +//
    1.41 +
    1.42 +#include <e32std.h>
    1.43 +#include <w32std.h>
    1.44 +#include <fbs.h>
    1.45 +
    1.46 +#define ENullWsHandle 0xffffffff
    1.47 +
    1.48 +void MainL()
    1.49 +	{
    1.50 +	const TSize KTestSize(320,240);
    1.51 +	const TSize KHalfSize(160,240);
    1.52 +	const TInt KScreenNo = 1;
    1.53 +
    1.54 +	RRegion shape;
    1.55 +	shape.AddRect(TRect(0,0,160,120));
    1.56 +	shape.AddRect(TRect(160,120,320,240));
    1.57 +	CleanupClosePushL(shape);
    1.58 +
    1.59 +	RWsSession ws;
    1.60 +	User::LeaveIfError(ws.Connect());
    1.61 +	CleanupClosePushL(ws);
    1.62 +
    1.63 +	CWsScreenDevice* scr = new(ELeave) CWsScreenDevice(ws);
    1.64 +	CleanupStack::PushL(scr);
    1.65 +	User::LeaveIfError(scr->Construct(KScreenNo));
    1.66 +	TDisplayMode displayMode = scr->DisplayMode();
    1.67 +
    1.68 +	CWindowGc* gc = NULL;
    1.69 +	User::LeaveIfError(scr->CreateContext(gc));
    1.70 +	CleanupStack::PushL(gc);
    1.71 +
    1.72 +	RWindowGroup group(ws);
    1.73 +	User::LeaveIfError(group.Construct(0x0badface, ETrue));
    1.74 +	CleanupClosePushL(group);
    1.75 +
    1.76 +	// create transparent window underneath that will be obscured by some opaque child window above it
    1.77 +	RWindow transWinUnderneath(ws);
    1.78 +	User::LeaveIfError(transWinUnderneath.Construct(group, ENullWsHandle));
    1.79 +	CleanupClosePushL(transWinUnderneath);
    1.80 +	transWinUnderneath.SetShadowDisabled(ETrue);
    1.81 +	transWinUnderneath.SetExtent(TPoint(0,0),KTestSize/*KHalfSize*/);
    1.82 +	transWinUnderneath.SetTransparencyAlphaChannel();
    1.83 +	transWinUnderneath.SetRequiredDisplayMode(EColor64K);
    1.84 +	transWinUnderneath.SetBackgroundColor(TRgb(255,0,0,128));
    1.85 +	transWinUnderneath.SetShape(shape);
    1.86 +	transWinUnderneath.Activate();
    1.87 +	transWinUnderneath.Invalidate();
    1.88 +	transWinUnderneath.BeginRedraw();
    1.89 +	transWinUnderneath.EndRedraw();
    1.90 +	ws.Flush();
    1.91 +
    1.92 +	User::After(1*1000*1000);
    1.93 +
    1.94 +	// save the reference image (semi-transparent red window)
    1.95 +	CFbsBitmap* refImage = new(ELeave) CFbsBitmap;
    1.96 +	CleanupStack::PushL(refImage);
    1.97 +	User::LeaveIfError(refImage->Create(KTestSize, displayMode));
    1.98 +	scr->CopyScreenToBitmap(refImage);
    1.99 +
   1.100 +	// create transparent window parent which will have opaque child
   1.101 +	RWindow transWinParent(ws);
   1.102 +	User::LeaveIfError(transWinParent.Construct(group, ENullWsHandle));
   1.103 +	CleanupClosePushL(transWinParent);
   1.104 +	transWinParent.SetShadowDisabled(ETrue);
   1.105 +	transWinParent.SetExtent(TPoint(0,0),KTestSize);
   1.106 +	transWinParent.SetTransparencyAlphaChannel();
   1.107 +	transWinParent.SetRequiredDisplayMode(EColor64K);
   1.108 +	transWinParent.SetBackgroundColor(TRgb(255,255,255,0));
   1.109 +	transWinParent.Activate();
   1.110 +
   1.111 +	transWinParent.Invalidate();
   1.112 +	transWinParent.BeginRedraw();
   1.113 +	transWinParent.EndRedraw();
   1.114 +	ws.Flush();
   1.115 +		
   1.116 +	// create opaque child window that obscure transparent window underneath (not its parent)
   1.117 +	RWindow opaqueWinChild(ws);
   1.118 +	User::LeaveIfError(opaqueWinChild.Construct(transWinParent, ENullWsHandle));
   1.119 +	CleanupClosePushL(opaqueWinChild);
   1.120 +	opaqueWinChild.SetExtent(TPoint(0,0),KTestSize/*KHalfSize*/);
   1.121 +	opaqueWinChild.SetRequiredDisplayMode(EColor64K);
   1.122 +	opaqueWinChild.SetShape(shape);
   1.123 +	opaqueWinChild.Activate();
   1.124 +	
   1.125 +	opaqueWinChild.Invalidate();
   1.126 +	opaqueWinChild.BeginRedraw();
   1.127 +	gc->Activate(opaqueWinChild);
   1.128 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.129 +	gc->SetPenStyle(CGraphicsContext::ENullPen);
   1.130 +	gc->SetBrushColor(KRgbGreen);
   1.131 +	gc->Clear();
   1.132 +	gc->SetBrushColor(KRgbBlue);
   1.133 +	gc->DrawEllipse(KTestSize/*KHalfSize*/);
   1.134 +	gc->Deactivate();
   1.135 +	opaqueWinChild.EndRedraw();
   1.136 +	ws.Flush();
   1.137 +
   1.138 +	User::After(1*1000*1000);
   1.139 +
   1.140 +	// preform the test by making transparent window parent invisible
   1.141 +	transWinParent.SetVisible(EFalse);
   1.142 +	ws.Flush();
   1.143 +
   1.144 +	User::After(2*1000*1000);
   1.145 +
   1.146 +	// save the test image (without the fix this would be an opaque red window)
   1.147 +	CFbsBitmap* testImage = new(ELeave) CFbsBitmap;
   1.148 +	CleanupStack::PushL(testImage);
   1.149 +	User::LeaveIfError(testImage->Create(KTestSize, displayMode));
   1.150 +	scr->CopyScreenToBitmap(testImage);
   1.151 +
   1.152 +	_LIT(KPanicMsg, "Test Failed");
   1.153 +	TInt nbytes = CFbsBitmap::ScanLineLength(KTestSize.iWidth, displayMode)*KTestSize.iHeight;
   1.154 +	if (Mem::Compare((TUint8*)testImage->DataAddress(), nbytes, (TUint8*)refImage->DataAddress(), nbytes)!=0)
   1.155 +		User::Panic(KPanicMsg, 0);
   1.156 +
   1.157 +	CleanupStack::PopAndDestroy(10, &shape);
   1.158 +	}
   1.159 +
   1.160 +GLDEF_C TInt E32Main()
   1.161 +	{
   1.162 +	CTrapCleanup* cs = CTrapCleanup::New();
   1.163 +	if (!cs)
   1.164 +		return KErrNoMemory;
   1.165 +		
   1.166 +	TRAPD(err,MainL());
   1.167 +
   1.168 +	delete cs;
   1.169 +	return err;
   1.170 +	}