Skip to content

Commit

Permalink
Merge pull request aduros#108 from MaxGraey/opt-hline
Browse files Browse the repository at this point in the history
Optimize drawHLineInternal
  • Loading branch information
aduros authored Sep 25, 2021
2 parents a42d8a7 + 53218c8 commit 56fdb3e
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions runtimes/web/src/framebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,24 @@ export class Framebuffer {
}

drawHLineInternal(color, startX, y, endX) {
const fillEnd = endX - (endX % 4);
const fillStart = Math.min((startX + 3) & ~0x03, fillEnd);
const fillEnd = endX - (endX & 3);
const fillStart = Math.min((startX + 3) & ~3, fillEnd);

if (fillEnd - fillStart >= 4) {
if (fillEnd - fillStart > 3) {
for (let xx = startX; xx < fillStart; xx++) {
this.drawPoint(color, xx, y);
}

if (fillEnd - fillStart >= 4) {
const from = (WIDTH * y + fillStart) >>> 2;
const to = (WIDTH * y + fillEnd) >>> 2;
const fillColor =
(color << 6) | (color << 4) | (color << 2) | color;
const from = (WIDTH * y + fillStart) >>> 2;
const to = (WIDTH * y + fillEnd) >>> 2;
const fillColor = color * 0b01010101;

this.bytes.fill(fillColor, from, to);
}
this.bytes.fill(fillColor, from, to);
startX = fillEnd;
}

for (let xx = fillEnd; xx < endX; xx++) {
this.drawPoint(color, xx, y);
}
} else {
for (let xx = startX; xx < endX; xx++) {
this.drawPoint(color, xx, y);
}
for (let xx = startX; xx < endX; xx++) {
this.drawPoint(color, xx, y);
}
}

Expand Down

0 comments on commit 56fdb3e

Please sign in to comment.