os/graphics/graphicsdeviceinterface/screendriver/sbit/Cdsb.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-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
//
sl@0
    15
sl@0
    16
#include <hal.h>
sl@0
    17
#include <cdsb.h>
sl@0
    18
#include <e32hal.h>
sl@0
    19
sl@0
    20
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
    21
#undef __WINS__
sl@0
    22
#include "../sgeneric/scdraw.h"
sl@0
    23
#elif defined(__WINS__)
sl@0
    24
#include "_WININC.H"
sl@0
    25
#endif
sl@0
    26
sl@0
    27
sl@0
    28
//
sl@0
    29
//	CGenericDirectScreenBitmap: Implementation of generic CDirectScreenBitmap class
sl@0
    30
//
sl@0
    31
NONSHARABLE_CLASS(CGenericDirectScreenBitmap) : public CDirectScreenBitmap
sl@0
    32
	{
sl@0
    33
public:
sl@0
    34
	 CGenericDirectScreenBitmap();
sl@0
    35
	 CGenericDirectScreenBitmap(TInt aScreenNo);
sl@0
    36
	~CGenericDirectScreenBitmap();
sl@0
    37
sl@0
    38
public:
sl@0
    39
	// Pure virtual from CDirectScreenBitmap
sl@0
    40
	virtual TInt Create(const TRect& aScreenRect, TSettingsFlags aSettingsFlags);
sl@0
    41
	virtual TInt BeginUpdate(TAcceleratedBitmapInfo& aBitmapInfo);
sl@0
    42
	virtual void EndUpdate(TRequestStatus& aComplete);
sl@0
    43
	virtual void EndUpdate(const TRect& aScreenRect, TRequestStatus& aComplete);
sl@0
    44
	virtual void Close();
sl@0
    45
sl@0
    46
public:
sl@0
    47
	enum TDsbPanic
sl@0
    48
		{
sl@0
    49
		EPanicAlreadyCreated = 1,
sl@0
    50
		EPanicNotCreated     = 2,
sl@0
    51
		EPanicInvalidMode    = 3,
sl@0
    52
		EPanicOutOfBounds	 = 4,
sl@0
    53
		EPanicNotWordAligned = 5,
sl@0
    54
		EPanicInvalidRect    = 6,
sl@0
    55
		EPanicIncompleteRequest = 7,
sl@0
    56
		EPanicHandleReturnedIncorrect = 8
sl@0
    57
		};
sl@0
    58
    static void Panic(TDsbPanic aPanic);
sl@0
    59
sl@0
    60
private:
sl@0
    61
	TInt DoCreate();
sl@0
    62
sl@0
    63
#ifdef __WINS__
sl@0
    64
	TRgb ExtractRgb(TUint8* aBuffer,TInt aPixelOffset) const;
sl@0
    65
	void WinsUpdate(const TRect& aScreenRect);
sl@0
    66
#endif
sl@0
    67
sl@0
    68
private:
sl@0
    69
#ifndef __WINS__
sl@0
    70
	TInt    iVideoAddress;
sl@0
    71
#endif
sl@0
    72
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
    73
    CScreenDeviceHelper iSurfaceUpdater;
sl@0
    74
    TUidPixelFormat iPixelFormat;
sl@0
    75
#endif
sl@0
    76
	TAcceleratedBitmapInfo iBitmapInfo;
sl@0
    77
	TUint32 iSettingsFlags;
sl@0
    78
	TRect   iUpdateRect;
sl@0
    79
	TInt    iDisplayOffsetLines;
sl@0
    80
	TInt    iBytesPerPixel;
sl@0
    81
	TInt	iDisplayOffsetPixel;
sl@0
    82
	TBool   iCreated;
sl@0
    83
    TInt    iScreenNo;
sl@0
    84
    RChunk 	iChunk;
sl@0
    85
    TBool 	iHasChunk;
sl@0
    86
	};
sl@0
    87
sl@0
    88
//
sl@0
    89
// Create a new instance of a DSB
sl@0
    90
// The default screen (with number 0) will be used
sl@0
    91
EXPORT_C CDirectScreenBitmap* CDirectScreenBitmap::NewL()
sl@0
    92
	{
sl@0
    93
	CGenericDirectScreenBitmap* pDsb=new(ELeave) CGenericDirectScreenBitmap;
sl@0
    94
	return(pDsb);
sl@0
    95
	}
sl@0
    96
sl@0
    97
//
sl@0
    98
// Create a new instance of a DSB
sl@0
    99
// The screen with aScreenNo number will be used
sl@0
   100
EXPORT_C CDirectScreenBitmap* CDirectScreenBitmap::NewL(TInt aScreenNo)
sl@0
   101
    {
sl@0
   102
	CGenericDirectScreenBitmap* pDsb = new (ELeave) CGenericDirectScreenBitmap(aScreenNo);
sl@0
   103
	return pDsb;
sl@0
   104
    }
