graphicsdeviceinterface/bitgdi/sbit/BitmapSpec.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2000-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 //
       
    15 
       
    16 #include <graphicsaccelerator.h>
       
    17 #include <fbs.h>
       
    18 
       
    19 
       
    20 /** 
       
    21 Constructor with a software or hardware bitmap.
       
    22 Its type is initialised to EFbsBitmap or EHardwareBitmap accordingly.
       
    23 
       
    24 @param aBitmap The bitmap which the object will access. 
       
    25 */
       
    26 EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(CFbsBitmap* aBitmap)
       
    27 	{
       
    28 	RHardwareBitmap hwb(aBitmap->HardwareBitmapHandle());
       
    29 	if(hwb.iHandle)
       
    30 		{
       
    31 		::new (this) TAcceleratedBitmapSpec(hwb);
       
    32 		return;
       
    33 		}
       
    34 	iType = EFbsBitmap;
       
    35 	iHandle = REINTERPRET_CAST(TInt,aBitmap);
       
    36 
       
    37 	iLockStatus = EBitmapNeedsLocking;
       
    38 
       
    39 	iSpare1 = 0;
       
    40 	iSpare2 = 0;
       
    41 	}
       
    42 
       
    43 /** 
       
    44 Constructor with a hardware bitmap. Its type is initialised to EHardwareBitmap. 
       
    45 	
       
    46 @param aBitmap The bitmap which the object will access. 
       
    47 */
       
    48 EXPORT_C TAcceleratedBitmapSpec::TAcceleratedBitmapSpec(RHardwareBitmap aBitmap)
       
    49 	{
       
    50 	iType = EHardwareBitmap;
       
    51 	iHandle = aBitmap.iHandle;
       
    52 	iLockStatus = EBitmapIsStatic;
       
    53 	iSpare1 = 0;
       
    54 	iSpare2 = 0;
       
    55 	}
       
    56 
       
    57 /** 
       
    58 Fills a TAcceleratedBitmapInfo structure with data for the bitmap.
       
    59 
       
    60 This data is only valid for the duration of any processing between a Lock()/Unlock() 
       
    61 pair.
       
    62 
       
    63 For compressed bitmaps the line pitch has no meaning so it is set to the negation
       
    64 of the compression type as defined by TBitmapfileCompression.
       
    65 
       
    66 @param aInfo On return, holds the information needed to directly access the 
       
    67 bitmap.
       
    68 @return KErrNone if sucessful, otherwise one of the system error codes, including 
       
    69 KErrUnknown if the object's type is ENoBitmap. 
       
    70 */
       
    71 EXPORT_C TInt TAcceleratedBitmapSpec::GetInfo(TAcceleratedBitmapInfo& aInfo) const
       
    72 	{
       
    73 	switch(iType)
       
    74 		{
       
    75 		case EFbsBitmap:
       
    76 			{
       
    77 			CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle);
       
    78 			aInfo.iDisplayMode = bmp->DisplayMode();
       
    79 			aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress());
       
    80 			aInfo.iSize = bmp->SizeInPixels();
       
    81 			SEpocBitmapHeader header = bmp->Header();
       
    82 			if (header.iCompression != ENoBitmapCompression)
       
    83 				{
       
    84 				aInfo.iLinePitch = -header.iCompression;
       
    85 				}
       
    86 			else
       
    87 				{
       
    88 				aInfo.iLinePitch = bmp->ScanLineLength(aInfo.iSize.iWidth,aInfo.iDisplayMode);
       
    89 				}
       
    90 			TUid extendedType = bmp->ExtendedBitmapType();
       
    91 			if (extendedType != KNullUid)
       
    92 				{
       
    93 				aInfo.iPixelShift = extendedType.iUid;
       
    94 				aInfo.iDataSize = bmp->DataSize();
       
    95 				}
       
    96 			else
       
    97 				{
       
    98 				aInfo.iPhysicalAddress = NULL;
       
    99 				switch(aInfo.iDisplayMode)
       
   100 					{
       
   101 					case ENone:
       
   102 						aInfo.iPixelShift = -1;
       
   103 						break;
       
   104 					case EGray2:
       
   105 						aInfo.iPixelShift = 0;
       
   106 						break;
       
   107 					case EGray4:
       
   108 						aInfo.iPixelShift = 1;
       
   109 						break;
       
   110 					case EGray16:
       
   111 					case EColor16:
       
   112 						aInfo.iPixelShift = 2;
       
   113 						break;
       
   114 					case EGray256:
       
   115 					case EColor256:
       
   116 						aInfo.iPixelShift = 3;
       
   117 						break;
       
   118 					case EColor4K:
       
   119 					case EColor64K:
       
   120 						aInfo.iPixelShift = 4;
       
   121 						break;
       
   122 					case EColor16M:
       
   123 					case ERgb:
       
   124 					case EColor16MU:
       
   125 					case EColor16MA: 
       
   126 					case EColor16MAP: 
       
   127 						aInfo.iPixelShift = 5;
       
   128 						break;
       
   129 					default:
       
   130 						aInfo.iPixelShift = -1;
       
   131 						break;
       
   132 					}
       
   133 				}
       
   134 			}
       
   135 			return KErrNone;
       
   136 
       
   137 		case EHardwareBitmap:
       
   138 			return RHardwareBitmap(iHandle).GetInfo(aInfo);
       
   139 
       
   140 		case ENoBitmap:
       
   141 		default:
       
   142 			Mem::FillZ(&aInfo,sizeof(aInfo));
       
   143 			return KErrUnknown;
       
   144 		}
       
   145 	}
       
   146 
       
   147 /** Locks the bitmap, if required.
       
   148 @param  aCount Reference to a bitmap lock count object for nesting 
       
   149 (only the first instance does the locking). */
       
   150 EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount)
       
   151 	{
       
   152 	switch(iType)
       
   153 		{
       
   154 		case EFbsBitmap:
       
   155 			if(aCount.Inc()==0)
       
   156 				REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess();
       
   157 			break;
       
   158 
       
   159 		case ENoBitmap:
       
   160 		case EHardwareBitmap:
       
   161 		default:
       
   162 			// Never needs locking
       
   163 			return;
       
   164 		}
       
   165 	}
       
   166 
       
   167 /** Locks the bitmap, if required, setting the accelerated
       
   168 bitmap information address.
       
   169 @param  aCount Reference to a bitmap lock count object for nesting 
       
   170 (only the first instance does the locking).
       
   171 @param  aInfo Information structure to set the address in. */
       
   172 EXPORT_C void TAcceleratedBitmapSpec::DoLock(TBitmapLockCount& aCount,TAcceleratedBitmapInfo& aInfo)
       
   173 	{
       
   174 	switch(iType)
       
   175 		{
       
   176 		case EFbsBitmap:
       
   177 			{
       
   178 			if(aCount.Inc()==0)
       
   179 				REINTERPRET_CAST(CFbsBitmap*,iHandle)->BeginDataAccess();
       
   180 
       
   181 			CFbsBitmap* bmp = REINTERPRET_CAST(CFbsBitmap*,iHandle);
       
   182 			aInfo.iAddress = REINTERPRET_CAST(TUint8*,bmp->DataAddress());
       
   183 			}
       
   184 			break;
       
   185 
       
   186 		case ENoBitmap:
       
   187 		case EHardwareBitmap:
       
   188 		default:
       
   189 			// Never needs locking
       
   190 			return;
       
   191 		}
       
   192 	}
       
   193 
       
   194 /** Unlocks the bitmap, if required.
       
   195 @param  aCount Reference to a bitmap lock count object for nesting 
       
   196 (only the last instance does the unlocking). */
       
   197 EXPORT_C void TAcceleratedBitmapSpec::DoUnlock(TBitmapLockCount& aCount)
       
   198 	{
       
   199 	switch(iType)
       
   200 		{
       
   201 		case EFbsBitmap:
       
   202 			if(aCount.Dec()==0)
       
   203 				REINTERPRET_CAST(CFbsBitmap*,iHandle)->EndDataAccess();
       
   204 			break;
       
   205 
       
   206 		case ENoBitmap:
       
   207 		case EHardwareBitmap:
       
   208 		default:
       
   209 			// Never needs unlocking
       
   210 			return;
       
   211 		}
       
   212 	}
       
   213