PERFORCE change 219770 for review
Brooks Davis
brooks at FreeBSD.org
Tue Nov 13 20:37:32 UTC 2012
http://p4web.freebsd.org/@@219770?ac=10
Change 219770 by brooks at brooks_zenith on 2012/11/13 20:36:49
Checkpoint a working configuration dialog.
Affected files ...
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/cheripoint/cheripoint.c#3 edit
Differences ...
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/cheripoint/cheripoint.c#3 (text+ko) ====
@@ -52,7 +52,9 @@
MTL_DM_640x480_CENTER /* 640x480 VGA from 480p, center pixels */
};
+int sb_vis = 0;
enum sbtype sb = SB_CAPSICUM;
+enum mtl_display_mode res = MTL_DM_720x480;
static uint32_t slide_fcol;
static uint32_t slide_width;
@@ -90,7 +92,253 @@
}
}
+/*
+ * Draw simple configuration dialog, let the user toggle things. When
+ * done (user pinches) return 0 if nothing changed, >0 if something did.
+ *
+ * The screen looks like:
+ *
+ * Sandbox Resolution
+ * [*] None [ ] 800x480
+ * [ ] Capsicum [*] 720x480
+ * [ ] CHERI [ ] 640x480 (Left)
+ * [ ] 640x480 (Center)
+ * [ ] Visible
+ *
+ */
+#define CD_BORDER_WIDTH 8
+#define CD_TEXT_SCALE 2
+#define CD_TEXT_ROWS 6
+#define CD_SB_COLS 12
+#define CD_GAP 16
+#define CD_RES_COLS 20
static int
+config_dialog(void)
+{
+ int changed = 0;
+ int f_height, f_width, tbufcols;
+ char *text;
+ uint32_t d_width, d_height, d_x, d_y;
+ uint32_t cfg_startr, row;
+ uint32_t sb_startc, sb_endc;
+ uint32_t res_startc, res_endc;
+ uint32_t *dbuf, *savebuf, *textbuf;
+ struct tsstate *ts;
+
+ dbuf = savebuf = textbuf = NULL;
+ text = NULL;
+
+ if ((savebuf = malloc(sizeof(uint32_t) * fb_width * fb_height)) == NULL)
+ return (-1);
+
+ f_width = fb_get_font_width() * 2;
+ f_height = fb_get_font_height() * 2;
+ tbufcols = CD_RES_COLS; /* XXX: max chars */
+ textbuf = malloc(sizeof(uint32_t) * f_height * f_width * tbufcols);
+ if (textbuf == NULL) {
+ changed = -1;
+ goto error;
+ }
+ if ((text = malloc(tbufcols + 1)) == NULL) {
+ changed = -1;
+ goto error;
+ }
+
+ d_width = (CD_BORDER_WIDTH * 2) + CD_GAP +
+ ((CD_SB_COLS + CD_RES_COLS) * f_width);
+ d_height = (CD_BORDER_WIDTH * 2) + (CD_TEXT_ROWS * f_height);
+ d_x = (fb_width - d_width) / 2;
+ d_y = (fb_height - d_height) / 2;
+ if ((dbuf = malloc(sizeof(uint32_t) * d_width * d_height)) == NULL) {
+ changed = -1;
+ goto error;
+ }
+
+ fb_save(savebuf);
+
+repaint:
+ fb_fill_buf(dbuf, white, d_width, d_height);
+
+ cfg_startr = CD_BORDER_WIDTH;
+ sb_startc = CD_BORDER_WIDTH;
+ sb_endc = sb_startc + (CD_SB_COLS * f_width);
+ res_startc = sb_endc + CD_GAP;
+ res_endc = res_startc + (CD_RES_COLS * f_width);
+
+ fb_fill_buf(textbuf, white, f_width * CD_SB_COLS, f_height);
+ fb_render_text("Sandbox",
+ 2, black, white, textbuf, f_width * CD_SB_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH, CD_BORDER_WIDTH + (0 * f_height),
+ textbuf, f_width * CD_SB_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_SB_COLS, f_height);
+ sprintf(text, "[%c] None", sb == SB_NONE ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_SB_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH, CD_BORDER_WIDTH + (1 * f_height),
+ textbuf, f_width * CD_SB_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_SB_COLS, f_height);
+ sprintf(text, "[%c] Capsicum", sb == SB_CAPSICUM ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_SB_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH, CD_BORDER_WIDTH + (2 * f_height),
+ textbuf, f_width * CD_SB_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_SB_COLS, f_height);
+ sprintf(text, "[%c] CHERI", sb == SB_CHERI ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_SB_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH, CD_BORDER_WIDTH + (3 * f_height),
+ textbuf, f_width * CD_SB_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_SB_COLS, f_height);
+ sprintf(text, "[%c] Visible", sb_vis ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_SB_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH, CD_BORDER_WIDTH + (5 * f_height),
+ textbuf, f_width * CD_SB_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_RES_COLS, f_height);
+ fb_render_text("Resolution",
+ 2, black, white, textbuf, f_width * CD_RES_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH + (f_width * CD_SB_COLS) + CD_GAP,
+ CD_BORDER_WIDTH + (0 * f_height),
+ textbuf, f_width * CD_RES_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_RES_COLS, f_height);
+ sprintf(text, "[%c] 800x480", res == MTL_DM_800x480 ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_RES_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH + (f_width * CD_SB_COLS) + CD_GAP,
+ CD_BORDER_WIDTH + (1 * f_height),
+ textbuf, f_width * CD_RES_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_RES_COLS, f_height);
+ sprintf(text, "[%c] 720x480", res == MTL_DM_720x480 ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_RES_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH + (f_width * CD_SB_COLS) + CD_GAP,
+ CD_BORDER_WIDTH + (2 * f_height),
+ textbuf, f_width * CD_RES_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_RES_COLS, f_height);
+ sprintf(text, "[%c] 640x480 (Left)", res == MTL_DM_640x480 ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_RES_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH + (f_width * CD_SB_COLS) + CD_GAP,
+ CD_BORDER_WIDTH + (3 * f_height),
+ textbuf, f_width * CD_RES_COLS, f_height);
+
+ fb_fill_buf(textbuf, white, f_width * CD_RES_COLS, f_height);
+ sprintf(text, "[%c] 640x480 (Centered)",
+ res == MTL_DM_640x480_CENTER ? '*' : ' ');
+ fb_render_text(text, 2, black, white, textbuf,
+ f_width * CD_RES_COLS, f_height);
+ fb_composite(dbuf, d_width, d_height,
+ CD_BORDER_WIDTH + (f_width * CD_SB_COLS) + CD_GAP,
+ CD_BORDER_WIDTH + (4 * f_height),
+ textbuf, f_width * CD_RES_COLS, f_height);
+
+ fb_post_region(dbuf, d_x, d_y, d_width, d_height);
+
+ for(;;) {
+ ts = ts_poll();
+#if DEBUG
+ printf("gesture 0x%x\n", ts->ts_gesture);
+#endif
+ switch (ts->ts_gesture) {
+ case TSG2_ZOOM_OUT:
+ goto done;
+ case TSG_CLICK:
+ row = (ts->ts_y1 - d_y - cfg_startr) / f_height;
+ if ((uint)ts->ts_x1 > d_x + sb_startc &&
+ (uint)ts->ts_x1 < d_x + sb_endc) {
+ switch (row) {
+ case 1:
+ if (sb != SB_NONE) {
+ changed = 1;
+ sb = SB_NONE;
+ goto repaint;
+ }
+ break;
+ case 2:
+ if (sb != SB_CAPSICUM) {
+ changed = 1;
+ sb = SB_CAPSICUM;
+ goto repaint;
+ }
+ break;
+ case 4:
+ if (sb != SB_CHERI) {
+ changed = 1;
+ sb = SB_CHERI;
+ goto repaint;
+ }
+ break;
+ case 6:
+ changed = 1;
+ sb_vis = sb_vis ? 0 : 1;
+ goto repaint;
+ break;
+ }
+ } else if ((uint)ts->ts_x1 > d_y + res_startc &&
+ (uint)ts->ts_x1 < d_y + res_endc) {
+ switch (row) {
+ case 1:
+ if (res != MTL_DM_800x480) {
+ changed = 1;
+ res = MTL_DM_800x480;
+ goto repaint;
+ }
+ break;
+ case 2:
+ if (res != MTL_DM_720x480) {
+ changed = 1;
+ res = MTL_DM_720x480;
+ goto repaint;
+ }
+ break;
+ case 3:
+ if (res != MTL_DM_640x480) {
+ changed = 1;
+ res = MTL_DM_640x480;
+ goto repaint;
+ }
+ break;
+ case 4:
+ if (res != MTL_DM_640x480_CENTER) {
+ changed = 1;
+ res = MTL_DM_640x480_CENTER;
+ goto repaint;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+done:
+ fb_post(savebuf);
+error:
+ free(savebuf);
+ free(dbuf);
+ free(textbuf);
+ free(text);
+
+ return (changed);
+}
+
+static int
strpcmp(const void *v1, const void *v2)
{
const char * const *sp1;
@@ -112,7 +360,7 @@
int pfd;
struct iboxstate *is;
- printf("rendering cover %s\n", cover);
+ printf("rendering cover\n");
fb_fill_region(white, 0, 0, fb_width, fb_height);
@@ -233,7 +481,6 @@
addslide(int *np, int *maxp, char ***arrayp, const char *name)
{
- printf("n %d, max %d\n", *np, *maxp);
if (*maxp == 0) {
*maxp = 8;
if ((*arrayp = malloc(sizeof(**arrayp) * (*maxp))) == NULL)
@@ -261,6 +508,7 @@
struct dirent *entry;
char *coverpat;
char **covers, **slides;
+ int error;
int cover, ncovers, maxcovers;
int slide, nslides, maxslides;
struct tsstate *ts;
@@ -276,7 +524,7 @@
fb_load_syscons_font(NULL, "/usr/share/syscons/fonts/iso-8x16.fnt");
busy_indicator();
- set_display_mode(MTL_DM_720x480);
+ set_display_mode(res);
printf("reading slides\n");
@@ -289,7 +537,6 @@
if (entry->d_type != DT_REG)
continue;
- printf("checking it %s is a cover\n", entry->d_name);
if (fnmatch("*-cover-*.png", entry->d_name, 0) == 0)
addslide(&ncovers, &maxcovers, &covers, entry->d_name);
else
@@ -315,12 +562,20 @@
ts_drain();
nop:
ts = ts_poll();
+#ifdef DEBUG
printf("gesture 0x%x\n", ts->ts_gesture);
+#endif
switch (ts->ts_gesture) {
case TSG2_ZOOM_OUT:
exit(0);
case TSG2_NORTH:
- /* XXX: display configuration box */
+ error = config_dialog();
+ ts_drain();
+ if (error == -1)
+ err(1, "internal error in config dialog");
+ else if (error == 0)
+ goto nop;
+ set_display_mode(res);
break;
case TSG_EAST:
if (slide == 0)
More information about the p4-projects
mailing list