os/graphics/graphicsdeviceinterface/bitgdi/sbit/FBSERVDV.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 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 <bitstd.h>
sl@0
    17
#include <bitdev.h>
sl@0
    18
#include <bitdraw.h>
sl@0
    19
#include <bitdrawscaling.h>
sl@0
    20
#include <bitdraworigin.h>
sl@0
    21
#include <bitdrawinterfaceid.h>
sl@0
    22
#include "BITPANIC.H"
sl@0
    23
sl@0
    24
/**
sl@0
    25
Used by RectCompare()
sl@0
    26
@internalComponent
sl@0
    27
*/
sl@0
    28
enum {EScanBufSize=0x80}; 
sl@0
    29
sl@0
    30
CFbsDevice::CFbsDevice():
sl@0
    31
	CBitmapDevice()
sl@0
    32
	{
sl@0
    33
	iFbs = RFbsSession::GetSession();
sl@0
    34
	}
sl@0
    35
sl@0
    36
sl@0
    37
/** Frees all resources owned by the object prior to its destruction. */
sl@0
    38
EXPORT_C CFbsDevice::~CFbsDevice()
sl@0
    39
	{
sl@0
    40
	delete iDrawDevice;
sl@0
    41
	delete iTypefaceStore;
sl@0
    42
	delete iBitBltMaskedBuffer;
sl@0
    43
	delete iGraphicsAccelerator;
sl@0
    44
	}
sl@0
    45
sl@0
    46
/** Creates a font and bitmap server graphics context for the device and 
sl@0
    47
activates it.
sl@0
    48
sl@0
    49
It is the responsibility of the caller to delete the graphics context when 
sl@0
    50
it is no longer needed.
sl@0
    51
sl@0
    52
@param aGc On return, contains a pointer to the graphics context. 
sl@0
    53
@return KErrNone if successful, otherwise, another one of the system-wide error 
sl@0
    54
codes. */
sl@0
    55
EXPORT_C TInt CFbsDevice::CreateContext(CFbsBitGc*& aGc)
sl@0
    56
	{
sl@0
    57
	TRAPD(ret,aGc = CFbsBitGc::NewL());
sl@0
    58
	if (ret != KErrNone)
sl@0
    59
		return ret;
sl@0
    60
sl@0
    61
	if (iScreenDevice)
sl@0
    62
		aGc->ActivateNoJustAutoUpdate(this);
sl@0
    63
	else
sl@0
    64
		aGc->Activate(this);
sl@0
    65
sl@0
    66
	return KErrNone;
sl@0
    67
	}
sl@0
    68
sl@0
    69
/** Gets the device's display mode.
sl@0
    70
sl@0
    71
@return The display mode of the device. */
sl@0
    72
EXPORT_C TDisplayMode CFbsDevice::DisplayMode() const
sl@0
    73
	{
sl@0
    74
	return iDrawDevice->DisplayMode();
sl@0
    75
	}
sl@0
    76
sl@0
    77
/** Gets the size of the device, in pixels.
sl@0
    78
sl@0
    79
@return The width and height of the device, in pixels */
sl@0
    80
EXPORT_C TSize CFbsDevice::SizeInPixels() const
sl@0
    81
	{
sl@0
    82
	return iDrawDevice->SizeInPixels();
sl@0
    83
	}
sl@0
    84
sl@0
    85
/** Compares two rectangles, including their contents.
sl@0
    86
sl@0
    87
This function is intended for use by test code only.
sl@0
    88
sl@0
    89
@param aSourceRect The first rectangle to be compared (in this device).
sl@0
    90
@param aDevice The font and bitmap server device in which the second rectangle 
sl@0
    91
is found.
sl@0
    92
@param aDeviceRect The second rectangle to be compared.
sl@0
    93
@return ETrue if the rectangles are the same; EFalse otherwise. */
sl@0
    94
EXPORT_C TBool CFbsDevice::RectCompare(const TRect& aSourceRect,
sl@0
    95
									   const CFbsDevice& aDevice,
sl@0
    96
									   const TRect& aDeviceRect) const
sl@0
    97
	{
sl@0
    98
	TRect deviceRect1;
sl@0
    99
	iDrawDevice->GetDrawRect(deviceRect1);
sl@0
   100
	TRect deviceRect2;
sl@0
   101
	aDevice.iDrawDevice->GetDrawRect(deviceRect2);
sl@0
   102
	TRect area(deviceRect1);
sl@0
   103
	TRect devarea(deviceRect2);
sl@0
   104
	TRect tmp(aSourceRect);
sl@0
   105
	TRect tmp2(aDeviceRect);
sl@0
   106
	tmp.Intersection(area);
sl@0
   107
	tmp2.Intersection(devarea);
sl@0
   108
	if (tmp!=aSourceRect ||
sl@0
   109
		tmp2!=aDeviceRect)
sl@0
   110
		return(EFalse);
sl@0
   111
	TInt width=aSourceRect.Width();
sl@0
   112
	TInt height=aSourceRect.Height();
sl@0
   113
	if (width!=aDeviceRect.Width() ||
sl@0
   114
		height!=aDeviceRect.Height())
sl@0
   115
		return(EFalse);
sl@0
   116
sl@0
   117
	TBuf8<EScanBufSize> buf1;
sl@0
   118
	TBuf8<EScanBufSize> buf2;
sl@0
   119
	TDisplayMode displayMode = iDrawDevice->ScanLineDisplayMode();
sl@0
   120
	if (displayMode < EGray256)
sl@0
   121
		displayMode = EGray256;
sl@0
   122
	else if (displayMode == EColor16)
sl@0
   123
		displayMode = EColor256; // Increase the display mode so that each pixel takes at least one byte
sl@0
   124
	TInt colsPerBuf=(EScanBufSize*EScanBufSize)/
sl@0
   125
				CFbsBitmap::ScanLineLength(EScanBufSize, displayMode);
sl@0
   126
	TBool ret=EFalse;
sl@0
   127
sl@0
   128
	for(TInt row=0;row<height;row++)
sl@0
   129
		{
sl@0
   130
		TInt read=0;
sl@0
   131
		TInt len=colsPerBuf;
sl@0
   132
		do
sl@0
   133
			{
sl@0
   134
			if ((width-read)<len)
sl@0
   135
				len=width-read;
sl@0
   136
			GetScanLine(buf1,TPoint(aSourceRect.iTl.iX+read,aSourceRect.iTl.iY+row),len,displayMode);
sl@0
   137
			aDevice.GetScanLine(buf2,TPoint(aDeviceRect.iTl.iX+read,aDeviceRect.iTl.iY+row),len,displayMode);
sl@0
   138
			if (buf1!=buf2)
sl@0
   139
				goto failed;
sl@0
   140
			read+=len;
sl@0
   141
			} while(read<width);
sl@0
   142
		}
sl@0
   143
	ret=ETrue;
sl@0
   144
failed:
sl@0
   145
	return(ret);
sl@0
   146
	}
sl@0
   147
sl@0
   148
/** Adds a font file to the device's typeface store. The specified font
sl@0
   149
file must be accessible to any process, i.e. not located inside an
sl@0
   150
application's private directory.
sl@0
   151
sl@0
   152
@param aName The name of the font file. 
sl@0
   153
@param aId On return, the UID value of the font file.
sl@0
   154
@return KErrNone if successful; otherwise, another of the system-wide error 
sl@0
   155
codes. */
sl@0
   156
EXPORT_C TInt CFbsDevice::AddFile(const TDesC& aName,TInt& aId)
sl@0
   157
	{
sl@0
   158
	return iTypefaceStore->AddFile(aName,aId);
sl@0
   159
	}
sl@0
   160
sl@0
   161
/** Decrements the reference count of a file which was added using 
sl@0
   162
AddFile(), and removes the file from the typeface store if the reference count reaches zero. 
sl@0
   163
sl@0
   164
If zero is passed as parameter, then an attempt is made to remove all font objects
sl@0
   165
from the device's typeface store provided none of the fonts in the store are 
sl@0
   166
currently accessed, otherwise it has no effect.
sl@0
   167
sl@0
   168
@param aId The UID value of the font file to be removed. The default is 0. */
sl@0
   169
EXPORT_C void CFbsDevice::RemoveFile(TInt aId)
sl@0
   170
	{
sl@0
   171
	iTypefaceStore->RemoveFile(aId);
sl@0
   172
	}
sl@0
   173
sl@0
   174
/** Provides access to a client-side font object in the device's typeface store that most closely 
sl@0
   175
matches a font specification.
sl@0
   176
sl@0
   177
When the font is no longer needed, call @c ReleaseFont().
sl@0
   178
sl@0
   179
Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() 
sl@0
   180
yielding (virtually) the same result. However clients are strongly encouraged to use the new
sl@0
   181
@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
sl@0
   182
character within any given text string will fit within the given amount of twips, whereas the design 
sl@0
   183
height is an aesthetic unit decided by the font designer without strict physical meaning, which 
sl@0
   184
may result in cropped characters.
sl@0
   185
sl@0
   186
@param aFont On return, points to the font which most closely matches the 
sl@0
   187
specified font.
sl@0
   188
@param aFontSpec An absolute font specification. Its iHeight member is 
sl@0
   189
interpreted as being in twips.
sl@0
   190
@return KErrNone if successful; otherwise, another one of the system-wide error 
sl@0
   191
codes.
sl@0
   192
@deprecated */
sl@0
   193
EXPORT_C TInt CFbsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   194
	{
sl@0
   195
	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
sl@0
   196
	}
sl@0
   197
sl@0
   198
/** Creates a client-side font from those available in the device's typeface 
sl@0
   199
store that most closely matches a font specification.
sl@0
   200
sl@0
   201
When the font is no longer needed, call @c ReleaseFont().
sl@0
   202
sl@0
   203
Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels() 
sl@0
   204
yielding (virtually) the same result. However clients are strongly encouraged to use the new
sl@0
   205
@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
sl@0
   206
character within any given text string will fit within the given amount of pixels, whereas the design 
sl@0
   207
height is an aesthetic unit decided by the font designer without strict physical meaning, which 
sl@0
   208
may result in cropped characters.
sl@0
   209
sl@0
   210
@param aFont On return, points to the font which most closely matches the 
sl@0
   211
specified font.
sl@0
   212
@param aFontSpec An absolute font specification. Its iHeight member is 
sl@0
   213
interpreted as being in pixels.
sl@0
   214
@return KErrNone if successful; otherwise, another of the system-wide error 
sl@0
   215
codes.
sl@0
   216
@deprecated */
sl@0
   217
EXPORT_C TInt CFbsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   218
	{
sl@0
   219
	return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
sl@0
   220
	}
sl@0
   221
sl@0
   222
/** Creates a client-side font from those available in the device's typeface 
sl@0
   223
store that most closely matches a font specification. 
sl@0
   224
sl@0
   225
When the font is no longer needed, call @c ReleaseFont().
sl@0
   226
sl@0
   227
This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the 
sl@0
   228
same result. However clients are strongly encouraged to use the new
sl@0
   229
@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every 
sl@0
   230
character within any given text string will fit within the given amount of twips, whereas the design 
sl@0
   231
height is an aesthetic unit decided by the font designer without strict physical meaning, which 
sl@0
   232
may result in cropped characters.
sl@0
   233
sl@0
   234
@param aFont On return, points to the font which most closely matches the 
sl@0
   235
specified font.
sl@0
   236
@param aFontSpec An absolute font specification. Its iHeight member is 
sl@0
   237
interpreted as being in twips.
sl@0
   238
@return KErrNone if successful; otherwise, another one of the system-wide error 
sl@0
   239
codes. */
sl@0
   240
EXPORT_C TInt  CFbsDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   241
	{
sl@0
   242
	return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
sl@0
   243
	}
sl@0
   244
sl@0
   245
/** Creates a client-side font from those available in the device's typeface 
sl@0
   246
store that most closely matches a font specification. 
sl@0
   247
sl@0
   248
When the font is no longer needed, call @c ReleaseFont().
sl@0
   249
sl@0
   250
This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the 
sl@0
   251
same result. However clients are strongly encouraged to use the new
sl@0
   252
@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every 
sl@0
   253
character within any given text string will fit within the given amount of pixels, whereas the design 
sl@0
   254
height is an aesthetic unit decided by the font designer without strict physical meaning, which 
sl@0
   255
may result in cropped characters.
sl@0
   256
sl@0
   257
@param aFont On return, points to the font which most closely matches the 
sl@0
   258
specified font.
sl@0
   259
@param aFontSpec An absolute font specification. Its iHeight member is 
sl@0
   260
interpreted as being in pixels.
sl@0
   261
@return KErrNone if successful; otherwise, another one of the system-wide error 
sl@0
   262
codes. */
sl@0
   263
EXPORT_C TInt  CFbsDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   264
	{
sl@0
   265
	return iTypefaceStore->GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
sl@0
   266
	}
sl@0
   267
sl@0
   268
/** Creates a client-side font from those available in the device's typeface 
sl@0
   269
store that most closely matches a font specification. 
sl@0
   270
sl@0
   271
When the font is no longer needed, call @c ReleaseFont().
sl@0
   272
sl@0
   273
The font and bitmap server returns a pointer to the nearest matching font 
sl@0
   274
from those available. Matches to max height of font - this does its best 
sl@0
   275
to return a font that will fit within the maximum height specified (but 
sl@0
   276
note that variations due to hinting algorithms may rarely result in this 
sl@0
   277
height being exceeded by up to one pixel). Problems can also be 
sl@0
   278
encountered with bitmap fonts where the typeface exists but doesn't have 
sl@0
   279
a font small enough.
sl@0
   280
sl@0
   281
@param aFont On return, the pointer is set to point to the device font which 
sl@0
   282
most closely approximates to the required font specification.
sl@0
   283
@param aFontSpec An absolute font specification. 
sl@0
   284
@param aMaxHeight The maximum height in twips within which the font must
sl@0
   285
fit - this overrides the height specified in aFontSpec. If maximum height
sl@0
   286
is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument
sl@0
   287
if equals to 1 pixel.
sl@0
   288
@return KErrNone, if successful; otherwise, another of the system-wide error 
sl@0
   289
codes. */
sl@0
   290
