|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtGui/QPaintDevice> |
|
43 #include <QtGui/QPainter> |
|
44 #include <QtGui/QPixmap> |
|
45 #include <QtGui/QWidget> |
|
46 |
|
47 #include "private/qt_x11_p.h" |
|
48 #include "private/qpixmap_x11_p.h" |
|
49 #include "private/qwidget_p.h" |
|
50 #include "qx11info_x11.h" |
|
51 #include "qwindowsurface_x11_p.h" |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 extern void *qt_getClipRects(const QRegion &r, int &num); // in qpaintengine_x11.cpp |
|
56 |
|
57 struct QX11WindowSurfacePrivate |
|
58 { |
|
59 QWidget *widget; |
|
60 QPixmap device; |
|
61 #ifndef QT_NO_XRENDER |
|
62 bool translucentBackground; |
|
63 #endif |
|
64 }; |
|
65 |
|
66 QX11WindowSurface::QX11WindowSurface(QWidget *widget) |
|
67 : QWindowSurface(widget), d_ptr(new QX11WindowSurfacePrivate), gc(0) |
|
68 { |
|
69 d_ptr->widget = widget; |
|
70 #ifndef QT_NO_XRENDER |
|
71 d_ptr->translucentBackground = X11->use_xrender |
|
72 && widget->x11Info().depth() == 32; |
|
73 setStaticContentsSupport(!d_ptr->translucentBackground); |
|
74 #else |
|
75 setStaticContentsSupport(true); |
|
76 #endif |
|
77 } |
|
78 |
|
79 |
|
80 QX11WindowSurface::~QX11WindowSurface() |
|
81 { |
|
82 delete d_ptr; |
|
83 if (gc) { |
|
84 XFreeGC(X11->display, gc); |
|
85 gc = 0; |
|
86 } |
|
87 } |
|
88 |
|
89 QPaintDevice *QX11WindowSurface::paintDevice() |
|
90 { |
|
91 return &d_ptr->device; |
|
92 } |
|
93 |
|
94 void QX11WindowSurface::beginPaint(const QRegion &rgn) |
|
95 { |
|
96 #ifndef QT_NO_XRENDER |
|
97 if (d_ptr->translucentBackground) { |
|
98 if (d_ptr->device.depth() != 32) |
|
99 static_cast<QX11PixmapData *>(d_ptr->device.data_ptr().data())->convertToARGB32(); |
|
100 ::Picture src = X11->getSolidFill(d_ptr->device.x11Info().screen(), Qt::transparent); |
|
101 ::Picture dst = d_ptr->device.x11PictureHandle(); |
|
102 const QVector<QRect> rects = rgn.rects(); |
|
103 const int w = d_ptr->device.width(); |
|
104 const int h = d_ptr->device.height(); |
|
105 for (QVector<QRect>::const_iterator it = rects.begin(); it != rects.end(); ++it) |
|
106 XRenderComposite(X11->display, PictOpSrc, src, 0, dst, |
|
107 0, 0, w, h, it->x(), it->y(), |
|
108 it->width(), it->height()); |
|
109 } |
|
110 #endif |
|
111 } |
|
112 |
|
113 void QX11WindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset) |
|
114 { |
|
115 if (d_ptr->device.isNull()) |
|
116 return; |
|
117 |
|
118 QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft(); |
|
119 QRegion wrgn(rgn); |
|
120 QRect br = rgn.boundingRect(); |
|
121 if (!wOffset.isNull()) |
|
122 wrgn.translate(-wOffset); |
|
123 QRect wbr = wrgn.boundingRect(); |
|
124 |
|
125 int num; |
|
126 XRectangle *rects = (XRectangle *)qt_getClipRects(wrgn, num); |
|
127 if (num <= 0) |
|
128 return; |
|
129 // qDebug() << "XSetClipRectangles"; |
|
130 // for (int i = 0; i < num; ++i) |
|
131 // qDebug() << ' ' << i << rects[i].x << rects[i].x << rects[i].y << rects[i].width << rects[i].height; |
|
132 if (num != 1) |
|
133 XSetClipRectangles(X11->display, gc, 0, 0, rects, num, YXBanded); |
|
134 XCopyArea(X11->display, d_ptr->device.handle(), widget->handle(), gc, |
|
135 br.x() + offset.x(), br.y() + offset.y(), br.width(), br.height(), wbr.x(), wbr.y()); |
|
136 if (num != 1) |
|
137 XSetClipMask(X11->display, gc, XNone); |
|
138 } |
|
139 |
|
140 void QX11WindowSurface::setGeometry(const QRect &rect) |
|
141 { |
|
142 QWindowSurface::setGeometry(rect); |
|
143 |
|
144 const QSize size = rect.size(); |
|
145 |
|
146 if (d_ptr->device.size() == size || size.width() <= 0 || size.height() <= 0) |
|
147 return; |
|
148 #ifndef QT_NO_XRENDER |
|
149 if (d_ptr->translucentBackground) { |
|
150 QX11PixmapData *data = new QX11PixmapData(QPixmapData::PixmapType); |
|
151 data->xinfo = d_ptr->widget->x11Info(); |
|
152 data->resize(size.width(), size.height()); |
|
153 d_ptr->device = QPixmap(data); |
|
154 } else |
|
155 #endif |
|
156 { |
|
157 QPixmap::x11SetDefaultScreen(d_ptr->widget->x11Info().screen()); |
|
158 |
|
159 QX11PixmapData *oldData = static_cast<QX11PixmapData *>(d_ptr->device.pixmapData()); |
|
160 Q_ASSERT(oldData); |
|
161 if (!(oldData->flags & QX11PixmapData::Uninitialized) && hasStaticContents()) { |
|
162 // Copy the content of the old pixmap into the new one. |
|
163 QX11PixmapData *newData = new QX11PixmapData(QPixmapData::PixmapType); |
|
164 newData->resize(size.width(), size.height()); |
|
165 Q_ASSERT(oldData->d == newData->d); |
|
166 |
|
167 QRegion staticRegion(staticContents()); |
|
168 // Make sure we're inside the boundaries of the old pixmap. |
|
169 staticRegion &= QRect(0, 0, oldData->w, oldData->h); |
|
170 const QRect boundingRect(staticRegion.boundingRect()); |
|
171 const int dx = boundingRect.x(); |
|
172 const int dy = boundingRect.y(); |
|
173 |
|
174 int num; |
|
175 XRectangle *rects = (XRectangle *)qt_getClipRects(staticRegion, num); |
|
176 GC tmpGc = XCreateGC(X11->display, oldData->hd, 0, 0); |
|
177 XSetClipRectangles(X11->display, tmpGc, 0, 0, rects, num, YXBanded); |
|
178 XCopyArea(X11->display, oldData->hd, newData->hd, tmpGc, |
|
179 dx, dy, qMin(boundingRect.width(), size.width()), |
|
180 qMin(boundingRect.height(), size.height()), dx, dy); |
|
181 XFreeGC(X11->display, tmpGc); |
|
182 newData->flags &= ~QX11PixmapData::Uninitialized; |
|
183 |
|
184 d_ptr->device = QPixmap(newData); |
|
185 } else { |
|
186 d_ptr->device = QPixmap(size); |
|
187 } |
|
188 } |
|
189 |
|
190 if (gc) { |
|
191 XFreeGC(X11->display, gc); |
|
192 gc = 0; |
|
193 } |
|
194 if (!d_ptr->device.isNull()) { |
|
195 gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); |
|
196 XSetGraphicsExposures(X11->display, gc, False); |
|
197 } |
|
198 } |
|
199 |
|
200 bool QX11WindowSurface::scroll(const QRegion &area, int dx, int dy) |
|
201 { |
|
202 QRect rect = area.boundingRect(); |
|
203 |
|
204 if (d_ptr->device.isNull()) |
|
205 return false; |
|
206 |
|
207 GC gc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); |
|
208 XCopyArea(X11->display, d_ptr->device.handle(), d_ptr->device.handle(), gc, |
|
209 rect.x(), rect.y(), rect.width(), rect.height(), |
|
210 rect.x()+dx, rect.y()+dy); |
|
211 XFreeGC(X11->display, gc); |
|
212 |
|
213 return true; |
|
214 } |
|
215 |
|
216 QPixmap QX11WindowSurface::grabWidget(const QWidget *widget, |
|
217 const QRect& rect) const |
|
218 { |
|
219 if (!widget || d_ptr->device.isNull()) |
|
220 return QPixmap(); |
|
221 |
|
222 QRect srcRect; |
|
223 |
|
224 // make sure the rect is inside the widget & clip to widget's rect |
|
225 if (!rect.isEmpty()) |
|
226 srcRect = rect & widget->rect(); |
|
227 else |
|
228 srcRect = widget->rect(); |
|
229 |
|
230 if (srcRect.isEmpty()) |
|
231 return QPixmap(); |
|
232 |
|
233 // If it's a child widget we have to translate the coordinates |
|
234 if (widget != window()) |
|
235 srcRect.translate(widget->mapTo(window(), QPoint(0, 0))); |
|
236 |
|
237 QPixmap::x11SetDefaultScreen(widget->x11Info().screen()); |
|
238 QPixmap px(srcRect.width(), srcRect.height()); |
|
239 |
|
240 GC tmpGc = XCreateGC(X11->display, d_ptr->device.handle(), 0, 0); |
|
241 |
|
242 // Copy srcRect from the backing store to the new pixmap |
|
243 XSetGraphicsExposures(X11->display, tmpGc, False); |
|
244 XCopyArea(X11->display, d_ptr->device.handle(), px.handle(), tmpGc, |
|
245 srcRect.x(), srcRect.y(), srcRect.width(), srcRect.height(), 0, 0); |
|
246 |
|
247 XFreeGC(X11->display, tmpGc); |
|
248 |
|
249 return px; |
|
250 } |
|
251 |
|
252 QT_END_NAMESPACE |