src/hbservers/hbsplashgenerator/hbsplashgen_server_symbian.cpp
changeset 5 627c4a0fd0e7
parent 3 11d3954df52a
child 23 e6ad4ef83b23
child 34 ed14f46c0e55
equal deleted inserted replaced
3:11d3954df52a 5:627c4a0fd0e7
    27 #include "hbsplashgenerator_p.h"
    27 #include "hbsplashgenerator_p.h"
    28 #include "hbsplashdirs_p.h"
    28 #include "hbsplashdirs_p.h"
    29 #include "hbsplashdefs_p.h"
    29 #include "hbsplashdefs_p.h"
    30 #include "hbsplashblacklist_p.h"
    30 #include "hbsplashblacklist_p.h"
    31 #include "hbsplash_direct_symbian_p.h"
    31 #include "hbsplash_direct_symbian_p.h"
       
    32 #include "hbsplashcompositor_p.h"
    32 #include <e32base.h>
    33 #include <e32base.h>
    33 #include <f32file.h>
    34 #include <f32file.h>
    34 #include <fbs.h>
    35 #include <fbs.h>
    35 #include <QDir>
    36 #include <QDir>
    36 #include <QList>
    37 #include <QList>
    52 }
    53 }
    53 
    54 
    54 CEikAppUi *HbSplashGenDocument::CreateAppUiL()
    55 CEikAppUi *HbSplashGenDocument::CreateAppUiL()
    55 {
    56 {
    56     qDebug() << PRE << "using custom appui";
    57     qDebug() << PRE << "using custom appui";
    57     return new (ELeave) HbSplashGenAppUi;
    58     return new(ELeave) HbSplashGenAppUi;
    58 }
    59 }
    59 
    60 
    60 CApaDocument *HbSplashGenApplication::CreateDocumentL()
    61 CApaDocument *HbSplashGenApplication::CreateDocumentL()
    61 {
    62 {
    62     return new (ELeave) HbSplashGenDocument(*this);
    63     return new(ELeave) HbSplashGenDocument(*this);
    63 }
    64 }
    64 
    65 
    65 class HbSplashGenServerSymbian : public CServer2
    66 class HbSplashGenServerSymbian : public CServer2
    66 {
    67 {
    67 public:
    68 public:
    68     HbSplashGenServerSymbian();
    69     HbSplashGenServerSymbian();
    69     ~HbSplashGenServerSymbian();
    70     ~HbSplashGenServerSymbian();
    70     CSession2 *NewSessionL(const TVersion &version, const RMessage2 &message) const;
    71     CSession2 *NewSessionL(const TVersion &version, const RMessage2 &message) const;
    71 
    72 
    72     void setSplashScreenDir(const QString &dir) { mSplashScreenDir = dir; }
    73     void setSplashScreenDir(const QString &dir) {
    73     void setSplashScreenDirContents(const QStringList &entries) { mSplashScreenDirEntries = entries; }
    74         mSplashScreenDir = dir;
    74     bool startupSuccess() const { return mStartupSuccess; }
    75     }
       
    76     void setSplashScreenDirContents(const QStringList &entries) {
       
    77         mSplashScreenDirEntries = entries;
       
    78     }
       
    79     bool startupSuccess() const {
       
    80         return mStartupSuccess;
       
    81     }
    75     void clearBitmapCache();
    82     void clearBitmapCache();
       
    83     void addCompositor(HbSplashCompositorInterface *compositor) {
       
    84         mCompositors.append(compositor);
       
    85     }
    76     bool processGetSplash(const RMessage2 &message);
    86     bool processGetSplash(const RMessage2 &message);
    77 
    87 
    78 private:
    88 private:
    79     bool completeGetSplash(const RMessage2 &message, const QString &fileName);
    89     struct BitmapCacheData {
    80     CFbsBitmap *getCachedBitmap(const QString &fileName) const;
    90         CFbsBitmap *mBitmap;
    81     void cacheBitmap(const QString &key, CFbsBitmap *bmp);
    91         int mExtraSplashFlags;
       
    92         Qt::Orientation mOrientation;
       
    93     };
       
    94 
       
    95     bool completeGetSplash(const RMessage2 &message, const QString &fileName, const QString &ori);
       
    96     void completeWithBitmap(const RMessage2 &message, const BitmapCacheData &data);
       
    97     const BitmapCacheData *getCachedBitmap(const QString &fileName) const;
       
    98     void cacheBitmap(const QString &key, const BitmapCacheData &data);
    82 
    99 
    83     bool mStartupSuccess;
   100     bool mStartupSuccess;
    84     RFs mFs;
   101     RFs mFs;
    85     QString mSplashScreenDir;
   102     QString mSplashScreenDir;
    86     QStringList mSplashScreenDirEntries;
   103     QStringList mSplashScreenDirEntries;
    87     QList< QPair<QString, CFbsBitmap *> > mBitmaps;
   104     QList< QPair<QString, BitmapCacheData> > mBitmaps;
       
   105     QList<HbSplashCompositorInterface *> mCompositors;
    88 };
   106 };
    89 
   107 
    90 class HbSplashGenServerSession : public CSession2
   108 class HbSplashGenServerSession : public CSession2
    91 {
   109 {
    92 public:
   110 public:
   114 HbSplashGenServer::~HbSplashGenServer()
   132 HbSplashGenServer::~HbSplashGenServer()
   115 {
   133 {
   116     delete mServer;
   134     delete mServer;
   117 }
   135 }
   118 
   136 
   119 void HbSplashGenServer::onOutputDirContentsUpdated(const QString &dir, const QStringList &entries)
   137 void HbSplashGenServer::onOutputDirContentsUpdated(const QString &dir,
       
   138         const QStringList &entries)
   120 {
   139 {
   121     qDebug() << PRE << "splash screen dir contents received" << dir;
   140     qDebug() << PRE << "splash screen dir contents received" << dir;
   122     qDebug() << PRE << entries;
   141     qDebug() << PRE << entries;
   123     mServer->setSplashScreenDir(dir);
   142     mServer->setSplashScreenDir(dir);
   124     mServer->setSplashScreenDirContents(entries);
   143     mServer->setSplashScreenDirContents(entries);
   130 }
   149 }
   131 
   150 
   132 bool HbSplashGenServer::startupSuccess() const
   151 bool HbSplashGenServer::startupSuccess() const
   133 {
   152 {
   134     return mServer->startupSuccess();
   153     return mServer->startupSuccess();
       
   154 }
       
   155 
       
   156 void HbSplashGenServer::addCompositor(HbSplashCompositorInterface *compositor)
       
   157 {
       
   158     mServer->addCompositor(compositor);
   135 }
   159 }
   136 
   160 
   137 HbSplashGenServerSymbian::HbSplashGenServerSymbian()
   161 HbSplashGenServerSymbian::HbSplashGenServerSymbian()
   138     : CServer2(CActive::EPriorityHigh)
   162     : CServer2(CActive::EPriorityHigh)
   139 {
   163 {
   160 {
   184 {
   161     mFs.Close();
   185     mFs.Close();
   162     clearBitmapCache();
   186     clearBitmapCache();
   163 }
   187 }
   164 
   188 
   165 CSession2 *HbSplashGenServerSymbian::NewSessionL(const TVersion &version, const RMessage2 &message) const
   189 CSession2 *HbSplashGenServerSymbian::NewSessionL(const TVersion &version,
       
   190         const RMessage2 &message) const
   166 {
   191 {
   167     Q_UNUSED(message);
   192     Q_UNUSED(message);
   168     TVersion v(hbsplash_version_major, hbsplash_version_minor, hbsplash_version_build);
   193     TVersion v(hbsplash_version_major, hbsplash_version_minor, hbsplash_version_build);
   169     if (!User::QueryVersionSupported(v, version)) {
   194     if (!User::QueryVersionSupported(v, version)) {
   170         User::Leave(KErrNotSupported);
   195         User::Leave(KErrNotSupported);
   171     }
   196     }
   172     return new (ELeave) HbSplashGenServerSession(const_cast<HbSplashGenServerSymbian *>(this));
   197     return new(ELeave) HbSplashGenServerSession(const_cast<HbSplashGenServerSymbian *>(this));
   173 }
   198 }
   174 
   199 
   175 void HbSplashGenServerSymbian::clearBitmapCache()
   200 void HbSplashGenServerSymbian::clearBitmapCache()
   176 {
   201 {
   177     for (int i = 0, ie = mBitmaps.count(); i != ie; ++i) {
   202     for (int i = 0, ie = mBitmaps.count(); i != ie; ++i) {
   178         delete mBitmaps.at(i).second;
   203         delete mBitmaps.at(i).second.mBitmap;
   179     }
   204     }
   180     mBitmaps.clear();
   205     mBitmaps.clear();
   181 }
   206 }
   182 
   207 
   183 CFbsBitmap *HbSplashGenServerSymbian::getCachedBitmap(const QString &fileName) const
   208 const HbSplashGenServerSymbian::BitmapCacheData *HbSplashGenServerSymbian::getCachedBitmap(
       
   209     const QString &fileName) const
   184 {
   210 {
   185     for (int i = 0, ie = mBitmaps.count(); i != ie; ++i) {
   211     for (int i = 0, ie = mBitmaps.count(); i != ie; ++i) {
   186         if (!mBitmaps.at(i).first.compare(fileName, Qt::CaseInsensitive)) {
   212         if (!mBitmaps.at(i).first.compare(fileName, Qt::CaseInsensitive)) {
   187             return mBitmaps.at(i).second;
   213             return &mBitmaps.at(i).second;
   188         }
   214         }
   189     }
   215     }
   190     return 0;
   216     return 0;
   191 }
   217 }
   192 
   218 
   193 void HbSplashGenServerSymbian::cacheBitmap(const QString &key, CFbsBitmap *bmp)
   219 void HbSplashGenServerSymbian::cacheBitmap(const QString &key, const BitmapCacheData &data)
   194 {
   220 {
   195     while (mBitmaps.count() >= bitmap_cache_limit) {
   221     while (mBitmaps.count() >= bitmap_cache_limit) {
   196         delete mBitmaps.at(0).second;
   222         delete mBitmaps.at(0).second.mBitmap;
   197         mBitmaps.removeAt(0);
   223         mBitmaps.removeAt(0);
   198     }
   224     }
   199     QPair<QString, CFbsBitmap *> entry(key, bmp);
   225     mBitmaps.append(QPair<QString, BitmapCacheData>(key, data));
   200     mBitmaps.append(entry);
   226 }
   201 }
   227 
   202 
   228 void HbSplashGenServerSymbian::completeWithBitmap(const RMessage2 &message,
   203 inline void completeWithBitmap(const RMessage2 &message, CFbsBitmap *bmp)
   229         const BitmapCacheData &data)
   204 {
   230 {
   205     TPckg<TInt> bmpHandle(bmp->Handle());
   231     foreach(HbSplashCompositorInterface * compositor, mCompositors) {
       
   232         compositor->composeToBitmap(data.mBitmap, data.mOrientation, data.mExtraSplashFlags);
       
   233     }
       
   234     TPckg<TInt> bmpHandle(data.mBitmap->Handle());
   206     message.Write(3, bmpHandle);
   235     message.Write(3, bmpHandle);
   207     message.Complete(KErrNone);
   236     message.Complete(KErrNone);
   208 }
   237 }
   209 
   238 
   210 bool HbSplashGenServerSymbian::completeGetSplash(const RMessage2 &message, const QString &fileName)
   239 bool HbSplashGenServerSymbian::completeGetSplash(const RMessage2 &message,
       
   240         const QString &fileName,
       
   241         const QString &ori)
   211 {
   242 {
   212     bool wantsBitmap = message.Function() == HbSplashSrvGetSplashData;
   243     bool wantsBitmap = message.Function() == HbSplashSrvGetSplashData;
   213     if (wantsBitmap) {
   244     if (wantsBitmap) {
   214         CFbsBitmap *cachedBitmap = getCachedBitmap(fileName);
   245         const BitmapCacheData *cachedBitmapData = getCachedBitmap(fileName);
   215         if (cachedBitmap) {
   246         if (cachedBitmapData) {
   216             qDebug() << PRE << "returning cached bitmap for" << fileName;
   247             qDebug() << PRE << "returning cached bitmap for" << fileName;
   217             completeWithBitmap(message, cachedBitmap);
   248             completeWithBitmap(message, *cachedBitmapData);
   218             return true;
   249             return true;
   219         }
   250         }
   220     }
   251     }
   221     QDir splashScreenDir(mSplashScreenDir);
   252     QDir splashScreenDir(mSplashScreenDir);
   222     QString nativeName = QDir::toNativeSeparators(splashScreenDir.filePath(fileName));
   253     QString nativeName = QDir::toNativeSeparators(splashScreenDir.filePath(fileName));
   223     qDebug() << PRE << "trying to read" << nativeName;
   254     qDebug() << PRE << "trying to read" << nativeName;
   224     TPtrC nativeNameDes(static_cast<const TUint16 *>(nativeName.utf16()), nativeName.length());
   255     TPtrC nativeNameDes(static_cast<const TUint16 *>(nativeName.utf16()), nativeName.length());
   225     RFile f;
   256     RFile f;
   226     if (f.Open(mFs, nativeNameDes, EFileRead | EFileShareReadersOrWriters) == KErrNone) {
   257     if (f.Open(mFs, nativeNameDes, EFileRead | EFileShareReadersOrWriters) == KErrNone) {
   227         if (wantsBitmap) {
   258         if (wantsBitmap) {
   228             CFbsBitmap *bmp = static_cast<CFbsBitmap *>(HbSplashDirectSymbian::load(&f, 0));
   259             BitmapCacheData data;
       
   260             data.mBitmap = static_cast<CFbsBitmap *>(
       
   261                                HbSplashDirectSymbian::load(&f, &data.mExtraSplashFlags));
   229             f.Close();
   262             f.Close();
   230             if (bmp) {
   263             if (data.mBitmap) {
   231                 cacheBitmap(fileName, bmp);
   264                 data.mOrientation = Qt::Vertical;
   232                 completeWithBitmap(message, bmp);
   265                 if (!ori.compare(QLatin1String("lsc"), Qt::CaseInsensitive)) {
       
   266                     data.mOrientation = Qt::Horizontal;
       
   267                 }
       
   268                 cacheBitmap(fileName, data);
       
   269                 completeWithBitmap(message, data);
   233             } else {
   270             } else {
   234                 qWarning() << PRE << "splash load failed";
   271                 qWarning() << PRE << "splash load failed";
   235                 return false;
   272                 return false;
   236             }
   273             }
   237         } else {
   274         } else {
   327         // to the generic one if needed.
   364         // to the generic one if needed.
   328         name = appSpecificName;
   365         name = appSpecificName;
   329         usingAppSpecific = true;
   366         usingAppSpecific = true;
   330     }
   367     }
   331 
   368 
   332     bool completed = completeGetSplash(message, name);
   369     bool completed = completeGetSplash(message, name, orientation);
   333     if (!completed) {
   370     if (!completed) {
   334         // If the screens are just being regenerated then there is a chance that
   371         // If the screens are just being regenerated then there is a chance that
   335         // the app-specific file is not yet ready but the generic one is already
   372         // the app-specific file is not yet ready but the generic one is already
   336         // there (and the directory listing checked before is out-of-date). So
   373         // there (and the directory listing checked before is out-of-date). So
   337         // try the generic file too.
   374         // try the generic file too.
   338         if (usingAppSpecific) {
   375         if (usingAppSpecific) {
   339             completed = completeGetSplash(message, genericName);
   376             completed = completeGetSplash(message, genericName, orientation);
   340         }
   377         }
   341         if (!completed) {
   378         if (!completed) {
   342             qWarning() << PRE << "could not complete getSplash request";
   379             qWarning() << PRE << "could not complete getSplash request";
   343             return false;
   380             return false;
   344         }
   381         }