blob: ca47f8fd22ef7ef1aaf01ef3f7e87da893856bdd [file] [log] [blame]
John Reck041b9852015-02-25 14:32:41 -08001/*
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
John Reck1bcacfd2017-11-03 10:12:19 -070024static EGLDisplay gDisplay = (EGLDisplay)1;
25static EGLSyncKHR gFence = (EGLSyncKHR)1;
John Reck041b9852015-02-25 14:32:41 -080026
27typedef struct {
28 EGLSurface surface;
29 EGLContext context;
30} ThreadState;
31
32static pthread_key_t ThreadStateKey;
33static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT;
34
35static void destroyThreadState(void* state) {
36 free(state);
37}
38
39static void makeThreadState() {
40 pthread_key_create(&ThreadStateKey, destroyThreadState);
41}
42
43ThreadState* getThreadState() {
44 ThreadState* ptr;
45 pthread_once(&ThreadStateSetupOnce, makeThreadState);
John Reck1bcacfd2017-11-03 10:12:19 -070046 if ((ptr = (ThreadState*)pthread_getspecific(ThreadStateKey)) == NULL) {
47 ptr = (ThreadState*)calloc(1, sizeof(ThreadState));
John Reck041b9852015-02-25 14:32:41 -080048 ptr->context = EGL_NO_CONTEXT;
49 ptr->surface = EGL_NO_SURFACE;
50 pthread_setspecific(ThreadStateKey, ptr);
51 }
52 return ptr;
53}
54
55EGLint eglGetError(void) {
56 return EGL_SUCCESS;
57}
58
59EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) {
60 return gDisplay;
61}
62
John Reck1bcacfd2017-11-03 10:12:19 -070063EGLBoolean eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
John Reck041b9852015-02-25 14:32:41 -080064 return EGL_TRUE;
65}
66
67EGLBoolean eglTerminate(EGLDisplay dpy) {
68 return EGL_TRUE;
69}
70
John Reck1bcacfd2017-11-03 10:12:19 -070071const char* eglQueryString(EGLDisplay dpy, EGLint name) {
Chris Craik63cd1b42016-05-03 16:01:26 -070072 if (name == EGL_EXTENSIONS) {
73 return "EGL_KHR_swap_buffers_with_damage";
74 }
John Reck041b9852015-02-25 14:32:41 -080075 return "";
76}
77
John Reck1bcacfd2017-11-03 10:12:19 -070078EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs,
79 EGLint config_size, EGLint* num_config) {
John Reck041b9852015-02-25 14:32:41 -080080 memset(configs, 9, sizeof(EGLConfig) * config_size);
81 *num_config = config_size;
82 return EGL_TRUE;
83}
84
John Reck1bcacfd2017-11-03 10:12:19 -070085EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win,
86 const EGLint* attrib_list) {
87 return (EGLSurface)malloc(sizeof(void*));
John Reck041b9852015-02-25 14:32:41 -080088}
89
John Reck1bcacfd2017-11-03 10:12:19 -070090EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list) {
91 return (EGLSurface)malloc(sizeof(void*));
John Reck041b9852015-02-25 14:32:41 -080092}
93
94EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
95 free(surface);
96 return EGL_TRUE;
97}
98
John Reck1bcacfd2017-11-03 10:12:19 -070099EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value) {
John Reck041b9852015-02-25 14:32:41 -0800100 *value = 1000;
101 return EGL_TRUE;
102}
103
104EGLBoolean eglReleaseThread(void) {
105 return EGL_TRUE;
106}
107
John Reck1bcacfd2017-11-03 10:12:19 -0700108EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) {
John Reck041b9852015-02-25 14:32:41 -0800109 return EGL_TRUE;
110}
111
112EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
113 return EGL_TRUE;
114}
115
John Reck1bcacfd2017-11-03 10:12:19 -0700116EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context,
117 const EGLint* attrib_list) {
118 return (EGLContext)malloc(sizeof(void*));
John Reck041b9852015-02-25 14:32:41 -0800119}
120EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
121 free(ctx);
122 return EGL_TRUE;
123}
124
John Reck1bcacfd2017-11-03 10:12:19 -0700125EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
John Reck041b9852015-02-25 14:32:41 -0800126 ThreadState* state = getThreadState();
127 state->surface = draw;
128 state->context = ctx;
129 return EGL_TRUE;
130}
131
132EGLContext eglGetCurrentContext(void) {
133 return getThreadState()->context;
134}
135
136EGLSurface eglGetCurrentSurface(EGLint readdraw) {
137 return getThreadState()->surface;
138}
139
140EGLDisplay eglGetCurrentDisplay(void) {
141 return gDisplay;
142}
143
144EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
145 return EGL_TRUE;
146}
147
John Reck1bcacfd2017-11-03 10:12:19 -0700148EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, EGLint* rects,
149 EGLint rectCount) {
Chris Craik63cd1b42016-05-03 16:01:26 -0700150 return EGL_TRUE;
151}
152
John Reck1bcacfd2017-11-03 10:12:19 -0700153EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
154 EGLClientBuffer buffer, const EGLint* attrib_list) {
155 return (EGLImageKHR)malloc(sizeof(EGLImageKHR));
John Reck041b9852015-02-25 14:32:41 -0800156}
157
John Reck1bcacfd2017-11-03 10:12:19 -0700158EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list) {
sergeyv83809fe2017-02-01 10:27:33 -0800159 return gFence;
160}
161
162EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) {
163 return EGL_TRUE;
164}
165
166EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) {
167 return EGL_CONDITION_SATISFIED_KHR;
168}
169
John Reck041b9852015-02-25 14:32:41 -0800170EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
171 free(image);
172 return EGL_TRUE;
173}
174
175void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {}