graphicsdeviceinterface/screendriver/sgeneric/scdraw.inl
changeset 0 5d03bc08d59c
child 2 5e30ef2e26cb
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 templated classes used to define screen display instances.
       
    15 // It only needs to be #included into scnew.cpp whisch is the only place the full-qualified templates are instanced.
       
    16 // Most of these methods are simply shims to the SurfaceHelper class.
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 #ifndef __SCDRAW_INL__
       
    24 #define __SCDRAW_INL__
       
    25 
       
    26 #include "scdraw.h"	//should have already happened.
       
    27 
       
    28 //
       
    29 // Implementation of  template CGenericScreenDevice
       
    30 // Arguments  <class T>
       
    31 // Defines the common portions of a screendriver for GCE 
       
    32 //	the actual mode and the bits per pixel (or pixels per word) is not specified.
       
    33 //
       
    34 
       
    35 
       
    36 /**	Nothing to do to init the screen for the display modes currently supported.
       
    37  * This is the place to set up the palette for low-colour screen devices, possibly including 12-bit.
       
    38  **/
       
    39 template <class T> TInt  CGenericScreenDevice<T>::InitScreen()
       
    40 	{
       
    41 	return KErrNone ;
       
    42 	}
       
    43 
       
    44 //Construct splits into 2 methods. This portion is not dependent on pixel format
       
    45 template <class T> TInt  CGenericScreenDevice<T>::ConstructScreen(TInt , TAny *, TSize aSize, TInt )
       
    46 	{
       
    47 	CDrawXxxBppBitmap::iScanLineWords = iHelper.BytesPerScanline() / 4;
       
    48 	if (CDrawXxxBppBitmap::iScanLineWords==0)
       
    49 		{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
       
    50 		return KErrHardwareNotAvailable;
       
    51 		}
       
    52 	TInt ret = CDrawXxxBppBitmap::Construct(aSize);
       
    53 	if (ret == KErrNone)
       
    54 		{
       
    55 		CDrawXxxBppBitmap::iBits = (TUint32*)iHelper.AddressFirstPixel();
       
    56 		if (CDrawXxxBppBitmap::iBits==NULL)
       
    57 			{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
       
    58 			ret=KErrHardwareNotAvailable;
       
    59 			}
       
    60 		}
       
    61 	return ret;
       
    62 	}
       
    63 
       
    64 //Switch from the previous aDrawDevice to this one
       
    65 template <class T> void CGenericScreenDevice<T>::SetDisplayMode(CFbsDrawDevice* aDrawDevice)
       
    66 	{
       
    67 	iHelper.ResetUpdateRegion();
       
    68 
       
    69 	// Inherit the original draw device's orientation, if available.
       
    70 	TDeviceOrientation devOrientation = EDeviceOrientationNormal;
       
    71 
       
    72 	TAny* interface = NULL;
       
    73 	TInt ret = aDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
       
    74 	//can't survive setting a different orientation to the source device so must read it successfully
       
    75 	__ASSERT_ALWAYS(ret == KErrNone,Panic(EScreenDriverPanicIncompatiblePreviousDevice));
       
    76 	devOrientation = reinterpret_cast<MSurfaceId*>(interface)->DeviceOrientation();
       
    77 	//SetDeviceOrientation will panic if it is incompatible
       
    78 	SetDeviceOrientation(devOrientation);
       
    79 
       
    80 	CDrawXxxBppBitmap::CopyOldSettings(aDrawDevice);
       
    81 	InitScreen();
       
    82 	}
       
    83 
       
    84 template <class T> TInt CGenericScreenDevice<T>::HorzTwipsPerThousandPixels() const
       
    85 	{
       
    86  	return iHelper.HorzTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
       
    87 	}
       
    88 
       
    89 template <class T> TInt CGenericScreenDevice<T>::VertTwipsPerThousandPixels() const
       
    90 	{
       
    91 	return iHelper.VertTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
       
    92 	}
       
    93 
       
    94 template <class T> void CGenericScreenDevice<T>::Update()
       
    95 	{
       
    96 	iHelper.Update();
       
    97 	}
       
    98 
       
    99 template <class T> void CGenericScreenDevice<T>::Update(const TRegion& aRegion)
       
   100 	{
       
   101 	iHelper.Update(aRegion);
       
   102 	}
       
   103 
       
   104 template <class T> void CGenericScreenDevice<T>::UpdateRegion(const TRect& aRect)
       
   105 	{
       
   106 	iHelper.UpdateRegion(aRect);
       
   107 	}
       
   108 
       
   109 template <class T> TInt CGenericScreenDevice<T>::GetInterface(TInt aInterfaceId, TAny*& aInterface)
       
   110 	{
       
   111 	if(aInterfaceId == KSurfaceInterfaceID)
       
   112 	    {
       
   113 		aInterface = static_cast <MSurfaceId*> (this);
       
   114 		return KErrNone;
       
   115 	    }
       
   116 	else
       
   117 		{
       
   118 	    return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface);
       
   119 		}
       
   120 	}
       
   121 
       
   122 template <class T> void CGenericScreenDevice<T>::GetSurface(TSurfaceId& aSid) const 
       
   123 	{
       
   124 	iHelper.GetSurface(aSid);
       
   125 	}
       
   126 
       
   127 
       
   128 template <class T> TUint CGenericScreenDevice<T>::DeviceOrientationsAvailable() const 
       
   129 	{
       
   130 	return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize);
       
   131 	}
       
   132 
       
   133 template <class T> TDeviceOrientation CGenericScreenDevice<T>::DeviceOrientation() const 
       
   134 	{
       
   135 	return iHelper.DeviceOrientation();
       
   136 	}
       
   137 
       
   138 //
       
   139 // Implementation of  template CPalettizedScreenDevice
       
   140 // Arguments  <class T,TDisplayMode displayMode,TInt pixelsPerWord>
       
   141 // Defines a screendriver for GCE with a mode specified without using a GUID, probably palettized
       
   142 //
       
   143 //
       
   144 
       
   145 
       
   146 //Initialise palletised modes that are not assigned GUIDs
       
   147 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
       
   148 TInt  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
       
   149 	{
       
   150 	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID
       
   151 	if (ret != KErrNone)
       
   152 		return ret;
       
   153 	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
       
   154 	}
       
   155 
       
   156 //Set size members based on pixel width/height, but also set stride member using pixels per word
       
   157 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
       
   158 void CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetSize(const TSize& aSize)
       
   159 	{
       
   160 	CDrawBitmap::SetSize(aSize);
       
   161 	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
       
   162 	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
       
   163 	}
       
   164 	
       
   165 
       
   166 //sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
       
   167 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
       
   168 TBool  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
       
   169 	{
       
   170 	TSize newSize;
       
   171 
       
   172 	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
       
   173 		{
       
   174 		return EFalse;
       
   175 		}
       
   176 
       
   177 	// Need to update size, scan line size, etc.
       
   178 	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
       
   179 	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
       
   180 	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
       
   181 	CGenericScreenDevice::SetSize(newSize);
       
   182 
       
   183 	return ETrue;
       
   184 	}
       
   185 
       
   186 	
       
   187 //
       
   188 // Implementation of  template CGuidScreenDevice
       
   189 // Arguments  <class T,TInt guidMode,TInt pixelsPerWord>
       
   190 // Defines a screendriver for GCE with a mode specified using a GUID, probably flat colour
       
   191 //
       
   192 //
       
   193 
       
   194 //Initialise modes that have been assigned GUIDs
       
   195 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
       
   196 TInt  CGuidScreenDevice<T,guidMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
       
   197 	{
       
   198 	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode);
       
   199 	if (ret != KErrNone)
       
   200 		{
       
   201 		return ret;
       
   202 		}
       
   203 	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
       
   204 	}
       
   205 
       
   206 
       
   207 //sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
       
   208 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
       
   209 TBool  CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
       
   210 	{
       
   211 	TSize newSize;
       
   212 
       
   213 	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
       
   214 		{
       
   215 		return EFalse;
       
   216 		}
       
   217 
       
   218 	// Need to update size, scan line size, etc.
       
   219 	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
       
   220 	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
       
   221 	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
       
   222 	CGenericScreenDevice::SetSize(newSize);
       
   223 
       
   224 	return ETrue;
       
   225 	}
       
   226 
       
   227 
       
   228 
       
   229 //Set size members based on pixel width/height, but also set stride member using pixels per word
       
   230 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
       
   231 void CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetSize(const TSize& aSize)
       
   232 	{
       
   233 	CDrawBitmap::SetSize(aSize);
       
   234 	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
       
   235 	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
       
   236 	}
       
   237 	
       
   238 
       
   239 
       
   240 
       
   241 
       
   242 #endif	//__SCDRAW_INL__