• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static EGLSyncKHR gFence = (EGLSyncKHR) 1;
26 
27 typedef struct {
28     EGLSurface surface;
29     EGLContext context;
30 } ThreadState;
31 
32 static pthread_key_t ThreadStateKey;
33 static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT;
34 
destroyThreadState(void * state)35 static void destroyThreadState(void* state) {
36     free(state);
37 }
38 
makeThreadState()39 static void makeThreadState() {
40     pthread_key_create(&ThreadStateKey, destroyThreadState);
41 }
42 
getThreadState()43 ThreadState* getThreadState() {
44     ThreadState* ptr;
45     pthread_once(&ThreadStateSetupOnce, makeThreadState);
46     if ((ptr = (ThreadState*) pthread_getspecific(ThreadStateKey)) == NULL) {
47         ptr = (ThreadState*) calloc(1, sizeof(ThreadState));
48         ptr->context = EGL_NO_CONTEXT;
49         ptr->surface = EGL_NO_SURFACE;
50         pthread_setspecific(ThreadStateKey, ptr);
51     }
52     return ptr;
53 }
54 
eglGetError(void)55 EGLint eglGetError(void) {
56     return EGL_SUCCESS;
57 }
58 
eglGetDisplay(EGLNativeDisplayType display_id)59 EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) {
60     return gDisplay;
61 }
62 
eglInitialize(EGLDisplay dpy,EGLint * major,EGLint * minor)63 EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) {
64     return EGL_TRUE;
65 }
66 
eglTerminate(EGLDisplay dpy)67 EGLBoolean eglTerminate(EGLDisplay dpy) {
68     return EGL_TRUE;
69 }
70 
eglQueryString(EGLDisplay dpy,EGLint name)71 const char * eglQueryString(EGLDisplay dpy, EGLint name) {
72     if (name == EGL_EXTENSIONS) {
73         return "EGL_KHR_swap_buffers_with_damage";
74     }
75     return "";
76 }
77 
eglChooseConfig(EGLDisplay dpy,const EGLint * attrib_list,EGLConfig * configs,EGLint config_size,EGLint * num_config)78 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
79                EGLConfig *configs, EGLint config_size,
80                EGLint *num_config) {
81     memset(configs, 9, sizeof(EGLConfig) * config_size);
82     *num_config = config_size;
83     return EGL_TRUE;
84 }
85 
eglCreateWindowSurface(EGLDisplay dpy,EGLConfig config,EGLNativeWindowType win,const EGLint * attrib_list)86 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
87                   EGLNativeWindowType win,
88                   const EGLint *attrib_list) {
89     return (EGLSurface) malloc(sizeof(void*));
90 }
91 
eglCreatePbufferSurface(EGLDisplay dpy,EGLConfig config,const EGLint * attrib_list)92 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
93                    const EGLint *attrib_list) {
94     return (EGLSurface) malloc(sizeof(void*));
95 }
96 
eglDestroySurface(EGLDisplay dpy,EGLSurface surface)97 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
98     free(surface);
99     return EGL_TRUE;
100 }
101 
eglQuerySurface(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint * value)102 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
103                EGLint attribute, EGLint *value) {
104     *value = 1000;
105     return EGL_TRUE;
106 }
107 
eglReleaseThread(void)108 EGLBoolean eglReleaseThread(void) {
109     return EGL_TRUE;
110 }
111 
eglSurfaceAttrib(EGLDisplay dpy,EGLSurface surface,EGLint attribute,EGLint value)112 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
113                 EGLint attribute, EGLint value) {
114     return EGL_TRUE;
115 }
116 
eglSwapInterval(EGLDisplay dpy,EGLint interval)117 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
118     return EGL_TRUE;
119 }
120 
eglCreateContext(EGLDisplay dpy,EGLConfig config,EGLContext share_context,const EGLint * attrib_list)121 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
122                 EGLContext share_context,
123                 const EGLint *attrib_list) {
124     return (EGLContext) malloc(sizeof(void*));
125 }
eglDestroyContext(EGLDisplay dpy,EGLContext ctx)126 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
127     free(ctx);
128     return EGL_TRUE;
129 }
130 
eglMakeCurrent(EGLDisplay dpy,EGLSurface draw,EGLSurface read,EGLContext ctx)131 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
132               EGLSurface read, EGLContext ctx) {
133     ThreadState* state = getThreadState();
134     state->surface = draw;
135     state->context = ctx;
136     return EGL_TRUE;
137 }
138 
eglGetCurrentContext(void)139 EGLContext eglGetCurrentContext(void) {
140     return getThreadState()->context;
141 }
142 
eglGetCurrentSurface(EGLint readdraw)143 EGLSurface eglGetCurrentSurface(EGLint readdraw) {
144     return getThreadState()->surface;
145 }
146 
eglGetCurrentDisplay(void)147 EGLDisplay eglGetCurrentDisplay(void) {
148     return gDisplay;
149 }
150 
eglSwapBuffers(EGLDisplay dpy,EGLSurface surface)151 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
152     return EGL_TRUE;
153 }
154 
eglSwapBuffersWithDamageKHR(EGLDisplay dpy,EGLSurface surface,EGLint * rects,EGLint rectCount)155 EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint rectCount) {
156     return EGL_TRUE;
157 }
158 
eglCreateImageKHR(EGLDisplay dpy,EGLContext ctx,EGLenum target,EGLClientBuffer buffer,const EGLint * attrib_list)159 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) {
160     return (EGLImageKHR) malloc(sizeof(EGLImageKHR));
161 }
162 
eglCreateSyncKHR(EGLDisplay dpy,EGLenum type,const EGLint * attrib_list)163 EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_list) {
164     return gFence;
165 }
166 
eglDestroySyncKHR(EGLDisplay dpy,EGLSyncKHR sync)167 EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) {
168     return EGL_TRUE;
169 }
170 
eglClientWaitSyncKHR(EGLDisplay dpy,EGLSyncKHR sync,EGLint flags,EGLTimeKHR timeout)171 EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) {
172     return EGL_CONDITION_SATISFIED_KHR;
173 }
174 
eglDestroyImageKHR(EGLDisplay dpy,EGLImageKHR image)175 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
176     free(image);
177     return EGL_TRUE;
178 }
179 
eglBeginFrame(EGLDisplay dpy,EGLSurface surface)180 void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {}
181