|
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 Qt Mobility Components. |
|
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 <QtTest/QtTest> |
|
43 |
|
44 #include <qpaintervideosurface_p.h> |
|
45 |
|
46 #include <QtGui/qapplication.h> |
|
47 #include <QtMultimedia/qvideosurfaceformat.h> |
|
48 |
|
49 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) |
|
50 #include <QtOpenGL/qgl.h> |
|
51 #include <QtOpenGL/qglframebufferobject.h> |
|
52 #endif |
|
53 |
|
54 QTM_USE_NAMESPACE |
|
55 class tst_QPainterVideoSurface : public QObject |
|
56 { |
|
57 Q_OBJECT |
|
58 private slots: |
|
59 void cleanup() {} |
|
60 void cleanupTestCase() {} |
|
61 |
|
62 void colors(); |
|
63 |
|
64 void supportedFormat_data(); |
|
65 void supportedFormat(); |
|
66 |
|
67 void present_data(); |
|
68 void present(); |
|
69 void presentOpaqueFrame(); |
|
70 |
|
71 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) |
|
72 |
|
73 void shaderType(); |
|
74 |
|
75 void shaderTypeStarted_data(); |
|
76 void shaderTypeStarted(); |
|
77 |
|
78 void shaderSupportedFormat_data(); |
|
79 void shaderSupportedFormat(); |
|
80 |
|
81 void shaderPresent_data(); |
|
82 void shaderPresent(); |
|
83 void shaderPresentOpaqueFrame_data(); |
|
84 void shaderPresentOpaqueFrame(); |
|
85 void shaderPresentGLFrame_data(); |
|
86 void shaderPresentGLFrame(); |
|
87 #endif |
|
88 }; |
|
89 |
|
90 Q_DECLARE_METATYPE(const uchar *) |
|
91 |
|
92 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) |
|
93 Q_DECLARE_METATYPE(QPainterVideoSurface::ShaderType); |
|
94 |
|
95 class QtTestGLVideoBuffer : public QAbstractVideoBuffer |
|
96 { |
|
97 public: |
|
98 QtTestGLVideoBuffer() |
|
99 : QAbstractVideoBuffer(GLTextureHandle) |
|
100 , m_textureId(0) |
|
101 { |
|
102 glGenTextures(1, &m_textureId); |
|
103 } |
|
104 |
|
105 ~QtTestGLVideoBuffer() |
|
106 { |
|
107 glDeleteTextures(1, &m_textureId); |
|
108 } |
|
109 |
|
110 GLuint textureId() const { return m_textureId; } |
|
111 |
|
112 QVariant handle() const { return m_textureId; } |
|
113 |
|
114 uchar *map(MapMode, int *, int *) { return 0; } |
|
115 void unmap() {} |
|
116 MapMode mapMode() const { return NotMapped; } |
|
117 |
|
118 private: |
|
119 GLuint m_textureId; |
|
120 }; |
|
121 |
|
122 #endif |
|
123 |
|
124 class QtTestOpaqueVideoBuffer : public QAbstractVideoBuffer |
|
125 { |
|
126 public: |
|
127 QtTestOpaqueVideoBuffer() |
|
128 : QAbstractVideoBuffer(UserHandle) |
|
129 {} |
|
130 |
|
131 uchar *map(MapMode, int *, int *) { return 0; } |
|
132 void unmap() {} |
|
133 MapMode mapMode() const { return NotMapped; } |
|
134 }; |
|
135 |
|
136 void tst_QPainterVideoSurface::colors() |
|
137 { |
|
138 QPainterVideoSurface surface; |
|
139 |
|
140 QCOMPARE(surface.brightness(), 0); |
|
141 QCOMPARE(surface.contrast(), 0); |
|
142 QCOMPARE(surface.hue(), 0); |
|
143 QCOMPARE(surface.saturation(), 0); |
|
144 |
|
145 surface.setBrightness(56); |
|
146 QCOMPARE(surface.brightness(), 56); |
|
147 |
|
148 surface.setContrast(43); |
|
149 QCOMPARE(surface.contrast(), 43); |
|
150 |
|
151 surface.setHue(-84); |
|
152 QCOMPARE(surface.hue(), -84); |
|
153 |
|
154 surface.setSaturation(100); |
|
155 QCOMPARE(surface.saturation(), 100); |
|
156 } |
|
157 |
|
158 static const uchar rgb32ImageData[] = |
|
159 { |
|
160 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, |
|
161 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 |
|
162 }; |
|
163 |
|
164 static const uchar argb32ImageData[] = |
|
165 { |
|
166 0x00, 0xff, 0x00, 0x00, 0xcc, 0x00, 0xff, 0xcc, |
|
167 0x77, 0x00, 0x00, 0x77, 0x00, 0xff, 0xff, 0x00 |
|
168 }; |
|
169 |
|
170 static const uchar rgb24ImageData[] = |
|
171 { |
|
172 0x00, 0xff, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, |
|
173 0xcc, 0x00, 0xcc, 0x77, 0xff, 0x77, 0x00, 0x00 |
|
174 }; |
|
175 |
|
176 static const uchar rgb565ImageData[] = |
|
177 { |
|
178 0xff, 0xff, 0xff, 0xff, |
|
179 0x00, 0x00, 0x00, 0x00 |
|
180 }; |
|
181 |
|
182 static const uchar yuvPlanarImageData[] = |
|
183 { |
|
184 0x00, 0x00, 0x0f, 0xff, 0xff, 0x0f, 0x00, 0x00, |
|
185 0x00, 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0f, 0x00, |
|
186 0x00, 0xff, 0x0f, 0x00, 0x00, 0x0f, 0xff, 0x00, |
|
187 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, |
|
188 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, |
|
189 0x0f, 0xff, 0x0f, 0x00, 0x00, 0x0f, 0xff, 0x0f, |
|
190 0x00, 0x0f, 0xff, 0x0f, 0x0f, 0xff, 0x0f, 0x00, |
|
191 0x00, 0x00, 0x0f, 0xff, 0xff, 0x0f, 0x00, 0x00, |
|
192 0x00, 0x0f, 0x0f, 0x00, |
|
193 0x0f, 0x00, 0x00, 0x0f, |
|
194 0x0f, 0x00, 0x00, 0x0f, |
|
195 0x00, 0x0f, 0x0f, 0x00, |
|
196 0x00, 0x0f, 0x0f, 0x00, |
|
197 0x0f, 0x00, 0x00, 0x0f, |
|
198 0x0f, 0x00, 0x00, 0x0f, |
|
199 0x00, 0x0f, 0x0f, 0x00, |
|
200 }; |
|
201 |
|
202 void tst_QPainterVideoSurface::supportedFormat_data() |
|
203 { |
|
204 QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); |
|
205 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
206 QTest::addColumn<QSize>("frameSize"); |
|
207 QTest::addColumn<bool>("supportedPixelFormat"); |
|
208 QTest::addColumn<bool>("supportedFormat"); |
|
209 |
|
210 QTest::newRow("rgb32 640x480") |
|
211 << QAbstractVideoBuffer::NoHandle |
|
212 << QVideoFrame::Format_RGB32 |
|
213 << QSize(640, 480) |
|
214 << true |
|
215 << true; |
|
216 QTest::newRow("rgb32 -640x480") |
|
217 << QAbstractVideoBuffer::NoHandle |
|
218 << QVideoFrame::Format_RGB32 |
|
219 << QSize(-640, 480) |
|
220 << true |
|
221 << false; |
|
222 QTest::newRow("rgb24 1024x768") |
|
223 << QAbstractVideoBuffer::NoHandle |
|
224 << QVideoFrame::Format_RGB24 |
|
225 << QSize(1024, 768) |
|
226 << true |
|
227 << true; |
|
228 QTest::newRow("rgb24 -1024x-768") |
|
229 << QAbstractVideoBuffer::NoHandle |
|
230 << QVideoFrame::Format_RGB24 |
|
231 << QSize(-1024, -768) |
|
232 << true |
|
233 << false; |
|
234 QTest::newRow("rgb565 0x0") |
|
235 << QAbstractVideoBuffer::NoHandle |
|
236 << QVideoFrame::Format_RGB565 |
|
237 << QSize(0, 0) |
|
238 << true |
|
239 << false; |
|
240 QTest::newRow("YUV420P 640x480") |
|
241 << QAbstractVideoBuffer::NoHandle |
|
242 << QVideoFrame::Format_YUV420P |
|
243 << QSize(640, 480) |
|
244 << false |
|
245 << false; |
|
246 QTest::newRow("YUV420P 640x-480") |
|
247 << QAbstractVideoBuffer::NoHandle |
|
248 << QVideoFrame::Format_YUV420P |
|
249 << QSize(640, -480) |
|
250 << false |
|
251 << false; |
|
252 QTest::newRow("Y8 640x480") |
|
253 << QAbstractVideoBuffer::NoHandle |
|
254 << QVideoFrame::Format_Y8 |
|
255 << QSize(640, 480) |
|
256 << false |
|
257 << false; |
|
258 QTest::newRow("Texture: rgb32 640x480") |
|
259 << QAbstractVideoBuffer::GLTextureHandle |
|
260 << QVideoFrame::Format_RGB32 |
|
261 << QSize(640, 480) |
|
262 << false |
|
263 << false; |
|
264 QTest::newRow("Texture: rgb32 -640x480") |
|
265 << QAbstractVideoBuffer::GLTextureHandle |
|
266 << QVideoFrame::Format_RGB32 |
|
267 << QSize(-640, 480) |
|
268 << false |
|
269 << false; |
|
270 QTest::newRow("rgb565 32x32") |
|
271 << QAbstractVideoBuffer::NoHandle |
|
272 << QVideoFrame::Format_RGB565 |
|
273 << QSize(32, 32) |
|
274 << true |
|
275 << true; |
|
276 QTest::newRow("rgb565 0x0") |
|
277 << QAbstractVideoBuffer::NoHandle |
|
278 << QVideoFrame::Format_RGB565 |
|
279 << QSize(0, 0) |
|
280 << true |
|
281 << false; |
|
282 QTest::newRow("argb32 256x256") |
|
283 << QAbstractVideoBuffer::NoHandle |
|
284 << QVideoFrame::Format_ARGB32 |
|
285 << QSize(256, 256) |
|
286 << true |
|
287 << true; |
|
288 QTest::newRow("Texture: rgb24 1024x768") |
|
289 << QAbstractVideoBuffer::GLTextureHandle |
|
290 << QVideoFrame::Format_RGB24 |
|
291 << QSize(1024, 768) |
|
292 << false |
|
293 << false; |
|
294 QTest::newRow("Texture: rgb24 -1024x-768") |
|
295 << QAbstractVideoBuffer::GLTextureHandle |
|
296 << QVideoFrame::Format_RGB24 |
|
297 << QSize(-1024, -768) |
|
298 << false |
|
299 << false; |
|
300 QTest::newRow("Texture: YUV420P 640x480") |
|
301 << QAbstractVideoBuffer::GLTextureHandle |
|
302 << QVideoFrame::Format_YUV420P |
|
303 << QSize(640, 480) |
|
304 << false |
|
305 << false; |
|
306 QTest::newRow("Texture: YUV420P 640x-480") |
|
307 << QAbstractVideoBuffer::GLTextureHandle |
|
308 << QVideoFrame::Format_YUV420P |
|
309 << QSize(640, -480) |
|
310 << false |
|
311 << false; |
|
312 QTest::newRow("User Buffer: rgb32 256x256") |
|
313 << QAbstractVideoBuffer::UserHandle |
|
314 << QVideoFrame::Format_RGB32 |
|
315 << QSize(256, 256) |
|
316 << false |
|
317 << false; |
|
318 } |
|
319 |
|
320 void tst_QPainterVideoSurface::supportedFormat() |
|
321 { |
|
322 QFETCH(QAbstractVideoBuffer::HandleType, handleType); |
|
323 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
324 QFETCH(QSize, frameSize); |
|
325 QFETCH(bool, supportedPixelFormat); |
|
326 QFETCH(bool, supportedFormat); |
|
327 |
|
328 QPainterVideoSurface surface; |
|
329 |
|
330 const QList<QVideoFrame::PixelFormat> pixelFormats = surface.supportedPixelFormats(handleType); |
|
331 |
|
332 QCOMPARE(pixelFormats.contains(pixelFormat), QBool(supportedPixelFormat)); |
|
333 |
|
334 QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); |
|
335 |
|
336 QCOMPARE(surface.isFormatSupported(format), supportedFormat); |
|
337 QCOMPARE(surface.start(format), supportedFormat); |
|
338 } |
|
339 |
|
340 void tst_QPainterVideoSurface::present_data() |
|
341 { |
|
342 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormatA"); |
|
343 QTest::addColumn<QSize>("frameSizeA"); |
|
344 QTest::addColumn<const uchar *>("frameDataA"); |
|
345 QTest::addColumn<int>("bytesA"); |
|
346 QTest::addColumn<int>("bytesPerLineA"); |
|
347 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormatB"); |
|
348 QTest::addColumn<QSize>("frameSizeB"); |
|
349 QTest::addColumn<const uchar *>("frameDataB"); |
|
350 QTest::addColumn<int>("bytesB"); |
|
351 QTest::addColumn<int>("bytesPerLineB"); |
|
352 |
|
353 QTest::newRow("rgb32 -> argb32") |
|
354 << QVideoFrame::Format_RGB32 |
|
355 << QSize(2, 2) |
|
356 << static_cast<const uchar *>(rgb32ImageData) |
|
357 << int(sizeof(rgb32ImageData)) |
|
358 << 8 |
|
359 << QVideoFrame::Format_ARGB32 |
|
360 << QSize(2, 2) |
|
361 << static_cast<const uchar *>(argb32ImageData) |
|
362 << int(sizeof(argb32ImageData)) |
|
363 << 8; |
|
364 |
|
365 QTest::newRow("rgb32 -> rgb24") |
|
366 << QVideoFrame::Format_RGB32 |
|
367 << QSize(2, 2) |
|
368 << static_cast<const uchar *>(rgb32ImageData) |
|
369 << int(sizeof(rgb32ImageData)) |
|
370 << 8 |
|
371 << QVideoFrame::Format_RGB24 |
|
372 << QSize(2, 2) |
|
373 << static_cast<const uchar *>(rgb24ImageData) |
|
374 << int(sizeof(rgb24ImageData)) |
|
375 << 8; |
|
376 |
|
377 QTest::newRow("rgb32 -> rgb565") |
|
378 << QVideoFrame::Format_RGB32 |
|
379 << QSize(2, 2) |
|
380 << static_cast<const uchar *>(rgb32ImageData) |
|
381 << int(sizeof(rgb32ImageData)) |
|
382 << 8 |
|
383 << QVideoFrame::Format_RGB565 |
|
384 << QSize(2, 2) |
|
385 << static_cast<const uchar *>(rgb565ImageData) |
|
386 << int(sizeof(rgb565ImageData)) |
|
387 << 4; |
|
388 |
|
389 QTest::newRow("rgb24 -> rgb565") |
|
390 << QVideoFrame::Format_RGB24 |
|
391 << QSize(2, 2) |
|
392 << static_cast<const uchar *>(rgb24ImageData) |
|
393 << int(sizeof(rgb24ImageData)) |
|
394 << 8 |
|
395 << QVideoFrame::Format_RGB565 |
|
396 << QSize(2, 2) |
|
397 << static_cast<const uchar *>(rgb565ImageData) |
|
398 << int(sizeof(rgb565ImageData)) |
|
399 << 4; |
|
400 } |
|
401 |
|
402 void tst_QPainterVideoSurface::present() |
|
403 { |
|
404 QFETCH(QVideoFrame::PixelFormat, pixelFormatA); |
|
405 QFETCH(QSize, frameSizeA); |
|
406 QFETCH(const uchar *, frameDataA); |
|
407 QFETCH(int, bytesA); |
|
408 QFETCH(int, bytesPerLineA); |
|
409 QFETCH(QVideoFrame::PixelFormat, pixelFormatB); |
|
410 QFETCH(QSize, frameSizeB); |
|
411 QFETCH(const uchar *, frameDataB); |
|
412 QFETCH(int, bytesB); |
|
413 QFETCH(int, bytesPerLineB); |
|
414 |
|
415 QPainterVideoSurface surface; |
|
416 |
|
417 QImage image(320, 240, QImage::Format_RGB32); |
|
418 |
|
419 QSignalSpy frameSpy(&surface, SIGNAL(frameChanged())); |
|
420 |
|
421 const QList<QVideoFrame::PixelFormat> pixelFormats = surface.supportedPixelFormats(); |
|
422 |
|
423 { // Test painting before started. |
|
424 QPainter painter(&image); |
|
425 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
426 } |
|
427 |
|
428 QVideoSurfaceFormat formatA(frameSizeA, pixelFormatA); |
|
429 |
|
430 QVERIFY(surface.start(formatA)); |
|
431 QCOMPARE(surface.isActive(), true); |
|
432 QCOMPARE(surface.isReady(), true); |
|
433 |
|
434 { // Test painting before receiving a frame. |
|
435 QPainter painter(&image); |
|
436 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
437 } |
|
438 QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); |
|
439 |
|
440 QVideoFrame frameA(bytesA, frameSizeA, bytesPerLineA, pixelFormatA); |
|
441 |
|
442 frameA.map(QAbstractVideoBuffer::WriteOnly); |
|
443 memcpy(frameA.bits(), frameDataA, frameA.mappedBytes()); |
|
444 frameA.unmap(); |
|
445 |
|
446 QVERIFY(surface.present(frameA)); |
|
447 QCOMPARE(surface.isReady(), false); |
|
448 QCOMPARE(frameSpy.count(), 1); |
|
449 |
|
450 { |
|
451 QPainter painter(&image); |
|
452 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
453 } |
|
454 QCOMPARE(surface.isActive(), true); |
|
455 QCOMPARE(surface.isReady(), false); |
|
456 |
|
457 { // Test repainting before receiving another frame. |
|
458 QPainter painter(&image); |
|
459 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
460 } |
|
461 QCOMPARE(surface.isActive(), true); |
|
462 QCOMPARE(surface.isReady(), false); |
|
463 |
|
464 // Not ready. |
|
465 QVERIFY(!surface.present(frameA)); |
|
466 QCOMPARE(frameSpy.count(), 1); |
|
467 |
|
468 surface.setReady(true); |
|
469 QCOMPARE(surface.isReady(), true); |
|
470 QVERIFY(surface.present(frameA)); |
|
471 QCOMPARE(frameSpy.count(), 2); |
|
472 |
|
473 // Try switching to a different format after starting. |
|
474 QVideoSurfaceFormat formatB(frameSizeB, pixelFormatB); |
|
475 |
|
476 QVERIFY(surface.start(formatB)); |
|
477 QCOMPARE(surface.isActive(), true); |
|
478 QCOMPARE(surface.isReady(), true); |
|
479 |
|
480 QVideoFrame frameB(bytesB, frameSizeB, bytesPerLineB, pixelFormatB); |
|
481 |
|
482 frameB.map(QAbstractVideoBuffer::WriteOnly); |
|
483 memcpy(frameB.bits(), frameDataB, frameB.mappedBytes()); |
|
484 frameB.unmap(); |
|
485 |
|
486 QVERIFY(surface.present(frameB)); |
|
487 QCOMPARE(surface.isReady(), false); |
|
488 QCOMPARE(frameSpy.count(), 3); |
|
489 |
|
490 { |
|
491 QPainter painter(&image); |
|
492 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
493 } |
|
494 QVERIFY(surface.isActive()); |
|
495 |
|
496 surface.stop(); |
|
497 |
|
498 QCOMPARE(surface.isActive(), false); |
|
499 QCOMPARE(surface.isReady(), false); |
|
500 |
|
501 // Try presenting a frame while stopped. |
|
502 QVERIFY(!surface.present(frameB)); |
|
503 QCOMPARE(surface.isReady(), false); |
|
504 QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); |
|
505 |
|
506 // Try presenting a frame with a different format. |
|
507 QVERIFY(surface.start(formatB)); |
|
508 QVERIFY(!surface.present(frameA)); |
|
509 QCOMPARE(surface.isActive(), false); |
|
510 QCOMPARE(surface.isReady(), false); |
|
511 QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); |
|
512 } |
|
513 |
|
514 void tst_QPainterVideoSurface::presentOpaqueFrame() |
|
515 { |
|
516 QPainterVideoSurface surface; |
|
517 |
|
518 QImage image(320, 240, QImage::Format_RGB32); |
|
519 |
|
520 QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); |
|
521 |
|
522 QVERIFY(surface.start(format)); |
|
523 QCOMPARE(surface.isActive(), true); |
|
524 QCOMPARE(surface.isReady(), true); |
|
525 |
|
526 QVideoFrame frame(new QtTestOpaqueVideoBuffer, QSize(64, 64), QVideoFrame::Format_RGB32); |
|
527 |
|
528 if (surface.present(frame)) { |
|
529 QPainter painter(&image); |
|
530 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
531 } |
|
532 |
|
533 QCOMPARE(surface.isActive(), false); |
|
534 QCOMPARE(surface.isReady(), false); |
|
535 QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); |
|
536 } |
|
537 |
|
538 #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) |
|
539 |
|
540 void tst_QPainterVideoSurface::shaderType() |
|
541 { |
|
542 QPainterVideoSurface surface; |
|
543 QGLWidget widget; |
|
544 widget.makeCurrent(); |
|
545 |
|
546 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
547 QCOMPARE(surface.supportedShaderTypes(), QPainterVideoSurface::NoShaders); |
|
548 |
|
549 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
550 QCOMPARE(surface.glContext(), widget.context()); |
|
551 |
|
552 { |
|
553 QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); |
|
554 |
|
555 surface.setShaderType(QPainterVideoSurface::NoShaders); |
|
556 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
557 QCOMPARE(spy.count(), 0); |
|
558 } |
|
559 |
|
560 #ifndef QT_OPENGL_ES |
|
561 if (surface.supportedShaderTypes() & QPainterVideoSurface::FragmentProgramShader) { |
|
562 QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); |
|
563 |
|
564 surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); |
|
565 QCOMPARE(surface.shaderType(), QPainterVideoSurface::FragmentProgramShader); |
|
566 QCOMPARE(spy.count(), 1); |
|
567 |
|
568 surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); |
|
569 QCOMPARE(surface.shaderType(), QPainterVideoSurface::FragmentProgramShader); |
|
570 QCOMPARE(spy.count(), 1); |
|
571 } |
|
572 #endif |
|
573 |
|
574 if (surface.supportedShaderTypes() & QPainterVideoSurface::GlslShader) { |
|
575 QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); |
|
576 |
|
577 surface.setShaderType(QPainterVideoSurface::GlslShader); |
|
578 QCOMPARE(surface.shaderType(), QPainterVideoSurface::GlslShader); |
|
579 QCOMPARE(spy.count(), 1); |
|
580 |
|
581 surface.setShaderType(QPainterVideoSurface::GlslShader); |
|
582 QCOMPARE(surface.shaderType(), QPainterVideoSurface::GlslShader); |
|
583 QCOMPARE(spy.count(), 1); |
|
584 } |
|
585 |
|
586 { |
|
587 QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); |
|
588 |
|
589 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
590 QCOMPARE(surface.glContext(), widget.context()); |
|
591 QCOMPARE(spy.count(), 0); |
|
592 } |
|
593 |
|
594 surface.setGLContext(0); |
|
595 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
596 QCOMPARE(surface.supportedShaderTypes(), QPainterVideoSurface::NoShaders); |
|
597 |
|
598 { |
|
599 QSignalSpy spy(&surface, SIGNAL(supportedFormatsChanged())); |
|
600 |
|
601 surface.setShaderType(QPainterVideoSurface::NoShaders); |
|
602 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
603 QCOMPARE(spy.count(), 0); |
|
604 |
|
605 #ifndef QT_OPENGL_ES |
|
606 surface.setShaderType(QPainterVideoSurface::FragmentProgramShader); |
|
607 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
608 QCOMPARE(spy.count(), 0); |
|
609 #endif |
|
610 |
|
611 surface.setShaderType(QPainterVideoSurface::GlslShader); |
|
612 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
613 QCOMPARE(spy.count(), 0); |
|
614 } |
|
615 } |
|
616 |
|
617 void tst_QPainterVideoSurface::shaderTypeStarted_data() |
|
618 { |
|
619 QTest::addColumn<QPainterVideoSurface::ShaderType>("shaderType"); |
|
620 |
|
621 #ifndef QT_OPENGL_ES |
|
622 QTest::newRow("ARBfp") |
|
623 << QPainterVideoSurface::FragmentProgramShader; |
|
624 #endif |
|
625 QTest::newRow("GLSL") |
|
626 << QPainterVideoSurface::GlslShader; |
|
627 } |
|
628 |
|
629 void tst_QPainterVideoSurface::shaderTypeStarted() |
|
630 { |
|
631 QFETCH(QPainterVideoSurface::ShaderType, shaderType); |
|
632 |
|
633 QGLWidget widget; |
|
634 widget.makeCurrent(); |
|
635 |
|
636 QPainterVideoSurface surface; |
|
637 |
|
638 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
639 |
|
640 if (!(surface.supportedShaderTypes() & shaderType)) |
|
641 QSKIP("Shader type unsupported on this platform", SkipSingle); |
|
642 |
|
643 surface.setShaderType(shaderType); |
|
644 QCOMPARE(surface.shaderType(), shaderType); |
|
645 |
|
646 QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); |
|
647 { |
|
648 QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); |
|
649 |
|
650 surface.setShaderType(QPainterVideoSurface::NoShaders); |
|
651 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
652 QCOMPARE(surface.isActive(), false); |
|
653 QCOMPARE(spy.count(), 1); |
|
654 QCOMPARE(spy.last().value(0).toBool(), false); |
|
655 } |
|
656 |
|
657 QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); |
|
658 { |
|
659 QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); |
|
660 |
|
661 surface.setShaderType(QPainterVideoSurface::NoShaders); |
|
662 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
663 QCOMPARE(surface.isActive(), true); |
|
664 QCOMPARE(spy.count(), 0); |
|
665 |
|
666 surface.setShaderType(shaderType); |
|
667 QCOMPARE(surface.shaderType(), shaderType); |
|
668 QCOMPARE(surface.isActive(), false); |
|
669 QCOMPARE(spy.count(), 1); |
|
670 QCOMPARE(spy.last().value(0).toBool(), false); |
|
671 } |
|
672 |
|
673 QVERIFY(surface.start(QVideoSurfaceFormat(QSize(640, 480), QVideoFrame::Format_RGB32))); |
|
674 { |
|
675 QSignalSpy spy(&surface, SIGNAL(activeChanged(bool))); |
|
676 |
|
677 surface.setShaderType(shaderType); |
|
678 QCOMPARE(surface.shaderType(), shaderType); |
|
679 QCOMPARE(surface.isActive(), true); |
|
680 QCOMPARE(spy.count(), 0); |
|
681 |
|
682 surface.setGLContext(0); |
|
683 QCOMPARE(surface.shaderType(), QPainterVideoSurface::NoShaders); |
|
684 QCOMPARE(surface.isActive(), false); |
|
685 QCOMPARE(spy.count(), 1); |
|
686 QCOMPARE(spy.last().value(0).toBool(), false); |
|
687 } |
|
688 } |
|
689 |
|
690 void tst_QPainterVideoSurface::shaderSupportedFormat_data() |
|
691 { |
|
692 QTest::addColumn<QPainterVideoSurface::ShaderType>("shaderType"); |
|
693 QTest::addColumn<QAbstractVideoBuffer::HandleType>("handleType"); |
|
694 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormat"); |
|
695 QTest::addColumn<QSize>("frameSize"); |
|
696 QTest::addColumn<bool>("supportedPixelFormat"); |
|
697 QTest::addColumn<bool>("supportedFormat"); |
|
698 |
|
699 QList<QPair<QPainterVideoSurface::ShaderType, QByteArray> > types; |
|
700 #ifndef QT_OPENGL_ES |
|
701 types << qMakePair(QPainterVideoSurface::FragmentProgramShader, QByteArray("ARBfp: ")); |
|
702 #endif |
|
703 types << qMakePair(QPainterVideoSurface::GlslShader, QByteArray("GLSL: ")); |
|
704 |
|
705 QPair<QPainterVideoSurface::ShaderType, QByteArray> type; |
|
706 foreach (type, types) { |
|
707 QTest::newRow((type.second + "rgb32 640x480").constData()) |
|
708 << type.first |
|
709 << QAbstractVideoBuffer::NoHandle |
|
710 << QVideoFrame::Format_RGB32 |
|
711 << QSize(640, 480) |
|
712 << true |
|
713 << true; |
|
714 QTest::newRow((type.second + "rgb32 -640x480").constData()) |
|
715 << type.first |
|
716 << QAbstractVideoBuffer::NoHandle |
|
717 << QVideoFrame::Format_RGB32 |
|
718 << QSize(-640, 480) |
|
719 << true |
|
720 << false; |
|
721 QTest::newRow((type.second + "rgb565 32x32").constData()) |
|
722 << type.first |
|
723 << QAbstractVideoBuffer::NoHandle |
|
724 << QVideoFrame::Format_RGB565 |
|
725 << QSize(32, 32) |
|
726 << true |
|
727 << true; |
|
728 QTest::newRow((type.second + "rgb565 0x0").constData()) |
|
729 << type.first |
|
730 << QAbstractVideoBuffer::NoHandle |
|
731 << QVideoFrame::Format_RGB565 |
|
732 << QSize(0, 0) |
|
733 << true |
|
734 << false; |
|
735 QTest::newRow((type.second + "argb32 256x256").constData()) |
|
736 << type.first |
|
737 << QAbstractVideoBuffer::NoHandle |
|
738 << QVideoFrame::Format_ARGB32 |
|
739 << QSize(256, 256) |
|
740 << true |
|
741 << true; |
|
742 QTest::newRow((type.second + "rgb24 1024x768").constData()) |
|
743 << type.first |
|
744 << QAbstractVideoBuffer::NoHandle |
|
745 << QVideoFrame::Format_RGB24 |
|
746 << QSize(1024, 768) |
|
747 << true |
|
748 << true; |
|
749 QTest::newRow((type.second + "rgb24 -1024x-768").constData()) |
|
750 << type.first |
|
751 << QAbstractVideoBuffer::NoHandle |
|
752 << QVideoFrame::Format_RGB24 |
|
753 << QSize(-1024, -768) |
|
754 << true |
|
755 << false; |
|
756 QTest::newRow((type.second + "YUV420P 640x480").constData()) |
|
757 << type.first |
|
758 << QAbstractVideoBuffer::NoHandle |
|
759 << QVideoFrame::Format_YUV420P |
|
760 << QSize(640, 480) |
|
761 << true |
|
762 << true; |
|
763 QTest::newRow((type.second + "YUV420P 640x-480").constData()) |
|
764 << type.first |
|
765 << QAbstractVideoBuffer::NoHandle |
|
766 << QVideoFrame::Format_YUV420P |
|
767 << QSize(640, -480) |
|
768 << true |
|
769 << false; |
|
770 QTest::newRow((type.second + "Y8 640x480").constData()) |
|
771 << type.first |
|
772 << QAbstractVideoBuffer::NoHandle |
|
773 << QVideoFrame::Format_Y8 |
|
774 << QSize(640, 480) |
|
775 << false |
|
776 << false; |
|
777 QTest::newRow((type.second + "Texture: rgb32 640x480").constData()) |
|
778 << type.first |
|
779 << QAbstractVideoBuffer::GLTextureHandle |
|
780 << QVideoFrame::Format_RGB32 |
|
781 << QSize(640, 480) |
|
782 << true |
|
783 << true; |
|
784 QTest::newRow((type.second + "Texture: rgb32 -640x480").constData()) |
|
785 << type.first |
|
786 << QAbstractVideoBuffer::GLTextureHandle |
|
787 << QVideoFrame::Format_RGB32 |
|
788 << QSize(-640, 480) |
|
789 << true |
|
790 << false; |
|
791 QTest::newRow((type.second + "Texture: rgb565 32x32").constData()) |
|
792 << type.first |
|
793 << QAbstractVideoBuffer::GLTextureHandle |
|
794 << QVideoFrame::Format_RGB565 |
|
795 << QSize(32, 32) |
|
796 << false |
|
797 << false; |
|
798 QTest::newRow((type.second + "Texture: rgb565 0x0").constData()) |
|
799 << type.first |
|
800 << QAbstractVideoBuffer::GLTextureHandle |
|
801 << QVideoFrame::Format_RGB565 |
|
802 << QSize(0, 0) |
|
803 << false |
|
804 << false; |
|
805 QTest::newRow((type.second + "Texture argb32 256x256").constData()) |
|
806 << type.first |
|
807 << QAbstractVideoBuffer::GLTextureHandle |
|
808 << QVideoFrame::Format_ARGB32 |
|
809 << QSize(256, 256) |
|
810 << true |
|
811 << true; |
|
812 QTest::newRow((type.second + "Texture: rgb24 1024x768").constData()) |
|
813 << type.first |
|
814 << QAbstractVideoBuffer::GLTextureHandle |
|
815 << QVideoFrame::Format_RGB24 |
|
816 << QSize(1024, 768) |
|
817 << false |
|
818 << false; |
|
819 QTest::newRow((type.second + "Texture: rgb24 -1024x-768").constData()) |
|
820 << type.first |
|
821 << QAbstractVideoBuffer::GLTextureHandle |
|
822 << QVideoFrame::Format_RGB24 |
|
823 << QSize(-1024, -768) |
|
824 << false |
|
825 << false; |
|
826 QTest::newRow((type.second + "Texture: YUV420P 640x480").constData()) |
|
827 << type.first |
|
828 << QAbstractVideoBuffer::GLTextureHandle |
|
829 << QVideoFrame::Format_YUV420P |
|
830 << QSize(640, 480) |
|
831 << false |
|
832 << false; |
|
833 QTest::newRow((type.second + "Texture: YUV420P 640x-480").constData()) |
|
834 << type.first |
|
835 << QAbstractVideoBuffer::GLTextureHandle |
|
836 << QVideoFrame::Format_YUV420P |
|
837 << QSize(640, -480) |
|
838 << false |
|
839 << false; |
|
840 QTest::newRow(type.second + "User Buffer: rgb32 256x256") |
|
841 << type.first |
|
842 << QAbstractVideoBuffer::UserHandle |
|
843 << QVideoFrame::Format_RGB32 |
|
844 << QSize(256, 256) |
|
845 << false |
|
846 << false; |
|
847 } |
|
848 } |
|
849 |
|
850 void tst_QPainterVideoSurface::shaderSupportedFormat() |
|
851 { |
|
852 QFETCH(QPainterVideoSurface::ShaderType, shaderType); |
|
853 QFETCH(QAbstractVideoBuffer::HandleType, handleType); |
|
854 QFETCH(QVideoFrame::PixelFormat, pixelFormat); |
|
855 QFETCH(QSize, frameSize); |
|
856 QFETCH(bool, supportedPixelFormat); |
|
857 QFETCH(bool, supportedFormat); |
|
858 |
|
859 QGLWidget widget; |
|
860 widget.makeCurrent(); |
|
861 |
|
862 QPainterVideoSurface surface; |
|
863 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
864 |
|
865 |
|
866 if (!(surface.supportedShaderTypes() & shaderType)) |
|
867 QSKIP("Shader type not supported on this platform", SkipSingle); |
|
868 |
|
869 surface.setShaderType(shaderType); |
|
870 if (surface.shaderType() != shaderType) |
|
871 QSKIP("Shader type couldn't be set", SkipSingle); |
|
872 |
|
873 const QList<QVideoFrame::PixelFormat> pixelFormats = surface.supportedPixelFormats(handleType); |
|
874 |
|
875 QCOMPARE(pixelFormats.contains(pixelFormat), QBool(supportedPixelFormat)); |
|
876 |
|
877 QVideoSurfaceFormat format(frameSize, pixelFormat, handleType); |
|
878 |
|
879 QCOMPARE(surface.isFormatSupported(format), supportedFormat); |
|
880 QCOMPARE(surface.start(format), supportedFormat); |
|
881 } |
|
882 |
|
883 void tst_QPainterVideoSurface::shaderPresent_data() |
|
884 { |
|
885 QTest::addColumn<QPainterVideoSurface::ShaderType>("shaderType"); |
|
886 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormatA"); |
|
887 QTest::addColumn<QSize>("frameSizeA"); |
|
888 QTest::addColumn<const uchar *>("frameDataA"); |
|
889 QTest::addColumn<int>("bytesA"); |
|
890 QTest::addColumn<int>("bytesPerLineA"); |
|
891 QTest::addColumn<QVideoFrame::PixelFormat>("pixelFormatB"); |
|
892 QTest::addColumn<QSize>("frameSizeB"); |
|
893 QTest::addColumn<const uchar *>("frameDataB"); |
|
894 QTest::addColumn<int>("bytesB"); |
|
895 QTest::addColumn<int>("bytesPerLineB"); |
|
896 |
|
897 QList<QPair<QPainterVideoSurface::ShaderType, QByteArray> > types; |
|
898 #ifndef QT_OPENGL_ES |
|
899 types << qMakePair(QPainterVideoSurface::FragmentProgramShader, QByteArray("ARBfp: ")); |
|
900 #endif |
|
901 types << qMakePair(QPainterVideoSurface::GlslShader, QByteArray("GLSL: ")); |
|
902 |
|
903 QPair<QPainterVideoSurface::ShaderType, QByteArray> type; |
|
904 foreach (type, types) { |
|
905 QTest::newRow((type.second + "rgb32 -> argb32").constData()) |
|
906 << type.first |
|
907 << QVideoFrame::Format_RGB32 |
|
908 << QSize(2, 2) |
|
909 << static_cast<const uchar *>(rgb32ImageData) |
|
910 << int(sizeof(rgb32ImageData)) |
|
911 << 8 |
|
912 << QVideoFrame::Format_ARGB32 |
|
913 << QSize(2, 2) |
|
914 << static_cast<const uchar *>(argb32ImageData) |
|
915 << int(sizeof(argb32ImageData)) |
|
916 << 8; |
|
917 |
|
918 QTest::newRow((type.second + "rgb32 -> rgb565").constData()) |
|
919 << type.first |
|
920 << QVideoFrame::Format_RGB32 |
|
921 << QSize(2, 2) |
|
922 << static_cast<const uchar *>(rgb32ImageData) |
|
923 << int(sizeof(rgb32ImageData)) |
|
924 << 8 |
|
925 << QVideoFrame::Format_RGB565 |
|
926 << QSize(2, 2) |
|
927 << static_cast<const uchar *>(rgb565ImageData) |
|
928 << int(sizeof(rgb565ImageData)) |
|
929 << 4; |
|
930 |
|
931 QTest::newRow((type.second + "rgb32 -> yuv420p").constData()) |
|
932 << type.first |
|
933 << QVideoFrame::Format_RGB32 |
|
934 << QSize(2, 2) |
|
935 << static_cast<const uchar *>(rgb32ImageData) |
|
936 << int(sizeof(rgb32ImageData)) |
|
937 << 8 |
|
938 << QVideoFrame::Format_YUV420P |
|
939 << QSize(8, 8) |
|
940 << static_cast<const uchar *>(yuvPlanarImageData) |
|
941 << int(sizeof(yuvPlanarImageData)) |
|
942 << 8; |
|
943 |
|
944 QTest::newRow((type.second + "yv12 -> rgb32").constData()) |
|
945 << type.first |
|
946 << QVideoFrame::Format_YV12 |
|
947 << QSize(8, 8) |
|
948 << static_cast<const uchar *>(yuvPlanarImageData) |
|
949 << int(sizeof(yuvPlanarImageData)) |
|
950 << 8 |
|
951 << QVideoFrame::Format_RGB32 |
|
952 << QSize(2, 2) |
|
953 << static_cast<const uchar *>(rgb32ImageData) |
|
954 << int(sizeof(rgb32ImageData)) |
|
955 << 8; |
|
956 } |
|
957 } |
|
958 |
|
959 void tst_QPainterVideoSurface::shaderPresent() |
|
960 { |
|
961 QFETCH(QPainterVideoSurface::ShaderType, shaderType); |
|
962 QFETCH(QVideoFrame::PixelFormat, pixelFormatA); |
|
963 QFETCH(QSize, frameSizeA); |
|
964 QFETCH(const uchar *, frameDataA); |
|
965 QFETCH(int, bytesA); |
|
966 QFETCH(int, bytesPerLineA); |
|
967 QFETCH(QVideoFrame::PixelFormat, pixelFormatB); |
|
968 QFETCH(QSize, frameSizeB); |
|
969 QFETCH(const uchar *, frameDataB); |
|
970 QFETCH(int, bytesB); |
|
971 QFETCH(int, bytesPerLineB); |
|
972 |
|
973 QGLWidget widget; |
|
974 widget.makeCurrent(); |
|
975 |
|
976 QPainterVideoSurface surface; |
|
977 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
978 |
|
979 if (!(surface.supportedShaderTypes() & shaderType)) |
|
980 QSKIP("Shader type unsupported on this platform", SkipSingle); |
|
981 |
|
982 surface.setShaderType(shaderType); |
|
983 if (surface.shaderType() != shaderType) |
|
984 QSKIP("Shader type couldn't be set", SkipSingle); |
|
985 |
|
986 QSignalSpy frameSpy(&surface, SIGNAL(frameChanged())); |
|
987 |
|
988 { // Test painting before starting the surface. |
|
989 QPainter painter(&widget); |
|
990 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
991 } |
|
992 QCOMPARE(surface.error(), QAbstractVideoSurface::NoError); |
|
993 |
|
994 QVideoSurfaceFormat formatA(frameSizeA, pixelFormatA); |
|
995 |
|
996 QVERIFY(surface.start(formatA)); |
|
997 QCOMPARE(surface.isActive(), true); |
|
998 QCOMPARE(surface.isReady(), true); |
|
999 |
|
1000 // Test painting before receiving a frame. |
|
1001 { |
|
1002 QPainter painter(&widget); |
|
1003 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1004 } |
|
1005 QCOMPARE(surface.isActive(), true); |
|
1006 QCOMPARE(surface.isReady(), true); |
|
1007 |
|
1008 QVideoFrame frameA(bytesA, frameSizeA, bytesPerLineA, pixelFormatA); |
|
1009 |
|
1010 frameA.map(QAbstractVideoBuffer::WriteOnly); |
|
1011 memcpy(frameA.bits(), frameDataA, frameA.mappedBytes()); |
|
1012 frameA.unmap(); |
|
1013 |
|
1014 QVERIFY(surface.present(frameA)); |
|
1015 QCOMPARE(surface.isReady(), false); |
|
1016 QCOMPARE(frameSpy.count(), 1); |
|
1017 |
|
1018 { |
|
1019 QPainter painter(&widget); |
|
1020 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1021 } |
|
1022 QCOMPARE(surface.isActive(), true); |
|
1023 QCOMPARE(surface.isReady(), false); |
|
1024 |
|
1025 { // Test repainting before receiving another frame. |
|
1026 QPainter painter(&widget); |
|
1027 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1028 } |
|
1029 QCOMPARE(surface.isActive(), true); |
|
1030 QCOMPARE(surface.isReady(), false); |
|
1031 |
|
1032 // Not ready. |
|
1033 QVERIFY(!surface.present(frameA)); |
|
1034 QCOMPARE(frameSpy.count(), 1); |
|
1035 |
|
1036 surface.setReady(true); |
|
1037 QCOMPARE(surface.isReady(), true); |
|
1038 QVERIFY(surface.present(frameA)); |
|
1039 QCOMPARE(frameSpy.count(), 2); |
|
1040 |
|
1041 // Try switching to a different format after starting. |
|
1042 QVideoSurfaceFormat formatB(frameSizeB, pixelFormatB); |
|
1043 |
|
1044 QVERIFY(surface.start(formatB)); |
|
1045 QCOMPARE(surface.isActive(), true); |
|
1046 QCOMPARE(surface.isReady(), true); |
|
1047 |
|
1048 QVideoFrame frameB(bytesB, frameSizeB, bytesPerLineB, pixelFormatB); |
|
1049 |
|
1050 frameB.map(QAbstractVideoBuffer::WriteOnly); |
|
1051 memcpy(frameB.bits(), frameDataB, frameB.mappedBytes()); |
|
1052 frameB.unmap(); |
|
1053 |
|
1054 QVERIFY(surface.present(frameB)); |
|
1055 QCOMPARE(surface.isReady(), false); |
|
1056 QCOMPARE(frameSpy.count(), 3); |
|
1057 |
|
1058 { |
|
1059 QPainter painter(&widget); |
|
1060 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1061 } |
|
1062 QCOMPARE(surface.isActive(), true); |
|
1063 |
|
1064 surface.stop(); |
|
1065 QCOMPARE(surface.isActive(), false); |
|
1066 QCOMPARE(surface.isReady(), false); |
|
1067 |
|
1068 // Try presenting a frame while stopped. |
|
1069 QVERIFY(!surface.present(frameB)); |
|
1070 QCOMPARE(surface.isReady(), false); |
|
1071 QCOMPARE(surface.error(), QAbstractVideoSurface::StoppedError); |
|
1072 |
|
1073 // Try stopping while already stopped. |
|
1074 surface.stop(); |
|
1075 QCOMPARE(surface.isActive(), false); |
|
1076 QCOMPARE(surface.isReady(), false); |
|
1077 |
|
1078 // Try presenting a frame with a different format. |
|
1079 QVERIFY(surface.start(formatB)); |
|
1080 QVERIFY(!surface.present(frameA)); |
|
1081 QCOMPARE(surface.isActive(), false); |
|
1082 QCOMPARE(surface.isReady(), false); |
|
1083 QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); |
|
1084 } |
|
1085 |
|
1086 void tst_QPainterVideoSurface::shaderPresentOpaqueFrame_data() |
|
1087 { |
|
1088 QTest::addColumn<QPainterVideoSurface::ShaderType>("shaderType"); |
|
1089 |
|
1090 #ifndef QT_OPENGL_ES |
|
1091 QTest::newRow("ARBfp") |
|
1092 << QPainterVideoSurface::FragmentProgramShader; |
|
1093 #endif |
|
1094 QTest::newRow("GLSL") |
|
1095 << QPainterVideoSurface::GlslShader; |
|
1096 } |
|
1097 |
|
1098 void tst_QPainterVideoSurface::shaderPresentOpaqueFrame() |
|
1099 { |
|
1100 QFETCH(QPainterVideoSurface::ShaderType, shaderType); |
|
1101 |
|
1102 QGLWidget widget; |
|
1103 widget.makeCurrent(); |
|
1104 |
|
1105 QPainterVideoSurface surface; |
|
1106 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
1107 |
|
1108 if (!(surface.supportedShaderTypes() & shaderType)) |
|
1109 QSKIP("Shader type unsupported on this platform", SkipSingle); |
|
1110 |
|
1111 surface.setShaderType(shaderType); |
|
1112 if (surface.shaderType() != shaderType) |
|
1113 QSKIP("Shader type couldn't be set", SkipSingle); |
|
1114 |
|
1115 QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); |
|
1116 |
|
1117 QVERIFY(surface.start(format)); |
|
1118 QCOMPARE(surface.isActive(), true); |
|
1119 QCOMPARE(surface.isReady(), true); |
|
1120 |
|
1121 QVideoFrame frame(new QtTestOpaqueVideoBuffer, QSize(64, 64), QVideoFrame::Format_RGB32); |
|
1122 |
|
1123 if (surface.present(frame)) { |
|
1124 QPainter painter(&widget); |
|
1125 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1126 } |
|
1127 |
|
1128 QCOMPARE(surface.isActive(), false); |
|
1129 QCOMPARE(surface.isReady(), false); |
|
1130 QCOMPARE(surface.error(), QAbstractVideoSurface::IncorrectFormatError); |
|
1131 } |
|
1132 |
|
1133 void tst_QPainterVideoSurface::shaderPresentGLFrame_data() |
|
1134 { |
|
1135 QTest::addColumn<QPainterVideoSurface::ShaderType>("shaderType"); |
|
1136 |
|
1137 #ifndef QT_OPENGL_ES |
|
1138 QTest::newRow("ARBfp") |
|
1139 << QPainterVideoSurface::FragmentProgramShader; |
|
1140 #endif |
|
1141 QTest::newRow("GLSL") |
|
1142 << QPainterVideoSurface::GlslShader; |
|
1143 } |
|
1144 |
|
1145 void tst_QPainterVideoSurface::shaderPresentGLFrame() |
|
1146 { |
|
1147 QFETCH(QPainterVideoSurface::ShaderType, shaderType); |
|
1148 |
|
1149 QGLWidget widget; |
|
1150 widget.makeCurrent(); |
|
1151 |
|
1152 QPainterVideoSurface surface; |
|
1153 surface.setGLContext(const_cast<QGLContext *>(widget.context())); |
|
1154 |
|
1155 if (!(surface.supportedShaderTypes() & shaderType)) |
|
1156 QSKIP("Shader type unsupported on this platform", SkipSingle); |
|
1157 |
|
1158 surface.setShaderType(shaderType); |
|
1159 if (surface.shaderType() != shaderType) |
|
1160 QSKIP("Shader type couldn't be set", SkipSingle); |
|
1161 |
|
1162 QVideoSurfaceFormat format( |
|
1163 QSize(2, 2), QVideoFrame::Format_RGB32, QAbstractVideoBuffer::GLTextureHandle); |
|
1164 |
|
1165 QVERIFY(surface.start(format)); |
|
1166 QCOMPARE(surface.isActive(), true); |
|
1167 QCOMPARE(surface.isReady(), true); |
|
1168 |
|
1169 QtTestGLVideoBuffer *buffer = new QtTestGLVideoBuffer; |
|
1170 |
|
1171 glBindTexture(GL_TEXTURE_2D, buffer->textureId()); |
|
1172 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb32ImageData); |
|
1173 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
1174 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
|
1175 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
|
1176 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
|
1177 |
|
1178 QVideoFrame frame(buffer, QSize(2, 2), QVideoFrame::Format_RGB32); |
|
1179 |
|
1180 QVERIFY(surface.present(frame)); |
|
1181 |
|
1182 { |
|
1183 QPainter painter(&widget); |
|
1184 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1185 } |
|
1186 |
|
1187 QCOMPARE(surface.isActive(), true); |
|
1188 QCOMPARE(surface.isReady(), false); |
|
1189 |
|
1190 { |
|
1191 QPainter painter(&widget); |
|
1192 surface.paint(&painter, QRect(0, 0, 320, 240)); |
|
1193 } |
|
1194 |
|
1195 QCOMPARE(surface.isActive(), true); |
|
1196 QCOMPARE(surface.isReady(), false); |
|
1197 } |
|
1198 |
|
1199 #endif |
|
1200 |
|
1201 QTEST_MAIN(tst_QPainterVideoSurface) |
|
1202 |
|
1203 #include "tst_qpaintervideosurface.moc" |