|
1 // Copyright (c) 2006-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 // The fix enables the fading effect with alpha-blending, which was not applied bofore. |
|
15 // The test will load a bitmap and two different masks: on/off and alpha-blend. |
|
16 // The bitmap will be masked with these masks and displayed before and after |
|
17 // setting the fading effect. |
|
18 // All different colour modes are being tested for both mask types. |
|
19 // The test will check the colour of a specific pixel in the scene before and after the |
|
20 // fading. The higher values in the After circle means that it has been highlighted. |
|
21 // The result will be printed in wstest log file. |
|
22 // |
|
23 // |
|
24 |
|
25 /** |
|
26 @file |
|
27 @test |
|
28 @internalComponent - Internal Symbian test code |
|
29 */ |
|
30 |
|
31 #include "TFADINGBITMAP.H" |
|
32 |
|
33 //=================================================== |
|
34 // CBaseWin Declaration |
|
35 //=================================================== |
|
36 |
|
37 CBaseWin::CBaseWin(): CTWin() |
|
38 { |
|
39 } |
|
40 |
|
41 CBaseWin::~CBaseWin() |
|
42 { |
|
43 delete iTempBitmap; |
|
44 delete iMaskGray256; |
|
45 delete iMaskGray2; |
|
46 delete iTempMask; |
|
47 delete iBitmap; |
|
48 } |
|
49 |
|
50 void CBaseWin::ConstructWinL(TPoint aPos, TSize aSize, TBool aVisible) |
|
51 { |
|
52 /*** Setting up the window ***/ |
|
53 iSize = aSize; |
|
54 SetUpL(aPos, aSize, TheClient->iGroup, *TheClient->iGc, aVisible); |
|
55 Win()->SetBackgroundColor(TRgb(20, 80, 20)); // dark green background |
|
56 BaseWin()->SetRequiredDisplayMode(EColor64K); |
|
57 |
|
58 /*** 24 bit bitmap ***/ |
|
59 // the original 24b bitmap to mask |
|
60 iTempBitmap = new (ELeave) CFbsBitmap(); |
|
61 User::LeaveIfError(iTempBitmap->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles24b)); |
|
62 iBitmap = new (ELeave) CFbsBitmap(); |
|
63 |
|
64 /*** on/off mask ***/ |
|
65 iMaskGray2 = new (ELeave) CFbsBitmap(); |
|
66 User::LeaveIfError(iMaskGray2->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles_mask2b)); |
|
67 |
|
68 /*** alpha-blend mask ***/ |
|
69 // holds the 24bit copy of the alpha blend mask which will be |
|
70 // copied into the proper Gray256 mask, iMaskGray256. |
|
71 iTempMask = new (ELeave) CFbsBitmap(); |
|
72 User::LeaveIfError(iTempMask->Load(_L("Z:\\WSTEST\\WSAUTOTEST.MBM"), EMbmWsautotestCircles_mask256)); |
|
73 // alpha blend mask; copying its data from iTempMask |
|
74 iMaskGray256 = new (ELeave) CFbsBitmap(); |
|
75 User::LeaveIfError(iMaskGray256->Create(iTempBitmap->SizeInPixels(),EGray256)); |
|
76 CFbsBitmapDevice *dev = CFbsBitmapDevice::NewL(iMaskGray256); |
|
77 CleanupStack::PushL(dev); |
|
78 CFbsBitGc *gc; |
|
79 User::LeaveIfError(dev->CreateContext(gc)); |
|
80 // performing the copying here |
|
81 gc->BitBlt(TPoint(0,0), iTempMask); |
|
82 // cleaning up |
|
83 CleanupStack::Pop(); |
|
84 delete gc; |
|
85 gc = NULL; |
|
86 delete dev; |
|
87 dev = NULL; |
|
88 } |
|
89 |
|
90 void CBaseWin::Draw() |
|
91 { |
|
92 iGc->Clear(); |
|
93 |
|
94 // Font intialization |
|
95 CFont* myFont; |
|
96 _LIT(KMyFontName,"Swiss"); |
|
97 TFontSpec myFontSpec = TFontSpec(KMyFontName,16); // to get smallest Swiss font |
|
98 TFontStyle style = TFontStyle (EPostureUpright, EStrokeWeightBold, EPrintPosNormal); |
|
99 myFontSpec.iFontStyle = style; |
|
100 User::LeaveIfError(TheClient->iScreen->GetNearestFontInPixels(myFont, myFontSpec)); |
|
101 iGc->UseFont(myFont); |
|
102 iGc->SetPenStyle(CGraphicsContext::ESolidPen); |
|
103 iGc->SetPenColor(TRgb(255, 255, 255)); |
|
104 |
|
105 // drawing text |
|
106 iGc->DrawText(_L("Fading = OFF"), TPoint(130,15)); |
|
107 iGc->DrawText(_L("Fading = ON"), TPoint(275,15)); |
|
108 iGc->DrawText(_L("Alpha blend"), TPoint(15,90)); |
|
109 iGc->DrawText(_L("on/off mask"), TPoint(15,190)); |
|
110 TBuf <30> displayMode(_L("Display Mode = ")); |
|
111 displayMode.Append(iMode); |
|
112 iGc->DrawText(displayMode, TPoint(385,100)); |
|
113 |
|
114 /*** drawing bitmap with its on/off mask and alpha-blending |
|
115 before and after fading ***/ |
|
116 iGc->BitBltMasked(TPoint(140,25), iBitmap, |
|
117 TRect(0,0,100,100), iMaskGray256, EFalse); |
|
118 // Save the pixel colour of a pixel on the outer ring of the circle |
|
119 // before fading enabled. |
|
120 TheClient->iScreen->GetPixel(iNonFadedPixel, TPoint(190,30)); |
|
121 |
|
122 iGc->SetFaded(ETrue); |
|
123 iGc->BitBltMasked(TPoint(270,25), iBitmap, |
|
124 TRect(0,0,100,100), iMaskGray256, EFalse); |
|
125 // Save the pixel colour of a pixel on the outer ring of the circle |
|
126 // after fading enabled. |
|
127 TheClient->iScreen->GetPixel(iFadedPixel, TPoint(320,30)); |
|
128 |
|
129 iGc->SetFaded(EFalse); |
|
130 |
|
131 iGc->BitBltMasked(TPoint(140,125), iBitmap, |
|
132 TRect(0,0,100,100), iMaskGray2, EFalse); |
|
133 iGc->SetFaded(ETrue); |
|
134 iGc->BitBltMasked(TPoint(270,125), iBitmap, |
|
135 TRect(0,0,100,100), iMaskGray2, EFalse); |
|
136 iGc->SetFaded(EFalse); |
|
137 |
|
138 iGc->DiscardFont(); |
|
139 TheClient->iScreen->ReleaseFont(myFont); |
|
140 } |
|
141 |
|
142 |
|
143 //=================================================== |
|
144 // CTFadingBitmap Definition |
|
145 //=================================================== |
|
146 |
|
147 CTFadingBitmap::CTFadingBitmap(CTestStep* aStep): |
|
148 CTWsGraphicsBase(aStep), iTestResult(ETrue) |
|
149 { |
|
150 } |
|
151 |
|
152 CTFadingBitmap::~CTFadingBitmap() |
|
153 { |
|
154 delete iBgWin; |
|
155 } |
|
156 |
|
157 void CTFadingBitmap::TestFadingL() |
|
158 { |
|
159 // Modes to test |
|
160 TDisplayMode modes[] = |
|
161 { |
|
162 EGray2, EGray4, EGray16, EGray256, |
|
163 EColor16, EColor256, EColor4K, EColor64K, |
|
164 EColor16M, EColor16MU, EColor16MA, EColor16MAP |
|
165 }; |
|
166 |
|
167 TBuf <12> modesTxt []= |
|
168 { |
|
169 _L("EGray2"), _L("EGray4"), _L("EGray16"), _L("EGray256"), |
|
170 _L("EColor16"), _L("EColor256"), _L("EColor4K"), _L("EColor64K"), |
|
171 _L("EColor16M"), _L("EColor16MU"), _L("EColor16MA"), _L("EColor16MAP") |
|
172 }; |
|
173 |
|
174 TBuf <100> testTxt; |
|
175 for( int i = 0; i < 12; i++) |
|
176 { |
|
177 testTxt.Format(modesTxt[i]); |
|
178 INFO_PRINTF1(testTxt); |
|
179 // Here we copy the content of the temp bitmap, which holds the test bitmap, |
|
180 // into the bitmap created with alternating color depths. |
|
181 User::LeaveIfError(iBgWin->iBitmap->Create(iBgWin->iTempBitmap->SizeInPixels(), modes[i])); |
|
182 CFbsBitmapDevice *dev = CFbsBitmapDevice::NewL(iBgWin->iBitmap); |
|
183 CleanupStack::PushL(dev); |
|
184 CFbsBitGc *gc; |
|
185 User::LeaveIfError(dev->CreateContext(gc)); |
|
186 // performing the copying here |
|
187 gc->BitBlt(TPoint(0,0), iBgWin->iTempBitmap); |
|
188 // setting the mode text to display it |
|
189 iBgWin->iMode = modesTxt[i]; |
|
190 // draws the bitmap on screen |
|
191 iBgWin->DrawNow(); |
|
192 TheClient->Flush(); |
|
193 User::After(5000); |
|
194 // cleaning up |
|
195 CleanupStack::Pop(); |
|
196 delete gc; |
|
197 gc = NULL; |
|
198 delete dev; |
|
199 dev = NULL; |
|
200 |
|
201 // Here the colours of pixels before and after fading are printed in wstest log |
|
202 testTxt.Format(_L("Nonfaded circle - color of the outside ring: R=%d G=%d B=%d"), iBgWin->iNonFadedPixel.Red(), iBgWin->iNonFadedPixel.Green(), iBgWin->iNonFadedPixel.Blue()); |
|
203 INFO_PRINTF1(testTxt); |
|
204 testTxt.Format(_L("Faded circle - color of the outside ring: R=%d G=%d B=%d"), iBgWin->iFadedPixel.Red(), iBgWin->iFadedPixel.Green(), iBgWin->iFadedPixel.Blue()); |
|
205 INFO_PRINTF1(testTxt); |
|
206 |
|
207 // Checks if the colors are the same before and after the fading. |
|
208 // The color will be the same only in EGray2 and EGray4 as there are no enough |
|
209 // color variations to represent the fading and nonfading effects. |
|
210 if(iTestResult && |
|
211 iBgWin->iNonFadedPixel.Red() == iBgWin->iFadedPixel.Red() && |
|
212 iBgWin->iNonFadedPixel.Green() == iBgWin->iFadedPixel.Green() && |
|
213 iBgWin->iNonFadedPixel.Blue() == iBgWin->iFadedPixel.Blue() && |
|
214 modes[i] != EGray2 && modes[i] != EGray4) |
|
215 iTestResult = EFalse; |
|
216 } |
|
217 } |
|
218 |
|
219 void CTFadingBitmap::ConstructL() |
|
220 { |
|
221 // construct the base window of the test in the background |
|
222 TSize scrSize = TSize(TheClient->iScreen->SizeInPixels()); |
|
223 iBgWin = new (ELeave) CBaseWin(); |
|
224 iBgWin->ConstructWinL(TPoint(0,0), scrSize, ETrue); |
|
225 } |
|
226 |
|
227 void CTFadingBitmap::RunTestCaseL(TInt aCurTestCase) |
|
228 { |
|
229 ((CTFadingBitmapStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
230 switch(aCurTestCase) |
|
231 { |
|
232 case 1: |
|
233 /** |
|
234 @SYMTestCaseID GRAPHICS-WSERV-0566 |
|
235 */ |
|
236 ((CTFadingBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0566")); |
|
237 TestFadingL(); |
|
238 // Fails or passes the test |
|
239 if(!iTestResult) |
|
240 TEST(EFalse); |
|
241 break; |
|
242 default: |
|
243 ((CTFadingBitmapStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
244 ((CTFadingBitmapStep*)iStep)->CloseTMSGraphicsStep(); |
|
245 TestComplete(); |
|
246 } |
|
247 ((CTFadingBitmapStep*)iStep)->RecordTestResultL(); |
|
248 } |
|
249 |
|
250 __WS_CONSTRUCT_STEP__(FadingBitmap) |