John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <EGL/egl.h> |
| 18 | #include <EGL/eglext.h> |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | static EGLDisplay gDisplay = (EGLDisplay) 1; |
| 25 | |
| 26 | typedef struct { |
| 27 | EGLSurface surface; |
| 28 | EGLContext context; |
| 29 | } ThreadState; |
| 30 | |
| 31 | static pthread_key_t ThreadStateKey; |
| 32 | static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT; |
| 33 | |
| 34 | static void destroyThreadState(void* state) { |
| 35 | free(state); |
| 36 | } |
| 37 | |
| 38 | static void makeThreadState() { |
| 39 | pthread_key_create(&ThreadStateKey, destroyThreadState); |
| 40 | } |
| 41 | |
| 42 | ThreadState* getThreadState() { |
| 43 | ThreadState* ptr; |
| 44 | pthread_once(&ThreadStateSetupOnce, makeThreadState); |
| 45 | if ((ptr = (ThreadState*) pthread_getspecific(ThreadStateKey)) == NULL) { |
| 46 | ptr = (ThreadState*) calloc(1, sizeof(ThreadState)); |
| 47 | ptr->context = EGL_NO_CONTEXT; |
| 48 | ptr->surface = EGL_NO_SURFACE; |
| 49 | pthread_setspecific(ThreadStateKey, ptr); |
| 50 | } |
| 51 | return ptr; |
| 52 | } |
| 53 | |
| 54 | EGLint eglGetError(void) { |
| 55 | return EGL_SUCCESS; |
| 56 | } |
| 57 | |
| 58 | EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) { |
| 59 | return gDisplay; |
| 60 | } |
| 61 | |
| 62 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { |
| 63 | return EGL_TRUE; |
| 64 | } |
| 65 | |
| 66 | EGLBoolean eglTerminate(EGLDisplay dpy) { |
| 67 | return EGL_TRUE; |
| 68 | } |
| 69 | |
| 70 | const char * eglQueryString(EGLDisplay dpy, EGLint name) { |
Chris Craik | 63cd1b4 | 2016-05-03 16:01:26 -0700 | [diff] [blame] | 71 | if (name == EGL_EXTENSIONS) { |
| 72 | return "EGL_KHR_swap_buffers_with_damage"; |
| 73 | } |
John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 74 | return ""; |
| 75 | } |
| 76 | |
| 77 | EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, |
| 78 | EGLConfig *configs, EGLint config_size, |
| 79 | EGLint *num_config) { |
| 80 | memset(configs, 9, sizeof(EGLConfig) * config_size); |
| 81 | *num_config = config_size; |
| 82 | return EGL_TRUE; |
| 83 | } |
| 84 | |
| 85 | EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, |
| 86 | EGLNativeWindowType win, |
| 87 | const EGLint *attrib_list) { |
| 88 | return (EGLSurface) malloc(sizeof(void*)); |
| 89 | } |
| 90 | |
| 91 | EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, |
| 92 | const EGLint *attrib_list) { |
| 93 | return (EGLSurface) malloc(sizeof(void*)); |
| 94 | } |
| 95 | |
| 96 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { |
| 97 | free(surface); |
| 98 | return EGL_TRUE; |
| 99 | } |
| 100 | |
| 101 | EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, |
| 102 | EGLint attribute, EGLint *value) { |
| 103 | *value = 1000; |
| 104 | return EGL_TRUE; |
| 105 | } |
| 106 | |
| 107 | EGLBoolean eglReleaseThread(void) { |
| 108 | return EGL_TRUE; |
| 109 | } |
| 110 | |
| 111 | EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, |
| 112 | EGLint attribute, EGLint value) { |
| 113 | return EGL_TRUE; |
| 114 | } |
| 115 | |
| 116 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) { |
| 117 | return EGL_TRUE; |
| 118 | } |
| 119 | |
| 120 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, |
| 121 | EGLContext share_context, |
| 122 | const EGLint *attrib_list) { |
| 123 | return (EGLContext) malloc(sizeof(void*)); |
| 124 | } |
| 125 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { |
| 126 | free(ctx); |
| 127 | return EGL_TRUE; |
| 128 | } |
| 129 | |
| 130 | EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, |
| 131 | EGLSurface read, EGLContext ctx) { |
| 132 | ThreadState* state = getThreadState(); |
| 133 | state->surface = draw; |
| 134 | state->context = ctx; |
| 135 | return EGL_TRUE; |
| 136 | } |
| 137 | |
| 138 | EGLContext eglGetCurrentContext(void) { |
| 139 | return getThreadState()->context; |
| 140 | } |
| 141 | |
| 142 | EGLSurface eglGetCurrentSurface(EGLint readdraw) { |
| 143 | return getThreadState()->surface; |
| 144 | } |
| 145 | |
| 146 | EGLDisplay eglGetCurrentDisplay(void) { |
| 147 | return gDisplay; |
| 148 | } |
| 149 | |
| 150 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { |
| 151 | return EGL_TRUE; |
| 152 | } |
| 153 | |
Chris Craik | 63cd1b4 | 2016-05-03 16:01:26 -0700 | [diff] [blame] | 154 | EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint rectCount) { |
| 155 | return EGL_TRUE; |
| 156 | } |
| 157 | |
John Reck | 041b985 | 2015-02-25 14:32:41 -0800 | [diff] [blame] | 158 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) { |
| 159 | return (EGLImageKHR) malloc(sizeof(EGLImageKHR)); |
| 160 | } |
| 161 | |
| 162 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) { |
| 163 | free(image); |
| 164 | return EGL_TRUE; |
| 165 | } |
| 166 | |
| 167 | void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {} |