Skip to content

Commit

Permalink
update viewport if screen is changed wang-bin#1038
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 30, 2018
1 parent b813048 commit 49ce5f8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/QtAV/OpenGLVideo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2016 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -115,6 +115,7 @@ private Q_SLOTS:
* shader manager and material will be reset
*/
void resetGL();
void updateViewport();
};


Expand Down
36 changes: 25 additions & 11 deletions src/opengl/OpenGLVideo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Multimedia framework based on Qt and FFmpeg
Copyright (C) 2012-2017 Wang Bin <[email protected]>
Copyright (C) 2012-2018 Wang Bin <[email protected]>
* This file is part of QtAV (from 2014)
Expand Down Expand Up @@ -173,7 +173,12 @@ void OpenGLVideoPrivate::updateGeometry(VideoShader* shader, const QRectF &t, co
gr->updateGeometry(geometry);
}

OpenGLVideo::OpenGLVideo() {}
OpenGLVideo::OpenGLVideo() {
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
// TODO: system resolution change
connect(QGuiApplication::instance(), SIGNAL(primaryScreenChanged(QScreen*)), this, SLOT(updateViewport()));
#endif
}

bool OpenGLVideo::isSupported(VideoFormat::PixelFormat pixfmt)
{
Expand Down Expand Up @@ -206,16 +211,8 @@ void OpenGLVideo::setOpenGLContext(QOpenGLContext *ctx)
d.material->setSaturation(s);
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
d.manager = ctx->findChild<ShaderManager*>(QStringLiteral("__qtav_shader_manager"));
QSizeF surfaceSize = ctx->surface()->size();
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
surfaceSize *= ctx->screen()->devicePixelRatio();
#else
surfaceSize *= qApp->devicePixelRatio(); //TODO: window()->devicePixelRatio() is the window screen's
#endif
#else
QSizeF surfaceSize = QSizeF(ctx->device()->width(), ctx->device()->height());
#endif
setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize));
updateViewport();
if (d.manager)
return;
// TODO: what if ctx is delete?
Expand Down Expand Up @@ -387,4 +384,21 @@ void OpenGLVideo::resetGL()
d_func().resetGL();
}

void OpenGLVideo::updateViewport()
{
DPTR_D(OpenGLVideo);
if (!d.ctx)
return;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QSizeF surfaceSize = d.ctx->surface()->size();
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
surfaceSize *= d.ctx->screen()->devicePixelRatio();
#else
surfaceSize *= qApp->devicePixelRatio(); //TODO: window()->devicePixelRatio() is the window screen's
#endif
#else
QSizeF surfaceSize = QSizeF(d.ctx->device()->width(), d.ctx->device()->height());
#endif
setProjectionMatrixToRect(QRectF(QPointF(), surfaceSize));
}
} //namespace QtAV

0 comments on commit 49ce5f8

Please sign in to comment.