EXPORT_C TInt  CFbsDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
sl@0
   291
	{
sl@0
   292
	return iTypefaceStore->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight);
sl@0
   293
	}
sl@0
   294
sl@0
   295
/** Creates a client-side font from those available in the device's typeface 
sl@0
   296
store that most closely matches a font specification. 
sl@0
   297
sl@0
   298
When the font is no longer needed, call @c ReleaseFont().
sl@0
   299
sl@0
   300
The font and bitmap server returns a pointer to the nearest matching font 
sl@0
   301
from those available. Matches to max height of font - this does its best 
sl@0
   302
to return a font that will fit within the maximum height specified (but 
sl@0
   303
note that variations due to hinting algorithms may rarely result in this 
sl@0
   304
height being exceeded by up to one pixel). Problems can also be 
sl@0
   305
encountered with bitmap fonts where the typeface exists but doesn't have 
sl@0
   306
a font small enough.
sl@0
   307
sl@0
   308
@param aFont On return, the pointer is set to point to the device font which 
sl@0
   309
most closely approximates to the required font specification.
sl@0
   310
@param aFontSpec An absolute font specification. 
sl@0
   311
@param aMaxHeight The maximum height in pixels within which the font must
sl@0
   312
fit - this overrides the height specified in aFontSpec.  If maximum height
sl@0
   313
is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument
sl@0
   314
if equals to 1 pixel.
sl@0
   315
@return KErrNone, if successful; otherwise, another of the system-wide error 
sl@0
   316
codes. */
sl@0
   317
EXPORT_C TInt  CFbsDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
sl@0
   318
	{
sl@0
   319
	return iTypefaceStore->GetNearestFontToMaxHeightInPixels(aFont, aFontSpec, aMaxHeight );
sl@0
   320
	}
sl@0
   321
sl@0
   322
/** Gets a specific bitmap font, identified by its UID, from the device's typeface 
sl@0
   323
store.
sl@0
   324
	
sl@0
   325
When the font is no longer needed, call ReleaseFont().
sl@0
   326
	
sl@0
   327
@param aFont On return, set to point to the font.
sl@0
   328
@param aUId The UID identifying the bitmap font.
sl@0
   329
@param aStyle Algorithmic style for the font.
sl@0
   330
@return KErrNone if successful; otherwise, another of the system-wide error 
sl@0
   331
codes. */
sl@0
   332
EXPORT_C TInt CFbsDevice::GetFontById(CFont*& aFont,TUid aUId,const TAlgStyle& aStyle)
sl@0
   333
	{
sl@0
   334
	return iTypefaceStore->GetFontById(aFont,aUId,aStyle);
sl@0
   335
	}
sl@0
   336
sl@0
   337
/** Marks the specified font as no longer needed by the user of the device.
sl@0
   338
sl@0
   339
As fonts can be shared between applications, this function does not delete 
sl@0
   340
the copy of the font from RAM unless the font is only being used by this device.
sl@0
   341
sl@0
   342
@param aFont A pointer to the font to be released. */
sl@0
   343
EXPORT_C void CFbsDevice::ReleaseFont(CFont* aFont)
sl@0
   344
	{
sl@0
   345
	iTypefaceStore->ReleaseFont(aFont);
sl@0
   346
	}
sl@0
   347
sl@0
   348
/** Gets the number of typefaces supported by the device.
sl@0
   349
sl@0
   350
@return The number of typefaces supported. */
sl@0
   351
EXPORT_C TInt CFbsDevice::NumTypefaces() const
sl@0
   352
	{
sl@0
   353
	return iTypefaceStore->NumTypefaces();
sl@0
   354
	}
sl@0
   355
sl@0
   356
/** Gets information about an indexed typeface.
sl@0
   357
sl@0
   358
@param aTypefaceSupport Provides information about the typeface, including 
sl@0
   359
its name and attributes.
sl@0
   360
@param aTypefaceIndex The index of the requested typeface in the device's 
sl@0
   361
typeface store; between zero and NumTypefaces() 1 inclusive.
sl@0
   362
@see CGraphicsDevice::TypefaceSupport() */
sl@0
   363
EXPORT_C void CFbsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,
sl@0
   364
										  TInt aTypefaceIndex) const
sl@0
   365
	{
sl@0
   366
	iTypefaceStore->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
sl@0
   367
	}
sl@0
   368
sl@0
   369
/** Gets the height of a font in twips.
sl@0
   370
sl@0
   371
This is an implementation of
sl@0
   372
CGraphicsDevice::FontHeightInTwips(). */
sl@0
   373
EXPORT_C TInt CFbsDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
sl@0
   374
    {
sl@0
   375
	return iTypefaceStore->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
sl@0
   376
	}
