aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickwidgets
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-06-13 23:10:03 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-06-13 23:10:03 +0200
commit9932617582470d717c97f8161a65133293c185c5 (patch)
tree1df48d67c6e5ca4aa8b7810fc9e717083b4199e3 /src/quickwidgets
parent7fde8a8d20da7fa00d974286fa903b3fee76d466 (diff)
parent17ee404f2678684674b9c5c0c523602953146e37 (diff)
Merge remote-tracking branch 'origin/5.3' into dev
Conflicts: src/quickwidgets/qquickwidget.cpp Change-Id: Id4b080aea713df68608847bb82570231e37ce536
Diffstat (limited to 'src/quickwidgets')
-rw-r--r--src/quickwidgets/qquickwidget.cpp73
-rw-r--r--src/quickwidgets/qquickwidget_p.h2
2 files changed, 53 insertions, 22 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index a8a33c07c8..f91d512ab0 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -89,7 +89,6 @@ void QQuickWidgetPrivate::init(QQmlEngine* e)
offscreenWindow = renderControl->createOffscreenWindow();
offscreenWindow->setTitle(QString::fromLatin1("Offscreen"));
// Do not call create() on offscreenWindow.
- createOffscreenSurface();
if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::RasterGLSurface))
setRenderToTexture();
@@ -144,6 +143,7 @@ QQuickWidgetPrivate::QQuickWidgetPrivate()
, offscreenSurface(0)
, renderControl(0)
, fbo(0)
+ , resolvedFbo(0)
, context(0)
, resizeMode(QQuickWidget::SizeViewToRootObject)
, initialSize(0,0)
@@ -164,21 +164,12 @@ QQuickWidgetPrivate::~QQuickWidgetPrivate()
Q_ASSERT(!context || (QOpenGLContext::currentContext() == context && context->surface() == offscreenSurface));
delete offscreenWindow;
delete renderControl;
+ delete resolvedFbo;
delete fbo;
- delete offscreenSurface;
destroyContext();
}
-void QQuickWidgetPrivate::createOffscreenSurface()
-{
- delete offscreenSurface;
- offscreenSurface = 0;
- offscreenSurface = new QOffscreenSurface;
- offscreenSurface->setFormat(offscreenWindow->requestedFormat());
- offscreenSurface->create();
-}
-
void QQuickWidgetPrivate::execute()
{
Q_Q(QQuickWidget);
@@ -237,6 +228,12 @@ void QQuickWidgetPrivate::renderSceneGraph()
renderControl->sync();
renderControl->render();
context->functions()->glFlush();
+
+ if (resolvedFbo) {
+ QRect rect(QPoint(0, 0), fbo->size());
+ QOpenGLFramebufferObject::blitFramebuffer(resolvedFbo, rect, fbo, rect);
+ }
+
context->doneCurrent();
q->update();
}
@@ -313,6 +310,7 @@ QQuickWidget::QQuickWidget(QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
d_func()->init();
}
@@ -325,6 +323,7 @@ QQuickWidget::QQuickWidget(const QUrl &source, QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
d_func()->init();
setSource(source);
}
@@ -342,6 +341,7 @@ QQuickWidget::QQuickWidget(QQmlEngine* engine, QWidget *parent)
: QWidget(*(new QQuickWidgetPrivate), parent, 0)
{
setMouseTracking(true);
+ setFocusPolicy(Qt::StrongFocus);
Q_ASSERT(engine);
d_func()->init(engine);
}
@@ -641,6 +641,13 @@ void QQuickWidgetPrivate::createContext()
return;
}
+ offscreenSurface = new QOffscreenSurface;
+ // Pass the context's format(), which, now that the underlying platform context is created,
+ // contains a QSurfaceFormat representing the _actual_ format of the underlying
+ // configuration. This is essential to get a surface that is compatible with the context.
+ offscreenSurface->setFormat(context->format());
+ offscreenSurface->create();
+
if (context->makeCurrent(offscreenSurface))
renderControl->initialize(context);
else
@@ -649,6 +656,8 @@ void QQuickWidgetPrivate::createContext()
void QQuickWidgetPrivate::destroyContext()
{
+ delete offscreenSurface;
+ offscreenSurface = 0;
delete context;
context = 0;
}
@@ -671,11 +680,23 @@ void QQuickWidget::createFramebufferObject()
context->makeCurrent(d->offscreenSurface);
+ int samples = d->offscreenWindow->requestedFormat().samples();
+ if (!QOpenGLExtensions(context).hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample))
+ samples = 0;
+
+ QOpenGLFramebufferObjectFormat format;
+ format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
+ format.setSamples(samples);
+
+ QSize fboSize = size() * window()->devicePixelRatio();
+
delete d->fbo;
- d->fbo = new QOpenGLFramebufferObject(size() * window()->devicePixelRatio());
- d->fbo->setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
+ d->fbo = new QOpenGLFramebufferObject(fboSize, format);
d->offscreenWindow->setRenderTarget(d->fbo);
+ if (samples > 0)
+ d->resolvedFbo = new QOpenGLFramebufferObject(fboSize);
+
// Sanity check: The window must not have an underlying platform window.
// Having one would mean create() was called and platforms that only support
// a single native window were in trouble.
@@ -685,9 +706,10 @@ void QQuickWidget::createFramebufferObject()
void QQuickWidget::destroyFramebufferObject()
{
Q_D(QQuickWidget);
- if (d->fbo)
- delete d->fbo;
+ delete d->fbo;
d->fbo = 0;
+ delete d->resolvedFbo;
+ d->resolvedFbo = 0;
}
QQuickWidget::ResizeMode QQuickWidget::resizeMode() const
@@ -766,7 +788,14 @@ void QQuickWidgetPrivate::setRootObject(QObject *obj)
GLuint QQuickWidgetPrivate::textureId() const
{
- return fbo ? fbo->texture() : 0;
+ Q_Q(const QQuickWidget);
+ if (!q->isWindow() && q->internalWinId()) {
+ qWarning() << "QQuickWidget cannot be used as a native child widget."
+ << "Consider setting Qt::AA_DontCreateNativeWidgetSiblings";
+ return 0;
+ }
+ return resolvedFbo ? resolvedFbo->texture()
+ : (fbo ? fbo->texture() : 0);
}
/*!
@@ -980,13 +1009,18 @@ bool QQuickWidget::event(QEvent *e)
switch (e->type()) {
#ifndef QT_NO_DRAGANDDROP
case QEvent::Drop:
- case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
// Drag/drop events only have local pos, so no need to map,
// but QQuickWindow::event() does not return true
d->offscreenWindow->event(e);
return e->isAccepted();
+ case QEvent::DragEnter:
+ // Don't reject drag events for the entire widget when one
+ // item rejects the drag enter
+ d->offscreenWindow->event(e);
+ e->accept();
+ return true;
#endif
case QEvent::TouchBegin:
case QEvent::TouchEnd:
@@ -1038,10 +1072,7 @@ void QQuickWidget::setFormat(const QSurfaceFormat &format)
newFormat.setDepthBufferSize(qMax(newFormat.depthBufferSize(), currentFormat.depthBufferSize()));
newFormat.setStencilBufferSize(qMax(newFormat.stencilBufferSize(), currentFormat.stencilBufferSize()));
newFormat.setAlphaBufferSize(qMax(newFormat.alphaBufferSize(), currentFormat.alphaBufferSize()));
- if (currentFormat != newFormat) {
- d->offscreenWindow->setFormat(newFormat);
- d->createOffscreenSurface();
- }
+ d->offscreenWindow->setFormat(newFormat);
}
/*!
diff --git a/src/quickwidgets/qquickwidget_p.h b/src/quickwidgets/qquickwidget_p.h
index 8efe32b3ce..356c34e7f5 100644
--- a/src/quickwidgets/qquickwidget_p.h
+++ b/src/quickwidgets/qquickwidget_p.h
@@ -87,7 +87,6 @@ public:
void createContext();
void destroyContext();
void handleContextCreationFailure(const QSurfaceFormat &format, bool isEs);
- void createOffscreenSurface();
GLuint textureId() const Q_DECL_OVERRIDE;
@@ -108,6 +107,7 @@ public:
QOffscreenSurface *offscreenSurface;
QQuickRenderControl *renderControl;
QOpenGLFramebufferObject *fbo;
+ QOpenGLFramebufferObject *resolvedFbo;
QOpenGLContext *context;
QQuickWidget::ResizeMode resizeMode;