os/graphics/graphicsdeviceinterface/screendriver/smomap/scnew.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.
     1 // Copyright (c) 2003-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 // This module implements the functions that create the screen class depending
    15 // on the screen type.
    16 // Include files                                                   
    17 // 
    18 //
    19 
    20 /**
    21  @file
    22 */
    23 /********************************************************************/
    24 #include <bitdraw.h>
    25 #include "scdraw.h"
    26 #include <hal.h>
    27 #include "ScreenInfo.h"
    28 #include <graphics/gdi/gdiconsts.h>
    29 
    30 /**
    31 Creates an instance of CFbsDrawDevice class.
    32 @param aScreenNo Screen number
    33 @param aDispMode Display mode
    34 @param aScreenInfo Screen parameters: video memory address and screen size
    35 @return A pointer to the created CFbsDrawDevice object
    36 @leave System-wide error code including KErrNoMemory
    37 @internalComponent
    38 */
    39 static CFbsDrawDevice* CreateInstanceL(TInt aScreenNo,
    40 									   TDisplayMode aDispMode,
    41 									   const TScreenInfo& aScreenInfo)
    42 	{
    43 	CFbsDrawDevice* drawDevice = NULL;
    44 
    45 	TInt bpp;
    46 	if(HAL::Get(aScreenNo, HALData::EDisplayMode, bpp) != KErrNone)
    47 		{
    48 		User::Leave(KErrNotSupported);
    49 		}
    50 	if(HAL::Get(aScreenNo, HALData::EDisplayBitsPerPixel, bpp) != KErrNone)
    51 		{
    52 		User::Leave(KErrNotSupported);
    53 		}
    54    
    55     //Switch the display mode, call the construtor of the class defined
    56     //in the ScmonXX.cpp or SccolXX.cpp file.
    57 	switch(aDispMode)
    58 		{
    59 	case EColor256: // 8 Bpp color mode
    60 		if(bpp == 8)
    61 			{
    62 			drawDevice = new (ELeave) CDrawEightBppScreenBitmapColor;
    63 			CleanupStack::PushL(drawDevice) ;
    64 			User::LeaveIfError(((CDrawEightBppScreenBitmapColor*)drawDevice)->ConstructScreenL(
    65                                                             aScreenNo,
    66 															aScreenInfo.iAddress, 
    67 															aScreenInfo.iSize));
    68 			}
    69 		else
    70 			{
    71 			User::Leave(KErrNotSupported);
    72 			}
    73 		break;
    74 
    75 	case EColor64K: // 16 Bpp color mode
    76 		if(bpp == 16)
    77 			{
    78 			drawDevice = new (ELeave) CDrawSixteenBppScreenBitmap;
    79 			CleanupStack::PushL(drawDevice);
    80 			User::LeaveIfError(((CDrawSixteenBppScreenBitmap*)drawDevice)->ConstructScreenL(
    81                                                             aScreenNo,
    82 															aScreenInfo.iAddress, 
    83 															aScreenInfo.iSize));
    84 			}
    85 		else
    86 			{
    87 			User::Leave(KErrNotSupported);
    88 			}
    89 		break;
    90    
    91    	case EColor16MU: // 24 unpacked Bpp color mode
    92 		if((bpp == 24 || bpp == 32) && aDispMode == CFbsDrawDevice::DisplayMode16M()) 	//there is some "ambiguity" about 24 and 32 bit modes... 
    93 	//They are both byte per color component, and both actually have 32 bits per pixel memory use.
    94 			{
    95 			drawDevice = new (ELeave) CDrawUTwentyFourBppScreenBitmap;
    96 			CleanupStack::PushL(drawDevice);
    97 			User::LeaveIfError(((CDrawUTwentyFourBppScreenBitmap*)drawDevice)->ConstructScreenL(
    98                                                             aScreenNo,
    99 															aScreenInfo.iAddress, 
   100 															aScreenInfo.iSize));
   101 			}
   102 		else
   103 			{
   104 			User::Leave(KErrNotSupported);
   105 			}
   106 		break;
   107 	
   108 	 case EColor16MA: // 32 Bpp color mode
   109 		if((bpp == 24 || bpp == 32) && aDispMode == CFbsDrawDevice::DisplayMode16M())  	//there is some "ambiguity" about 24 and 32 bit modes... 
   110 	//They are both byte per color component, and both actually have 32 bits per pixel memory use.
   111 			{
   112 			drawDevice = new (ELeave) CDrawThirtyTwoBppScreenBitmapAlpha;
   113 			CleanupStack::PushL(drawDevice);
   114 			User::LeaveIfError(((CDrawThirtyTwoBppScreenBitmapAlpha*)drawDevice)->ConstructScreenL(
   115                                                             aScreenNo,
   116 															aScreenInfo.iAddress, 
   117 															aScreenInfo.iSize));
   118 			}
   119 		else
   120 			{
   121 			User::Leave(KErrNotSupported);
   122 			}
   123 		break;
   124 		
   125 	case EColor16MAP: // 32 Bpp color mode
   126 		if((bpp == 24 || bpp == 32) && aDispMode == CFbsDrawDevice::DisplayMode16M()) 	//there is some "ambiguity" about 24 and 32 bit modes... 
   127 	//They are both byte per color component, and both actually have 32 bits per pixel memory use.
   128 			{
   129 			drawDevice = new (ELeave) CDrawThirtyTwoBppScreenBitmapAlphaPM;
   130 			CleanupStack::PushL(drawDevice);
   131 			User::LeaveIfError(((CDrawThirtyTwoBppScreenBitmapAlphaPM*)drawDevice)->ConstructScreenL(
   132                                                             aScreenNo,
   133 															aScreenInfo.iAddress, 
   134 															aScreenInfo.iSize));
   135 			}
   136 		else
   137 			{
   138 			User::Leave(KErrNotSupported);
   139 			}
   140 		break;
   141 
   142 	default:
   143 		User::Leave(KErrNotSupported);
   144 		}
   145 
   146 	CleanupStack::Pop(drawDevice);
   147     return drawDevice;
   148 	}
   149 
   150 
   151 /********************************************************************/
   152 /*  Implementation of CFbsDrawDevice class                          */
   153 /********************************************************************/
   154 
   155 /**
   156 This function calls the correct constructor in function of the display mode.
   157 @param aInfo, Structure of the LCD info
   158 @param aDispMode, display mode   
   159 @return A pointer to just created screen device, which implements CFbsDrawDevice interface
   160 @deprecated Use CFbsDrawDevice::NewScreenDeviceL(TInt aScreenNo, TDisplayMode aDispMode)
   161 */
   162 EXPORT_C CFbsDrawDevice* CFbsDrawDevice::NewScreenDeviceL(TScreenInfoV01 aInfo, TDisplayMode aDispMode)
   163 	{
   164     __ASSERT_ALWAYS(aInfo.iScreenAddressValid, Panic(EScreenDriverPanicInvalidWindowHandle));
   165 	TScreenInfo screenInfo(aInfo.iScreenAddress, aInfo.iScreenSize);
   166 	return ::CreateInstanceL(KDefaultScreenNo, aDispMode, screenInfo);
   167 	}
   168 
   169 /**
   170 Creates a new screen device instance, which implements CFbsDrawDevice interface.
   171 The method has to be implemented for each type of supported video hardware.
   172 @param aScreenNo Screen number
   173 @param aDispMode Requested display mode
   174 @return A pointer to just created screen device, which implements CFbsDrawDevice interface
   175 @leave KErrNoMemory Not enough memory
   176 	   KErrNotSupported The requested screen device type is not supported
   177 */
   178 EXPORT_C CFbsDrawDevice* CFbsDrawDevice::NewScreenDeviceL(TInt aScreenNo,
   179 														  TDisplayMode aDispMode)
   180 	{
   181 	TInt address = 0, width = 0, height = 0;
   182 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayMemoryAddress, address));
   183 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayXPixels, width));
   184 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayYPixels, height));
   185 	__ASSERT_ALWAYS(width > 0 && height > 0 && address != 0, Panic(EScreenDriverPanicInvalidHalValue));
   186 	TScreenInfo screenInfo(reinterpret_cast <TAny*> (address), TSize(width, height));
   187 	return ::CreateInstanceL(aScreenNo, aDispMode, screenInfo);
   188 	}
   189 
   190 /**
   191 Depending on the current graphics hardware this 
   192 will return one of the 16M video modes defined in
   193 TDisplayMode, or ENone if a 16M video mode is not supported.
   194 @see TDisplayMode
   195 @return	a 16M display mode or ENone.
   196 */
   197 EXPORT_C TDisplayMode CFbsDrawDevice::DisplayMode16M()
   198 	{
   199 //	return ENone;
   200 	return EColor16MA;
   201 	}