| 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 | #ifndef KHRN_CLIENT_PLATFORM_H |
| 28 | #define KHRN_CLIENT_PLATFORM_H |
| 29 | |
| 30 | #include "interface/khronos/include/EGL/egl.h" |
| 31 | #include "interface/khronos/include/EGL/eglext.h" |
| 32 | #include "interface/khronos/common/khrn_int_common.h" |
| 33 | #include "interface/khronos/common/khrn_int_image.h" |
| 34 | #include "interface/khronos/egl/egl_int.h" |
| 35 | #include <stdlib.h> // for size_t |
| 36 | |
| 37 | /* Per-platform types are defined in here. Most platforms can be supported |
| 38 | * via vcos, but 'direct' has its own header and types, which is why |
| 39 | * the indirection is required. |
| 40 | */ |
| 41 | #if defined(ABSTRACT_PLATFORM) |
| 42 | #include "interface/khronos/common/abstract/khrn_client_platform_filler_abstract.h" |
| 43 | #elif defined(RPC_DIRECT) && !defined(RPC_LIBRARY) && !defined(RPC_DIRECT_MULTI) |
| 44 | #include "interface/khronos/common/direct/khrn_client_platform_filler_direct.h" |
| 45 | #elif defined(KHRN_VCOS_VCHIQ) |
| 46 | #include "interface/khronos/common/vcos_vchiq/khrn_client_platform_filler_vcos_vchiq.h" |
| 47 | #else |
| 48 | #include "interface/khronos/common/vcos/khrn_client_platform_filler_vcos.h" |
| 49 | #endif |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | /* |
| 55 | named counting semaphore |
| 56 | */ |
| 57 | |
| 58 | /* Uses forward declared ref to avoid problems with mixing direct and vcos-based |
| 59 | * semaphores. |
| 60 | */ |
| 61 | |
| 62 | |
| 63 | /* |
| 64 | workaround for broken platforms which don't detect threads exiting |
| 65 | */ |
| 66 | extern void platform_hint_thread_finished(void); |
| 67 | |
| 68 | /* |
| 69 | heap |
| 70 | */ |
| 71 | |
| 72 | /* |
| 73 | void *khrn_platform_malloc(size_t size, const char *desc) |
| 74 | |
| 75 | Preconditions: |
| 76 | |
| 77 | desc is a literal, null-terminated string |
| 78 | The caller of this function is contracted to later call khrn_platform_free |
| 79 | (or pass such responsibility on) if we don't return NULL |
| 80 | |
| 81 | Postconditions: |
| 82 | |
| 83 | Return value is NULL or a memory allocation of at least size bytes, |
| 84 | valid until khrn_platform_free is called. The memory is sufficiently |
| 85 | aligned that it can be used for normal data structures. |
| 86 | */ |
| 87 | |
| 88 | extern void *khrn_platform_malloc(size_t size, const char *desc); |
| 89 | |
| 90 | /* |
| 91 | void khrn_platform_free(void *v) |
| 92 | |
| 93 | Preconditions: |
| 94 | |
| 95 | v is a valid pointer returned from khrn_platform_malloc |
| 96 | |
| 97 | Postconditions: |
| 98 | |
| 99 | v is freed |
| 100 | |
| 101 | Invariants preserved: |
| 102 | |
| 103 | - |
| 104 | |
| 105 | Invariants used: |
| 106 | |
| 107 | - |
| 108 | */ |
| 109 | extern void khrn_platform_free(void *v); |
| 110 | |
| 111 | extern void khrn_platform_maybe_free_process(void); |
| 112 | |
| 113 | /* |
| 114 | uint64_t khronos_platform_get_process_id() |
| 115 | |
| 116 | get process id |
| 117 | |
| 118 | Preconditions: |
| 119 | |
| 120 | - |
| 121 | |
| 122 | Postconditions: |
| 123 | |
| 124 | Repeated calls within a process return the same value. Calls from a different process |
| 125 | return a different value. |
| 126 | */ |
| 127 | |
| 128 | extern uint64_t khronos_platform_get_process_id(void); |
| 129 | |
| 130 | /* |
| 131 | window system |
| 132 | */ |
| 133 | |
| 134 | #define PLATFORM_WIN_NONE ((uint32_t)0xffffffff) |
| 135 | |
| 136 | #ifdef EGL_SERVER_SMALLINT |
| 137 | |
| 138 | static INLINE EGLNativeWindowType platform_canonical_win(EGLNativeWindowType win) |
| 139 | { |
| 140 | switch ((uintptr_t)win) { |
| 141 | case (uintptr_t)NATIVE_WINDOW_800_480: return PACK_NATIVE_WINDOW(800, 480, 0, 1); |
| 142 | case (uintptr_t)NATIVE_WINDOW_640_480: return PACK_NATIVE_WINDOW(640, 480, 0, 1); |
| 143 | case (uintptr_t)NATIVE_WINDOW_320_240: return PACK_NATIVE_WINDOW(320, 240, 0, 1); |
| 144 | case (uintptr_t)NATIVE_WINDOW_240_320: return PACK_NATIVE_WINDOW(240, 320, 0, 1); |
| 145 | case (uintptr_t)NATIVE_WINDOW_64_64: return PACK_NATIVE_WINDOW(64, 64, 0, 1); |
| 146 | case (uintptr_t)NATIVE_WINDOW_400_480_A: return PACK_NATIVE_WINDOW(400, 480, 0, 2); |
| 147 | case (uintptr_t)NATIVE_WINDOW_400_480_B: return PACK_NATIVE_WINDOW(400, 480, 1, 2); |
| 148 | case (uintptr_t)NATIVE_WINDOW_512_512: return PACK_NATIVE_WINDOW(512, 512, 0, 1); |
| 149 | case (uintptr_t)NATIVE_WINDOW_360_640: return PACK_NATIVE_WINDOW(360, 640, 0, 1); |
| 150 | case (uintptr_t)NATIVE_WINDOW_640_360: return PACK_NATIVE_WINDOW(640, 360, 0, 1); |
| 151 | case (uintptr_t)NATIVE_WINDOW_1280_720: return PACK_NATIVE_WINDOW(1280, 720, 0, 1); |
| 152 | case (uintptr_t)NATIVE_WINDOW_1920_1080: return PACK_NATIVE_WINDOW(1920, 1080, 0, 1); |
| 153 | case (uintptr_t)NATIVE_WINDOW_480_320: return PACK_NATIVE_WINDOW(480, 320, 0, 1); |
| 154 | case (uintptr_t)NATIVE_WINDOW_1680_1050: return PACK_NATIVE_WINDOW(1680, 1050, 0, 1); |
| 155 | default: return win; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | static INLINE uint32_t platform_get_handle(EGLDisplay dpy, EGLNativeWindowType win) |
| 160 | { |
| 161 | #ifdef ABSTRACT_PLATFORM |
| 162 | return (uint32_t)win; |
| 163 | #else |
| 164 | return (uint32_t)(size_t)platform_canonical_win(win); |
| 165 | #endif /* ABSTRACT_PLATFORM */ |
| 166 | } |
| 167 | |
| 168 | #ifndef ABSTRACT_PLATFORM |
| 169 | static INLINE void platform_get_dimensions(EGLDisplay dpy, |
| 170 | EGLNativeWindowType win, uint32_t *width, uint32_t *height, uint32_t *swapchain_count) |
| 171 | { |
| 172 | win = platform_canonical_win(win); |
| 173 | *width = UNPACK_NATIVE_WINDOW_W(win); |
| 174 | *height = UNPACK_NATIVE_WINDOW_H(win); |
| 175 | #ifdef KHRN_SIMPLE_MULTISAMPLE |
| 176 | *width *= 2; |
| 177 | *height *= 2; |
| 178 | #endif |
| 179 | *swapchain_count = 0; |
| 180 | } |
| 181 | #else |
| 182 | void platform_get_dimensions(EGLDisplay dpy, |
| 183 | EGLNativeWindowType win, uint32_t *width, uint32_t *height, uint32_t *swapchain_count); |
| 184 | void platform_lock(void * opaque_buffer_handle); |
| 185 | void platform_unlock(void * opaque_buffer_handle); |
| 186 | #endif /* ABSTRACT_PLATFORM */ |
| 187 | #else |
| 188 | |
| 189 | /* |
| 190 | uint32_t platform_get_handle(EGLNativeWindowType win) |
| 191 | |
| 192 | Implementation notes: |
| 193 | |
| 194 | Platform-specific implementation. |
| 195 | |
| 196 | Preconditions: |
| 197 | |
| 198 | - |
| 199 | |
| 200 | Postconditions: |
| 201 | |
| 202 | If win is a valid client-side handle to window W |
| 203 | Then return value is a server-side handle to window W. |
| 204 | Else return value is PLATFORM_WIN_NONE |
| 205 | */ |
| 206 | extern uint32_t platform_get_handle(EGLDisplay dpy, EGLNativeWindowType win); |
| 207 | |
| 208 | /* |
| 209 | void platform_get_dimensions(EGLNativeWindowType win, uint32_t *width, uint32_t *height, uint32_t *swapchain_count) |
| 210 | |
| 211 | Implementation notes: |
| 212 | |
| 213 | Platform-specific implementation. |
| 214 | |
| 215 | Preconditions: |
| 216 | |
| 217 | win is a valid client-side window handle |
| 218 | width, height are valid pointers |
| 219 | |
| 220 | Postconditions: |
| 221 | |
| 222 | - |
| 223 | */ |
| 224 | extern void platform_get_dimensions(EGLDisplay dpy, EGLNativeWindowType win, |
| 225 | uint32_t *width, uint32_t *height, uint32_t *swapchain_count); |
| 226 | #endif |
| 227 | extern void platform_surface_update(uint32_t handle); |
| 228 | |
| 229 | /* |
| 230 | bool platform_get_pixmap_info(EGLNativePixmapType pixmap, KHRN_IMAGE_WRAP_T *image); |
| 231 | |
| 232 | Preconditions: |
| 233 | |
| 234 | image is a valid pointer |
| 235 | |
| 236 | Postconditions: |
| 237 | |
| 238 | Either: |
| 239 | - false is returned because pixmap is an invalid pixmap handle, or |
| 240 | - true is returned and image is set up to describe the pixmap, and if it's a |
| 241 | client-side pixmap the pointer is also set |
| 242 | */ |
| 243 | |
| 244 | extern bool platform_get_pixmap_info(EGLNativePixmapType pixmap, KHRN_IMAGE_WRAP_T *image); |
| 245 | /* |
| 246 | should look something like this: |
| 247 | |
| 248 | if (regular server-side pixmap) { |
| 249 | handle[0] = handle; |
| 250 | } else if (global image server-side pixmap) { |
| 251 | handle[0] = id[0]; |
| 252 | handle[1] = id[1]; |
| 253 | } |
| 254 | */ |
| 255 | extern void platform_get_pixmap_server_handle(EGLNativePixmapType pixmap, uint32_t *handle); |
| 256 | |
| 257 | extern void platform_wait_EGL(uint32_t handle); |
| 258 | extern void platform_retrieve_pixmap_completed(EGLNativePixmapType pixmap); |
| 259 | extern void platform_send_pixmap_completed(EGLNativePixmapType pixmap); |
| 260 | |
| 261 | /* |
| 262 | bool platform_match_pixmap_api_support(EGLNativePixmapType pixmap, uint32_t api_support); |
| 263 | |
| 264 | Preconditions: |
| 265 | |
| 266 | pixmap is probably a valid native pixmap handle |
| 267 | api_support is a bitmap which is a subset of (EGL_OPENGL_ES_BIT | EGL_OPENVG_BIT | EGL_OPENGL_ES2_BIT) |
| 268 | |
| 269 | Postconditions: |
| 270 | |
| 271 | If result is true then rendering to this pixmap using these APIs is supported on this platform |
| 272 | */ |
| 273 | |
| 274 | extern bool platform_match_pixmap_api_support(EGLNativePixmapType pixmap, uint32_t api_support); |
| 275 | |
| 276 | #if EGL_BRCM_global_image && EGL_KHR_image |
| 277 | extern bool platform_use_global_image_as_egl_image(uint32_t id_0, uint32_t id_1, EGLNativePixmapType pixmap, EGLint *error); |
| 278 | extern void platform_acquire_global_image(uint32_t id_0, uint32_t id_1); |
| 279 | extern void platform_release_global_image(uint32_t id_0, uint32_t id_1); |
| 280 | extern void platform_get_global_image_info(uint32_t id_0, uint32_t id_1, |
| 281 | uint32_t *pixel_format, uint32_t *width, uint32_t *height); |
| 282 | #endif |
| 283 | |
| 284 | /* Platform optimised versions of memcpy and memcmp */ |
| 285 | extern uint32_t platform_memcmp(const void * aLeft, const void * aRight, size_t aLen); |
| 286 | extern void platform_memcpy(void * aTrg, const void * aSrc, size_t aLength); |
| 287 | |
| 288 | struct CLIENT_THREAD_STATE; |
| 289 | extern void platform_client_lock(void); |
| 290 | extern void platform_client_release(void); |
| 291 | extern void platform_init_rpc(struct CLIENT_THREAD_STATE *state); |
| 292 | extern void platform_term_rpc(struct CLIENT_THREAD_STATE *state); |
| 293 | extern void platform_maybe_free_process(void); |
| 294 | extern void platform_destroy_winhandle(void *a, uint32_t b); |
| 295 | |
| 296 | extern uint32_t platform_get_color_format ( uint32_t format ); |
| 297 | |
| 298 | #if !defined(__SYMBIAN32__) |
| 299 | // hack for now - we want prototypes |
| 300 | extern void egl_gce_win_change_image(void); |
| 301 | #endif |
| 302 | |
| 303 | #ifdef __cplusplus |
| 304 | } |
| 305 | #endif |
| 306 | |
| 307 | extern EGLDisplay khrn_platform_set_display_id(EGLNativeDisplayType display_id); |
| 308 | |
| 309 | extern uint32_t khrn_platform_get_window_position(EGLNativeWindowType win); |
| 310 | |
| 311 | extern void khrn_platform_release_pixmap_info(EGLNativePixmapType pixmap, KHRN_IMAGE_WRAP_T *image); |
| 312 | extern void khrn_platform_bind_pixmap_to_egl_image(EGLNativePixmapType pixmap, EGLImageKHR egl_image, bool send); |
| 313 | extern void khrn_platform_unbind_pixmap_from_egl_image(EGLImageKHR egl_image); |
| 314 | extern uint32_t platform_get_color_format ( uint32_t format ); |
| 315 | extern void platform_dequeue(EGLDisplay dpy, EGLNativeWindowType window); |
| 316 | #include "interface/khronos/include/WF/wfc.h" |
| 317 | typedef struct |
| 318 | { |
| 319 | WFCDevice device; |
| 320 | WFCContext context; |
| 321 | WFCSource source; |
| 322 | WFCint src_x, src_y, src_width, src_height; |
| 323 | WFCint dest_width, dest_height; |
| 324 | uint32_t stop_bouncing; |
| 325 | uint32_t num_of_elements; |
| 326 | WFCElement *element; |
| 327 | } WFC_BOUNCE_DATA_T; |
| 328 | |
| 329 | void *platform_wfc_bounce_thread(void *param); |
| 330 | |
| 331 | #endif // KHRN_CLIENT_PLATFORM_H |
| 332 | |