os/graphics/graphicsdeviceinterface/screendriver/sgeneric/scdraw.inl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/screendriver/sgeneric/scdraw.inl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,259 @@
     1.4 +// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// This module implements the templated classes used to define screen display instances.
    1.18 +// It only needs to be #included into scnew.cpp whisch is the only place the full-qualified templates are instanced.
    1.19 +// Most of these methods are simply shims to the SurfaceHelper class.
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 +*/
    1.26 +#ifndef __SCDRAW_INL__
    1.27 +#define __SCDRAW_INL__
    1.28 +
    1.29 +#include "scdraw.h"	//should have already happened.
    1.30 +
    1.31 +//
    1.32 +// Implementation of  template CGenericScreenDevice
    1.33 +// Arguments  <class T>
    1.34 +// Defines the common portions of a screendriver for GCE 
    1.35 +//	the actual mode and the bits per pixel (or pixels per word) is not specified.
    1.36 +//
    1.37 +
    1.38 +
    1.39 +/**	Nothing to do to init the screen for the display modes currently supported.
    1.40 + * This is the place to set up the palette for low-colour screen devices, possibly including 12-bit.
    1.41 + **/
    1.42 +template <class T> TInt  CGenericScreenDevice<T>::InitScreen()
    1.43 +	{
    1.44 +	return KErrNone ;
    1.45 +	}
    1.46 +
    1.47 +//Construct splits into 2 methods. This portion is not dependent on pixel format
    1.48 +template <class T> TInt  CGenericScreenDevice<T>::ConstructScreen(TInt , TAny *, TSize aSize, TInt )
    1.49 +	{
    1.50 +	CDrawXxxBppBitmap::iScanLineWords = iHelper.BytesPerScanline() / 4;
    1.51 +	if (CDrawXxxBppBitmap::iScanLineWords==0)
    1.52 +		{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
    1.53 +		return KErrHardwareNotAvailable;
    1.54 +		}
    1.55 +	TInt ret = CDrawXxxBppBitmap::Construct(aSize, iHelper.BytesPerScanline());
    1.56 +	if (ret == KErrNone)
    1.57 +		{
    1.58 +		CDrawXxxBppBitmap::iBits = (TUint32*)iHelper.AddressFirstPixel();
    1.59 +		if (CDrawXxxBppBitmap::iBits==NULL)
    1.60 +			{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
    1.61 +			ret=KErrHardwareNotAvailable;
    1.62 +			}
    1.63 +		}
    1.64 +	return ret;
    1.65 +	}
    1.66 +
    1.67 +//Switch from the previous aDrawDevice to this one
    1.68 +template <class T> void CGenericScreenDevice<T>::SetDisplayMode(CFbsDrawDevice* aDrawDevice)
    1.69 +	{
    1.70 +	iHelper.ResetUpdateRegion();
    1.71 +
    1.72 +	// Inherit the original draw device's orientation, if available.
    1.73 +	TDeviceOrientation devOrientation = EDeviceOrientationNormal;
    1.74 +
    1.75 +	TAny* interface = NULL;
    1.76 +	TInt ret = aDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
    1.77 +	//can't survive setting a different orientation to the source device so must read it successfully
    1.78 +	__ASSERT_ALWAYS(ret == KErrNone,Panic(EScreenDriverPanicIncompatiblePreviousDevice));
    1.79 +	devOrientation = reinterpret_cast<MSurfaceId*>(interface)->DeviceOrientation();
    1.80 +	//SetDeviceOrientation will panic if it is incompatible
    1.81 +	SetDeviceOrientation(devOrientation);
    1.82 +
    1.83 +	CDrawXxxBppBitmap::CopyOldSettings(aDrawDevice);
    1.84 +	InitScreen();
    1.85 +	}
    1.86 +
    1.87 +template <class T> TInt CGenericScreenDevice<T>::HorzTwipsPerThousandPixels() const
    1.88 +	{
    1.89 + 	return iHelper.HorzTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
    1.90 +	}
    1.91 +
    1.92 +template <class T> TInt CGenericScreenDevice<T>::VertTwipsPerThousandPixels() const
    1.93 +	{
    1.94 +	return iHelper.VertTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
    1.95 +	}
    1.96 +
    1.97 +template <class T> void CGenericScreenDevice<T>::Update()
    1.98 +	{
    1.99 +	iHelper.Update();
   1.100 +	}
   1.101 +
   1.102 +template <class T> void CGenericScreenDevice<T>::Update(const TRegion& aRegion)
   1.103 +	{
   1.104 +    if(!aRegion.IsEmpty() && !aRegion.CheckError())
   1.105 +        {
   1.106 +        if (aRegion.Count()>KMaxUpdateRegionRectangles)
   1.107 +            {
   1.108 +            UpdateRegion(aRegion.BoundingRect());
   1.109 +            }
   1.110 +        else
   1.111 +            {
   1.112 +            TInt rcCnt = aRegion.Count();
   1.113 +            for (TInt ii=0; ii < rcCnt; ++ii)
   1.114 +                {  
   1.115 +                UpdateRegion(aRegion[ii]);  //Applies deorientate (offset, scale, rotate)
   1.116 +                }
   1.117 +            }
   1.118 +        }
   1.119 +    Update();
   1.120 +	}
   1.121 +
   1.122 +template <class T> void CGenericScreenDevice<T>::UpdateRegion(const TRect& aRect)
   1.123 +    {
   1.124 +    const TRect rect = CDrawXxxBppBitmap::DeOrientate(aRect);//rect - physical coordinates
   1.125 +    
   1.126 +    iHelper.UpdateRegion(rect);
   1.127 +    }
   1.128 +
   1.129 +template <class T> TInt CGenericScreenDevice<T>::GetInterface(TInt aInterfaceId, TAny*& aInterface)
   1.130 +	{
   1.131 +	if(aInterfaceId == KSurfaceInterfaceID)
   1.132 +	    {
   1.133 +		aInterface = static_cast <MSurfaceId*> (this);
   1.134 +		return KErrNone;
   1.135 +	    }
   1.136 +	else
   1.137 +		{
   1.138 +	    return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface);
   1.139 +		}
   1.140 +	}
   1.141 +
   1.142 +template <class T> void CGenericScreenDevice<T>::GetSurface(TSurfaceId& aSid) const 
   1.143 +	{
   1.144 +	iHelper.GetSurface(aSid);
   1.145 +	}
   1.146 +
   1.147 +
   1.148 +template <class T> TUint CGenericScreenDevice<T>::DeviceOrientationsAvailable() const 
   1.149 +	{
   1.150 +	return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize);
   1.151 +	}
   1.152 +
   1.153 +template <class T> TDeviceOrientation CGenericScreenDevice<T>::DeviceOrientation() const 
   1.154 +	{
   1.155 +	return iHelper.DeviceOrientation();
   1.156 +	}
   1.157 +
   1.158 +//
   1.159 +// Implementation of  template CPalettizedScreenDevice
   1.160 +// Arguments  <class T,TDisplayMode displayMode,TInt pixelsPerWord>
   1.161 +// Defines a screendriver for GCE with a mode specified without using a GUID, probably palettized
   1.162 +//
   1.163 +//
   1.164 +
   1.165 +
   1.166 +//Initialise palletised modes that are not assigned GUIDs
   1.167 +template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   1.168 +TInt  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
   1.169 +	{
   1.170 +	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID
   1.171 +	if (ret != KErrNone)
   1.172 +		return ret;
   1.173 +	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
   1.174 +	}
   1.175 +
   1.176 +//Set size members based on pixel width/height, but also set stride member using pixels per word
   1.177 +template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   1.178 +void CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetSize(const TSize& aSize)
   1.179 +	{
   1.180 +	CDrawBitmap::SetSize(aSize);
   1.181 +	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
   1.182 +	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
   1.183 +	}
   1.184 +	
   1.185 +
   1.186 +//sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
   1.187 +template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
   1.188 +TBool  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
   1.189 +	{
   1.190 +	TSize newSize;
   1.191 +
   1.192 +	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
   1.193 +		{
   1.194 +		return EFalse;
   1.195 +		}
   1.196 +
   1.197 +	// Need to update size, scan line size, etc.
   1.198 +	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
   1.199 +	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
   1.200 +	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
   1.201 +	CGenericScreenDevice::SetSize(newSize);
   1.202 +
   1.203 +	return ETrue;
   1.204 +	}
   1.205 +
   1.206 +	
   1.207 +//
   1.208 +// Implementation of  template CGuidScreenDevice
   1.209 +// Arguments  <class T,TInt guidMode,TInt pixelsPerWord>
   1.210 +// Defines a screendriver for GCE with a mode specified using a GUID, probably flat colour
   1.211 +//
   1.212 +//
   1.213 +
   1.214 +//Initialise modes that have been assigned GUIDs
   1.215 +template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   1.216 +TInt  CGuidScreenDevice<T,guidMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
   1.217 +	{
   1.218 +	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode);
   1.219 +	if (ret != KErrNone)
   1.220 +		{
   1.221 +		return ret;
   1.222 +		}
   1.223 +	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
   1.224 +	}
   1.225 +
   1.226 +
   1.227 +//sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
   1.228 +template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   1.229 +TBool  CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
   1.230 +	{
   1.231 +	TSize newSize;
   1.232 +
   1.233 +	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
   1.234 +		{
   1.235 +		return EFalse;
   1.236 +		}
   1.237 +
   1.238 +	// Need to update size, scan line size, etc.
   1.239 +	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
   1.240 +	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
   1.241 +	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
   1.242 +	CGenericScreenDevice::SetSize(newSize);
   1.243 +
   1.244 +	return ETrue;
   1.245 +	}
   1.246 +
   1.247 +
   1.248 +
   1.249 +//Set size members based on pixel width/height, but also set stride member using pixels per word
   1.250 +template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
   1.251 +void CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetSize(const TSize& aSize)
   1.252 +	{
   1.253 +	CDrawBitmap::SetSize(aSize);
   1.254 +	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
   1.255 +	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
   1.256 +	}
   1.257 +	
   1.258 +
   1.259 +
   1.260 +
   1.261 +
   1.262 +#endif	//__SCDRAW_INL__