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.
20 #include <e32event_private.h>
26 enum TScreenDriverPanic
28 EScreenDriverPanicNoDevicePresent=1,
29 EScreenDriverPanicInvalidParameter,
30 EScreenDriverPanicInvalidDisplayMode,
31 EScreenDriverPanicInvalidWindowHandle,
32 EScreenDriverPanicOutOfBounds,
33 EScreenDriverPanicZeroLength,
34 EScreenDriverPanicNullPointer,
35 EScreenDriverPanicInvalidPointer,
36 EScreenDriverPanicAlphaBlendInvariant,
37 EScreenDriverPanicIvalidMethodCall,
38 EScreenDriverPanicInvalidSize,
39 EScreenDriverPanicInvalidHalValue,
40 EScreenDriverPanicInvalidScreenNo,
41 EScreenDriverPanicIncompatiblePreviousDevice //<The previous device in SetDisplayMode was not compatible
48 GLREF_C void Panic(TScreenDriverPanic aPanicCode);
55 class CFbsDrawDevice : public CBase
59 Defines possible Shadowmode values
63 /** No Shadow mode is supported.
66 /** Shadow mode is supported.
69 /** Faded mode is supported.
72 /** Shadow and faded mode is supported.
77 Defines possible rotation values
81 /** Normal orientation is supported.
84 /** A 90 degree rotation is supported.
86 EOrientationRotated90,
87 /** A 180 degree rotation is supported.
89 EOrientationRotated180,
90 /** A 270 degree rotation is supported.
92 EOrientationRotated270
96 DEPRECATED: Use NewScreenDeviceL(TInt aScreenNo, TDisplayMode aDispMode)
100 IMPORT_C static CFbsDrawDevice* NewScreenDeviceL(TScreenInfoV01 aInfo,TDisplayMode aDispMode);
103 Creates a new screen device instance, which implements CFbsDrawDevice interface.
104 The method has to be implemented for each type of supported video hardware.
105 @param aScreenNo Screen number
106 @param aDispMode Requested display mode
107 @return A pointer to just created screen device, which implements CFbsDrawDevice interface
108 @leave KErrNoMemory Not enough memory
109 KErrNotSupported The requested screen device type is not supported
111 IMPORT_C static CFbsDrawDevice* NewScreenDeviceL(TInt aScreenNo, TDisplayMode aDispMode);
114 DEPRECATED: Use NewBitmapDeviceL(const TSize& aSize, TDisplayMode aDispMode, TInt aDataStride)
118 IMPORT_C static CFbsDrawDevice* NewBitmapDeviceL(TScreenInfoV01 aInfo, TDisplayMode aDispMode, TInt aDataStride);
121 Creates a new bitmap device instance, which implements CFbsDrawDevice interface.
123 @param aSize Bitmap device size
124 @param aDispMode Bitmap display mode
125 @param aDataStride Bitmap data stride
126 @return A pointer to just created bitmap device, which implements CFbsDrawDevice interface
127 @leave KErrNoMemory Not enough memory
128 KErrArgument Invalid aSize value
130 IMPORT_C static CFbsDrawDevice* NewBitmapDeviceL(const TSize& aSize, TDisplayMode aDispMode, TInt aDataStride);
133 Depending on current graphics hardware the method will return one of
134 two possible 16M video modes:
135 EColor16M or EColor16MU. If the hardware doesn't support EColor16M
136 or EColor16MU mode, the return value will be ENone.
138 @return EColor16M, EColor16MU or ENone.
139 ENone - it means that current hardware doesn't support 16M color mode.
141 IMPORT_C static TDisplayMode DisplayMode16M();
144 Return the display mode of the device.
147 virtual TDisplayMode DisplayMode() const = 0;
150 Scanline width in pixels.
151 The return value can be greater or equal than iSize.iWidth, because
152 the scan line memory is allocated in 32-bit words and can be rounded up, if
153 the display mode allows more than 1 pixel to be stored in a single byte.
154 @return The (adjusted) width in pixels.
156 virtual TInt LongWidth() const = 0;
159 Alter the colours within a defined rectangle according to the supplied mapping.
160 The colour map is supplied as pairs of TRgb objects. One member of the pair defines a colour value
161 to match, the other defines a colour to replace that value by.
162 Note that, for comparison purposes, smaller gamuts (e.g. 64K colour) are mapped to TRgb form before
163 comparison, so a colour that is not representable in the current display mode will not be matched.
164 Pixels in the original that do not match an entry in the colour map are unchanged.
165 @param aRect Area of the device/bitmap to be mapped in logical coordinates
166 @param aColors Colour map. This should be provided as a set of TRgb pairs, one to be matched
167 and the other to provide a replacement.
168 @param aNumPairs Number of pairs of colours in aColors.
169 @param aMapForwards If ETrue, match the first colour of a pair and replace by the second, otherwise
170 match the second and replace by the first.
171 @panic EScreenDriverPanicOutOfBounds if aRect transforms back to illegal physical coordinates.
172 @panic EScreenDriverPanicNullPointer if aColors == NULL
173 @panic EScreenDriverPanicZeroLength if aNumPairs == 0
175 virtual void MapColors(const TRect& aRect,const TRgb* aColors,TInt aNumPairs,TBool aMapForwards) = 0;
178 Reads a line of aLength pixels starting at [aX, aY] (in logical coordinates). The direction of reading
179 is affected by the current orientation, and the "stride" taken in sampling pixels is affected by
180 any scaling currently in force. Pixels are converted (if necessary) to the form specified by
181 aDispMode before being written to the buffer. The entire line to be read must be within the
182 physical bounds of the bitmap or device
183 @param aX X coordinate of the pixel to start reading from (logical coordinates)
184 @param aY Y coordinate of the pixel to start reading from(logical coordinates)
185 @param aLength Number of pixels to read
186 @param aBuffer Buffer to receive the pixel data (must be large enough)
187 @param aDispMode Format to use for writing pixels into the buffer.
188 @panic EScreenDriverPanicOutOfBounds if either end of the line is out of bounds
189 @panic EScreenDriverPanicNullPointer if aBuffer == NULL
190 @panic EScreenDriverPanicZeroLength if aLength == 0
192 virtual void ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer,TDisplayMode aDispMode) const = 0;
195 Get the colour of the pixel at the logical position [aX,aY]
196 @param aX X-coordinate of pixel to read (logical coordinates)
197 @param aY Y-coordinate of pixel to read (logical coordinates)
198 @return The colour pf the pixel at [aX,aY]
199 @panic EScreenDriverPanicOutOfBounds if [aX,aY] transforms back to illegal physical coordinates.
201 virtual TRgb ReadPixel(TInt aX,TInt aY) const = 0;
204 Returns a pointer to a buffer large enough to read a line of pixels of maximum length. Ownership of
205 the buffer is retained by the bitmap or device object. Repeated calls to this function will return
207 @return A pointer to a scan line buffer
209 virtual TUint32* ScanLineBuffer() const = 0;
212 Scanline width in bytes. The return value may be greater than the actual number of bytes needed
213 to store the pixels, since scan line memory is allocated in 32-bit words and can be rounded up.
214 @return The (adjusted) width in bytes.
216 virtual TInt ScanLineBytes() const = 0;
219 Return the display mode to be used when passing pixel data to the device using the scanline buffer.
221 @see CFbsDrawDevice::DisplayMode
223 virtual TDisplayMode ScanLineDisplayMode() const = 0;
226 Returns the screen size in pixels, taking the orientation into account.
227 Always prefer GetDrawRect() to SizeInPixels() call.
228 GetDrawRect() will take into account possible non-[0,0] top-left corner of the drawing
229 rectangle if the device is scaled.
230 @return TSize Screen size in pixels
232 virtual TSize SizeInPixels() const = 0;
235 Allows the caller to calculate the physical size of a bitmap on the current hardware
236 by calculating how many twips a 1000-pixel wide bitmap would be. Only applicable to
237 screen-based devices; bitmap devices return 0.
238 @return Twips per 1000 pixels
240 virtual TInt HorzTwipsPerThousandPixels() const = 0;
243 Allows the caller to calculate the physical size of a bitmap on the current hardware
244 by calculating how many twips a 1000-pixel high bitmap would be. Only applicable to
245 screen-based devices; bitmap devices return 0.
246 @return Twips per 1000 pixels
248 virtual TInt VertTwipsPerThousandPixels() const = 0;
251 Reports on which orientations are available on the device/bitmap.
252 @param aOrientation Array to receive the capability (use CFbsDrawDevice::TOrientation as an index)
254 virtual void OrientationsAvailable(TBool aOrientation[4]) = 0;
257 Set the orientation of the device
258 @param aOrientation Orientation to set
259 @return ETrue if the new orientation was set successfully, EFalse otherwise
261 virtual TBool SetOrientation(TOrientation aOrientation) = 0;
264 Combines the current content of the device/bitmap with a supplied colour, based on a bitmask and
265 a draw mode. The bitmask is supplied as an array of TUint32s, one for each line (so there should
266 be aHeight entries in the array). Since one word is used per line, aLength must be <= 32. Each bit
267 of the mask controls one pixel - if the bit is 1, the pixel is combined with aColor, if the bit
268 is 0, the pixel is left unchanged. Note that bits in the bitmask are examined in low-high order,
269 so bit0 affects the pixel at aX, bit1 affects the pixel at aX+1 and so forth.
270 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
271 @param aX Left edge of the rectangle (logical coordinates)
272 @param aY Top edge of the rectangle (logical coordinates)
273 @param aBuffer Array of bitmasks - one per line
274 @param aLength Width of the rectangle (must be >0 and <= 32)
275 @param aHeight Height of the rectangle (== number of entries in aBuffer)
276 @param aColor Colour to combine with the existing pixel data
277 @param aDrawMode Combination function for source and destination pixels.
278 @panic EScreenDriverPanicOutOfBounds If any part of the rectangle maps to an illegal physical coordinate
280 @panic EScreenDriverPanicNullPointer If aBuffer == NULL
281 @panic EScreenDriverPanicZeroLength If aLength <= 0
283 virtual void WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode) = 0;
286 Combines the current content of the device/bitmap with a supplied colour, based on a bitmask and
287 a draw mode. This function differs from WriteBinary, in that aLength can be greater than 32, and
288 the height is implicitly 1. aBuffer must contain sufficient elements to hold aLength bits
289 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
290 @param aX Starting X coordinate (logical coordinates)
291 @param aY Starting Y coordinate (logical coordinates)
292 @param aBuffer Array of bitmasks
293 @param aLength Number of pixels
294 @param aColor Colour to combine with existing pixels
295 @param aDrawMode Combination function for source and destination pixels.
296 @panic EScreenDriverPanicOutOfBounds If any part of the line maps to an illegal physical coordinate
297 @panic EScreenDriverPanicNullPointer If aBuffer == NULL
298 @panic EScreenDriverPanicZeroLength If aLength <= 0
301 virtual void WriteBinaryLine(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode) = 0;
304 Similar to WriteBinaryLine, but writes a vertical, rather than a horizontal line. LIne is drawn upward
305 (decreasing Y) if aUp == ETrue.
308 virtual void WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode,TBool aUp) = 0;
311 Write the given colour to the location [aX,aY], combining it with the existing pixel
313 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
314 @param aX X coordinate (logical coordinates)
315 @param aY Y coordinate (logical coordinates)
316 @param aColor Colour to write
317 @param aDrawMode Combination function for source and destination pixels.
318 @panic EScreenDriverPanicOutOfBounds If [aX,aY] maps to an illegal physical address
320 virtual void WriteRgb(TInt aX,TInt aY,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode) = 0;
323 Write the given colour to the rectangle [aX,aY] - [aX+aLength,aY+aHeight], combining it
324 with the exiasting pixels using aDrawMode
325 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
326 @param aX X coordinate (logical coordinates)
327 @param aY Y coordinate (logical coordinates)
328 @param aLength Width of the rectangle (logical coordinates)
329 @param aHeight Height of the rectangle (logical coordinates)
330 @param aColor Colour to write
331 @param aDrawMode Combination function for source and destination pixels.
332 @panic EScreenDriverPanicOutOfBounds If any part of the rectangle maps to an illegal physical address
334 virtual void WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode) = 0;
337 The method performs an alpha blending of the source data - aRgbBuffer and screen pixels, using
338 the data from aMaskBuffer buffer as an alpha blending factor.
339 The formula used for that, is:
340 (C1 * A + C2 * (255 - A)) / 255, where:
341 - C1 - a pixel from aRgbBuffer;
342 - C2 - a pixel from the sceen;
343 - A - a pixel from aMaskBuffer;
344 The content of source and mask buffers is preserved.
345 The calculated alpha blended pixel is written to the destination - the screen or a bitmap.
346 If the shadowing/fading flag is set, a shadow/fade copy of the source bitmap will be used.
347 @param aX Logical X coordinate of the start of the line.
348 @param aY Logical Y coordinate of the line.
349 @param aLength Source data - length in pixels.
350 @param aRgbBuffer A pointer to a line of the source bitmap data.
351 Must be in ERgb format.
352 @param aMaskBuffer Buffer containing the data which should be used as an
353 alpha blending factor. Must be in EGray256 format.
354 @param aDrawMode Combination function for source and destination pixels.
355 @panic EScreenDriverPanicOutOfBounds If any part of the line maps to an illegal physical address
357 virtual void WriteRgbAlphaLine(TInt aX,TInt aY,TInt aLength,TUint8* aRgbBuffer,TUint8* aMaskBuffer, CGraphicsContext::TDrawMode aDrawMode) = 0;
360 Combine the data in aBuffer with existing pixels along the line [aX,aY]-[aX+aLength,aY],
361 using aDrawMode as the combining function.
362 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
363 @param aX Logical X coordinate of the start of the line.
364 @param aY Logical Y coordinate of the line.
365 @param aLength Source data - length in pixels.
366 @param aBuffer Source data. Must be in the format returned by ScanLineDisplayMode().
367 @param aDrawMode Combination function for source and destination pixels.
368 @panic EScreenDriverPanicOutOfBounds If any part of the line maps to an illegal physical address
370 virtual void WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer,CGraphicsContext::TDrawMode aDrawMode) = 0;
374 Do any necessary initialisation on screen devices (default applies to bitmaps)
375 @return Success/failure code
377 virtual TInt InitScreen() {return(KErrNone);}
379 /** Sets or unsets auto-update for the screen.
381 @param aValue ETrue, if the screen is set to auto-update; EFalse, otherwise.
383 virtual void SetAutoUpdate(TBool aValue) {(void) aValue;} // To avoid compiler warning for unused parameter
386 Set the internal data buffer to point to the supplied buffer. No checks are made that the buffer
387 is appropriate for the purpose. Ownership is not taken.
388 @param aBits A buffer of sufficient size.
390 virtual void SetBits(TAny*) {}
393 Set up a custom palette for those bit formats that support palettised colour
394 @param aPalette Palette to use
395 @return Success/failure code
397 virtual TInt SetCustomPalette(const CPalette*) { return KErrNotSupported; }
400 Retrieve a custom palette, if the bit format supports it.
401 @param aPalette Pointer to a CPalette. The palette will be created by this function.
402 @return Success/failure code
404 virtual TInt GetCustomPalette(CPalette*&) { return KErrNotSupported; }
407 Copies all settings (scaling, orientation, etc.) from the supplied device
408 and reinitialised the current device.
409 @param aDrawDevice Device to get settings from
411 virtual void SetDisplayMode(CFbsDrawDevice*) {}
414 Set the origin point of the dither matrix (if appropriate)
415 @param aPoint Dither origin (logical coordiantes)
417 virtual void SetDitherOrigin(const TPoint&) {}
420 Sets the user display mode - used for certain colour mapping functions
422 virtual void SetUserDisplayMode(TDisplayMode) {}
425 Sets the current shadowing mode
428 virtual void SetShadowMode(TShadowMode) {}
431 Set the current fading parameters
432 @param aBlackMap Black point
433 @param aWhiteMap White point
435 virtual void SetFadingParameters(TUint8 /*aBlackMap*/,TUint8 /*aWhiteMap*/) {}
438 Apply shadow processing to all the pixels in the supplied rectangle
439 @param aRect Area to apply shadow processing to (logical coordinates)
440 @panic EScreenDriverPanicOutOfBounds If any part of the rectangle maps to an illegal physical address
442 virtual void ShadowArea(const TRect&) {} // Obeys shadow mode
445 Applies shadow processing to the supplied buffer
446 @param aLength Length of buffer in pixels
447 @param aBuffer Buffer to process in the format returned by ScanLineDisplayMode()
448 @panic EScreenDriverPanicZeroLength If aLength <= 0
449 @panic EScreenDriverPanicNullPointer If aBuffer == NULL
451 virtual void ShadowBuffer(TInt,TUint32*) {} // Obeys shadow mode
454 Update the screen with the update region.
456 virtual void Update() {}
459 Update the screen with the union of the update and specified regions.
460 @param aRegion Region to update (logical coordinates)
462 virtual void Update(const TRegion&) {}
465 Update the update region.
466 @param aRegion Region to update (logical coordinates)
468 virtual void UpdateRegion(const TRect&) {}
472 Blend aColor with the pixels along the line [aX,aY]-[aX+aLength,aY], using aMaskBuffer
474 If the shadowing/fading flag is set, a shadow/fade copy of the source bitmap will be used.
475 @param aX Logical X coordinate of the start of the line
476 @param aY Logical Y coordinate of the line.
477 @param aLength Length of line to modify
478 @param aColor Colour to blend with existing pixels
479 @param aMaskBuffer Buffer containing the data which should be used as an
480 alpha blending factor.
481 @panic EScreenDriverPanicOutOfBounds If any part of the line maps to an illegal physical address
483 virtual void WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer) = 0;
486 The method performs an alpha blending of the source data - aRgbBuffer1 and aBuffer2, using
487 the data from aMaskBuffer buffer as an alpha blending factor.
488 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
489 The formula used for that, is:
490 (C1 * A + C2 * (255 - A)) / 255, where:
491 - C1 - a pixel from aRgbBuffer1;
492 - C2 - a pixel from aBuffer2;
493 - A - a pixel from aMaskBuffer;
494 The content of source and mask buffers is preserved.
495 The calculated alpha blended pixel is written to the destination - the screen or a bitmap.
496 If the shadowing/fading flag is set, the resulting pixels will be shadowed/faded.
497 @param aX Logical X coordinate of the position in the target the result should be drawn to.
498 @param aY Logical Y coordinate of the position in the target the result should be drawn to.
499 @param aLength Source data - length in pixels.
500 @param aRgbBuffer1 A pointer to a line of the source bitmap data 1.
501 Must be in ERgb format.
502 @param aBuffer2 A pointer to a line of the source bitmap data 2.
503 Must be in the format returned by ScanLineDisplayMode().
504 @param aMaskBuffer Buffer containing the data which should be used as an
505 alpha blending factor. Must be in EGray256 format.
506 @param aDrawMode Drawing mode
508 virtual void WriteRgbAlphaLine(TInt aX,TInt aY,TInt aLength,
509 const TUint8* aRgbBuffer1,
510 const TUint8* aBuffer2,
511 const TUint8* aMaskBuffer,
512 CGraphicsContext::TDrawMode aDrawMode) = 0;
514 Retrieves a pointer to the specified CFbsDrawDevice interface extension.
515 @param aInterfaceId Interface identifier of the interface to be retrieved.
516 @param aInterface Address of pointer variable that retrieves the specified interface.
517 @return KErrNone If the interface is supported, KErrNotSupported otherwise.
518 @see BitDrawInterfaceId.h file for the IDs of supported interfaces
520 virtual TInt GetInterface(TInt aInterfaceId, TAny*& aInterface) = 0;
523 Gets logical coordinates of the drawing rectangle.
524 If the device is not scaled and with zero origin, logocal coordinates of
525 the drawing rectangle are the same as its physical coordinates.
526 If the device is rotated, drawing rectangle width and height are swapped.
527 Always prefer GetDrawRect() to SizeInPixels() call. SizeInPixels() will return
528 drawing rectangle width and height. But if the device is scaled or with nonzero origin,
529 GetDrawRect() will take into account and the top-left corner of the drawing rectangle too,
530 which may not be [0, 0].
531 @param aDrawRect Upon return aRect contains drawing rectangle logical coordinates.
533 virtual void GetDrawRect(TRect& aDrawRect) const = 0;
536 The method swaps bitmap device's width and height.
537 For example: if the size is (40, 20), the swapped size will be (20, 40).
538 The device's content is not preserved.
539 The method leaves CDrawBitmap object in a consistent state -
540 scaling settings will be set with their default values (the scaling is switched off),
541 iDitherOrigin will be set to (0,0), iOrigin to (0,0).
542 Note: This method is used internally by BITGDI component. Do not call it!
544 virtual void SwapWidthAndHeight() = 0;