os/graphics/graphicsdeviceinterface/screendriver/sgeneric/scdraw.inl
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2010 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, iHelper.BytesPerScanline());
    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     if(!aRegion.IsEmpty() && !aRegion.CheckError())
   102         {
   103         if (aRegion.Count()>KMaxUpdateRegionRectangles)
   104             {
   105             UpdateRegion(aRegion.BoundingRect());
   106             }
   107         else
   108             {
   109             TInt rcCnt = aRegion.Count();
   110             for (TInt ii=0; ii < rcCnt; ++ii)
   111                 {  
   112                 UpdateRegion(aRegion[ii]);  //Applies deorientate (offset, scale, rotate)
   113                 }
   114             }
   115         }
   116     Update();
   117 	}
   118 
   119 template <class T> void CGenericScreenDevice<T>::UpdateRegion(const TRect& aRect)
   120     {
   121     const TRect rect = CDrawXxxBppBitmap::DeOrientate(aRect);//rect - physical coordinates
   122     
   123     iHelper.UpdateRegion(rect);
   124     }
   125 
   126 template <class T> TInt CGenericScreenDevice<T>::GetInterface(TInt aInterfaceId, TAny*& aInterface)
   127 	{
   128 	if(aInterfaceId == KSurfaceInterfaceID)
   129 	    {
   130 		aInterface = static_cast <MSurfaceId*> (this);
   131 		return KErrNone;
   132 	    }
   133 	else
   134 		{
   135 	    return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface);
   136 		}
   137 	}
   138 
   139 template <class T> void CGenericScreenDevice<T>::GetSurface(TSurfaceId& aSid) const 
   140 	{
   141 	iHelper.GetSurface(aSid);
   142 	}
   143 
   144 
   145 template <class T> TUint CGenericScreenDevice<T>::DeviceOrientationsAvailable() const 
   146 	{
   147 	return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize);
   148 	}
   149 
   150 template <class T> TDeviceOrientation CGenericScreenDevice<T>::DeviceOrientation() const 
   151 	{
   152 	return iHelper.DeviceOrientation();
   153 	}
   154 
   155 //
   156 // Implementation of  template CPalettizedScreenDevice
   157 // Arguments  <class T,TDisplayMode displayMode,TInt pixelsPerWord>
   158 // Defines a screendriver for GCE with a mode specified without using a GUID, probably palettized
   159 //
   160 //
   161 
   162 
   163 //Initialise palletised modes that are not assigned GUIDs
   164 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   165 TInt  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
   166 	{
   167 	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID
   168 	if (ret != KErrNone)
   169 		return ret;
   170 	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
   171 	}
   172 
   173 //Set size members based on pixel width/height, but also set stride member using pixels per word
   174 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   175 void CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetSize(const TSize& aSize)
   176 	{
   177 	CDrawBitmap::SetSize(aSize);
   178 	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
   179 	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
   180 	}
   181 	
   182 
   183 //sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
   184 template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   185 TBool  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
   186 	{
   187 	TSize newSize;
   188 
   189 	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
   190 		{
   191 		return EFalse;
   192 		}
   193 
   194 	// Need to update size, scan line size, etc.
   195 	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
   196 	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
   197 	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
   198 	CGenericScreenDevice::SetSize(newSize);
   199 
   200 	return ETrue;
   201 	}
   202 
   203 	
   204 //
   205 // Implementation of  template CGuidScreenDevice
   206 // Arguments  <class T,TInt guidMode,TInt pixelsPerWord>
   207 // Defines a screendriver for GCE with a mode specified using a GUID, probably flat colour
   208 //
   209 //
   210 
   211 //Initialise modes that have been assigned GUIDs
   212 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   213 TInt  CGuidScreenDevice<T,guidMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
   214 	{
   215 	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode);
   216 	if (ret != KErrNone)
   217 		{
   218 		return ret;
   219 		}
   220 	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
   221 	}
   222 
   223 
   224 //sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
   225 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   226 TBool  CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
   227 	{
   228 	TSize newSize;
   229 
   230 	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
   231 		{
   232 		return EFalse;
   233 		}
   234 
   235 	// Need to update size, scan line size, etc.
   236 	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
   237 	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
   238 	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
   239 	CGenericScreenDevice::SetSize(newSize);
   240 
   241 	return ETrue;
   242 	}
   243 
   244 
   245 
   246 //Set size members based on pixel width/height, but also set stride member using pixels per word
   247 template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   248 void CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetSize(const TSize& aSize)
   249 	{
   250 	CDrawBitmap::SetSize(aSize);
   251 	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
   252 	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
   253 	}
   254 	
   255 
   256 
   257 
   258 
   259 #endif	//__SCDRAW_INL__