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