src/hbservers/hbsplashgenerator/hbsplashindicompositor.cpp
changeset 30 80e4d18b72f5
parent 7 923ff622b8b9
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
    33 #include <QTimer>
    33 #include <QTimer>
    34 #include <QApplication>
    34 #include <QApplication>
    35 
    35 
    36 #ifdef Q_OS_SYMBIAN
    36 #ifdef Q_OS_SYMBIAN
    37 #include <fbs.h>
    37 #include <fbs.h>
       
    38 _LIT_SECURITY_POLICY_PASS(KRdPolicy); // all pass
       
    39 _LIT_SECURITY_POLICY_S0(KWrPolicy, hbsplash_server_uid3.iUid); // pass hbsplashgenerator only
    38 #endif
    40 #endif
    39 
    41 
    40 // The indicator compositor renders a part of the mainwindow (the
    42 // The indicator compositor renders a part of the mainwindow (the
    41 // statusbar) into an image from time to time. This pixel data is then
    43 // statusbar) into an image from time to time. This pixel data is then
    42 // copied over to the splash screen bitmap whenever a client requests
    44 // copied over to the splash screen bitmap whenever a client requests
    43 // a screen (except if the screen is marked having a non-standard
    45 // a screen (except if the screen is marked having a non-standard
    44 // (hidden or transparent) statusbar).
    46 // (hidden or transparent) statusbar).
    45 //
    47 //
    46 // This ensures that there will be relatively up-to-date indicators in
    48 // This ensures that there will be relatively up-to-date indicators in
    47 // the splash screens.
    49 // the splash screens.
       
    50 //
       
    51 // This module also publishes the global statusbar image that can be
       
    52 // accessed in other processes via HbGlobalStatusBar.
    48 
    53 
    49 HbSplashIndicatorCompositor::HbSplashIndicatorCompositor(HbSplashGenerator *gen)
    54 HbSplashIndicatorCompositor::HbSplashIndicatorCompositor(HbSplashGenerator *gen)
    50     : mGenerator(gen), mSleeping(false), mSignalsConnected(false)
    55     : mGenerator(gen), mSleeping(false), mSignalsConnected(false)
    51 {
    56 {
    52     // When the splash screens are regenerated the statusbar must be rendered
    57     // When the splash screens are regenerated the statusbar must be rendered
    62 
    67 
    63     // There must be no activity while the device is sleeping so listen to sleep
    68     // There must be no activity while the device is sleeping so listen to sleep
    64     // mode events too.
    69     // mode events too.
    65     HbSleepModeListener::instance(); // just to make sure it is created
    70     HbSleepModeListener::instance(); // just to make sure it is created
    66     QApplication::instance()->installEventFilter(this);
    71     QApplication::instance()->installEventFilter(this);
       
    72 
       
    73 #ifdef Q_OS_SYMBIAN
       
    74     // The statusbar images will also be stored as CFbsBitmap and the
       
    75     // handles will be published in P&S properties.
       
    76     mStatusBarBitmapPrt = mStatusBarBitmapLsc = 0;
       
    77     RProperty::Define(hbsplash_server_uid3, HbSplashSbBitmapPrtKey,
       
    78                       RProperty::EInt, KRdPolicy, KWrPolicy);
       
    79     RProperty::Define(hbsplash_server_uid3, HbSplashSbBitmapLscKey,
       
    80                       RProperty::EInt, KRdPolicy, KWrPolicy);
       
    81     mStatusBarBitmapHandlePropPrt.Attach(hbsplash_server_uid3, HbSplashSbBitmapPrtKey);
       
    82     mStatusBarBitmapHandlePropLsc.Attach(hbsplash_server_uid3, HbSplashSbBitmapLscKey);
       
    83 #endif
       
    84 }
       
    85 
       
    86 HbSplashIndicatorCompositor::~HbSplashIndicatorCompositor()
       
    87 {
       
    88 #ifdef Q_OS_SYMBIAN
       
    89     delete mStatusBarBitmapPrt;
       
    90     delete mStatusBarBitmapLsc;
       
    91     mStatusBarBitmapHandlePropPrt.Close();
       
    92     mStatusBarBitmapHandlePropLsc.Close();
       
    93 #endif
    67 }
    94 }
    68 
    95 
    69 void HbSplashIndicatorCompositor::release()
    96 void HbSplashIndicatorCompositor::release()
    70 {
    97 {
    71     delete this;
    98     delete this;
    89 
   116 
    90 void HbSplashIndicatorCompositor::queueRender(bool lazy)
   117 void HbSplashIndicatorCompositor::queueRender(bool lazy)
    91 {
   118 {
    92     // Compress subsequent change notifications into one update.
   119     // Compress subsequent change notifications into one update.
    93     if (!mRenderTimer->isActive() && !mSleeping) {
   120     if (!mRenderTimer->isActive() && !mSleeping) {
    94         mRenderTimer->start(lazy ? 10000 : 100); // 10 sec or 0.1 sec
   121         mRenderTimer->start(lazy ? 1500 : 100); // 1.5s if charging, 0.1s otherwise
    95     }
   122     }
    96 }
   123 }
    97 
   124 
    98 void HbSplashIndicatorCompositor::renderStatusBar()
   125 void HbSplashIndicatorCompositor::renderStatusBar()
    99 {
   126 {
   119         HbSplashGenerator::setStatusBarElementsVisible(mw, true);
   146         HbSplashGenerator::setStatusBarElementsVisible(mw, true);
   120         mw->setOrientation(Qt::Vertical, false);
   147         mw->setOrientation(Qt::Vertical, false);
   121         doRender(mw, &mStatusBarImagePrt, &mStatusBarRectPrt);
   148         doRender(mw, &mStatusBarImagePrt, &mStatusBarRectPrt);
   122         mw->setOrientation(Qt::Horizontal, false);
   149         mw->setOrientation(Qt::Horizontal, false);
   123         doRender(mw, &mStatusBarImageLsc, &mStatusBarRectLsc);
   150         doRender(mw, &mStatusBarImageLsc, &mStatusBarRectLsc);
       
   151 #ifdef Q_OS_SYMBIAN
       
   152         publishAsBitmap(mStatusBarImagePrt, &mStatusBarBitmapPrt, &mStatusBarBitmapHandlePropPrt);
       
   153         publishAsBitmap(mStatusBarImageLsc, &mStatusBarBitmapLsc, &mStatusBarBitmapHandlePropLsc);
       
   154 #endif
   124     } catch (const std::bad_alloc &) {
   155     } catch (const std::bad_alloc &) {
       
   156         qWarning("[hbsplashindicompositor] caught bad_alloc");
   125         mStatusBarImagePrt = mStatusBarImageLsc = QImage();
   157         mStatusBarImagePrt = mStatusBarImageLsc = QImage();
   126     }
   158     }
   127     mGenerator->unlockMainWindow();
   159     mGenerator->unlockMainWindow();
   128 }
   160 }
   129 
   161 
   181         mSleeping = false;
   213         mSleeping = false;
   182         queueRender();
   214         queueRender();
   183     }
   215     }
   184     return QObject::eventFilter(obj, event);
   216     return QObject::eventFilter(obj, event);
   185 }
   217 }
       
   218 
       
   219 #ifdef Q_OS_SYMBIAN
       
   220 void HbSplashIndicatorCompositor::publishAsBitmap(const QImage &image,
       
   221                                                   CFbsBitmap **bitmap,
       
   222                                                   RProperty *prop)
       
   223 {
       
   224     int w = image.width();
       
   225     int h = image.height();
       
   226     if (*bitmap) {
       
   227         TSize bitmapSize = (*bitmap)->SizeInPixels();
       
   228         if (bitmapSize.iWidth != w || bitmapSize.iHeight != h) {
       
   229             delete *bitmap;
       
   230             *bitmap = 0;
       
   231         }
       
   232     }
       
   233     if (!*bitmap) {
       
   234         *bitmap = new CFbsBitmap;
       
   235         if ((*bitmap)->Create(TSize(w, h), EColor16MAP) != KErrNone) {
       
   236             qWarning("[hbsplashindicompositor] bitmap Create() failed for size %dx%d", w, h);
       
   237             delete *bitmap;
       
   238             *bitmap = 0;
       
   239             return;
       
   240         }
       
   241     }
       
   242     uchar *dst = reinterpret_cast<uchar *>((*bitmap)->DataAddress());
       
   243     int dstBpl = CFbsBitmap::ScanLineLength(w, (*bitmap)->DisplayMode());
       
   244     const uchar *src = image.bits();
       
   245     int srcBpl = image.bytesPerLine();
       
   246     if (dstBpl == srcBpl) {
       
   247         qMemCopy(dst, src, h * srcBpl);
       
   248         prop->Set((*bitmap)->Handle());
       
   249     } else {
       
   250         qWarning("[hbsplashindicompositor] bpl mismatch (%d - %d)", srcBpl, dstBpl);
       
   251     }
       
   252 }
       
   253 #endif // Q_OS_SYMBIAN