1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
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 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | static void callback_destroy_context(KHRN_POINTER_MAP_T *map, uint32_t key, void *value, void *data) |
29 | { |
30 | EGL_CONTEXT_T *context = (EGL_CONTEXT_T *)value; |
31 | |
32 | UNUSED(map); |
33 | UNUSED(data); |
34 | UNUSED_NDEBUG(key); |
35 | |
36 | vcos_assert( context != NULL ); |
37 | vcos_assert((uintptr_t)key == (uintptr_t)context->name); |
38 | |
39 | vcos_assert(!context->is_destroyed); |
40 | |
41 | context->is_destroyed = true; |
42 | egl_context_maybe_free(context); |
43 | } |
44 | |
45 | /* |
46 | void callback_destroy_surface(KHRN_POINTER_MAP_T *map, uint32_t key, void *value, void *data) |
47 | |
48 | Implementation notes: |
49 | |
50 | Passed as a callback to khrn_pointer_map_iterate. |
51 | |
52 | Preconditions: |
53 | |
54 | Thread owns EGL lock |
55 | |
56 | map is the CLIENT_PROCESS_STATE_T.surfaces |
57 | value is a pointer to a valid EGL_SURFACE_T |
58 | key is a key in map |
59 | map[key] == value |
60 | |
61 | Postconditions: |
62 | |
63 | Does not alter map |
64 | value is a dead pointer (i.e. either a pointer to a freed thing or something we don't hold a reference to) |
65 | |
66 | Invariants preserved: |
67 | |
68 | (EGL_SURFACE_IS_DESTROYED) |
69 | |
70 | Invariants used: |
71 | |
72 | (CLIENT_PROCESS_STATE_SURFACES) |
73 | (EGL_SURFACE_BINDING_COUNT) |
74 | */ |
75 | |
76 | static void callback_destroy_surface(KHRN_POINTER_MAP_T *map, uint32_t key, void *value, void *data) |
77 | { |
78 | EGL_SURFACE_T *surface = (EGL_SURFACE_T *)value; |
79 | |
80 | UNUSED(map); |
81 | UNUSED(data); |
82 | UNUSED_NDEBUG(key); |
83 | |
84 | vcos_assert( surface != NULL ); |
85 | vcos_assert((uintptr_t)key == (uintptr_t)surface->name); |
86 | |
87 | surface->is_destroyed = true; |
88 | egl_surface_maybe_free(surface); |
89 | } |
90 | |
91 | /* |
92 | CLIENT_PROCESS_STATE_T *client_egl_get_process_state(CLIENT_THREAD_STATE_T *thread, EGLDisplay dpy, EGLBoolean check_inited) |
93 | |
94 | Returns the process-global CLIENT_PROCESS_STATE_T object. If check_inited is true, also insists that the process state |
95 | is inited. |
96 | |
97 | Implementation notes: |
98 | |
99 | - |
100 | |
101 | Preconditions: |
102 | |
103 | thread is a valid pointer |
104 | Thread owns EGL lock |
105 | |
106 | Postconditions: |
107 | |
108 | The following conditions cause error to assume the specified value |
109 | |
110 | EGL_BAD_DISPLAY An EGLDisplay argument does not name a valid EGLDisplay |
111 | EGL_NOT_INITIALIZED check_inited is true and EGL is not initialized for the specified display. |
112 | |
113 | if more than one condition holds, the first error is generated. |
114 | |
115 | If error, NULL is returned. Otherwise a pointer is returned which is valid for the lifetime of the process. |
116 | |
117 | Invariants preserved: |
118 | |
119 | - |
120 | |
121 | Invariants used: |
122 | |
123 | - |
124 | */ |
125 | |
126 | CLIENT_PROCESS_STATE_T *client_egl_get_process_state(CLIENT_THREAD_STATE_T *thread, EGLDisplay dpy, EGLBoolean check_inited) |
127 | { |
128 | if ((size_t)dpy == 1) { |
129 | CLIENT_PROCESS_STATE_T *process = CLIENT_GET_PROCESS_STATE(); |
130 | |
131 | if (check_inited && !process->inited) { |
132 | thread->error = EGL_NOT_INITIALIZED; |
133 | return NULL; |
134 | } else |
135 | return process; |
136 | } else { |
137 | thread->error = EGL_BAD_DISPLAY; |
138 | return NULL; |
139 | } |
140 | } |
141 | |