• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8 
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13 
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19 
20 
21 #include "../../util.h"
22 #include <QGLWidget>
23 #include <QGraphicsView>
24 #include <QGraphicsWebView>
25 #include <QScopedPointer>
26 #include <QWebFrame>
27 #include <QtTest/QtTest>
28 
29 class GraphicsView;
30 
31 class tst_WebGlPerformance : public QObject {
32     Q_OBJECT
33 
34 private slots:
35     void init();
36     void cleanup();
37 
38     void benchSoftwareFallbackRgb16();
39     void benchSoftwareFallbackRgb32();
40     void benchSoftwareFallbackArgb32();
41     void benchSoftwareFallbackArgb32Premultiplied();
42 
43 private:
44     void benchmarkFrameRenderingOnImage(QImage::Format);
45 
46     QScopedPointer<GraphicsView> m_view;
47 };
48 
49 class GraphicsView : public QGraphicsView {
50 public:
51     GraphicsView();
52     QGraphicsWebView* m_webView;
53 
54 protected:
55     void resizeEvent(QResizeEvent*);
56 };
57 
GraphicsView()58 GraphicsView::GraphicsView()
59 {
60     QGraphicsScene* const scene = new QGraphicsScene(this);
61     setScene(scene);
62 
63     m_webView = new QGraphicsWebView;
64     scene->addItem(m_webView);
65 
66     m_webView->page()->settings()->setAttribute(QWebSettings::WebGLEnabled, true);
67 
68     resize(800, 600);
69     setFrameShape(QFrame::NoFrame);
70     setViewport(new QGLWidget);
71 }
72 
resizeEvent(QResizeEvent * event)73 void GraphicsView::resizeEvent(QResizeEvent* event)
74 {
75     QGraphicsView::resizeEvent(event);
76     QRectF rect(QPoint(0, 0), event->size());
77     m_webView->setGeometry(rect);
78     scene()->setSceneRect(rect);
79 }
80 
init()81 void tst_WebGlPerformance::init()
82 {
83     m_view.reset(new GraphicsView);
84     m_view->showMaximized();
85     QTest::qWaitForWindowShown(m_view.data());
86 }
87 
cleanup()88 void tst_WebGlPerformance::cleanup()
89 {
90     m_view.reset();
91 }
92 
benchSoftwareFallbackRgb16()93 void tst_WebGlPerformance::benchSoftwareFallbackRgb16()
94 {
95     benchmarkFrameRenderingOnImage(QImage::Format_RGB16);
96 }
97 
benchSoftwareFallbackRgb32()98 void tst_WebGlPerformance::benchSoftwareFallbackRgb32()
99 {
100     benchmarkFrameRenderingOnImage(QImage::Format_RGB32);
101 }
102 
benchSoftwareFallbackArgb32()103 void tst_WebGlPerformance::benchSoftwareFallbackArgb32()
104 {
105     benchmarkFrameRenderingOnImage(QImage::Format_ARGB32);
106 }
107 
benchSoftwareFallbackArgb32Premultiplied()108 void tst_WebGlPerformance::benchSoftwareFallbackArgb32Premultiplied()
109 {
110     benchmarkFrameRenderingOnImage(QImage::Format_ARGB32_Premultiplied);
111 }
112 
benchmarkFrameRenderingOnImage(QImage::Format format)113 void tst_WebGlPerformance::benchmarkFrameRenderingOnImage(QImage::Format format)
114 {
115     m_view->m_webView->load(QUrl(QLatin1String("qrc:///testcases/10000_triangles.html")));
116     const bool pageLoaded = waitForSignal(m_view->m_webView, SIGNAL(loadFinished(bool)));
117     Q_ASSERT(pageLoaded);
118     Q_UNUSED(pageLoaded);
119 
120     QImage target(m_view->size(), format);
121     QBENCHMARK {
122         QPainter painter(&target);
123         m_view->render(&painter);
124         painter.end();
125     }
126 }
127 
128 QTEST_MAIN(tst_WebGlPerformance)
129 
130 #include "tst_webgl.moc"
131