Made ByteItem pixmap cache generation thread-safe
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Bloom::Widgets
|
|||||||
ByteItem::ByteItem(Targets::TargetMemoryAddress address)
|
ByteItem::ByteItem(Targets::TargetMemoryAddress address)
|
||||||
: HexViewerItem(address)
|
: HexViewerItem(address)
|
||||||
{
|
{
|
||||||
if (ByteItem::standardPixmapsByValue.empty()) {
|
if (!ByteItem::pixmapCachesGenerated) {
|
||||||
ByteItem::generatePixmapCaches();
|
ByteItem::generatePixmapCaches();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,12 +94,17 @@ namespace Bloom::Widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ByteItem::generatePixmapCaches() {
|
void ByteItem::generatePixmapCaches() {
|
||||||
static const auto standardBackgroundColor = QColor(0x32, 0x33, 0x30, 255);
|
const auto lock = std::unique_lock(ByteItem::pixmapCacheMutex);
|
||||||
static const auto highlightedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255);
|
|
||||||
static const auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255);
|
|
||||||
static const auto groupedBackgroundColor = QColor(0x44, 0x44, 0x41, 255);
|
|
||||||
static const auto stackMemoryBackgroundColor = QColor(0x67, 0x57, 0x20, 210);
|
|
||||||
|
|
||||||
|
if (ByteItem::pixmapCachesGenerated) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr auto standardBackgroundColor = QColor(0x32, 0x33, 0x30, 255);
|
||||||
|
static constexpr auto highlightedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255);
|
||||||
|
static constexpr auto selectedBackgroundColor = QColor(0x3C, 0x59, 0x5C, 255);
|
||||||
|
static constexpr auto groupedBackgroundColor = QColor(0x44, 0x44, 0x41, 255);
|
||||||
|
static constexpr auto stackMemoryBackgroundColor = QColor(0x44, 0x44, 0x41, 200);
|
||||||
static const auto hoveredStackMemoryBackgroundColor = QColor(
|
static const auto hoveredStackMemoryBackgroundColor = QColor(
|
||||||
stackMemoryBackgroundColor.red(),
|
stackMemoryBackgroundColor.red(),
|
||||||
stackMemoryBackgroundColor.green(),
|
stackMemoryBackgroundColor.green(),
|
||||||
@@ -257,5 +262,7 @@ namespace Bloom::Widgets
|
|||||||
painter.setPen(standardFontColor);
|
painter.setPen(standardFontColor);
|
||||||
painter.drawText(byteItemRect, Qt::AlignCenter, "??");
|
painter.drawText(byteItemRect, Qt::AlignCenter, "??");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteItem::pixmapCachesGenerated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
#include "HexViewerItem.hpp"
|
#include "HexViewerItem.hpp"
|
||||||
@@ -35,6 +37,9 @@ namespace Bloom::Widgets
|
|||||||
) const override;
|
) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static inline std::atomic<bool> pixmapCachesGenerated = false;
|
||||||
|
static inline std::mutex pixmapCacheMutex;
|
||||||
|
|
||||||
static inline std::vector<QPixmap> standardPixmapsByValue = {};
|
static inline std::vector<QPixmap> standardPixmapsByValue = {};
|
||||||
static inline std::vector<QPixmap> selectedPixmapsByValue = {};
|
static inline std::vector<QPixmap> selectedPixmapsByValue = {};
|
||||||
static inline std::vector<QPixmap> groupedPixmapsByValue = {};
|
static inline std::vector<QPixmap> groupedPixmapsByValue = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user