examples/sfexamples/GfxWorkbench/src/GfxBitBitView.cpp

00001 /*
00002 Copyright (c) 2002-2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  Application view implementation
00028 */ 
00029 
00030 
00031 // INCLUDE FILES
00032 #include <GDI.H>
00033 #include <coemain.h>
00034 #include <EIKENV.H>
00035 #include "GfxBitBlitView.h"
00036 #include "GfxVideoPlayer.h"
00037 #include "hal.h"
00038 #include "CGfxTimer.h"
00039 
00040 const TInt KNumberOfTests = 12;
00041 const TInt KNumOfBlits = 1000;
00042 const TTimeIntervalMicroSeconds32 KProfileYieldInMicroSeconds = 1000000/20;
00043 
00044 _LIT(KLogFileDir, "c:\\data\\other\\");
00045 _LIT(KLogFileName, "c:\\data\\other\\bitblit.txt");
00046 
00047 // ============================ MEMBER FUNCTIONS ===============================
00048 
00049 // -----------------------------------------------------------------------------
00050 // CGfxDirectScreenBitmapView::NewL()
00051 // Two-phased constructor.
00052 // -----------------------------------------------------------------------------
00053 //
00054 CGfxBitBlitView* CGfxBitBlitView::NewL( const TRect& aRect )
00055         {
00056         CGfxBitBlitView* self = CGfxBitBlitView::NewLC( aRect );
00057         CleanupStack::Pop( self );
00058         return self;
00059         }
00060 
00061 // -----------------------------------------------------------------------------
00062 // CGfxDirectScreenBitmapView::NewLC()
00063 // Two-phased constructor.
00064 // -----------------------------------------------------------------------------
00065 //
00066 CGfxBitBlitView* CGfxBitBlitView::NewLC( const TRect& aRect )
00067         {
00068         CGfxBitBlitView* self = new ( ELeave ) CGfxBitBlitView;
00069         CleanupStack::PushL( self );
00070         self->ConstructL( aRect );
00071         return self;
00072         }
00073 
00074 // -----------------------------------------------------------------------------
00075 // CGfxDirectScreenBitmapView::ConstructL()
00076 // Symbian 2nd phase constructor can leave.
00077 // -----------------------------------------------------------------------------
00078 //
00079 void CGfxBitBlitView::ConstructL( const TRect& aRect )
00080         {
00081         // Create a window for this application view
00082         CreateWindowL();
00083 
00084         // Set the windows size
00085         SetRect( aRect );
00086 
00087         iTimer = new(ELeave) CGfxTimer(*this, 0);
00088         iTimer->ConstructL();
00089         
00090         // Activate the window, which makes it ready to be drawn
00091         ActivateL();
00092         }
00093 
00094 // -----------------------------------------------------------------------------
00095 // CGfxDirectScreenBitmapView::CGfxDirectScreenBitmapView()
00096 // C++ default constructor can NOT contain any code, that might leave.
00097 // -----------------------------------------------------------------------------
00098 //
00099 CGfxBitBlitView::CGfxBitBlitView()
00100         {
00101         }
00102 
00103 
00104 // -----------------------------------------------------------------------------
00105 // CGfxDirectScreenBitmapView::~CGfxDirectScreenBitmapView()
00106 // Destructor.
00107 // -----------------------------------------------------------------------------
00108 //
00109 CGfxBitBlitView::~CGfxBitBlitView()
00110         {
00111         delete iTimer;
00112         CloseLogFile();
00113         }
00114 
00115 
00116 // -----------------------------------------------------------------------------
00117 // CGfxDirectScreenBitmapView::Draw()
00118 // Draws the display.
00119 // -----------------------------------------------------------------------------
00120 //
00121 void CGfxBitBlitView::Draw( const TRect& /*aRect*/ ) const
00122         {
00123         // Get the standard graphics context
00124         CWindowGc& gc = SystemGc();
00125 
00126         // Gets the control's extent
00127         TRect drawRect( Rect());
00128 
00129         // Clears the screen
00130         gc.Clear( drawRect );
00131         }
00132 
00133 // -----------------------------------------------------------------------------
00134 // CGfxDirectScreenBitmapView::SizeChanged()
00135 // Called by framework when the view size is changed.
00136 // -----------------------------------------------------------------------------
00137 //
00138 void CGfxBitBlitView::SizeChanged()
00139         {  
00140         DrawNow();
00141         }
00142 // End of File
00143 
00144 CFbsBitmap* BitmapForDepthL(TDisplayMode aDisplayMode, TSize aSize)
00145         {
00146         CFbsBitmap* offScreenBitmap = new (ELeave) CFbsBitmap();
00147         CleanupStack::PushL(offScreenBitmap);
00148         User::LeaveIfError(offScreenBitmap->Create(aSize,aDisplayMode));
00149         
00150         // create an off-screen device and context
00151         CGraphicsContext* bitmapContext=NULL;
00152         CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(offScreenBitmap);
00153         CleanupStack::PushL(bitmapDevice);
00154         User::LeaveIfError(bitmapDevice->CreateContext(bitmapContext));
00155         CleanupStack::PushL(bitmapContext);
00156         
00157         bitmapContext->SetBrushColor(KRgbRed);
00158         bitmapContext->SetBrushStyle(CGraphicsContext::ESolidBrush);
00159         //bitmapContext->Clear();
00160         
00161         CleanupStack::PopAndDestroy(2);
00162         CleanupStack::Pop(offScreenBitmap);
00163         return offScreenBitmap;
00164         }
00165 
00166 void CGfxBitBlitView::StartL()
00167         {
00168         iCurrentTest = 0;
00169         CreateLogFileL();
00170         iTimer->Start(KProfileYieldInMicroSeconds);
00171         }
00172 
00173 void CGfxBitBlitView::GfxTimerFiredL(TInt /*aId*/)
00174         {
00175         ProfileBitBlitL(iCurrentTest);
00176         
00177         iCurrentTest++;
00178         if(iCurrentTest<KNumberOfTests)
00179                 {
00180                 iTimer->Start(KProfileYieldInMicroSeconds);
00181                 }
00182         else
00183                 {
00184                 iEikonEnv->AlertWin(_L("Log Complete"), KLogFileName);
00185                 CloseLogFile();
00186                 }
00187         }
00188 
00189 void CGfxBitBlitView::CreateLogFileL()
00190         {
00191         const TDisplayMode defaultDisplayMode = iEikonEnv->DefaultDisplayMode();
00192         
00193         (void)iEikonEnv->FsSession().MkDirAll(KLogFileDir);
00194         User::LeaveIfError(iLogFile.Replace(iEikonEnv->FsSession(), KLogFileName,EFileWrite ));
00195         User::LeaveIfError( iLogFile.Write(_L8("Bitblit test results\n")) );
00196         TBuf8<255> out;
00197         out.Format(_L8("Default Display Mode %D\n\n"), static_cast<TInt>(defaultDisplayMode) );
00198         User::LeaveIfError(iLogFile.Write(out));
00199         out.Format(_L8("Width: %D, Height: %D,\n\n"), Size().iWidth, Size().iHeight);
00200         iLogFile.Write(out);
00201         
00202         TInt nanokernel_tick_period;
00203         HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period);
00204         out.Format(_L8("Nano tick period: %D\n\n"), nanokernel_tick_period);
00205         User::LeaveIfError(iLogFile.Write(out));;
00206         
00207         iLogFile.Flush();
00208         }
00209 void CGfxBitBlitView::CloseLogFile()
00210         {
00211         iLogFile.Close();
00212         }
00213 
00214 void CGfxBitBlitView::ProfileBitBlitL(TInt aTestNo)
00215         {
00216         
00217         // create a bitmap to be used off-screen
00218         TDisplayMode tests[KNumberOfTests]={
00220                         EGray2,
00222                         EGray4,
00224                         EGray16,
00226                         EGray256,
00228                         EColor16,
00230                         EColor256,
00232                         EColor64K,
00234                         EColor16M,
00236                         ERgb,
00238                         EColor4K,
00240                         EColor16MU,
00242                         EColor16MA};
00243 
00244 
00245         TBuf8<255> out;
00246 
00247         CFbsBitmap* bmp = NULL;
00248         TRAPD(err, bmp=BitmapForDepthL(tests[aTestNo], Size()));
00249         if(err)
00250                 {
00251                 RDebug::Print(_L("BITBLIT: ERROR, %D"), err);
00252                 _LIT8(KFormat, "BITBLIT: %D ERROR, %D\n\r");
00253                 out.Format(KFormat, aTestNo, err);
00254                 }
00255         else
00256                 {
00257                 CleanupStack::PushL(bmp);
00258                 TUint32 startTick = User::NTickCount();
00259 
00260                 ActivateGc();
00261                 CWindowGc& gc = SystemGc();
00262 
00263                 for(TInt l=0; l<KNumOfBlits; l++)
00264                         {
00265                         gc.BitBlt(TPoint(0,0), bmp);
00266                         }
00267                 
00268                 DeactivateGc();
00269 
00270                 TUint32 endTick = User::NTickCount();
00271                 TInt mils = endTick-startTick;
00272                 RDebug::Print(_L("BITBLIT: %D, %D"), aTestNo, mils);
00273                 _LIT8(KFormat, "BITBLIT: %D, %D\n\r");
00274                 out.Format(KFormat, aTestNo, mils);     
00275                 CleanupStack::PopAndDestroy(bmp);
00276                 }
00277         
00278         User::LeaveIfError(iLogFile.Write(out));
00279         iLogFile.Flush();
00280         }
00281         
00282 void CGfxBitBlitView::StopL()
00283         {
00284         iTimer->Cancel();
00285         }
00286 

Generated by  doxygen 1.6.2