Qt 4.8
qbbrootwindow.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion <blackberry-qt@qnx.com>
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qbbrootwindow.h"
43 
44 #include "qbbscreen.h"
45 
46 #include <QtCore/QUuid>
47 
48 #if defined(QBBROOTWINDOW_DEBUG)
49 #include <QtCore/QDebug>
50 #endif
51 
52 #include <errno.h>
53 #include <unistd.h>
54 
55 static const int MAGIC_ZORDER_FOR_NO_NAV = 10;
56 
58  : m_screen(screen),
59  m_window(0),
60  m_windowGroupName()
61 {
62 #if defined(QBBROOTWINDOW_DEBUG)
63  qDebug() << Q_FUNC_INFO;
64 #endif
65  // Create one top-level QNX window to act as a container for child windows
66  // since navigator only supports one application window
67  errno = 0;
68  int result = screen_create_window(&m_window, m_screen->nativeContext());
69  int val[2];
70  if (result != 0) {
71  qFatal("QBBRootWindow: failed to create window, errno=%d", errno);
72  }
73 
74  // Move window to proper display
75  errno = 0;
76  screen_display_t display = m_screen->nativeDisplay();
77  result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display);
78  if (result != 0) {
79  qFatal("QBBRootWindow: failed to set window display, errno=%d", errno);
80  }
81 
82  // Make sure window is above navigator but below keyboard if running as root
83  // since navigator won't automatically set our z-order in this case
84  if (getuid() == 0) {
85  errno = 0;
86  val[0] = MAGIC_ZORDER_FOR_NO_NAV;
87  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, val);
88  if (result != 0) {
89  qFatal("QBBRootWindow: failed to set window z-order, errno=%d", errno);
90  }
91  }
92 
93  // Window won't be visible unless it has some buffers so make one dummy buffer that is 1x1
94  errno = 0;
95  val[0] = SCREEN_USAGE_NATIVE;
96  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, val);
97  if (result != 0) {
98  qFatal("QBBRootWindow: failed to set window buffer usage, errno=%d", errno);
99  }
100 
101  errno = 0;
102  val[0] = m_screen->nativeFormat();
103  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val);
104  if (result != 0) {
105  qFatal("QBBRootWindow: failed to set window pixel format, errno=%d", errno);
106  }
107 
108  errno = 0;
109  val[0] = 1;
110  val[1] = 1;
111  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val);
112  if (result != 0) {
113  qFatal("QBBRootWindow: failed to set window buffer size, errno=%d", errno);
114  }
115 
116  errno = 0;
117  result = screen_create_window_buffers(m_window, 1);
118  if (result != 0) {
119  qFatal("QBB: failed to create window buffer, errno=%d", errno);
120  }
121 
122  // Window is always the size of the display
123  errno = 0;
124  QRect geometry = m_screen->geometry();
125  val[0] = geometry.width();
126  val[1] = geometry.height();
127  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val);
128  if (result != 0) {
129  qFatal("QBBRootWindow: failed to set window size, errno=%d", errno);
130  }
131 
132  // Fill the window with solid black
133  errno = 0;
134  val[0] = 0;
135  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_COLOR, val);
136  if (result != 0) {
137  qFatal("QBBRootWindow: failed to set window colour, errno=%d", errno);
138  }
139 
140  // Make the window opaque
141  errno = 0;
142  val[0] = SCREEN_TRANSPARENCY_NONE;
143  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, val);
144  if (result != 0) {
145  qFatal("QBBRootWindow: failed to set window transparency, errno=%d", errno);
146  }
147 
148  // Set the swap interval to 1
149  errno = 0;
150  val[0] = 1;
151  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, val);
152  if (result != 0) {
153  qFatal("QBBRootWindow: failed to set window swap interval, errno=%d", errno);
154  }
155 
156  // Set viewport size equal to window size but move outside buffer so the fill colour is used exclusively
157  errno = 0;
158  val[0] = geometry.width();
159  val[1] = geometry.height();
160  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val);
161  if (result != 0) {
162  qFatal("QBBRootWindow: failed to set window source size, errno=%d", errno);
163  }
164 
165  errno = 0;
166  val[0] = 1;
167  val[1] = 0;
168  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_POSITION, val);
169  if (result != 0) {
170  qFatal("QBBRootWindow: failed to set window source position, errno=%d", errno);
171  }
172 
174  post();
175 }
176 
178 {
179  // Cleanup top-level QNX window
180  screen_destroy_window(m_window);
181 }
182 
184 {
185 #if defined(QBBROOTWINDOW_DEBUG)
186  qDebug() << Q_FUNC_INFO;
187 #endif
188  errno = 0;
189  screen_buffer_t buffer;
190  int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&buffer);
191  if (result != 0) {
192  qFatal("QBBRootWindow: failed to query window buffer, errno=%d", errno);
193  }
194 
195  errno = 0;
196  int dirtyRect[] = {0, 0, 1, 1};
197  result = screen_post_window(m_window, buffer, 1, dirtyRect, 0);
198  if (result != 0) {
199  qFatal("QBB: failed to post window buffer, errno=%d", errno);
200  }
201 }
202 
204 {
205 #if defined(QBBROOTWINDOW_DEBUG)
206  qDebug() << Q_FUNC_INFO;
207 #endif
208  // Force immediate display update
209  errno = 0;
210  int result = screen_flush_context(m_screen->nativeContext(), 0);
211  if (result != 0) {
212  qFatal("QBBRootWindow: failed to flush context, errno=%d", errno);
213  }
214 }
215 
216 void QBBRootWindow::setRotation(int rotation)
217 {
218 #if defined(QBBROOTWINDOW_DEBUG)
219  qDebug() << Q_FUNC_INFO << "angle =" << rotation;
220 #endif
221  errno = 0;
222  int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ROTATION, &rotation);
223  if (result != 0) {
224  qFatal("QBBRootWindow: failed to set window rotation, errno=%d", errno);
225  }
226 }
227 
228 void QBBRootWindow::resize(const QSize &size)
229 {
230  errno = 0;
231  int val[] = {size.width(), size.height()};
232  int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val);
233  if (result != 0) {
234  qFatal("QBBRootWindow: failed to set window size, errno=%d", errno);
235  }
236 
237  errno = 0;
238  result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val);
239  if (result != 0) {
240  qFatal("QBBRootWindow: failed to set window source size, errno=%d", errno);
241  }
242 
243  // NOTE: display will update when child windows relayout and repaint
244 }
245 
247 {
248  // Generate a random window group name
250 
251  // Create window group so child windows can be parented by container window
252  errno = 0;
253  int result = screen_create_window_group(m_window, m_windowGroupName.constData());
254  if (result != 0) {
255  qFatal("QBBRootWindow: failed to create app window group, errno=%d", errno);
256  }
257 }
int nativeFormat() const
Definition: qbbscreen.h:71
QByteArray m_windowGroupName
Definition: qbbrootwindow.h:76
screen_context_t nativeContext() const
Definition: qbbscreen.h:73
static QUuid createUuid()
On any platform other than Windows, this function returns a new UUID with variant QUuid::DCE and vers...
Definition: quuid.cpp:897
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
void flush() const
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void post() const
QString toString() const
Returns the string representation of this QUuid.
Definition: quuid.cpp:512
void resize(const QSize &size)
Q_CORE_EXPORT void qDebug(const char *,...)
int width() const
Returns the width.
Definition: qsize.h:126
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
virtual QRect geometry() const
Reimplement in subclass to return the pixel geometry of the screen.
Definition: qbbscreen.h:63
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
screen_display_t nativeDisplay() const
Definition: qbbscreen.h:72
Q_CORE_EXPORT void qFatal(const char *,...)
QBBScreen * m_screen
Definition: qbbrootwindow.h:74
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setRotation(int rotation)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
screen_window_t m_window
Definition: qbbrootwindow.h:75
void createWindowGroup()
QBBRootWindow(QBBScreen *screen)
static const int MAGIC_ZORDER_FOR_NO_NAV
int errno
#define Q_FUNC_INFO
Definition: qglobal.h:1871