|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbsplashscreen_p.h" |
|
27 #include <QPainter> |
|
28 #include <QImage> |
|
29 #include <QApplication> |
|
30 #include <QWidget> |
|
31 #include <QPixmap> |
|
32 |
|
33 // To play nice with GPU resources it may be beneficial to avoid using QWidget |
|
34 // for showing the splash screen. (each top-level widget results in creating a |
|
35 // new window surface which consumes gpu memory) Instead, we can create & show a |
|
36 // CCoeControl which draws using the traditional Symbian GC methods. (And thus |
|
37 // uses the "legacy" surface which is still available currently. However if some |
|
38 // day it is removed then this solution will not work anymore.) |
|
39 #ifdef Q_OS_SYMBIAN |
|
40 // Do not enable for now, may cause some flickering. |
|
41 // The system transition effects may not like this solution anyway. |
|
42 //#define HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
43 #endif |
|
44 |
|
45 #ifdef HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
46 #include <coecntrl.h> |
|
47 #include <fbs.h> |
|
48 #include <w32std.h> |
|
49 #endif |
|
50 |
|
51 /*! |
|
52 \class HbSplashScreen |
|
53 |
|
54 \brief Shows a splash screen suitable for the current application, if available. |
|
55 |
|
56 \internal |
|
57 */ |
|
58 |
|
59 class HbSplashScreenInterface |
|
60 { |
|
61 public: |
|
62 virtual void start(HbSplash::Flags flags) = 0; |
|
63 virtual void release() = 0; |
|
64 }; |
|
65 |
|
66 class HbSplashScreenGeneric : public QWidget, public HbSplashScreenInterface |
|
67 { |
|
68 public: |
|
69 HbSplashScreenGeneric(); |
|
70 ~HbSplashScreenGeneric(); |
|
71 |
|
72 void start(HbSplash::Flags flags); |
|
73 void release(); |
|
74 |
|
75 private: |
|
76 void paintEvent(QPaintEvent *event); |
|
77 void repaint(); |
|
78 |
|
79 uchar *mImageData; |
|
80 QPixmap mContents; |
|
81 }; |
|
82 |
|
83 #ifdef HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
84 |
|
85 class HbSplashScreenSymbian : public CCoeControl, public HbSplashScreenInterface |
|
86 { |
|
87 public: |
|
88 HbSplashScreenSymbian(); |
|
89 ~HbSplashScreenSymbian(); |
|
90 |
|
91 void start(HbSplash::Flags flags); |
|
92 void release(); |
|
93 |
|
94 private: |
|
95 void Draw(const TRect &rect) const; |
|
96 |
|
97 CFbsBitmap *mContents; |
|
98 }; |
|
99 |
|
100 #endif // HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
101 |
|
102 static HbSplashScreenInterface *splashScreen = 0; |
|
103 |
|
104 void HbSplashScreen::start(HbSplash::Flags flags) |
|
105 { |
|
106 if (!splashScreen) { |
|
107 splashScreen = |
|
108 #ifdef HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
109 new HbSplashScreenSymbian |
|
110 #else |
|
111 new HbSplashScreenGeneric |
|
112 #endif |
|
113 ; |
|
114 } |
|
115 splashScreen->start(flags); |
|
116 } |
|
117 |
|
118 void HbSplashScreen::destroy() |
|
119 { |
|
120 if (splashScreen) { |
|
121 splashScreen->release(); |
|
122 splashScreen = 0; |
|
123 } |
|
124 } |
|
125 |
|
126 bool HbSplashScreen::exists() |
|
127 { |
|
128 return splashScreen != 0; |
|
129 } |
|
130 |
|
131 HbSplashScreenGeneric::HbSplashScreenGeneric() |
|
132 : QWidget(0, Qt::SplashScreen), mImageData(0) |
|
133 { |
|
134 } |
|
135 |
|
136 HbSplashScreenGeneric::~HbSplashScreenGeneric() |
|
137 { |
|
138 delete mImageData; |
|
139 } |
|
140 |
|
141 void HbSplashScreenGeneric::release() |
|
142 { |
|
143 delete this; |
|
144 } |
|
145 |
|
146 void HbSplashScreenGeneric::start(HbSplash::Flags flags) |
|
147 { |
|
148 try { |
|
149 if (!mImageData) { |
|
150 int w, h, bpl; |
|
151 QImage::Format fmt; |
|
152 mImageData = HbSplash::load(w, h, bpl, fmt, flags); |
|
153 if (mImageData) { |
|
154 QImage img(mImageData, w, h, bpl, fmt); |
|
155 mContents = QPixmap::fromImage(img); |
|
156 resize(mContents.size()); |
|
157 } |
|
158 } |
|
159 if (!mContents.isNull()) { |
|
160 #ifdef HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
161 showFullScreen(); |
|
162 #else |
|
163 show(); |
|
164 #endif |
|
165 QApplication::processEvents(); |
|
166 QApplication::flush(); |
|
167 } |
|
168 } catch (const std::bad_alloc &) { |
|
169 } |
|
170 } |
|
171 |
|
172 void HbSplashScreenGeneric::paintEvent(QPaintEvent *event) |
|
173 { |
|
174 Q_UNUSED(event); |
|
175 QPainter painter(this); |
|
176 painter.drawPixmap(QPointF(0, 0), mContents); |
|
177 } |
|
178 |
|
179 void HbSplashScreenGeneric::repaint() |
|
180 { |
|
181 QWidget::repaint(); |
|
182 QApplication::flush(); |
|
183 } |
|
184 |
|
185 #ifdef HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |
|
186 |
|
187 HbSplashScreenSymbian::HbSplashScreenSymbian() |
|
188 : mContents(0) |
|
189 { |
|
190 } |
|
191 |
|
192 HbSplashScreenSymbian::~HbSplashScreenSymbian() |
|
193 { |
|
194 delete mContents; |
|
195 } |
|
196 |
|
197 void HbSplashScreenSymbian::release() |
|
198 { |
|
199 delete this; |
|
200 } |
|
201 |
|
202 static uchar *fbsBitmapAllocFunc(int w, int h, int bpl, QImage::Format fmt, void *param) |
|
203 { |
|
204 if (fmt != QImage::Format_ARGB32_Premultiplied) { |
|
205 qWarning("HbSplash: fbsBitmapAllocFunc: unsupported format %d", fmt); |
|
206 return 0; |
|
207 } |
|
208 TDisplayMode mode = EColor16MAP; |
|
209 CFbsBitmap *bmp = static_cast<CFbsBitmap *>(param); |
|
210 if (bmp->Create(TSize(w, h), mode) == KErrNone) { |
|
211 int bmpBpl = CFbsBitmap::ScanLineLength(w, mode); |
|
212 if (bpl == bmpBpl) { |
|
213 return reinterpret_cast<uchar *>(bmp->DataAddress()); |
|
214 } else { |
|
215 qWarning("HbSplash: fbsBitmapAllocFunc: bpl mismatch (%d - %d)", bpl, bmpBpl); |
|
216 } |
|
217 } else { |
|
218 qWarning("HbSplash: fbsBitmapAllocFunc: bitmap Create() failed"); |
|
219 } |
|
220 return 0; |
|
221 } |
|
222 |
|
223 void HbSplashScreenSymbian::start(HbSplash::Flags flags) |
|
224 { |
|
225 try { |
|
226 if (!mContents) { |
|
227 mContents = new CFbsBitmap; |
|
228 int w, h, bpl; |
|
229 QImage::Format fmt; |
|
230 if (HbSplash::load(w, h, bpl, fmt, flags, QString(), fbsBitmapAllocFunc, mContents)) { |
|
231 TRect rect(TPoint(0, 0), TSize(w, h)); |
|
232 TRAPD(err, { |
|
233 CreateWindowL(); |
|
234 RWindow *window = static_cast<RWindow *>(DrawableWindow()); |
|
235 window->SetSurfaceTransparency(ETrue); |
|
236 SetRect(rect); |
|
237 ActivateL(); }); |
|
238 if (err == KErrNone) { |
|
239 MakeVisible(ETrue); |
|
240 DrawNow(); |
|
241 } else { |
|
242 qWarning("HbSplash: symbian control init failed (%d)", err); |
|
243 } |
|
244 } else { |
|
245 delete mContents; |
|
246 mContents = 0; |
|
247 } |
|
248 } |
|
249 } catch (const std::bad_alloc &) { |
|
250 } |
|
251 } |
|
252 |
|
253 void HbSplashScreenSymbian::Draw(const TRect &rect) const |
|
254 { |
|
255 Q_UNUSED(rect); |
|
256 if (mContents) { |
|
257 SystemGc().BitBlt(TPoint(0, 0), mContents); |
|
258 } |
|
259 } |
|
260 |
|
261 #endif // HB_SPLASH_USE_SYMBIAN_LEGACY_SURFACE |