aboutsummaryrefslogtreecommitdiffstats
path: root/android/display.c
blob: 8bad5857d8c692278ad03f5ae37b9a82c40ef712 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Copyright (C) 2010 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/

/* Initialization of the Android-specific DisplayState.
 * Read docs/DISPLAY-STATE.TXT to understand what this
 * is supposed to do.
 */
#include "android/display.h"
#include "android/utils/system.h"

/*

TECHNICAL NOTE:

DisplayState <--> QFrameBuffer <--> QEmulator/SDL

*/

/* QFrameBuffer producer callbacks */

/* this is called periodically by the GUI timer to check for updates
 * and poll user events. Use vga_hw_update().
 */
static void
android_display_producer_check(void *opaque)
{
    /* core: call vga_hw_update(). this will eventually
     * lead to calls to android_display_update()
     */
    (void)opaque;
    vga_hw_update();
}

static void
android_display_producer_invalidate(void *opaque)
{
    (void)opaque;
    vga_hw_invalidate();
}

/* QFrameBuffer client callbacks */

/* this is called from dpy_update() each time a hardware framebuffer
 * rectangular update was detected. Send this to the QFrameBuffer.
 */
static void
android_display_update(DisplayState *ds, int x, int y, int w, int h)
{
    QFrameBuffer* qfbuff = ds->opaque;
    qframebuffer_update(qfbuff, x, y, w, h);
}

static void
android_display_resize(DisplayState *ds)
{
    QFrameBuffer* qfbuff = ds->opaque;
    qframebuffer_rotate(qfbuff, 0);
}

static void
android_display_refresh(DisplayState *ds)
{
    QFrameBuffer* qfbuff = ds->opaque;
    qframebuffer_poll(qfbuff);
}


void android_display_init(DisplayState* ds, QFrameBuffer* qf)
{
    DisplayChangeListener* dcl;

    qframebuffer_set_producer(qf, ds,
                              android_display_producer_check,
                              android_display_producer_invalidate,
                              NULL); // detach

    /* Replace the display surface with one with the right dimensions */
    qemu_free_displaysurface(ds);
    ds->opaque    = qf;
    ds->surface   = qemu_create_displaysurface_from(qf->width,
                                                    qf->height,
                                                    qf->bits_per_pixel,
                                                    qf->pitch,
                                                    qf->pixels);

    /* Register a change listener for it */
    ANEW0(dcl);
    dcl->dpy_update      = android_display_update;
    dcl->dpy_resize      = android_display_resize;
    dcl->dpy_refresh     = android_display_refresh;
    dcl->dpy_text_cursor = NULL;

    register_displaychangelistener(ds, dcl);
}