refactor(new_editor): unify d3d12 text run caching
This commit is contained in:
@@ -224,10 +224,13 @@ void CompositeCoverage(
|
||||
const std::size_t srcOffset =
|
||||
static_cast<std::size_t>(row) * textureStride +
|
||||
static_cast<std::size_t>(column) * channelCount;
|
||||
std::uint8_t coverage = 0u;
|
||||
std::uint32_t coverageSum = 0u;
|
||||
for (std::size_t channel = 0u; channel < channelCount; ++channel) {
|
||||
coverage = (std::max)(coverage, alphaTexture[srcOffset + channel]);
|
||||
coverageSum += static_cast<std::uint32_t>(alphaTexture[srcOffset + channel]);
|
||||
}
|
||||
const std::uint8_t coverage = static_cast<std::uint8_t>(
|
||||
(coverageSum + static_cast<std::uint32_t>(channelCount / 2u)) /
|
||||
static_cast<std::uint32_t>(channelCount));
|
||||
|
||||
if (coverage == 0u) {
|
||||
continue;
|
||||
@@ -533,13 +536,9 @@ float D3D12UiTextSystem::MeasureTextWidth(
|
||||
bool D3D12UiTextSystem::RasterizeTextMask(
|
||||
std::string_view text,
|
||||
float fontSize,
|
||||
std::vector<std::uint8_t>& outRgbaPixels,
|
||||
UINT& outWidth,
|
||||
UINT& outHeight,
|
||||
RasterizedTextRun& outRun,
|
||||
std::string& outError) {
|
||||
outRgbaPixels.clear();
|
||||
outWidth = 0u;
|
||||
outHeight = 0u;
|
||||
outRun = {};
|
||||
outError.clear();
|
||||
|
||||
if (!m_dwriteFactory) {
|
||||
@@ -593,16 +592,18 @@ bool D3D12UiTextSystem::RasterizeTextMask(
|
||||
const float topPad = (std::max)(overhangMetrics.top, 0.0f);
|
||||
const float rightPad = (std::max)(overhangMetrics.right, 0.0f);
|
||||
const float bottomPad = (std::max)(overhangMetrics.bottom, 0.0f);
|
||||
outWidth = (std::max)(
|
||||
outRun.width = (std::max)(
|
||||
1u,
|
||||
static_cast<UINT>(std::ceil(
|
||||
textMetrics.widthIncludingTrailingWhitespace + leftPad + rightPad)));
|
||||
outHeight = (std::max)(
|
||||
outRun.height = (std::max)(
|
||||
1u,
|
||||
static_cast<UINT>(std::ceil(
|
||||
(std::max)(textMetrics.height, scaledFontSize * 1.6f) + topPad + bottomPad)));
|
||||
outRgbaPixels.assign(
|
||||
static_cast<std::size_t>(outWidth) * static_cast<std::size_t>(outHeight) * 4u,
|
||||
outRun.offsetX = -leftPad;
|
||||
outRun.offsetY = -topPad;
|
||||
outRun.rgbaPixels.assign(
|
||||
static_cast<std::size_t>(outRun.width) * static_cast<std::size_t>(outRun.height) * 4u,
|
||||
0u);
|
||||
|
||||
GlyphRunCollector* collector = new GlyphRunCollector(dpiScale);
|
||||
@@ -675,9 +676,9 @@ bool D3D12UiTextSystem::RasterizeTextMask(
|
||||
}
|
||||
|
||||
CompositeCoverage(
|
||||
outRgbaPixels,
|
||||
outWidth,
|
||||
outHeight,
|
||||
outRun.rgbaPixels,
|
||||
outRun.width,
|
||||
outRun.height,
|
||||
bounds,
|
||||
alphaTexture.data(),
|
||||
static_cast<std::size_t>(boundsWidth) * 3u,
|
||||
|
||||
Reference in New Issue
Block a user