Skip to content

Commit

Permalink
fix many HighDPI/Retina/screenPixelRatio issues on macOS
Browse files Browse the repository at this point in the history
other platforms need to implement Gui::isHighDPI() or getScreenPixelRatio()
  • Loading branch information
devernay committed Jun 7, 2021
1 parent e44bfd0 commit 2d3d97b
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 46 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
- Fix checkerboard drawing on macOS Catalina and later. #614
- Fix undoing "Reset to default" on parameters. #630
- Fix NodeGraph manipulation and navigation issues. #491 #627
- Fix Retina/High-DPI display issues on macOS (other platforms need to implement Gui::isHighDPI() or getScreenPixelRatio()).

### Plugins

- Transform and CornerPin nodes now displays the motion path.

- Transform, CornerPin, Position and Ramp nodes now display the motion path.
- HueCorrect now has the ability to do hue vs. hue adjustments, with an option to change the background curve guide. #610

## Version 2.4.0

Expand Down
5 changes: 3 additions & 2 deletions Engine/RotoPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,7 @@ RotoPaint::drawOverlay(double time,
std::list<RotoDrawableItemPtr> drawables = getNode()->getRotoContext()->getCurvesByRenderOrder();
std::pair<double, double> pixelScale;
std::pair<double, double> viewportSize;
double screenPixelRatio = getCurrentViewportForOverlays()->getScreenPixelRatio();

getCurrentViewportForOverlays()->getPixelScale(pixelScale.first, pixelScale.second);
getCurrentViewportForOverlays()->getViewportSize(viewportSize.first, viewportSize.second);
Expand All @@ -1686,11 +1687,11 @@ RotoPaint::drawOverlay(double time,
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);


double cpWidth = kControlPointMidSize * 2;
glPointSize(cpWidth);
glPointSize(cpWidth * screenPixelRatio);
for (std::list<RotoDrawableItemPtr>::const_iterator it = drawables.begin(); it != drawables.end(); ++it) {
if ( !(*it)->isGloballyActivated() ) {
continue;
Expand Down
5 changes: 3 additions & 2 deletions Engine/RotoPaintInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ RotoPaintInteract::drawSelectedCpsBBOX()
QPointF topLeft = selectedCpsBbox.topLeft();
QPointF btmRight = selectedCpsBbox.bottomRight();

glLineWidth(1.5);
double screenPixelRatio = p->publicInterface->getCurrentViewportForOverlays()->getScreenPixelRatio();
glLineWidth(1.5 * screenPixelRatio);

if (hoverState == eHoverStateBbox) {
glColor4f(0.9, 0.5, 0, 1.);
Expand Down Expand Up @@ -415,7 +416,7 @@ RotoPaintInteract::drawSelectedCpsBBOX()
QPointF midLeft(topLeft.x(), ( topLeft.y() + btmRight.y() ) / 2.);

///draw the 4 corners points and the 4 mid points
glPointSize(5.f);
glPointSize(5.f * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2f( topLeft.x(), topLeft.y() );
glVertex2f( btmRight.x(), topLeft.y() );
Expand Down
11 changes: 6 additions & 5 deletions Engine/TrackerNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ TrackerNode::drawOverlay(double time,
overlay->getPixelScale(pixelScaleX, pixelScaleY);
double viewportSize[2];
overlay->getViewportSize(viewportSize[0], viewportSize[1]);
double screenPixelRatio = overlay->getScreenPixelRatio();

{
GLProtectAttrib a(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_TRANSFORM_BIT);
Expand Down Expand Up @@ -792,7 +793,7 @@ TrackerNode::drawOverlay(double time,
///Draw a custom interact, indicating the track isn't selected
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(1.5f);
glLineWidth(1.5f * screenPixelRatio);

for (int l = 0; l < 2; ++l) {
// shadow (uses GL_PROJECTION)
Expand All @@ -812,7 +813,7 @@ TrackerNode::drawOverlay(double time,
double x = centerKnob->getValueAtTime(time, 0);
double y = centerKnob->getValueAtTime(time, 1);

glPointSize(POINT_SIZE);
glPointSize(POINT_SIZE * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
Expand All @@ -826,7 +827,7 @@ TrackerNode::drawOverlay(double time,
glVertex2d(x, y + CROSS_SIZE * pixelScaleY);
glEnd();
}
glPointSize(1.);
glPointSize(1. * screenPixelRatio);
} else { // if (isSelected) {
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
Expand Down Expand Up @@ -1059,7 +1060,7 @@ TrackerNode::drawOverlay(double time,
glVertex2d( searchBtmLeft.x(), searchBtmRight.y() );
glEnd();

glPointSize(POINT_SIZE);
glPointSize(POINT_SIZE * screenPixelRatio);
glBegin(GL_POINTS);

///draw center
Expand Down Expand Up @@ -1246,7 +1247,7 @@ TrackerNode::drawOverlay(double time,
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);
//GLProtectMatrix p(GL_PROJECTION); // useless (we do two glTranslate in opposite directions)

const double addTrackSize = TO_DPIX(ADDTRACK_SIZE);
Expand Down
8 changes: 5 additions & 3 deletions Engine/TrackerNodeInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ TrackerNodeInteract::drawSelectedMarkerKeyframes(const std::pair<double, double>
if ( !_p->publicInterface->getNode()->getOverlayColor(&overlayColor[0], &overlayColor[1], &overlayColor[2]) ) {
overlayColor[0] = overlayColor[1] = overlayColor[2] = 0.8;
}
double screenPixelRatio = overlay->getScreenPixelRatio();

KnobDoublePtr centerKnob = marker->getCenterKnob();
KnobDoublePtr offsetKnob = marker->getOffsetKnob();
Expand Down Expand Up @@ -808,7 +809,7 @@ TrackerNodeInteract::drawSelectedMarkerKeyframes(const std::pair<double, double>
}
}

glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);
glCheckError();
glBegin(GL_LINE_LOOP);
glVertex2d(textureRectCanonical.x1, textureRectCanonical.y1);
Expand Down Expand Up @@ -864,6 +865,7 @@ TrackerNodeInteract::drawSelectedMarkerTexture(const std::pair<double, double>&
{
TrackMarkerPtr marker = selectedMarker.lock();
OverlaySupport* overlay = _p->publicInterface->getCurrentViewportForOverlays();
double screenPixelRatio = overlay->getScreenPixelRatio();

assert(overlay);
ViewerInstance* viewer = overlay->getInternalViewerNode();
Expand Down Expand Up @@ -947,7 +949,7 @@ TrackerNodeInteract::drawSelectedMarkerTexture(const std::pair<double, double>&
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1., 1., 1., 0.5);
glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);
glCheckError();
glBegin(GL_LINE_LOOP);
glVertex2d(textureRectCanonical.x1, textureRectCanonical.y1);
Expand All @@ -957,7 +959,7 @@ TrackerNodeInteract::drawSelectedMarkerTexture(const std::pair<double, double>&
glEnd();

glColor4f(0.8, 0.8, 0.8, 1.);
glPointSize(POINT_SIZE);
glPointSize(POINT_SIZE * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2d(textureRectCanonical.x2, textureRectCanonical.y1);
glEnd();
Expand Down
7 changes: 4 additions & 3 deletions Gui/CurveGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ CurveGui::drawCurve(int curveIndex,
hasDrawnExpr = true;
}
}
double screenPixelRatio = _curveWidget->getScreenPixelRatio();
bool isPeriodic = false;
std::pair<double,double> parametricRange = std::make_pair(-std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
if (isBezier) {
Expand Down Expand Up @@ -404,12 +405,12 @@ CurveGui::drawCurve(int curveIndex,


glColor4f( curveColor.redF(), curveColor.greenF(), curveColor.blueF(), curveColor.alphaF() );
glPointSize(_thickness);
glPointSize(_thickness * screenPixelRatio);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);
glCheckError();
if (hasDrawnExpr) {
drawLineStrip(exprVertices, btmLeft, topRight);
Expand Down Expand Up @@ -443,7 +444,7 @@ CurveGui::drawCurve(int curveIndex,
glColor4f( curveColor.redF(), curveColor.greenF(), curveColor.blueF(), curveColor.alphaF() );

//draw keyframes
glPointSize(7.f);
glPointSize(7.f * screenPixelRatio);
glEnable(GL_POINT_SMOOTH);

const SelectedKeys & selectedKeyFrames = _curveWidget->getSelectedKeyFrames();
Expand Down
2 changes: 1 addition & 1 deletion Gui/CurveWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ CurveWidget::getScreenPixelRatio() const
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return windowHandle()->devicePixelRatio()
#else
return 1.;
return _imp->_gui->isHighDPI() ? 2. : 1.;
#endif
}
#endif
Expand Down
9 changes: 5 additions & 4 deletions Gui/CurveWidgetPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ CurveWidgetPrivate::drawSelectionRectangle()
// always running in the main thread
assert( qApp && qApp->thread() == QThread::currentThread() );
assert( QGLContext::currentContext() == _widget->context() );

double screenPixelRatio = _widget->getScreenPixelRatio();
{
GLProtectAttrib a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);

Expand All @@ -311,7 +311,7 @@ CurveWidgetPrivate::drawSelectionRectangle()
glEnd();


glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);

glColor4f(0.5, 0.5, 0.5, 1.);
glBegin(GL_LINE_LOOP);
Expand Down Expand Up @@ -560,6 +560,7 @@ CurveWidgetPrivate::drawSelectedKeyFramesBbox()
// always running in the main thread
assert( qApp && qApp->thread() == QThread::currentThread() );
assert( QGLContext::currentContext() == _widget->context() );
double screenPixelRatio = _widget->getScreenPixelRatio();

{
GLProtectAttrib a(GL_HINT_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
Expand All @@ -576,7 +577,7 @@ CurveWidgetPrivate::drawSelectedKeyFramesBbox()
double xMid = ( topLeft.x() + btmRight.x() ) / 2.;
double yMid = ( topLeft.y() + btmRight.y() ) / 2.;

glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);

glColor4f(0.5, 0.5, 0.5, 1.);
glBegin(GL_LINE_LOOP);
Expand Down Expand Up @@ -623,7 +624,7 @@ CurveWidgetPrivate::drawSelectedKeyFramesBbox()
}
glEnd();

glPointSize(BOUNDING_BOX_HANDLE_SIZE);
glPointSize(BOUNDING_BOX_HANDLE_SIZE * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2f( topLeft.x(), topLeft.y() );
glVertex2f( btmRight.x(), topLeft.y() );
Expand Down
4 changes: 3 additions & 1 deletion Gui/CustomParamInteract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QtCore/QByteArray>

#include "Gui/KnobGui.h"
#include "Gui/Gui.h"
#include "Gui/QtEnumConvert.h"
#include "Gui/GuiApplicationManager.h"

Expand Down Expand Up @@ -198,7 +199,8 @@ CustomParamInteract::getScreenPixelRatio() const
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return windowHandle()->devicePixelRatio()
#else
return 1.;
KnobGuiPtr k = _imp->knob.lock();
return (k && k->getGui()->isHighDPI()) ? 2. : 1.;
#endif
}
#endif
Expand Down
15 changes: 9 additions & 6 deletions Gui/DopeSheetView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,8 @@ DopeSheetViewPrivate::drawNodeRowSeparation(const DSNodePtr dsNode) const
GLProtectAttrib a(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT);
QRectF nameItemRect = hierarchyView->visualItemRect( dsNode->getTreeItem() );
QRectF rowRect = nameItemRectToRowRect(nameItemRect);

glLineWidth( appPTR->getCurrentSettings()->getDopeSheetEditorNodeSeparationWith() );
double screenPixelRatio = q_ptr->getScreenPixelRatio();
glLineWidth(appPTR->getCurrentSettings()->getDopeSheetEditorNodeSeparationWith() * screenPixelRatio);
glColor4f(0.f, 0.f, 0.f, 1.f);

glBegin(GL_LINES);
Expand All @@ -1123,6 +1123,7 @@ DopeSheetViewPrivate::drawNodeRowSeparation(const DSNodePtr dsNode) const
void
DopeSheetViewPrivate::drawRange(const DSNodePtr &dsNode) const
{
double screenPixelRatio = q_ptr->getScreenPixelRatio();
// Draw the clip
{
std::map<DSNode *, FrameRange >::const_iterator foundRange = nodeRanges.find( dsNode.get() );
Expand Down Expand Up @@ -1173,7 +1174,7 @@ DopeSheetViewPrivate::drawRange(const DSNodePtr &dsNode) const
clipRectCenterY = (clipRectZoomCoords.y1 + clipRectZoomCoords.y2) / 2.;

GLProtectAttrib aa(GL_CURRENT_BIT | GL_LINE_BIT);
glLineWidth(2);
glLineWidth(2 * screenPixelRatio);

glColor4f(fillColor.redF(), fillColor.greenF(), fillColor.blueF(), 1.f);

Expand Down Expand Up @@ -1589,6 +1590,7 @@ void
DopeSheetViewPrivate::drawSelectionRect() const
{
running_in_main_thread_and_context(q_ptr);
double screenPixelRatio = q_ptr->getScreenPixelRatio();

// Perform drawing
{
Expand All @@ -1609,7 +1611,7 @@ DopeSheetViewPrivate::drawSelectionRect() const
glVertex2f(selectionRect.x2, selectionRect.y1);
glEnd();

glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);

// Draw outline
glColor4f(0.5, 0.5, 0.5, 1.);
Expand All @@ -1633,6 +1635,7 @@ void
DopeSheetViewPrivate::drawSelectedKeysBRect() const
{
running_in_main_thread_and_context(q_ptr);
double screenPixelRatio = q_ptr->getScreenPixelRatio();

// Perform drawing
{
Expand All @@ -1643,7 +1646,7 @@ DopeSheetViewPrivate::drawSelectedKeysBRect() const
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);

glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);

glColor4f(0.5, 0.5, 0.5, 1.);

Expand Down Expand Up @@ -2711,7 +2714,7 @@ DopeSheetView::getScreenPixelRatio() const
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return windowHandle()->devicePixelRatio()
#else
return 1.;
return _imp->gui->isHighDPI() ? 2. : 1.;
#endif
}
#endif
Expand Down
21 changes: 17 additions & 4 deletions Gui/Histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,16 @@ Histogram::onCPUHistogramComputed()

#endif

double
Histogram::getScreenPixelRatio() const
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return windowHandle()->devicePixelRatio()
#else
return getGui()->isHighDPI() ? 2. : 1.;
#endif
}

void
HistogramPrivate::drawScale()
{
Expand Down Expand Up @@ -1653,9 +1663,11 @@ HistogramPrivate::drawWarnings()
}
}


void
HistogramPrivate::drawMissingImage()
{
double screenPixelRatio = widget->getScreenPixelRatio();
QPointF topLeft = zoomCtx.toZoomCoordinates(0, 0);
QPointF btmRight = zoomCtx.toZoomCoordinates( widget->width(), widget->height() );
QPointF topRight( btmRight.x(), topLeft.y() );
Expand All @@ -1664,14 +1676,14 @@ HistogramPrivate::drawMissingImage()
GLProtectAttrib a(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT);

glColor4f(0.9, 0.9, 0, 1);
glLineWidth(1.5);
glLineWidth(1.5 * screenPixelRatio);
glBegin(GL_LINES);
glVertex2f( topLeft.x(), topLeft.y() );
glVertex2f( btmRight.x(), btmRight.y() );
glVertex2f( btmLeft.x(), btmLeft.y() );
glVertex2f( topRight.x(), topRight.y() );
glEnd();
glLineWidth(1.);
glLineWidth(1. * screenPixelRatio);
}
QString txt( tr("Missing image") );
QFontMetrics m(_font);
Expand All @@ -1687,8 +1699,9 @@ void
HistogramPrivate::drawViewerPicker()
{
// always running in the main thread
double screenPixelRatio = widget->getScreenPixelRatio();

glLineWidth(2.);
glLineWidth(2. * screenPixelRatio);

assert( qApp && qApp->thread() == QThread::currentThread() );
assert( QGLContext::currentContext() == widget->context() );
Expand Down Expand Up @@ -1757,7 +1770,7 @@ HistogramPrivate::drawViewerPicker()
glEnd();
}

glLineWidth(1.);
glLineWidth(1. * screenPixelRatio);
} // HistogramPrivate::drawViewerPicker

void
Expand Down
1 change: 1 addition & 0 deletions Gui/Histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON
void hideViewerCursor();

int getViewerTextureInputDisplayed() const;
double getScreenPixelRatio() const;

public Q_SLOTS:

Expand Down

0 comments on commit 2d3d97b

Please sign in to comment.