author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 02 Feb 2010 00:43:10 +0200 | |
changeset 3 | 41300fa6a67c |
parent 0 | 1918ee327afb |
child 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 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 plugins 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 "qdirectfbscreen.h" |
|
43 |
#include "qdirectfbpaintdevice.h" |
|
44 |
#include "qdirectfbpaintengine.h" |
|
45 |
||
46 |
#ifndef QT_NO_QWS_DIRECTFB |
|
47 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
QDirectFBPaintDevice::QDirectFBPaintDevice(QDirectFBScreen *scr) |
|
51 |
: QCustomRasterPaintDevice(0), dfbSurface(0), screen(scr), |
|
52 |
bpl(-1), lockFlgs(DFBSurfaceLockFlags(0)), mem(0), engine(0), imageFormat(QImage::Format_Invalid) |
|
53 |
{ |
|
54 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
55 |
subSurface = 0; |
|
56 |
syncPending = false; |
|
57 |
#endif |
|
58 |
} |
|
59 |
||
60 |
QDirectFBPaintDevice::~QDirectFBPaintDevice() |
|
61 |
{ |
|
62 |
if (QDirectFBScreen::instance()) { |
|
63 |
unlockSurface(); |
|
64 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
65 |
releaseSubSurface(); |
|
66 |
#endif |
|
67 |
if (dfbSurface) { |
|
68 |
screen->releaseDFBSurface(dfbSurface); |
|
69 |
} |
|
70 |
} |
|
71 |
delete engine; |
|
72 |
} |
|
73 |
||
74 |
IDirectFBSurface *QDirectFBPaintDevice::directFBSurface() const |
|
75 |
{ |
|
76 |
return dfbSurface; |
|
77 |
} |
|
78 |
||
79 |
bool QDirectFBPaintDevice::lockSurface(DFBSurfaceLockFlags lockFlags) |
|
80 |
{ |
|
81 |
if (lockFlgs && (lockFlags & ~lockFlgs)) |
|
82 |
unlockSurface(); |
|
83 |
if (!mem) { |
|
84 |
Q_ASSERT(dfbSurface); |
|
85 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
86 |
if (!subSurface) { |
|
87 |
DFBResult result; |
|
88 |
subSurface = screen->getSubSurface(dfbSurface, QRect(), QDirectFBScreen::TrackSurface, &result); |
|
89 |
if (result != DFB_OK || !subSurface) { |
|
90 |
DirectFBError("Couldn't create sub surface", result); |
|
91 |
return false; |
|
92 |
} |
|
93 |
} |
|
94 |
IDirectFBSurface *surface = subSurface; |
|
95 |
#else |
|
96 |
IDirectFBSurface *surface = dfbSurface; |
|
97 |
#endif |
|
98 |
Q_ASSERT(surface); |
|
99 |
mem = QDirectFBScreen::lockSurface(surface, lockFlags, &bpl); |
|
100 |
lockFlgs = lockFlags; |
|
101 |
Q_ASSERT(mem); |
|
102 |
Q_ASSERT(bpl > 0); |
|
103 |
const QSize s = size(); |
|
104 |
lockedImage = QImage(mem, s.width(), s.height(), bpl, |
|
105 |
QDirectFBScreen::getImageFormat(dfbSurface)); |
|
106 |
return true; |
|
107 |
} |
|
108 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
109 |
if (syncPending) { |
|
110 |
syncPending = false; |
|
111 |
screen->waitIdle(); |
|
112 |
} |
|
113 |
#endif |
|
114 |
return false; |
|
115 |
} |
|
116 |
||
117 |
void QDirectFBPaintDevice::unlockSurface() |
|
118 |
{ |
|
119 |
if (QDirectFBScreen::instance() && lockFlgs) { |
|
120 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
121 |
IDirectFBSurface *surface = subSurface; |
|
122 |
#else |
|
123 |
IDirectFBSurface *surface = dfbSurface; |
|
124 |
#endif |
|
125 |
if (surface) { |
|
126 |
surface->Unlock(surface); |
|
127 |
lockFlgs = static_cast<DFBSurfaceLockFlags>(0); |
|
128 |
mem = 0; |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
void *QDirectFBPaintDevice::memory() const |
|
134 |
{ |
|
135 |
return mem; |
|
136 |
} |
|
137 |
||
138 |
QImage::Format QDirectFBPaintDevice::format() const |
|
139 |
{ |
|
140 |
return imageFormat; |
|
141 |
} |
|
142 |
||
143 |
int QDirectFBPaintDevice::bytesPerLine() const |
|
144 |
{ |
|
145 |
Q_ASSERT(!mem || bpl != -1); |
|
146 |
return bpl; |
|
147 |
} |
|
148 |
||
149 |
QSize QDirectFBPaintDevice::size() const |
|
150 |
{ |
|
151 |
int w, h; |
|
152 |
dfbSurface->GetSize(dfbSurface, &w, &h); |
|
153 |
return QSize(w, h); |
|
154 |
} |
|
155 |
||
156 |
int QDirectFBPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const |
|
157 |
{ |
|
158 |
if (!dfbSurface) |
|
159 |
return 0; |
|
160 |
||
161 |
switch (metric) { |
|
162 |
case QPaintDevice::PdmWidth: |
|
163 |
case QPaintDevice::PdmHeight: |
|
164 |
return (metric == PdmWidth ? size().width() : size().height()); |
|
165 |
case QPaintDevice::PdmWidthMM: |
|
166 |
return (size().width() * 1000) / dotsPerMeterX(); |
|
167 |
case QPaintDevice::PdmHeightMM: |
|
168 |
return (size().height() * 1000) / dotsPerMeterY(); |
|
169 |
case QPaintDevice::PdmPhysicalDpiX: |
|
170 |
case QPaintDevice::PdmDpiX: |
|
171 |
return (dotsPerMeterX() * 254) / 10000; // 0.0254 meters-per-inch |
|
172 |
case QPaintDevice::PdmPhysicalDpiY: |
|
173 |
case QPaintDevice::PdmDpiY: |
|
174 |
return (dotsPerMeterY() * 254) / 10000; // 0.0254 meters-per-inch |
|
175 |
case QPaintDevice::PdmDepth: |
|
176 |
return QDirectFBScreen::depth(imageFormat); |
|
177 |
case QPaintDevice::PdmNumColors: { |
|
178 |
if (!lockedImage.isNull()) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
return lockedImage.colorCount(); |
0 | 180 |
|
181 |
DFBResult result; |
|
182 |
IDirectFBPalette *palette = 0; |
|
183 |
unsigned int numColors = 0; |
|
184 |
||
185 |
result = dfbSurface->GetPalette(dfbSurface, &palette); |
|
186 |
if ((result != DFB_OK) || !palette) |
|
187 |
return 0; |
|
188 |
||
189 |
result = palette->GetSize(palette, &numColors); |
|
190 |
palette->Release(palette); |
|
191 |
if (result != DFB_OK) |
|
192 |
return 0; |
|
193 |
||
194 |
return numColors; |
|
195 |
} |
|
196 |
default: |
|
197 |
qCritical("QDirectFBPaintDevice::metric(): Unhandled metric!"); |
|
198 |
return 0; |
|
199 |
} |
|
200 |
} |
|
201 |
||
202 |
QPaintEngine *QDirectFBPaintDevice::paintEngine() const |
|
203 |
{ |
|
204 |
return engine; |
|
205 |
} |
|
206 |
||
207 |
#ifdef QT_DIRECTFB_SUBSURFACE |
|
208 |
void QDirectFBPaintDevice::releaseSubSurface() |
|
209 |
{ |
|
210 |
Q_ASSERT(QDirectFBScreen::instance()); |
|
211 |
if (subSurface) { |
|
212 |
unlockSurface(); |
|
213 |
screen->releaseDFBSurface(subSurface); |
|
214 |
subSurface = 0; |
|
215 |
} |
|
216 |
} |
|
217 |
#endif |
|
218 |
||
219 |
QT_END_NAMESPACE |
|
220 |
||
221 |
#endif // QT_NO_QWS_DIRECTFB |