sl@0
   105
sl@0
   106
CGenericDirectScreenBitmap::CGenericDirectScreenBitmap() :
sl@0
   107
#ifndef __WINS__
sl@0
   108
	iVideoAddress(NULL),
sl@0
   109
#endif
sl@0
   110
	iBitmapInfo(),
sl@0
   111
	iSettingsFlags(ENone),
sl@0
   112
	iUpdateRect(),
sl@0
   113
	iDisplayOffsetLines(0),
sl@0
   114
	iBytesPerPixel(0),
sl@0
   115
	iDisplayOffsetPixel(0),
sl@0
   116
	iHasChunk(EFalse)
sl@0
   117
	{
sl@0
   118
    }
sl@0
   119
sl@0
   120
CGenericDirectScreenBitmap::CGenericDirectScreenBitmap(TInt aScreenNo) :
sl@0
   121
    iScreenNo(aScreenNo)
sl@0
   122
    {
sl@0
   123
    }
sl@0
   124
sl@0
   125
CGenericDirectScreenBitmap::~CGenericDirectScreenBitmap()
sl@0
   126
	{
sl@0
   127
	Close();
sl@0
   128
	}
sl@0
   129
sl@0
   130
//
sl@0
   131
// Create a DSB object using a region of the screen previously
sl@0
   132
// 'claimed' via the Window Servers Direct Screen Acceass API
sl@0
   133
//
sl@0
   134
TInt CGenericDirectScreenBitmap::Create(const TRect& aScreenRect, TSettingsFlags aSettingsFlags)
sl@0
   135
	{
sl@0
   136
	__ASSERT_ALWAYS(!iCreated, Panic(EPanicAlreadyCreated));
sl@0
   137
sl@0
   138
	__ASSERT_ALWAYS((aSettingsFlags&(EDoubleBuffer|EIncrementalUpdate)) !=
sl@0
   139
					(EDoubleBuffer|EIncrementalUpdate), Panic(EPanicInvalidMode));
sl@0
   140
sl@0
   141
    //Initialize iScreenNo - its value occupies upper 5 bits of aSettingsFlags.
sl@0
   142
    //(32 - 1) is max allowed screen number
sl@0
   143
    iScreenNo = static_cast <TUint32> ((aSettingsFlags & 0xF8000000) >> 27);
sl@0
   144
sl@0
   145
	// Find the screen dimensions from the HAL and validate
sl@0
   146
	TInt screenWidth = 0;
sl@0
   147
	TInt screenHeight = 0;
sl@0
   148
sl@0
   149
	TInt r = HAL::Get(iScreenNo, HALData::EDisplayXPixels, screenWidth);
sl@0
   150
	if (r!=KErrNone)
sl@0
   151
		{
sl@0
   152
		return r;
sl@0
   153
		}
sl@0
   154
sl@0
   155
	r = HAL::Get(iScreenNo, HALData::EDisplayYPixels,screenHeight);
sl@0
   156
	if (r!=KErrNone)
sl@0
   157
		{
sl@0
   158
		return r;
sl@0
   159
		}
sl@0
   160
sl@0
   161
	__ASSERT_ALWAYS(aScreenRect.iTl.iX >= 0 &&
sl@0
   162
	                aScreenRect.iTl.iY >= 0 &&
sl@0
   163
	                ((aScreenRect.Width() <= screenWidth &&
sl@0
   164
	                aScreenRect.Height() <= screenHeight)
sl@0
   165
	                ||
sl@0
   166
	                (aScreenRect.Width() <= screenHeight &&
sl@0
   167
	                aScreenRect.Height() <= screenWidth)),
sl@0
   168
	                Panic(EPanicOutOfBounds));
sl@0
   169
sl@0
   170
	__ASSERT_ALWAYS(aScreenRect.Width() > 0 &&
sl@0
   171
					aScreenRect.Height() > 0, Panic(EPanicInvalidRect));
sl@0
   172
sl@0
   173
	iUpdateRect = aScreenRect;
sl@0
   174
	iSettingsFlags = aSettingsFlags;
sl@0
   175
sl@0
   176
	r = DoCreate();
sl@0
   177
	if(r != KErrNone)
sl@0
   178
		{
sl@0
   179
		return r;
sl@0
   180
		}
sl@0
   181
sl@0
   182
	// Check that LHS is word-aligned
sl@0
   183
	const TUint pixelStartInBytes = aScreenRect.iTl.iX*iBytesPerPixel;
sl@0
   184
	const TUint pixelEndInBytes = aScreenRect.iBr.iX*iBytesPerPixel;
sl@0
   185
sl@0
   186
	// Check the alignment
sl@0
   187
	__ASSERT_ALWAYS(!(pixelStartInBytes & 0x03), Panic(EPanicNotWordAligned));
sl@0
   188
	__ASSERT_ALWAYS(!(pixelEndInBytes & 0x03),	 Panic(EPanicNotWordAligned));
sl@0
   189
sl@0
   190
	const TUint scanlineBytes = pixelEndInBytes-pixelStartInBytes;
sl@0
   191
sl@0
   192
#ifndef __WINS__	
sl@0
   193
	iVideoAddress += pixelStartInBytes +						// X Offset
sl@0
   194
						 iUpdateRect.iTl.iY*iDisplayOffsetLines +	// Y Offset
sl@0
   195
						 iDisplayOffsetPixel;						 // Pixel (Palette) Offset
sl@0
   196
#endif 
sl@0
   197
	
sl@0
   198
	// Since this is a generic implementation, we only require one
sl@0
   199
	//  buffer for both incremental and double buffered mode
sl@0
   200
	iBitmapInfo.iAddress = (TUint8*)User::Alloc(scanlineBytes * iUpdateRect.Height());
sl@0
   201
	if(!iBitmapInfo.iAddress)
sl@0
   202
		return KErrNoMemory;
sl@0
   203
sl@0
   204
	iBitmapInfo.iSize			 = TSize(iUpdateRect.Width(), iUpdateRect.Height());
sl@0
   205
	iBitmapInfo.iLinePitch		 = scanlineBytes;
sl@0
   206
	iBitmapInfo.iPhysicalAddress = 0;
sl@0
   207
sl@0
   208
	// All done
sl@0
   209
	iCreated = ETrue;
sl@0
   210
sl@0
   211
	return KErrNone;
sl@0
   212
	}
