Home | History | Annotate | Download | only in debug
      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) {
     71     return "";
     72 }
     73 
     74 EGLBoolean eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list,
     75                EGLConfig *configs, EGLint config_size,
     76                EGLint *num_config) {
     77     memset(configs, 9, sizeof(EGLConfig) * config_size);
     78     *num_config = config_size;
     79     return EGL_TRUE;
     80 }
     81 
     82 EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
     83                   EGLNativeWindowType win,
     84                   const EGLint *attrib_list) {
     85     return (EGLSurface) malloc(sizeof(void*));
     86 }
     87 
     88 EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
     89                    const EGLint *attrib_list) {
     90     return (EGLSurface) malloc(sizeof(void*));
     91 }
     92 
     93 EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) {
     94     free(surface);
     95     return EGL_TRUE;
     96 }
     97 
     98 EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
     99                EGLint attribute, EGLint *value) {
    100     *value = 1000;
    101     return EGL_TRUE;
    102 }
    103 
    104 EGLBoolean eglReleaseThread(void) {
    105     return EGL_TRUE;
    106 }
    107 
    108 EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
    109                 EGLint attribute, EGLint value) {
    110     return EGL_TRUE;
    111 }
    112 
    113 EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) {
    114     return EGL_TRUE;
    115 }
    116 
    117 EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config,
    118                 EGLContext share_context,
    119                 const EGLint *attrib_list) {
    120     return (EGLContext) malloc(sizeof(void*));
    121 }
    122 EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) {
    123     free(ctx);
    124     return EGL_TRUE;
    125 }
    126 
    127 EGLBoolean eglMakeCurrent(EGLDisplay dpy, EGLSurface draw,
    128               EGLSurface read, EGLContext ctx) {
    129     ThreadState* state = getThreadState();
    130     state->surface = draw;
    131     state->context = ctx;
    132     return EGL_TRUE;
    133 }
    134 
    135 EGLContext eglGetCurrentContext(void) {
    136     return getThreadState()->context;
    137 }
    138 
    139 EGLSurface eglGetCurrentSurface(EGLint readdraw) {
    140     return getThreadState()->surface;
    141 }
    142 
    143 EGLDisplay eglGetCurrentDisplay(void) {
    144     return gDisplay;
    145 }
    146 
    147 EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
    148     return EGL_TRUE;
    149 }
    150 
    151 EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) {
    152     return (EGLImageKHR) malloc(sizeof(EGLImageKHR));
    153 }
    154 
    155 EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
    156     free(image);
    157     return EGL_TRUE;
    158 }
    159 
    160 void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {}
    161