Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include <bitdrawscaling.h>
22 #include <bitdraworigin.h>
23 #include <bitdrawinterfaceid.h>
25 #include <bmalphablend.h>
26 #include <graphics/gdi/gdiconsts.h>
29 #if defined(SYMBIAN_GRAPHICS_GCE)
30 #include <bitdrawsurface.h>
34 @param aScreenNo The screen number. If the device has a support for only one screen, its
37 CFbsScreenDevice::CFbsScreenDevice(TInt aScreenNo):
44 /** Creates a new CFbsScreenDevice object.
46 @param aLibname Not used.
47 @param aDispMode The display mode of the device.
48 @return The newly created FBSERV screen device. */
49 EXPORT_C CFbsScreenDevice* CFbsScreenDevice::NewL(const TDesC& /*aLibname*/,
50 TDisplayMode aDispMode)
52 return CFbsScreenDevice::NewL(KDefaultScreenNo, aDispMode);
55 /** Creates a new CFbsScreenDevice object.
57 @param aLibname Not used.
58 @param aDispMode The display mode of the device.
59 @param aWhite Not used.
60 @return The newly created font and bitmap server screen device.
61 @deprecated Use two param version instead. */
62 EXPORT_C CFbsScreenDevice* CFbsScreenDevice::NewL(const TDesC& /*aLibname*/,
63 TDisplayMode aDispMode,
66 return CFbsScreenDevice::NewL(KDefaultScreenNo, aDispMode);
70 Creates a new CFbsScreenDevice object.
71 @param aScreenNo The screen number. If the device has a support for only one screen, its
73 @param aDispMode The display mode of the device.
74 @return The newly created FBSERV screen device.
76 EXPORT_C CFbsScreenDevice* CFbsScreenDevice::NewL(TInt aScreenNo, TDisplayMode aDispMode)
78 CFbsScreenDevice* self = new (ELeave) CFbsScreenDevice(aScreenNo);
79 CleanupStack::PushL(self);
80 self->ConstructL(aScreenNo, aDispMode);
81 CleanupStack::Pop(); // self
85 /** Frees all resources owned by the object prior to its destruction. */
86 EXPORT_C CFbsScreenDevice::~CFbsScreenDevice()
90 void CFbsScreenDevice::ConstructL(TInt aScreenNo, TDisplayMode aDispMode)
92 iDrawDevice = CFbsDrawDevice::NewScreenDeviceL(aScreenNo, aDispMode);
93 iScreenDevice = ETrue;
94 iTypefaceStore = CFbsTypefaceStore::NewL(this);
95 if(aDispMode != EGray4) // Flicker-free blitting not enabled under EGray4 because it messes up the EGray16-emulating dithering
97 TInt scanLineBytes = iDrawDevice->ScanLineBytes();
98 const TSize screenSize = SizeInPixels();
99 if(screenSize.iHeight > screenSize.iWidth)
101 scanLineBytes = scanLineBytes * screenSize.iHeight / screenSize.iWidth;
103 iBitBltMaskedBuffer = new(ELeave) TUint8[scanLineBytes * 2];
108 /** Copies a scanline into a buffer.
110 This implements the pure virtual function
111 CBitmapDevice::GetScanLine(). */
112 EXPORT_C void CFbsScreenDevice::GetScanLine(TDes8& aBuf,const TPoint& aStartPixel,
113 TInt aLength,TDisplayMode aDispMode) const
118 ((CFbsScreenDevice*)this)->DoGetScanLine(aBuf,aStartPixel,aLength,aDispMode);
122 /** Gets the RGB colour of an individual pixel on a bitmapped graphics
125 This implements the pure virtual function
126 CBitmapDevice::GetPixel(). */
127 EXPORT_C void CFbsScreenDevice::GetPixel(TRgb& aColor,const TPoint& aPoint) const
133 iDrawDevice->GetDrawRect(deviceRect);
134 if (!deviceRect.Contains(aPoint))
137 aColor = iDrawDevice->ReadPixel(aPoint.iX,aPoint.iY);
141 /** Converts a horizontal dimension from pixels to twips.
143 This implements the pure virtual function
144 MGraphicsDeviceMap::HorizontalPixelsToTwips(). */
145 EXPORT_C TInt CFbsScreenDevice::HorizontalPixelsToTwips(TInt aPixels) const
147 TInt64 pixels=aPixels;
148 pixels=(iDrawDevice->HorzTwipsPerThousandPixels() * pixels + 500) / 1000;
149 return I64INT(pixels);
153 /** Converts a vertical dimension from pixels to twips.
155 This implements the pure virtual function
156 MGraphicsDeviceMap::VerticalPixelsToTwips(). */
157 EXPORT_C TInt CFbsScreenDevice::VerticalPixelsToTwips(TInt aPixels) const
159 TInt64 pixels=aPixels;
160 pixels=(iDrawDevice->VertTwipsPerThousandPixels() * pixels + 500) / 1000;
161 return I64INT(pixels);
166 This method has been deprecated. Sprites are no longer supported in BitGDI.
167 Calling this method has no effect.
170 EXPORT_C void CFbsScreenDevice::DrawSpriteBegin()
176 This method has been deprecated. Sprites are no longer supported in BitGDI.
177 Calling this method has no effect.
180 EXPORT_C void CFbsScreenDevice::DrawSpriteEnd()
186 This method has been deprecated. Sprites are no longer supported in BitGDI.
187 Calling this method has no effect.
192 EXPORT_C TSpriteBase* CFbsScreenDevice::HideSprite() const
199 This method has been deprecated. Sprites are no longer supported in BitGDI.
200 Calling this method has no effect.
202 @param aRect Ignored.
203 @param aClippingRegion Ignored.
207 EXPORT_C TSpriteBase* CFbsScreenDevice::HideSprite(const TRect& /*aRect*/,
208 const TRegion* /*aClippingRegion*/) const
215 This method has been deprecated. Sprites are no longer supported in BitGDI.
216 Calling this method has no effect.
218 @param aSprite Ignored.
221 EXPORT_C void CFbsScreenDevice::ShowSprite(TSpriteBase* /*aSprite*/) const
227 This method has been deprecated. Sprites are no longer supported in BitGDI.
228 Calling this method has no effect.
230 @param aSprite Ignored.
231 @param aRect Ignored.
232 @param aClippingRegion Ignored.
235 EXPORT_C void CFbsScreenDevice::ShowSprite(TSpriteBase* /*aSprite*/,const TRect& /*aRect*/,
236 const TRegion* /*aClippingRegion*/) const
241 /** Changes the screen device.
243 @param aOldDevice A pointer to the old screen device. */
244 EXPORT_C void CFbsScreenDevice::ChangeScreenDevice(CFbsScreenDevice* aOldDevice)
246 if (aOldDevice == NULL)
248 TInt ret = iDrawDevice->InitScreen();
249 BG_ASSERT_ALWAYS(ret == KErrNone,EBitgdiPanicInvalidWindowHandle);
253 delete aOldDevice->iGraphicsAccelerator;
254 aOldDevice->iGraphicsAccelerator = NULL;
256 if (aOldDevice != this)
258 iDrawDevice->SetDisplayMode(aOldDevice->iDrawDevice);
259 iOrientation = aOldDevice->iOrientation;
261 // else we're re-initialising the existing CFbsScreenDevice's graphics accelerator only
264 //Check if the screen device is scaled or the origin is moved.
265 //If it is, then do not create graphics accelerator
266 //instance, because it does not have support for scaling&origin.
267 TBool scalingOff = ETrue;
268 TBool originZero = ETrue;
269 MScalingSettings* scalingSettings = NULL;
270 if(iDrawDevice->GetInterface(KScalingSettingsInterfaceID,
271 reinterpret_cast <TAny*&> (scalingSettings)) == KErrNone)
273 BG_ASSERT_DEBUG_INVARIANT(scalingSettings);
274 scalingOff = scalingSettings->IsScalingOff();
276 MDrawDeviceOrigin* originInterface = NULL;
277 if(iDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID,
278 reinterpret_cast <TAny*&> (originInterface)) == KErrNone)
280 BG_ASSERT_DEBUG_INVARIANT(originInterface);
282 originInterface->Get(origin);
283 originZero = origin.iX == 0 && origin.iY == 0;
285 if(scalingOff && originZero)
287 RHardwareBitmap screen;
288 //Some explanations about "-1 - iScreenNo" expression.
289 //SetAsScreenReference() is a public, exported method with a default argument'value -1.
290 //In SetAsScreenReference()'s implementation before "Multiple screens" source code update,
291 //"-1" value meant - this is a screen hardware bitmap. Positive value meant -
292 //in-memory hardware bitmap.
293 //After "Multiple screens" update, the meaning of SetAsScreenReference()'s argument is:
294 // - Positive value - in-memory hardware bitmap;
295 // - Negative value - screen number: "-1" - screen 0, "-2" - screen 1, "-3" - screen 2, ...;
296 if(screen.SetAsScreenReference(-1 - iScreenNo)==KErrNone)
298 TRAP_IGNORE(iGraphicsAccelerator = CHardwareGraphicsAccelerator::NewL(screen));
304 /** Gets the palette attributes of the device.
306 @param aModifiable On return, holds information on whether or not the device
307 palette is modifiable (ETrue) or fixed (EFalse).
308 @param aNumEntries On return, holds the number of entries in the device
310 EXPORT_C void CFbsScreenDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
312 aModifiable = (iDrawDevice->DisplayMode() == EColor256);
313 aNumEntries = TDisplayModeUtils::NumDisplayModeColors(iDrawDevice->DisplayMode());
317 /** Sets the device's palette to the specified palette.
319 Setting the palette is only possible if the device has a modifiable palette,
320 which can be determined by calling PaletteAttributes().
322 @param aPalette The new palette for the device. */
323 EXPORT_C void CFbsScreenDevice::SetPalette(CPalette* aPalette)
325 SetCustomPalette(aPalette); // Have to ignore error for compatibility
329 /** Gets the device's current palette.
331 This function is only supported if the device has a modifiable palette,
332 which can be determined by calling PaletteAttributes().
334 @param aPalette On return, holds the devices current palette.
335 @return KErrNone, if successful; otherwise, another of the system-wide error
337 EXPORT_C TInt CFbsScreenDevice::GetPalette(CPalette*& aPalette) const
339 return iDrawDevice->GetCustomPalette(aPalette);
344 This method has been deprecated. Sprites are no longer supported in BitGDI.
345 Calling this method has no effect.
348 EXPORT_C void CFbsScreenDevice::CancelSprite() const
353 /** Sets or unsets auto-update for the screen.
355 @param aValue ETrue, if the screen is set to auto-update; EFalse, otherwise. */
356 EXPORT_C void CFbsScreenDevice::SetAutoUpdate(TBool aValue)
358 iDrawDevice->SetAutoUpdate(aValue);
362 /** Forces any out of date region of the screen to update. */
363 EXPORT_C void CFbsScreenDevice::Update()
365 iDrawDevice->Update();
369 /** Forces any out of date region of the screen to update,
370 and additionally forces the specified region to update.
372 @param aRegion The region of the screen to update, in addition
373 to any out of date region. */
374 EXPORT_C void CFbsScreenDevice::Update(const TRegion& aRegion)
376 iDrawDevice->Update(aRegion);
380 /** Gets the size of the device area, in twips.
382 This implements the pure virtual function CGraphicsDevice::SizeInTwips().
384 @see CGraphicsDevice::SizeInTwips() */
385 EXPORT_C TSize CFbsScreenDevice::SizeInTwips() const
388 twipssize.iWidth = HorizontalPixelsToTwips(iDrawDevice->SizeInPixels().iWidth);
389 twipssize.iHeight = VerticalPixelsToTwips(iDrawDevice->SizeInPixels().iHeight);
394 /** Converts a horizontal dimension from twips to pixels.
396 This implements the pure virtual function
397 MGraphicsDeviceMap::HorizontalTwipsToPixels(). */
398 EXPORT_C TInt CFbsScreenDevice::HorizontalTwipsToPixels(TInt aTwips) const
400 const TInt htptp = iDrawDevice->HorzTwipsPerThousandPixels();
401 TInt64 twips = aTwips;
402 twips = (1000 * twips + (htptp >> 1)) / htptp;
403 return I64INT(twips);
407 /** Converts a vertical dimension from twips to pixels.
409 This implements the pure virtual function
410 MGraphicsDeviceMap::VerticalTwipsToPixels(). */
411 EXPORT_C TInt CFbsScreenDevice::VerticalTwipsToPixels(TInt aTwips) const
413 const TInt vtptp = iDrawDevice->VertTwipsPerThousandPixels();
414 TInt64 twips = aTwips;
415 twips = (1000 * twips + (vtptp >> 1)) / vtptp;
416 return I64INT(twips);
420 /** Creates and returns a hardware bitmap (a bitmap which can be drawn to by a
421 graphics accelerator whose operations may be implemented in hardware or software),
422 whose handle is to the screen.
424 This allows the caller to draw to the screen like any other hardware bitmap.
426 This function may not be supported on all hardware. If unsupported, it returns
427 an RHardwareBitmap with a handle of zero.
429 The hardware bitmap can be used to draw directly to the screen. Use it to
430 create a TAcceleratedBitmapSpec object, which can either be used to get a
431 TAcceleratedBitmapInfo, or can be passed to a graphics operation (an instance
432 of a class derived from class TGraphicsOperation) e.g. a bitblt to copy one
433 part of the screen to another.
435 Direct screen access must only be carried out in combination with the Window
436 Server's direct screen access classes; i.e. only use the hardware bitmap on
437 the CFbsScreenDevice which you get from CDirectScreenAccess, and not from
438 your own CFbsScreenDevice.
440 @return A hardware bitmap whose handle is to the screen.
441 @see TAcceleratedBitmapSpec
442 @see TGraphicsOperation
443 @see CGraphicsAccelerator::Operation()
444 @see CDirectScreenAccess */
445 EXPORT_C RHardwareBitmap CFbsScreenDevice::HardwareBitmap()
448 //Some explanations about "-1 - iScreenNo" expression.
449 //SetAsScreenReference() is a public, exported method with a default argument'value -1.
450 //In SetAsScreenReference()'s implementation before "Multiple screens" source code update,
451 //"-1" value meant - this is a screen hardware bitmap. Positive value meant -
452 //in-memory hardware bitmap.
453 //After "Multiple screens" update, the meaning of SetAsScreenReference()'s argument is:
454 // - Positive value - in-memory hardware bitmap;
455 // - Negative value - screen number: "-1" - screen 0, "-2" - screen 1, "-3" - screen 2, ...;
456 hwb.SetAsScreenReference(-1 - iScreenNo);
460 /** Returns pointer to the location of first pixel in frame buffer. Not necessarily the same as pointer
463 @return Pointer to the location of first pixel or NULL if it is not accessible.
466 EXPORT_C const TUint32* CFbsScreenDevice::Bits() const
468 TAny* interface = NULL;
469 TInt ret = iDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
473 return reinterpret_cast<MFastBlit2*>(interface)->Bits();
476 /** Returns frame buffer line pitch or stride.
478 @return Frame buffer stride.
481 EXPORT_C TInt CFbsScreenDevice::Stride() const
483 return iDrawDevice->ScanLineBytes();
486 /** Query the screen number to which the object refers.
488 @return Screen number as passed in aScreenNo to NewL.
492 EXPORT_C TInt CFbsScreenDevice::ScreenNo() const
497 /** Get the surface identifier for the current device orientation of the screen.
498 If screen device doesn't support providing a surface, the caller is panicked.
500 @param aSurface Set to the surface identifier for the screen buffer.
504 EXPORT_C void CFbsScreenDevice::GetSurface(TSurfaceId& aSurface) const
506 #if defined(SYMBIAN_GRAPHICS_GCE)
507 TAny* interface = NULL;
508 TInt ret = iDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
511 reinterpret_cast<MSurfaceId*>(interface)->GetSurface(aSurface);
515 (void)aSurface; // Satisfies the compiler, if its a Non-GCE build.
516 Panic(EBitgdiPanicInvalidScreenDeviceLibrary);
519 /** This function is used to request the device orientations supported by the
522 @return A bitwise combination of one or more TDeviceOrientation enumerated
523 values indicating the device orientations that are supported by this device.
527 EXPORT_C TUint CFbsScreenDevice::DeviceOrientationsAvailable() const
529 #if defined(SYMBIAN_GRAPHICS_GCE)
530 TAny* interface = NULL;
531 TInt ret = iDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
533 return reinterpret_cast<MSurfaceId*>(interface)->DeviceOrientationsAvailable();
535 Panic(EBitgdiPanicInvalidScreenDeviceLibrary);
536 return 0; // Make the compiler happy.
539 /** This function selects the surface and device buffer to use in the screen
540 driver for this screen. Normal and 180° rotations will generally use the same
541 surface, while 90° and 270° will use another. The surfaces may have different
542 width, height, stride and surface, so functions that make use of any of these
543 may be affected after a change in surface orientation, and the return value
544 should be checked for this reason.
546 This call does not change the way rendering is performed, but may operate on
547 the underlying memory using a new shape. The call does not change the display
548 controller’s settings, as this is handled via the GCE. All this changes are the
549 internal attributes of the screen device and driver objects. A CFbsBitGc object
550 activated on the device should be reactivated, to update its own attributes, or
551 drawing may be corrupted.
553 Note: while TDeviceOrientation values do not directly correspond to
554 CFbsBitGc::TGraphicsOrientation values, and cannot be used interchangeably, it
555 is simple to generate the former from the latter using the left-shift operator
556 (i.e. device == (1 << graphics)). In particular a device orientation of 90
557 degrees clockwise is equivalent to a content orientation of 90 degrees anti-
558 clockwise, which is what TGraphicsOrientation refers to for the equivalent
559 setting. The letters "CW" in the TDeviceOrientation enumeration refer to a
560 clockwise device rotation, so EDeviceOrientation90CW is a 90 degree clockwise
561 rotation of the device.
563 @param aOrientation The new device orientation, relative to the normal physical
565 @return ETrue is returned if any of the surface, width, height or stride
566 attributes of the screen device have changed as a result of the call or EFalse
567 if none of the attributes have changed.
571 EXPORT_C TBool CFbsScreenDevice::SetDeviceOrientation(TDeviceOrientation aOrientation) const
573 #if defined(SYMBIAN_GRAPHICS_GCE)
574 TAny* interface = NULL;
575 TInt ret = iDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
577 return reinterpret_cast<MSurfaceId*>(interface)->SetDeviceOrientation(aOrientation);
579 (void)aOrientation; // Satisfies the compiler, if its a Non-GCE build.
580 Panic(EBitgdiPanicInvalidScreenDeviceLibrary);
581 return EFalse; // Make the compiler happy.
584 /** This function is used to request the current device orientation.
586 @return One of the TDeviceOrientation enumerated values.
590 EXPORT_C TDeviceOrientation CFbsScreenDevice::DeviceOrientation() const
592 #if defined(SYMBIAN_GRAPHICS_GCE)
593 TAny* interface = NULL;
594 TInt ret = iDrawDevice->GetInterface(KSurfaceInterfaceID, interface);
596 return reinterpret_cast<MSurfaceId*>(interface)->DeviceOrientation();
598 Panic(EBitgdiPanicInvalidScreenDeviceLibrary);
599 return EDeviceOrientationNormal; // Make the compiler happy.