1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/bitgdi/sbit/FBSERVDV.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,719 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <bitstd.h>
1.20 +#include <bitdev.h>
1.21 +#include <bitdraw.h>
1.22 +#include <bitdrawscaling.h>
1.23 +#include <bitdraworigin.h>
1.24 +#include <bitdrawinterfaceid.h>
1.25 +#include "BITPANIC.H"
1.26 +
1.27 +/**
1.28 +Used by RectCompare()
1.29 +@internalComponent
1.30 +*/
1.31 +enum {EScanBufSize=0x80};
1.32 +
1.33 +CFbsDevice::CFbsDevice():
1.34 + CBitmapDevice()
1.35 + {
1.36 + iFbs = RFbsSession::GetSession();
1.37 + }
1.38 +
1.39 +
1.40 +/** Frees all resources owned by the object prior to its destruction. */
1.41 +EXPORT_C CFbsDevice::~CFbsDevice()
1.42 + {
1.43 + delete iDrawDevice;
1.44 + delete iTypefaceStore;
1.45 + delete iBitBltMaskedBuffer;
1.46 + delete iGraphicsAccelerator;
1.47 + }
1.48 +
1.49 +/** Creates a font and bitmap server graphics context for the device and
1.50 +activates it.
1.51 +
1.52 +It is the responsibility of the caller to delete the graphics context when
1.53 +it is no longer needed.
1.54 +
1.55 +@param aGc On return, contains a pointer to the graphics context.
1.56 +@return KErrNone if successful, otherwise, another one of the system-wide error
1.57 +codes. */
1.58 +EXPORT_C TInt CFbsDevice::CreateContext(CFbsBitGc*& aGc)
1.59 + {
1.60 + TRAPD(ret,aGc = CFbsBitGc::NewL());
1.61 + if (ret != KErrNone)
1.62 + return ret;
1.63 +
1.64 + if (iScreenDevice)
1.65 + aGc->ActivateNoJustAutoUpdate(this);
1.66 + else
1.67 + aGc->Activate(this);
1.68 +
1.69 + return KErrNone;
1.70 + }
1.71 +
1.72 +/** Gets the device's display mode.
1.73 +
1.74 +@return The display mode of the device. */
1.75 +EXPORT_C TDisplayMode CFbsDevice::DisplayMode() const
1.76 + {
1.77 + return iDrawDevice->DisplayMode();
1.78 + }
1.79 +
1.80 +/** Gets the size of the device, in pixels.
1.81 +
1.82 +@return The width and height of the device, in pixels */
1.83 +EXPORT_C TSize CFbsDevice::SizeInPixels() const
1.84 + {
1.85 + return iDrawDevice->SizeInPixels();
1.86 + }
1.87 +
1.88 +/** Compares two rectangles, including their contents.
1.89 +
1.90 +This function is intended for use by test code only.
1.91 +
1.92 +@param aSourceRect The first rectangle to be compared (in this device).
1.93 +@param aDevice The font and bitmap server device in which the second rectangle
1.94 +is found.
1.95 +@param aDeviceRect The second rectangle to be compared.
1.96 +@return ETrue if the rectangles are the same; EFalse otherwise. */
1.97 +EXPORT_C TBool CFbsDevice::RectCompare(const TRect& aSourceRect,
1.98 + const CFbsDevice& aDevice,
1.99 + const TRect& aDeviceRect) const
1.100 + {
1.101 + TRect deviceRect1;
1.102 + iDrawDevice->GetDrawRect(deviceRect1);
1.103 + TRect deviceRect2;
1.104 + aDevice.iDrawDevice->GetDrawRect(deviceRect2);
1.105 + TRect area(deviceRect1);
1.106 + TRect devarea(deviceRect2);
1.107 + TRect tmp(aSourceRect);
1.108 + TRect tmp2(aDeviceRect);
1.109 + tmp.Intersection(area);
1.110 + tmp2.Intersection(devarea);
1.111 + if (tmp!=aSourceRect ||
1.112 + tmp2!=aDeviceRect)
1.113 + return(EFalse);
1.114 + TInt width=aSourceRect.Width();
1.115 + TInt height=aSourceRect.Height();
1.116 + if (width!=aDeviceRect.Width() ||
1.117 + height!=aDeviceRect.Height())
1.118 + return(EFalse);
1.119 +
1.120 + TBuf8<EScanBufSize> buf1;
1.121 + TBuf8<EScanBufSize> buf2;
1.122 + TDisplayMode displayMode = iDrawDevice->ScanLineDisplayMode();
1.123 + if (displayMode < EGray256)
1.124 + displayMode = EGray256;
1.125 + else if (displayMode == EColor16)
1.126 + displayMode = EColor256; // Increase the display mode so that each pixel takes at least one byte
1.127 + TInt colsPerBuf=(EScanBufSize*EScanBufSize)/
1.128 + CFbsBitmap::ScanLineLength(EScanBufSize, displayMode);
1.129 + TBool ret=EFalse;
1.130 +
1.131 + for(TInt row=0;row<height;row++)
1.132 + {
1.133 + TInt read=0;
1.134 + TInt len=colsPerBuf;
1.135 + do
1.136 + {
1.137 + if ((width-read)<len)
1.138 + len=width-read;
1.139 + GetScanLine(buf1,TPoint(aSourceRect.iTl.iX+read,aSourceRect.iTl.iY+row),len,displayMode);
1.140 + aDevice.GetScanLine(buf2,TPoint(aDeviceRect.iTl.iX+read,aDeviceRect.iTl.iY+row),len,displayMode);
1.141 + if (buf1!=buf2)
1.142 + goto failed;
1.143 + read+=len;
1.144 + } while(read<width);
1.145 + }
1.146 + ret=ETrue;
1.147 +failed:
1.148 + return(ret);
1.149 + }
1.150 +
1.151 +/** Adds a font file to the device's typeface store. The specified font
1.152 +file must be accessible to any process, i.e. not located inside an
1.153 +application's private directory.
1.154 +
1.155 +@param aName The name of the font file.
1.156 +@param aId On return, the UID value of the font file.
1.157 +@return KErrNone if successful; otherwise, another of the system-wide error
1.158 +codes. */
1.159 +EXPORT_C TInt CFbsDevice::AddFile(const TDesC& aName,TInt& aId)
1.160 + {
1.161 + return iTypefaceStore->AddFile(aName,aId);
1.162 + }
1.163 +
1.164 +/** Decrements the reference count of a file which was added using
1.165 +AddFile(), and removes the file from the typeface store if the reference count reaches zero.
1.166 +
1.167 +If zero is passed as parameter, then an attempt is made to remove all font objects
1.168 +from the device's typeface store provided none of the fonts in the store are
1.169 +currently accessed, otherwise it has no effect.
1.170 +
1.171 +@param aId The UID value of the font file to be removed. The default is 0. */
1.172 +EXPORT_C void CFbsDevice::RemoveFile(TInt aId)
1.173 + {
1.174 + iTypefaceStore->RemoveFile(aId);
1.175 + }
1.176 +
1.177 +/** Provides access to a client-side font object in the device's typeface store that most closely
1.178 +matches a font specification.
1.179 +
1.180 +When the font is no longer needed, call @c ReleaseFont().
1.181 +
1.182 +Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips()
1.183 +yielding (virtually) the same result. However clients are strongly encouraged to use the new
1.184 +@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every
1.185 +character within any given text string will fit within the given amount of twips, whereas the design
1.186 +height is an aesthetic unit decided by the font designer without strict physical meaning, which
1.187 +may result in cropped characters.
1.188 +
1.189 +@param aFont On return, points to the font which most closely matches the
1.190 +specified font.
1.191 +@param aFontSpec An absolute font specification. Its iHeight member is
1.192 +interpreted as being in twips.
1.193 +@return KErrNone if successful; otherwise, another one of the system-wide error
1.194 +codes.
1.195 +@deprecated */
1.196 +EXPORT_C TInt CFbsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.197 + {
1.198 + return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.199 + }
1.200 +
1.201 +/** Creates a client-side font from those available in the device's typeface
1.202 +store that most closely matches a font specification.
1.203 +
1.204 +When the font is no longer needed, call @c ReleaseFont().
1.205 +
1.206 +Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels()
1.207 +yielding (virtually) the same result. However clients are strongly encouraged to use the new
1.208 +@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every
1.209 +character within any given text string will fit within the given amount of pixels, whereas the design
1.210 +height is an aesthetic unit decided by the font designer without strict physical meaning, which
1.211 +may result in cropped characters.
1.212 +
1.213 +@param aFont On return, points to the font which most closely matches the
1.214 +specified font.
1.215 +@param aFontSpec An absolute font specification. Its iHeight member is
1.216 +interpreted as being in pixels.
1.217 +@return KErrNone if successful; otherwise, another of the system-wide error
1.218 +codes.
1.219 +@deprecated */
1.220 +EXPORT_C TInt CFbsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
1.221 + {
1.222 + return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
1.223 + }
1.224 +
1.225 +/** Creates a client-side font from those available in the device's typeface
1.226 +store that most closely matches a font specification.
1.227 +
1.228 +When the font is no longer needed, call @c ReleaseFont().
1.229 +
1.230 +This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the
1.231 +same result. However clients are strongly encouraged to use the new
1.232 +@c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every
1.233 +character within any given text string will fit within the given amount of twips, whereas the design
1.234 +height is an aesthetic unit decided by the font designer without strict physical meaning, which
1.235 +may result in cropped characters.
1.236 +
1.237 +@param aFont On return, points to the font which most closely matches the
1.238 +specified font.
1.239 +@param aFontSpec An absolute font specification. Its iHeight member is
1.240 +interpreted as being in twips.
1.241 +@return KErrNone if successful; otherwise, another one of the system-wide error
1.242 +codes. */
1.243 +EXPORT_C TInt CFbsDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.244 + {
1.245 + return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.246 + }
1.247 +
1.248 +/** Creates a client-side font from those available in the device's typeface
1.249 +store that most closely matches a font specification.
1.250 +
1.251 +When the font is no longer needed, call @c ReleaseFont().
1.252 +
1.253 +This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the
1.254 +same result. However clients are strongly encouraged to use the new
1.255 +@c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every
1.256 +character within any given text string will fit within the given amount of pixels, whereas the design
1.257 +height is an aesthetic unit decided by the font designer without strict physical meaning, which
1.258 +may result in cropped characters.
1.259 +
1.260 +@param aFont On return, points to the font which most closely matches the
1.261 +specified font.
1.262 +@param aFontSpec An absolute font specification. Its iHeight member is
1.263 +interpreted as being in pixels.
1.264 +@return KErrNone if successful; otherwise, another one of the system-wide error
1.265 +codes. */
1.266 +EXPORT_C TInt CFbsDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec)
1.267 + {
1.268 + return iTypefaceStore->GetNearestFontToDesignHeightInPixels(aFont, aFontSpec);
1.269 + }
1.270 +
1.271 +/** Creates a client-side font from those available in the device's typeface
1.272 +store that most closely matches a font specification.
1.273 +
1.274 +When the font is no longer needed, call @c ReleaseFont().
1.275 +
1.276 +The font and bitmap server returns a pointer to the nearest matching font
1.277 +from those available. Matches to max height of font - this does its best
1.278 +to return a font that will fit within the maximum height specified (but
1.279 +note that variations due to hinting algorithms may rarely result in this
1.280 +height being exceeded by up to one pixel). Problems can also be
1.281 +encountered with bitmap fonts where the typeface exists but doesn't have
1.282 +a font small enough.
1.283 +
1.284 +@param aFont On return, the pointer is set to point to the device font which
1.285 +most closely approximates to the required font specification.
1.286 +@param aFontSpec An absolute font specification.
1.287 +@param aMaxHeight The maximum height in twips within which the font must
1.288 +fit - this overrides the height specified in aFontSpec. If maximum height
1.289 +is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument
1.290 +if equals to 1 pixel.
1.291 +@return KErrNone, if successful; otherwise, another of the system-wide error
1.292 +codes. */
1.293 +EXPORT_C TInt CFbsDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
1.294 + {
1.295 + return iTypefaceStore->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight);
1.296 + }
1.297 +
1.298 +/** Creates a client-side font from those available in the device's typeface
1.299 +store that most closely matches a font specification.
1.300 +
1.301 +When the font is no longer needed, call @c ReleaseFont().
1.302 +
1.303 +The font and bitmap server returns a pointer to the nearest matching font
1.304 +from those available. Matches to max height of font - this does its best
1.305 +to return a font that will fit within the maximum height specified (but
1.306 +note that variations due to hinting algorithms may rarely result in this
1.307 +height being exceeded by up to one pixel). Problems can also be
1.308 +encountered with bitmap fonts where the typeface exists but doesn't have
1.309 +a font small enough.
1.310 +
1.311 +@param aFont On return, the pointer is set to point to the device font which
1.312 +most closely approximates to the required font specification.
1.313 +@param aFontSpec An absolute font specification.
1.314 +@param aMaxHeight The maximum height in pixels within which the font must
1.315 +fit - this overrides the height specified in aFontSpec. If maximum height
1.316 +is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument
1.317 +if equals to 1 pixel.
1.318 +@return KErrNone, if successful; otherwise, another of the system-wide error
1.319 +codes. */
1.320 +EXPORT_C TInt CFbsDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
1.321 + {
1.322 + return iTypefaceStore->GetNearestFontToMaxHeightInPixels(aFont, aFontSpec, aMaxHeight );
1.323 + }
1.324 +
1.325 +/** Gets a specific bitmap font, identified by its UID, from the device's typeface
1.326 +store.
1.327 +
1.328 +When the font is no longer needed, call ReleaseFont().
1.329 +
1.330 +@param aFont On return, set to point to the font.
1.331 +@param aUId The UID identifying the bitmap font.
1.332 +@param aStyle Algorithmic style for the font.
1.333 +@return KErrNone if successful; otherwise, another of the system-wide error
1.334 +codes. */
1.335 +EXPORT_C TInt CFbsDevice::GetFontById(CFont*& aFont,TUid aUId,const TAlgStyle& aStyle)
1.336 + {
1.337 + return iTypefaceStore->GetFontById(aFont,aUId,aStyle);
1.338 + }
1.339 +
1.340 +/** Marks the specified font as no longer needed by the user of the device.
1.341 +
1.342 +As fonts can be shared between applications, this function does not delete
1.343 +the copy of the font from RAM unless the font is only being used by this device.
1.344 +
1.345 +@param aFont A pointer to the font to be released. */
1.346 +EXPORT_C void CFbsDevice::ReleaseFont(CFont* aFont)
1.347 + {
1.348 + iTypefaceStore->ReleaseFont(aFont);
1.349 + }
1.350 +
1.351 +/** Gets the number of typefaces supported by the device.
1.352 +
1.353 +@return The number of typefaces supported. */
1.354 +EXPORT_C TInt CFbsDevice::NumTypefaces() const
1.355 + {
1.356 + return iTypefaceStore->NumTypefaces();
1.357 + }
1.358 +
1.359 +/** Gets information about an indexed typeface.
1.360 +
1.361 +@param aTypefaceSupport Provides information about the typeface, including
1.362 +its name and attributes.
1.363 +@param aTypefaceIndex The index of the requested typeface in the device's
1.364 +typeface store; between zero and NumTypefaces() 1 inclusive.
1.365 +@see CGraphicsDevice::TypefaceSupport() */
1.366 +EXPORT_C void CFbsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,
1.367 + TInt aTypefaceIndex) const
1.368 + {
1.369 + iTypefaceStore->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
1.370 + }
1.371 +
1.372 +/** Gets the height of a font in twips.
1.373 +
1.374 +This is an implementation of
1.375 +CGraphicsDevice::FontHeightInTwips(). */
1.376 +EXPORT_C TInt CFbsDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
1.377 + {
1.378 + return iTypefaceStore->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
1.379 + }
1.380 +
1.381 +/** Gets the height, in pixels, of the specified typeface at one of its
1.382 +defined heights.
1.383 +
1.384 +This is an implementation of
1.385 +CBitMapDevice::FontHeightInPixels(). */
1.386 +EXPORT_C TInt CFbsDevice::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const
1.387 + {
1.388 + return iTypefaceStore->FontHeightInPixels(aTypefaceIndex,aHeightIndex);
1.389 + }
1.390 +
1.391 + /**
1.392 + Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store.
1.393 + @capability ECapabilityWriteDeviceData
1.394 + @publishedPartner
1.395 + @released
1.396 + @param aLinkedTypefaceSpec. The typeface specification to be added.
1.397 + @param aId. A unique ID for the typeface
1.398 + @return an global error code
1.399 + @see CLinkedTypefaceSpecification
1.400 + */
1.401 + EXPORT_C TInt CFbsDevice::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec, TInt& aId)
1.402 + {
1.403 + return iTypefaceStore->RegisterLinkedTypeface(aLinkedTypefaceSpec, aId);
1.404 + }
1.405 +
1.406 +/** Sets the variable 8 bits per pixel colour palette, replacing the system default
1.407 +one. Only the entries in the system default palette which have corresponding
1.408 +entries in aPalette are overwritten, i.e. if aPalette contains fewer than
1.409 +256 colours, some will remain unchanged. If aPalette has more than 256 entries,
1.410 +the additional entries are ignored.
1.411 +
1.412 +@param aPalette The custom palette.
1.413 +@return KErrNone if successful; otherwise, another of the system-wide error
1.414 +codes. */
1.415 +EXPORT_C TInt CFbsDevice::SetCustomPalette(const CPalette* aPalette)
1.416 + {
1.417 + TInt ret = iDrawDevice->SetCustomPalette(aPalette);
1.418 + if(ret==KErrNone)
1.419 + {
1.420 + // Graphics accelerator doesn't currently support changing palettes,
1.421 + // so delete it if the palette is successfully changed.
1.422 + delete iGraphicsAccelerator;
1.423 + iGraphicsAccelerator = NULL;
1.424 + }
1.425 + return ret;
1.426 + }
1.427 +
1.428 +/**
1.429 +The method gets a scanline and puts the scanline data into aBuf.
1.430 +@internalComponent
1.431 +@param aBuf The destination buffer. It should be with enough length to collect
1.432 +requested scanline data.
1.433 +@param aPixel The first pixel of the requested scanline data
1.434 +@param aLength The length in pixels of requested data
1.435 +@param aDispMode requested scanline should be converted regarding aDispMode parameter
1.436 +*/
1.437 +void CFbsDevice::DoGetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,
1.438 + TDisplayMode aDispMode)
1.439 + {
1.440 + TRect deviceRect;
1.441 + iDrawDevice->GetDrawRect(deviceRect);
1.442 + if (aPixel.iY < deviceRect.iTl.iY || aPixel.iY > deviceRect.iBr.iY)
1.443 + return;
1.444 +
1.445 + TInt byteLength = 0;
1.446 + TInt bitsPerPixel = 0;
1.447 +
1.448 + switch(aDispMode)
1.449 + {
1.450 + case EGray2:
1.451 + bitsPerPixel = 1;
1.452 + byteLength = aLength / 8 + (aLength % 8 ? 1 : 0);
1.453 + break;
1.454 + case EGray4:
1.455 + bitsPerPixel = 2;
1.456 + byteLength = aLength / 4 + (aLength % 4 ? 1 : 0);
1.457 + break;
1.458 + case EGray16:
1.459 + case EColor16:
1.460 + bitsPerPixel = 4;
1.461 + byteLength = aLength / 2 + (aLength % 2 ? 1 : 0);
1.462 + break;
1.463 + case EGray256:
1.464 + case EColor256:
1.465 + bitsPerPixel = 8;
1.466 + byteLength = aLength;
1.467 + break;
1.468 + case EColor4K:
1.469 + case EColor64K:
1.470 + bitsPerPixel = 16;
1.471 + byteLength = aLength * 2;
1.472 + break;
1.473 + case EColor16M:
1.474 + bitsPerPixel = 24;
1.475 + byteLength = aLength * 3;
1.476 + break;
1.477 + case ERgb:
1.478 + case EColor16MU:
1.479 + case EColor16MA:
1.480 + case EColor16MAP:
1.481 + bitsPerPixel = 32;
1.482 + byteLength = aLength * 4;
1.483 + break;
1.484 + case ENone:
1.485 + default:
1.486 + BG_PANIC_ALWAYS(EBitgdiPanicInvalidDisplayMode);
1.487 + }
1.488 +
1.489 + if (byteLength > aBuf.MaxLength())
1.490 + {
1.491 + TInt pixelsMaxCount = (aBuf.MaxLength() * 8) / bitsPerPixel;
1.492 + if(aLength > pixelsMaxCount)
1.493 + {
1.494 + aLength = pixelsMaxCount;
1.495 + }
1.496 + aBuf.SetMax();
1.497 + }
1.498 + else
1.499 + {
1.500 + aBuf.SetLength(byteLength);
1.501 + }
1.502 +
1.503 + TInt x1 = Max(aPixel.iX, deviceRect.iTl.iX);
1.504 + TInt x2 = Min(aPixel.iX + aLength, deviceRect.iBr.iX);
1.505 + if (x2 <= x1)
1.506 + return;
1.507 +
1.508 + TUint8* vals = (TUint8*)(aBuf.Ptr());
1.509 + iDrawDevice->ReadLine(x1,aPixel.iY,x2 - x1,vals,aDispMode);
1.510 + }
1.511 +
1.512 +void CFbsDevice::TruncateRect(TRect& aRect)
1.513 + {
1.514 + TInt width = iDrawDevice->SizeInPixels().iWidth << 4;
1.515 + TInt height = iDrawDevice->SizeInPixels().iHeight << 4;
1.516 +
1.517 + aRect.iTl.iX = Min(aRect.iTl.iX,width);
1.518 + aRect.iTl.iY = Min(aRect.iTl.iY,height);
1.519 + aRect.iBr.iX = Min(aRect.iBr.iX,width);
1.520 + aRect.iBr.iY = Min(aRect.iBr.iY,height);
1.521 +
1.522 + width =- width;
1.523 + height =- height;
1.524 +
1.525 + aRect.iTl.iX = Max(aRect.iTl.iX,width);
1.526 + aRect.iTl.iY = Max(aRect.iTl.iY,height);
1.527 + aRect.iBr.iX = Max(aRect.iBr.iX,width);
1.528 + aRect.iBr.iY = Max(aRect.iBr.iY,height);
1.529 + }
1.530 +
1.531 +TBool CFbsDevice::SetOrientation(CFbsBitGc::TGraphicsOrientation aOrientation)
1.532 + {
1.533 + TBool ret = iDrawDevice->SetOrientation((CFbsDrawDevice::TOrientation)aOrientation);
1.534 + if(ret)
1.535 + iOrientation = aOrientation;
1.536 + return ret;
1.537 + }
1.538 +
1.539 +/**
1.540 +Depending on the current graphics hardware this
1.541 +will return one of the 16M video modes defined in
1.542 +TDisplayMode, or ENone if a 16M video mode is not supported.
1.543 +@see TDisplayMode
1.544 +@return a 16M display mode or ENone.
1.545 +*/
1.546 +EXPORT_C TDisplayMode CFbsDevice::DisplayMode16M()
1.547 + {
1.548 + return CFbsDrawDevice::DisplayMode16M();
1.549 + }
1.550 +
1.551 +/**
1.552 +Sets scaling factor by which the drawing device should scale the drawing images.
1.553 +If you want to un-scale the device, call SetScalingFactor() with Origin (0,0),
1.554 +factorX = 1, factorY = 1, divisorX = 1, divisorY = 1.
1.555 +
1.556 +Note: The existing graphics acceleration interface does not have support for scaling.
1.557 +
1.558 +Note: All graphics contexts, already created by the scaled device, should be
1.559 +re-activated calling CFbsBitGc::Activate().
1.560 +
1.561 +@param aOrigin Specifies physical coordinates of the new scaling origin
1.562 +of the drawing device. The drawing device maps the logical point [0, 0] to
1.563 +the "aOrigin" physical point .
1.564 +@param aFactorX Scaling factor for the X-axis of the screen device.
1.565 +@param aFactorY Scaling factor for the y-axis of the screen device.
1.566 +@param aDivisorX Not used. Should be set to 1.
1.567 +@param aDivisorY Not used. Should be set to 1.
1.568 +@return KErrNone If the method succeeds.
1.569 + KErrNotSupported The drawing device does not have scaling capabilities.
1.570 +*/
1.571 +EXPORT_C TInt CFbsDevice::SetScalingFactor(const TPoint& aOrigin,
1.572 + TInt aFactorX, TInt aFactorY,
1.573 + TInt aDivisorX, TInt aDivisorY)
1.574 + {
1.575 + //This class takes care about setting scaling and origin and restoring the original values
1.576 + //if some of the operations fails.
1.577 + class TInitializer
1.578 + {
1.579 + public:
1.580 + TInitializer(CFbsDrawDevice* aDrawDevice) :
1.581 + iScalingSettings(NULL), iOriginInterface(NULL),
1.582 + iError(KErrNone),
1.583 + iFx(1), iFy(1), iDivX(1), iDivY(1),
1.584 + iOrigin(0, 0)
1.585 + {//Acquire the interfaces and save the original settings. They will be used if the initialization fails.
1.586 + iError = aDrawDevice->GetInterface(KScalingSettingsInterfaceID,
1.587 + reinterpret_cast <TAny*&> (iScalingSettings));
1.588 + if(iError == KErrNone)
1.589 + {
1.590 + BG_ASSERT_DEBUG_INVARIANT(iScalingSettings);
1.591 + iScalingSettings->Get(iFx, iFy, iDivX, iDivY);
1.592 + iError = aDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID,
1.593 + reinterpret_cast <TAny*&> (iOriginInterface));
1.594 + if(iError == KErrNone)
1.595 + {
1.596 + BG_ASSERT_DEBUG_INVARIANT(iOriginInterface);
1.597 + iOriginInterface->Get(iOrigin);
1.598 + }
1.599 + }
1.600 + }
1.601 + ~TInitializer()
1.602 + {//Restore the original settings if setting of the new ones had failed.
1.603 + if(iError != KErrNone)
1.604 + {
1.605 + if(iScalingSettings)
1.606 + {
1.607 + (void)iScalingSettings->Set(iFx, iFy, iDivX, iDivY);
1.608 + }
1.609 + if(iOriginInterface)
1.610 + {
1.611 + (void)iOriginInterface->Set(iOrigin);
1.612 + }
1.613 + }
1.614 + }
1.615 + void SetScalingFactor(TInt aFactorX, TInt aFactorY, TInt aDivisorX, TInt aDivisorY)
1.616 + {
1.617 + if(iError == KErrNone)
1.618 + {
1.619 + iError = iScalingSettings->Set(aFactorX, aFactorY, aDivisorX, aDivisorY);
1.620 + }
1.621 + }
1.622 + void SetOrigin(const TPoint& aOrigin)
1.623 + {
1.624 + if(iError == KErrNone)
1.625 + {
1.626 + iError = iOriginInterface->Set(aOrigin);
1.627 + }
1.628 + }
1.629 + TInt Error() const
1.630 + {
1.631 + return iError;
1.632 + }
1.633 + private:
1.634 + MScalingSettings* iScalingSettings;
1.635 + MDrawDeviceOrigin* iOriginInterface;
1.636 + TInt iError;
1.637 + TInt iFx, iFy, iDivX, iDivY;
1.638 + TPoint iOrigin;
1.639 + };
1.640 + TInitializer initializer(iDrawDevice);
1.641 + initializer.SetScalingFactor(aFactorX, aFactorY, aDivisorX, aDivisorY);
1.642 + initializer.SetOrigin(aOrigin);
1.643 + TInt err = initializer.Error();
1.644 + if(err == KErrNone &&
1.645 + (aFactorX != aDivisorX || aFactorY != aDivisorY || aOrigin.iX != 0 || aOrigin.iY != 0))
1.646 + {
1.647 + //Graphics accelerator interface doesn't have support for scaling&origin.
1.648 + delete iGraphicsAccelerator;
1.649 + iGraphicsAccelerator = NULL;
1.650 + }
1.651 + return err;
1.652 + }
1.653 +
1.654 +/**
1.655 +Gets logical coordinates of the drawing rectangle.
1.656 +If the device is not scaled, logocal coordinates of the drawing rectangle are the
1.657 +same as its physical coordinates.
1.658 +@param aRect Upon return aRect contains drawing rectangle logical coordinates.
1.659 +*/
1.660 +EXPORT_C void CFbsDevice::GetDrawRect(TRect& aRect) const
1.661 + {
1.662 + iDrawDevice->GetDrawRect(aRect);
1.663 + }
1.664 +
1.665 +/**
1.666 +An overloaded version of DrawingBegin(TBool). Similarly to that method, calls to
1.667 +DrawingBegin(const CFbsBitmap*, TBool) must be paired with a subsequent call to
1.668 +DrawingEnd(const CFbsBitmap*, TBool). Also, code must not leave between a
1.669 +DrawingBegin(const CFbsBitmap*, TBool) - DrawingEnd(const CFbsBitmap*, TBool) pair.
1.670 +@param aBitmap An additional parameter compared to the basic overload.
1.671 +aBitmap is a pointer to a CFbsBitmap object to be frozen. If a null pointer
1.672 +is given then the method panics.
1.673 +@param aAlways Not used.
1.674 +
1.675 +@see CFbsBitmapDevice::DrawingBegin()
1.676 +*/
1.677 +void CFbsDevice::DrawingBegin(const CFbsBitmap* aBitmap, TBool /*aAlways*/)
1.678 + {
1.679 + BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap);
1.680 + if (aBitmap)
1.681 + aBitmap->BeginDataAccess();
1.682 + DrawingBegin();
1.683 + }
1.684 +
1.685 +/**
1.686 +This must always be called after DrawingBegin(const CFbsBitmap*, TBool).
1.687 +Like DrawingBegin(const CFbsBitmap*, TBool) it will panic in debug builds
1.688 +if passed a null pointer.
1.689 +@param aBitmap A pointer to a CFbsBitmap object to be unfrozen.
1.690 +@param aAlways Not used.
1.691 +
1.692 +@see CFbsBitmapDevice::DrawingEnd()
1.693 +*/
1.694 +void CFbsDevice::DrawingEnd(const CFbsBitmap* aBitmap, TBool /*aAlways*/)
1.695 + {
1.696 + BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap);
1.697 + if (aBitmap)
1.698 + aBitmap->EndDataAccess(ETrue);
1.699 + DrawingEnd();
1.700 + }
1.701 +
1.702 +/**
1.703 +Used to set an offset
1.704 +@param aOrigin The offset to give
1.705 +@return KErrNone on success, otherwise a system wide error code
1.706 +*/
1.707 +EXPORT_C TInt CFbsDevice::SetDrawDeviceOffset(const TPoint& aOrigin)
1.708 + {
1.709 + if(!iDrawDevice)
1.710 + {
1.711 + return KErrGeneral;
1.712 + }
1.713 + MDrawDeviceOrigin* drawDevice=NULL;
1.714 + if ( iDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID,reinterpret_cast<void*&>(drawDevice))<KErrNone
1.715 + || drawDevice==NULL
1.716 + )
1.717 + {
1.718 + return KErrNotSupported;
1.719 + }
1.720 + drawDevice->Set(aOrigin);
1.721 + return KErrNone;
1.722 + }