examples/SFExamples/GfxWorkbench/src/CGfxDirectBitmap.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:  
00028 */ 
00029 #include "CGfxDirectScreenBitmap.h"
00030 #include <coemain.h>
00031 #include <cdsb.h>
00032 
00033 
00034 CGfxDirectScreenBitmap::CGfxDirectScreenBitmap(RWsSession& aClient, 
00035         RWindow& aWindow):
00036         CActive(CActive::EPriorityStandard),
00037         iClient(aClient),
00038         iWindow(aWindow)
00039 {
00040 }
00041 
00042 void CGfxDirectScreenBitmap::ConstructL()
00043     {
00044     
00045         iDSBitmap =CDirectScreenBitmap::NewL();
00046         
00047     // Create the DSA object
00048     iDirectScreenAccess = CDirectScreenAccess::NewL(
00049         iClient,                // WS session
00050         *(CCoeEnv::Static()->ScreenDevice()),        // CWsScreenDevice
00051         iWindow,                // RWindowBase
00052         *this                   // MDirectScreenAccess
00053         );
00054 
00055     CActiveScheduler::Add(this);
00056     }
00057 
00058 CGfxDirectScreenBitmap::~CGfxDirectScreenBitmap()
00059         {
00060         Cancel();
00061         delete iDirectScreenAccess;
00062         delete iDSBitmap;
00063         }
00064 
00065         
00066    // Implement MDirectScreenAccess
00067 void CGfxDirectScreenBitmap::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/)
00068         {
00069         // Do not attempt to restart
00070         }
00071 
00072 void CGfxDirectScreenBitmap::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
00073         {
00074         Cancel();
00075         }
00076 
00077 void CGfxDirectScreenBitmap::RunL()
00078         {       
00079         ProcessFrame();
00080         }
00081 
00082 void CGfxDirectScreenBitmap::DoCancel()
00083         {
00084     // Cancel timer
00085     // Cancel DSA
00086     iDirectScreenAccess->Cancel();      
00087     iDSBitmap->Close();
00088         }
00089 
00090 TAcceleratedBitmapInfo CGfxDirectScreenBitmap::BeginDraw()
00091         {
00092         TAcceleratedBitmapInfo bitmapInfo;
00093         iDSBitmap->BeginUpdate(bitmapInfo);
00094         return bitmapInfo;
00095         }
00096 /*
00097  * EndDraw - Signal completion of drawing to the offscreen screen buffer.
00098  * Let the screen controller copy it to the LCD and notify completion via iStatus
00099  */
00100 void CGfxDirectScreenBitmap::EndDraw()
00101         {
00102         if(IsActive())
00103                 {
00104                 Cancel();
00105                 }
00106         iDSBitmap->EndUpdate(iStatus);
00107         SetActive();
00108         }
00109 /*
00110  * ProcessFrame - Fill the offscreen screen buffer with a animated image
00111  */
00112 void CGfxDirectScreenBitmap::ProcessFrame()
00113         {
00114         TAcceleratedBitmapInfo bmpInfo = BeginDraw();
00115         TUint8* screenAddress = bmpInfo.iAddress;
00116         TUint8* p = screenAddress;
00117         
00118         TInt width = bmpInfo.iSize.iWidth;
00119         TInt height = bmpInfo.iSize.iHeight;
00120         
00121         TInt byteShift = (1<< bmpInfo.iPixelShift)/8;
00122         if( bmpInfo.iPixelShift == 32 ) // work around bug in older Nokia firmware (Search for KIS000575 on Forum Nokia Knowledge base)
00123                 byteShift = 4;
00124         
00125         const TInt padding = byteShift -3;
00126         const TInt rowWidthInBytes = bmpInfo.iLinePitch;
00127 
00128         TInt y=height;
00129         while(--y)
00130                 {
00131                 TUint8* b=p;
00132                 for(TInt x=0; x<width; x++)
00133                         {
00134                         (*b++) = 255;                                                   // red
00135                         (*b++) = (x+iFrameCounter)%64 * 4;              // green
00136                         (*b++) = (y+(iFrameCounter/2))%64 * 4;  // blue
00137                         b+=padding;                                                             // pad
00138                         }
00139                 p += rowWidthInBytes;   //  reset to start of row in case of
00140                 }
00141         
00142         iFrameCounter++;        
00143         EndDraw();
00144 
00145         }
00146 
00147 void CGfxDirectScreenBitmap::StartL(TRect &aRect)
00148     {
00149     iControlScreenRect = aRect;
00150     User::LeaveIfError(
00151                 iDSBitmap->Create(iControlScreenRect, CDirectScreenBitmap::EDoubleBuffer));
00152     
00153     // Initialise DSA
00154     iDirectScreenAccess -> StartL();
00155     // Get graphics context for it
00156     iGc = iDirectScreenAccess -> Gc();
00157     iGc -> SetBrushStyle(CGraphicsContext::ESolidBrush);
00158     // Get region that DSA can draw in
00159     iRegion = iDirectScreenAccess -> DrawingRegion();
00160     // Set the display to clip to this region
00161     iGc -> SetClippingRegion(iRegion); 
00162 
00163     ProcessFrame();
00164     }
00165 
00166 void CGfxDirectScreenBitmap::StopL()
00167         {
00168         Cancel();
00169         }
00170 

Generated by  doxygen 1.6.2