uifw/AvKon/AknExtendedFader/src/AknExtendedFaderImpl.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #define GRAPHICS_BUILD_WSERV2 1
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <bitdev.h>
       
    21 #include <bitdraw.h>
       
    22 #include <bitdrawinterfaceid.h>
       
    23 #include <bmalphablend.h>
       
    24 
       
    25 #include "AknExtendedFaderImpl.h"
       
    26 #include "AknExtendedFaderGfx.h"
       
    27 #include "AknExtendedFaderTraces.h"
       
    28 
       
    29 
       
    30 _LIT(KAknExtendedFaderName, "AknExtendedFader");
       
    31 
       
    32 
       
    33 class CHelperFbsDevice : public CFbsBitmapDevice
       
    34 {
       
    35 public:
       
    36 	CFbsDrawDevice* DrawDevice() { return iDrawDevice; }
       
    37 };
       
    38 
       
    39 CAknExtendedFader* CAknExtendedFader::CreateL()
       
    40 	{
       
    41 	TRACE("CAknExtendedFader::CreateL");
       
    42 	return new (ELeave) CAknExtendedFader;
       
    43 	}
       
    44 	
       
    45 void CAknExtendedFader::ConstructL(MWsGraphicDrawerEnvironment& aEnv,const TDesC8& /*aData*/)
       
    46 	{
       
    47 	TRACE("CAknExtendedFader::ConstructL >>");
       
    48 	
       
    49 	BaseConstructL(aEnv);
       
    50 	
       
    51 	// Start P&S watchers
       
    52 	//iStartupWatcher = CAknExtendedFaderStartupWatcher::NewL(*this);  <-- Can be added if needs to watch startup, but probably not needed
       
    53 	iColorSchemeWatcher = CAknExtendedFaderColorSchemeWatcher::NewL(*this);
       
    54 	
       
    55 	TRACE("CAknExtendedFader::ConstructL <<");
       
    56 	}
       
    57 
       
    58 // By default do white fader
       
    59 CAknExtendedFader::CAknExtendedFader() : 
       
    60 	iColorOverlayR(0xFF), iColorOverlayG(0x00), iColorOverlayB(0x00),
       
    61   	iBlackMap(16), iWhiteMap(140)
       
    62 	{
       
    63 	}
       
    64 	
       
    65 CAknExtendedFader::~CAknExtendedFader()
       
    66 	{
       
    67 	TRACE("CAknExtendedFader::~CAknExtendedFader");
       
    68 	
       
    69 	delete iStartupWatcher; iStartupWatcher = 0;
       
    70 	delete iColorSchemeWatcher; iColorSchemeWatcher = 0;
       
    71 	
       
    72 	TRACE("CAknExtendedFader::~CAknExtendedFader <<");
       
    73 	}
       
    74 
       
    75 TBool CAknExtendedFader::DoFastFading(CFbsBitGc* aBitGc, const TRegion * aRegion)
       
    76 	{
       
    77 	TRACE("CAknExtendedFader::DoFastFading >>");
       
    78 	
       
    79 	// Get the drawdevice
       
    80 	CHelperFbsDevice* device = static_cast<CHelperFbsDevice*>(aBitGc->Device());
       
    81 	if(!device)
       
    82 		{
       
    83 		TRACE("CAknExtendedFader::DoFastFading: !device");
       
    84 		return EFalse;
       
    85 		}
       
    86 	
       
    87 	CFbsDrawDevice* drawDevice = device->DrawDevice();
       
    88 	if(!drawDevice)
       
    89 		{
       
    90 		TRACE("CAknExtendedFader::DoFastFading: !drawDevice");
       
    91 		return EFalse;
       
    92 		}
       
    93 	
       
    94 	device->DrawingBegin();
       
    95 	
       
    96 	// Display mode
       
    97 	TDisplayMode displayMode = drawDevice->DisplayMode();
       
    98 	TRACE1("CAknExtendedFader::DoFastFading: display mode = %d", displayMode);
       
    99 	
       
   100 	TBool ret = EFalse;
       
   101 	switch(displayMode)
       
   102 		{
       
   103 		case EColor64K:
       
   104 			ret = DoFastFading64K(drawDevice, aRegion);
       
   105 			break;
       
   106 			
       
   107 		case EColor16MU:
       
   108 			// fall-through
       
   109 			
       
   110 		case EColor16MA:
       
   111 			ret = DoFastFading16MX(drawDevice, aRegion);
       
   112 			break;
       
   113 			
       
   114 		default:
       
   115 			// Other modes not supported
       
   116 			ret = EFalse;
       
   117 			break;
       
   118 		}
       
   119 	
       
   120 	device->DrawingEnd();
       
   121 	
       
   122 	TRACE("CAknExtendedFader::DoFastFading <<");
       
   123 	return ret;
       
   124 	}
       
   125 	
       
   126 TBool CAknExtendedFader::DoFastFading16MX(CFbsDrawDevice* aDrawDevice, const TRegion * aRegion)
       
   127 	{
       
   128 	// Do fast fading for 32-bit graphics
       
   129 	TRACE("CAknExtendedFader::DoFastFading16MX >>");	
       
   130 	
       
   131 	TAny* ptr = NULL;
       
   132 	TInt ret = aDrawDevice->GetInterface(KFastBlit2InterfaceID, ptr);
       
   133 	if(ret!=KErrNone)
       
   134 		{
       
   135 		// We need to get the fastblit2 interface to access the image data
       
   136 		TRACE("CAknExtendedFader::DoFastFading16MX: !fastblit2");
       
   137 		return EFalse;
       
   138 		}
       
   139 	
       
   140 	MFastBlit2* interface = static_cast<MFastBlit2*>(ptr);
       
   141 		
       
   142 	TUint32* dataAddress = const_cast<TUint32*>(interface->Bits());
       
   143 	if(!dataAddress)
       
   144 		{
       
   145 		TRACE("CAknExtendedFader::DoFastFading16MX: !dataAddress");
       
   146 		return EFalse;
       
   147 		}
       
   148 
       
   149 	// Image width often != scanline length
       
   150 	TSize size(aDrawDevice->SizeInPixels());
       
   151 	TInt strideInPixels = aDrawDevice->ScanLineBytes() >> 2;
       
   152 
       
   153 	TInt rectCount = aRegion->Count();
       
   154 	
       
   155 	TInt fadeMapFactor = iWhiteMap - iBlackMap;
       
   156 	TInt fadeMapOffset = iBlackMap;
       
   157 
       
   158 	for(TInt i=0; i<rectCount; i++)
       
   159 		{
       
   160 		const TRect& rect((*aRegion)[i]);
       
   161 		
       
   162 		TRACE5("CAknExtendedFader::DoFastFading16MX: rect %d = %d.%d -> %d.%d", i+1, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
       
   163 
       
   164 		TAknExtendedFaderGfx::FadeRect_GrayColorize_16MX(dataAddress, strideInPixels, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY, fadeMapFactor, fadeMapOffset, iColorOverlayR, iColorOverlayG, iColorOverlayB);
       
   165 		
       
   166 		// Ensure screen device is informed of area to update
       
   167 		aDrawDevice->UpdateRegion(rect);
       
   168 		}
       
   169 
       
   170 	TRACE("CAknExtendedFader::DoFastFading16MX <<");	
       
   171 	return ETrue;
       
   172 	}
       
   173 
       
   174 TBool CAknExtendedFader::DoFastFading64K(CFbsDrawDevice* aDrawDevice, const TRegion * aRegion)
       
   175 	{
       
   176 	// Do fast fading for 16-bit graphics
       
   177 	TRACE("CAknExtendedFader::DoFastFading64K >>");	
       
   178 	
       
   179 	TAny* ptr = NULL;
       
   180 	TInt ret = aDrawDevice->GetInterface(KFastBlit2InterfaceID, ptr);
       
   181 	if(ret!=KErrNone)
       
   182 		{
       
   183 		// We need to get the fastblit2 interface to access the image data
       
   184 		TRACE("CAknExtendedFader::DoFastFading64K: !fastblit2");
       
   185 		return EFalse;
       
   186 		}
       
   187 	
       
   188 	MFastBlit2* interface = static_cast<MFastBlit2*>(ptr);
       
   189 		
       
   190 	TUint32* dataAddress = const_cast<TUint32*>(interface->Bits());
       
   191 	if(!dataAddress)
       
   192 		{
       
   193 		TRACE("CAknExtendedFader::DoFastFading64K: !dataAddress");
       
   194 		return EFalse;
       
   195 		}
       
   196 
       
   197 	// Image width often != scanline length
       
   198 	TSize size(aDrawDevice->SizeInPixels());
       
   199 	TInt strideInPixels = aDrawDevice->ScanLineBytes() >> 1;
       
   200 
       
   201 	TInt rectCount = aRegion->Count();
       
   202 	
       
   203 	TInt fadeMapFactor = iWhiteMap - iBlackMap;
       
   204 	TInt fadeMapOffset = iBlackMap;
       
   205 
       
   206 	for(TInt i=0; i<rectCount; i++)
       
   207 		{
       
   208 		const TRect& rect((*aRegion)[i]);
       
   209 		
       
   210 		TRACE5("CAknExtendedFader::DoFastFading64K: rect %d = %d.%d -> %d.%d", i+1, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY);
       
   211 
       
   212 		TAknExtendedFaderGfx::FadeRect_GrayColorize_64K((TUint16*)dataAddress, strideInPixels, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY, fadeMapFactor, fadeMapOffset, iColorOverlayR, iColorOverlayG, iColorOverlayB);
       
   213 
       
   214 		// Ensure screen device is informed of area to update
       
   215 		aDrawDevice->UpdateRegion(rect);
       
   216 		}
       
   217 
       
   218 	TRACE("CAknExtendedFader::DoFastFading64K <<");	
       
   219 	return ETrue;
       
   220 	}
       
   221 
       
   222 void CAknExtendedFader::FadeArea(CFbsBitGc* aBitGc,const TRegion * aRegion)
       
   223 	{
       
   224 	if(!aBitGc || !aRegion)
       
   225 		{
       
   226 		return;
       
   227 		}
       
   228 
       
   229 	TRACE("CAknExtendedFader::FadeArea >>");
       
   230 		
       
   231 	TInt rectCount = aRegion->Count();
       
   232 	if(!rectCount)
       
   233 		{
       
   234 		// Quick bailout if there is nothing to fade
       
   235 		return;
       
   236 		}
       
   237 
       
   238   	aBitGc->Reset();
       
   239 	if(!DoFastFading(aBitGc, aRegion))
       
   240 	{
       
   241 		// For some reason fast fading was not possible (wrong display mode?), use legacy fading.
       
   242 		TRACE("CAknExtendedFader::FadeArea: Do traditional fading");
       
   243 	  	aBitGc->SetFadingParameters(iBlackMap,iWhiteMap);
       
   244 		aBitGc->FadeArea(aRegion);
       
   245 	}
       
   246 		
       
   247 	TRACE("CAknExtendedFader::FadeArea <<");
       
   248 	}
       
   249 
       
   250 void CAknExtendedFader::SetFadingParameters(const TDesC8& /*aData*/)
       
   251   	{
       
   252 	// No implementation needed
       
   253   	}
       
   254 
       
   255 TAny* CAknExtendedFader::ResolveObjectInterface(TUint aTypeId)
       
   256 	{
       
   257 	switch (aTypeId)
       
   258 		{
       
   259 		case MWsFader::EWsObjectInterfaceId:
       
   260 			return static_cast<MWsFader*>(this);
       
   261 		}
       
   262 
       
   263 	return NULL;
       
   264 	}
       
   265 
       
   266 const TDesC& CAknExtendedFader::PluginName() const
       
   267 	{
       
   268 	return KAknExtendedFaderName;
       
   269 	}
       
   270 
       
   271 void CAknExtendedFader::GlobalSystemStateChangedL(TPSGlobalSystemState aState)
       
   272 	{
       
   273 	TRACE1("CAknExtendedFader::GlobalSystemStateChangedL: aState = %d", aState);
       
   274 	}
       
   275 
       
   276 void CAknExtendedFader::ColorSchemeChanged(const TUint32 &aNewColor, const TUint8& aNewBlackMap, const TUint8& aNewWhiteMap)
       
   277 	{
       
   278 	TRACE3("CAknExtendedFader::ColorSchemeChanged: aNewColor=%08X, aNewBlackMap=%08X, aNewWhiteMap=%08X", aNewColor, aNewBlackMap, aNewWhiteMap);
       
   279 		
       
   280 	// Save fader values
       
   281 	iBlackMap = aNewBlackMap;
       
   282 	iWhiteMap = aNewWhiteMap;
       
   283 	
       
   284 	// Save color scheme as separate R,G,B
       
   285 	iColorOverlayR = (aNewColor>>16)&0xFF;
       
   286 	iColorOverlayG = (aNewColor>>8)&0xFF;
       
   287 	iColorOverlayB = aNewColor&0xFF;
       
   288 	
       
   289 	//iBlackMap = 16;
       
   290 	//iWhiteMap = 140;
       
   291 	
       
   292 	//iColorOverlayR = 0xFF;
       
   293 	//iColorOverlayG = 0x00;
       
   294 	//iColorOverlayB = 0x00;
       
   295 	}
       
   296