sl@0: // Copyright (c) 1996-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: // used for timing graphics sl@0: // sl@0: // sl@0: sl@0: #include "TTIME.H" sl@0: sl@0: #define TEST_BITMAP_NAME _L("Z:\\WSTEST\\TEST.MBM") sl@0: sl@0: GLREF_C void Panic(TInt aPanic); sl@0: sl@0: enum TFuncType sl@0: { sl@0: EBitmapTest, sl@0: EXorTest, sl@0: ESmallClearTest, sl@0: ERectCompareTest, sl@0: EUseFontTest, sl@0: EBitBltTest, sl@0: EFullScreenBitBltTest, sl@0: EMaskedBitBltTest, sl@0: EFillPatternTest, sl@0: EBackupWindowDrawingTest, sl@0: }; sl@0: sl@0: class TGraphicsTest : public CBase sl@0: { sl@0: public: sl@0: void DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2); sl@0: void DrawBitmapTestL(TInt aParam1, TAny *aParam2); sl@0: void XorTest(TInt aParam1, TAny *aParam2); sl@0: void SmallClearTest(TInt , TAny *); sl@0: void RectCompareTest(TInt , TAny *); sl@0: void UseFontTestL(TInt , TAny *); sl@0: void BitBltTestL(TInt , TAny *); sl@0: void FullScreenBitBltTestL(TInt , TAny *); sl@0: void MaskedBitBltTestL(TInt , TAny *); sl@0: void FillPatternTestL(TInt , TAny *); sl@0: void BackedUpWindowDrawingL(TInt aMode, TAny *); sl@0: private: sl@0: RWsSession iWs; sl@0: CWsScreenDevice *iDevice; sl@0: RWindowGroup iGroup; sl@0: RWindow iWindow; sl@0: RBackedUpWindow iBackedUpWindow; sl@0: RDrawableWindow *iWindowPtr; sl@0: CWindowGc *iGc; sl@0: }; sl@0: sl@0: TInt CreateGraphicsTest(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2) sl@0: { sl@0: TGraphicsTest *iTest=NULL; sl@0: TRAPD(err,iTest=new(ELeave) TGraphicsTest()); sl@0: if (err==KErrNone) sl@0: { sl@0: TRAP(err,iTest->DoTestL(aOwningGroup, aFunc, aParam1, aParam2)); sl@0: delete iTest; sl@0: } sl@0: return(err); sl@0: } sl@0: sl@0: void TGraphicsTest::DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2) sl@0: { sl@0: iWs.Connect(); sl@0: iDevice=new(ELeave) CWsScreenDevice(iWs); sl@0: iDevice->Construct(); sl@0: iGroup=RWindowGroup(iWs); sl@0: iGroup.Construct(ENullWsHandle); sl@0: iGroup.SetOwningWindowGroup(aOwningGroup); sl@0: // sl@0: if (aFunc==EBackupWindowDrawingTest) sl@0: { sl@0: iBackedUpWindow=RBackedUpWindow(iWs); sl@0: iWindowPtr=&iBackedUpWindow; sl@0: iBackedUpWindow.Construct(iGroup,EGray4,ENullWsHandle); sl@0: } sl@0: else sl@0: { sl@0: iWindow=RWindow(iWs); sl@0: iWindowPtr=&iWindow; sl@0: iWindow.Construct(iGroup,ENullWsHandle); sl@0: } sl@0: User::LeaveIfError(iWindowPtr->SetExtentErr(TPoint(), iDevice->SizeInPixels())); sl@0: iWindowPtr->Activate(); sl@0: // sl@0: iDevice->CreateContext(iGc); sl@0: iGc->Activate(*iWindowPtr); sl@0: if (iWindowPtr==&iWindow) sl@0: { sl@0: iWindow.BeginRedraw(); sl@0: iGc->Clear(); sl@0: iWindow.EndRedraw(); sl@0: } sl@0: switch(aFunc) sl@0: { sl@0: case EBitmapTest: sl@0: DrawBitmapTestL(aParam1, aParam2); sl@0: break; sl@0: case EXorTest: sl@0: XorTest(aParam1, aParam2); sl@0: break; sl@0: case ESmallClearTest: sl@0: SmallClearTest(aParam1, aParam2); sl@0: break; sl@0: case ERectCompareTest: sl@0: RectCompareTest(aParam1, aParam2); sl@0: break; sl@0: case EUseFontTest: sl@0: UseFontTestL(aParam1, aParam2); sl@0: break; sl@0: case EBitBltTest: sl@0: BitBltTestL(aParam1, aParam2); sl@0: break; sl@0: case EFullScreenBitBltTest: sl@0: FullScreenBitBltTestL(aParam1, aParam2); sl@0: break; sl@0: case EMaskedBitBltTest: sl@0: MaskedBitBltTestL(aParam1, aParam2); sl@0: break; sl@0: case EFillPatternTest: sl@0: FillPatternTestL(aParam1, aParam2); sl@0: break; sl@0: case EBackupWindowDrawingTest: sl@0: BackedUpWindowDrawingL(aParam1, aParam2); sl@0: break; sl@0: default:; sl@0: } sl@0: // sl@0: delete iGc; sl@0: iWindowPtr->Close(); sl@0: iGroup.Close(); sl@0: delete iDevice; sl@0: iWs.Close(); sl@0: } sl@0: sl@0: // Draw bitmap // sl@0: sl@0: void TGraphicsTest::DrawBitmapTestL(TInt , TAny *) sl@0: { sl@0: CFbsBitmap *bitmap=new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(bitmap->Load(TEST_BITMAP_NAME,0)); sl@0: for(TInt nTimes=0;nTimes<10;nTimes++) sl@0: { sl@0: iGc->Clear(); sl@0: TSize size(iDevice->SizeInPixels()); sl@0: iGc->DrawBitmap(TRect(-size.iWidth,-size.iHeight,size.iWidth<<1,size.iHeight<<1),bitmap); sl@0: iWs.Flush(); sl@0: } sl@0: delete bitmap; sl@0: } sl@0: sl@0: TInt DrawBitmapTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EBitmapTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader DrawBitmapTest={_S("Draw bitmap"),DrawBitmapTestFunc}; sl@0: sl@0: // XOR Test // sl@0: sl@0: void TGraphicsTest::XorTest(TInt , TAny *) sl@0: { sl@0: iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR); sl@0: iGc->SetBrushColor(TRgb::Gray256(255)); sl@0: iGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: for(TInt count=0;count<10;count++) sl@0: { sl@0: for(TInt wid=1;wid<320;wid+=3) sl@0: { sl@0: iGc->DrawRect(TRect(10,10,10+wid,150)); sl@0: // iWs.Flush(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TInt XorIngTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EXorTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader XorIngTest={_S("Xor'ing"),XorIngTestFunc}; sl@0: sl@0: // XOR Test // sl@0: sl@0: void TGraphicsTest::SmallClearTest(TInt , TAny *) sl@0: { sl@0: iGc->SetBrushColor(TRgb::Gray256(255)); sl@0: iGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: iGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: for(TInt count=0;count<500;count++) sl@0: { sl@0: for(TInt wid=1;wid<30;wid++) sl@0: { sl@0: iGc->DrawRect(TRect(1,0,10+wid,100)); sl@0: // iWs.Flush(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: TInt SmallClearTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, ESmallClearTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader SmallClearTest={_S("Small clear rect"),SmallClearTestFunc}; sl@0: sl@0: // XOR Test // sl@0: sl@0: enum {EMaxWidth=100}; sl@0: sl@0: void TGraphicsTest::RectCompareTest(TInt , TAny *) sl@0: { sl@0: TSize size(iDevice->SizeInPixels()); sl@0: for(TInt count=0;count<10;count++) sl@0: iDevice->RectCompare(TRect(0,0,size.iWidth>>1,size.iHeight),TRect(size.iWidth>>1,0,size.iWidth,size.iHeight)); sl@0: } sl@0: sl@0: TInt RectCompareTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, ERectCompareTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader RectCompareTest={_S("RectCompare"),RectCompareTestFunc}; sl@0: sl@0: // Use Font // sl@0: sl@0: void TGraphicsTest::UseFontTestL(TInt , TAny *) sl@0: { sl@0: CFbsFont *font; sl@0: TFontSpec fspec(KTestFontTypefaceName,200); sl@0: User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec)); sl@0: for(TInt count=0;count<1000;count++) sl@0: iGc->UseFont(font); sl@0: iDevice->ReleaseFont(font); sl@0: } sl@0: sl@0: TInt UseFontTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EUseFontTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader UseFontTest={_S("UseFont(x1000)"),UseFontTestFunc}; sl@0: sl@0: // Small BitBlt // sl@0: sl@0: void TGraphicsTest::BitBltTestL(TInt , TAny *) sl@0: { sl@0: CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs); sl@0: TSize size(25,50); sl@0: bitmap->Create(size,EGray4); sl@0: CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap); sl@0: CFbsBitGc *gc=CFbsBitGc::NewL(); sl@0: gc->Activate(bitmapDevice); sl@0: gc->DrawEllipse(TRect(size)); sl@0: delete gc; sl@0: delete bitmapDevice; sl@0: for(TInt count=0;count<10;count++) sl@0: { sl@0: iGc->Clear(); sl@0: TPoint pos(0,0); sl@0: for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth) sl@0: { sl@0: pos.iY=0; sl@0: for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight) sl@0: iGc->BitBlt(pos,bitmap); sl@0: } sl@0: } sl@0: delete bitmap; sl@0: } sl@0: sl@0: TInt BitBltTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EBitBltTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader BitBltTest={_S("BitBlt"),BitBltTestFunc}; sl@0: sl@0: // Full Screen BitBlt // sl@0: sl@0: void TGraphicsTest::FullScreenBitBltTestL(TInt , TAny *) sl@0: { sl@0: CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs); sl@0: TSize size(640,240); sl@0: User::LeaveIfError(bitmap->Create(size,EGray4)); sl@0: CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap); sl@0: CFbsBitGc *gc=CFbsBitGc::NewL(); sl@0: gc->Activate(bitmapDevice); sl@0: for(TInt pos=0;posDrawRect(TRect(pos,0,pos+16,size.iHeight)); sl@0: iGc->BitBlt(TPoint(0,0),bitmap); sl@0: iWs.Flush(); sl@0: } sl@0: delete gc; sl@0: delete bitmapDevice; sl@0: delete bitmap; sl@0: } sl@0: sl@0: TInt FullScreenBitBltTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EFullScreenBitBltTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader FullScreenBitBltTest={_S("FullScreenBitBlt"),FullScreenBitBltTestFunc}; sl@0: sl@0: // Masked BitBlt // sl@0: sl@0: void TGraphicsTest::MaskedBitBltTestL(TInt , TAny *) sl@0: { sl@0: TSize size(24,48); sl@0: CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs); sl@0: bitmap->Create(size,EGray4); sl@0: CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap); sl@0: CFbsBitGc *gc=CFbsBitGc::NewL(); sl@0: gc->Activate(bitmapDevice); sl@0: gc->DrawEllipse(TRect(size)); sl@0: delete bitmapDevice; sl@0: // Now do the mask sl@0: CWsBitmap *mask=new(ELeave) CWsBitmap(iWs); sl@0: mask->Create(size,EGray4); sl@0: bitmapDevice=CFbsBitmapDevice::NewL(mask); sl@0: gc->Activate(bitmapDevice); sl@0: gc->SetPenColor(TRgb::Gray4(3)); sl@0: gc->DrawEllipse(TRect(size)); sl@0: delete bitmapDevice; sl@0: // sl@0: delete gc; sl@0: for(TInt count=0;count<10;count++) sl@0: { sl@0: iGc->Clear(); sl@0: TPoint pos(0,0); sl@0: for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth+1) sl@0: { sl@0: pos.iY=0; sl@0: for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight) sl@0: iGc->BitBltMasked(pos,bitmap,TRect(size),mask,EFalse); sl@0: } sl@0: } sl@0: delete bitmap; sl@0: delete mask; sl@0: } sl@0: sl@0: TInt MaskedBitBltTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EMaskedBitBltTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader MaskedBitBltTest={_S("MaskedBitBlt"),MaskedBitBltTestFunc}; sl@0: sl@0: // Fill Pattern // sl@0: sl@0: void TGraphicsTest::FillPatternTestL(TInt , TAny *) sl@0: { sl@0: TSize scrSize(iDevice->SizeInPixels()); sl@0: TSize rectSize(scrSize.iWidth/5-1,scrSize.iHeight/2); sl@0: sl@0: CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs); sl@0: sl@0: TSize bitmapSize(50,40); sl@0: bitmap->Create(bitmapSize,EGray4); sl@0: CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap); sl@0: CFbsBitGc *gc=CFbsBitGc::NewL(); sl@0: gc->Activate(bitmapDevice); sl@0: gc->SetBrushColor(TRgb::Gray4(2)); sl@0: gc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: gc->DrawEllipse(TRect(bitmapSize)); sl@0: delete bitmapDevice; sl@0: delete gc; sl@0: // sl@0: iGc->UseBrushPattern(bitmap); sl@0: iGc->SetBrushStyle(CGraphicsContext::EPatternedBrush); sl@0: iGc->SetPenStyle(CGraphicsContext::ESolidPen); sl@0: for(TInt count=0;count<50;count++) sl@0: { sl@0: iGc->Clear(); sl@0: TPoint pos(0,0); sl@0: for(TInt xcount=0;xcount<5;xcount++,pos.iX+=rectSize.iWidth) sl@0: { sl@0: pos.iY=0; sl@0: for(TInt ycount=0;ycount<2;ycount++,pos.iY+=rectSize.iHeight) sl@0: iGc->DrawRect(TRect(pos,rectSize)); sl@0: } sl@0: } sl@0: delete bitmap; sl@0: } sl@0: sl@0: TInt FillPatternTestFunc(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EFillPatternTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader FillPatternTest={_S("FillPattern"),FillPatternTestFunc}; sl@0: sl@0: // Backup Window Drawing // sl@0: sl@0: void TGraphicsTest::BackedUpWindowDrawingL(TInt aMode, TAny *) sl@0: { sl@0: TSize scrSize(iDevice->SizeInPixels()); sl@0: CFbsFont *font=NULL; sl@0: if (aMode==1) sl@0: { sl@0: TFontSpec fspec(KTestFontTypefaceName,200); sl@0: User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec)); sl@0: iGc->UseFont(font); sl@0: } sl@0: iGc->SetPenStyle(CGraphicsContext::ESolidPen); sl@0: TPoint pos; sl@0: for(TInt count=0;count<10;count++) sl@0: { sl@0: iGc->Clear(); sl@0: for(pos.iY=0;pos.iYDrawLine(pos,pos+TSize(scrSize.iWidth,0)); sl@0: } sl@0: if (aMode==1) sl@0: iDevice->ReleaseFont(font); sl@0: } sl@0: sl@0: TInt BackupWindowDrawingFunc1(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 0, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader BackupWindowDrawingCreate1={_S("BackupWindowDrawing 1"),BackupWindowDrawingFunc1}; sl@0: sl@0: TInt BackupWindowDrawingFunc2(TInt aOwningGroup) sl@0: { sl@0: return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 1, NULL)); sl@0: } sl@0: sl@0: GLDEF_D TTimeTestHeader BackupWindowDrawingCreate2={_S("BackupWindowDrawing 2"),BackupWindowDrawingFunc2};