Skip to content
Snippets Groups Projects
Commit b09982aa authored by Edric's avatar Edric Committed by gerrit2
Browse files

fix share screen on HDPI

FFMEPG only deal with the true resolution of the screen
(not the scaled HDPI one) so we need to feed it the real size of screen
(entire screen share) or a scaled version of the selection rect (partial
screen share)

see https://github.com/FFmpeg/FFmpeg/commit/e82883aa88bfccf2669e914eab9deef6cecfd0db

Change-Id: I3f2e1ec41a75c3e4b18a84c86491f95a6f98a877
Tuleap: #716
parent 11eed6ac
Branches
No related tags found
No related merge requests found
...@@ -18,6 +18,16 @@ ...@@ -18,6 +18,16 @@
#include "selectareadialog.h" #include "selectareadialog.h"
#ifdef Q_OS_WIN
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <winuser.h>
#undef OUT
#undef IN
#undef ERROR
#endif
#include <QApplication> #include <QApplication>
#include <QScreen> #include <QScreen>
#include <QPainter> #include <QPainter>
...@@ -37,11 +47,13 @@ SelectAreaDialog::SelectAreaDialog() : ...@@ -37,11 +47,13 @@ SelectAreaDialog::SelectAreaDialog() :
setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_TranslucentBackground, true);
setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_PaintOnScreen);
grabMouse(); grabMouse();
rubberBand_ = new QRubberBand(QRubberBand::Rectangle,0); rubberBand_ = new QRubberBand(QRubberBand::Rectangle, this);
QApplication::setOverrideCursor(Qt::CrossCursor); QApplication::setOverrideCursor(Qt::CrossCursor);
QScreen* screen = QGuiApplication::primaryScreen(); QScreen* screen = QGuiApplication::primaryScreen();
if (screen) if (screen) {
originalPixmap_ = screen->grabWindow(0); originalPixmap_ = screen->grabWindow(0);
originalPixmap_.setDevicePixelRatio(screen->devicePixelRatio());
}
} }
void void
...@@ -71,13 +83,23 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event) ...@@ -71,13 +83,23 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
releaseMouse(); releaseMouse();
if (auto call = CallModel::instance().selectedCall()) { if (auto call = CallModel::instance().selectedCall()) {
if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) { if (auto outVideo = call->firstMedia<Media::Video>(Media::Media::Direction::OUT)) {
int x, y, width, height; QRect realRect = rubberBand_->geometry();
QRect realRect; #ifdef Q_OS_WIN
rubberBand_->geometry().getRect(&x, &y, &width, &height); if (QGuiApplication::primaryScreen()->devicePixelRatio() > 1.0) {
realRect.setX(x); auto scaledSize = QGuiApplication::primaryScreen()->geometry();
realRect.setY(y); auto sourceHdc = GetDC(nullptr);
realRect.setWidth(width); auto vertres = GetDeviceCaps(sourceHdc, VERTRES);
realRect.setHeight(height); auto horzres = GetDeviceCaps(sourceHdc, HORZRES);
auto height = realRect.height() * QGuiApplication::primaryScreen()->devicePixelRatio();
auto width = realRect.width() * QGuiApplication::primaryScreen()->devicePixelRatio();
float xRatio = static_cast<float>(horzres) / static_cast<float>(scaledSize.width());
float yRatio = static_cast<float>(vertres) / static_cast<float>(scaledSize.height());
realRect.setX(static_cast<int>(realRect.x() * xRatio));
realRect.setY(static_cast<int>(realRect.y() * yRatio));
realRect.setWidth(static_cast<int>(width));
realRect.setHeight(static_cast<int>(height));
}
#endif
outVideo->sourceModel()->setDisplay(0, realRect); outVideo->sourceModel()->setDisplay(0, realRect);
} }
} }
...@@ -88,7 +110,8 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event) ...@@ -88,7 +110,8 @@ SelectAreaDialog::mouseReleaseEvent(QMouseEvent* event)
} }
void void
SelectAreaDialog::paintEvent(QPaintEvent* event) { SelectAreaDialog::paintEvent(QPaintEvent* event)
{
Q_UNUSED(event) Q_UNUSED(event)
QPainter painter(this); QPainter painter(this);
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMimeData> #include <QMimeData>
#include <QSplitter> #include <QSplitter>
#include <QScreen>
#include <memory> #include <memory>
...@@ -81,8 +82,8 @@ VideoView::resizeEvent(QResizeEvent* event) ...@@ -81,8 +82,8 @@ VideoView::resizeEvent(QResizeEvent* event)
int deltaH = event->size().height() - event->oldSize().height(); int deltaH = event->size().height() - event->oldSize().height();
QPoint previewCenter = ui->videoWidget->getPreviewRect().center(); QPoint previewCenter = ui->videoWidget->getPreviewRect().center();
float cx = (float)(event->oldSize().width()) / 2.f; int cx = (event->oldSize().width()) / 2;
float cy = (float)(event->oldSize().height()) / 2.f; int cy = (event->oldSize().height()) / 2;
QPoint center = QPoint(cx, cy); QPoint center = QPoint(cx, cy);
// first we check if we want to displace the preview // first we check if we want to displace the preview
...@@ -255,8 +256,12 @@ VideoView::showContextMenu(const QPoint& pos) ...@@ -255,8 +256,12 @@ VideoView::showContextMenu(const QPoint& pos)
} }
connect(shareAction, &QAction::triggered, [=]() { connect(shareAction, &QAction::triggered, [=]() {
if (outVideo) if (outVideo) {
outVideo->sourceModel()->setDisplay(0, QApplication::desktop()->rect()); auto realRect = QApplication::desktop()->geometry();
realRect.setWidth(static_cast<int>(realRect.width() * QApplication::primaryScreen()->devicePixelRatio()));
realRect.setHeight(static_cast<int>(realRect.height() * QApplication::primaryScreen()->devicePixelRatio()));
outVideo->sourceModel()->setDisplay(0, realRect);
}
}); });
connect(shareFileAction, &QAction::triggered, [=]() { connect(shareFileAction, &QAction::triggered, [=]() {
QFileDialog dialog(this); QFileDialog dialog(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment