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.
sl@0
     1
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// This module implements the templated classes used to define screen display instances.
sl@0
    15
// It only needs to be #included into scnew.cpp whisch is the only place the full-qualified templates are instanced.
sl@0
    16
// Most of these methods are simply shims to the SurfaceHelper class.
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
*/
sl@0
    23
#ifndef __SCDRAW_INL__
sl@0
    24
#define __SCDRAW_INL__
sl@0
    25
sl@0
    26
#include "scdraw.h"	//should have already happened.
sl@0
    27
sl@0
    28
//
sl@0
    29
// Implementation of  template CGenericScreenDevice
sl@0
    30
// Arguments  <class T>
sl@0
    31
// Defines the common portions of a screendriver for GCE 
sl@0
    32
//	the actual mode and the bits per pixel (or pixels per word) is not specified.
sl@0
    33
//
sl@0
    34
sl@0
    35
sl@0
    36
/**	Nothing to do to init the screen for the display modes currently supported.
sl@0
    37
 * This is the place to set up the palette for low-colour screen devices, possibly including 12-bit.
sl@0
    38
 **/
sl@0
    39
template <class T> TInt  CGenericScreenDevice<T>::InitScreen()
sl@0
    40
	{
sl@0
    41
	return KErrNone ;
sl@0
    42
	}
sl@0
    43
sl@0
    44
//Construct splits into 2 methods. This portion is not dependent on pixel format
sl@0
    45
template <class T> TInt  CGenericScreenDevice<T>::ConstructScreen(TInt , TAny *, TSize aSize, TInt )
sl@0
    46
	{
sl@0
    47
	CDrawXxxBppBitmap::iScanLineWords = iHelper.BytesPerScanline() / 4;
sl@0
    48
	if (CDrawXxxBppBitmap::iScanLineWords==0)
sl@0
    49
		{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
sl@0
    50
		return KErrHardwareNotAvailable;
sl@0
    51
		}
sl@0
    52
	TInt ret = CDrawXxxBppBitmap::Construct(aSize, iHelper.BytesPerScanline());
sl@0
    53
	if (ret == KErrNone)
sl@0
    54
		{
sl@0
    55
		CDrawXxxBppBitmap::iBits = (TUint32*)iHelper.AddressFirstPixel();
sl@0
    56
		if (CDrawXxxBppBitmap::iBits==NULL)
sl@0
    57
			{	//Note: This will cause WServ startup to fail. WServ only accepts KErrNotSupported
sl@0
    58
			ret=KErrHardwareNotAvailable;
sl@0
    59
			}
sl@0
    60
		}
sl@0
    61
	return ret;
sl@0
    62
	}
sl@0
    63
sl@0
    64
//Switch from the previous aDrawDevice to this one
sl@0
    65
template <class T> void CGenericScreenDevice<T>::SetDisplayMode(CFbsDrawDevice* aDrawDevice)
sl@0
    66
	{
sl@0
    67
	iHelper.ResetUpdateRegion();
sl@0
    68
sl@0
    69
	// Inherit the original draw device's orientation, if available.
sl@0
    70
	TDeviceOrientation devOrientation = EDeviceOrientationNormal;
sl@0
    71
sl@0
    72
	TAny* interface = NULL;
sl@0
    73
	TInt ret = aDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
sl@0
    74
	//can't survive setting a different orientation to the source device so must read it successfully
sl@0
    75
	__ASSERT_ALWAYS(ret == KErrNone,Panic(EScreenDriverPanicIncompatiblePreviousDevice));
sl@0
    76
	devOrientation = reinterpret_cast<MSurfaceId*>(interface)->DeviceOrientation();
sl@0
    77
	//SetDeviceOrientation will panic if it is incompatible
sl@0
    78
	SetDeviceOrientation(devOrientation);
sl@0
    79
sl@0
    80
	CDrawXxxBppBitmap::CopyOldSettings(aDrawDevice);
sl@0
    81
	InitScreen();
sl@0
    82
	}
sl@0
    83
sl@0
    84
template <class T> TInt CGenericScreenDevice<T>::HorzTwipsPerThousandPixels() const
sl@0
    85
	{
sl@0
    86
 	return iHelper.HorzTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
sl@0
    87
	}
sl@0
    88
sl@0
    89
template <class T> TInt CGenericScreenDevice<T>::VertTwipsPerThousandPixels() const
sl@0
    90
	{
sl@0
    91
	return iHelper.VertTwipsPerThousandPixels(CDrawXxxBppBitmap::iSize);
sl@0
    92
	}
