[844] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
| 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qpixmapdata_vg_p.h"
|
---|
| 43 | #include "qvgfontglyphcache_p.h"
|
---|
| 44 | #include <private/qt_s60_p.h>
|
---|
| 45 |
|
---|
| 46 | #include <fbs.h>
|
---|
| 47 | #include <bitdev.h>
|
---|
| 48 |
|
---|
| 49 | #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE
|
---|
| 50 | # include <sgresource/sgimage.h>
|
---|
| 51 | # ifdef SYMBIAN_FBSERV_GLYPHDATA // defined in fbs.h
|
---|
| 52 | # define QT_SYMBIAN_HARDWARE_GLYPH_CACHE
|
---|
| 53 | # include <graphics/fbsglyphdataiterator.h>
|
---|
| 54 | # include <private/qfontengine_s60_p.h>
|
---|
| 55 | # endif
|
---|
| 56 | #endif
|
---|
| 57 |
|
---|
| 58 | QT_BEGIN_NAMESPACE
|
---|
| 59 |
|
---|
| 60 | typedef VGImage (*_vgCreateEGLImageTargetKHR)(VGeglImageKHR);
|
---|
| 61 | static _vgCreateEGLImageTargetKHR qt_vgCreateEGLImageTargetKHR = 0;
|
---|
| 62 |
|
---|
| 63 | namespace QVG
|
---|
| 64 | {
|
---|
| 65 | VGImage vgCreateEGLImageTargetKHR(VGeglImageKHR eglImage);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | VGImage QVG::vgCreateEGLImageTargetKHR(VGeglImageKHR eglImage)
|
---|
| 69 | {
|
---|
| 70 | if (!qt_vgCreateEGLImageTargetKHR && QEgl::hasExtension("EGL_KHR_image"))
|
---|
| 71 | qt_vgCreateEGLImageTargetKHR = (_vgCreateEGLImageTargetKHR) eglGetProcAddress("vgCreateEGLImageTargetKHR");
|
---|
| 72 |
|
---|
| 73 | return qt_vgCreateEGLImageTargetKHR ? qt_vgCreateEGLImageTargetKHR(eglImage) : 0;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | extern int qt_vg_pixmap_serial;
|
---|
| 77 |
|
---|
| 78 | static CFbsBitmap* createBlitCopy(CFbsBitmap* bitmap)
|
---|
| 79 | {
|
---|
| 80 | CFbsBitmap *copy = q_check_ptr(new CFbsBitmap);
|
---|
| 81 | if(!copy)
|
---|
| 82 | return 0;
|
---|
| 83 |
|
---|
| 84 | if (copy->Create(bitmap->SizeInPixels(), bitmap->DisplayMode()) != KErrNone) {
|
---|
| 85 | delete copy;
|
---|
| 86 | copy = 0;
|
---|
| 87 |
|
---|
| 88 | return 0;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | CFbsBitmapDevice* bitmapDevice = 0;
|
---|
| 92 | CFbsBitGc *bitmapGc = 0;
|
---|
| 93 | QT_TRAP_THROWING(bitmapDevice = CFbsBitmapDevice::NewL(copy));
|
---|
| 94 | QT_TRAP_THROWING(bitmapGc = CFbsBitGc::NewL());
|
---|
| 95 | bitmapGc->Activate(bitmapDevice);
|
---|
| 96 |
|
---|
| 97 | bitmapGc->BitBlt(TPoint(), bitmap);
|
---|
| 98 |
|
---|
| 99 | delete bitmapGc;
|
---|
| 100 | delete bitmapDevice;
|
---|
| 101 |
|
---|
| 102 | return copy;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | #ifdef QT_SYMBIAN_SUPPORTS_SGIMAGE
|
---|
| 106 | static VGImage sgImageToVGImage(QEglContext *context, const RSgImage &sgImage)
|
---|
| 107 | {
|
---|
| 108 | // when "0" used as argument then
|
---|
| 109 | // default display, context are used
|
---|
| 110 | if (!context)
|
---|
| 111 | context = qt_vg_create_context(0, QInternal::Pixmap);
|
---|
| 112 |
|
---|
| 113 | VGImage vgImage = VG_INVALID_HANDLE;
|
---|
| 114 |
|
---|
| 115 | if (sgImage.IsNull())
|
---|
| 116 | return vgImage;
|
---|
| 117 |
|
---|
| 118 | const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE};
|
---|
| 119 | EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(),
|
---|
| 120 | EGL_NO_CONTEXT,
|
---|
| 121 | EGL_NATIVE_PIXMAP_KHR,
|
---|
| 122 | (EGLClientBuffer)&sgImage,
|
---|
| 123 | (EGLint*)KEglImageAttribs);
|
---|
| 124 |
|
---|
| 125 | if (!eglImage)
|
---|
| 126 | return vgImage;
|
---|
| 127 |
|
---|
| 128 | vgImage = QVG::vgCreateEGLImageTargetKHR(eglImage);
|
---|
| 129 |
|
---|
| 130 | QEgl::eglDestroyImageKHR(QEgl::display(), eglImage);
|
---|
| 131 | return vgImage;
|
---|
| 132 | }
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
| 135 | void QVGPixmapData::cleanup()
|
---|
| 136 | {
|
---|
| 137 | is_null = w = h = 0;
|
---|
| 138 | recreate = false;
|
---|
| 139 | source = QImage();
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void QVGPixmapData::fromNativeType(void* pixmap, NativeType type)
|
---|
| 143 | {
|
---|
| 144 | if (type == QPixmapData::SgImage && pixmap) {
|
---|
| 145 | #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL)
|
---|
| 146 | RSgImage *sgImage = reinterpret_cast<RSgImage*>(pixmap);
|
---|
| 147 | destroyImages();
|
---|
| 148 | prevSize = QSize();
|
---|
| 149 |
|
---|
| 150 | VGImage vgImage = sgImageToVGImage(context, *sgImage);
|
---|
| 151 | if (vgImage != VG_INVALID_HANDLE) {
|
---|
| 152 | w = vgGetParameteri(vgImage, VG_IMAGE_WIDTH);
|
---|
| 153 | h = vgGetParameteri(vgImage, VG_IMAGE_HEIGHT);
|
---|
| 154 | d = 32; // We always use ARGB_Premultiplied for VG pixmaps.
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | is_null = (w <= 0 || h <= 0);
|
---|
| 158 | source = QImage(); // vgGetImageSubData() some day?
|
---|
| 159 | recreate = false;
|
---|
| 160 | prevSize = QSize(w, h);
|
---|
| 161 | //setSerialNumber(++qt_vg_pixmap_serial);
|
---|
| 162 | #endif
|
---|
| 163 | } else if (type == QPixmapData::FbsBitmap) {
|
---|
| 164 | CFbsBitmap *bitmap = reinterpret_cast<CFbsBitmap*>(pixmap);
|
---|
| 165 |
|
---|
| 166 | bool deleteSourceBitmap = false;
|
---|
| 167 | #ifdef Q_SYMBIAN_HAS_EXTENDED_BITMAP_TYPE
|
---|
| 168 |
|
---|
| 169 | // Rasterize extended bitmaps
|
---|
| 170 |
|
---|
| 171 | TUid extendedBitmapType = bitmap->ExtendedBitmapType();
|
---|
| 172 | if (extendedBitmapType != KNullUid) {
|
---|
| 173 | bitmap = createBlitCopy(bitmap);
|
---|
| 174 | deleteSourceBitmap = true;
|
---|
| 175 | }
|
---|
| 176 | #endif
|
---|
| 177 |
|
---|
| 178 | if (bitmap->IsCompressedInRAM()) {
|
---|
| 179 | bitmap = createBlitCopy(bitmap);
|
---|
| 180 | deleteSourceBitmap = true;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | TDisplayMode displayMode = bitmap->DisplayMode();
|
---|
| 184 | QImage::Format format = qt_TDisplayMode2Format(displayMode);
|
---|
| 185 |
|
---|
| 186 | TSize size = bitmap->SizeInPixels();
|
---|
| 187 | int bytesPerLine = bitmap->ScanLineLength(size.iWidth, displayMode);
|
---|
| 188 |
|
---|
| 189 | bitmap->BeginDataAccess();
|
---|
| 190 | uchar *bytes = (uchar*)bitmap->DataAddress();
|
---|
| 191 | QImage img = QImage(bytes, size.iWidth, size.iHeight, bytesPerLine, format);
|
---|
| 192 | img = img.copy();
|
---|
| 193 | bitmap->EndDataAccess();
|
---|
| 194 |
|
---|
| 195 | if(displayMode == EGray2) {
|
---|
| 196 | //Symbian thinks set pixels are white/transparent, Qt thinks they are foreground/solid
|
---|
| 197 | //So invert mono bitmaps so that masks work correctly.
|
---|
| 198 | img.invertPixels();
|
---|
| 199 | } else if(displayMode == EColor16M) {
|
---|
| 200 | img = img.rgbSwapped(); // EColor16M is BGR
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | fromImage(img, Qt::AutoColor);
|
---|
| 204 |
|
---|
| 205 | if(deleteSourceBitmap)
|
---|
| 206 | delete bitmap;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 | void* QVGPixmapData::toNativeType(NativeType type)
|
---|
| 211 | {
|
---|
| 212 | if (type == QPixmapData::SgImage) {
|
---|
| 213 | #if defined(QT_SYMBIAN_SUPPORTS_SGIMAGE) && !defined(QT_NO_EGL)
|
---|
| 214 | toVGImage();
|
---|
| 215 |
|
---|
| 216 | if (!isValid() || vgImage == VG_INVALID_HANDLE)
|
---|
| 217 | return 0;
|
---|
| 218 |
|
---|
| 219 | TInt err = 0;
|
---|
| 220 |
|
---|
| 221 | RSgDriver driver;
|
---|
| 222 | err = driver.Open();
|
---|
| 223 | if (err != KErrNone)
|
---|
| 224 | return 0;
|
---|
| 225 |
|
---|
| 226 | TSgImageInfo sgInfo;
|
---|
| 227 | sgInfo.iPixelFormat = EUidPixelFormatARGB_8888_PRE;
|
---|
| 228 | sgInfo.iSizeInPixels.SetSize(w, h);
|
---|
| 229 | sgInfo.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
|
---|
| 230 |
|
---|
| 231 | QScopedPointer<RSgImage> sgImage(new RSgImage());
|
---|
| 232 | err = sgImage->Create(sgInfo, NULL, NULL);
|
---|
| 233 | if (err != KErrNone) {
|
---|
| 234 | driver.Close();
|
---|
| 235 | return 0;
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | const EGLint KEglImageAttribs[] = {EGL_IMAGE_PRESERVED_SYMBIAN, EGL_TRUE, EGL_NONE};
|
---|
| 239 | EGLImageKHR eglImage = QEgl::eglCreateImageKHR(QEgl::display(),
|
---|
| 240 | EGL_NO_CONTEXT,
|
---|
| 241 | EGL_NATIVE_PIXMAP_KHR,
|
---|
| 242 | (EGLClientBuffer)sgImage.data(),
|
---|
| 243 | (EGLint*)KEglImageAttribs);
|
---|
| 244 | if (!eglImage || eglGetError() != EGL_SUCCESS) {
|
---|
| 245 | sgImage->Close();
|
---|
| 246 | driver.Close();
|
---|
| 247 | return 0;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | VGImage dstVgImage = QVG::vgCreateEGLImageTargetKHR(eglImage);
|
---|
| 251 | if (!dstVgImage || vgGetError() != VG_NO_ERROR) {
|
---|
| 252 | QEgl::eglDestroyImageKHR(QEgl::display(), eglImage);
|
---|
| 253 | sgImage->Close();
|
---|
| 254 | driver.Close();
|
---|
| 255 | return 0;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | vgCopyImage(dstVgImage, 0, 0,
|
---|
| 259 | vgImage, 0, 0,
|
---|
| 260 | w, h, VG_FALSE);
|
---|
| 261 |
|
---|
| 262 | if (vgGetError() != VG_NO_ERROR) {
|
---|
| 263 | sgImage->Close();
|
---|
| 264 | sgImage.reset();
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | // release stuff
|
---|
| 268 | vgDestroyImage(dstVgImage);
|
---|
| 269 | QEgl::eglDestroyImageKHR(QEgl::display(), eglImage);
|
---|
| 270 | driver.Close();
|
---|
| 271 | return reinterpret_cast<void*>(sgImage.take());
|
---|
| 272 | #endif
|
---|
| 273 | } else if (type == QPixmapData::FbsBitmap) {
|
---|
| 274 | CFbsBitmap *bitmap = q_check_ptr(new CFbsBitmap);
|
---|
| 275 |
|
---|
| 276 | if (bitmap) {
|
---|
| 277 | if (bitmap->Create(TSize(source.width(), source.height()),
|
---|
| 278 | EColor16MAP) == KErrNone) {
|
---|
| 279 | const uchar *sptr = const_cast<const QImage&>(source).bits();
|
---|
| 280 | bitmap->BeginDataAccess();
|
---|
| 281 |
|
---|
| 282 | uchar *dptr = (uchar*)bitmap->DataAddress();
|
---|
| 283 | Mem::Copy(dptr, sptr, source.byteCount());
|
---|
| 284 |
|
---|
| 285 | bitmap->EndDataAccess();
|
---|
| 286 | } else {
|
---|
| 287 | delete bitmap;
|
---|
| 288 | bitmap = 0;
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | return reinterpret_cast<void*>(bitmap);
|
---|
| 293 | }
|
---|
| 294 | return 0;
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | QSymbianVGFontGlyphCache::QSymbianVGFontGlyphCache() : QVGFontGlyphCache()
|
---|
| 298 | {
|
---|
| 299 | #ifdef QT_SYMBIAN_HARDWARE_GLYPH_CACHE
|
---|
| 300 | invertedGlyphs = true;
|
---|
| 301 | #endif
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | void QSymbianVGFontGlyphCache::cacheGlyphs(QVGPaintEnginePrivate *d,
|
---|
| 305 | QFontEngine *fontEngine,
|
---|
| 306 | const glyph_t *g, int count)
|
---|
| 307 | {
|
---|
| 308 | #ifdef QT_SYMBIAN_HARDWARE_GLYPH_CACHE
|
---|
| 309 | QFontEngineS60 *s60fontEngine = static_cast<QFontEngineS60*>(fontEngine);
|
---|
| 310 | if (s60fontEngine->m_activeFont->TypeUid() != KCFbsFontUid)
|
---|
| 311 | return QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count);
|
---|
| 312 |
|
---|
| 313 | QVector<glyph_t> uncachedGlyphs;
|
---|
| 314 | while (count-- > 0) {
|
---|
| 315 | // Skip this glyph if we have already cached it before.
|
---|
| 316 | glyph_t glyph = *g++;
|
---|
| 317 | if (((glyph < 256) && ((cachedGlyphsMask[glyph / 32] & (1 << (glyph % 32))) != 0))
|
---|
| 318 | || cachedGlyphs.contains(glyph))
|
---|
| 319 | continue;
|
---|
| 320 | if (!uncachedGlyphs.contains(glyph))
|
---|
| 321 | uncachedGlyphs.append(glyph);
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | if (!uncachedGlyphs.isEmpty()) {
|
---|
| 325 | CFbsFont *cfbsFont = static_cast<CFbsFont *>(s60fontEngine->m_activeFont);
|
---|
| 326 | RFbsGlyphDataIterator iter;
|
---|
| 327 |
|
---|
| 328 | int err = iter.Open(*cfbsFont, (const unsigned int*)uncachedGlyphs.constData(), uncachedGlyphs.count());
|
---|
| 329 |
|
---|
| 330 | if (err == KErrNotSupported || err == KErrInUse) { // Fallback in possibly supported error cases
|
---|
| 331 | iter.Close();
|
---|
| 332 | qWarning("Falling back to default QVGFontGlyphCache");
|
---|
| 333 | return QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | for (; err == KErrNone; err = iter.Next()) {
|
---|
| 337 | const unsigned int glyph = iter.GlyphCode();
|
---|
| 338 |
|
---|
| 339 | const RSgImage& image = iter.Image();
|
---|
| 340 | const TOpenFontCharMetrics& metrics = iter.Metrics();
|
---|
| 341 |
|
---|
| 342 | TRect glyphBounds;
|
---|
| 343 | metrics.GetHorizBounds(glyphBounds);
|
---|
| 344 | VGImage vgImage = sgImageToVGImage(0, image);
|
---|
| 345 | VGfloat origin[2];
|
---|
| 346 | VGfloat escapement[2];
|
---|
| 347 | origin[0] = -glyphBounds.iTl.iX;
|
---|
| 348 | origin[1] = glyphBounds.iBr.iY;
|
---|
| 349 | escapement[0] = 0;
|
---|
| 350 | escapement[1] = 0;
|
---|
| 351 | vgSetGlyphToImage(font, glyph, vgImage, origin, escapement);
|
---|
| 352 | vgDestroyImage(vgImage);
|
---|
| 353 |
|
---|
| 354 | // Add to cache
|
---|
| 355 | if (glyph < 256)
|
---|
| 356 | cachedGlyphsMask[glyph / 32] |= (1 << (glyph % 32));
|
---|
| 357 | else
|
---|
| 358 | cachedGlyphs.insert(glyph);
|
---|
| 359 | }
|
---|
| 360 | iter.Close();
|
---|
| 361 |
|
---|
| 362 | if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
|
---|
| 363 | qWarning("Not enough memory to cache glyph");
|
---|
| 364 | else if (err != KErrNotFound)
|
---|
| 365 | qWarning("Received error %d from glyph cache", err);
|
---|
| 366 | }
|
---|
| 367 | #else
|
---|
| 368 | QVGFontGlyphCache::cacheGlyphs(d, fontEngine, g, count);
|
---|
| 369 | #endif
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | QT_END_NAMESPACE
|
---|