graphicsdeviceinterface/screendriver/smcot/SCCOL.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1997-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 <hal.h>
       
    17 #include "scdraw.h"
       
    18 
       
    19 /**
       
    20 Constructs the CDrawScreenBitmap object.
       
    21 @param aScreenNo Screen number. It will be used in HAL::Get() calls.
       
    22 @param aBitmapAddress The screen memory address.
       
    23 @param aSize Screen size
       
    24 @return System-wide error codes, KErrNone if the construction was successfull.
       
    25 */
       
    26 TInt CDrawScreenBitmap::ConstructScreen(TInt aScreenNo, TAny* aBitmapAddress,TSize aSize)
       
    27 	{
       
    28     iScreenNo = aScreenNo;
       
    29 	TInt ret = SCREEN_LAYOUT_BASE_BITMAP::Construct(aSize);
       
    30 	if (ret != KErrNone)
       
    31 		return ret;
       
    32 
       
    33 	//fixup for emulating smaller screen
       
    34 	TInt offset = 0;
       
    35 	// get the offset in bytes
       
    36 	ret = HAL::Get(iScreenNo, HALData::EDisplayOffsetBetweenLines, offset);
       
    37 
       
    38 	TInt bitsPerPixel = BitsPerPixel(iDispMode);
       
    39  	TInt bytesPerPixel  = (bitsPerPixel/8 + (bitsPerPixel % 8 ? 1 : 0));
       
    40 
       
    41 	if (ret == KErrNone )
       
    42 		{
       
    43 		// Find iLongwidth (in pixels) from the offset (in bytes).
       
    44 		if (bitsPerPixel >= 8)
       
    45 			{
       
    46 			// a pixel fits in 1 or more bytes
       
    47 		    iLongWidth =  offset / bytesPerPixel;
       
    48 			}
       
    49 			else
       
    50 			{
       
    51 			// 1 or more pixels per byte
       
    52 			TInt pixelsPerByte  = 8 / bitsPerPixel;
       
    53 		    iLongWidth =  offset * pixelsPerByte;
       
    54 			}
       
    55 		iScanLineWords = offset / 4;
       
    56 		
       
    57 		// correct the size of the ScanLineBuffer
       
    58 		User::Heap().Free(iScanLineBuffer);
       
    59 		iScanLineBuffer = (TUint32*)(User::Heap().Alloc(offset));
       
    60 		if(iScanLineBuffer == NULL)
       
    61 			return KErrNoMemory;
       
    62 		}
       
    63 	else
       
    64 		{
       
    65 		return ret;
       
    66 		}
       
    67 	//fixup for emulating smaller screen
       
    68 
       
    69 	offset = 0; // Pass in display mode
       
    70 	ret = HAL::Get(iScreenNo, HALData::EDisplayOffsetToFirstPixel,offset);
       
    71 	iBits = (TUint32*)aBitmapAddress;
       
    72 	iBits += offset / sizeof(TUint32);
       
    73 	return ret;
       
    74 	}
       
    75 
       
    76 void CDrawScreenBitmap::SetDisplayMode(CFbsDrawDevice* aDrawDevice)
       
    77 	{
       
    78 	CopyOldSettings(aDrawDevice);
       
    79 	}
       
    80 
       
    81 void CDrawScreenBitmap::OrientationsAvailable(TBool aOrientation[4])
       
    82 	{
       
    83 	aOrientation[EOrientationNormal] = ETrue;
       
    84 	aOrientation[EOrientationRotated90] = ETrue;
       
    85 	aOrientation[EOrientationRotated180] = ETrue;
       
    86 	aOrientation[EOrientationRotated270] = ETrue;
       
    87 	}
       
    88 
       
    89 TBool CDrawScreenBitmap::SetOrientation(TOrientation aOrientation)
       
    90 	{
       
    91 	iOrientation = aOrientation;
       
    92 	return ETrue;
       
    93 	}
       
    94 
       
    95 TInt CDrawScreenBitmap::HorzTwipsPerThousandPixels() const
       
    96 	{
       
    97 	if (iSize.iWidth == 0)
       
    98 		return 0;
       
    99 
       
   100 	TInt twips = 0;
       
   101 	HAL::Get(iScreenNo, HALData::EDisplayXTwips,twips);
       
   102 
       
   103 	return twips * 1000 / iSize.iWidth; // iSize gets iWidth and iHeight swapped by changing the orientation so always use iWidth
       
   104 	}
       
   105 
       
   106 TInt CDrawScreenBitmap::VertTwipsPerThousandPixels() const
       
   107 	{
       
   108 	if (iSize.iHeight == 0)
       
   109 		return 0;
       
   110 
       
   111 	TInt twips = 0;
       
   112 	HAL::Get(iScreenNo, HALData::EDisplayYTwips,twips);
       
   113 
       
   114 	return twips * 1000 / iSize.iHeight;
       
   115 	}
       
   116