Skip to content

Commit 620243b

Browse files
authored
Merge pull request #9194 from gadfort/gui-bpin-limits
gui: limit number of bpins to avoid excessive render times
2 parents 514fd69 + 77ce483 commit 620243b

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/gui/src/renderThread.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QPolygon>
1111
#include <algorithm>
1212
#include <cmath>
13+
#include <cstdint>
1314
#include <exception>
1415
#include <iterator>
1516
#include <mutex>
@@ -1552,18 +1553,14 @@ void RenderThread::setupIOPins(odb::dbBlock* block, const odb::Rect& bounds)
15521553
}
15531554

15541555
const auto die_area = block->getDieArea();
1555-
const auto die_width = die_area.dx();
1556-
const auto die_height = die_area.dy();
15571556

15581557
pin_draw_names_ = viewer_->options_->areIOPinNamesVisible();
1558+
const double scale_factor
1559+
= 0.02; // 4 Percent of bounds is used to draw pin-markers
1560+
const int die_max_dim = std::min(die_area.maxDXDY(), bounds.maxDXDY());
1561+
const double abs_min_dim = 8.0; // prevent markers from falling apart
1562+
pin_max_size_ = std::max(scale_factor * die_max_dim, abs_min_dim);
15591563
if (pin_draw_names_) {
1560-
const double scale_factor
1561-
= 0.02; // 4 Percent of bounds is used to draw pin-markers
1562-
const int die_max_dim
1563-
= std::min(std::max(die_width, die_height), bounds.maxDXDY());
1564-
const double abs_min_dim = 8.0; // prevent markers from falling apart
1565-
pin_max_size_ = std::max(scale_factor * die_max_dim, abs_min_dim);
1566-
15671564
pin_font_ = viewer_->options_->ioPinMarkersFont();
15681565
const QFontMetrics font_metrics(pin_font_);
15691566

@@ -1690,16 +1687,33 @@ void RenderThread::drawIOPins(Painter& painter,
16901687
};
16911688
std::vector<PinText> pin_text_spec;
16921689

1690+
const int min_bpin_size = viewer_->options_->isDetailedVisibility()
1691+
? viewer_->fineViewableResolution()
1692+
: viewer_->nominalViewableResolution();
1693+
const int64_t max_lin_bpins = bounds.minDXDY() / min_bpin_size;
1694+
const int64_t max_bpins
1695+
= std::min(kMaxBPinsPerLayer, max_lin_bpins * max_lin_bpins);
1696+
16931697
painter.setPen(layer);
16941698
painter.setBrush(layer);
16951699

1700+
auto bpins = viewer_->search_.searchBPins(
1701+
block, layer, bounds.xMin(), bounds.yMin(), bounds.xMax(), bounds.yMax());
1702+
debugPrint(logger_,
1703+
GUI,
1704+
"draw",
1705+
2,
1706+
"found {} bpins on layer {}, drawing limit {} ({}) bpins",
1707+
bpins.size(),
1708+
layer->getName(),
1709+
max_bpins,
1710+
max_lin_bpins);
1711+
if (bpins.size() > max_bpins) {
1712+
return;
1713+
}
1714+
16961715
std::vector<odb::Rect> pin_text_spec_shape_rects;
1697-
for (const auto& [box, pin] : viewer_->search_.searchBPins(block,
1698-
layer,
1699-
bounds.xMin(),
1700-
bounds.yMin(),
1701-
bounds.xMax(),
1702-
bounds.yMax())) {
1716+
for (const auto& [box, pin] : bpins) {
17031717
if (restart_) {
17041718
break;
17051719
}

src/gui/src/renderThread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <QString>
1010
#include <QThread>
1111
#include <QWaitCondition>
12+
#include <cstdint>
1213
#include <map>
1314
#include <mutex>
1415
#include <utility>
@@ -169,6 +170,8 @@ class RenderThread : public QThread
169170
QFont pin_font_;
170171
bool pin_draw_names_ = false;
171172
double pin_max_size_ = 0.0;
173+
174+
static constexpr int64_t kMaxBPinsPerLayer = 100000;
172175
};
173176

174177
} // namespace gui

src/gui/src/search.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <QObject>
77
#include <atomic>
8+
#include <iterator>
89
#include <map>
910
#include <mutex>
1011
#include <tuple>
@@ -126,6 +127,8 @@ class Search : public QObject, public odb::dbBlockCallBackObj
126127
Iterator begin() { return begin_; }
127128
Iterator end() { return end_; }
128129

130+
int size() const { return std::distance(begin_, end_); }
131+
129132
private:
130133
Iterator begin_;
131134
Iterator end_;

0 commit comments

Comments
 (0)