Qt 4.8
pvreglwindowsurface.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
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 "pvreglwindowsurface.h"
43 #include "pvreglscreen.h"
44 #include <QScreen>
45 #include <QDebug>
46 #include <QWSDisplay>
47 
49  (QWidget *widget, PvrEglScreen *screen, int screenNum)
50  : QWSGLWindowSurface(widget)
51 {
52  setSurfaceFlags(QWSWindowSurface::Opaque);
53 
54  this->widget = widget;
55  this->screen = screen;
56  this->pdevice = 0;
57 
58  QPoint pos = offset(widget);
59  QSize size = widget->size();
60 
61  PvrQwsRect pvrRect;
62  pvrRect.x = pos.x();
63  pvrRect.y = pos.y();
64  pvrRect.width = size.width();
65  pvrRect.height = size.height();
66  transformRects(&pvrRect, 1);
67 
68  // Try to recover a previous PvrQwsDrawable object for the widget
69  // if there is one. This can happen when a PvrEglWindowSurface
70  // is created for a widget, bound to a EGLSurface, and then destroyed.
71  // When a new PvrEglWindowSurface is created for the widget, it will
72  // pick up the previous PvrQwsDrawable if the EGLSurface has not been
73  // destroyed in the meantime.
74  drawable = pvrQwsFetchWindow((long)widget);
75  if (drawable)
76  pvrQwsSetGeometry(drawable, &pvrRect);
77  else
78  drawable = pvrQwsCreateWindow(screenNum, (long)widget, &pvrRect);
79  pvrQwsSetRotation(drawable, screen->transformation());
80 }
81 
84 {
86  drawable = 0;
87  widget = 0;
88  screen = 0;
89  pdevice = 0;
90 }
91 
93 {
94  // Release the PvrQwsDrawable. If it is bound to an EGLSurface,
95  // then it will stay around until a new PvrEglWindowSurface is
96  // created for the widget. If it is not bound to an EGLSurface,
97  // it will be destroyed immediately.
100 
101  delete pdevice;
102 }
103 
105 {
106  return (widget != 0);
107 }
108 
110 {
111  if (drawable) {
112  // XXX: adjust for the screen offset.
113  PvrQwsRect pvrRect;
114  pvrRect.x = rect.x();
115  pvrRect.y = rect.y();
116  pvrRect.width = rect.width();
117  pvrRect.height = rect.height();
118  transformRects(&pvrRect, 1);
119  pvrQwsSetGeometry(drawable, &pvrRect);
121  }
123 }
124 
126 {
127  QRect rect = geometry().translated(offset);
128  if (drawable) {
129  PvrQwsRect pvrRect;
130  pvrRect.x = rect.x();
131  pvrRect.y = rect.y();
132  pvrRect.width = rect.width();
133  pvrRect.height = rect.height();
134  transformRects(&pvrRect, 1);
135  pvrQwsSetGeometry(drawable, &pvrRect);
137  }
138  return QWSGLWindowSurface::move(offset);
139 }
140 
142 {
143  // Nothing interesting to pass to the server just yet.
144  return QByteArray();
145 }
146 
148 {
149  Q_UNUSED(state);
150 }
151 
153  (QWidget *widget, const QRegion &region, const QPoint &offset)
154 {
155  // The GL paint engine is responsible for the swapBuffers() call.
156  // If we were to call the base class's implementation of flush()
157  // then it would fetch the image() and manually blit it to the
158  // screeen instead of using the fast PVR2D blit.
159  Q_UNUSED(widget);
160  Q_UNUSED(region);
161  Q_UNUSED(offset);
162 }
163 
165 {
166  if (drawable) {
167  PvrQwsRect pvrRect;
168  pvrQwsGetGeometry(drawable, &pvrRect);
170  if (data) {
171  return QImage((uchar *)data, pvrRect.width, pvrRect.height,
172  pvrQwsGetStride(drawable), screen->pixelFormat());
173  }
174  }
175  return QImage(16, 16, screen->pixelFormat());
176 }
177 
179 {
180  return widget;
181 }
182 
184 {
185  QWSGLWindowSurface::setDirectRegion(r, id);
186 
187  if (!drawable)
188  return;
189 
190  // Clip the region to the window boundaries in case the child
191  // is partially outside the geometry of the parent.
192  QWidget *window = widget->window();
193  QRegion region = r;
194  if (widget != window) {
195  QRect rect = window->geometry();
196  rect.moveTo(window->mapToGlobal(QPoint(0, 0)));
197  region = region.intersect(rect);
198  }
199 
200  if (region.isEmpty()) {
202  } else if (region.rectCount() == 1) {
203  QRect rect = region.boundingRect();
204  PvrQwsRect pvrRect;
205  pvrRect.x = rect.x();
206  pvrRect.y = rect.y();
207  pvrRect.width = rect.width();
208  pvrRect.height = rect.height();
209  transformRects(&pvrRect, 1);
210  pvrQwsSetVisibleRegion(drawable, &pvrRect, 1);
212  if (!pvrQwsSwapBuffers(drawable, 1))
213  screen->solidFill(QColor(0, 0, 0), region);
214  } else {
215  QVector<QRect> rects = region.rects();
216  PvrQwsRect *pvrRects = new PvrQwsRect [rects.size()];
217  for (int index = 0; index < rects.size(); ++index) {
218  QRect rect = rects[index];
219  pvrRects[index].x = rect.x();
220  pvrRects[index].y = rect.y();
221  pvrRects[index].width = rect.width();
222  pvrRects[index].height = rect.height();
223  }
224  transformRects(pvrRects, rects.size());
225  pvrQwsSetVisibleRegion(drawable, pvrRects, rects.size());
227  if (!pvrQwsSwapBuffers(drawable, 1))
228  screen->solidFill(QColor(0, 0, 0), region);
229  delete [] pvrRects;
230  }
231 }
232 
233 void PvrEglWindowSurface::transformRects(PvrQwsRect *rects, int count) const
234 {
235  switch (screen->transformation()) {
236  case 0: break;
237 
238  case 90:
239  {
240  for (int index = 0; index < count; ++index) {
241  int x = rects[index].y;
242  int y = screen->height() - (rects[index].x + rects[index].width);
243  rects[index].x = x;
244  rects[index].y = y;
245  qSwap(rects[index].width, rects[index].height);
246  }
247  }
248  break;
249 
250  case 180:
251  {
252  for (int index = 0; index < count; ++index) {
253  int x = screen->width() - (rects[index].x + rects[index].width);
254  int y = screen->height() - (rects[index].y + rects[index].height);
255  rects[index].x = x;
256  rects[index].y = y;
257  }
258  }
259  break;
260 
261  case 270:
262  {
263  for (int index = 0; index < count; ++index) {
264  int x = screen->width() - (rects[index].y + rects[index].height);
265  int y = rects[index].x;
266  rects[index].x = x;
267  rects[index].y = y;
268  qSwap(rects[index].width, rects[index].height);
269  }
270  }
271  break;
272  }
273 }
void pvrQwsSetGeometry(PvrQwsDrawable *drawable, const PvrQwsRect *rect)
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
QRect geometry() const
Returns the currently allocated area on the screen.
int height() const
Returns the logical height of the framebuffer in pixels.
Definition: qscreen_qws.h:228
void pvrQwsClearVisibleRegion(PvrQwsDrawable *drawable)
void solidFill(const QColor &color, const QRegion &region)
Fills the given region of the screen with the specified color.
QPointer< QWidget > widget
QByteArray permanentState() const
Implement this function to return the data required for creating a server-side representation of the ...
QRect rect(const QWidget *widget) const
Returns the rectangle for widget in the coordinates of this window surface.
PvrQwsDrawable * pvrQwsFetchWindow(long winId)
void flush(QWidget *widget, const QRegion &region, const QPoint &offset)
Flushes the given region from the specified widget onto the screen.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect translated(int dx, int dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:328
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
virtual QPoint offset(const QWidget *widget) const
Returns the offset of widget in the coordinates of this window surface.
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
void setSurfaceFlags(SurfaceFlags type)
Sets the surface flags describing the contents of this surface, to be the given flags.
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void pvrQwsGetGeometry(PvrQwsDrawable *drawable, PvrQwsRect *rect)
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
int pvrQwsGetStride(PvrQwsDrawable *drawable)
QImage image() const
Implement this function to return an image of the top-level window.
unsigned char uchar
Definition: qglobal.h:994
int width() const
Returns the logical width of the framebuffer in pixels.
Definition: qscreen_qws.h:227
int width() const
Returns the width.
Definition: qsize.h:126
int transformation() const
virtual bool move(const QPoint &offset)
Move the surface with the given offset.
PvrQwsDrawable * pvrQwsCreateWindow(int screen, long winId, const PvrQwsRect *rect)
bool isEmpty() const
Returns true if the region is empty; otherwise returns false.
Definition: qregion.cpp:4098
int pvrQwsReleaseWindow(PvrQwsDrawable *drawable)
void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
QRegion intersect(const QRegion &r) const
Use intersected(r) instead.
Definition: qregion.cpp:4249
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static const char * data(const QByteArray &arr)
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
QSize size
the size of the widget excluding any window frame
Definition: qwidget.h:165
bool isValid() const
Implement this function to return true if the surface is a valid surface for the given top-level wind...
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
QImage::Format pixelFormat() const
Returns the pixel format of the screen, or QImage::Format_Invalid if the pixel format is not a suppor...
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void pvrQwsSetRotation(PvrQwsDrawable *drawable, int angle)
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
QPaintDevice * paintDevice()
Implement this function to return the appropriate paint device.
void setPermanentState(const QByteArray &state)
Implement this function to attach a server-side surface instance to the corresponding client side ins...
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 transformRects(PvrQwsRect *rects, int count) const
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
quint16 index
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
int pvrQwsSwapBuffers(PvrQwsDrawable *drawable, int repaintOnly)
void setDirectRegion(const QRegion &region, int id)
void pvrQwsSetVisibleRegion(PvrQwsDrawable *drawable, const PvrQwsRect *rects, int numRects)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
void pvrQwsDestroyDrawable(PvrQwsDrawable *drawable)
PvrQwsDrawable * drawable
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
QRect geometry
the geometry of the widget relative to its parent and excluding the window frame
Definition: qwidget.h:158
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
The QWSGLWindowSurface class provides the drawing area for top-level windows with Qt for Embedded Lin...
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.
QWidget * window() const
Returns a pointer to the top-level window associated with this surface.
virtual void setGeometry(const QRect &rect)
Sets the currently allocated area to be the given rect.
bool move(const QPoint &offset)
Move the surface with the given offset.
void * pvrQwsGetRenderBuffer(PvrQwsDrawable *drawable)