Skip to content

Instantly share code, notes, and snippets.

@balazs
Created September 10, 2012 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazs/3691147 to your computer and use it in GitHub Desktop.
Save balazs/3691147 to your computer and use it in GitHub Desktop.
diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
index 3276de9..9b2fcdc 100644
--- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
+++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp
@@ -442,15 +442,6 @@ void QQuickWebViewPrivate::handleMouseEvent(QMouseEvent* event)
void QQuickWebViewPrivate::setNeedsDisplay()
{
Q_Q(QQuickWebView);
- if (renderToOffscreenBuffer()) {
- // This is used for running the rendering code-path while running tests to make sure
- // we synchronise the rendering correctly which is necessary to get valid pixel results.
- QImage dummyImage(QSize(1, 1), QImage::Format_ARGB32);
- QPainter painter(&dummyImage);
- q->page()->paintSnapshot(&painter);
- return;
- }
-
q->page()->update();
}
diff --git a/Tools/WebKitTestRunner/Target.pri b/Tools/WebKitTestRunner/Target.pri
index 27b65c6..5a778e2 100644
--- a/Tools/WebKitTestRunner/Target.pri
+++ b/Tools/WebKitTestRunner/Target.pri
@@ -29,7 +29,7 @@ SOURCES += \
DESTDIR = $${ROOT_BUILD_DIR}/bin
-QT = core gui gui-private widgets network testlib quick quick-private webkit
+QT = core gui gui-private widgets network testlib quick quick-private webkit v8 v8-private
WEBKIT += wtf javascriptcore webkit2
diff --git a/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp b/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp
index 832d98d..55b331e 100644
--- a/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp
+++ b/Tools/WebKitTestRunner/qt/PlatformWebViewQt.cpp
@@ -38,6 +38,9 @@
#include <WebKit2/WKImageQt.h>
#include <qpa/qwindowsysteminterface.h>
+#include <QtQuick/private/qquickwindow_p.h>
+#include <QtGui/qopenglframebufferobject.h>
+
namespace WTR {
class WrapperWindow : public QQuickView {
@@ -46,8 +49,21 @@ public:
WrapperWindow(QQuickWebView* view)
: QQuickView(QUrl("data:text/plain,import QtQuick 2.0\nItem { objectName: 'root' }"))
, m_view(view)
+ , m_fbo(0)
{
connect(this, SIGNAL(statusChanged(QQuickView::Status)), SLOT(handleStatusChanged(QQuickView::Status)));
+ connect(this, SIGNAL(beforeRendering()), SLOT(onBeforeRendering()), Qt::DirectConnection);
+ }
+
+ QImage snapshotImage()
+ {
+ grabWindow();
+ return m_fbo ? m_fbo->toImage() : QImage();
+ }
+
+ ~WrapperWindow()
+ {
+ delete m_fbo;
}
private Q_SLOTS:
@@ -56,6 +72,12 @@ private Q_SLOTS:
if (status != QQuickView::Ready)
return;
+ setSurfaceType(QWindow::OpenGLSurface);
+ create();
+
+ QQuickWindowPrivate* d = QQuickWindowPrivate::get(this);
+ d->setRenderWithoutShowing(true);
+
setGeometry(0, 0, 800, 600);
setResizeMode(QQuickView::SizeRootObjectToView);
@@ -66,10 +88,26 @@ private Q_SLOTS:
m_view->page()->setFocus(true);
}
+ void onBeforeRendering();
+
private:
QQuickWebView* m_view;
+ QOpenGLFramebufferObject* m_fbo;
};
+void WrapperWindow::onBeforeRendering()
+{
+ if (m_fbo && m_fbo->size() == size())
+ return;
+ if (m_fbo)
+ m_fbo->release();
+ delete m_fbo;
+ m_fbo = new QOpenGLFramebufferObject(size());
+ m_fbo->bind();
+ setRenderTarget(m_fbo);
+
+}
+
PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
: m_view(new QQuickWebView(contextRef, pageGroupRef))
, m_window(new WrapperWindow(m_view))
@@ -77,7 +115,6 @@ PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGro
, m_modalEventLoop(0)
{
QQuickWebViewExperimental experimental(m_view);
- experimental.setRenderToOffscreenBuffer(true);
m_view->setAllowAnyHTTPSCertificateForLocalHost(true);
m_view->componentComplete();
}
@@ -152,11 +189,7 @@ void PlatformWebView::makeWebViewFirstResponder()
WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
{
- QRect geometry = m_window->geometry();
- QImage image(geometry.size(), QImage::Format_ARGB32);
- QPainter painter(&image);
- m_view->page()->paintSnapshot(&painter);
- return WKImageCreateFromQImage(image);
+ return WKImageCreateFromQImage(qobject_cast<WrapperWindow*>(m_window)->snapshotImage());
}
} // namespace WTR
.test {
@media () {
test
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment