sw_engine: small optimization with a fast-clipping region access

Now the engine can access intermidate rle sections
with a specific y ranges, It doesn't need full iterations.
This commit is contained in:
Hermet Park 2025-06-21 12:14:55 +09:00
parent 4e495d3c81
commit a4849d40b3

View file

@ -881,12 +881,18 @@ bool rleClip(SwRle *rle, const SwRle *clip)
Array<SwSpan> out;
out.reserve(std::max(rle->spans.count, clip->spans.count));
auto spans = rle->data();
auto end = rle->spans.end();
auto cspans = clip->data();
auto cend = clip->spans.end();
const SwSpan *end;
auto spans = rle->fetch(clip->spans.first().y, clip->spans.last().y, &end);
while(spans < end && cspans < cend) {
if (spans >= end) {
rle->spans.clear();
return false;
}
const SwSpan *cend;
auto cspans = clip->fetch(spans->y, (end - 1)->y, &cend);
while (spans < end && cspans < cend) {
//align y-coordinates.
if (cspans->y > spans->y) {
++spans;
@ -928,9 +934,10 @@ bool rleClip(SwRle *rle, const RenderRegion* clip)
Array<SwSpan> out;
out.reserve(rle->spans.count);
auto data = out.data;
const SwSpan* end;
uint16_t x, len;
ARRAY_FOREACH(p, rle->spans) {
for (auto p = rle->fetch(*clip, &end); p < end; ++p) {
if (p->y >= max.y) break;
if (p->y < min.y || p->x >= max.x || (p->x + p->len) <= min.x) continue;
if (p->x < min.x) {
@ -948,4 +955,4 @@ bool rleClip(SwRle *rle, const RenderRegion* clip)
}
out.move(rle->spans);
return true;
}
}