sl@0
   377
sl@0
   378
/**  Gets the height, in pixels, of the specified typeface at one of its
sl@0
   379
defined heights.
sl@0
   380
sl@0
   381
This is an implementation of
sl@0
   382
CBitMapDevice::FontHeightInPixels(). */
sl@0
   383
EXPORT_C TInt CFbsDevice::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const
sl@0
   384
	{
sl@0
   385
	return iTypefaceStore->FontHeightInPixels(aTypefaceIndex,aHeightIndex);
sl@0
   386
	}
sl@0
   387
sl@0
   388
	/**
sl@0
   389
	Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
sl@0
   390
	@capability ECapabilityWriteDeviceData
sl@0
   391
	@publishedPartner
sl@0
   392
	@released
sl@0
   393
	@param aLinkedTypefaceSpec.  The typeface specification to be added.
sl@0
   394
	@param aId. A unique ID for the typeface
sl@0
   395
	@return an global error code
sl@0
   396
	@see CLinkedTypefaceSpecification
sl@0
   397
	*/
sl@0
   398
	EXPORT_C TInt CFbsDevice::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec, TInt& aId)
sl@0
   399
	{
sl@0
   400
	return iTypefaceStore->RegisterLinkedTypeface(aLinkedTypefaceSpec, aId);
sl@0
   401
	}
sl@0
   402
sl@0
   403
/** Sets the variable 8 bits per pixel colour palette, replacing the system default 
sl@0
   404
one. Only the entries in the system default palette which have corresponding 
sl@0
   405
entries in aPalette are overwritten, i.e. if aPalette contains fewer than 
sl@0
   406
256 colours, some will remain unchanged. If aPalette has more than 256 entries, 
sl@0
   407
the additional entries are ignored.
sl@0
   408
sl@0
   409
@param aPalette The custom palette.
sl@0
   410
@return KErrNone if successful; otherwise, another of the system-wide error 
sl@0
   411
codes. */
sl@0
   412
EXPORT_C TInt CFbsDevice::SetCustomPalette(const CPalette* aPalette)
sl@0
   413
	{
sl@0
   414
	TInt ret = iDrawDevice->SetCustomPalette(aPalette);
sl@0
   415
	if(ret==KErrNone)
sl@0
   416
		{
sl@0
   417
		// Graphics accelerator doesn't currently support changing palettes,
sl@0
   418
		// so delete it if the palette is successfully changed.
sl@0
   419
		delete iGraphicsAccelerator;
sl@0
   420
		iGraphicsAccelerator = NULL;
sl@0
   421
		}
sl@0
   422
	return ret;
sl@0
   423
	}
sl@0
   424
sl@0
   425
/**
sl@0
   426
The method gets a scanline and puts the scanline data into aBuf.
sl@0
   427
@internalComponent
sl@0
   428
@param aBuf The destination buffer. It should be with enough length to collect 
sl@0
   429
requested scanline data.
sl@0
   430
@param aPixel The first pixel of the requested scanline data
sl@0
   431
@param aLength The length in pixels of requested data
sl@0
   432
@param aDispMode requested scanline should be converted regarding aDispMode parameter
sl@0
   433
*/
sl@0
   434
void CFbsDevice::DoGetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,
sl@0
   435
							   TDisplayMode aDispMode)