sl@0
   213
sl@0
   214
#ifndef __WINS__
sl@0
   215
//
sl@0
   216
// Attempt to initialise using the HAL
sl@0
   217
//
sl@0
   218
TInt CGenericDirectScreenBitmap::DoCreate()
sl@0
   219
	{
sl@0
   220
    // For GCE, if multiple modes are supported, only one needs to be returned.
sl@0
   221
	// On the emulator, what is returned via EDisplayMode can be set via ColorDepth setting in epoc.ini
sl@0
   222
	// On the hardware, 24/32bpp color mode is returned via EDisplayMode as pre-defined. 
sl@0
   223
	TInt displayMode = 0;
sl@0
   224
	TInt r1 = HAL::Get(iScreenNo, HALData::EDisplayMode, displayMode);
sl@0
   225
	if (r1!=KErrNone)
sl@0
   226
		{
sl@0
   227
		return r1;
sl@0
   228
		}
sl@0
   229
sl@0
   230
	TInt bitsPerPixel = displayMode;
sl@0
   231
sl@0
   232
	r1 = HAL::Get(iScreenNo, HALData::EDisplayBitsPerPixel, bitsPerPixel);
sl@0
   233
	if (r1!=KErrNone)
sl@0
   234
		{
sl@0
   235
		return r1;
sl@0
   236
		}
sl@0
   237
	iBytesPerPixel = (bitsPerPixel+7) >> 3;
sl@0
   238
sl@0
   239
	// Store the important driver parameters to avoid HAL calls when drawing
sl@0
   240
	iDisplayOffsetPixel = displayMode;
sl@0
   241
	r1 = HAL::Get(iScreenNo, HALData::EDisplayOffsetToFirstPixel, iDisplayOffsetPixel);
sl@0
   242
	if (r1!=KErrNone)
sl@0
   243
		{
sl@0
   244
		return r1;
sl@0
   245
		}
sl@0
   246
	iDisplayOffsetLines = displayMode;
sl@0
   247
	r1 = HAL::Get(iScreenNo, HALData::EDisplayOffsetBetweenLines, iDisplayOffsetLines);
sl@0
   248
	if (r1!=KErrNone)
sl@0
   249
		{
sl@0
   250
		return r1;
sl@0
   251
		}
sl@0
   252
	
sl@0
   253
	TInt val = 0;
sl@0
   254
	r1 = HAL::Get(iScreenNo, HALData::EDisplayMemoryHandle,val);
sl@0
   255
	if (r1 == KErrNotSupported)
sl@0
   256
		{
sl@0
   257
		// EDisplayMemoryHandle is not supported, use the address instead
sl@0
   258
		r1 = HAL::Get(iScreenNo, HALData::EDisplayMemoryAddress, iVideoAddress);
sl@0
   259
		if (r1!=KErrNone)
sl@0
   260
			{
sl@0
   261
			return r1;
sl@0
   262
			}
sl@0
   263
		}
sl@0
   264
	else if (r1 == KErrNone)
sl@0
   265
		{
sl@0
   266
		// EDisplayMemoryHandle is supported, use the handle base address
sl@0
   267
		__ASSERT_ALWAYS(val != 0, Panic(EPanicHandleReturnedIncorrect));
sl@0
   268
		RChunk chunk;
sl@0
   269
		r1 = chunk.SetReturnedHandle(val);
sl@0
   270
		if (r1 != KErrNone)
sl@0
   271
			{
sl@0
   272
			return r1;
sl@0
   273
			}
sl@0
   274
		iChunk = chunk;
sl@0
   275
		r1 = iChunk.Duplicate(RThread(), EOwnerProcess);
sl@0
   276
		chunk.Close();
sl@0
   277
		if (r1 != KErrNone)
sl@0
   278
			{
sl@0
   279
			return r1;
sl@0
   280
			}
sl@0
   281
		iVideoAddress = (TInt)iChunk.Base();
sl@0
   282
		iHasChunk = ETrue;
sl@0
   283
		}
sl@0
   284
	else  
sl@0
   285
		{
sl@0
   286
		return r1;
sl@0
   287
		}
sl@0
   288
sl@0
   289
	// The HAL doesn't specify explicit dislpay modes, so we need
sl@0
   290
	// to calculate the mode using bitsPerPixel and isMono
sl@0
   291
	TBool isMono = displayMode;
sl@0
   292
	r1 = HAL::Get(iScreenNo, HALData::EDisplayIsMono, isMono);
sl@0
   293
	if (r1!=KErrNone)
sl@0
   294
		{
sl@0
   295
		return r1;   
sl@0
   296
		}
sl@0
   297
     switch(bitsPerPixel)
sl@0
   298
		{
sl@0
   299
		// EGray2, EGray4, EGray16, EColor16 not supported on the hardware
sl@0
   300
		// The generic scdv support EGray2, EGray4, EGray16, EColor16 on the emulator
sl@0
   301
		// However, the low display modes should not be used.
sl@0
   302
		case 1:
sl@0
   303
			iBitmapInfo.iPixelShift = 0;
sl@0
   304
			iBitmapInfo.iDisplayMode = EGray2;
sl@0
   305
			iBytesPerPixel = 2;
sl@0
   306
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   307
			iPixelFormat = EUidPixelFormatUnknown;
sl@0
   308
#endif
sl@0
   309
			break;
sl@0
   310
		case 2:
sl@0
   311
			iBitmapInfo.iPixelShift = 1;
sl@0
   312
			iBitmapInfo.iDisplayMode = EGray4;
sl@0
   313
			iBytesPerPixel = 2;
sl@0
   314
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   315
			iPixelFormat = EUidPixelFormatUnknown;
sl@0
   316
#endif
sl@0
   317
			break;
sl@0
   318
		case 4:
sl@0
   319
			iBitmapInfo.iPixelShift = 2;
sl@0
   320
			iBitmapInfo.iDisplayMode = isMono ? EGray16 : EColor16;
sl@0
   321
			iBytesPerPixel = 2;
sl@0
   322
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   323
			iPixelFormat = EUidPixelFormatUnknown;
sl@0
   324
#endif
sl@0
   325
			break;	 
sl@0
   326
		case 8:
sl@0
   327
			iBitmapInfo.iPixelShift = 3;
sl@0
   328
			iBitmapInfo.iDisplayMode = isMono ? EGray256 : EColor256;
sl@0
   329
			iBytesPerPixel = 2;
sl@0
   330
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   331
			iPixelFormat = EUidPixelFormatUnknown;
sl@0
   332
#endif
sl@0
   333
			break;
sl@0
   334
		case 12:
sl@0
   335
			iBitmapInfo.iPixelShift = 4;
sl@0
   336
			iBitmapInfo.iDisplayMode = EColor4K;
sl@0
   337
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   338
			iPixelFormat = EUidPixelFormatXRGB_4444;
sl@0
   339
#endif
sl@0
   340
			break;
sl@0
   341
		case 16:
sl@0
   342
			iBitmapInfo.iPixelShift = 4;
sl@0
   343
			iBitmapInfo.iDisplayMode = EColor64K;
sl@0
   344
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   345
			iPixelFormat = EUidPixelFormatRGB_565;
sl@0
   346
#endif
sl@0
   347
			break;
sl@0
   348
		case 24:
sl@0
   349
		case 32:
sl@0
   350
			iBitmapInfo.iPixelShift = 5;
sl@0
   351
			iBitmapInfo.iDisplayMode = EColor16MA;
sl@0
   352
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   353
			iPixelFormat = EUidPixelFormatARGB_8888;
sl@0
   354
			iBytesPerPixel = 4;
sl@0
   355
#endif
sl@0
   356
			break;
sl@0
   357
		default:
sl@0
   358
			return KErrNotSupported;
sl@0
   359
		}
sl@0
   360
sl@0
   361
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   362
    TInt ret = iSurfaceUpdater.Construct(iScreenNo,iPixelFormat,displayMode);
sl@0
   363
 	if (ret != KErrNone)
sl@0
   364
 		{
sl@0
   365
 		return ret;
sl@0
   366
 		}
sl@0
   367
#endif
sl@0
   368
sl@0
   369
	return KErrNone;
sl@0
   370
	}
