os/graphics/graphicsdeviceinterface/screendriver/swins/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) 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 // WINS platform
    15 // 
    16 //
    17 
    18 #include <hal.h>
    19 #include "SCDRAW.H"
    20 #include "ScreenInfo.h"
    21 #include <graphics/gdi/gdiconsts.h>
    22 
    23 /**
    24 Creates an instance of CFbsDrawDevice class.
    25 @param aScreenNo Screen number
    26 @param aDispMode Display mode
    27 @param aScreenInfo Screen parameters: video memory address and screen size
    28 @return A pointer to the created CFbsDrawDevice object
    29 @leave System-wide error code including KErrNoMemory
    30 @internalComponent
    31 */
    32 static CFbsDrawDevice* CreateInstanceL(TInt aScreenNo,
    33 									   TDisplayMode aDispMode,
    34 									   const TScreenInfo& aScreenInfo)
    35 	{
    36 	TUint depths = 0;
    37 	// As multiple screens are possible, the (optional) second parameter is necessary here
    38 	// to find the color depth specific to this screen.
    39 	EmulatorColorDepth(depths, aScreenNo); 
    40 	ASSERT(depths);
    41 
    42 	CFbsDrawDevice* drawDevice = NULL;
    43 
    44 	switch(aDispMode)
    45 		{
    46 	case EGray2:
    47 		if (!(depths & KEmulGray2))
    48 			User::Leave(KErrNotSupported);
    49 		drawDevice = new(ELeave) CDrawOneBppScreenBitmap;
    50 		CleanupStack::PushL(drawDevice);
    51 		User::LeaveIfError((static_cast<CDrawOneBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
    52 																			aScreenInfo.iAddress,
    53 																			aScreenInfo.iSize));
    54 		break;
    55 	case EGray4:
    56 		if (!(depths & KEmulGray4))
    57 			User::Leave(KErrNotSupported);
    58 		drawDevice = new(ELeave) CDrawTwoBppScreenBitmap;
    59 		CleanupStack::PushL(drawDevice);
    60 		User::LeaveIfError((static_cast<CDrawTwoBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
    61 																			aScreenInfo.iAddress,
    62 																			aScreenInfo.iSize));
    63 		break;
    64 	case EGray16:
    65 		if (!(depths & KEmulGray16))
    66 			User::Leave(KErrNotSupported);
    67 		drawDevice = new(ELeave) CDrawFourBppScreenBitmapGray;
    68 		CleanupStack::PushL(drawDevice);
    69 		User::LeaveIfError((static_cast<CDrawFourBppScreenBitmapGray*> (drawDevice)) ->ConstructScreen(aScreenNo,
    70 																			aScreenInfo.iAddress,
    71 																			aScreenInfo.iSize));
    72 		break;
    73 	case EGray256:
    74 		if (!(depths & KEmulGray256))
    75 			User::Leave(KErrNotSupported);
    76 		drawDevice = new(ELeave) CDrawEightBppScreenBitmapGray;
    77 		CleanupStack::PushL(drawDevice);
    78 		User::LeaveIfError((static_cast<CDrawEightBppScreenBitmapGray*> (drawDevice)) ->ConstructScreen(aScreenNo,
    79 																			aScreenInfo.iAddress,
    80 																			aScreenInfo.iSize));
    81 		break;
    82 	case EColor16:
    83 		if (!(depths & KEmulColor16))
    84 			User::Leave(KErrNotSupported);
    85 		drawDevice = new(ELeave) CDrawFourBppScreenBitmapColor;
    86 		CleanupStack::PushL(drawDevice);
    87 		User::LeaveIfError((static_cast<CDrawFourBppScreenBitmapColor*> (drawDevice)) ->ConstructScreen(aScreenNo,
    88 																			aScreenInfo.iAddress,
    89 																			aScreenInfo.iSize));
    90 		break;
    91 	case EColor256:
    92 		if (!(depths & KEmulColor256))
    93 			User::Leave(KErrNotSupported);
    94 		drawDevice = new(ELeave) CDrawEightBppScreenBitmapColor;
    95 		CleanupStack::PushL(drawDevice);
    96 		User::LeaveIfError((static_cast<CDrawEightBppScreenBitmapColor*> (drawDevice)) ->ConstructScreen(aScreenNo,
    97 																			aScreenInfo.iAddress,
    98 																			aScreenInfo.iSize));
    99 		break;
   100 	case EColor4K:
   101 		if (!(depths & KEmulColor4K))
   102 			User::Leave(KErrNotSupported);
   103 		drawDevice = new(ELeave) CDrawTwelveBppScreenBitmap;
   104 		CleanupStack::PushL(drawDevice);
   105 		User::LeaveIfError((static_cast<CDrawTwelveBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
   106 																			aScreenInfo.iAddress,
   107 																			aScreenInfo.iSize));
   108 		break;
   109 	case EColor64K:
   110 		if (!(depths & KEmulColor64K))
   111 			User::Leave(KErrNotSupported);
   112 		drawDevice = new(ELeave) CDrawSixteenBppScreenBitmap;
   113 		CleanupStack::PushL(drawDevice);
   114 		User::LeaveIfError((static_cast<CDrawSixteenBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
   115 																			aScreenInfo.iAddress,
   116 																			aScreenInfo.iSize));
   117 		break;
   118 	case EColor16M:
   119 		if (!(depths & KEmulColor16M))
   120 			User::Leave(KErrNotSupported);
   121 		drawDevice = new(ELeave) CDrawTwentyFourBppScreenBitmap;
   122 		CleanupStack::PushL(drawDevice);
   123 		User::LeaveIfError((static_cast<CDrawTwentyFourBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
   124 																			aScreenInfo.iAddress,
   125 																			aScreenInfo.iSize));
   126 		break;
   127 	case EColor16MU:
   128 		if (!(depths & KEmulColor16M))
   129 			User::Leave(KErrNotSupported);
   130 		drawDevice = new(ELeave) CDrawUTwentyFourBppScreenBitmap;
   131 		CleanupStack::PushL(drawDevice);
   132 		User::LeaveIfError((static_cast<CDrawUTwentyFourBppScreenBitmap*> (drawDevice)) ->ConstructScreen(aScreenNo,
   133 																			aScreenInfo.iAddress,
   134 																			aScreenInfo.iSize));
   135 		break;
   136 	case EColor16MA:
   137 		if (!(depths & KEmulColor16M))
   138 			User::Leave(KErrNotSupported);
   139 		drawDevice = new(ELeave) CDrawThirtyTwoBppScreenBitmapAlpha;
   140 		CleanupStack::PushL(drawDevice);
   141 		User::LeaveIfError((static_cast<CDrawThirtyTwoBppScreenBitmapAlpha*> (drawDevice)) ->ConstructScreen(aScreenNo,
   142 																			aScreenInfo.iAddress,
   143 																			aScreenInfo.iSize));
   144 		break;
   145 	case EColor16MAP:
   146 		if (!(depths & KEmulColor16M))
   147 			User::Leave(KErrNotSupported);
   148 		drawDevice = new(ELeave) CDrawThirtyTwoBppScreenBitmapAlphaPM;
   149 		CleanupStack::PushL(drawDevice);
   150 		User::LeaveIfError((static_cast<CDrawThirtyTwoBppScreenBitmapAlphaPM*> (drawDevice)) ->ConstructScreen(aScreenNo,
   151 																			aScreenInfo.iAddress,
   152 																			aScreenInfo.iSize));
   153 		break;
   154 	default:
   155 		User::Leave(KErrNotSupported);
   156 		}
   157 
   158 	CleanupStack::Pop(); // drawDevice
   159 	return drawDevice;
   160 	}
   161 
   162 /**
   163 @deprecated Use NewScreenDeviceL(TInt aScreenNo, TDisplayMode aDispMode)
   164 */
   165 EXPORT_C CFbsDrawDevice* CFbsDrawDevice::NewScreenDeviceL(TScreenInfoV01 aInfo,
   166 														  TDisplayMode aDispMode)
   167 	{
   168 	__ASSERT_ALWAYS(aInfo.iScreenAddressValid && aInfo.iScreenAddress, Panic(EScreenDriverPanicInvalidWindowHandle));
   169 	TScreenInfo screenInfo(aInfo.iScreenAddress, aInfo.iScreenSize);
   170 	return ::CreateInstanceL(KDefaultScreenNo, aDispMode, screenInfo);
   171 	}
   172 
   173 /**
   174 Creates a new screen device instance, which implements CFbsDrawDevice interface.
   175 The method has to be implemented for each type of supported video hardware.
   176 @param aScreenNo Screen number
   177 @param aDispMode Requested display mode
   178 @return A pointer to just created screen device, which implements CFbsDrawDevice interface
   179 @leave KErrNoMemory Not enough memory
   180 	   KErrNotSupported The requested screen device type is not supported
   181 */
   182 EXPORT_C CFbsDrawDevice* CFbsDrawDevice::NewScreenDeviceL(TInt aScreenNo,
   183 														  TDisplayMode aDispMode)
   184 	{
   185 	TInt address = 0, width = 0, height = 0;
   186 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayMemoryAddress, address));
   187 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayXPixels, width));
   188 	User::LeaveIfError(HAL::Get(aScreenNo, HALData::EDisplayYPixels, height));
   189 	__ASSERT_ALWAYS(width > 0 && height > 0 && address != 0, Panic(EScreenDriverPanicInvalidHalValue));
   190 	TScreenInfo screenInfo(reinterpret_cast <TAny*> (address), TSize(width, height));
   191 	return ::CreateInstanceL(aScreenNo, aDispMode, screenInfo);
   192 	}
   193 
   194 /**
   195 Depending on the current graphics hardware this 
   196 will return one of the 16M video modes defined in
   197 TDisplayMode, or ENone if a 16M video mode is not supported.
   198 @see TDisplayMode
   199 @return	a 16M display mode or ENone.
   200 */
   201 EXPORT_C TDisplayMode CFbsDrawDevice::DisplayMode16M()
   202 	{
   203 	return EColor16MU;
   204 	}