sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "BITPANIC.H" sl@0: sl@0: /** sl@0: Used by RectCompare() sl@0: @internalComponent sl@0: */ sl@0: enum {EScanBufSize=0x80}; sl@0: sl@0: CFbsDevice::CFbsDevice(): sl@0: CBitmapDevice() sl@0: { sl@0: iFbs = RFbsSession::GetSession(); sl@0: } sl@0: sl@0: sl@0: /** Frees all resources owned by the object prior to its destruction. */ sl@0: EXPORT_C CFbsDevice::~CFbsDevice() sl@0: { sl@0: delete iDrawDevice; sl@0: delete iTypefaceStore; sl@0: delete iBitBltMaskedBuffer; sl@0: delete iGraphicsAccelerator; sl@0: } sl@0: sl@0: /** Creates a font and bitmap server graphics context for the device and sl@0: activates it. sl@0: sl@0: It is the responsibility of the caller to delete the graphics context when sl@0: it is no longer needed. sl@0: sl@0: @param aGc On return, contains a pointer to the graphics context. sl@0: @return KErrNone if successful, otherwise, another one of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::CreateContext(CFbsBitGc*& aGc) sl@0: { sl@0: TRAPD(ret,aGc = CFbsBitGc::NewL()); sl@0: if (ret != KErrNone) sl@0: return ret; sl@0: sl@0: if (iScreenDevice) sl@0: aGc->ActivateNoJustAutoUpdate(this); sl@0: else sl@0: aGc->Activate(this); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** Gets the device's display mode. sl@0: sl@0: @return The display mode of the device. */ sl@0: EXPORT_C TDisplayMode CFbsDevice::DisplayMode() const sl@0: { sl@0: return iDrawDevice->DisplayMode(); sl@0: } sl@0: sl@0: /** Gets the size of the device, in pixels. sl@0: sl@0: @return The width and height of the device, in pixels */ sl@0: EXPORT_C TSize CFbsDevice::SizeInPixels() const sl@0: { sl@0: return iDrawDevice->SizeInPixels(); sl@0: } sl@0: sl@0: /** Compares two rectangles, including their contents. sl@0: sl@0: This function is intended for use by test code only. sl@0: sl@0: @param aSourceRect The first rectangle to be compared (in this device). sl@0: @param aDevice The font and bitmap server device in which the second rectangle sl@0: is found. sl@0: @param aDeviceRect The second rectangle to be compared. sl@0: @return ETrue if the rectangles are the same; EFalse otherwise. */ sl@0: EXPORT_C TBool CFbsDevice::RectCompare(const TRect& aSourceRect, sl@0: const CFbsDevice& aDevice, sl@0: const TRect& aDeviceRect) const sl@0: { sl@0: TRect deviceRect1; sl@0: iDrawDevice->GetDrawRect(deviceRect1); sl@0: TRect deviceRect2; sl@0: aDevice.iDrawDevice->GetDrawRect(deviceRect2); sl@0: TRect area(deviceRect1); sl@0: TRect devarea(deviceRect2); sl@0: TRect tmp(aSourceRect); sl@0: TRect tmp2(aDeviceRect); sl@0: tmp.Intersection(area); sl@0: tmp2.Intersection(devarea); sl@0: if (tmp!=aSourceRect || sl@0: tmp2!=aDeviceRect) sl@0: return(EFalse); sl@0: TInt width=aSourceRect.Width(); sl@0: TInt height=aSourceRect.Height(); sl@0: if (width!=aDeviceRect.Width() || sl@0: height!=aDeviceRect.Height()) sl@0: return(EFalse); sl@0: sl@0: TBuf8 buf1; sl@0: TBuf8 buf2; sl@0: TDisplayMode displayMode = iDrawDevice->ScanLineDisplayMode(); sl@0: if (displayMode < EGray256) sl@0: displayMode = EGray256; sl@0: else if (displayMode == EColor16) sl@0: displayMode = EColor256; // Increase the display mode so that each pixel takes at least one byte sl@0: TInt colsPerBuf=(EScanBufSize*EScanBufSize)/ sl@0: CFbsBitmap::ScanLineLength(EScanBufSize, displayMode); sl@0: TBool ret=EFalse; sl@0: sl@0: for(TInt row=0;rowAddFile(aName,aId); sl@0: } sl@0: sl@0: /** Decrements the reference count of a file which was added using sl@0: AddFile(), and removes the file from the typeface store if the reference count reaches zero. sl@0: sl@0: If zero is passed as parameter, then an attempt is made to remove all font objects sl@0: from the device's typeface store provided none of the fonts in the store are sl@0: currently accessed, otherwise it has no effect. sl@0: sl@0: @param aId The UID value of the font file to be removed. The default is 0. */ sl@0: EXPORT_C void CFbsDevice::RemoveFile(TInt aId) sl@0: { sl@0: iTypefaceStore->RemoveFile(aId); sl@0: } sl@0: sl@0: /** Provides access to a client-side font object in the device's typeface store that most closely sl@0: matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() sl@0: yielding (virtually) the same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in twips. sl@0: @return KErrNone if successful; otherwise, another one of the system-wide error sl@0: codes. sl@0: @deprecated */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** Creates a client-side font from those available in the device's typeface sl@0: store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels() sl@0: yielding (virtually) the same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of pixels, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in pixels. sl@0: @return KErrNone if successful; otherwise, another of the system-wide error sl@0: codes. sl@0: @deprecated */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontInPixels(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** Creates a client-side font from those available in the device's typeface sl@0: store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the sl@0: same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in twips. sl@0: @return KErrNone if successful; otherwise, another one of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** Creates a client-side font from those available in the device's typeface sl@0: store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the sl@0: same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of pixels, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in pixels. sl@0: @return KErrNone if successful; otherwise, another one of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return iTypefaceStore->GetNearestFontToDesignHeightInPixels(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** Creates a client-side font from those available in the device's typeface sl@0: store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: The font and bitmap server returns a pointer to the nearest matching font sl@0: from those available. Matches to max height of font - this does its best sl@0: to return a font that will fit within the maximum height specified (but sl@0: note that variations due to hinting algorithms may rarely result in this sl@0: height being exceeded by up to one pixel). Problems can also be sl@0: encountered with bitmap fonts where the typeface exists but doesn't have sl@0: a font small enough. sl@0: sl@0: @param aFont On return, the pointer is set to point to the device font which sl@0: most closely approximates to the required font specification. sl@0: @param aFontSpec An absolute font specification. sl@0: @param aMaxHeight The maximum height in twips within which the font must sl@0: fit - this overrides the height specified in aFontSpec. If maximum height sl@0: is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument sl@0: if equals to 1 pixel. sl@0: @return KErrNone, if successful; otherwise, another of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: return iTypefaceStore->GetNearestFontToMaxHeightInTwips(aFont, aFontSpec, aMaxHeight); sl@0: } sl@0: sl@0: /** Creates a client-side font from those available in the device's typeface sl@0: store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: The font and bitmap server returns a pointer to the nearest matching font sl@0: from those available. Matches to max height of font - this does its best sl@0: to return a font that will fit within the maximum height specified (but sl@0: note that variations due to hinting algorithms may rarely result in this sl@0: height being exceeded by up to one pixel). Problems can also be sl@0: encountered with bitmap fonts where the typeface exists but doesn't have sl@0: a font small enough. sl@0: sl@0: @param aFont On return, the pointer is set to point to the device font which sl@0: most closely approximates to the required font specification. sl@0: @param aFontSpec An absolute font specification. sl@0: @param aMaxHeight The maximum height in pixels within which the font must sl@0: fit - this overrides the height specified in aFontSpec. If maximum height sl@0: is greater than 1024 pixels, the function returns KErrTooBig. And returns KErrArgument sl@0: if equals to 1 pixel. sl@0: @return KErrNone, if successful; otherwise, another of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: return iTypefaceStore->GetNearestFontToMaxHeightInPixels(aFont, aFontSpec, aMaxHeight ); sl@0: } sl@0: sl@0: /** Gets a specific bitmap font, identified by its UID, from the device's typeface sl@0: store. sl@0: sl@0: When the font is no longer needed, call ReleaseFont(). sl@0: sl@0: @param aFont On return, set to point to the font. sl@0: @param aUId The UID identifying the bitmap font. sl@0: @param aStyle Algorithmic style for the font. sl@0: @return KErrNone if successful; otherwise, another of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::GetFontById(CFont*& aFont,TUid aUId,const TAlgStyle& aStyle) sl@0: { sl@0: return iTypefaceStore->GetFontById(aFont,aUId,aStyle); sl@0: } sl@0: sl@0: /** Marks the specified font as no longer needed by the user of the device. sl@0: sl@0: As fonts can be shared between applications, this function does not delete sl@0: the copy of the font from RAM unless the font is only being used by this device. sl@0: sl@0: @param aFont A pointer to the font to be released. */ sl@0: EXPORT_C void CFbsDevice::ReleaseFont(CFont* aFont) sl@0: { sl@0: iTypefaceStore->ReleaseFont(aFont); sl@0: } sl@0: sl@0: /** Gets the number of typefaces supported by the device. sl@0: sl@0: @return The number of typefaces supported. */ sl@0: EXPORT_C TInt CFbsDevice::NumTypefaces() const sl@0: { sl@0: return iTypefaceStore->NumTypefaces(); sl@0: } sl@0: sl@0: /** Gets information about an indexed typeface. sl@0: sl@0: @param aTypefaceSupport Provides information about the typeface, including sl@0: its name and attributes. sl@0: @param aTypefaceIndex The index of the requested typeface in the device's sl@0: typeface store; between zero and NumTypefaces() 1 inclusive. sl@0: @see CGraphicsDevice::TypefaceSupport() */ sl@0: EXPORT_C void CFbsDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, sl@0: TInt aTypefaceIndex) const sl@0: { sl@0: iTypefaceStore->TypefaceSupport(aTypefaceSupport,aTypefaceIndex); sl@0: } sl@0: sl@0: /** Gets the height of a font in twips. sl@0: sl@0: This is an implementation of sl@0: CGraphicsDevice::FontHeightInTwips(). */ sl@0: EXPORT_C TInt CFbsDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return iTypefaceStore->FontHeightInTwips(aTypefaceIndex,aHeightIndex); sl@0: } sl@0: sl@0: /** Gets the height, in pixels, of the specified typeface at one of its sl@0: defined heights. sl@0: sl@0: This is an implementation of sl@0: CBitMapDevice::FontHeightInPixels(). */ sl@0: EXPORT_C TInt CFbsDevice::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return iTypefaceStore->FontHeightInPixels(aTypefaceIndex,aHeightIndex); sl@0: } sl@0: sl@0: /** sl@0: Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store. sl@0: @capability ECapabilityWriteDeviceData sl@0: @publishedPartner sl@0: @released sl@0: @param aLinkedTypefaceSpec. The typeface specification to be added. sl@0: @param aId. A unique ID for the typeface sl@0: @return an global error code sl@0: @see CLinkedTypefaceSpecification sl@0: */ sl@0: EXPORT_C TInt CFbsDevice::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec, TInt& aId) sl@0: { sl@0: return iTypefaceStore->RegisterLinkedTypeface(aLinkedTypefaceSpec, aId); sl@0: } sl@0: sl@0: /** Sets the variable 8 bits per pixel colour palette, replacing the system default sl@0: one. Only the entries in the system default palette which have corresponding sl@0: entries in aPalette are overwritten, i.e. if aPalette contains fewer than sl@0: 256 colours, some will remain unchanged. If aPalette has more than 256 entries, sl@0: the additional entries are ignored. sl@0: sl@0: @param aPalette The custom palette. sl@0: @return KErrNone if successful; otherwise, another of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CFbsDevice::SetCustomPalette(const CPalette* aPalette) sl@0: { sl@0: TInt ret = iDrawDevice->SetCustomPalette(aPalette); sl@0: if(ret==KErrNone) sl@0: { sl@0: // Graphics accelerator doesn't currently support changing palettes, sl@0: // so delete it if the palette is successfully changed. sl@0: delete iGraphicsAccelerator; sl@0: iGraphicsAccelerator = NULL; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: The method gets a scanline and puts the scanline data into aBuf. sl@0: @internalComponent sl@0: @param aBuf The destination buffer. It should be with enough length to collect sl@0: requested scanline data. sl@0: @param aPixel The first pixel of the requested scanline data sl@0: @param aLength The length in pixels of requested data sl@0: @param aDispMode requested scanline should be converted regarding aDispMode parameter sl@0: */ sl@0: void CFbsDevice::DoGetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength, sl@0: TDisplayMode aDispMode) sl@0: { sl@0: TRect deviceRect; sl@0: iDrawDevice->GetDrawRect(deviceRect); sl@0: if (aPixel.iY < deviceRect.iTl.iY || aPixel.iY > deviceRect.iBr.iY) sl@0: return; sl@0: sl@0: TInt byteLength = 0; sl@0: TInt bitsPerPixel = 0; sl@0: sl@0: switch(aDispMode) sl@0: { sl@0: case EGray2: sl@0: bitsPerPixel = 1; sl@0: byteLength = aLength / 8 + (aLength % 8 ? 1 : 0); sl@0: break; sl@0: case EGray4: sl@0: bitsPerPixel = 2; sl@0: byteLength = aLength / 4 + (aLength % 4 ? 1 : 0); sl@0: break; sl@0: case EGray16: sl@0: case EColor16: sl@0: bitsPerPixel = 4; sl@0: byteLength = aLength / 2 + (aLength % 2 ? 1 : 0); sl@0: break; sl@0: case EGray256: sl@0: case EColor256: sl@0: bitsPerPixel = 8; sl@0: byteLength = aLength; sl@0: break; sl@0: case EColor4K: sl@0: case EColor64K: sl@0: bitsPerPixel = 16; sl@0: byteLength = aLength * 2; sl@0: break; sl@0: case EColor16M: sl@0: bitsPerPixel = 24; sl@0: byteLength = aLength * 3; sl@0: break; sl@0: case ERgb: sl@0: case EColor16MU: sl@0: case EColor16MA: sl@0: case EColor16MAP: sl@0: bitsPerPixel = 32; sl@0: byteLength = aLength * 4; sl@0: break; sl@0: case ENone: sl@0: default: sl@0: BG_PANIC_ALWAYS(EBitgdiPanicInvalidDisplayMode); sl@0: } sl@0: sl@0: if (byteLength > aBuf.MaxLength()) sl@0: { sl@0: TInt pixelsMaxCount = (aBuf.MaxLength() * 8) / bitsPerPixel; sl@0: if(aLength > pixelsMaxCount) sl@0: { sl@0: aLength = pixelsMaxCount; sl@0: } sl@0: aBuf.SetMax(); sl@0: } sl@0: else sl@0: { sl@0: aBuf.SetLength(byteLength); sl@0: } sl@0: sl@0: TInt x1 = Max(aPixel.iX, deviceRect.iTl.iX); sl@0: TInt x2 = Min(aPixel.iX + aLength, deviceRect.iBr.iX); sl@0: if (x2 <= x1) sl@0: return; sl@0: sl@0: TUint8* vals = (TUint8*)(aBuf.Ptr()); sl@0: iDrawDevice->ReadLine(x1,aPixel.iY,x2 - x1,vals,aDispMode); sl@0: } sl@0: sl@0: void CFbsDevice::TruncateRect(TRect& aRect) sl@0: { sl@0: TInt width = iDrawDevice->SizeInPixels().iWidth << 4; sl@0: TInt height = iDrawDevice->SizeInPixels().iHeight << 4; sl@0: sl@0: aRect.iTl.iX = Min(aRect.iTl.iX,width); sl@0: aRect.iTl.iY = Min(aRect.iTl.iY,height); sl@0: aRect.iBr.iX = Min(aRect.iBr.iX,width); sl@0: aRect.iBr.iY = Min(aRect.iBr.iY,height); sl@0: sl@0: width =- width; sl@0: height =- height; sl@0: sl@0: aRect.iTl.iX = Max(aRect.iTl.iX,width); sl@0: aRect.iTl.iY = Max(aRect.iTl.iY,height); sl@0: aRect.iBr.iX = Max(aRect.iBr.iX,width); sl@0: aRect.iBr.iY = Max(aRect.iBr.iY,height); sl@0: } sl@0: sl@0: TBool CFbsDevice::SetOrientation(CFbsBitGc::TGraphicsOrientation aOrientation) sl@0: { sl@0: TBool ret = iDrawDevice->SetOrientation((CFbsDrawDevice::TOrientation)aOrientation); sl@0: if(ret) sl@0: iOrientation = aOrientation; sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Depending on the current graphics hardware this sl@0: will return one of the 16M video modes defined in sl@0: TDisplayMode, or ENone if a 16M video mode is not supported. sl@0: @see TDisplayMode sl@0: @return a 16M display mode or ENone. sl@0: */ sl@0: EXPORT_C TDisplayMode CFbsDevice::DisplayMode16M() sl@0: { sl@0: return CFbsDrawDevice::DisplayMode16M(); sl@0: } sl@0: sl@0: /** sl@0: Sets scaling factor by which the drawing device should scale the drawing images. sl@0: If you want to un-scale the device, call SetScalingFactor() with Origin (0,0), sl@0: factorX = 1, factorY = 1, divisorX = 1, divisorY = 1. sl@0: sl@0: Note: The existing graphics acceleration interface does not have support for scaling. sl@0: sl@0: Note: All graphics contexts, already created by the scaled device, should be sl@0: re-activated calling CFbsBitGc::Activate(). sl@0: sl@0: @param aOrigin Specifies physical coordinates of the new scaling origin sl@0: of the drawing device. The drawing device maps the logical point [0, 0] to sl@0: the "aOrigin" physical point . sl@0: @param aFactorX Scaling factor for the X-axis of the screen device. sl@0: @param aFactorY Scaling factor for the y-axis of the screen device. sl@0: @param aDivisorX Not used. Should be set to 1. sl@0: @param aDivisorY Not used. Should be set to 1. sl@0: @return KErrNone If the method succeeds. sl@0: KErrNotSupported The drawing device does not have scaling capabilities. sl@0: */ sl@0: EXPORT_C TInt CFbsDevice::SetScalingFactor(const TPoint& aOrigin, sl@0: TInt aFactorX, TInt aFactorY, sl@0: TInt aDivisorX, TInt aDivisorY) sl@0: { sl@0: //This class takes care about setting scaling and origin and restoring the original values sl@0: //if some of the operations fails. sl@0: class TInitializer sl@0: { sl@0: public: sl@0: TInitializer(CFbsDrawDevice* aDrawDevice) : sl@0: iScalingSettings(NULL), iOriginInterface(NULL), sl@0: iError(KErrNone), sl@0: iFx(1), iFy(1), iDivX(1), iDivY(1), sl@0: iOrigin(0, 0) sl@0: {//Acquire the interfaces and save the original settings. They will be used if the initialization fails. sl@0: iError = aDrawDevice->GetInterface(KScalingSettingsInterfaceID, sl@0: reinterpret_cast (iScalingSettings)); sl@0: if(iError == KErrNone) sl@0: { sl@0: BG_ASSERT_DEBUG_INVARIANT(iScalingSettings); sl@0: iScalingSettings->Get(iFx, iFy, iDivX, iDivY); sl@0: iError = aDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, sl@0: reinterpret_cast (iOriginInterface)); sl@0: if(iError == KErrNone) sl@0: { sl@0: BG_ASSERT_DEBUG_INVARIANT(iOriginInterface); sl@0: iOriginInterface->Get(iOrigin); sl@0: } sl@0: } sl@0: } sl@0: ~TInitializer() sl@0: {//Restore the original settings if setting of the new ones had failed. sl@0: if(iError != KErrNone) sl@0: { sl@0: if(iScalingSettings) sl@0: { sl@0: (void)iScalingSettings->Set(iFx, iFy, iDivX, iDivY); sl@0: } sl@0: if(iOriginInterface) sl@0: { sl@0: (void)iOriginInterface->Set(iOrigin); sl@0: } sl@0: } sl@0: } sl@0: void SetScalingFactor(TInt aFactorX, TInt aFactorY, TInt aDivisorX, TInt aDivisorY) sl@0: { sl@0: if(iError == KErrNone) sl@0: { sl@0: iError = iScalingSettings->Set(aFactorX, aFactorY, aDivisorX, aDivisorY); sl@0: } sl@0: } sl@0: void SetOrigin(const TPoint& aOrigin) sl@0: { sl@0: if(iError == KErrNone) sl@0: { sl@0: iError = iOriginInterface->Set(aOrigin); sl@0: } sl@0: } sl@0: TInt Error() const sl@0: { sl@0: return iError; sl@0: } sl@0: private: sl@0: MScalingSettings* iScalingSettings; sl@0: MDrawDeviceOrigin* iOriginInterface; sl@0: TInt iError; sl@0: TInt iFx, iFy, iDivX, iDivY; sl@0: TPoint iOrigin; sl@0: }; sl@0: TInitializer initializer(iDrawDevice); sl@0: initializer.SetScalingFactor(aFactorX, aFactorY, aDivisorX, aDivisorY); sl@0: initializer.SetOrigin(aOrigin); sl@0: TInt err = initializer.Error(); sl@0: if(err == KErrNone && sl@0: (aFactorX != aDivisorX || aFactorY != aDivisorY || aOrigin.iX != 0 || aOrigin.iY != 0)) sl@0: { sl@0: //Graphics accelerator interface doesn't have support for scaling&origin. sl@0: delete iGraphicsAccelerator; sl@0: iGraphicsAccelerator = NULL; sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: /** sl@0: Gets logical coordinates of the drawing rectangle. sl@0: If the device is not scaled, logocal coordinates of the drawing rectangle are the sl@0: same as its physical coordinates. sl@0: @param aRect Upon return aRect contains drawing rectangle logical coordinates. sl@0: */ sl@0: EXPORT_C void CFbsDevice::GetDrawRect(TRect& aRect) const sl@0: { sl@0: iDrawDevice->GetDrawRect(aRect); sl@0: } sl@0: sl@0: /** sl@0: An overloaded version of DrawingBegin(TBool). Similarly to that method, calls to sl@0: DrawingBegin(const CFbsBitmap*, TBool) must be paired with a subsequent call to sl@0: DrawingEnd(const CFbsBitmap*, TBool). Also, code must not leave between a sl@0: DrawingBegin(const CFbsBitmap*, TBool) - DrawingEnd(const CFbsBitmap*, TBool) pair. sl@0: @param aBitmap An additional parameter compared to the basic overload. sl@0: aBitmap is a pointer to a CFbsBitmap object to be frozen. If a null pointer sl@0: is given then the method panics. sl@0: @param aAlways Not used. sl@0: sl@0: @see CFbsBitmapDevice::DrawingBegin() sl@0: */ sl@0: void CFbsDevice::DrawingBegin(const CFbsBitmap* aBitmap, TBool /*aAlways*/) sl@0: { sl@0: BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap); sl@0: if (aBitmap) sl@0: aBitmap->BeginDataAccess(); sl@0: DrawingBegin(); sl@0: } sl@0: sl@0: /** sl@0: This must always be called after DrawingBegin(const CFbsBitmap*, TBool). sl@0: Like DrawingBegin(const CFbsBitmap*, TBool) it will panic in debug builds sl@0: if passed a null pointer. sl@0: @param aBitmap A pointer to a CFbsBitmap object to be unfrozen. sl@0: @param aAlways Not used. sl@0: sl@0: @see CFbsBitmapDevice::DrawingEnd() sl@0: */ sl@0: void CFbsDevice::DrawingEnd(const CFbsBitmap* aBitmap, TBool /*aAlways*/) sl@0: { sl@0: BG_ASSERT_DEBUG(aBitmap, EBitgdiPanicInvalidBitmap); sl@0: if (aBitmap) sl@0: aBitmap->EndDataAccess(ETrue); sl@0: DrawingEnd(); sl@0: } sl@0: sl@0: /** sl@0: Used to set an offset sl@0: @param aOrigin The offset to give sl@0: @return KErrNone on success, otherwise a system wide error code sl@0: */ sl@0: EXPORT_C TInt CFbsDevice::SetDrawDeviceOffset(const TPoint& aOrigin) sl@0: { sl@0: if(!iDrawDevice) sl@0: { sl@0: return KErrGeneral; sl@0: } sl@0: MDrawDeviceOrigin* drawDevice=NULL; sl@0: if ( iDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID,reinterpret_cast(drawDevice))Set(aOrigin); sl@0: return KErrNone; sl@0: }