sl@0
   436
	{
sl@0
   437
	TRect deviceRect;
sl@0
   438
	iDrawDevice->GetDrawRect(deviceRect);
sl@0
   439
	if (aPixel.iY < deviceRect.iTl.iY || aPixel.iY > deviceRect.iBr.iY)
sl@0
   440
		return;
sl@0
   441
sl@0
   442
	TInt byteLength = 0;
sl@0
   443
	TInt bitsPerPixel = 0;
sl@0
   444
sl@0
   445
	switch(aDispMode)
sl@0
   446
		{
sl@0
   447
	case EGray2:
sl@0
   448
		bitsPerPixel = 1;
sl@0
   449
		byteLength = aLength / 8 + (aLength % 8 ? 1 : 0);
sl@0
   450
		break;
sl@0
   451
	case EGray4:
sl@0
   452
		bitsPerPixel = 2;
sl@0
   453
		byteLength = aLength / 4 + (aLength % 4 ? 1 : 0);
sl@0
   454
		break;
sl@0
   455
	case EGray16:
sl@0
   456
	case EColor16:
sl@0
   457
		bitsPerPixel = 4;
sl@0
   458
		byteLength = aLength / 2 + (aLength % 2 ? 1 : 0);
sl@0
   459
		break;
sl@0
   460
	case EGray256:
sl@0
   461
	case EColor256:
sl@0
   462
		bitsPerPixel = 8;
sl@0
   463
		byteLength = aLength;
sl@0
   464
		break;
sl@0
   465
	case EColor4K:
sl@0
   466
	case EColor64K:
sl@0
   467
		bitsPerPixel = 16;
sl@0
   468
		byteLength = aLength * 2;
sl@0
   469
		break;
sl@0
   470
	case EColor16M:
sl@0
   471
		bitsPerPixel = 24;
sl@0
   472
		byteLength = aLength * 3;
sl@0
   473
		break;
sl@0
   474
	case ERgb:
sl@0
   475
	case EColor16MU:
sl@0
   476
	case EColor16MA:
sl@0
   477
	case EColor16MAP:
sl@0
   478
		bitsPerPixel = 32;
sl@0
   479
		byteLength = aLength * 4;
sl@0
   480
		break;
sl@0
   481
	case ENone:
sl@0
   482
	default:
sl@0
   483
		BG_PANIC_ALWAYS(EBitgdiPanicInvalidDisplayMode);
sl@0
   484
		}
sl@0
   485
sl@0
   486
	if (byteLength > aBuf.MaxLength())
sl@0
   487
		{
sl@0
   488
		TInt pixelsMaxCount = (aBuf.MaxLength() * 8) / bitsPerPixel;
sl@0
   489
		if(aLength > pixelsMaxCount)
sl@0
   490
			{
sl@0
   491
			aLength = pixelsMaxCount;
sl@0
   492
			}
sl@0
   493
		aBuf.SetMax();
sl@0
   494
		}
sl@0
   495
	else
sl@0
   496
		{
sl@0
   497
		aBuf.SetLength(byteLength);
sl@0
   498
		}
sl@0
   499
sl@0
   500
	TInt x1 = Max(aPixel.iX, deviceRect.iTl.iX);
sl@0
   501
	TInt x2 = Min(aPixel.iX + aLength, deviceRect.iBr.iX);
sl@0
   502
	if (x2 <= x1)
sl@0
   503
		return;
sl@0
   504
sl@0
   505
	TUint8* vals = (TUint8*)(aBuf.Ptr());
sl@0
   506
	iDrawDevice->ReadLine(x1,aPixel.iY,x2 - x1,vals,aDispMode);
sl@0
   507
	}
sl@0
   508
sl@0
   509
void CFbsDevice::TruncateRect(TRect& aRect)
sl@0
   510
	{
sl@0
   511
	TInt width = iDrawDevice->SizeInPixels().iWidth << 4;
sl@0
   512
	TInt height = iDrawDevice->SizeInPixels().iHeight << 4;
sl@0
   513
sl@0
   514
	aRect.iTl.iX = Min(aRect.iTl.iX,width);
sl@0
   515
	aRect.iTl.iY = Min(aRect.iTl.iY,height);
sl@0
   516
	aRect.iBr.iX = Min(aRect.iBr.iX,width);
sl@0
   517
	aRect.iBr.iY = Min(aRect.iBr.iY,height);
sl@0
   518
sl@0
   519
	width =- width;
sl@0
   520
	height =- height;
sl@0
   521
sl@0
   522
	aRect.iTl.iX = Max(aRect.iTl.iX,width);
sl@0
   523
	aRect.iTl.iY = Max(aRect.iTl.iY,height);
sl@0
   524
	aRect.iBr.iX = Max(aRect.iBr.iX,width);
sl@0
   525
	aRect.iBr.iY = Max(aRect.iBr.iY,height);
sl@0
   526
	}
sl@0
   527
sl@0
   528
TBool CFbsDevice::SetOrientation(CFbsBitGc::TGraphicsOrientation aOrientation)
sl@0
   529
	{
sl@0
   530
	TBool ret = iDrawDevice->SetOrientation((CFbsDrawDevice::TOrientation)aOrientation);
sl@0
   531
	if(ret)
sl@0
   532
		iOrientation = aOrientation;
sl@0
   533
	return ret;
sl@0
   534
	}
sl@0
   535
sl@0
   536
/**
sl@0
   537
Depending on the current graphics hardware this 
sl@0
   538
will return one of the 16M video modes defined in
sl@0
   539
TDisplayMode, or ENone if a 16M video mode is not supported.
sl@0
   540
@see TDisplayMode
sl@0
   541
@return	a 16M display mode or ENone.
sl@0
   542
*/
sl@0
   543
EXPORT_C TDisplayMode CFbsDevice::DisplayMode16M()
sl@0
   544
	{
sl@0
   545
	return CFbsDrawDevice::DisplayMode16M();
sl@0
   546
	}
sl@0
   547
sl@0
   548
