gbm: factor out gbm_window_{init,teardown}
[mesa-waffle.git] / src / waffle / android / droid_platform.c
blobeb1407f4babb78cc382e18370b58ff10623539ad
1 // Copyright 2012 Intel Corporation
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // - Redistributions of source code must retain the above copyright notice, this
9 // list of conditions and the following disclaimer.
11 // - Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <dlfcn.h>
27 #include <stdlib.h>
29 #include "wcore_error.h"
31 #include "linux_platform.h"
33 #include "wegl_config.h"
34 #include "wegl_context.h"
35 #include "wegl_util.h"
37 #include "droid_display.h"
38 #include "droid_platform.h"
39 #include "droid_window.h"
41 static const struct wcore_platform_vtbl droid_platform_vtbl;
43 static bool
44 droid_platform_destroy(struct wcore_platform *wc_self)
46 struct droid_platform *self = droid_platform(wc_self);
47 bool ok = true;
49 if (!self)
50 return true;
52 if (self->linux)
53 ok &= linux_platform_destroy(self->linux);
55 ok &= wcore_platform_teardown(wc_self);
56 free(self);
57 return ok;
60 struct wcore_platform*
61 droid_platform_create(void)
63 struct droid_platform *self;
64 bool ok = true;
66 self = wcore_calloc(sizeof(*self));
67 if (self == NULL)
68 return NULL;
70 ok = wcore_platform_init(&self->wcore);
71 if (!ok)
72 goto error;
74 self->linux = linux_platform_create();
75 if (!self->linux)
76 goto error;
78 self->wcore.vtbl = &droid_platform_vtbl;
79 return &self->wcore;
81 error:
82 droid_platform_destroy(&self->wcore);
83 return NULL;
86 static bool
87 droid_dl_can_open(
88 struct wcore_platform *wc_self,
89 int32_t waffle_dl)
91 return linux_platform_dl_can_open(droid_platform(wc_self)->linux,
92 waffle_dl);
95 static void*
96 droid_dl_sym(
97 struct wcore_platform *wc_self,
98 int32_t waffle_dl,
99 const char *name)
101 return linux_platform_dl_sym(droid_platform(wc_self)->linux,
102 waffle_dl, name);
105 static const struct wcore_platform_vtbl droid_platform_vtbl = {
106 .destroy = droid_platform_destroy,
108 .make_current = wegl_make_current,
109 .get_proc_address = wegl_get_proc_address,
110 .dl_can_open = droid_dl_can_open,
111 .dl_sym = droid_dl_sym,
113 .display = {
114 .connect = droid_display_connect,
115 .destroy = droid_display_disconnect,
116 .supports_context_api = wegl_display_supports_context_api,
117 .get_native = NULL,
120 .config = {
121 .choose = wegl_config_choose,
122 .destroy = wegl_config_destroy,
123 .get_native = NULL,
126 .context = {
127 .create = wegl_context_create,
128 .destroy = wegl_context_destroy,
129 .get_native = NULL,
132 .window = {
133 .create = droid_window_create,
134 .destroy = droid_window_destroy,
135 .show = droid_window_show,
136 .swap_buffers = wegl_surface_swap_buffers,
137 .resize = droid_window_resize,
138 .get_native = NULL,