1/**
2 * \file
3 * \brief Slide show
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <string.h>
18#include <barrelfish/barrelfish.h>
19#include <if/keyboard_defs.h>
20
21#include "slideshow.h"
22#include "bmp.h"
23#include "zlib_load.h"
24
25#define SLIDE_BMP_SIZE          3145728
26
27char    *fb = NULL;
28int     xres, yres, bpp;
29
30static char                     *screen = NULL;
31void                            *slide[MAX_SLIDES];
32size_t                          slide_length[MAX_SLIDES];
33size_t                          nslides = 0;
34size_t                          curslide = 0;
35
36#if 0
37static void cls(void)
38{
39    memset(fb, 0, SCREEN_SIZE);
40}
41#endif
42
43static void vsync(void)
44{
45    wait_for_vsync();
46    memcpy(screen, fb, SCREEN_SIZE);
47}
48
49static void draw_slide(void)
50{
51    void *myslide = malloc(SLIDE_BMP_SIZE);
52    assert(myslide != NULL);
53    size_t myslide_length;
54
55    int r = zlib_load(myslide, SLIDE_BMP_SIZE, &myslide_length,
56                      slide[curslide], slide_length[curslide]);
57    assert(r == 0);
58
59    r = bmp_load(myslide, myslide_length);
60    assert(r == 0);
61
62    free(myslide);
63
64    vsync();
65}
66
67void keyboard_key_event(struct keyboard_binding *b, uint8_t scancode, bool ext)
68{
69#if 0
70    bool pressed = scancode & 0x80 ? false : true;
71
72    if(pressed) {
73        printf("Keypress: %d\n", scancode);
74    }
75#endif
76
77    switch(scancode) {
78    case 77:        // Right arrow
79    case 81:        // Page down
80    case 80:        // Down arrow
81    case 57:        // Space
82        if(curslide < nslides - 1) {
83            curslide++;
84        }
85        printf("Next slide\n");
86        break;
87
88    case 75:        // Left arrow
89    case 73:        // Page up
90    case 72:        // Up arrow
91        if(curslide > 0) {
92            curslide--;
93        }
94        printf("Prev slide\n");
95        break;
96
97    case 1:         // escape
98        printf("Exit\n");
99        quit();
100
101    default:
102        return;
103    }
104
105    draw_slide();
106}
107
108void slideshow(char *scrn, int xr, int yr, int bp)
109{
110    xres = xr;
111    yres = yr;
112    assert(bp == 32 || bp == 24);
113    bpp = bp / 8;
114
115    // Get an appropriately sized off-screen surface
116    fb = malloc(SCREEN_SIZE);
117    assert(fb != NULL);
118
119    screen = scrn;
120
121    draw_slide();
122}
123