/**
sl@0
   549
Sets scaling factor by which the drawing device should scale the drawing images.
sl@0
   550
If you want to un-scale the device, call SetScalingFactor() with Origin (0,0), 
sl@0
   551
factorX = 1, factorY = 1, divisorX = 1, divisorY = 1.
sl@0
   552
sl@0
   553
Note: The existing graphics acceleration interface does not have support for scaling.
sl@0
   554
sl@0
   555
Note: All graphics contexts, already created by the scaled device, should be 
sl@0
   556
re-activated calling CFbsBitGc::Activate().
sl@0
   557
sl@0
   558
@param aOrigin Specifies physical coordinates of the new scaling origin
sl@0
   559
of the drawing device. The drawing device maps the logical point [0, 0] to
sl@0
   560
the "aOrigin" physical point .
sl@0
   561
@param aFactorX Scaling factor for the X-axis of the screen device.
sl@0
   562
@param aFactorY Scaling factor for the y-axis of the screen device.
sl@0
   563
@param aDivisorX Not used. Should be set to 1.
sl@0
   564
@param aDivisorY Not used. Should be set to 1.
sl@0
   565
@return KErrNone If the method succeeds.
sl@0
   566
        KErrNotSupported The drawing device does not have scaling capabilities.
sl@0
   567
*/
sl@0
   568
EXPORT_C TInt CFbsDevice::SetScalingFactor(const TPoint& aOrigin,
sl@0
   569
										   TInt aFactorX, TInt aFactorY,
sl@0
   570
										   TInt aDivisorX, TInt aDivisorY)
sl@0
   571
	{
sl@0
   572
	//This class takes care about setting scaling and origin and restoring the original values
sl@0
   573
	//if some of the operations fails.
sl@0
   574
	class TInitializer
sl@0
   575
		{
sl@0
   576
	public:
sl@0
   577
		TInitializer(CFbsDrawDevice* aDrawDevice) :
sl@0
   578
			iScalingSettings(NULL), iOriginInterface(NULL),
sl@0
   579
			iError(KErrNone),
sl@0
   580
			iFx(1), iFy(1), iDivX(1), iDivY(1),
sl@0
   581
			iOrigin(0, 0)
sl@0
   582
			{//Acquire the interfaces and save the original settings.  They will be used if the initialization fails.
sl@0
   583
			iError = aDrawDevice->GetInterface(KScalingSettingsInterfaceID, 
sl@0
   584
											   reinterpret_cast <TAny*&> (iScalingSettings));
sl@0
   585
			if(iError == KErrNone)
sl@0
   586
				{
sl@0
   587
				BG_ASSERT_DEBUG_INVARIANT(iScalingSettings);
sl@0
   588
				iScalingSettings->Get(iFx, iFy, iDivX, iDivY);
sl@0
   589
				iError = aDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, 
sl@0
   590
												   reinterpret_cast <TAny*&> (iOriginInterface));
sl@0
   591
				if(iError == KErrNone)
sl@0
   592
					{
sl@0
   593
					BG_ASSERT_DEBUG_INVARIANT(iOriginInterface);
sl@0
   594
					iOriginInterface->Get(iOrigin);
sl@0
   595
					}
sl@0
   596
				}
sl@0
   597
			}
sl@0
   598
		~TInitializer()
sl@0
   599
			{//Restore the original settings if setting of the new ones had failed.
sl@0
   600
			if(iError != KErrNone)
sl@0
   601
				{
sl@0
   602
				if(iScalingSettings)
sl@0
   603
					{
sl@0
   604
					(void)iScalingSettings->Set(iFx, iFy, iDivX, iDivY);
sl@0
   605
					}
sl@0
   606
				if(iOriginInterface)
sl@0
   607
					{
sl@0
   608
					(void)iOriginInterface->Set(iOrigin);
sl@0
   609
					}
sl@0
   610
				}
sl@0
   611
			}
sl@0
   612
		void SetScalingFactor(TInt aFactorX, TInt aFactorY, TInt aDivisorX, TInt aDivisorY)
sl@0
   613
			{
sl@0
   614
			if(iError == KErrNone)
sl@0
   615
				{
sl@0
   616
				iError = iScalingSettings->Set(aFactorX, aFactorY, aDivisorX, aDivisorY);
sl@0
   617
				}
sl@0
   618
			}
sl@0
   619
		void SetOrigin(const TPoint& aOrigin)
sl@0
   620
			{
sl@0
   621
			if(iError == KErrNone)
sl@0
   622
				{
sl@0
   623
				iError = iOriginInterface->Set(aOrigin);
sl@0
   624
				}
sl@0
   625
			}
sl@0
   626
		TInt Error() const
sl@0
   627
			{
sl@0
   628
			return iError;
sl@0
   629
			}
sl@0
   630
	private:
sl@0
   631
		MScalingSettings* iScalingSettings;
sl@0
   632
		MDrawDeviceOrigin* iOriginInterface;
sl@0
   633
		TInt iError;
sl@0
   634
		TInt iFx, iFy, iDivX, iDivY;
sl@0
   635
		TPoint iOrigin;
sl@0
   636
		};
