sl@0: // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // This module implements the templated classes used to define screen display instances. sl@0: // It only needs to be #included into scnew.cpp whisch is the only place the full-qualified templates are instanced. sl@0: // Most of these methods are simply shims to the SurfaceHelper class. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: #ifndef __SCDRAW_INL__ sl@0: #define __SCDRAW_INL__ sl@0: sl@0: #include "scdraw.h" //should have already happened. sl@0: sl@0: // sl@0: // Implementation of template CGenericScreenDevice sl@0: // Arguments sl@0: // Defines the common portions of a screendriver for GCE sl@0: // the actual mode and the bits per pixel (or pixels per word) is not specified. sl@0: // sl@0: sl@0: sl@0: /** Nothing to do to init the screen for the display modes currently supported. sl@0: * This is the place to set up the palette for low-colour screen devices, possibly including 12-bit. sl@0: **/ sl@0: template TInt CGenericScreenDevice::InitScreen() sl@0: { sl@0: return KErrNone ; sl@0: } sl@0: sl@0: //Construct splits into 2 methods. This portion is not dependent on pixel format sl@0: template TInt CGenericScreenDevice::ConstructScreen(TInt , TAny *, TSize aSize, TInt ) sl@0: { sl@0: CDrawXxxBppBitmap::iScanLineWords = iHelper.BytesPerScanline() / 4; sl@0: if (CDrawXxxBppBitmap::iScanLineWords==0) sl@0: { //Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported sl@0: return KErrHardwareNotAvailable; sl@0: } sl@0: TInt ret = CDrawXxxBppBitmap::Construct(aSize, iHelper.BytesPerScanline()); sl@0: if (ret == KErrNone) sl@0: { sl@0: CDrawXxxBppBitmap::iBits = (TUint32*)iHelper.AddressFirstPixel(); sl@0: if (CDrawXxxBppBitmap::iBits==NULL) sl@0: { //Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported sl@0: ret=KErrHardwareNotAvailable; sl@0: } sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: //Switch from the previous aDrawDevice to this one sl@0: template void CGenericScreenDevice::SetDisplayMode(CFbsDrawDevice* aDrawDevice) sl@0: { sl@0: iHelper.ResetUpdateRegion(); sl@0: sl@0: // Inherit the original draw device's orientation, if available. sl@0: TDeviceOrientation devOrientation = EDeviceOrientationNormal; sl@0: sl@0: TAny* interface = NULL; sl@0: TInt ret = aDrawDevice->GetInterface(KSurfaceInterfaceID, interface); sl@0: //can't survive setting a different orientation to the source device so must read it successfully sl@0: __ASSERT_ALWAYS(ret == KErrNone,Panic(EScreenDriverPanicIncompatiblePreviousDevice)); sl@0: devOrientation = reinterpret_cast(interface)->DeviceOrientation(); sl@0: //SetDeviceOrientation will panic if it is incompatible sl@0: SetDeviceOrientation(devOrientation); sl@0: sl@0: CDrawXxxBppBitmap::CopyOldSettings(aDrawDevice); sl@0: InitScreen(); sl@0: } sl@0: sl@0: template TInt CGenericScreenDevice::HorzTwipsPerThousandPixels() const sl@0: { sl@0: return iHelper.HorzTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize); sl@0: } sl@0: sl@0: template TInt CGenericScreenDevice::VertTwipsPerThousandPixels() const sl@0: { sl@0: return iHelper.VertTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize); sl@0: } sl@0: sl@0: template void CGenericScreenDevice::Update() sl@0: { sl@0: iHelper.Update(); sl@0: } sl@0: sl@0: template void CGenericScreenDevice::Update(const TRegion& aRegion) sl@0: { sl@0: if(!aRegion.IsEmpty() && !aRegion.CheckError()) sl@0: { sl@0: if (aRegion.Count()>KMaxUpdateRegionRectangles) sl@0: { sl@0: UpdateRegion(aRegion.BoundingRect()); sl@0: } sl@0: else sl@0: { sl@0: TInt rcCnt = aRegion.Count(); sl@0: for (TInt ii=0; ii < rcCnt; ++ii) sl@0: { sl@0: UpdateRegion(aRegion[ii]); //Applies deorientate (offset, scale, rotate) sl@0: } sl@0: } sl@0: } sl@0: Update(); sl@0: } sl@0: sl@0: template void CGenericScreenDevice::UpdateRegion(const TRect& aRect) sl@0: { sl@0: const TRect rect = CDrawXxxBppBitmap::DeOrientate(aRect);//rect - physical coordinates sl@0: sl@0: iHelper.UpdateRegion(rect); sl@0: } sl@0: sl@0: template TInt CGenericScreenDevice::GetInterface(TInt aInterfaceId, TAny*& aInterface) sl@0: { sl@0: if(aInterfaceId == KSurfaceInterfaceID) sl@0: { sl@0: aInterface = static_cast (this); sl@0: return KErrNone; sl@0: } sl@0: else sl@0: { sl@0: return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface); sl@0: } sl@0: } sl@0: sl@0: template void CGenericScreenDevice::GetSurface(TSurfaceId& aSid) const sl@0: { sl@0: iHelper.GetSurface(aSid); sl@0: } sl@0: sl@0: sl@0: template TUint CGenericScreenDevice::DeviceOrientationsAvailable() const sl@0: { sl@0: return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize); sl@0: } sl@0: sl@0: template TDeviceOrientation CGenericScreenDevice::DeviceOrientation() const sl@0: { sl@0: return iHelper.DeviceOrientation(); sl@0: } sl@0: sl@0: // sl@0: // Implementation of template CPalettizedScreenDevice sl@0: // Arguments sl@0: // Defines a screendriver for GCE with a mode specified without using a GUID, probably palettized sl@0: // sl@0: // sl@0: sl@0: sl@0: //Initialise palletised modes that are not assigned GUIDs sl@0: template sl@0: TInt CPalettizedScreenDevice::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode) sl@0: { sl@0: TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID sl@0: if (ret != KErrNone) sl@0: return ret; sl@0: return CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode); sl@0: } sl@0: sl@0: //Set size members based on pixel width/height, but also set stride member using pixels per word sl@0: template sl@0: void CPalettizedScreenDevice::SetSize(const TSize& aSize) sl@0: { sl@0: CDrawBitmap::SetSize(aSize); sl@0: __ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant()); sl@0: CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord; sl@0: } sl@0: sl@0: sl@0: //sets the orientation flags, and rotates the bitmap. Calls SetSize, which uses pixelsPerWord sl@0: template sl@0: TBool CPalettizedScreenDevice::SetDeviceOrientation(TDeviceOrientation aOrientation) sl@0: { sl@0: TSize newSize; sl@0: sl@0: if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // Need to update size, scan line size, etc. sl@0: CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4; //presumption here that BPS is always mod4. sl@0: CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel(); sl@0: __ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue)); sl@0: CGenericScreenDevice::SetSize(newSize); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: // sl@0: // Implementation of template CGuidScreenDevice sl@0: // Arguments sl@0: // Defines a screendriver for GCE with a mode specified using a GUID, probably flat colour sl@0: // sl@0: // sl@0: sl@0: //Initialise modes that have been assigned GUIDs sl@0: template sl@0: TInt CGuidScreenDevice::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode) sl@0: { sl@0: TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode); sl@0: if (ret != KErrNone) sl@0: { sl@0: return ret; sl@0: } sl@0: return CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode); sl@0: } sl@0: sl@0: sl@0: //sets the orientation flags, and rotates the bitmap. Calls SetSize, which uses pixelsPerWord sl@0: template sl@0: TBool CGuidScreenDevice::SetDeviceOrientation(TDeviceOrientation aOrientation) sl@0: { sl@0: TSize newSize; sl@0: sl@0: if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // Need to update size, scan line size, etc. sl@0: CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4; //presumption here that BPS is always mod4. sl@0: CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel(); sl@0: __ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue)); sl@0: CGenericScreenDevice::SetSize(newSize); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: sl@0: //Set size members based on pixel width/height, but also set stride member using pixels per word sl@0: template sl@0: void CGuidScreenDevice::SetSize(const TSize& aSize) sl@0: { sl@0: CDrawBitmap::SetSize(aSize); sl@0: __ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant()); sl@0: CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: #endif //__SCDRAW_INL__