First public contribution.
     1 // Copyright (c) 2008-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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    16 #ifndef CDISPLAYPOLICY_H
 
    17 #define CDISPLAYPOLICY_H
 
    22 #include <graphics/displaycontrolbase.h>
 
    23 #include <graphics/displaymapping.h>
 
    24 #include <graphics/displayconfiguration.h>
 
    25 #include <graphics/wsdisplaypolicy.h>
 
    27 enum TCoordinateSpace;
 
    28 class MWsGraphicDrawerEnvironment;
 
    30 class MWsScreenConfigList;
 
    36 class CDisplayPolicy : public CBase
 
    46 	// Constructors and destructor
 
    54 	 * Two-phased constructor.
 
    56 	static CDisplayPolicy* NewL(MWsGraphicDrawerEnvironment* aEnv,MWsScreen* aScreen,TInt aScreenNumber);
 
    59 	 * Two-phased constructor.
 
    61 	static CDisplayPolicy* NewLC(MWsGraphicDrawerEnvironment* aEnv,MWsScreen* aScreen,TInt aScreenNumber);
 
    63 	void NewAppModesAvailable();
 
    64 	void GetAppModeList();
 
    65 	TInt MapCoordinates(TCoordinateSpace aSourceSpace, const TRect& aSource, 
 
    66 			TCoordinateSpace aTargetSpace, TRect& aTarget) const;
 
    67 	void AddVirtualResolutionCount(TInt& aDisplayCount) const; 
 
    68 	TInt AddVirtualResolutions(RArray<MDisplayControlBase::TResolution>& aResolutions) const;
 
    69 	MDisplayControlBase::TResolution AppModeToResolution(RArray<MDisplayControlBase::TResolution>& aResolutions,TInt appMode)const;
 
    70 	TInt GetSizeModeConfiguration(RArray<MDisplayControlBase::TResolution>& aResolutions,TInt aScreenSizeMode, 
 
    71 			TDisplayConfiguration& aConfig, TRect& aSizeModePosition) const;
 
    74 	 * Used when display is disconnected.
 
    76 	TInt GetSizeModeConfiguration(TInt aScreenSizeMode,TDisplayConfiguration& aConfig, TRect& aSizeModePosition);
 
    77 	TBool SettingConfiguration(const RArray<MDisplayControlBase::TResolution>& aResolutions,
 
    78 			TDisplayConfiguration& aConfig)const;
 
    79 	TBool PolicyEnabled()const{return (iUiScaling==ENone)?EFalse:ETrue;}
 
    81 	void SetCompositionInfo (const TDisplayConfiguration& aCompositionConfig,const TDisplayConfiguration& aUiConfig);
 
    82 	void SetSizeModeExtent(TRect& aExtent, TBitFlags32 /*aContext*/);
 
    83 	void	AdjustStageBufferSize(const TSize& aOldSize,TSize& aNewSize);
 
    84 	void	CalculateMinBufferSize(RArray<MDisplayControlBase::TResolution>& aResolutions, TInt aConnectionStatus);
 
    85 	TInt 	SuitableAppMode(MWsDisplayPolicy::TDisplayStatus aSituation);
 
    86 	void 	SetLastAppMode(TInt aMode);
 
    88 	TSize	GetUiResolution();
 
    89 	TSize   GetUiResolutionAsTwips() const;
 
    90 	TRect 	GetPolicyAppMode();
 
    97 		TRect	iPixels;	//<Size and pisition in pixels
 
    98 		TSize	iTwips;		//<Size in TWips
 
   100 		enum	THighFlags	//<Policy flags are per app mode. Lower bits are defined by MWsScreenConfigList::TModeFlags 
 
   104 		//The app modes are presented based on Normal rotation to calculate correctly with display resolutions
 
   105 		//which are always in normal rotation
 
   106 		TInt	iOrientations;	//<Index bits via CFbsBitGc::TGraphicsOrientation
 
   107 		TInt	iModeIndex;	//<Which screen mode index it refers to
 
   111 	 * Constructor for performing 1st stage construction
 
   116 	 * EPOC default constructor for performing 2nd stage construction
 
   118 	void ConstructL(MWsGraphicDrawerEnvironment* aEnv,MWsScreen* aScreen,TInt aScreenNumber);
 
   119 	TBool FindVirtualMode(const RArray<MDisplayControlBase::TResolution>& aResolutions,
 
   120 			const CDisplayPolicy::TAppMode& aAppMode,TSize& aFullAppModeSize,TInt& aIndex,TInt& aBestScale) const;
 
   122 	TSize ResolutionSize(RArray<MDisplayControlBase::TResolution>& aResolutions, const TSize aBestAppSize,
 
   123 			TInt aIndex, TInt aScale) const;
 
   124 	TSize ResolutionSizeFromTwips(RArray<MDisplayControlBase::TResolution>& aResolutions, TInt aAppMode,const TSize& aBestAppSize, 
 
   125 			TInt aIndex,TBool aSwapAxis) const;
 
   126 	TSize ResolutionSizeFromAssumedTwips(RArray<MDisplayControlBase::TResolution>& aResolutions,const TSize& aBestAppSize,
 
   127 			TInt aIndex,TBool aSwapAxis,TInt aScale) const;
 
   129 	TBool MatchConfigToResolutions(const RArray<MDisplayControlBase::TResolution>& aResolutions,
 
   130 			const TDisplayConfiguration& aConfig, TInt aStartIndex, TInt& aResolutionIndex)const;
 
   131 	TBool SetConfigToResolution(TInt aAppMode, MDisplayControlBase::TResolution aResolution, TDisplayConfiguration& aConfig)const;
 
   132 	void CenteredAppInUi(const TSize& aUiSize,const TRect& aAppExtent,TRect& aSizeModePosition) const;
 
   133 	TInt MapCompositionToUi(const TRect& aSource, TRect& aTarget, TBool aIsReverseMapping) const;
 
   134 	void MapUiToApplication(const TRect& aSource, TRect& aTarget, TBool aIsReverseMapping) const;
 
   135 	TInt MapUiToDSA(const TRect& aSource, TRect& aTarget, TBool aIsReverseMapping) const;
 
   136 	void GetModeInfoL(const MWsScreenConfigList& aList,TInt aIndex,TPoint& aOffset,TSize& aSize,TAppMode& aMode) const;
 
   137 	TInt MinSizedModeIndex();
 
   138 	/** Used when calculating how to map app mode to hardware resolutions
 
   145 		TInt operator*(TInt aInt) const;
 
   151 	RArray<TAppMode>	iAppModes;
 
   153 	MWsIniFile* iScreenIniFile;
 
   156 	TRect iAppSizePixels;
 
   158 	TSize iCompositionSizeTwips;
 
   159 	TSize iCompositionSizePixels;
 
   160 	TSize	iMinUiBufferSize;
 
   161 	TInt 	iNumNormalAppModes;
 
   163 	TInt 	iConnectionStatus;
 
   164 	TInt 	iSmallestAppMode;
 
   165 	TSize 	iSmallestAppSize;
 
   166 	TDisplayConfiguration::TRotation iLastUiRotation;
 
   167 	TDisplayConfiguration::TRotation iLastCompositionRotation;
 
   170 #endif // CDISPLAYPOLICY_H