Skip to content

Commit 18bcdec

Browse files
committed
bgcolor so you never blit your background
1 parent 1145d4c commit 18bcdec

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

Diff for: kernelflut.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <signal.h> /* sigaction, sig_atomic_t */
22
#include <stdbool.h> /* bool, true, false */
33
#include <stdio.h> /* perror, printf */
4-
#include <stdlib.h> /* atoi */
4+
#include <stdlib.h> /* atoi, strtoul */
55
#include <string.h> /* memset */
66
#include <unistd.h> /* close, getopt */
77

@@ -32,7 +32,7 @@ static void interrupt(int _, siginfo_t *__, void *___)
3232
doomed = 1;
3333
}
3434

35-
static int loop(int width)
35+
static int loop(int width, uint32_t bgcolor)
3636
{
3737
struct evdi_update update;
3838

@@ -56,7 +56,8 @@ static int loop(int width)
5656

5757
err = pf_set_buf((uint32_t *) update.fb, width,
5858
update.rects[rect].x1, update.rects[rect].x2,
59-
update.rects[rect].y1, update.rects[rect].y2);
59+
update.rects[rect].y1, update.rects[rect].y2,
60+
bgcolor);
6061
if (err)
6162
return err;
6263
}
@@ -78,6 +79,7 @@ static int usage(char *progname)
7879
"\n"
7980
"Options:\n"
8081
" -a use async i/o\n"
82+
" -b RRGGBB occasionally blit every pixel except this one\n"
8183
" -c CONNECTIONS size of pixelflut connection pool (default %d)\n"
8284
" -d WxH scale down to width W and height H\n"
8385
" -o X,Y move the top-left corner down by Y pixels and right by X pixels\n"
@@ -118,13 +120,20 @@ int main(int argc, char *argv[])
118120
int origin_x = 0;
119121
int origin_y = 0;
120122

123+
uint32_t bgcolor = PF_NO_BGCOLOR;
124+
121125
char c;
122126
int opt;
123-
while ((opt = getopt(argc, argv, "ac:d:o:sph?")) != -1) {
127+
while ((opt = getopt(argc, argv, "ab:c:d:o:sph?")) != -1) {
124128
switch (opt) {
125129
case 'a':
126130
asyncio = true;
127131
break;
132+
case 'b':
133+
bgcolor = strtoul(optarg, NULL, 16);
134+
if (bgcolor > 0x00ffffff)
135+
return usage(argv[0]);
136+
break;
128137
case 'c':
129138
connections = atoi(optarg);
130139
if (connections <= 0)
@@ -210,7 +219,7 @@ int main(int argc, char *argv[])
210219
return err;
211220

212221
const int width = 800; // DEBUG
213-
err = loop(width);
222+
err = loop(width, bgcolor);
214223
if (err == EXCEPTION_PT_FINISHED || err == EXCEPTION_INT)
215224
err = 0;
216225

Diff for: pixelflut.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#define ROUNDS 5
1616
#define STAGGER 2
17-
#define BYTES_PER_PIXEL 4 /* RGB32 */ // DEBUG
17+
#define REBLIT_FREQUENCY 23 /* should be prime and far from 2^n */
1818

1919
/* performance test */
2020
#define PT_TRIALS 5
@@ -175,9 +175,12 @@ int pf_set(int x, int y, unsigned char r, unsigned char g, unsigned char b)
175175
return 0;
176176
}
177177

178-
int pf_set_buf(uint32_t *fb, int width, int x1, int x2, int y1, int y2)
178+
int pf_set_buf(const uint32_t * const fb, const int width, const int x1, const int x2, const int y1, const int y2, const uint32_t bgcolor)
179179
{
180-
static uint32_t *last_buf = NULL;
180+
static const uint32_t *last_buf = NULL;
181+
static int skip_reblit = 0;
182+
183+
const bool ignore_bgcolor = (bgcolor == PF_NO_BGCOLOR);
181184

182185
if (pt_active)
183186
clock_gettime(CLOCK_MONOTONIC_RAW, &pt_running);
@@ -192,15 +195,16 @@ int pf_set_buf(uint32_t *fb, int width, int x1, int x2, int y1, int y2)
192195
int xi = x1 + row_bias;
193196

194197
for (int x = xi, i = row_start_i + xi; x < x2; x += ROUNDS, i += ROUNDS) {
198+
skip_reblit = (skip_reblit + 1) % REBLIT_FREQUENCY;
195199

196200
/* get next connection from pool */
197201
int fd = conns[active_conn_i];
198202
active_conn_i = (active_conn_i + 1) % num_conns;
199203

200204
uint32_t color = fb[i];
201205

202-
/* skip redundant pixels */
203-
if (last_buf && last_buf[i] == color)
206+
/* skip redundant pixels. sometimes reblit anyway if skip_reblit reaches zero */
207+
if (last_buf && last_buf[i] == color && (ignore_bgcolor || (color & 0x00ffffff) == bgcolor || skip_reblit))
204208
continue;
205209

206210
/* extract colors */

Diff for: pixelflut.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <stdint.h> /* uint16_t */
44

5+
#define PF_NO_BGCOLOR 0x80000000
6+
57
struct pf_size {
68
int w;
79
int h;
@@ -23,10 +25,11 @@ int pf_size(struct pf_size *ret);
2325
int pf_set(int x, int y, unsigned char r, unsigned char g, unsigned char b);
2426

2527
/*
26-
* pf_set_buf tells pixelflut at fd to set a bunch of RGB32 pixels from fb.
27-
* Returns 0 on success.
28+
* pf_set_buf tells pixelflut at fd to set a bunch of RGB32 pixels from fb. If
29+
* bgcolor isn't PF_NO_BGCOLOR, then occasionally repaint every pixel except
30+
* this color. Returns 0 on success.
2831
*/
29-
int pf_set_buf(uint32_t *fb, int width, int x1, int x2, int y1, int y2);
32+
int pf_set_buf(const uint32_t * const fb, const int width, const int x1, const int x2, const int y1, const int y2, const uint32_t bgcolor);
3033

3134
/*
3235
* pf_close closes the connection pool opened by pf_connect and deallocates its

0 commit comments

Comments
 (0)