sl@0
   637
	TInitializer initializer(iDrawDevice);
sl@0
   638
	initializer.SetScalingFactor(aFactorX, aFactorY, aDivisorX, aDivisorY);
sl@0
   639
	initializer.SetOrigin(aOrigin);
sl@0
   640
	TInt err = initializer.Error();
sl@0
   641
	if(err == KErrNone && 
sl@0
   642
	  (aFactorX != aDivisorX || aFactorY != aDivisorY || aOrigin.iX != 0 || aOrigin.iY != 0))
sl@0
   643
		{
sl@0
   644
		//Graphics accelerator interface doesn't have support for scaling&origin.
sl@0
   645
		delete iGraphicsAccelerator;
sl@0
   646
		iGraphicsAccelerator = NULL;
sl@0
   647
		}
sl@0
   648
	return err;
sl@0
   649
	}
sl@0
   650
sl@0
   651
/**
sl@0
   652
Gets logical coordinates of the drawing rectangle.
sl@0
   653
If the device is not scaled, logocal coordinates of the drawing rectangle are the
sl@0
   654
same as its physical coordinates.
sl@0
   655
@param aRect Upon return aRect contains drawing rectangle logical coordinates.
sl@0
   656
*/
sl@0
   657
EXPORT_C void CFbsDevice::GetDrawRect(TRect& aRect) const
sl@0
   658
	{
sl@0
   659
	iDrawDevice->GetDrawRect(aRect);
sl@0
   660
	}
sl@0
   661
sl@0
   662
/**
sl@0
   663
An overloaded version of DrawingBegin(TBool). Similarly to that method, calls to
sl@0
   664
DrawingBegin(const CFbsBitmap*, TBool) must be paired with a subsequent call to
sl@0
   665
DrawingEnd(const CFbsBitmap*, TBool). Also, code must not leave between a
sl@0
   666
DrawingBegin(const CFbsBitmap*, TBool) - DrawingEnd(const CFbsBitmap*, TBool) pair.
sl@0
   667
@param aBitmap An additional parameter compared to the basic overload.
sl@0
   668
aBitmap is a pointer to a CFbsBitmap object to be frozen. If a null pointer
sl@0
   669
is given then the method panics.
sl@0
   670
@param aAlways Not used.
sl@0
   671
sl@0
   672
@see CFbsBitmapDevice::DrawingBegin()
sl@0
   673
*/
sl@0
   674
void CFbsDevice::DrawingBegin(const CFbsBitmap* aBitmap, TBool /*aAlways*/)
sl@0
   675
	{
sl@0
   676
	BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap);
sl@0
   677
	if (aBitmap)
sl@0
   678
		aBitmap->BeginDataAccess();
sl@0
   679
	DrawingBegin();
sl@0
   680
	}
sl@0
   681
sl@0
   682
/**
sl@0
   683
This must always be called after DrawingBegin(const CFbsBitmap*, TBool).
sl@0
   684
Like DrawingBegin(const CFbsBitmap*, TBool) it will panic in debug builds
sl@0
   685
if passed a null pointer.
sl@0
   686
@param aBitmap A pointer to a CFbsBitmap object to be unfrozen.
sl@0
   687
@param aAlways Not used.
sl@0
   688
sl@0
   689
@see CFbsBitmapDevice::DrawingEnd()
sl@0
   690
*/
sl@0
   691
void CFbsDevice::DrawingEnd(const CFbsBitmap* aBitmap, TBool /*aAlways*/)
sl@0
   692
	{
sl@0
   693
	BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap);
sl@0
   694
	if (aBitmap)
sl@0
   695
		aBitmap->EndDataAccess(ETrue);
sl@0
   696
	DrawingEnd();
sl@0
   697
	}
sl@0
   698
sl@0
   699
/**
sl@0
   700
Used to set an offset
sl@0
   701
@param aOrigin The offset to give
sl@0
   702
@return KErrNone on success, otherwise a system wide error code
sl@0
   703
*/
sl@0
   704
EXPORT_C TInt CFbsDevice::SetDrawDeviceOffset(const TPoint& aOrigin)
sl@0
   705
	{
sl@0
   706
	if(!iDrawDevice)
sl@0
   707
		{
sl@0
   708
		return KErrGeneral;
sl@0
   709
		}
sl@0
   710
	MDrawDeviceOrigin* drawDevice=NULL;
sl@0
   711
	if (	iDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID,reinterpret_cast<void*&>(drawDevice))<KErrNone
sl@0
   712
		||	drawDevice==NULL
sl@0
   713
			)
sl@0
   714
		{
sl@0
   715
		return KErrNotSupported;
sl@0
   716
		}
sl@0
   717
	drawDevice->Set(aOrigin);
sl@0
   718
	return KErrNone;
sl@0
   719
	}