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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
23 #ifndef __SCDRAW_INL__
24 #define __SCDRAW_INL__
26 #include "scdraw.h" //should have already happened.
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.
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.
39 template <class T> TInt CGenericScreenDevice<T>::InitScreen()
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 )
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;
52 TInt ret = CDrawXxxBppBitmap::Construct(aSize, iHelper.BytesPerScanline());
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;
64 //Switch from the previous aDrawDevice to this one
65 template <class T> void CGenericScreenDevice<T>::SetDisplayMode(CFbsDrawDevice* aDrawDevice)
67 iHelper.ResetUpdateRegion();
69 // Inherit the original draw device's orientation, if available.
70 TDeviceOrientation devOrientation = EDeviceOrientationNormal;
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);
80 CDrawXxxBppBitmap::CopyOldSettings(aDrawDevice);
84 template <class T> TInt CGenericScreenDevice<T>::HorzTwipsPerThousandPixels() const
86 return iHelper.HorzTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
89 template <class T> TInt CGenericScreenDevice<T>::VertTwipsPerThousandPixels() const
91 return iHelper.VertTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
94 template <class T> void CGenericScreenDevice<T>::Update()
99 template <class T> void CGenericScreenDevice<T>::Update(const TRegion& aRegion)
101 if(!aRegion.IsEmpty() && !aRegion.CheckError())
103 if (aRegion.Count()>KMaxUpdateRegionRectangles)
105 UpdateRegion(aRegion.BoundingRect());
109 TInt rcCnt = aRegion.Count();
110 for (TInt ii=0; ii < rcCnt; ++ii)
112 UpdateRegion(aRegion[ii]); //Applies deorientate (offset, scale, rotate)
119 template <class T> void CGenericScreenDevice<T>::UpdateRegion(const TRect& aRect)
121 const TRect rect = CDrawXxxBppBitmap::DeOrientate(aRect);//rect - physical coordinates
123 iHelper.UpdateRegion(rect);
126 template <class T> TInt CGenericScreenDevice<T>::GetInterface(TInt aInterfaceId, TAny*& aInterface)
128 if(aInterfaceId == KSurfaceInterfaceID)
130 aInterface = static_cast <MSurfaceId*> (this);
135 return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface);
139 template <class T> void CGenericScreenDevice<T>::GetSurface(TSurfaceId& aSid) const
141 iHelper.GetSurface(aSid);
145 template <class T> TUint CGenericScreenDevice<T>::DeviceOrientationsAvailable() const
147 return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize);
150 template <class T> TDeviceOrientation CGenericScreenDevice<T>::DeviceOrientation() const
152 return iHelper.DeviceOrientation();
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
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)
167 TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID
170 return CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
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)
177 CDrawBitmap::SetSize(aSize);
178 __ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
179 CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
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)
189 if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
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);
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
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)
215 TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode);
220 return CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
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)
230 if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
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);
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)
250 CDrawBitmap::SetSize(aSize);
251 __ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
252 CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
259 #endif //__SCDRAW_INL__