sl@0
    93
sl@0
    94
template <class T> void CGenericScreenDevice<T>::Update()
sl@0
    95
	{
sl@0
    96
	iHelper.Update();
sl@0
    97
	}
sl@0
    98
sl@0
    99
template <class T> void CGenericScreenDevice<T>::Update(const TRegion& aRegion)
sl@0
   100
	{
sl@0
   101
    if(!aRegion.IsEmpty() && !aRegion.CheckError())
sl@0
   102
        {
sl@0
   103
        if (aRegion.Count()>KMaxUpdateRegionRectangles)
sl@0
   104
            {
sl@0
   105
            UpdateRegion(aRegion.BoundingRect());
sl@0
   106
            }
sl@0
   107
        else
sl@0
   108
            {
sl@0
   109
            TInt rcCnt = aRegion.Count();
sl@0
   110
            for (TInt ii=0; ii < rcCnt; ++ii)
sl@0
   111
                {  
sl@0
   112
                UpdateRegion(aRegion[ii]);  //Applies deorientate (offset, scale, rotate)
sl@0
   113
                }
sl@0
   114
            }
sl@0
   115
        }
sl@0
   116
    Update();
sl@0
   117
	}
sl@0
   118
sl@0
   119
template <class T> void CGenericScreenDevice<T>::UpdateRegion(const TRect& aRect)
sl@0
   120
    {
sl@0
   121
    const TRect rect = CDrawXxxBppBitmap::DeOrientate(aRect);//rect - physical coordinates
sl@0
   122
    
sl@0
   123
    iHelper.UpdateRegion(rect);
sl@0
   124
    }
sl@0
   125
sl@0
   126
template <class T> TInt CGenericScreenDevice<T>::GetInterface(TInt aInterfaceId, TAny*& aInterface)
sl@0
   127
	{
sl@0
   128
	if(aInterfaceId == KSurfaceInterfaceID)
sl@0
   129
	    {
sl@0
   130
		aInterface = static_cast <MSurfaceId*> (this);
sl@0
   131
		return KErrNone;
sl@0
   132
	    }
sl@0
   133
	else
sl@0
   134
		{
sl@0
   135
	    return CDrawXxxBppBitmap::GetInterface(aInterfaceId, aInterface);
sl@0
   136
		}
sl@0
   137
	}
sl@0
   138
sl@0
   139
template <class T> void CGenericScreenDevice<T>::GetSurface(TSurfaceId& aSid) const 
sl@0
   140
	{
sl@0
   141
	iHelper.GetSurface(aSid);
sl@0
   142
	}
sl@0
   143
sl@0
   144
sl@0
   145
template <class T> TUint CGenericScreenDevice<T>::DeviceOrientationsAvailable() const 
sl@0
   146
	{
sl@0
   147
	return iHelper.DeviceOrientationsAvailable(CGenericScreenDevice::iSize);
sl@0
   148
	}
sl@0
   149
sl@0
   150
template <class T> TDeviceOrientation CGenericScreenDevice<T>::DeviceOrientation() const 
sl@0
   151
	{
sl@0
   152
	return iHelper.DeviceOrientation();
sl@0
   153
	}
sl@0
   154
sl@0
   155
//
sl@0
   156
// Implementation of  template CPalettizedScreenDevice
sl@0
   157
// Arguments  <class T,TDisplayMode displayMode,TInt pixelsPerWord>
sl@0
   158
// Defines a screendriver for GCE with a mode specified without using a GUID, probably palettized
sl@0
   159
//
sl@0
   160
//
sl@0
   161
sl@0
   162
sl@0
   163
//Initialise palletised modes that are not assigned GUIDs
sl@0
   164
template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
sl@0
   165
TInt  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
sl@0
   166
	{
sl@0
   167
	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, (TUidPixelFormat)0,aHalMode); //displayMode is NOT recorded in surfaceID
sl@0
   168
	if (ret != KErrNone)
sl@0
   169
		return ret;
sl@0
   170
	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
sl@0
   171
	}
sl@0
   172
sl@0
   173
//Set size members based on pixel width/height, but also set stride member using pixels per word
sl@0
   174
template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
sl@0
   175
void CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetSize(const TSize& aSize)
sl@0
   176
	{
sl@0
   177
	CDrawBitmap::SetSize(aSize);
sl@0
   178
	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
sl@0
   179
	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
sl@0
   180
	}
sl@0
   181
	
sl@0
   182
sl@0
   183
//sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
sl@0
   184
template <class T,TDisplayMode displayMode,TInt pixelsPerWord> 
sl@0
   185
TBool  CPalettizedScreenDevice<T,displayMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
sl@0
   186
	{
sl@0
   187
	TSize newSize;
sl@0
   188
sl@0
   189
	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
sl@0
   190
		{
sl@0
   191
		return EFalse;
sl@0
   192
		}
sl@0
   193
sl@0
   194
	// Need to update size, scan line size, etc.
sl@0
   195
	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
sl@0
   196
	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
sl@0
   197
	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
sl@0
   198
	CGenericScreenDevice::SetSize(newSize);
sl@0
   199
sl@0
   200
	return ETrue;
sl@0
   201
	}
sl@0
   202
sl@0
   203
	
sl@0
   204
//
sl@0
   205
// Implementation of  template CGuidScreenDevice
sl@0
   206
// Arguments  <class T,TInt guidMode,TInt pixelsPerWord>
sl@0
   207
// Defines a screendriver for GCE with a mode specified using a GUID, probably flat colour
sl@0
   208
//
sl@0
   209
//
sl@0
   210
sl@0
   211
//Initialise modes that have been assigned GUIDs
sl@0
   212
template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
sl@0
   213
TInt  CGuidScreenDevice<T,guidMode,pixelsPerWord>::ConstructScreen(TInt aScreenNo, TAny *aBitmapAddress, TSize aSize, TInt aHalMode)
sl@0
   214
	{
sl@0
   215
	TInt ret = CGenericScreenDevice::iHelper.Construct(aScreenNo, guidMode,aHalMode);
sl@0
   216
	if (ret != KErrNone)
sl@0
   217
		{
sl@0
   218
		return ret;
sl@0
   219
		}
sl@0
   220
	return  CGenericScreenDevice::ConstructScreen(aScreenNo,aBitmapAddress,aSize,aHalMode);
sl@0
   221
	}
sl@0
   222
sl@0
   223
sl@0
   224
//sets the orientation flags, and rotates  the bitmap.	Calls SetSize, which uses pixelsPerWord 
sl@0
   225
template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
sl@0
   226
TBool  CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetDeviceOrientation(TDeviceOrientation aOrientation)
sl@0
   227
	{
sl@0
   228
	TSize newSize;
sl@0
   229
sl@0
   230
	if (!CGenericScreenDevice::iHelper.SetDeviceOrientation(aOrientation, newSize))
sl@0
   231
		{
sl@0
   232
		return EFalse;
sl@0
   233
		}
sl@0
   234
sl@0
   235
	// Need to update size, scan line size, etc.
sl@0
   236
	CGenericScreenDevice::iScanLineWords = CGenericScreenDevice::iHelper.BytesPerScanline() / 4;	 //presumption here that BPS is always mod4.
sl@0
   237
	CGenericScreenDevice::iBits = (TUint32*)CGenericScreenDevice::iHelper.AddressFirstPixel();
sl@0
   238
	__ASSERT_ALWAYS(CGenericScreenDevice::iScanLineWords && CGenericScreenDevice::iBits,Panic(EScreenDriverPanicInvalidHalValue));
sl@0
   239
	CGenericScreenDevice::SetSize(newSize);
sl@0
   240
sl@0
   241
	return ETrue;
sl@0
   242
	}
sl@0
   243
sl@0
   244
sl@0
   245
sl@0
   246
//Set size members based on pixel width/height, but also set stride member using pixels per word
sl@0
   247
template <class T,TUidPixelFormat guidMode,TInt pixelsPerWord> 
sl@0
   248
void CGuidScreenDevice<T,guidMode,pixelsPerWord>::SetSize(const TSize& aSize)
sl@0
   249
	{
sl@0
   250
	CDrawBitmap::SetSize(aSize);
sl@0
   251
	__ASSERT_DEBUG(CGenericScreenDevice::iSize == aSize, User::Invariant());
sl@0
   252
	CGenericScreenDevice::iLongWidth = CGenericScreenDevice::iScanLineWords * pixelsPerWord;
sl@0
   253
	}
sl@0
   254
	
sl@0
   255
sl@0
   256
sl@0
   257
sl@0
   258
sl@0
   259
#endif	//__SCDRAW_INL__