Commit 402ac576ec951f68eb02787515bd1f87354c35eb

Fix compilation and remove trailing whitespace.

Fix compilation on systems that support the extended bitmap format.

Reviewed-by: Jani Hautakangas
  
6868/*!
6969 \since 4.6
7070
71 Symbian Font And Bitmap server client that is
71 Symbian Font And Bitmap server client that is
7272 used to lock the global bitmap heap. Only used in
7373 S60 v3.1 and S60 v3.2.
7474*/
7575class QSymbianFbsClient
7676{
7777public:
78
79 QSymbianFbsClient() : heapLock(0), heapLocked(false)
78
79 QSymbianFbsClient() : heapLock(0), heapLocked(false)
8080 {
8181 QT_TRAP_THROWING(heapLock = new(ELeave) CFbsBitmap);
82 heapLock->Create(TSize(0,0), S60->screenDevice()->DisplayMode());
82 heapLock->Create(TSize(0,0), S60->screenDevice()->DisplayMode());
8383 }
84
84
8585 ~QSymbianFbsClient()
8686 {
8787 delete heapLock;
8888 }
89
89
9090 bool lockHeap()
9191 {
9292 bool wasLocked = heapLocked;
93
93
9494 if (heapLock && !heapLocked) {
9595 heapLock->LockHeap(ETrue);
9696 heapLocked = true;
9797 }
98
98
9999 return wasLocked;
100100 }
101
101
102102 bool unlockHeap()
103103 {
104104 bool wasLocked = heapLocked;
105
105
106106 if (heapLock && heapLocked) {
107107 heapLock->UnlockHeap(ETrue);
108108 heapLocked = false;
109109 }
110
110
111111 return wasLocked;
112112 }
113
114
113
114
115115private:
116
116
117117 CFbsBitmap *heapLock;
118118 bool heapLocked;
119119};
156156
157157 bool heapWasLocked;
158158 QSysInfo::SymbianVersion symbianVersion;
159
160 explicit QSymbianBitmapDataAccess() : heapWasLocked(false)
159
160 explicit QSymbianBitmapDataAccess() : heapWasLocked(false)
161161 {
162162 symbianVersion = QSysInfo::symbianVersion();
163163 };
164
164
165165 ~QSymbianBitmapDataAccess() {};
166
166
167167 inline void beginDataAccess(CFbsBitmap *bitmap)
168168 {
169169 if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3)
171171 else
172172 bitmap->LockHeap(ETrue);
173173 }
174
174
175175 inline void endDataAccess(CFbsBitmap *bitmap)
176176 {
177177 if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3) {
182182 }
183183 }
184184};
185
186
185
186
187187#define UPDATE_BUFFER() \
188188 { \
189189 beginDataAccess(); \
194194static CFbsBitmap* createSymbianCFbsBitmap(const TSize& size, TDisplayMode mode)
195195{
196196 QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
197
197
198198 CFbsBitmap* bitmap = 0;
199199 QT_TRAP_THROWING(bitmap = new (ELeave) CFbsBitmap);
200
200
201201 if (bitmap->Create(size, mode) != KErrNone) {
202202 delete bitmap;
203203 bitmap = 0;
204204 }
205
205
206206 lock.relock();
207
207
208208 return bitmap;
209209}
210210
212212{
213213 if(bitmap->IsCompressedInRAM()) {
214214 QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
215
215
216216 CFbsBitmap *uncompressed = 0;
217217 QT_TRAP_THROWING(uncompressed = new (ELeave) CFbsBitmap);
218
218
219219 if (uncompressed->Create(bitmap->SizeInPixels(), bitmap->DisplayMode()) != KErrNone) {
220220 delete bitmap;
221221 bitmap = 0;
222222 lock.relock();
223
223
224224 return bitmap;
225225 }
226
226
227227 lock.relock();
228
228
229229 CBitmapContext *bitmapContext = 0;
230230 CFbsBitmapDevice* bitmapDevice = 0;
231231 QT_TRAP_THROWING(bitmapDevice = CFbsBitmapDevice::NewL(uncompressed));
235235 delete bitmapDevice;
236236 bitmap = 0;
237237 bitmapDevice = 0;
238
238
239239 lock.relock();
240
240
241241 return bitmap;
242242 }
243
243
244244 bitmapContext->DrawBitmap(TPoint(), bitmap);
245
245
246246 delete bitmapContext;
247247 delete bitmapDevice;
248
248
249249 return uncompressed;
250250 } else {
251251 return bitmap;
256256{
257257 CWsScreenDevice* screenDevice = S60->screenDevice();
258258 TSize screenSize = screenDevice->SizeInPixels();
259
259
260260 TSize srcSize;
261261 // Find out if this is one of our windows.
262262 QSymbianControl *sControl;
270270 y += relativePos.iY;
271271 srcSize = winId->Size();
272272 }
273
273
274274 TRect srcRect(TPoint(x, y), srcSize);
275275 // Clip to the screen
276276 srcRect.Intersection(TRect(screenSize));
277
277
278278 if (w > 0 && h > 0) {
279279 TRect subRect(TPoint(x, y), TSize(w, h));
280280 // Clip to the subRect
281281 srcRect.Intersection(subRect);
282282 }
283
283
284284 if (srcRect.IsEmpty())
285285 return QPixmap();
286
286
287287 CFbsBitmap* temporary = createSymbianCFbsBitmap(srcRect.Size(), screenDevice->DisplayMode());
288
288
289289 QPixmap pix;
290
290
291291 if (temporary && screenDevice->CopyScreenToBitmap(temporary, srcRect) == KErrNone) {
292 pix = QPixmap::fromSymbianCFbsBitmap(temporary);
292 pix = QPixmap::fromSymbianCFbsBitmap(temporary);
293293 }
294
294
295295 delete temporary;
296296 return pix;
297297}
320320 Creates \c CFbsBitmap that is equivalent to the QPixmap, based on
321321 the given \a mode. If the creation then this function returns 0.
322322
323 It is the caller's responsibility to release the \c CFbsBitmap data
323 It is the caller's responsibility to release the \c CFbsBitmap data
324324 after use either by deleting the bitmap or calling \c Reset().
325325
326326 \warning On S60 3.1 and S60 3.2 conversion mode will always be CopyData
332332CFbsBitmap *QPixmap::toSymbianCFbsBitmap(ConversionMode mode) const
333333{
334334 QS60PixmapData *s60data = static_cast<QS60PixmapData *>(data.data());
335
335
336336 if (isNull() || !s60data->cfbsBitmap)
337337 return 0;
338
338
339339 bool convertToArgb32 = false;
340
340
341341 QSysInfo::SymbianVersion symbianVersion = QSysInfo::symbianVersion();
342342 if (symbianVersion == QSysInfo::SV_9_2 || symbianVersion == QSysInfo::SV_9_3) {
343 // Convert argb32_premultiplied to argb32 since Symbian 9.2 and Symbian 9.3 do
343 // Convert argb32_premultiplied to argb32 since Symbian 9.2 and Symbian 9.3 do
344344 // not support premultipied format.
345
345
346346 if (s60data->image.format() == QImage::Format_ARGB32_Premultiplied) {
347347 mode = CopyData;
348348 convertToArgb32 = true;
349349 }
350350 }
351
351
352352 CFbsBitmap *bitmap = 0;
353
353
354354 TDisplayMode displayMode = s60data->cfbsBitmap->DisplayMode();
355
355
356356 if(displayMode == EGray2) {
357357 //Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
358358 //So invert mono bitmaps so that masks work correctly.
359359 s60data->image.invertPixels();
360360 mode = CopyData;
361361 }
362
362
363363 if (mode == CopyData) {
364364 QImage source;
365
365
366366 if (convertToArgb32) {
367367 source = s60data->image.convertToFormat(QImage::Format_ARGB32);
368368 displayMode = EColor16MA;
369369 } else {
370370 source = s60data->image;
371371 }
372
372
373373 CFbsBitmap *newBitmap = createSymbianCFbsBitmap(TSize(source.width(), source.height()), displayMode);
374374 const uchar *sptr = source.bits();
375375 s60data->symbianBitmapDataAccess->beginDataAccess(newBitmap);
376
376
377377 uchar *dptr = (uchar*)newBitmap->DataAddress();
378378 Mem::Copy(dptr, sptr, source.numBytes());
379
379
380380 s60data->symbianBitmapDataAccess->endDataAccess(newBitmap);
381
381
382382 bitmap = newBitmap;
383383 } else {
384
384
385385 QT_TRAP_THROWING(bitmap = new (ELeave) CFbsBitmap);
386
386
387387 TInt err = bitmap->Duplicate(s60data->cfbsBitmap->Handle());
388388 if (err != KErrNone) {
389389 qWarning("Could not duplicate CFbsBitmap");
391391 bitmap = 0;
392392 }
393393 }
394
394
395395 if(displayMode == EGray2) {
396396 // restore pixels
397397 s60data->image.invertPixels();
398398 }
399
399
400400 return bitmap;
401401}
402402
404404 \fn QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap, ConversionMode mode)
405405 \since 4.6
406406
407 Creates a QPixmap from native \c CFbsBitmap \a bitmap. The conversion
407 Creates a QPixmap from native \c CFbsBitmap \a bitmap. The conversion
408408 is based on the specified \a mode. Conversion mode is always QPixmap::CopyData
409 if given \a bitmap does not have display mode of TDisplayMode::EGray2,
410 \c TDisplayMode::EColor16MU or \c TDisplayMode::EColor16MAP.
411
409 if given \a bitmap does not have display mode of TDisplayMode::EGray2,
410 \c TDisplayMode::EColor16MU or \c TDisplayMode::EColor16MAP.
411
412412 If the CFbsBitmap is not valid this function will return a null QPixmap.
413413
414414 \warning This function is only available on Symbian OS.
418418QPixmap QPixmap::fromSymbianCFbsBitmap(CFbsBitmap *bitmap, ConversionMode mode)
419419{
420420 if (bitmap) {
421
421
422422 bool deleteSourceBitmap = false;
423
424#if Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE
425
423
424#ifdef Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE
425
426426 // Rasterize extended bitmaps
427
428 TUid extendedBitmapType = = bitmap->ExtendedBitmapType();
427
428 TUid extendedBitmapType = bitmap->ExtendedBitmapType();
429429 if (extendedBitmapType != KNullUid) {
430430 CFbsBitmap *rasterBitmap = createSymbianCFbsBitmap(bitmap->SizeInPixels(), EColor16MA);
431
431
432432 CFbsBitmapDevice *rasterBitmapDev = 0;
433433 QT_TRAP_THROWING(rasterBitmapDev = CFbsBitmapDevice::NewL(rasterBitmap));
434
434
435435 CFbsBitGc *rasterBitmapGc = 0;
436436 TInt err = rasterBitmapDev->CreateContext(rasterBitmapGc);
437437 if (err != KErrNone) {
440440 rasterBitmapDev = 0;
441441 return QPixmap();
442442 }
443
443
444444 rasterBitmapGc->BitBlt(TPoint( 0, 0), bitmap);
445
445
446446 bitmap = rasterBitmap;
447
447
448448 delete rasterBitmapDev;
449449 delete rasterBitmapGc;
450
450
451451 rasterBitmapDev = 0;
452452 rasterBitmapGc = 0;
453
453
454454 deleteSourceBitmap = true;
455455 }
456#endif
457
458
456#endif
457
458
459459 deleteSourceBitmap = bitmap->IsCompressedInRAM();
460460 CFbsBitmap *sourceBitmap = uncompress(bitmap);
461
461
462462 TDisplayMode displayMode = sourceBitmap->DisplayMode();
463463 QImage::Format format = qt_TDisplayMode2Format(displayMode);
464
464
465465 QImage::Format opaqueFormat = QNativeImage::systemFormat();
466466 QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
467
467
468468 if (format != opaqueFormat && format != alphaFormat && format != QImage::Format_MonoLSB)
469469 mode = CopyData;
470470
471
471
472472 QPixmapData::PixelType type = (format!=QImage::Format_MonoLSB)
473473 ? QPixmapData::PixmapType
474474 : QPixmapData::BitmapType;
475
475
476476 QS60PixmapData *pixmapData = 0;
477
477
478478 if (mode == CopyData) {
479
479
480480 TSize size = sourceBitmap->SizeInPixels();
481
481
482482 QSymbianBitmapDataAccess da;
483483 da.beginDataAccess(sourceBitmap);
484484 uchar *bytes = (uchar*)sourceBitmap->DataAddress();
485485 QImage img = QImage(bytes, size.iWidth, size.iHeight, format);
486486 da.endDataAccess(sourceBitmap);
487
487
488488 pixmapData = new QS60PixmapData(type);
489489 pixmapData->fromImage(img, Qt::AutoColor);
490
490
491491 if(deleteSourceBitmap)
492492 delete sourceBitmap;
493
493
494494 if(displayMode == EGray2) {
495495 //Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
496496 //So invert mono bitmaps so that masks work correctly.
499499 } else {
500500 CFbsBitmap* duplicate = 0;
501501 QT_TRAP_THROWING(duplicate = new (ELeave) CFbsBitmap);
502
502
503503 TInt err = duplicate->Duplicate(sourceBitmap->Handle());
504504 if (err != KErrNone) {
505505 qWarning("Could not duplicate CFbsBitmap");
506
506
507507 if(deleteSourceBitmap)
508508 delete sourceBitmap;
509
509
510510 delete duplicate;
511511 return QPixmap();
512512 }
513
513
514514 pixmapData = new QS60PixmapData(type);
515515 pixmapData->fromSymbianBitmap(duplicate);
516
516
517517 if(deleteSourceBitmap)
518518 delete sourceBitmap;
519519 }
520
520
521521 return QPixmap(pixmapData);
522522 }
523
523
524524 return QPixmap();
525525}
526526
546546 w = width;
547547 h = height;
548548 is_null = true;
549
549
550550 release();
551551 return;
552552 } else if (!cfbsBitmap) {
554554 if (pixelType() == BitmapType)
555555 mode = EGray2;
556556 else
557 mode = EColor16MU;
558
557 mode = EColor16MU;
558
559559 CFbsBitmap* bitmap = createSymbianCFbsBitmap(TSize(width, height), mode);
560560 fromSymbianBitmap(bitmap);
561561 } else {
562
562
563563 TSize newSize(width, height);
564
564
565565 if(cfbsBitmap->SizeInPixels() != newSize) {
566566 cfbsBitmap->Resize(TSize(width, height));
567567 if(pengine) {
569569 pengine = 0;
570570 }
571571 }
572
572
573573 UPDATE_BUFFER();
574574 }
575575}
595595 delete cfbsBitmap;
596596 lock.relock();
597597 }
598
598
599599 delete pengine;
600600 image = QImage();
601601 cfbsBitmap = 0;
611611void QS60PixmapData::fromSymbianBitmap(CFbsBitmap* bitmap)
612612{
613613 cfbsBitmap = bitmap;
614
614
615615 if(!initSymbianBitmapContext()) {
616616 qWarning("Could not create CBitmapContext");
617617 release();
618618 return;
619619 }
620
620
621621 setSerialNumber(cfbsBitmap->Handle());
622
622
623623 UPDATE_BUFFER();
624
624
625625 // Create default palette if needed
626626 if (cfbsBitmap->DisplayMode() == EGray2) {
627627 image.setNumColors(2);
628628 image.setColor(0, QColor(Qt::color0).rgba());
629629 image.setColor(1, QColor(Qt::color1).rgba());
630
630
631631 //Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
632632 //So invert mono bitmaps so that masks work correctly.
633633 image.invertPixels();
644644void QS60PixmapData::fromImage(const QImage &img, Qt::ImageConversionFlags flags)
645645{
646646 QImage sourceImage;
647
647
648648 if (pixelType() == BitmapType) {
649649 sourceImage = img.convertToFormat(QImage::Format_MonoLSB);
650650 } else {
653653 ? img.convertToFormat(QImage::Format_ARGB32_Premultiplied)
654654 : img.convertToFormat(QImage::Format_RGB32);
655655 } else {
656
656
657657 QImage::Format opaqueFormat = QNativeImage::systemFormat();
658658 QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
659
659
660660 if (!img.hasAlphaChannel()
661661 || ((flags & Qt::NoOpaqueDetection) == 0
662662 && !const_cast<QImage &>(img).data_ptr()->checkForAlphaPixels())) {
666666 }
667667 }
668668 }
669
670
669
670
671671 QImage::Format destFormat = sourceImage.format();
672672 TDisplayMode mode;
673673 switch (destFormat) {
693693 qWarning("Image format not supported: %d", image.format());
694694 return;
695695 }
696
696
697697 cfbsBitmap = createSymbianCFbsBitmap(TSize(sourceImage.width(), sourceImage.height()), mode);
698698 if (!(cfbsBitmap && initSymbianBitmapContext())) {
699699 qWarning("Could not create CFbsBitmap and/or CBitmapContext");
700700 release();
701701 return;
702702 }
703
703
704704 setSerialNumber(cfbsBitmap->Handle());
705
705
706706 const uchar *sptr = const_cast<const QImage &>(sourceImage).bits();
707707 symbianBitmapDataAccess->beginDataAccess(cfbsBitmap);
708708 uchar *dptr = (uchar*)cfbsBitmap->DataAddress();
709709 Mem::Copy(dptr, sptr, sourceImage.numBytes());
710 symbianBitmapDataAccess->endDataAccess(cfbsBitmap);
711
710 symbianBitmapDataAccess->endDataAccess(cfbsBitmap);
711
712712 UPDATE_BUFFER();
713
713
714714 if (destFormat == QImage::Format_MonoLSB) {
715715 image.setNumColors(2);
716716 image.setColor(0, QColor(Qt::color0).rgba());
717 image.setColor(1, QColor(Qt::color1).rgba());
717 image.setColor(1, QColor(Qt::color1).rgba());
718718 } else {
719719 image.setColorTable(sourceImage.colorTable());
720720 }
726726 QBitmap::fromImage(data->toImage().copy(rect));
727727 return;
728728 }
729
729
730730 const QS60PixmapData *s60Data = static_cast<const QS60PixmapData*>(data);
731
731
732732 resize(rect.width(), rect.height());
733733 cfbsBitmap->SetDisplayMode(s60Data->cfbsBitmap->DisplayMode());
734
734
735735 bitmapContext->BitBlt(TPoint(0, 0), s60Data->cfbsBitmap, qt_QRect2TRect(rect));
736736}
737737
811811 } else {
812812 const int w = image.width();
813813 const int h = image.height();
814
814
815815 const QImage imageMask = mask.toImage().convertToFormat(QImage::Format_MonoLSB);
816816 QImage newImage = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
817817 for (int y = 0; y < h; ++y) {
853853{
854854 if(!cfbsBitmap)
855855 return;
856
856
857857 symbianBitmapDataAccess->beginDataAccess(cfbsBitmap);
858
858
859859 uchar* newBytes = (uchar*)cfbsBitmap->DataAddress();
860
860
861861 if (newBytes == bytes)
862862 return;
863
864
863
864
865865 bytes = newBytes;
866866 TDisplayMode mode = cfbsBitmap->DisplayMode();
867867 QImage::Format format = qt_TDisplayMode2Format(mode);
868868 TSize size = cfbsBitmap->SizeInPixels();
869
869
870870 QVector<QRgb> savedColorTable;
871871 if (!image.isNull())
872872 savedColorTable = image.colorTable();
873
873
874874 image = QImage(bytes, size.iWidth, size.iHeight, format);
875
875
876876 // Restore the palette or create a default
877877 if (!savedColorTable.isEmpty()) {
878878 image.setColorTable(savedColorTable);
879879 }
880
880
881881 w = size.iWidth;
882882 h = size.iHeight;
883883 d = image.depth();
884884 is_null = (w <= 0 || h <= 0);
885
885
886886 if (pengine) {
887887 QS60PaintEngine *engine = static_cast<QS60PaintEngine *>(pengine);
888888 engine->prepare(&image);
893893{
894894 if(!cfbsBitmap)
895895 return;
896
896
897897 symbianBitmapDataAccess->endDataAccess(cfbsBitmap);
898898}
899899