1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | //TESTED_COMPONENT=src/multimedia |
30 | |
31 | #include <qtmultimediaglobal.h> |
32 | #include "qgraphicsvideoitem.h" |
33 | #include <QtTest/QtTest> |
34 | #include "qmediaobject.h" |
35 | #include "qmediaservice.h" |
36 | #include <private/qpaintervideosurface_p.h> |
37 | #include "qvideorenderercontrol.h" |
38 | |
39 | #include <qabstractvideosurface.h> |
40 | #include <qvideosurfaceformat.h> |
41 | |
42 | #include <QtWidgets/qapplication.h> |
43 | #include <QtWidgets/qgraphicsscene.h> |
44 | #include <QtWidgets/qgraphicsview.h> |
45 | |
46 | QT_USE_NAMESPACE |
47 | class tst_QGraphicsVideoItem : public QObject |
48 | { |
49 | Q_OBJECT |
50 | public slots: |
51 | void initTestCase(); |
52 | |
53 | private slots: |
54 | void nullObject(); |
55 | void nullService(); |
56 | void noOutputs(); |
57 | void serviceDestroyed(); |
58 | void mediaObjectDestroyed(); |
59 | void setMediaObject(); |
60 | |
61 | void show(); |
62 | |
63 | void aspectRatioMode(); |
64 | void offset(); |
65 | void size(); |
66 | void nativeSize_data(); |
67 | void nativeSize(); |
68 | |
69 | void boundingRect_data(); |
70 | void boundingRect(); |
71 | |
72 | void paint(); |
73 | void paintSurface(); |
74 | }; |
75 | |
76 | Q_DECLARE_METATYPE(const uchar *) |
77 | Q_DECLARE_METATYPE(Qt::AspectRatioMode) |
78 | |
79 | class QtTestRendererControl : public QVideoRendererControl |
80 | { |
81 | public: |
82 | QtTestRendererControl() |
83 | : m_surface(0) |
84 | { |
85 | } |
86 | |
87 | QAbstractVideoSurface *surface() const { return m_surface; } |
88 | void setSurface(QAbstractVideoSurface *surface) { m_surface = surface; } |
89 | |
90 | private: |
91 | QAbstractVideoSurface *m_surface; |
92 | }; |
93 | |
94 | class QtTestVideoService : public QMediaService |
95 | { |
96 | Q_OBJECT |
97 | public: |
98 | QtTestVideoService( |
99 | QtTestRendererControl *renderer) |
100 | : QMediaService(0) |
101 | , rendererRef(0) |
102 | , rendererControl(renderer) |
103 | { |
104 | } |
105 | |
106 | ~QtTestVideoService() |
107 | { |
108 | delete rendererControl; |
109 | } |
110 | |
111 | QMediaControl *requestControl(const char *name) |
112 | { |
113 | if (qstrcmp(str1: name, QVideoRendererControl_iid) == 0 && rendererControl) { |
114 | rendererRef += 1; |
115 | |
116 | return rendererControl; |
117 | } else { |
118 | return 0; |
119 | } |
120 | } |
121 | |
122 | void releaseControl(QMediaControl *control) |
123 | { |
124 | Q_ASSERT(control); |
125 | |
126 | if (control == rendererControl) { |
127 | rendererRef -= 1; |
128 | |
129 | if (rendererRef == 0) |
130 | rendererControl->setSurface(0); |
131 | } |
132 | } |
133 | |
134 | int rendererRef; |
135 | QtTestRendererControl *rendererControl; |
136 | }; |
137 | |
138 | class QtTestVideoObject : public QMediaObject |
139 | { |
140 | Q_OBJECT |
141 | public: |
142 | QtTestVideoObject(QtTestRendererControl *renderer) |
143 | : QMediaObject(0, new QtTestVideoService(renderer)) |
144 | { |
145 | testService = qobject_cast<QtTestVideoService*>(object: service()); |
146 | } |
147 | |
148 | QtTestVideoObject(QtTestVideoService *service): |
149 | QMediaObject(0, service), |
150 | testService(service) |
151 | { |
152 | } |
153 | |
154 | ~QtTestVideoObject() |
155 | { |
156 | delete testService; |
157 | } |
158 | |
159 | QtTestVideoService *testService; |
160 | }; |
161 | |
162 | class QtTestGraphicsVideoItem : public QGraphicsVideoItem |
163 | { |
164 | public: |
165 | QtTestGraphicsVideoItem(QGraphicsItem *parent = 0) |
166 | : QGraphicsVideoItem(parent) |
167 | , m_paintCount(0) |
168 | { |
169 | } |
170 | |
171 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
172 | { |
173 | ++m_paintCount; |
174 | |
175 | QTestEventLoop::instance().exitLoop(); |
176 | |
177 | QGraphicsVideoItem::paint(painter, option, widget); |
178 | } |
179 | |
180 | bool waitForPaint(int secs) |
181 | { |
182 | const int paintCount = m_paintCount; |
183 | |
184 | QTestEventLoop::instance().enterLoop(secs); |
185 | |
186 | return m_paintCount != paintCount; |
187 | } |
188 | |
189 | int paintCount() const |
190 | { |
191 | return m_paintCount; |
192 | } |
193 | |
194 | private: |
195 | int m_paintCount; |
196 | }; |
197 | |
198 | void tst_QGraphicsVideoItem::initTestCase() |
199 | { |
200 | qRegisterMetaType<Qt::AspectRatioMode>(); |
201 | } |
202 | |
203 | void tst_QGraphicsVideoItem::nullObject() |
204 | { |
205 | QGraphicsVideoItem item(0); |
206 | |
207 | QVERIFY(item.boundingRect().isEmpty()); |
208 | } |
209 | |
210 | void tst_QGraphicsVideoItem::nullService() |
211 | { |
212 | QtTestVideoService *service = 0; |
213 | |
214 | QtTestVideoObject object(service); |
215 | |
216 | QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
217 | object.bind(item); |
218 | |
219 | QVERIFY(item->boundingRect().isEmpty()); |
220 | |
221 | item->hide(); |
222 | item->show(); |
223 | |
224 | QGraphicsScene graphicsScene; |
225 | graphicsScene.addItem(item); |
226 | QGraphicsView graphicsView(&graphicsScene); |
227 | graphicsView.show(); |
228 | } |
229 | |
230 | void tst_QGraphicsVideoItem::noOutputs() |
231 | { |
232 | QtTestRendererControl *control = 0; |
233 | QtTestVideoObject object(control); |
234 | |
235 | QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
236 | object.bind(item); |
237 | |
238 | QVERIFY(item->boundingRect().isEmpty()); |
239 | |
240 | item->hide(); |
241 | item->show(); |
242 | |
243 | QGraphicsScene graphicsScene; |
244 | graphicsScene.addItem(item); |
245 | QGraphicsView graphicsView(&graphicsScene); |
246 | graphicsView.show(); |
247 | } |
248 | |
249 | void tst_QGraphicsVideoItem::serviceDestroyed() |
250 | { |
251 | QtTestVideoObject object(new QtTestRendererControl); |
252 | |
253 | QGraphicsVideoItem item; |
254 | object.bind(&item); |
255 | |
256 | QCOMPARE(object.testService->rendererRef, 1); |
257 | |
258 | QtTestVideoService *service = object.testService; |
259 | object.testService = 0; |
260 | |
261 | delete service; |
262 | |
263 | QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
264 | QVERIFY(item.boundingRect().isEmpty()); |
265 | } |
266 | |
267 | void tst_QGraphicsVideoItem::mediaObjectDestroyed() |
268 | { |
269 | QtTestVideoObject *object = new QtTestVideoObject(new QtTestRendererControl); |
270 | |
271 | QGraphicsVideoItem item; |
272 | object->bind(&item); |
273 | |
274 | QCOMPARE(object->testService->rendererRef, 1); |
275 | |
276 | delete object; |
277 | object = 0; |
278 | |
279 | QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(object)); |
280 | QVERIFY(item.boundingRect().isEmpty()); |
281 | } |
282 | |
283 | void tst_QGraphicsVideoItem::setMediaObject() |
284 | { |
285 | QMediaObject *nullObject = 0; |
286 | QtTestVideoObject object(new QtTestRendererControl); |
287 | |
288 | QGraphicsVideoItem item; |
289 | |
290 | QCOMPARE(item.mediaObject(), nullObject); |
291 | QCOMPARE(object.testService->rendererRef, 0); |
292 | |
293 | object.bind(&item); |
294 | QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
295 | QCOMPARE(object.testService->rendererRef, 1); |
296 | QVERIFY(object.testService->rendererControl->surface() == 0); |
297 | |
298 | { // Surface setup is deferred until after the first paint. |
299 | QImage image(320, 240, QImage::Format_RGB32); |
300 | QPainter painter(&image); |
301 | |
302 | item.paint(painter: &painter, option: 0); |
303 | } |
304 | QVERIFY(object.testService->rendererControl->surface() != 0); |
305 | |
306 | object.unbind(&item); |
307 | QCOMPARE(item.mediaObject(), nullObject); |
308 | |
309 | QCOMPARE(object.testService->rendererRef, 0); |
310 | QVERIFY(object.testService->rendererControl->surface() == 0); |
311 | |
312 | item.setVisible(false); |
313 | |
314 | object.bind(&item); |
315 | QCOMPARE(item.mediaObject(), static_cast<QMediaObject *>(&object)); |
316 | QCOMPARE(object.testService->rendererRef, 1); |
317 | QVERIFY(object.testService->rendererControl->surface() != 0); |
318 | } |
319 | |
320 | void tst_QGraphicsVideoItem::show() |
321 | { |
322 | QtTestVideoObject object(new QtTestRendererControl); |
323 | QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
324 | object.bind(item); |
325 | |
326 | // Graphics items are visible by default |
327 | QCOMPARE(object.testService->rendererRef, 1); |
328 | QVERIFY(object.testService->rendererControl->surface() == 0); |
329 | |
330 | item->hide(); |
331 | QCOMPARE(object.testService->rendererRef, 1); |
332 | |
333 | item->show(); |
334 | QCOMPARE(object.testService->rendererRef, 1); |
335 | QVERIFY(object.testService->rendererControl->surface() == 0); |
336 | |
337 | QGraphicsScene graphicsScene; |
338 | graphicsScene.addItem(item); |
339 | QGraphicsView graphicsView(&graphicsScene); |
340 | graphicsView.show(); |
341 | |
342 | QVERIFY(item->paintCount() || item->waitForPaint(1)); |
343 | QVERIFY(object.testService->rendererControl->surface() != 0); |
344 | |
345 | QVERIFY(item->boundingRect().isEmpty()); |
346 | |
347 | QVideoSurfaceFormat format(QSize(320,240),QVideoFrame::Format_RGB32); |
348 | QVERIFY(object.testService->rendererControl->surface()->start(format)); |
349 | |
350 | QCoreApplication::processEvents(); |
351 | QVERIFY(!item->boundingRect().isEmpty()); |
352 | } |
353 | |
354 | void tst_QGraphicsVideoItem::aspectRatioMode() |
355 | { |
356 | QGraphicsVideoItem item; |
357 | |
358 | QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatio); |
359 | |
360 | item.setAspectRatioMode(Qt::IgnoreAspectRatio); |
361 | QCOMPARE(item.aspectRatioMode(), Qt::IgnoreAspectRatio); |
362 | |
363 | item.setAspectRatioMode(Qt::KeepAspectRatioByExpanding); |
364 | QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatioByExpanding); |
365 | |
366 | item.setAspectRatioMode(Qt::KeepAspectRatio); |
367 | QCOMPARE(item.aspectRatioMode(), Qt::KeepAspectRatio); |
368 | } |
369 | |
370 | void tst_QGraphicsVideoItem::offset() |
371 | { |
372 | QGraphicsVideoItem item; |
373 | |
374 | QCOMPARE(item.offset(), QPointF(0, 0)); |
375 | |
376 | item.setOffset(QPointF(-32.4, 43.0)); |
377 | QCOMPARE(item.offset(), QPointF(-32.4, 43.0)); |
378 | |
379 | item.setOffset(QPointF(1, 1)); |
380 | QCOMPARE(item.offset(), QPointF(1, 1)); |
381 | |
382 | item.setOffset(QPointF(12, -30.4)); |
383 | QCOMPARE(item.offset(), QPointF(12, -30.4)); |
384 | |
385 | item.setOffset(QPointF(-90.4, -75)); |
386 | QCOMPARE(item.offset(), QPointF(-90.4, -75)); |
387 | } |
388 | |
389 | void tst_QGraphicsVideoItem::size() |
390 | { |
391 | QGraphicsVideoItem item; |
392 | |
393 | QCOMPARE(item.size(), QSizeF(320, 240)); |
394 | |
395 | item.setSize(QSizeF(542.5, 436.3)); |
396 | QCOMPARE(item.size(), QSizeF(542.5, 436.3)); |
397 | |
398 | item.setSize(QSizeF(-43, 12)); |
399 | QCOMPARE(item.size(), QSizeF(0, 0)); |
400 | |
401 | item.setSize(QSizeF(54, -9)); |
402 | QCOMPARE(item.size(), QSizeF(0, 0)); |
403 | |
404 | item.setSize(QSizeF(-90, -65)); |
405 | QCOMPARE(item.size(), QSizeF(0, 0)); |
406 | |
407 | item.setSize(QSizeF(1000, 1000)); |
408 | QCOMPARE(item.size(), QSizeF(1000, 1000)); |
409 | } |
410 | |
411 | void tst_QGraphicsVideoItem::nativeSize_data() |
412 | { |
413 | QTest::addColumn<QSize>(name: "frameSize" ); |
414 | QTest::addColumn<QRect>(name: "viewport" ); |
415 | QTest::addColumn<QSize>(name: "pixelAspectRatio" ); |
416 | QTest::addColumn<QSizeF>(name: "nativeSize" ); |
417 | |
418 | QTest::newRow(dataTag: "640x480" ) |
419 | << QSize(640, 480) |
420 | << QRect(0, 0, 640, 480) |
421 | << QSize(1, 1) |
422 | << QSizeF(640, 480); |
423 | |
424 | QTest::newRow(dataTag: "800x600, (80,60, 640x480) viewport" ) |
425 | << QSize(800, 600) |
426 | << QRect(80, 60, 640, 480) |
427 | << QSize(1, 1) |
428 | << QSizeF(640, 480); |
429 | |
430 | QTest::newRow(dataTag: "800x600, (80,60, 640x480) viewport, 4:3" ) |
431 | << QSize(800, 600) |
432 | << QRect(80, 60, 640, 480) |
433 | << QSize(4, 3) |
434 | << QSizeF(853, 480); |
435 | } |
436 | |
437 | void tst_QGraphicsVideoItem::nativeSize() |
438 | { |
439 | QFETCH(QSize, frameSize); |
440 | QFETCH(QRect, viewport); |
441 | QFETCH(QSize, pixelAspectRatio); |
442 | QFETCH(QSizeF, nativeSize); |
443 | |
444 | QtTestVideoObject object(new QtTestRendererControl); |
445 | QGraphicsVideoItem item; |
446 | object.bind(&item); |
447 | |
448 | QCOMPARE(item.nativeSize(), QSizeF()); |
449 | |
450 | QSignalSpy spy(&item, SIGNAL(nativeSizeChanged(QSizeF))); |
451 | |
452 | QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); |
453 | format.setViewport(viewport); |
454 | format.setPixelAspectRatio(pixelAspectRatio); |
455 | |
456 | { // Surface setup is deferred until after the first paint. |
457 | QImage image(320, 240, QImage::Format_RGB32); |
458 | QPainter painter(&image); |
459 | |
460 | item.paint(painter: &painter, option: 0); |
461 | } |
462 | QVERIFY(object.testService->rendererControl->surface() != 0); |
463 | QVERIFY(object.testService->rendererControl->surface()->start(format)); |
464 | |
465 | QCoreApplication::processEvents(); |
466 | QCOMPARE(item.nativeSize(), nativeSize); |
467 | QCOMPARE(spy.count(), 1); |
468 | QCOMPARE(spy.last().first().toSizeF(), nativeSize); |
469 | |
470 | object.testService->rendererControl->surface()->stop(); |
471 | |
472 | QCoreApplication::processEvents(); |
473 | QVERIFY(item.nativeSize().isEmpty()); |
474 | QCOMPARE(spy.count(), 2); |
475 | QVERIFY(spy.last().first().toSizeF().isEmpty()); |
476 | } |
477 | |
478 | void tst_QGraphicsVideoItem::boundingRect_data() |
479 | { |
480 | QTest::addColumn<QSize>(name: "frameSize" ); |
481 | QTest::addColumn<QPointF>(name: "offset" ); |
482 | QTest::addColumn<QSizeF>(name: "size" ); |
483 | QTest::addColumn<Qt::AspectRatioMode>(name: "aspectRatioMode" ); |
484 | QTest::addColumn<QRectF>(name: "expectedRect" ); |
485 | |
486 | |
487 | QTest::newRow(dataTag: "640x480: (0,0 640x480), Keep" ) |
488 | << QSize(640, 480) |
489 | << QPointF(0, 0) |
490 | << QSizeF(640, 480) |
491 | << Qt::KeepAspectRatio |
492 | << QRectF(0, 0, 640, 480); |
493 | |
494 | QTest::newRow(dataTag: "800x600, (0,0, 640x480), Keep" ) |
495 | << QSize(800, 600) |
496 | << QPointF(0, 0) |
497 | << QSizeF(640, 480) |
498 | << Qt::KeepAspectRatio |
499 | << QRectF(0, 0, 640, 480); |
500 | |
501 | QTest::newRow(dataTag: "800x600, (0,0, 640x480), KeepByExpanding" ) |
502 | << QSize(800, 600) |
503 | << QPointF(0, 0) |
504 | << QSizeF(640, 480) |
505 | << Qt::KeepAspectRatioByExpanding |
506 | << QRectF(0, 0, 640, 480); |
507 | |
508 | QTest::newRow(dataTag: "800x600, (0,0, 640x480), Ignore" ) |
509 | << QSize(800, 600) |
510 | << QPointF(0, 0) |
511 | << QSizeF(640, 480) |
512 | << Qt::IgnoreAspectRatio |
513 | << QRectF(0, 0, 640, 480); |
514 | |
515 | QTest::newRow(dataTag: "800x600, (100,100, 640x480), Keep" ) |
516 | << QSize(800, 600) |
517 | << QPointF(100, 100) |
518 | << QSizeF(640, 480) |
519 | << Qt::KeepAspectRatio |
520 | << QRectF(100, 100, 640, 480); |
521 | |
522 | QTest::newRow(dataTag: "800x600, (100,-100, 640x480), KeepByExpanding" ) |
523 | << QSize(800, 600) |
524 | << QPointF(100, -100) |
525 | << QSizeF(640, 480) |
526 | << Qt::KeepAspectRatioByExpanding |
527 | << QRectF(100, -100, 640, 480); |
528 | |
529 | QTest::newRow(dataTag: "800x600, (-100,-100, 640x480), Ignore" ) |
530 | << QSize(800, 600) |
531 | << QPointF(-100, -100) |
532 | << QSizeF(640, 480) |
533 | << Qt::IgnoreAspectRatio |
534 | << QRectF(-100, -100, 640, 480); |
535 | |
536 | QTest::newRow(dataTag: "800x600, (0,0, 1920x1024), Keep" ) |
537 | << QSize(800, 600) |
538 | << QPointF(0, 0) |
539 | << QSizeF(1920, 1024) |
540 | << Qt::KeepAspectRatio |
541 | << QRectF(832.0 / 3, 0, 4096.0 / 3, 1024); |
542 | |
543 | QTest::newRow(dataTag: "800x600, (0,0, 1920x1024), KeepByExpanding" ) |
544 | << QSize(800, 600) |
545 | << QPointF(0, 0) |
546 | << QSizeF(1920, 1024) |
547 | << Qt::KeepAspectRatioByExpanding |
548 | << QRectF(0, 0, 1920, 1024); |
549 | |
550 | QTest::newRow(dataTag: "800x600, (0,0, 1920x1024), Ignore" ) |
551 | << QSize(800, 600) |
552 | << QPointF(0, 0) |
553 | << QSizeF(1920, 1024) |
554 | << Qt::IgnoreAspectRatio |
555 | << QRectF(0, 0, 1920, 1024); |
556 | |
557 | QTest::newRow(dataTag: "800x600, (100,100, 1920x1024), Keep" ) |
558 | << QSize(800, 600) |
559 | << QPointF(100, 100) |
560 | << QSizeF(1920, 1024) |
561 | << Qt::KeepAspectRatio |
562 | << QRectF(100 + 832.0 / 3, 100, 4096.0 / 3, 1024); |
563 | |
564 | QTest::newRow(dataTag: "800x600, (100,-100, 1920x1024), KeepByExpanding" ) |
565 | << QSize(800, 600) |
566 | << QPointF(100, -100) |
567 | << QSizeF(1920, 1024) |
568 | << Qt::KeepAspectRatioByExpanding |
569 | << QRectF(100, -100, 1920, 1024); |
570 | |
571 | QTest::newRow(dataTag: "800x600, (-100,-100, 1920x1024), Ignore" ) |
572 | << QSize(800, 600) |
573 | << QPointF(-100, -100) |
574 | << QSizeF(1920, 1024) |
575 | << Qt::IgnoreAspectRatio |
576 | << QRectF(-100, -100, 1920, 1024); |
577 | } |
578 | |
579 | void tst_QGraphicsVideoItem::boundingRect() |
580 | { |
581 | QFETCH(QSize, frameSize); |
582 | QFETCH(QPointF, offset); |
583 | QFETCH(QSizeF, size); |
584 | QFETCH(Qt::AspectRatioMode, aspectRatioMode); |
585 | QFETCH(QRectF, expectedRect); |
586 | |
587 | QtTestVideoObject object(new QtTestRendererControl); |
588 | QGraphicsVideoItem item; |
589 | object.bind(&item); |
590 | |
591 | item.setOffset(offset); |
592 | item.setSize(size); |
593 | item.setAspectRatioMode(aspectRatioMode); |
594 | |
595 | QVideoSurfaceFormat format(frameSize, QVideoFrame::Format_ARGB32); |
596 | |
597 | { // Surface setup is deferred until after the first paint. |
598 | QImage image(320, 240, QImage::Format_RGB32); |
599 | QPainter painter(&image); |
600 | |
601 | item.paint(painter: &painter, option: 0); |
602 | } |
603 | QVERIFY(object.testService->rendererControl->surface() != 0); |
604 | QVERIFY(object.testService->rendererControl->surface()->start(format)); |
605 | |
606 | QCoreApplication::processEvents(); |
607 | QCOMPARE(item.boundingRect(), expectedRect); |
608 | } |
609 | |
610 | static const uchar rgb32ImageData[] = |
611 | { |
612 | 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0x00, |
613 | 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00 |
614 | }; |
615 | |
616 | void tst_QGraphicsVideoItem::paint() |
617 | { |
618 | QtTestVideoObject object(new QtTestRendererControl); |
619 | QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
620 | object.bind(item); |
621 | |
622 | QGraphicsScene graphicsScene; |
623 | graphicsScene.addItem(item); |
624 | QGraphicsView graphicsView(&graphicsScene); |
625 | graphicsView.show(); |
626 | QVERIFY(item->waitForPaint(1)); |
627 | |
628 | QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>( |
629 | object: object.testService->rendererControl->surface()); |
630 | if (!surface) |
631 | QSKIP("QGraphicsVideoItem is not QPainterVideoSurface based" ); |
632 | |
633 | QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); |
634 | |
635 | QVERIFY(surface->start(format)); |
636 | QCOMPARE(surface->isActive(), true); |
637 | QCOMPARE(surface->isReady(), true); |
638 | |
639 | QVERIFY(item->waitForPaint(1)); |
640 | |
641 | QCOMPARE(surface->isActive(), true); |
642 | QCOMPARE(surface->isReady(), true); |
643 | |
644 | QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); |
645 | |
646 | frame.map(mode: QAbstractVideoBuffer::WriteOnly); |
647 | memcpy(dest: frame.bits(), src: rgb32ImageData, n: frame.mappedBytes()); |
648 | frame.unmap(); |
649 | |
650 | QVERIFY(surface->present(frame)); |
651 | QCOMPARE(surface->isActive(), true); |
652 | QCOMPARE(surface->isReady(), false); |
653 | |
654 | QVERIFY(item->waitForPaint(1)); |
655 | |
656 | QCOMPARE(surface->isActive(), true); |
657 | QCOMPARE(surface->isReady(), true); |
658 | } |
659 | |
660 | void tst_QGraphicsVideoItem::paintSurface() |
661 | { |
662 | QtTestGraphicsVideoItem *item = new QtTestGraphicsVideoItem; |
663 | QVERIFY(item->videoSurface()); |
664 | |
665 | QGraphicsScene graphicsScene; |
666 | graphicsScene.addItem(item); |
667 | QGraphicsView graphicsView(&graphicsScene); |
668 | graphicsView.show(); |
669 | QVERIFY(item->waitForPaint(1)); |
670 | |
671 | QPainterVideoSurface *surface = qobject_cast<QPainterVideoSurface *>( |
672 | object: item->videoSurface()); |
673 | if (!surface) |
674 | QSKIP("QGraphicsVideoItem is not QPainterVideoSurface based" ); |
675 | |
676 | QVideoSurfaceFormat format(QSize(2, 2), QVideoFrame::Format_RGB32); |
677 | |
678 | QVERIFY(surface->start(format)); |
679 | QCOMPARE(surface->isActive(), true); |
680 | QCOMPARE(surface->isReady(), true); |
681 | |
682 | QVERIFY(item->waitForPaint(1)); |
683 | |
684 | QCOMPARE(surface->isActive(), true); |
685 | QCOMPARE(surface->isReady(), true); |
686 | |
687 | QVideoFrame frame(sizeof(rgb32ImageData), QSize(2, 2), 8, QVideoFrame::Format_RGB32); |
688 | |
689 | frame.map(mode: QAbstractVideoBuffer::WriteOnly); |
690 | memcpy(dest: frame.bits(), src: rgb32ImageData, n: frame.mappedBytes()); |
691 | frame.unmap(); |
692 | |
693 | QVERIFY(surface->present(frame)); |
694 | QCOMPARE(surface->isActive(), true); |
695 | QCOMPARE(surface->isReady(), false); |
696 | |
697 | QVERIFY(item->waitForPaint(1)); |
698 | |
699 | QCOMPARE(surface->isActive(), true); |
700 | QCOMPARE(surface->isReady(), true); |
701 | } |
702 | |
703 | QTEST_MAIN(tst_QGraphicsVideoItem) |
704 | |
705 | #include "tst_qgraphicsvideoitem.moc" |
706 | |