sl@0
   371
#endif
sl@0
   372
sl@0
   373
#ifdef __WINS__
sl@0
   374
//
sl@0
   375
// Attempt to initialise for WINS
sl@0
   376
// This is intended for use if HAL initialisation fails.
sl@0
   377
//
sl@0
   378
TInt CGenericDirectScreenBitmap::DoCreate()
sl@0
   379
	{
sl@0
   380
    RWindows* window = ::WindowHandler(iScreenNo);
sl@0
   381
    if(window)
sl@0
   382
		{
sl@0
   383
		iBitmapInfo.iDisplayMode = window->iDisplayMode;
sl@0
   384
		iDisplayOffsetLines		 = window->iEpocBitmapLinePitch;
sl@0
   385
		iDisplayOffsetPixel		 = 0;
sl@0
   386
sl@0
   387
		switch(iBitmapInfo.iDisplayMode)
sl@0
   388
			{
sl@0
   389
			case EGray2:
sl@0
   390
				iBitmapInfo.iPixelShift = 0;
sl@0
   391
				iBytesPerPixel = 1;
sl@0
   392
				break;
sl@0
   393
			case EGray4:
sl@0
   394
				iBitmapInfo.iPixelShift = 1;
sl@0
   395
				iBytesPerPixel = 1;
sl@0
   396
				break;
sl@0
   397
			case EGray16:
sl@0
   398
			case EColor16:
sl@0
   399
				iBitmapInfo.iPixelShift = 2;
sl@0
   400
				iBytesPerPixel = 1;
sl@0
   401
				break;
sl@0
   402
			case EGray256:
sl@0
   403
			case EColor256:
sl@0
   404
				iBitmapInfo.iPixelShift = 3;
sl@0
   405
				iBytesPerPixel = 1;
sl@0
   406
				break;
sl@0
   407
			case EColor4K:
sl@0
   408
			case EColor64K:
sl@0
   409
				iBitmapInfo.iPixelShift = 4;
sl@0
   410
				iBytesPerPixel = 2;
sl@0
   411
				break;
sl@0
   412
			case EColor16M:
sl@0
   413
				iBitmapInfo.iPixelShift = 5;
sl@0
   414
				iBytesPerPixel = 3;
sl@0
   415
				break;
sl@0
   416
			case ERgb:
sl@0
   417
			case EColor16MU:
sl@0
   418
			case EColor16MA:
sl@0
   419
			case EColor16MAP:
sl@0
   420
				iBitmapInfo.iPixelShift = 5;
sl@0
   421
				iBytesPerPixel = 4;
sl@0
   422
				break;
sl@0
   423
			default:
sl@0
   424
				return KErrNotSupported;
sl@0
   425
			}
sl@0
   426
sl@0
   427
		return KErrNone;
sl@0
   428
		}
sl@0
   429
	else
sl@0
   430
		{
sl@0
   431
		return KErrNoMemory;
sl@0
   432
		}
sl@0
   433
	}
