| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | //#define D3D_DEBUG_BACKBUFFER
|
|---|
| 43 |
|
|---|
| 44 | #include <QtGui/QPaintDevice>
|
|---|
| 45 | #include <QtGui/QWidget>
|
|---|
| 46 | #include "qdebug.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "qpaintengine_d3d_p.h"
|
|---|
| 49 | #include "qwindowsurface_d3d_p.h"
|
|---|
| 50 | #include "private/qwidget_p.h"
|
|---|
| 51 | #include "private/qbackingstore_p.h"
|
|---|
| 52 |
|
|---|
| 53 | #include <d3d9.h>
|
|---|
| 54 |
|
|---|
| 55 | QT_BEGIN_NAMESPACE
|
|---|
| 56 |
|
|---|
| 57 | extern QDirect3DPaintEngine *qt_d3dEngine();
|
|---|
| 58 |
|
|---|
| 59 | struct QD3DWindowSurfacePrivate
|
|---|
| 60 | {
|
|---|
| 61 | QSize m_lastSize;
|
|---|
| 62 | QWidget *m_widget;
|
|---|
| 63 | };
|
|---|
| 64 |
|
|---|
| 65 | QD3DWindowSurface::QD3DWindowSurface(QWidget *window)
|
|---|
| 66 | : QWindowSurface(window), d_ptr(new QD3DWindowSurfacePrivate)
|
|---|
| 67 | {
|
|---|
| 68 | Q_ASSERT(window->isTopLevel());
|
|---|
| 69 | d_ptr->m_widget = window;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 | QD3DWindowSurface::~QD3DWindowSurface()
|
|---|
| 74 | {
|
|---|
| 75 | delete d_ptr;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | QPaintDevice *QD3DWindowSurface::paintDevice()
|
|---|
| 79 | {
|
|---|
| 80 | return d_ptr->m_widget;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | void QD3DWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
|
|---|
| 85 | {
|
|---|
| 86 | QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();
|
|---|
| 87 |
|
|---|
| 88 | QDirect3DPaintEngine *engine = qt_d3dEngine();
|
|---|
| 89 | LPDIRECT3DSWAPCHAIN9 swapchain = engine->swapChain(d_ptr->m_widget);
|
|---|
| 90 |
|
|---|
| 91 | if (swapchain) {
|
|---|
| 92 | QRect br = rgn.boundingRect();
|
|---|
| 93 | QRect wbr = br.translated(-wOffset);
|
|---|
| 94 |
|
|---|
| 95 | RECT destrect;
|
|---|
| 96 | destrect.left = wbr.x();
|
|---|
| 97 | destrect.top = wbr.y();
|
|---|
| 98 | destrect.right = destrect.left + wbr.width();
|
|---|
| 99 | destrect.bottom = destrect.top + wbr.height();
|
|---|
| 100 |
|
|---|
| 101 | RECT srcrect;
|
|---|
| 102 | srcrect.left = br.x() + offset.x();
|
|---|
| 103 | srcrect.top = br.y() + offset.y();
|
|---|
| 104 | srcrect.right = wbr.width() + srcrect.left;
|
|---|
| 105 | srcrect.bottom = wbr.height() + srcrect.top;
|
|---|
| 106 | int devwidth = d_ptr->m_lastSize.width();
|
|---|
| 107 | int devheight = d_ptr->m_lastSize.height();
|
|---|
| 108 |
|
|---|
| 109 | if (devwidth <= srcrect.right) {
|
|---|
| 110 | int diff = srcrect.right - devwidth;
|
|---|
| 111 | srcrect.right -= diff;
|
|---|
| 112 | destrect.right -= diff;
|
|---|
| 113 | if (srcrect.right <= srcrect.left)
|
|---|
| 114 | return;
|
|---|
| 115 | }
|
|---|
| 116 | if (devheight <= srcrect.bottom) {
|
|---|
| 117 | int diff = srcrect.bottom - devheight;
|
|---|
| 118 | srcrect.bottom -= diff;
|
|---|
| 119 | destrect.bottom -= diff;
|
|---|
| 120 | if (srcrect.bottom <= srcrect.top)
|
|---|
| 121 | return;
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | if (FAILED(swapchain->Present(&srcrect, &destrect, widget->winId(), 0, 0)))
|
|---|
| 125 | qWarning("QDirect3DPaintEngine: failed to present back buffer.");
|
|---|
| 126 |
|
|---|
| 127 | #ifdef D3D_DEBUG_BACKBUFFER
|
|---|
| 128 | qDebug() << widget << srcrect.left << srcrect.top << wbr.width() << wbr.height() << "Dest: " << destrect.left << destrect.top;
|
|---|
| 129 | IDirect3DSurface9 *surface;
|
|---|
| 130 | swapchain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &surface);
|
|---|
| 131 | QString filename("C:\\test.bmp");
|
|---|
| 132 | D3DXSaveSurfaceToFile(filename.utf16(), D3DXIFF_BMP, surface, 0, 0);
|
|---|
| 133 | surface->Release();
|
|---|
| 134 | #endif
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void QD3DWindowSurface::setGeometry(const QRect &rect)
|
|---|
| 139 | {
|
|---|
| 140 | if (rect.isEmpty())
|
|---|
| 141 | qt_d3dEngine()->releaseSwapChain(d_ptr->m_widget);
|
|---|
| 142 |
|
|---|
| 143 | d_ptr->m_lastSize = rect.size();
|
|---|
| 144 | QWindowSurface::setGeometry(rect);
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | bool QD3DWindowSurface::scroll(const QRegion &area, int dx, int dy)
|
|---|
| 149 | {
|
|---|
| 150 | QDirect3DPaintEngine *engine = qt_d3dEngine();
|
|---|
| 151 | QRect rect = area.boundingRect();
|
|---|
| 152 |
|
|---|
| 153 | RECT destrect;
|
|---|
| 154 | destrect.left = rect.x()+dx;
|
|---|
| 155 | destrect.top = rect.y()+dy;
|
|---|
| 156 | destrect.right = rect.width() + destrect.left;
|
|---|
| 157 | destrect.bottom = rect.height() + destrect.top;
|
|---|
| 158 |
|
|---|
| 159 | RECT srcrect;
|
|---|
| 160 | srcrect.left = rect.x();
|
|---|
| 161 | srcrect.top = rect.y();
|
|---|
| 162 | srcrect.right = rect.width() + srcrect.left;
|
|---|
| 163 | srcrect.bottom = rect.height() + srcrect.top;
|
|---|
| 164 |
|
|---|
| 165 | engine->scroll(d_ptr->m_widget, srcrect, destrect);
|
|---|
| 166 | return true;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | QT_END_NAMESPACE
|
|---|