Restore support for using faster dotted pens in wxMSW

Changes of d245dc9e1f (Fix drawing of dotted lines with wxDC in wxMSW,
2020-03-27) improved the appearance of dotted and dashed lines in wxMSW
but at the expense of significant (up to a factor of 300) slowdown.

Allow the applications for which the drawing performance is important to
explicitly request the old behaviour, with uglier, but faster, pens by
choosing to use low quality pens.

Update the graphics benchmark to allow specifying the pen quality and
verify that the performance when using it is the same as before 3.1.4.

See https://github.com/wxWidgets/wxWidgets/pull/2218

See #7097.

Closes #18875.
This commit is contained in:
Vadim Zeitlin
2021-02-07 01:27:00 +01:00
parent a5afa85c0a
commit b53f7ac904
6 changed files with 208 additions and 10 deletions

View File

@@ -52,6 +52,7 @@ struct GraphicsBenchmarkOptions
mapMode = 0;
penWidth = 0;
penStyle = wxPENSTYLE_INVALID;
penQuality = wxPEN_QUALITY_DEFAULT;
width = 800;
height = 600;
@@ -87,6 +88,7 @@ struct GraphicsBenchmarkOptions
numIters;
wxPenStyle penStyle;
wxPenQuality penQuality;
bool testBitmaps,
testImages,
@@ -410,16 +412,29 @@ private:
{
if ( opts.mapMode != 0 )
dc.SetMapMode((wxMappingMode)opts.mapMode);
bool setPen = false;
wxPenInfo penInfo(*wxWHITE);
if ( opts.penWidth != 0 )
dc.SetPen(wxPen(*wxWHITE, opts.penWidth));
{
penInfo.Width(opts.penWidth);
setPen = true;
}
if ( opts.penStyle != wxPENSTYLE_INVALID )
{
wxPen pen = dc.GetPen();
if ( !pen.IsOk() )
pen = wxPen(*wxWHITE, 1);
pen.SetStyle(opts.penStyle);
dc.SetPen(pen);
penInfo.Style(opts.penStyle);
setPen = true;
}
if ( opts.penQuality != wxPEN_QUALITY_DEFAULT )
{
penInfo.Quality(opts.penQuality);
setPen = true;
}
if ( setPen )
dc.SetPen(penInfo);
}
void BenchmarkLines(const wxString& msg, wxDC& dc)
@@ -865,6 +880,7 @@ public:
{ wxCMD_LINE_OPTION, "m", "map-mode", "", wxCMD_LINE_VAL_NUMBER },
{ wxCMD_LINE_OPTION, "p", "pen-width", "", wxCMD_LINE_VAL_NUMBER },
{ wxCMD_LINE_OPTION, "s", "pen-style", "solid | dot | long_dash | short_dash", wxCMD_LINE_VAL_STRING },
{ wxCMD_LINE_OPTION, "", "pen-quality", "default | low | high", wxCMD_LINE_VAL_STRING },
{ wxCMD_LINE_OPTION, "w", "width", "", wxCMD_LINE_VAL_NUMBER },
{ wxCMD_LINE_OPTION, "h", "height", "", wxCMD_LINE_VAL_NUMBER },
{ wxCMD_LINE_OPTION, "I", "images", "", wxCMD_LINE_VAL_NUMBER },
@@ -913,6 +929,19 @@ public:
}
}
}
wxString penQuality;
if ( parser.Found("pen-quality", &penQuality) )
{
if ( penQuality == "low" )
opts.penQuality = wxPEN_QUALITY_LOW;
else if ( penQuality == "high" )
opts.penQuality = wxPEN_QUALITY_HIGH;
else if ( penQuality != "default" )
{
wxLogError("Unsupported pen quality.");
return false;
}
}
if ( parser.Found("w", &opts.width) && opts.width < 1 )
return false;
if ( parser.Found("h", &opts.height) && opts.height < 1 )