sl@0
   434
#endif
sl@0
   435
sl@0
   436
//
sl@0
   437
// Begin update - aBitmapinfo returns the current bitmap
sl@0
   438
//
sl@0
   439
TInt CGenericDirectScreenBitmap::BeginUpdate(TAcceleratedBitmapInfo& aBitmapInfo)
sl@0
   440
	{
sl@0
   441
	__ASSERT_ALWAYS(iCreated, Panic(EPanicNotCreated));
sl@0
   442
	aBitmapInfo = iBitmapInfo;
sl@0
   443
	return KErrNone;
sl@0
   444
	}
sl@0
   445
sl@0
   446
sl@0
   447
#ifdef __WINS__
sl@0
   448
sl@0
   449
void CGenericDirectScreenBitmap::WinsUpdate(const TRect& aScreenRect)
sl@0
   450
	{
sl@0
   451
	const TUint dS = iBitmapInfo.iLinePitch;
sl@0
   452
	const TUint offY = aScreenRect.iTl.iY - iUpdateRect.iTl.iY;
sl@0
   453
	TUint8* pS = iBitmapInfo.iAddress + (offY*dS);
sl@0
   454
	RWindows* window = ::WindowHandler(iScreenNo);
sl@0
   455
	TInt orientation=window->Orientation();
sl@0
   456
	TRect orientedRect;
sl@0
   457
	TSize orientedSize;
sl@0
   458
sl@0
   459
	orientedSize = window->GetOrientedSize();
sl@0
   460
	orientedRect = window->GetOrientedRect(aScreenRect);
sl@0
   461
sl@0
   462
	TInt BrX = iUpdateRect.iBr.iX-1;
sl@0
   463
	TInt BrY = iUpdateRect.iBr.iY-1;
sl@0
   464
sl@0
   465
	for(TInt y=aScreenRect.iTl.iY; y < aScreenRect.iBr.iY; y++)
sl@0
   466
		{
sl@0
   467
sl@0
   468
		TRgb pixelColor;
sl@0
   469
sl@0
   470
		TInt xSource = aScreenRect.iTl.iX-iUpdateRect.iTl.iX;
sl@0
   471
sl@0
   472
		for(TInt x = aScreenRect.iTl.iX; x < aScreenRect.iBr.iX; x++)
sl@0
   473
			{
sl@0
   474
			TUint8* pD;
sl@0
   475
sl@0
   476
			switch(orientation)
sl@0
   477
				{
sl@0
   478
				case 0:
sl@0
   479
					pD = window->PixelAddress(x, y);
sl@0
   480
					break;
sl@0
   481
				case 1:
sl@0
   482
					pD = window->PixelAddress(y, BrX-x);
sl@0
   483
					break;
sl@0
   484
				case 2:
sl@0
   485
					pD = window->PixelAddress(BrX-x, BrY-y);
sl@0
   486
					break;
sl@0
   487
				case 3:
sl@0
   488
					pD = window->PixelAddress(BrY-y, x);
sl@0
   489
					break;
sl@0
   490
				default:
sl@0
   491
					break;
sl@0
   492
				}
sl@0
   493
sl@0
   494
			// Convert the user colour to RGB, as required by the WINS Emulator
sl@0
   495
			pixelColor = ExtractRgb(pS, xSource++);
sl@0
   496
sl@0
   497
			pD[0] = TUint8(pixelColor.Blue());
sl@0
   498
			pD[1] = TUint8(pixelColor.Green());
sl@0
   499
			pD[2] = TUint8(pixelColor.Red());
sl@0
   500
sl@0
   501
			}
sl@0
   502
		pS += dS;
sl@0
   503
		}
sl@0
   504
sl@0
   505
	RRegion region;
sl@0
   506
	region.AddRect(orientedRect);
sl@0
   507
	window->Update(region,orientedSize);
sl@0
   508
	region.Close();
sl@0
   509
	}
sl@0
   510
sl@0
   511
#endif
sl@0
   512
sl@0
   513
//
sl@0
   514
// End Update - Commit changes to the Frame Buffer
sl@0
   515
//
sl@0
   516
void CGenericDirectScreenBitmap::EndUpdate(TRequestStatus& aComplete)
sl@0
   517
	{
sl@0
   518
	__ASSERT_ALWAYS(iCreated, Panic(EPanicNotCreated));
sl@0
   519
sl@0
   520
	TUint8* pS = iBitmapInfo.iAddress;
sl@0
   521
	const TUint dS = iBitmapInfo.iLinePitch;
sl@0
   522
	
sl@0
   523
#ifdef __WINS__
sl@0
   524
sl@0
   525
	WinsUpdate(iUpdateRect);
sl@0
   526
sl@0
   527
#else
sl@0
   528
	TUint8* pD = (TUint8*)iVideoAddress;
sl@0
   529
	const TUint dD = iDisplayOffsetLines;
sl@0
   530
sl@0
   531
	for(TInt y=iUpdateRect.Height(); y>0; y--)
sl@0
   532
		{
sl@0
   533
		Mem::Move((void *)pD, (void *)pS, dS);
sl@0
   534
		pS += dS;
sl@0
   535
		pD += dD;
sl@0
   536
		}
sl@0
   537
#endif
sl@0
   538
	
sl@0
   539
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   540
	// update the region and complete notification on the client's TRequestStatus
sl@0
   541
	// This means the backbuffer is held up until the surface update has completed
sl@0
   542
	// notification.
sl@0
   543
	iSurfaceUpdater.UpdateRegion(iUpdateRect);
sl@0
   544
	iSurfaceUpdater.Update(aComplete);
sl@0
   545
#else
sl@0
   546
	// In the generic implementation, complete the request immediately to allow the client
sl@0
   547
	// to render to the back buffer
sl@0
   548
	TRequestStatus* pComplete=&aComplete;
sl@0
   549
	User::RequestComplete(pComplete,KErrNone);
sl@0
   550
#endif
sl@0
   551
sl@0
   552
 	}
sl@0
   553
sl@0
   554
//
sl@0
   555
// End Update - Commit changes within the given area to the Frame Buffer
sl@0
   556
//
sl@0
   557
