Subversion Repositories Kolibri OS

Rev

Rev 3807 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3770 Serge 1
/**************************************************************************
2
 *
3
 * Copyright 2010 VMware, Inc.
4
 * All Rights Reserved.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the
8
 * "Software"), to deal in the Software without restriction, including
9
 * without limitation the rights to use, copy, modify, merge, publish,
10
 * distribute, sub license, and/or sell copies of the Software, and to
11
 * permit persons to whom the Software is furnished to do so, subject to
12
 * the following conditions:
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17
 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
21
 *
22
 * The above copyright notice and this permission notice (including the
23
 * next paragraph) shall be included in all copies or substantial portions
24
 * of the Software.
25
 *
26
 *
27
 **************************************************************************/
28
 
29
#include "sw/kos_sw_winsys.h"
30
#include "pipe/p_screen.h"
31
#include "state_tracker/graw.h"
32
#include "target-helpers/inline_debug_helper.h"
33
#include "target-helpers/inline_sw_helper.h"
34
#include 
35
 
36
static struct {
37
   void (* draw)(void);
38
} graw;
39
 
40
struct pipe_screen *
41
graw_create_window_and_screen(int x,
42
                              int y,
43
                              unsigned width,
44
                              unsigned height,
45
                              enum pipe_format format,
46
                              void **handle)
47
{
3847 Serge 48
    struct sw_winsys *winsys = NULL;
49
    struct pipe_screen *screen = NULL;
50
    struct pipe_loader_device *dev;
51
	int ret;
3770 Serge 52
 
3847 Serge 53
    if (format != PIPE_FORMAT_B8G8R8X8_UNORM)
54
        goto fail;
3770 Serge 55
 
3847 Serge 56
    winsys = kos_create_sw_winsys();
57
    if (winsys == NULL)
58
        goto fail;
3770 Serge 59
 
3847 Serge 60
	/* find a hardware device */
61
	ret = pipe_loader_probe(&dev, 1);
62
 
63
	/* init a pipe screen */
64
	screen = pipe_loader_create_screen(dev, "drivers");
3773 Serge 65
 
3847 Serge 66
    if (screen == NULL)
67
        goto fail;
3773 Serge 68
 
69
    BeginDraw();
70
    DrawWindow(x, y,width-1,height-1,
71
               NULL,0,0x41);
72
    EndDraw();
73
 
74
    *handle = (void *)winsys;
3770 Serge 75
    return (screen);
76
 
77
fail:
78
 
79
   if (screen)
80
      screen->destroy(screen);
81
 
82
   return NULL;
83
}
84
 
85
void
86
graw_set_display_func(void (* draw)(void))
87
{
88
   graw.draw = draw;
89
}
90
 
91
void
92
graw_main_loop(void)
93
{
3773 Serge 94
    int ev;
95
    oskey_t   key;
96
 
97
    BeginDraw();
98
    DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
99
    EndDraw();
100
 
101
    if (graw.draw)
102
    {
103
       graw.draw();
104
    }
105
 
106
    while(1)
107
    {
3807 Serge 108
        ev = wait_for_event(2);
3773 Serge 109
 
110
        switch(ev)
111
        {
112
            case 1:
113
                BeginDraw();
114
                DrawWindow(0,0,0,0, NULL, 0x000000,0x41);
115
                EndDraw();
116
 
117
                if (graw.draw)
118
                {
119
                    graw.draw();
120
                }
121
                continue;
122
 
123
            case 2:
124
                key = get_key();
125
//                printf("key %x\n", key.code);
126
                if( key.code == 0x1b)
127
                    return;
128
                continue;
129
        };
3807 Serge 130
        if (graw.draw)
131
        {
132
            graw.draw();
133
        }
134
 
3773 Serge 135
    };
3770 Serge 136
}