nullegl.cpp revision 63cd1b4d1150e47d1aa9a2124772ecbd223054e4
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 24static EGLDisplay gDisplay = (EGLDisplay) 1; 25 26typedef struct { 27 EGLSurface surface; 28 EGLContext context; 29} ThreadState; 30 31static pthread_key_t ThreadStateKey; 32static pthread_once_t ThreadStateSetupOnce = PTHREAD_ONCE_INIT; 33 34static void destroyThreadState(void* state) { 35 free(state); 36} 37 38static void makeThreadState() { 39 pthread_key_create(&ThreadStateKey, destroyThreadState); 40} 41 42ThreadState* 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 54EGLint eglGetError(void) { 55 return EGL_SUCCESS; 56} 57 58EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id) { 59 return gDisplay; 60} 61 62EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) { 63 return EGL_TRUE; 64} 65 66EGLBoolean eglTerminate(EGLDisplay dpy) { 67 return EGL_TRUE; 68} 69 70const char * eglQueryString(EGLDisplay dpy, EGLint name) { 71 if (name == EGL_EXTENSIONS) { 72 return "EGL_KHR_swap_buffers_with_damage"; 73 } 74 return ""; 75} 76 77EGLBoolean 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 85EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, 86 EGLNativeWindowType win, 87 const EGLint *attrib_list) { 88 return (EGLSurface) malloc(sizeof(void*)); 89} 90 91EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, 92 const EGLint *attrib_list) { 93 return (EGLSurface) malloc(sizeof(void*)); 94} 95 96EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface surface) { 97 free(surface); 98 return EGL_TRUE; 99} 100 101EGLBoolean eglQuerySurface(EGLDisplay dpy, EGLSurface surface, 102 EGLint attribute, EGLint *value) { 103 *value = 1000; 104 return EGL_TRUE; 105} 106 107EGLBoolean eglReleaseThread(void) { 108 return EGL_TRUE; 109} 110 111EGLBoolean eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface, 112 EGLint attribute, EGLint value) { 113 return EGL_TRUE; 114} 115 116EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint interval) { 117 return EGL_TRUE; 118} 119 120EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, 121 EGLContext share_context, 122 const EGLint *attrib_list) { 123 return (EGLContext) malloc(sizeof(void*)); 124} 125EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) { 126 free(ctx); 127 return EGL_TRUE; 128} 129 130EGLBoolean 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 138EGLContext eglGetCurrentContext(void) { 139 return getThreadState()->context; 140} 141 142EGLSurface eglGetCurrentSurface(EGLint readdraw) { 143 return getThreadState()->surface; 144} 145 146EGLDisplay eglGetCurrentDisplay(void) { 147 return gDisplay; 148} 149 150EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { 151 return EGL_TRUE; 152} 153 154EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, EGLint *rects, EGLint rectCount) { 155 return EGL_TRUE; 156} 157 158EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attrib_list) { 159 return (EGLImageKHR) malloc(sizeof(EGLImageKHR)); 160} 161 162EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) { 163 free(image); 164 return EGL_TRUE; 165} 166 167void eglBeginFrame(EGLDisplay dpy, EGLSurface surface) {} 168