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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
/*
* Mesa 3-D graphics library
* Version: 7.12
*
* Copyright (C) 2011 LunarG Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
/**
* For NULL window system,
*
* - the only valid native display is EGL_DEFAULT_DISPLAY
* - there is no window or pixmap
*/
#include "util/u_memory.h"
#include "null/null_sw_winsys.h"
#include "common/native.h"
struct null_display {
struct native_display base;
const struct native_event_handler *event_handler;
struct native_config *configs;
int num_configs;
};
static INLINE struct null_display *
null_display(const struct native_display *ndpy)
{
return (struct null_display *) ndpy;
}
static const struct native_config **
null_display_get_configs(struct native_display *ndpy, int *num_configs)
{
struct null_display *null = null_display(ndpy);
const struct native_config **configs;
int i;
configs = MALLOC(sizeof(*configs) * null->num_configs);
if (configs) {
for (i = 0; i < null->num_configs; i++)
configs[i] = &null->configs[i];
if (num_configs)
*num_configs = null->num_configs;
}
return configs;
}
static int
null_display_get_param(struct native_display *ndpy,
enum native_param_type param)
{
return 0;
}
static void
null_display_destroy(struct native_display *ndpy)
{
struct null_display *null = null_display(ndpy);
FREE(null->configs);
ndpy_uninit(&null->base);
FREE(null);
}
static boolean
null_display_init_config(struct native_display *ndpy)
{
const enum pipe_format color_formats[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_B8G8R8X8_UNORM,
PIPE_FORMAT_B5G6R5_UNORM,
PIPE_FORMAT_NONE
};
struct null_display *null = null_display(ndpy);
int i;
null->configs = CALLOC(Elements(color_formats) - 1, sizeof(*null->configs));
if (!null->configs)
return FALSE;
/* add configs */
for (i = 0; color_formats[i] != PIPE_FORMAT_NONE; i++) {
if (null->base.screen->is_format_supported(null->base.screen,
color_formats[i], PIPE_TEXTURE_2D, 0,
PIPE_BIND_RENDER_TARGET)) {
struct native_config *nconf = &null->configs[null->num_configs];
nconf->color_format = color_formats[i];
nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_BACK_LEFT;
null->num_configs++;
}
}
return TRUE;
}
static boolean
null_display_init_screen(struct native_display *ndpy)
{
struct null_display *null = null_display(ndpy);
struct sw_winsys *ws;
ws = null_sw_create();
if (!ws)
return FALSE;
null->base.screen = null->event_handler->new_sw_screen(&null->base, ws);
if (!null->base.screen) {
if (ws->destroy)
ws->destroy(ws);
return FALSE;
}
if (!null_display_init_config(&null->base)) {
ndpy_uninit(&null->base);
return FALSE;
}
return TRUE;
}
static struct native_display *
null_display_create(const struct native_event_handler *event_handler)
{
struct null_display *null;
null = CALLOC_STRUCT(null_display);
if (!null)
return NULL;
null->event_handler = event_handler;
null->base.init_screen = null_display_init_screen;
null->base.destroy = null_display_destroy;
null->base.get_param = null_display_get_param;
null->base.get_configs = null_display_get_configs;
return &null->base;
}
static const struct native_event_handler *null_event_handler;
static struct native_display *
native_create_display(void *dpy, boolean use_sw)
{
struct native_display *ndpy = NULL;
/* the only valid display is NULL */
if (!dpy)
ndpy = null_display_create(null_event_handler);
return ndpy;
}
static const struct native_platform null_platform = {
"NULL", /* name */
native_create_display
};
const struct native_platform *
native_get_null_platform(const struct native_event_handler *event_handler)
{
null_event_handler = event_handler;
return &null_platform;
}
|