LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BootupAnimation.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef BOOTUPANIMATION_H
23 #define BOOTUPANIMATION_H
24 
25 #include "Common.h"
26 
27 #include <glib.h>
28 #include <vector>
29 #include <string>
30 #include <QObject>
31 #include <QWidget>
32 #include <QPointer>
33 #include <QGraphicsObject>
34 #include <QPropertyAnimation>
35 #include <QParallelAnimationGroup>
36 #include <QTextLayout>
37 #include <QSocketNotifier>
38 
39 
40 #define BOOT_ANIM_MESSAGE_LENGHT (int)(sizeof(char) + 2 * sizeof(int))
41 #define BOOT_ANIM_MESSAGE_END_ANIMATION 0x01
42 #define BOOT_ANIM_MESSAGE_START_PROGRESS 0x02
43 #define BOOT_ANIM_MESSAGE_END_PROGRESS 0x03
44 #define BOOT_ANIM_MESSAGE_PROGRESS_UPDATE 0x04
45 
46 extern int bootAnimPipeFd;
47 extern pid_t bootAnimPid;
48 
49 class PGSurface;
50 class PGContext;
51 class PGFont;
52 class PGFallbackFonts;
53 
54 class BootupAnimation : public QObject
55 {
56  Q_OBJECT
57  //Q_PROPERTY(qreal glowOpacity READ glowOpacity WRITE setGlowOpacity)
58  //Q_PROPERTY(int spinnerProgress READ spinnerProgress WRITE setSpinnerProgress)
59 
60 public:
61  // static functions invoked by the main process to communicate with the Animation Process
62  static void stopBootupAnimation();
63  static void startActivityAnimation();
64  static void stopActivityAnimation();
65  static void setActivityAnimationProgress(int val, int total);
66 
67 public:
68 
69  BootupAnimation(int readPipeFd);
71 
72  void start();
73 
74 
75 protected:
76  void paintEvent(QPaintEvent *event);
77  void paint(QPainter* painter);
78 
79 private Q_SLOTS:
80  void pipeDataAvailable(int pipe);
81 
82 private:
83 
84  void init();
85  void deinit();
86 
87  void generateUtf16AndGlyphOffsets();
88  std::vector<gunichar2> convertToUtf16(const std::string& s) const;
89  std::vector<int> getGlyphOffsets(const std::vector<gunichar2>& s, int height) const;
90 
91  void updateScreen(PGSurface* surf);
92  void updateScreen(PGSurface* surf, int dx, int dy, int dr, int db);
93 
94  int spinnerProgress() { return m_activitySpinner; }
95  void setSpinnerProgress(int progress) { m_activitySpinner = progress; }
96 
97  void stop();
98 
99  void startActivity();
100  void stopActivity();
101 
102  void setActivityProgress(int val, int total);
103 
104  void renderInStateLogo();
105  void renderInStateActivity();
106 
107  static gpointer renderThread(gpointer arg);
108  void renderThread();
109 
110 private:
111 
112  enum State {
113  StateIdle,
114  StateLogo,
115  StateActivity
116  };
117 
118  GThread* m_renderThread;
119 
120  State m_state;
121  PGContext* m_ctxt;
122  PGFont* m_font;
123  PGFallbackFonts* m_fallbackFonts;
124  PGSurface* m_logoSurf;
125  PGSurface* m_logoBrightSurf;
126  PGSurface* m_activityStaticSurf;
127  PGSurface* m_activityProgressSurf;
128  PGSurface* m_activitySpinnerSurf;
129 
130  int m_readPipeFd;
131  QSocketNotifier m_readNotifier;
132 
133  int m_textHeight1;
134  int m_textHeight2;
135 
136 
137  float m_logoScale;
138  int m_logoAlpha;
139  int m_uiFrame;
140  int m_uiAlpha;
141  float m_uiScale;
142  int m_activityProgress;
143  int m_activitySpinner;
144  int m_rotation;
145 
146  std::vector<gunichar2> m_textLine1;
147  std::vector<gunichar2> m_textLine2;
148  std::vector<int> m_glyphOffsetsLine1;
149  std::vector<int> m_glyphOffsetsLine2;
150  int m_widthLine1;
151  int m_widthLine2;
152 
153 };
154 
155 // ====================================================================
156 // animation transition class used by the SysMgr process to simulate the animation animation fade when the bootup process is done.
157 
158 
160 {
161  Q_OBJECT
162 
163 public:
164 
167 
168  void start();
169  void stop();
170 
171  QRectF boundingRect() const;
172  virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
173 
174 private Q_SLOTS:
175  void fadeAnimationFinished();
176 
177 private:
178 
179  void init();
180  void deinit();
181 
182 private:
183  QRect m_bounds;
184  QPixmap* m_screenPixmap;
185  int m_rotation;
186 
187  QPointer<QPropertyAnimation> m_opacityAnimationPtr;
188  QPointer<QPropertyAnimation> m_scaleAnimationPtr;
189  QPointer<QParallelAnimationGroup> m_fadeAnimationGroupPtr;
190 };
191 
192 
193 
194 
195 #endif /* BOOTUPANIMATION_H */