2
* Mesa 3-D graphics library
5
* Copyright (C) 2011 LunarG Inc.
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
14
* The above copyright notice and this permission notice shall be included
15
* in all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
* DEALINGS IN THE SOFTWARE.
26
* Chia-I Wu <olv@lunarg.com>
30
* For NULL window system,
32
* - the only valid native display is EGL_DEFAULT_DISPLAY
33
* - there is no window or pixmap
36
#include "util/u_memory.h"
37
#include "null/null_sw_winsys.h"
38
#include "common/native.h"
41
struct native_display base;
43
const struct native_event_handler *event_handler;
45
struct native_config *configs;
49
static INLINE struct null_display *
50
null_display(const struct native_display *ndpy)
52
return (struct null_display *) ndpy;
55
static const struct native_config **
56
null_display_get_configs(struct native_display *ndpy, int *num_configs)
58
struct null_display *null = null_display(ndpy);
59
const struct native_config **configs;
62
configs = MALLOC(sizeof(*configs) * null->num_configs);
64
for (i = 0; i < null->num_configs; i++)
65
configs[i] = &null->configs[i];
67
*num_configs = null->num_configs;
74
null_display_get_param(struct native_display *ndpy,
75
enum native_param_type param)
81
null_display_destroy(struct native_display *ndpy)
83
struct null_display *null = null_display(ndpy);
86
ndpy_uninit(&null->base);
91
null_display_init_config(struct native_display *ndpy)
93
const enum pipe_format color_formats[] = {
94
PIPE_FORMAT_B8G8R8A8_UNORM,
95
PIPE_FORMAT_B8G8R8X8_UNORM,
96
PIPE_FORMAT_B5G6R5_UNORM,
99
struct null_display *null = null_display(ndpy);
102
null->configs = CALLOC(Elements(color_formats) - 1, sizeof(*null->configs));
107
for (i = 0; color_formats[i] != PIPE_FORMAT_NONE; i++) {
108
if (null->base.screen->is_format_supported(null->base.screen,
109
color_formats[i], PIPE_TEXTURE_2D, 0,
110
PIPE_BIND_RENDER_TARGET)) {
111
struct native_config *nconf = &null->configs[null->num_configs];
113
nconf->color_format = color_formats[i];
114
nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_BACK_LEFT;
123
null_display_init_screen(struct native_display *ndpy)
125
struct null_display *null = null_display(ndpy);
126
struct sw_winsys *ws;
128
ws = null_sw_create();
132
null->base.screen = null->event_handler->new_sw_screen(&null->base, ws);
133
if (!null->base.screen) {
139
if (!null_display_init_config(&null->base)) {
140
ndpy_uninit(&null->base);
147
static struct native_display *
148
null_display_create(const struct native_event_handler *event_handler)
150
struct null_display *null;
152
null = CALLOC_STRUCT(null_display);
156
null->event_handler = event_handler;
158
null->base.init_screen = null_display_init_screen;
159
null->base.destroy = null_display_destroy;
160
null->base.get_param = null_display_get_param;
161
null->base.get_configs = null_display_get_configs;
166
static const struct native_event_handler *null_event_handler;
168
static struct native_display *
169
native_create_display(void *dpy, boolean use_sw)
171
struct native_display *ndpy = NULL;
173
/* the only valid display is NULL */
175
ndpy = null_display_create(null_event_handler);
180
static const struct native_platform null_platform = {
182
native_create_display
185
const struct native_platform *
186
native_get_null_platform(const struct native_event_handler *event_handler)
188
null_event_handler = event_handler;
189
return &null_platform;