void CGenericDirectScreenBitmap::EndUpdate(const TRect& aScreenRect, TRequestStatus& aComplete)
sl@0
   558
	{
sl@0
   559
	__ASSERT_ALWAYS(iCreated, Panic(EPanicNotCreated));
sl@0
   560
sl@0
   561
	__ASSERT_ALWAYS(aScreenRect.iTl.iX >= iUpdateRect.iTl.iX &&
sl@0
   562
					aScreenRect.iTl.iY >= iUpdateRect.iTl.iY &&
sl@0
   563
					aScreenRect.iBr.iX <= iUpdateRect.iBr.iX &&
sl@0
   564
					aScreenRect.iBr.iY <= iUpdateRect.iBr.iY, Panic(EPanicOutOfBounds));
sl@0
   565
sl@0
   566
	__ASSERT_ALWAYS(aScreenRect.Width() > 0 &&
sl@0
   567
					aScreenRect.Height() > 0, Panic(EPanicInvalidRect));
sl@0
   568
sl@0
   569
	// We can only use this functionality in Incremental Update mode
sl@0
   570
	__ASSERT_ALWAYS(iSettingsFlags == CDirectScreenBitmap::EIncrementalUpdate, Panic(EPanicInvalidMode));
sl@0
   571
sl@0
   572
	const TUint offY = aScreenRect.iTl.iY - iUpdateRect.iTl.iY;
sl@0
   573
sl@0
   574
	const TUint dS = iBitmapInfo.iLinePitch;
sl@0
   575
sl@0
   576
#ifdef __WINS__
sl@0
   577
sl@0
   578
	WinsUpdate(aScreenRect);
sl@0
   579
sl@0
   580
#else
sl@0
   581
	
sl@0
   582
	TInt xLeft  = aScreenRect.iTl.iX*iBytesPerPixel;
sl@0
   583
	TInt xRight = aScreenRect.iBr.iX*iBytesPerPixel;
sl@0
   584
sl@0
   585
	// We have already tested the limits against iUpdateRect, which is
sl@0
   586
	// word aligned, so we are safe to perform a round up/down here
sl@0
   587
	// without fear of overrunning the buffer.
sl@0
   588
sl@0
   589
	xLeft &= ~0x03;
sl@0
   590
	xRight = (xRight+0x03)&~0x03;
sl@0
   591
sl@0
   592
	const TUint offX = xLeft - iUpdateRect.iTl.iX*iBytesPerPixel;
sl@0
   593
sl@0
   594
	const TUint bytesToCopy = xRight-xLeft;
sl@0
   595
sl@0
   596
	const TUint dD = iDisplayOffsetLines;
sl@0
   597
sl@0
   598
	TUint8* pS = iBitmapInfo.iAddress + offX + (offY*dS);
sl@0
   599
	TUint8* pD = (TUint8*)iVideoAddress + offX + (offY*dD);
sl@0
   600
sl@0
   601
	for(TInt y=aScreenRect.Height(); y>0; y--)
sl@0
   602
		{
sl@0
   603
		Mem::Move((void *)pD, (void *)pS, bytesToCopy);
sl@0
   604
		pS += dS;
sl@0
   605
		pD += dD;
sl@0
   606
		}
sl@0
   607
#endif
sl@0
   608
sl@0
   609
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   610
	// update the region and complete notification on the client's TRequestStatus
sl@0
   611
	// This means the backbuffer is held up until the surface update has completed
sl@0
   612
	// notification.
sl@0
   613
	iSurfaceUpdater.UpdateRegion(iUpdateRect);
sl@0
   614
	iSurfaceUpdater.Update(aComplete);
sl@0
   615
#else
sl@0
   616
	// In the generic implementation, complete the request immediately to allow the client
sl@0
   617
	// to render to the back buffer
sl@0
   618
	TRequestStatus* pComplete=&aComplete;
sl@0
   619
	User::RequestComplete(pComplete,KErrNone);
sl@0
   620
#endif	
sl@0
   621
sl@0
   622
	}
sl@0
   623
sl@0
   624
#ifdef __WINS__
sl@0
   625
//
sl@0
   626
// Extracts the RGB value of the specidied pixel from the buffer
sl@0
   627
//
sl@0
   628
TRgb CGenericDirectScreenBitmap::ExtractRgb(TUint8* aBuffer,TInt aPixelOffset) const
sl@0
   629
	{
sl@0
   630
	switch (iBitmapInfo.iDisplayMode)
sl@0
   631
		{
sl@0
   632
	case EGray2:
sl@0
   633
		{
sl@0
   634
		TUint8 byte = *(aBuffer + (aPixelOffset >> 3));
sl@0
   635
		if (byte & (1 << (aPixelOffset & 7)))
sl@0
   636
			return KRgbWhite;
sl@0
   637
		return KRgbBlack;
sl@0
   638
		}
sl@0
   639
	case EGray4:
sl@0
   640
		{
sl@0
   641
		TUint8 byte = *(aBuffer + (aPixelOffset >> 2));
sl@0
   642
		byte >>= ((aPixelOffset & 3) << 1);
sl@0
   643
		return TRgb::_Gray4(byte & 3);
sl@0
   644
		}
sl@0
   645
	case EGray16:
sl@0
   646
		{
sl@0
   647
		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
sl@0
   648
		if (aPixelOffset & 1)
sl@0
   649
			byte >>= 4;
sl@0
   650
		return TRgb::_Gray16(byte & 0xf);
sl@0
   651
		}
sl@0
   652
	case EGray256:
sl@0
   653
		return TRgb::_Gray256(*(aBuffer + aPixelOffset));
sl@0
   654
	case EColor16:
sl@0
   655
		{
sl@0
   656
		TUint8 byte = *(aBuffer + (aPixelOffset >> 1));
sl@0
   657
		if (aPixelOffset & 1)
sl@0
   658
			byte >>= 4;
sl@0
   659
		return TRgb::Color16(byte & 0xf);
sl@0
   660
		}
sl@0
   661
	case EColor256:
sl@0
   662
		return TRgb::Color256(*(aBuffer + aPixelOffset));
sl@0
   663
	case EColor4K:
sl@0
   664
		{
sl@0
   665
		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
sl@0
   666
		return TRgb::_Color4K(doubleByte & 0xfff);
sl@0
   667
		}
sl@0
   668
	case EColor64K:
sl@0
   669
		{
sl@0
   670
		TUint16 doubleByte = *(((TUint16*)aBuffer) + aPixelOffset);
sl@0
   671
		return TRgb::_Color64K(doubleByte);
sl@0
   672
		}
sl@0
   673
	case EColor16M:
sl@0
   674
		{
sl@0
   675
		aBuffer += aPixelOffset * 3;
sl@0
   676
		TInt value = *aBuffer++;
sl@0
   677
		value |= *aBuffer++ << 8;
sl@0
   678
		value |= *aBuffer << 16;
sl@0
   679
		return TRgb::_Color16M(value);
sl@0
   680
		}
sl@0
   681
	case ERgb:
sl@0
   682
		return *(((TRgb*)aBuffer) + aPixelOffset);
sl@0
   683
	case EColor16MU:
sl@0
   684
		{
sl@0
   685
		aBuffer += aPixelOffset * 4;
sl@0
   686
		TInt value = *aBuffer++;
sl@0
   687
		value |= *aBuffer++ << 8;
sl@0
   688
		value |= *aBuffer << 16;
sl@0
   689
		return TRgb::_Color16MU(value);
sl@0
   690
		}
sl@0
   691
	case EColor16MA:
sl@0
   692
		{
sl@0
   693
		aBuffer += aPixelOffset * 4;
sl@0
   694
		TInt value = *aBuffer++;
sl@0
   695
		value |= *aBuffer++ << 8;
sl@0
   696
		value |= *aBuffer++ << 16;
sl@0
   697
		value |= *aBuffer << 24;
sl@0
   698
		return TRgb::_Color16MA(value);
sl@0
   699
		}
sl@0
   700
	case EColor16MAP:
sl@0
   701
		{
sl@0
   702
		aBuffer += aPixelOffset * 4;
sl@0
   703
		TInt value = *aBuffer++;
sl@0
   704
		value |= *aBuffer++ << 8;
sl@0
   705
		value |= *aBuffer++ << 16;
sl@0
   706
		value |= *aBuffer << 24;
sl@0
   707
		return TRgb::_Color16MAP(value);
sl@0
   708
		}	
sl@0
   709
	default:
sl@0
   710
		break;
sl@0
   711
		};
sl@0
   712
	return KRgbBlack;
sl@0
   713
	}
sl@0
   714
#endif
sl@0
   715
sl@0
   716
sl@0
   717
//
sl@0
   718
// Close - Deallocate resources and cancel outstanding updates
sl@0
   719
//
sl@0
   720
void CGenericDirectScreenBitmap::Close()
sl@0
   721
	{
sl@0
   722
	if(iCreated)
sl@0
   723
		{
sl@0
   724
#ifdef SYMBIAN_GRAPHICS_GCE
sl@0
   725
		iSurfaceUpdater.CancelUpdateNotification();
sl@0
   726
#endif
sl@0
   727
		User::Free(iBitmapInfo.iAddress);
sl@0
   728
		iBitmapInfo.iAddress = NULL;
sl@0
   729
		iCreated = EFalse;
sl@0
   730
		}
sl@0
   731
	if (iHasChunk)
sl@0
   732
		{
sl@0
   733
		iChunk.Close();
sl@0
   734
		}
sl@0
   735
	}
sl@0
   736
sl@0
   737
//
sl@0
   738
// Panic the user if a serious error occurs
sl@0
   739
//
sl@0
   740
void CGenericDirectScreenBitmap::Panic(TDsbPanic aPanic)
sl@0
   741
	{
sl@0
   742
	_LIT( KPanicString, "CGenericDirectScreenBitmap" );
sl@0
   743
	User::Panic( KPanicString, aPanic );
sl@0
   744
	}
sl@0
   745
sl@0
   746