| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1 | /* | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2 | ** | 
|  | 3 | ** Copyright 2007 The Android Open Source Project | 
|  | 4 | ** | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 5 | ** Licensed under the Apache License Version 2.0(the "License"); | 
|  | 6 | ** you may not use this file except in compliance with the License. | 
|  | 7 | ** You may obtain a copy of the License at | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 9 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 11 | ** Unless required by applicable law or agreed to in writing software | 
|  | 12 | ** distributed under the License is distributed on an "AS IS" BASIS | 
|  | 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied. | 
|  | 14 | ** See the License for the specific language governing permissions and | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 15 | ** limitations under the License. | 
|  | 16 | */ | 
|  | 17 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | #include <assert.h> | 
|  | 19 | #include <errno.h> | 
|  | 20 | #include <stdlib.h> | 
|  | 21 | #include <stdio.h> | 
|  | 22 | #include <string.h> | 
|  | 23 | #include <unistd.h> | 
|  | 24 | #include <fcntl.h> | 
|  | 25 | #include <sys/ioctl.h> | 
|  | 26 | #include <sys/types.h> | 
|  | 27 | #include <sys/mman.h> | 
|  | 28 |  | 
|  | 29 | #include <cutils/log.h> | 
|  | 30 | #include <cutils/atomic.h> | 
|  | 31 |  | 
|  | 32 | #include <utils/threads.h> | 
| Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 33 | #include <ui/ANativeObjectBase.h> | 
| Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 34 | #include <ui/Fence.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 |  | 
|  | 36 | #include <EGL/egl.h> | 
|  | 37 | #include <EGL/eglext.h> | 
|  | 38 | #include <GLES/gl.h> | 
|  | 39 | #include <GLES/glext.h> | 
|  | 40 |  | 
|  | 41 | #include <pixelflinger/format.h> | 
|  | 42 | #include <pixelflinger/pixelflinger.h> | 
|  | 43 |  | 
|  | 44 | #include "context.h" | 
|  | 45 | #include "state.h" | 
|  | 46 | #include "texture.h" | 
|  | 47 | #include "matrix.h" | 
|  | 48 |  | 
|  | 49 | #undef NELEM | 
|  | 50 | #define NELEM(x) (sizeof(x)/sizeof(*(x))) | 
|  | 51 |  | 
| Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 52 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 4b9511c | 2011-11-13 23:52:47 -0800 | [diff] [blame] | 53 |  | 
|  | 54 | EGLBoolean EGLAPI eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, | 
|  | 55 | EGLint left, EGLint top, EGLint width, EGLint height); | 
|  | 56 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | // ---------------------------------------------------------------------------- | 
|  | 58 | namespace android { | 
| Mathias Agopian | 5f2165f | 2012-02-24 18:25:41 -0800 | [diff] [blame] | 59 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | // ---------------------------------------------------------------------------- | 
|  | 61 |  | 
|  | 62 | const unsigned int NUM_DISPLAYS = 1; | 
|  | 63 |  | 
|  | 64 | static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER; | 
|  | 65 | static pthread_mutex_t gErrorKeyMutex = PTHREAD_MUTEX_INITIALIZER; | 
|  | 66 | static pthread_key_t gEGLErrorKey = -1; | 
| Elliott Hughes | 6071da7 | 2015-08-12 15:27:47 -0700 | [diff] [blame] | 67 | #ifndef __ANDROID__ | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | namespace gl { | 
|  | 69 | pthread_key_t gGLKey = -1; | 
|  | 70 | }; // namespace gl | 
|  | 71 | #endif | 
|  | 72 |  | 
|  | 73 | template<typename T> | 
|  | 74 | static T setError(GLint error, T returnValue) { | 
|  | 75 | if (ggl_unlikely(gEGLErrorKey == -1)) { | 
|  | 76 | pthread_mutex_lock(&gErrorKeyMutex); | 
|  | 77 | if (gEGLErrorKey == -1) | 
|  | 78 | pthread_key_create(&gEGLErrorKey, NULL); | 
|  | 79 | pthread_mutex_unlock(&gErrorKeyMutex); | 
|  | 80 | } | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 81 | pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)error); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | return returnValue; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | static GLint getError() { | 
|  | 86 | if (ggl_unlikely(gEGLErrorKey == -1)) | 
|  | 87 | return EGL_SUCCESS; | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 88 | GLint error = (GLint)(uintptr_t)pthread_getspecific(gEGLErrorKey); | 
| Jamie Gennis | 2076f35 | 2011-01-30 15:59:36 -0800 | [diff] [blame] | 89 | if (error == 0) { | 
|  | 90 | // The TLS key has been created by another thread, but the value for | 
|  | 91 | // this thread has not been initialized. | 
|  | 92 | return EGL_SUCCESS; | 
|  | 93 | } | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 94 | pthread_setspecific(gEGLErrorKey, (void*)(uintptr_t)EGL_SUCCESS); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | return error; | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | // ---------------------------------------------------------------------------- | 
|  | 99 |  | 
|  | 100 | struct egl_display_t | 
|  | 101 | { | 
|  | 102 | egl_display_t() : type(0), initialized(0) { } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 103 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | static egl_display_t& get_display(EGLDisplay dpy); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 105 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | static EGLBoolean is_valid(EGLDisplay dpy) { | 
|  | 107 | return ((uintptr_t(dpy)-1U) >= NUM_DISPLAYS) ? EGL_FALSE : EGL_TRUE; | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | NativeDisplayType   type; | 
|  | 111 | volatile int32_t    initialized; | 
|  | 112 | }; | 
|  | 113 |  | 
|  | 114 | static egl_display_t gDisplays[NUM_DISPLAYS]; | 
|  | 115 |  | 
|  | 116 | egl_display_t& egl_display_t::get_display(EGLDisplay dpy) { | 
|  | 117 | return gDisplays[uintptr_t(dpy)-1U]; | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | struct egl_context_t { | 
|  | 121 | enum { | 
|  | 122 | IS_CURRENT      =   0x00010000, | 
|  | 123 | NEVER_CURRENT   =   0x00020000 | 
|  | 124 | }; | 
|  | 125 | uint32_t            flags; | 
|  | 126 | EGLDisplay          dpy; | 
|  | 127 | EGLConfig           config; | 
|  | 128 | EGLSurface          read; | 
|  | 129 | EGLSurface          draw; | 
|  | 130 |  | 
|  | 131 | static inline egl_context_t* context(EGLContext ctx) { | 
|  | 132 | ogles_context_t* const gl = static_cast<ogles_context_t*>(ctx); | 
|  | 133 | return static_cast<egl_context_t*>(gl->rasterizer.base); | 
|  | 134 | } | 
|  | 135 | }; | 
|  | 136 |  | 
|  | 137 | // ---------------------------------------------------------------------------- | 
|  | 138 |  | 
|  | 139 | struct egl_surface_t | 
|  | 140 | { | 
|  | 141 | enum { | 
|  | 142 | PAGE_FLIP = 0x00000001, | 
|  | 143 | MAGIC     = 0x31415265 | 
|  | 144 | }; | 
|  | 145 |  | 
|  | 146 | uint32_t            magic; | 
|  | 147 | EGLDisplay          dpy; | 
|  | 148 | EGLConfig           config; | 
|  | 149 | EGLContext          ctx; | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 150 | bool                zombie; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 |  | 
|  | 152 | egl_surface_t(EGLDisplay dpy, EGLConfig config, int32_t depthFormat); | 
|  | 153 | virtual     ~egl_surface_t(); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 154 | bool    isValid() const; | 
|  | 155 | virtual     bool    initCheck() const = 0; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 156 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl) = 0; | 
|  | 158 | virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl) = 0; | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 159 | virtual     EGLBoolean  connect() { return EGL_TRUE; } | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 160 | virtual     void        disconnect() {} | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | virtual     EGLint      getWidth() const = 0; | 
|  | 162 | virtual     EGLint      getHeight() const = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 |  | 
|  | 164 | virtual     EGLint      getHorizontalResolution() const; | 
|  | 165 | virtual     EGLint      getVerticalResolution() const; | 
|  | 166 | virtual     EGLint      getRefreshRate() const; | 
|  | 167 | virtual     EGLint      getSwapBehavior() const; | 
|  | 168 | virtual     EGLBoolean  swapBuffers(); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 169 | virtual     EGLBoolean  setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | protected: | 
|  | 171 | GGLSurface              depth; | 
|  | 172 | }; | 
|  | 173 |  | 
|  | 174 | egl_surface_t::egl_surface_t(EGLDisplay dpy, | 
|  | 175 | EGLConfig config, | 
|  | 176 | int32_t depthFormat) | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 177 | : magic(MAGIC), dpy(dpy), config(config), ctx(0), zombie(false) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | { | 
|  | 179 | depth.version = sizeof(GGLSurface); | 
|  | 180 | depth.data = 0; | 
|  | 181 | depth.format = depthFormat; | 
|  | 182 | } | 
|  | 183 | egl_surface_t::~egl_surface_t() | 
|  | 184 | { | 
|  | 185 | magic = 0; | 
|  | 186 | free(depth.data); | 
|  | 187 | } | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 188 | bool egl_surface_t::isValid() const { | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 189 | ALOGE_IF(magic != MAGIC, "invalid EGLSurface (%p)", this); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 190 | return magic == MAGIC; | 
|  | 191 | } | 
|  | 192 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | EGLBoolean egl_surface_t::swapBuffers() { | 
|  | 194 | return EGL_FALSE; | 
|  | 195 | } | 
|  | 196 | EGLint egl_surface_t::getHorizontalResolution() const { | 
|  | 197 | return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f); | 
|  | 198 | } | 
|  | 199 | EGLint egl_surface_t::getVerticalResolution() const { | 
|  | 200 | return (0 * EGL_DISPLAY_SCALING) * (1.0f / 25.4f); | 
|  | 201 | } | 
|  | 202 | EGLint egl_surface_t::getRefreshRate() const { | 
|  | 203 | return (60 * EGL_DISPLAY_SCALING); | 
|  | 204 | } | 
|  | 205 | EGLint egl_surface_t::getSwapBehavior() const { | 
|  | 206 | return EGL_BUFFER_PRESERVED; | 
|  | 207 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 208 | EGLBoolean egl_surface_t::setSwapRectangle( | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 209 | EGLint /*l*/, EGLint /*t*/, EGLint /*w*/, EGLint /*h*/) | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 210 | { | 
|  | 211 | return EGL_FALSE; | 
|  | 212 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 |  | 
|  | 214 | // ---------------------------------------------------------------------------- | 
|  | 215 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 216 | struct egl_window_surface_v2_t : public egl_surface_t | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 218 | egl_window_surface_v2_t( | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | EGLDisplay dpy, EGLConfig config, | 
|  | 220 | int32_t depthFormat, | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 221 | ANativeWindow* window); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 223 | ~egl_window_surface_v2_t(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 225 | virtual     bool        initCheck() const { return true; } // TODO: report failure if ctor fails | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | virtual     EGLBoolean  swapBuffers(); | 
|  | 227 | virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl); | 
|  | 228 | virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl); | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 229 | virtual     EGLBoolean  connect(); | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 230 | virtual     void        disconnect(); | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 231 | virtual     EGLint      getWidth() const    { return width;  } | 
|  | 232 | virtual     EGLint      getHeight() const   { return height; } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | virtual     EGLint      getHorizontalResolution() const; | 
|  | 234 | virtual     EGLint      getVerticalResolution() const; | 
|  | 235 | virtual     EGLint      getRefreshRate() const; | 
|  | 236 | virtual     EGLint      getSwapBehavior() const; | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 237 | virtual     EGLBoolean  setSwapRectangle(EGLint l, EGLint t, EGLint w, EGLint h); | 
| Mathias Agopian | 8d2e83b | 2009-06-24 22:37:39 -0700 | [diff] [blame] | 238 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | private: | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 240 | status_t lock(ANativeWindowBuffer* buf, int usage, void** vaddr); | 
|  | 241 | status_t unlock(ANativeWindowBuffer* buf); | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 242 | ANativeWindow*   nativeWindow; | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 243 | ANativeWindowBuffer*   buffer; | 
|  | 244 | ANativeWindowBuffer*   previousBuffer; | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 245 | gralloc_module_t const*    module; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 246 | int width; | 
|  | 247 | int height; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 248 | void* bits; | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 249 | GGLFormat const* pixelFormatTable; | 
|  | 250 |  | 
|  | 251 | struct Rect { | 
|  | 252 | inline Rect() { }; | 
|  | 253 | inline Rect(int32_t w, int32_t h) | 
|  | 254 | : left(0), top(0), right(w), bottom(h) { } | 
|  | 255 | inline Rect(int32_t l, int32_t t, int32_t r, int32_t b) | 
|  | 256 | : left(l), top(t), right(r), bottom(b) { } | 
|  | 257 | Rect& andSelf(const Rect& r) { | 
|  | 258 | left   = max(left, r.left); | 
|  | 259 | top    = max(top, r.top); | 
|  | 260 | right  = min(right, r.right); | 
|  | 261 | bottom = min(bottom, r.bottom); | 
|  | 262 | return *this; | 
|  | 263 | } | 
|  | 264 | bool isEmpty() const { | 
|  | 265 | return (left>=right || top>=bottom); | 
|  | 266 | } | 
|  | 267 | void dump(char const* what) { | 
| Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 268 | ALOGD("%s { %5d, %5d, w=%5d, h=%5d }", | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 269 | what, left, top, right-left, bottom-top); | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | int32_t left; | 
|  | 273 | int32_t top; | 
|  | 274 | int32_t right; | 
|  | 275 | int32_t bottom; | 
|  | 276 | }; | 
|  | 277 |  | 
|  | 278 | struct Region { | 
|  | 279 | inline Region() : count(0) { } | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 280 | typedef Rect const* const_iterator; | 
|  | 281 | const_iterator begin() const { return storage; } | 
|  | 282 | const_iterator end() const { return storage+count; } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 283 | static Region subtract(const Rect& lhs, const Rect& rhs) { | 
|  | 284 | Region reg; | 
|  | 285 | Rect* storage = reg.storage; | 
|  | 286 | if (!lhs.isEmpty()) { | 
|  | 287 | if (lhs.top < rhs.top) { // top rect | 
|  | 288 | storage->left   = lhs.left; | 
|  | 289 | storage->top    = lhs.top; | 
|  | 290 | storage->right  = lhs.right; | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 291 | storage->bottom = rhs.top; | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 292 | storage++; | 
|  | 293 | } | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 294 | const int32_t top = max(lhs.top, rhs.top); | 
|  | 295 | const int32_t bot = min(lhs.bottom, rhs.bottom); | 
|  | 296 | if (top < bot) { | 
|  | 297 | if (lhs.left < rhs.left) { // left-side rect | 
|  | 298 | storage->left   = lhs.left; | 
|  | 299 | storage->top    = top; | 
|  | 300 | storage->right  = rhs.left; | 
|  | 301 | storage->bottom = bot; | 
|  | 302 | storage++; | 
|  | 303 | } | 
|  | 304 | if (lhs.right > rhs.right) { // right-side rect | 
|  | 305 | storage->left   = rhs.right; | 
|  | 306 | storage->top    = top; | 
|  | 307 | storage->right  = lhs.right; | 
|  | 308 | storage->bottom = bot; | 
|  | 309 | storage++; | 
|  | 310 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 311 | } | 
|  | 312 | if (lhs.bottom > rhs.bottom) { // bottom rect | 
|  | 313 | storage->left   = lhs.left; | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 314 | storage->top    = rhs.bottom; | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 315 | storage->right  = lhs.right; | 
|  | 316 | storage->bottom = lhs.bottom; | 
|  | 317 | storage++; | 
|  | 318 | } | 
|  | 319 | reg.count = storage - reg.storage; | 
|  | 320 | } | 
|  | 321 | return reg; | 
|  | 322 | } | 
|  | 323 | bool isEmpty() const { | 
|  | 324 | return count<=0; | 
|  | 325 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 326 | private: | 
|  | 327 | Rect storage[4]; | 
|  | 328 | ssize_t count; | 
|  | 329 | }; | 
|  | 330 |  | 
|  | 331 | void copyBlt( | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 332 | ANativeWindowBuffer* dst, void* dst_vaddr, | 
|  | 333 | ANativeWindowBuffer* src, void const* src_vaddr, | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 334 | const Region& clip); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 335 |  | 
|  | 336 | Rect dirtyRegion; | 
|  | 337 | Rect oldDirtyRegion; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | }; | 
|  | 339 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 340 | egl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | EGLConfig config, | 
|  | 342 | int32_t depthFormat, | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 343 | ANativeWindow* window) | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 344 | : egl_surface_t(dpy, config, depthFormat), | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 345 | nativeWindow(window), buffer(0), previousBuffer(0), module(0), | 
| Mathias Agopian | 9cdb01d | 2011-04-28 19:50:21 -0700 | [diff] [blame] | 346 | bits(NULL) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | { | 
| Mathias Agopian | 69e43b7 | 2011-05-11 13:41:09 -0700 | [diff] [blame] | 348 | hw_module_t const* pModule; | 
|  | 349 | hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule); | 
|  | 350 | module = reinterpret_cast<gralloc_module_t const*>(pModule); | 
|  | 351 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 352 | pixelFormatTable = gglGetPixelFormatTable(); | 
|  | 353 |  | 
|  | 354 | // keep a reference on the window | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 355 | nativeWindow->common.incRef(&nativeWindow->common); | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 356 | nativeWindow->query(nativeWindow, NATIVE_WINDOW_WIDTH, &width); | 
|  | 357 | nativeWindow->query(nativeWindow, NATIVE_WINDOW_HEIGHT, &height); | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 358 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 359 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 360 | egl_window_surface_v2_t::~egl_window_surface_v2_t() { | 
|  | 361 | if (buffer) { | 
|  | 362 | buffer->common.decRef(&buffer->common); | 
|  | 363 | } | 
|  | 364 | if (previousBuffer) { | 
|  | 365 | previousBuffer->common.decRef(&previousBuffer->common); | 
|  | 366 | } | 
|  | 367 | nativeWindow->common.decRef(&nativeWindow->common); | 
|  | 368 | } | 
|  | 369 |  | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 370 | EGLBoolean egl_window_surface_v2_t::connect() | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 371 | { | 
| Mathias Agopian | 5221271 | 2009-08-11 22:34:02 -0700 | [diff] [blame] | 372 | // we're intending to do software rendering | 
|  | 373 | native_window_set_usage(nativeWindow, | 
|  | 374 | GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); | 
|  | 375 |  | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 376 | // dequeue a buffer | 
| Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 377 | int fenceFd = -1; | 
|  | 378 | if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, | 
|  | 379 | &fenceFd) != NO_ERROR) { | 
|  | 380 | return setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | // wait for the buffer | 
|  | 384 | sp<Fence> fence(new Fence(fenceFd)); | 
|  | 385 | if (fence->wait(Fence::TIMEOUT_NEVER) != NO_ERROR) { | 
|  | 386 | nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd); | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 387 | return setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 388 | } | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 389 |  | 
|  | 390 | // allocate a corresponding depth-buffer | 
|  | 391 | width = buffer->width; | 
|  | 392 | height = buffer->height; | 
|  | 393 | if (depth.format) { | 
|  | 394 | depth.width   = width; | 
|  | 395 | depth.height  = height; | 
|  | 396 | depth.stride  = depth.width; // use the width here | 
| Michael Lentine | 9530388 | 2015-05-28 17:43:06 -0700 | [diff] [blame] | 397 | uint64_t allocSize = static_cast<uint64_t>(depth.stride) * | 
|  | 398 | static_cast<uint64_t>(depth.height) * 2; | 
|  | 399 | if (depth.stride < 0 || depth.height > INT_MAX || | 
|  | 400 | allocSize > UINT32_MAX) { | 
|  | 401 | return setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 402 | } | 
|  | 403 | depth.data    = (GGLubyte*)malloc(allocSize); | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 404 | if (depth.data == 0) { | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 405 | return setError(EGL_BAD_ALLOC, EGL_FALSE); | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 406 | } | 
|  | 407 | } | 
|  | 408 |  | 
|  | 409 | // keep a reference on the buffer | 
|  | 410 | buffer->common.incRef(&buffer->common); | 
|  | 411 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 412 | // pin the buffer down | 
|  | 413 | if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | | 
|  | 414 | GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) { | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 415 | ALOGE("connect() failed to lock buffer %p (%ux%u)", | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 416 | buffer, buffer->width, buffer->height); | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 417 | return setError(EGL_BAD_ACCESS, EGL_FALSE); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 418 | // FIXME: we should make sure we're not accessing the buffer anymore | 
|  | 419 | } | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 420 | return EGL_TRUE; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 421 | } | 
|  | 422 |  | 
|  | 423 | void egl_window_surface_v2_t::disconnect() | 
|  | 424 | { | 
| Mathias Agopian | 9648c1a | 2009-06-03 19:00:53 -0700 | [diff] [blame] | 425 | if (buffer && bits) { | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 426 | bits = NULL; | 
|  | 427 | unlock(buffer); | 
|  | 428 | } | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 429 | if (buffer) { | 
| Jesse Hall | 5f55556 | 2013-03-07 15:14:18 -0800 | [diff] [blame] | 430 | nativeWindow->cancelBuffer(nativeWindow, buffer, -1); | 
| Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 431 | buffer->common.decRef(&buffer->common); | 
|  | 432 | buffer = 0; | 
|  | 433 | } | 
|  | 434 | if (previousBuffer) { | 
|  | 435 | previousBuffer->common.decRef(&previousBuffer->common); | 
|  | 436 | previousBuffer = 0; | 
|  | 437 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 438 | } | 
|  | 439 |  | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 440 | status_t egl_window_surface_v2_t::lock( | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 441 | ANativeWindowBuffer* buf, int usage, void** vaddr) | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 442 | { | 
| Mathias Agopian | bc49291 | 2009-11-03 20:38:08 -0800 | [diff] [blame] | 443 | int err; | 
| Mathias Agopian | 695b66f | 2010-12-08 17:44:07 -0800 | [diff] [blame] | 444 |  | 
|  | 445 | err = module->lock(module, buf->handle, | 
|  | 446 | usage, 0, 0, buf->width, buf->height, vaddr); | 
|  | 447 |  | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 448 | return err; | 
|  | 449 | } | 
|  | 450 |  | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 451 | status_t egl_window_surface_v2_t::unlock(ANativeWindowBuffer* buf) | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 452 | { | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 453 | if (!buf) return BAD_VALUE; | 
| Mathias Agopian | bc49291 | 2009-11-03 20:38:08 -0800 | [diff] [blame] | 454 | int err = NO_ERROR; | 
| Mathias Agopian | 695b66f | 2010-12-08 17:44:07 -0800 | [diff] [blame] | 455 |  | 
|  | 456 | err = module->unlock(module, buf->handle); | 
|  | 457 |  | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 458 | return err; | 
|  | 459 | } | 
|  | 460 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 461 | void egl_window_surface_v2_t::copyBlt( | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 462 | ANativeWindowBuffer* dst, void* dst_vaddr, | 
|  | 463 | ANativeWindowBuffer* src, void const* src_vaddr, | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 464 | const Region& clip) | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 465 | { | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 466 | // NOTE: dst and src must be the same format | 
|  | 467 |  | 
| Mathias Agopian | 9cdb01d | 2011-04-28 19:50:21 -0700 | [diff] [blame] | 468 | Region::const_iterator cur = clip.begin(); | 
|  | 469 | Region::const_iterator end = clip.end(); | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 470 |  | 
| Mathias Agopian | 9cdb01d | 2011-04-28 19:50:21 -0700 | [diff] [blame] | 471 | const size_t bpp = pixelFormatTable[src->format].size; | 
|  | 472 | const size_t dbpr = dst->stride * bpp; | 
|  | 473 | const size_t sbpr = src->stride * bpp; | 
|  | 474 |  | 
|  | 475 | uint8_t const * const src_bits = (uint8_t const *)src_vaddr; | 
|  | 476 | uint8_t       * const dst_bits = (uint8_t       *)dst_vaddr; | 
|  | 477 |  | 
|  | 478 | while (cur != end) { | 
|  | 479 | const Rect& r(*cur++); | 
|  | 480 | ssize_t w = r.right - r.left; | 
|  | 481 | ssize_t h = r.bottom - r.top; | 
|  | 482 | if (w <= 0 || h<=0) continue; | 
|  | 483 | size_t size = w * bpp; | 
|  | 484 | uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp; | 
|  | 485 | uint8_t       * d = dst_bits + (r.left + dst->stride * r.top) * bpp; | 
|  | 486 | if (dbpr==sbpr && size==sbpr) { | 
|  | 487 | size *= h; | 
|  | 488 | h = 1; | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 489 | } | 
| Mathias Agopian | 9cdb01d | 2011-04-28 19:50:21 -0700 | [diff] [blame] | 490 | do { | 
|  | 491 | memcpy(d, s, size); | 
|  | 492 | d += dbpr; | 
|  | 493 | s += sbpr; | 
|  | 494 | } while (--h > 0); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 495 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
|  | 498 | EGLBoolean egl_window_surface_v2_t::swapBuffers() | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | { | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 500 | if (!buffer) { | 
|  | 501 | return setError(EGL_BAD_ACCESS, EGL_FALSE); | 
|  | 502 | } | 
|  | 503 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 504 | /* | 
|  | 505 | * Handle eglSetSwapRectangleANDROID() | 
|  | 506 | * We copyback from the front buffer | 
|  | 507 | */ | 
|  | 508 | if (!dirtyRegion.isEmpty()) { | 
|  | 509 | dirtyRegion.andSelf(Rect(buffer->width, buffer->height)); | 
|  | 510 | if (previousBuffer) { | 
| Kristian Monsen | 72c384e | 2010-10-27 17:59:09 +0100 | [diff] [blame] | 511 | // This was const Region copyBack, but that causes an | 
|  | 512 | // internal compile error on simulator builds | 
|  | 513 | /*const*/ Region copyBack(Region::subtract(oldDirtyRegion, dirtyRegion)); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 514 | if (!copyBack.isEmpty()) { | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 515 | void* prevBits; | 
|  | 516 | if (lock(previousBuffer, | 
| Mathias Agopian | 240c9fe | 2009-06-25 15:39:25 -0700 | [diff] [blame] | 517 | GRALLOC_USAGE_SW_READ_OFTEN, &prevBits) == NO_ERROR) { | 
|  | 518 | // copy from previousBuffer to buffer | 
|  | 519 | copyBlt(buffer, bits, previousBuffer, prevBits, copyBack); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 520 | unlock(previousBuffer); | 
|  | 521 | } | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 | oldDirtyRegion = dirtyRegion; | 
|  | 525 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 526 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 527 | if (previousBuffer) { | 
|  | 528 | previousBuffer->common.decRef(&previousBuffer->common); | 
|  | 529 | previousBuffer = 0; | 
|  | 530 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 531 |  | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 532 | unlock(buffer); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 533 | previousBuffer = buffer; | 
| Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 534 | nativeWindow->queueBuffer(nativeWindow, buffer, -1); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 535 | buffer = 0; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 536 |  | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 537 | // dequeue a new buffer | 
| Jamie Gennis | d8e812c | 2012-06-13 16:32:25 -0700 | [diff] [blame] | 538 | int fenceFd = -1; | 
|  | 539 | if (nativeWindow->dequeueBuffer(nativeWindow, &buffer, &fenceFd) == NO_ERROR) { | 
|  | 540 | sp<Fence> fence(new Fence(fenceFd)); | 
|  | 541 | if (fence->wait(Fence::TIMEOUT_NEVER)) { | 
|  | 542 | nativeWindow->cancelBuffer(nativeWindow, buffer, fenceFd); | 
|  | 543 | return setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 544 | } | 
| Mathias Agopian | 031213e | 2010-08-18 16:07:34 -0700 | [diff] [blame] | 545 |  | 
|  | 546 | // reallocate the depth-buffer if needed | 
|  | 547 | if ((width != buffer->width) || (height != buffer->height)) { | 
|  | 548 | // TODO: we probably should reset the swap rect here | 
|  | 549 | // if the window size has changed | 
|  | 550 | width = buffer->width; | 
|  | 551 | height = buffer->height; | 
|  | 552 | if (depth.data) { | 
|  | 553 | free(depth.data); | 
|  | 554 | depth.width   = width; | 
|  | 555 | depth.height  = height; | 
|  | 556 | depth.stride  = buffer->stride; | 
| Michael Lentine | 9530388 | 2015-05-28 17:43:06 -0700 | [diff] [blame] | 557 | uint64_t allocSize = static_cast<uint64_t>(depth.stride) * | 
|  | 558 | static_cast<uint64_t>(depth.height) * 2; | 
|  | 559 | if (depth.stride < 0 || depth.height > INT_MAX || | 
|  | 560 | allocSize > UINT32_MAX) { | 
|  | 561 | setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 562 | return EGL_FALSE; | 
|  | 563 | } | 
|  | 564 | depth.data    = (GGLubyte*)malloc(allocSize); | 
| Mathias Agopian | 031213e | 2010-08-18 16:07:34 -0700 | [diff] [blame] | 565 | if (depth.data == 0) { | 
|  | 566 | setError(EGL_BAD_ALLOC, EGL_FALSE); | 
|  | 567 | return EGL_FALSE; | 
|  | 568 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | } | 
|  | 570 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 571 |  | 
| Mathias Agopian | 031213e | 2010-08-18 16:07:34 -0700 | [diff] [blame] | 572 | // keep a reference on the buffer | 
|  | 573 | buffer->common.incRef(&buffer->common); | 
|  | 574 |  | 
|  | 575 | // finally pin the buffer down | 
|  | 576 | if (lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | | 
|  | 577 | GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) { | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 578 | ALOGE("eglSwapBuffers() failed to lock buffer %p (%ux%u)", | 
| Mathias Agopian | 031213e | 2010-08-18 16:07:34 -0700 | [diff] [blame] | 579 | buffer, buffer->width, buffer->height); | 
|  | 580 | return setError(EGL_BAD_ACCESS, EGL_FALSE); | 
|  | 581 | // FIXME: we should make sure we're not accessing the buffer anymore | 
|  | 582 | } | 
|  | 583 | } else { | 
|  | 584 | return setError(EGL_BAD_CURRENT_SURFACE, EGL_FALSE); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 585 | } | 
|  | 586 |  | 
|  | 587 | return EGL_TRUE; | 
|  | 588 | } | 
|  | 589 |  | 
|  | 590 | EGLBoolean egl_window_surface_v2_t::setSwapRectangle( | 
|  | 591 | EGLint l, EGLint t, EGLint w, EGLint h) | 
|  | 592 | { | 
|  | 593 | dirtyRegion = Rect(l, t, l+w, t+h); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | return EGL_TRUE; | 
|  | 595 | } | 
|  | 596 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 597 | EGLBoolean egl_window_surface_v2_t::bindDrawSurface(ogles_context_t* gl) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | { | 
|  | 599 | GGLSurface buffer; | 
|  | 600 | buffer.version = sizeof(GGLSurface); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 601 | buffer.width   = this->buffer->width; | 
|  | 602 | buffer.height  = this->buffer->height; | 
|  | 603 | buffer.stride  = this->buffer->stride; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 604 | buffer.data    = (GGLubyte*)bits; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 605 | buffer.format  = this->buffer->format; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | gl->rasterizer.procs.colorBuffer(gl, &buffer); | 
|  | 607 | if (depth.data != gl->rasterizer.state.buffers.depth.data) | 
|  | 608 | gl->rasterizer.procs.depthBuffer(gl, &depth); | 
| Mathias Agopian | 0a3139a | 2009-06-10 16:01:54 -0700 | [diff] [blame] | 609 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 610 | return EGL_TRUE; | 
|  | 611 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 612 | EGLBoolean egl_window_surface_v2_t::bindReadSurface(ogles_context_t* gl) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 613 | { | 
|  | 614 | GGLSurface buffer; | 
|  | 615 | buffer.version = sizeof(GGLSurface); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 616 | buffer.width   = this->buffer->width; | 
|  | 617 | buffer.height  = this->buffer->height; | 
|  | 618 | buffer.stride  = this->buffer->stride; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 619 | buffer.data    = (GGLubyte*)bits; // FIXME: hopefully is is LOCKED!!! | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 620 | buffer.format  = this->buffer->format; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | gl->rasterizer.procs.readBuffer(gl, &buffer); | 
|  | 622 | return EGL_TRUE; | 
|  | 623 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 624 | EGLint egl_window_surface_v2_t::getHorizontalResolution() const { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | return (nativeWindow->xdpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f); | 
|  | 626 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 627 | EGLint egl_window_surface_v2_t::getVerticalResolution() const { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 628 | return (nativeWindow->ydpi * EGL_DISPLAY_SCALING) * (1.0f / 25.4f); | 
|  | 629 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 630 | EGLint egl_window_surface_v2_t::getRefreshRate() const { | 
|  | 631 | return (60 * EGL_DISPLAY_SCALING); // FIXME | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 633 | EGLint egl_window_surface_v2_t::getSwapBehavior() const | 
|  | 634 | { | 
|  | 635 | /* | 
|  | 636 | * EGL_BUFFER_PRESERVED means that eglSwapBuffers() completely preserves | 
|  | 637 | * the content of the swapped buffer. | 
|  | 638 | * | 
|  | 639 | * EGL_BUFFER_DESTROYED means that the content of the buffer is lost. | 
|  | 640 | * | 
|  | 641 | * However when ANDROID_swap_retcangle is supported, EGL_BUFFER_DESTROYED | 
|  | 642 | * only applies to the area specified by eglSetSwapRectangleANDROID(), that | 
|  | 643 | * is, everything outside of this area is preserved. | 
|  | 644 | * | 
|  | 645 | * This implementation of EGL assumes the later case. | 
|  | 646 | * | 
|  | 647 | */ | 
|  | 648 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 649 | return EGL_BUFFER_DESTROYED; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 650 | } | 
|  | 651 |  | 
|  | 652 | // ---------------------------------------------------------------------------- | 
|  | 653 |  | 
|  | 654 | struct egl_pixmap_surface_t : public egl_surface_t | 
|  | 655 | { | 
|  | 656 | egl_pixmap_surface_t( | 
|  | 657 | EGLDisplay dpy, EGLConfig config, | 
|  | 658 | int32_t depthFormat, | 
|  | 659 | egl_native_pixmap_t const * pixmap); | 
|  | 660 |  | 
|  | 661 | virtual ~egl_pixmap_surface_t() { } | 
|  | 662 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 663 | virtual     bool        initCheck() const { return !depth.format || depth.data!=0; } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl); | 
|  | 665 | virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl); | 
|  | 666 | virtual     EGLint      getWidth() const    { return nativePixmap.width;  } | 
|  | 667 | virtual     EGLint      getHeight() const   { return nativePixmap.height; } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | private: | 
|  | 669 | egl_native_pixmap_t     nativePixmap; | 
|  | 670 | }; | 
|  | 671 |  | 
|  | 672 | egl_pixmap_surface_t::egl_pixmap_surface_t(EGLDisplay dpy, | 
|  | 673 | EGLConfig config, | 
|  | 674 | int32_t depthFormat, | 
|  | 675 | egl_native_pixmap_t const * pixmap) | 
|  | 676 | : egl_surface_t(dpy, config, depthFormat), nativePixmap(*pixmap) | 
|  | 677 | { | 
|  | 678 | if (depthFormat) { | 
|  | 679 | depth.width   = pixmap->width; | 
|  | 680 | depth.height  = pixmap->height; | 
|  | 681 | depth.stride  = depth.width; // use the width here | 
| Michael Lentine | 9530388 | 2015-05-28 17:43:06 -0700 | [diff] [blame] | 682 | uint64_t allocSize = static_cast<uint64_t>(depth.stride) * | 
|  | 683 | static_cast<uint64_t>(depth.height) * 2; | 
|  | 684 | if (depth.stride < 0 || depth.height > INT_MAX || | 
|  | 685 | allocSize > UINT32_MAX) { | 
|  | 686 | setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | 
|  | 687 | return; | 
|  | 688 | } | 
|  | 689 | depth.data    = (GGLubyte*)malloc(allocSize); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 690 | if (depth.data == 0) { | 
|  | 691 | setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } | 
|  | 693 | } | 
|  | 694 | } | 
|  | 695 | EGLBoolean egl_pixmap_surface_t::bindDrawSurface(ogles_context_t* gl) | 
|  | 696 | { | 
|  | 697 | GGLSurface buffer; | 
|  | 698 | buffer.version = sizeof(GGLSurface); | 
|  | 699 | buffer.width   = nativePixmap.width; | 
|  | 700 | buffer.height  = nativePixmap.height; | 
|  | 701 | buffer.stride  = nativePixmap.stride; | 
|  | 702 | buffer.data    = nativePixmap.data; | 
|  | 703 | buffer.format  = nativePixmap.format; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 704 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | gl->rasterizer.procs.colorBuffer(gl, &buffer); | 
|  | 706 | if (depth.data != gl->rasterizer.state.buffers.depth.data) | 
|  | 707 | gl->rasterizer.procs.depthBuffer(gl, &depth); | 
|  | 708 | return EGL_TRUE; | 
|  | 709 | } | 
|  | 710 | EGLBoolean egl_pixmap_surface_t::bindReadSurface(ogles_context_t* gl) | 
|  | 711 | { | 
|  | 712 | GGLSurface buffer; | 
|  | 713 | buffer.version = sizeof(GGLSurface); | 
|  | 714 | buffer.width   = nativePixmap.width; | 
|  | 715 | buffer.height  = nativePixmap.height; | 
|  | 716 | buffer.stride  = nativePixmap.stride; | 
|  | 717 | buffer.data    = nativePixmap.data; | 
|  | 718 | buffer.format  = nativePixmap.format; | 
|  | 719 | gl->rasterizer.procs.readBuffer(gl, &buffer); | 
|  | 720 | return EGL_TRUE; | 
|  | 721 | } | 
|  | 722 |  | 
|  | 723 | // ---------------------------------------------------------------------------- | 
|  | 724 |  | 
|  | 725 | struct egl_pbuffer_surface_t : public egl_surface_t | 
|  | 726 | { | 
|  | 727 | egl_pbuffer_surface_t( | 
|  | 728 | EGLDisplay dpy, EGLConfig config, int32_t depthFormat, | 
|  | 729 | int32_t w, int32_t h, int32_t f); | 
|  | 730 |  | 
|  | 731 | virtual ~egl_pbuffer_surface_t(); | 
|  | 732 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 733 | virtual     bool        initCheck() const   { return pbuffer.data != 0; } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 734 | virtual     EGLBoolean  bindDrawSurface(ogles_context_t* gl); | 
|  | 735 | virtual     EGLBoolean  bindReadSurface(ogles_context_t* gl); | 
|  | 736 | virtual     EGLint      getWidth() const    { return pbuffer.width;  } | 
|  | 737 | virtual     EGLint      getHeight() const   { return pbuffer.height; } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | private: | 
|  | 739 | GGLSurface  pbuffer; | 
|  | 740 | }; | 
|  | 741 |  | 
|  | 742 | egl_pbuffer_surface_t::egl_pbuffer_surface_t(EGLDisplay dpy, | 
|  | 743 | EGLConfig config, int32_t depthFormat, | 
|  | 744 | int32_t w, int32_t h, int32_t f) | 
|  | 745 | : egl_surface_t(dpy, config, depthFormat) | 
|  | 746 | { | 
|  | 747 | size_t size = w*h; | 
|  | 748 | switch (f) { | 
|  | 749 | case GGL_PIXEL_FORMAT_A_8:          size *= 1; break; | 
|  | 750 | case GGL_PIXEL_FORMAT_RGB_565:      size *= 2; break; | 
|  | 751 | case GGL_PIXEL_FORMAT_RGBA_8888:    size *= 4; break; | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 752 | case GGL_PIXEL_FORMAT_RGBX_8888:    size *= 4; break; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | default: | 
| Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 754 | ALOGE("incompatible pixel format for pbuffer (format=%d)", f); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 755 | pbuffer.data = 0; | 
|  | 756 | break; | 
|  | 757 | } | 
|  | 758 | pbuffer.version = sizeof(GGLSurface); | 
|  | 759 | pbuffer.width   = w; | 
|  | 760 | pbuffer.height  = h; | 
|  | 761 | pbuffer.stride  = w; | 
|  | 762 | pbuffer.data    = (GGLubyte*)malloc(size); | 
|  | 763 | pbuffer.format  = f; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 764 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 765 | if (depthFormat) { | 
|  | 766 | depth.width   = pbuffer.width; | 
|  | 767 | depth.height  = pbuffer.height; | 
|  | 768 | depth.stride  = depth.width; // use the width here | 
| Michael Lentine | 9530388 | 2015-05-28 17:43:06 -0700 | [diff] [blame] | 769 | uint64_t allocSize = static_cast<uint64_t>(depth.stride) * | 
|  | 770 | static_cast<uint64_t>(depth.height) * 2; | 
|  | 771 | if (depth.stride < 0 || depth.height > INT_MAX || | 
|  | 772 | allocSize > UINT32_MAX) { | 
|  | 773 | setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | 
|  | 774 | return; | 
|  | 775 | } | 
|  | 776 | depth.data    = (GGLubyte*)malloc(allocSize); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | if (depth.data == 0) { | 
|  | 778 | setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); | 
|  | 779 | return; | 
|  | 780 | } | 
|  | 781 | } | 
|  | 782 | } | 
|  | 783 | egl_pbuffer_surface_t::~egl_pbuffer_surface_t() { | 
|  | 784 | free(pbuffer.data); | 
|  | 785 | } | 
|  | 786 | EGLBoolean egl_pbuffer_surface_t::bindDrawSurface(ogles_context_t* gl) | 
|  | 787 | { | 
|  | 788 | gl->rasterizer.procs.colorBuffer(gl, &pbuffer); | 
|  | 789 | if (depth.data != gl->rasterizer.state.buffers.depth.data) | 
|  | 790 | gl->rasterizer.procs.depthBuffer(gl, &depth); | 
|  | 791 | return EGL_TRUE; | 
|  | 792 | } | 
|  | 793 | EGLBoolean egl_pbuffer_surface_t::bindReadSurface(ogles_context_t* gl) | 
|  | 794 | { | 
|  | 795 | gl->rasterizer.procs.readBuffer(gl, &pbuffer); | 
|  | 796 | return EGL_TRUE; | 
|  | 797 | } | 
|  | 798 |  | 
|  | 799 | // ---------------------------------------------------------------------------- | 
|  | 800 |  | 
|  | 801 | struct config_pair_t { | 
|  | 802 | GLint key; | 
|  | 803 | GLint value; | 
|  | 804 | }; | 
|  | 805 |  | 
|  | 806 | struct configs_t { | 
|  | 807 | const config_pair_t* array; | 
|  | 808 | int                  size; | 
|  | 809 | }; | 
|  | 810 |  | 
|  | 811 | struct config_management_t { | 
|  | 812 | GLint key; | 
|  | 813 | bool (*match)(GLint reqValue, GLint confValue); | 
|  | 814 | static bool atLeast(GLint reqValue, GLint confValue) { | 
|  | 815 | return (reqValue == EGL_DONT_CARE) || (confValue >= reqValue); | 
|  | 816 | } | 
|  | 817 | static bool exact(GLint reqValue, GLint confValue) { | 
|  | 818 | return (reqValue == EGL_DONT_CARE) || (confValue == reqValue); | 
|  | 819 | } | 
|  | 820 | static bool mask(GLint reqValue, GLint confValue) { | 
|  | 821 | return (confValue & reqValue) == reqValue; | 
|  | 822 | } | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 823 | static bool ignore(GLint /*reqValue*/, GLint /*confValue*/) { | 
| Mathias Agopian | 6397167 | 2010-10-25 15:51:24 -0700 | [diff] [blame] | 824 | return true; | 
|  | 825 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 826 | }; | 
|  | 827 |  | 
|  | 828 | // ---------------------------------------------------------------------------- | 
|  | 829 |  | 
|  | 830 | #define VERSION_MAJOR 1 | 
|  | 831 | #define VERSION_MINOR 2 | 
|  | 832 | static char const * const gVendorString     = "Google Inc."; | 
| Mathias Agopian | 141550b | 2010-10-19 14:47:08 -0700 | [diff] [blame] | 833 | static char const * const gVersionString    = "1.2 Android Driver 1.2.0"; | 
| Mathias Agopian | cc2b156 | 2012-05-21 14:01:37 -0700 | [diff] [blame] | 834 | static char const * const gClientApiString  = "OpenGL_ES"; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 835 | static char const * const gExtensionsString = | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 836 | "EGL_KHR_fence_sync " | 
| Mathias Agopian | e6bf8b3 | 2009-05-06 23:47:08 -0700 | [diff] [blame] | 837 | "EGL_KHR_image_base " | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 838 | // "KHR_image_pixmap " | 
|  | 839 | "EGL_ANDROID_image_native_buffer " | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 840 | "EGL_ANDROID_swap_rectangle " | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 841 | ; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 |  | 
|  | 843 | // ---------------------------------------------------------------------------- | 
|  | 844 |  | 
|  | 845 | struct extention_map_t { | 
|  | 846 | const char * const name; | 
|  | 847 | __eglMustCastToProperFunctionPointerType address; | 
|  | 848 | }; | 
|  | 849 |  | 
|  | 850 | static const extention_map_t gExtentionMap[] = { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 851 | { "glDrawTexsOES", | 
|  | 852 | (__eglMustCastToProperFunctionPointerType)&glDrawTexsOES }, | 
|  | 853 | { "glDrawTexiOES", | 
|  | 854 | (__eglMustCastToProperFunctionPointerType)&glDrawTexiOES }, | 
|  | 855 | { "glDrawTexfOES", | 
|  | 856 | (__eglMustCastToProperFunctionPointerType)&glDrawTexfOES }, | 
|  | 857 | { "glDrawTexxOES", | 
|  | 858 | (__eglMustCastToProperFunctionPointerType)&glDrawTexxOES }, | 
|  | 859 | { "glDrawTexsvOES", | 
|  | 860 | (__eglMustCastToProperFunctionPointerType)&glDrawTexsvOES }, | 
|  | 861 | { "glDrawTexivOES", | 
|  | 862 | (__eglMustCastToProperFunctionPointerType)&glDrawTexivOES }, | 
|  | 863 | { "glDrawTexfvOES", | 
|  | 864 | (__eglMustCastToProperFunctionPointerType)&glDrawTexfvOES }, | 
|  | 865 | { "glDrawTexxvOES", | 
|  | 866 | (__eglMustCastToProperFunctionPointerType)&glDrawTexxvOES }, | 
|  | 867 | { "glQueryMatrixxOES", | 
|  | 868 | (__eglMustCastToProperFunctionPointerType)&glQueryMatrixxOES }, | 
|  | 869 | { "glEGLImageTargetTexture2DOES", | 
|  | 870 | (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetTexture2DOES }, | 
|  | 871 | { "glEGLImageTargetRenderbufferStorageOES", | 
|  | 872 | (__eglMustCastToProperFunctionPointerType)&glEGLImageTargetRenderbufferStorageOES }, | 
|  | 873 | { "glClipPlanef", | 
|  | 874 | (__eglMustCastToProperFunctionPointerType)&glClipPlanef }, | 
|  | 875 | { "glClipPlanex", | 
|  | 876 | (__eglMustCastToProperFunctionPointerType)&glClipPlanex }, | 
|  | 877 | { "glBindBuffer", | 
|  | 878 | (__eglMustCastToProperFunctionPointerType)&glBindBuffer }, | 
|  | 879 | { "glBufferData", | 
|  | 880 | (__eglMustCastToProperFunctionPointerType)&glBufferData }, | 
|  | 881 | { "glBufferSubData", | 
|  | 882 | (__eglMustCastToProperFunctionPointerType)&glBufferSubData }, | 
|  | 883 | { "glDeleteBuffers", | 
|  | 884 | (__eglMustCastToProperFunctionPointerType)&glDeleteBuffers }, | 
|  | 885 | { "glGenBuffers", | 
|  | 886 | (__eglMustCastToProperFunctionPointerType)&glGenBuffers }, | 
| Mathias Agopian | 8d2e83b | 2009-06-24 22:37:39 -0700 | [diff] [blame] | 887 | { "eglCreateImageKHR", | 
|  | 888 | (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, | 
|  | 889 | { "eglDestroyImageKHR", | 
|  | 890 | (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 891 | { "eglCreateSyncKHR", | 
|  | 892 | (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, | 
|  | 893 | { "eglDestroySyncKHR", | 
|  | 894 | (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, | 
|  | 895 | { "eglClientWaitSyncKHR", | 
|  | 896 | (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, | 
|  | 897 | { "eglGetSyncAttribKHR", | 
|  | 898 | (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, | 
| Mathias Agopian | 8d2e83b | 2009-06-24 22:37:39 -0700 | [diff] [blame] | 899 | { "eglSetSwapRectangleANDROID", | 
|  | 900 | (__eglMustCastToProperFunctionPointerType)&eglSetSwapRectangleANDROID }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | }; | 
|  | 902 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 903 | /* | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 904 | * In the lists below, attributes names MUST be sorted. | 
|  | 905 | * Additionally, all configs must be sorted according to | 
|  | 906 | * the EGL specification. | 
|  | 907 | */ | 
|  | 908 |  | 
|  | 909 | static config_pair_t const config_base_attribute_list[] = { | 
|  | 910 | { EGL_STENCIL_SIZE,               0                                 }, | 
|  | 911 | { EGL_CONFIG_CAVEAT,              EGL_SLOW_CONFIG                   }, | 
|  | 912 | { EGL_LEVEL,                      0                                 }, | 
|  | 913 | { EGL_MAX_PBUFFER_HEIGHT,         GGL_MAX_VIEWPORT_DIMS             }, | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 914 | { EGL_MAX_PBUFFER_PIXELS, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 915 | GGL_MAX_VIEWPORT_DIMS*GGL_MAX_VIEWPORT_DIMS                 }, | 
|  | 916 | { EGL_MAX_PBUFFER_WIDTH,          GGL_MAX_VIEWPORT_DIMS             }, | 
|  | 917 | { EGL_NATIVE_RENDERABLE,          EGL_TRUE                          }, | 
|  | 918 | { EGL_NATIVE_VISUAL_ID,           0                                 }, | 
|  | 919 | { EGL_NATIVE_VISUAL_TYPE,         GGL_PIXEL_FORMAT_RGB_565          }, | 
|  | 920 | { EGL_SAMPLES,                    0                                 }, | 
|  | 921 | { EGL_SAMPLE_BUFFERS,             0                                 }, | 
|  | 922 | { EGL_TRANSPARENT_TYPE,           EGL_NONE                          }, | 
|  | 923 | { EGL_TRANSPARENT_BLUE_VALUE,     0                                 }, | 
|  | 924 | { EGL_TRANSPARENT_GREEN_VALUE,    0                                 }, | 
|  | 925 | { EGL_TRANSPARENT_RED_VALUE,      0                                 }, | 
|  | 926 | { EGL_BIND_TO_TEXTURE_RGBA,       EGL_FALSE                         }, | 
|  | 927 | { EGL_BIND_TO_TEXTURE_RGB,        EGL_FALSE                         }, | 
|  | 928 | { EGL_MIN_SWAP_INTERVAL,          1                                 }, | 
| Mathias Agopian | 56fa275 | 2009-09-27 20:18:16 -0700 | [diff] [blame] | 929 | { EGL_MAX_SWAP_INTERVAL,          1                                 }, | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 930 | { EGL_LUMINANCE_SIZE,             0                                 }, | 
|  | 931 | { EGL_ALPHA_MASK_SIZE,            0                                 }, | 
|  | 932 | { EGL_COLOR_BUFFER_TYPE,          EGL_RGB_BUFFER                    }, | 
| Mathias Agopian | 56fa275 | 2009-09-27 20:18:16 -0700 | [diff] [blame] | 933 | { EGL_RENDERABLE_TYPE,            EGL_OPENGL_ES_BIT                 }, | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 934 | { EGL_CONFORMANT,                 0                                 } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | }; | 
|  | 936 |  | 
|  | 937 | // These configs can override the base attribute list | 
|  | 938 | // NOTE: when adding a config here, don't forget to update eglCreate*Surface() | 
|  | 939 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 940 | // 565 configs | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | static config_pair_t const config_0_attribute_list[] = { | 
|  | 942 | { EGL_BUFFER_SIZE,     16 }, | 
|  | 943 | { EGL_ALPHA_SIZE,       0 }, | 
|  | 944 | { EGL_BLUE_SIZE,        5 }, | 
|  | 945 | { EGL_GREEN_SIZE,       6 }, | 
|  | 946 | { EGL_RED_SIZE,         5 }, | 
|  | 947 | { EGL_DEPTH_SIZE,       0 }, | 
|  | 948 | { EGL_CONFIG_ID,        0 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 949 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 950 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 951 | }; | 
|  | 952 |  | 
|  | 953 | static config_pair_t const config_1_attribute_list[] = { | 
|  | 954 | { EGL_BUFFER_SIZE,     16 }, | 
|  | 955 | { EGL_ALPHA_SIZE,       0 }, | 
|  | 956 | { EGL_BLUE_SIZE,        5 }, | 
|  | 957 | { EGL_GREEN_SIZE,       6 }, | 
|  | 958 | { EGL_RED_SIZE,         5 }, | 
|  | 959 | { EGL_DEPTH_SIZE,      16 }, | 
|  | 960 | { EGL_CONFIG_ID,        1 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 961 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGB_565 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 963 | }; | 
|  | 964 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 965 | // RGB 888 configs | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | static config_pair_t const config_2_attribute_list[] = { | 
|  | 967 | { EGL_BUFFER_SIZE,     32 }, | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 968 | { EGL_ALPHA_SIZE,       0 }, | 
|  | 969 | { EGL_BLUE_SIZE,        8 }, | 
|  | 970 | { EGL_GREEN_SIZE,       8 }, | 
|  | 971 | { EGL_RED_SIZE,         8 }, | 
|  | 972 | { EGL_DEPTH_SIZE,       0 }, | 
|  | 973 | { EGL_CONFIG_ID,        6 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 974 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 }, | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 975 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 976 | }; | 
|  | 977 |  | 
|  | 978 | static config_pair_t const config_3_attribute_list[] = { | 
|  | 979 | { EGL_BUFFER_SIZE,     32 }, | 
|  | 980 | { EGL_ALPHA_SIZE,       0 }, | 
|  | 981 | { EGL_BLUE_SIZE,        8 }, | 
|  | 982 | { EGL_GREEN_SIZE,       8 }, | 
|  | 983 | { EGL_RED_SIZE,         8 }, | 
|  | 984 | { EGL_DEPTH_SIZE,      16 }, | 
|  | 985 | { EGL_CONFIG_ID,        7 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 986 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBX_8888 }, | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 987 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 988 | }; | 
|  | 989 |  | 
|  | 990 | // 8888 configs | 
|  | 991 | static config_pair_t const config_4_attribute_list[] = { | 
|  | 992 | { EGL_BUFFER_SIZE,     32 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | { EGL_ALPHA_SIZE,       8 }, | 
|  | 994 | { EGL_BLUE_SIZE,        8 }, | 
|  | 995 | { EGL_GREEN_SIZE,       8 }, | 
|  | 996 | { EGL_RED_SIZE,         8 }, | 
|  | 997 | { EGL_DEPTH_SIZE,       0 }, | 
|  | 998 | { EGL_CONFIG_ID,        2 }, | 
| Mathias Agopian | 6af358e | 2010-10-21 15:58:25 -0700 | [diff] [blame] | 999 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBA_8888 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 1001 | }; | 
|  | 1002 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1003 | static config_pair_t const config_5_attribute_list[] = { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | { EGL_BUFFER_SIZE,     32 }, | 
|  | 1005 | { EGL_ALPHA_SIZE,       8 }, | 
|  | 1006 | { EGL_BLUE_SIZE,        8 }, | 
|  | 1007 | { EGL_GREEN_SIZE,       8 }, | 
|  | 1008 | { EGL_RED_SIZE,         8 }, | 
|  | 1009 | { EGL_DEPTH_SIZE,      16 }, | 
|  | 1010 | { EGL_CONFIG_ID,        3 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 1011 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_RGBA_8888 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 1013 | }; | 
|  | 1014 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1015 | // A8 configs | 
|  | 1016 | static config_pair_t const config_6_attribute_list[] = { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | { EGL_BUFFER_SIZE,      8 }, | 
|  | 1018 | { EGL_ALPHA_SIZE,       8 }, | 
|  | 1019 | { EGL_BLUE_SIZE,        0 }, | 
|  | 1020 | { EGL_GREEN_SIZE,       0 }, | 
|  | 1021 | { EGL_RED_SIZE,         0 }, | 
|  | 1022 | { EGL_DEPTH_SIZE,       0 }, | 
|  | 1023 | { EGL_CONFIG_ID,        4 }, | 
| Mathias Agopian | d8e5ceb | 2010-10-20 17:21:43 -0700 | [diff] [blame] | 1024 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_A_8 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 1026 | }; | 
|  | 1027 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1028 | static config_pair_t const config_7_attribute_list[] = { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1029 | { EGL_BUFFER_SIZE,      8 }, | 
|  | 1030 | { EGL_ALPHA_SIZE,       8 }, | 
|  | 1031 | { EGL_BLUE_SIZE,        0 }, | 
|  | 1032 | { EGL_GREEN_SIZE,       0 }, | 
|  | 1033 | { EGL_RED_SIZE,         0 }, | 
|  | 1034 | { EGL_DEPTH_SIZE,      16 }, | 
|  | 1035 | { EGL_CONFIG_ID,        5 }, | 
| Mathias Agopian | 6af358e | 2010-10-21 15:58:25 -0700 | [diff] [blame] | 1036 | { EGL_NATIVE_VISUAL_ID, GGL_PIXEL_FORMAT_A_8 }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1037 | { EGL_SURFACE_TYPE,     EGL_WINDOW_BIT|EGL_PBUFFER_BIT|EGL_PIXMAP_BIT }, | 
|  | 1038 | }; | 
|  | 1039 |  | 
|  | 1040 | static configs_t const gConfigs[] = { | 
|  | 1041 | { config_0_attribute_list, NELEM(config_0_attribute_list) }, | 
|  | 1042 | { config_1_attribute_list, NELEM(config_1_attribute_list) }, | 
|  | 1043 | { config_2_attribute_list, NELEM(config_2_attribute_list) }, | 
|  | 1044 | { config_3_attribute_list, NELEM(config_3_attribute_list) }, | 
|  | 1045 | { config_4_attribute_list, NELEM(config_4_attribute_list) }, | 
|  | 1046 | { config_5_attribute_list, NELEM(config_5_attribute_list) }, | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1047 | { config_6_attribute_list, NELEM(config_6_attribute_list) }, | 
|  | 1048 | { config_7_attribute_list, NELEM(config_7_attribute_list) }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | }; | 
|  | 1050 |  | 
|  | 1051 | static config_management_t const gConfigManagement[] = { | 
|  | 1052 | { EGL_BUFFER_SIZE,                config_management_t::atLeast }, | 
|  | 1053 | { EGL_ALPHA_SIZE,                 config_management_t::atLeast }, | 
|  | 1054 | { EGL_BLUE_SIZE,                  config_management_t::atLeast }, | 
|  | 1055 | { EGL_GREEN_SIZE,                 config_management_t::atLeast }, | 
|  | 1056 | { EGL_RED_SIZE,                   config_management_t::atLeast }, | 
|  | 1057 | { EGL_DEPTH_SIZE,                 config_management_t::atLeast }, | 
|  | 1058 | { EGL_STENCIL_SIZE,               config_management_t::atLeast }, | 
|  | 1059 | { EGL_CONFIG_CAVEAT,              config_management_t::exact   }, | 
|  | 1060 | { EGL_CONFIG_ID,                  config_management_t::exact   }, | 
|  | 1061 | { EGL_LEVEL,                      config_management_t::exact   }, | 
| Mathias Agopian | 6397167 | 2010-10-25 15:51:24 -0700 | [diff] [blame] | 1062 | { EGL_MAX_PBUFFER_HEIGHT,         config_management_t::ignore   }, | 
|  | 1063 | { EGL_MAX_PBUFFER_PIXELS,         config_management_t::ignore   }, | 
|  | 1064 | { EGL_MAX_PBUFFER_WIDTH,          config_management_t::ignore   }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1065 | { EGL_NATIVE_RENDERABLE,          config_management_t::exact   }, | 
| Mathias Agopian | 6397167 | 2010-10-25 15:51:24 -0700 | [diff] [blame] | 1066 | { EGL_NATIVE_VISUAL_ID,           config_management_t::ignore   }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | { EGL_NATIVE_VISUAL_TYPE,         config_management_t::exact   }, | 
|  | 1068 | { EGL_SAMPLES,                    config_management_t::exact   }, | 
|  | 1069 | { EGL_SAMPLE_BUFFERS,             config_management_t::exact   }, | 
|  | 1070 | { EGL_SURFACE_TYPE,               config_management_t::mask    }, | 
|  | 1071 | { EGL_TRANSPARENT_TYPE,           config_management_t::exact   }, | 
|  | 1072 | { EGL_TRANSPARENT_BLUE_VALUE,     config_management_t::exact   }, | 
|  | 1073 | { EGL_TRANSPARENT_GREEN_VALUE,    config_management_t::exact   }, | 
|  | 1074 | { EGL_TRANSPARENT_RED_VALUE,      config_management_t::exact   }, | 
|  | 1075 | { EGL_BIND_TO_TEXTURE_RGBA,       config_management_t::exact   }, | 
|  | 1076 | { EGL_BIND_TO_TEXTURE_RGB,        config_management_t::exact   }, | 
|  | 1077 | { EGL_MIN_SWAP_INTERVAL,          config_management_t::exact   }, | 
|  | 1078 | { EGL_MAX_SWAP_INTERVAL,          config_management_t::exact   }, | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1079 | { EGL_LUMINANCE_SIZE,             config_management_t::atLeast }, | 
|  | 1080 | { EGL_ALPHA_MASK_SIZE,            config_management_t::atLeast }, | 
|  | 1081 | { EGL_COLOR_BUFFER_TYPE,          config_management_t::exact   }, | 
|  | 1082 | { EGL_RENDERABLE_TYPE,            config_management_t::mask    }, | 
|  | 1083 | { EGL_CONFORMANT,                 config_management_t::mask    } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1084 | }; | 
|  | 1085 |  | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1086 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1087 | static config_pair_t const config_defaults[] = { | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1088 | // attributes that are not specified are simply ignored, if a particular | 
|  | 1089 | // one needs not be ignored, it must be specified here, eg: | 
|  | 1090 | // { EGL_SURFACE_TYPE, EGL_WINDOW_BIT }, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | }; | 
|  | 1092 |  | 
|  | 1093 | // ---------------------------------------------------------------------------- | 
|  | 1094 |  | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1095 | static status_t getConfigFormatInfo(EGLint configID, | 
|  | 1096 | int32_t& pixelFormat, int32_t& depthFormat) | 
|  | 1097 | { | 
|  | 1098 | switch(configID) { | 
|  | 1099 | case 0: | 
|  | 1100 | pixelFormat = GGL_PIXEL_FORMAT_RGB_565; | 
|  | 1101 | depthFormat = 0; | 
|  | 1102 | break; | 
|  | 1103 | case 1: | 
|  | 1104 | pixelFormat = GGL_PIXEL_FORMAT_RGB_565; | 
|  | 1105 | depthFormat = GGL_PIXEL_FORMAT_Z_16; | 
|  | 1106 | break; | 
|  | 1107 | case 2: | 
|  | 1108 | pixelFormat = GGL_PIXEL_FORMAT_RGBX_8888; | 
|  | 1109 | depthFormat = 0; | 
|  | 1110 | break; | 
|  | 1111 | case 3: | 
|  | 1112 | pixelFormat = GGL_PIXEL_FORMAT_RGBX_8888; | 
|  | 1113 | depthFormat = GGL_PIXEL_FORMAT_Z_16; | 
|  | 1114 | break; | 
|  | 1115 | case 4: | 
|  | 1116 | pixelFormat = GGL_PIXEL_FORMAT_RGBA_8888; | 
|  | 1117 | depthFormat = 0; | 
|  | 1118 | break; | 
|  | 1119 | case 5: | 
|  | 1120 | pixelFormat = GGL_PIXEL_FORMAT_RGBA_8888; | 
|  | 1121 | depthFormat = GGL_PIXEL_FORMAT_Z_16; | 
|  | 1122 | break; | 
|  | 1123 | case 6: | 
|  | 1124 | pixelFormat = GGL_PIXEL_FORMAT_A_8; | 
|  | 1125 | depthFormat = 0; | 
|  | 1126 | break; | 
|  | 1127 | case 7: | 
|  | 1128 | pixelFormat = GGL_PIXEL_FORMAT_A_8; | 
|  | 1129 | depthFormat = GGL_PIXEL_FORMAT_Z_16; | 
|  | 1130 | break; | 
|  | 1131 | default: | 
|  | 1132 | return NAME_NOT_FOUND; | 
|  | 1133 | } | 
|  | 1134 | return NO_ERROR; | 
|  | 1135 | } | 
|  | 1136 |  | 
|  | 1137 | // ---------------------------------------------------------------------------- | 
|  | 1138 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | template<typename T> | 
|  | 1140 | static int binarySearch(T const sortedArray[], int first, int last, EGLint key) | 
|  | 1141 | { | 
|  | 1142 | while (first <= last) { | 
|  | 1143 | int mid = (first + last) / 2; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1144 | if (key > sortedArray[mid].key) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | first = mid + 1; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1146 | } else if (key < sortedArray[mid].key) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | last = mid - 1; | 
|  | 1148 | } else { | 
|  | 1149 | return mid; | 
|  | 1150 | } | 
|  | 1151 | } | 
|  | 1152 | return -1; | 
|  | 1153 | } | 
|  | 1154 |  | 
|  | 1155 | static int isAttributeMatching(int i, EGLint attr, EGLint val) | 
|  | 1156 | { | 
|  | 1157 | // look for the attribute in all of our configs | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1158 | config_pair_t const* configFound = gConfigs[i].array; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | int index = binarySearch<config_pair_t>( | 
|  | 1160 | gConfigs[i].array, | 
|  | 1161 | 0, gConfigs[i].size-1, | 
|  | 1162 | attr); | 
|  | 1163 | if (index < 0) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1164 | configFound = config_base_attribute_list; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | index = binarySearch<config_pair_t>( | 
|  | 1166 | config_base_attribute_list, | 
|  | 1167 | 0, NELEM(config_base_attribute_list)-1, | 
|  | 1168 | attr); | 
|  | 1169 | } | 
|  | 1170 | if (index >= 0) { | 
|  | 1171 | // attribute found, check if this config could match | 
|  | 1172 | int cfgMgtIndex = binarySearch<config_management_t>( | 
|  | 1173 | gConfigManagement, | 
|  | 1174 | 0, NELEM(gConfigManagement)-1, | 
|  | 1175 | attr); | 
| Christoffer Gurell | 97640b9 | 2009-10-12 11:57:27 +0200 | [diff] [blame] | 1176 | if (cfgMgtIndex >= 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | bool match = gConfigManagement[cfgMgtIndex].match( | 
|  | 1178 | val, configFound[index].value); | 
|  | 1179 | if (match) { | 
|  | 1180 | // this config matches | 
|  | 1181 | return 1; | 
|  | 1182 | } | 
|  | 1183 | } else { | 
|  | 1184 | // attribute not found. this should NEVER happen. | 
|  | 1185 | } | 
|  | 1186 | } else { | 
|  | 1187 | // error, this attribute doesn't exist | 
|  | 1188 | } | 
|  | 1189 | return 0; | 
|  | 1190 | } | 
|  | 1191 |  | 
|  | 1192 | static int makeCurrent(ogles_context_t* gl) | 
|  | 1193 | { | 
|  | 1194 | ogles_context_t* current = (ogles_context_t*)getGlThreadSpecific(); | 
|  | 1195 | if (gl) { | 
|  | 1196 | egl_context_t* c = egl_context_t::context(gl); | 
|  | 1197 | if (c->flags & egl_context_t::IS_CURRENT) { | 
|  | 1198 | if (current != gl) { | 
|  | 1199 | // it is an error to set a context current, if it's already | 
|  | 1200 | // current to another thread | 
|  | 1201 | return -1; | 
|  | 1202 | } | 
|  | 1203 | } else { | 
|  | 1204 | if (current) { | 
|  | 1205 | // mark the current context as not current, and flush | 
|  | 1206 | glFlush(); | 
|  | 1207 | egl_context_t::context(current)->flags &= ~egl_context_t::IS_CURRENT; | 
|  | 1208 | } | 
|  | 1209 | } | 
|  | 1210 | if (!(c->flags & egl_context_t::IS_CURRENT)) { | 
|  | 1211 | // The context is not current, make it current! | 
|  | 1212 | setGlThreadSpecific(gl); | 
|  | 1213 | c->flags |= egl_context_t::IS_CURRENT; | 
|  | 1214 | } | 
|  | 1215 | } else { | 
|  | 1216 | if (current) { | 
|  | 1217 | // mark the current context as not current, and flush | 
|  | 1218 | glFlush(); | 
|  | 1219 | egl_context_t::context(current)->flags &= ~egl_context_t::IS_CURRENT; | 
|  | 1220 | } | 
|  | 1221 | // this thread has no context attached to it | 
|  | 1222 | setGlThreadSpecific(0); | 
|  | 1223 | } | 
|  | 1224 | return 0; | 
|  | 1225 | } | 
|  | 1226 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1227 | static EGLBoolean getConfigAttrib(EGLDisplay /*dpy*/, EGLConfig config, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | EGLint attribute, EGLint *value) | 
|  | 1229 | { | 
|  | 1230 | size_t numConfigs =  NELEM(gConfigs); | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 1231 | int index = (int)(uintptr_t)config; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1232 | if (uint32_t(index) >= numConfigs) | 
|  | 1233 | return setError(EGL_BAD_CONFIG, EGL_FALSE); | 
|  | 1234 |  | 
|  | 1235 | int attrIndex; | 
|  | 1236 | attrIndex = binarySearch<config_pair_t>( | 
|  | 1237 | gConfigs[index].array, | 
|  | 1238 | 0, gConfigs[index].size-1, | 
|  | 1239 | attribute); | 
|  | 1240 | if (attrIndex>=0) { | 
|  | 1241 | *value = gConfigs[index].array[attrIndex].value; | 
|  | 1242 | return EGL_TRUE; | 
|  | 1243 | } | 
|  | 1244 |  | 
|  | 1245 | attrIndex = binarySearch<config_pair_t>( | 
|  | 1246 | config_base_attribute_list, | 
|  | 1247 | 0, NELEM(config_base_attribute_list)-1, | 
|  | 1248 | attribute); | 
|  | 1249 | if (attrIndex>=0) { | 
|  | 1250 | *value = config_base_attribute_list[attrIndex].value; | 
|  | 1251 | return EGL_TRUE; | 
|  | 1252 | } | 
|  | 1253 | return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | 
|  | 1254 | } | 
|  | 1255 |  | 
|  | 1256 | static EGLSurface createWindowSurface(EGLDisplay dpy, EGLConfig config, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1257 | NativeWindowType window, const EGLint* /*attrib_list*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | { | 
|  | 1259 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1260 | return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 
|  | 1261 | if (window == 0) | 
|  | 1262 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1263 |  | 
|  | 1264 | EGLint surfaceType; | 
|  | 1265 | if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE) | 
|  | 1266 | return EGL_FALSE; | 
|  | 1267 |  | 
|  | 1268 | if (!(surfaceType & EGL_WINDOW_BIT)) | 
|  | 1269 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1270 |  | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 1271 | if (static_cast<ANativeWindow*>(window)->common.magic != | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1272 | ANDROID_NATIVE_WINDOW_MAGIC) { | 
|  | 1273 | return setError(EGL_BAD_NATIVE_WINDOW, EGL_NO_SURFACE); | 
|  | 1274 | } | 
|  | 1275 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1276 | EGLint configID; | 
|  | 1277 | if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE) | 
|  | 1278 | return EGL_FALSE; | 
|  | 1279 |  | 
|  | 1280 | int32_t depthFormat; | 
|  | 1281 | int32_t pixelFormat; | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1282 | if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1283 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1284 | } | 
|  | 1285 |  | 
|  | 1286 | // FIXME: we don't have access to the pixelFormat here just yet. | 
|  | 1287 | // (it's possible that the surface is not fully initialized) | 
|  | 1288 | // maybe this should be done after the page-flip | 
|  | 1289 | //if (EGLint(info.format) != pixelFormat) | 
|  | 1290 | //    return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1291 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1292 | egl_surface_t* surface; | 
|  | 1293 | surface = new egl_window_surface_v2_t(dpy, config, depthFormat, | 
| Dianne Hackborn | 4b5e91e | 2010-06-30 13:56:17 -0700 | [diff] [blame] | 1294 | static_cast<ANativeWindow*>(window)); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1296 | if (!surface->initCheck()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | // there was a problem in the ctor, the error | 
|  | 1298 | // flag has been set. | 
|  | 1299 | delete surface; | 
|  | 1300 | surface = 0; | 
|  | 1301 | } | 
|  | 1302 | return surface; | 
|  | 1303 | } | 
|  | 1304 |  | 
|  | 1305 | static EGLSurface createPixmapSurface(EGLDisplay dpy, EGLConfig config, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1306 | NativePixmapType pixmap, const EGLint* /*attrib_list*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | { | 
|  | 1308 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1309 | return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 
|  | 1310 | if (pixmap == 0) | 
|  | 1311 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1312 |  | 
|  | 1313 | EGLint surfaceType; | 
|  | 1314 | if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE) | 
|  | 1315 | return EGL_FALSE; | 
|  | 1316 |  | 
|  | 1317 | if (!(surfaceType & EGL_PIXMAP_BIT)) | 
|  | 1318 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1319 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1320 | if (static_cast<egl_native_pixmap_t*>(pixmap)->version != | 
|  | 1321 | sizeof(egl_native_pixmap_t)) { | 
|  | 1322 | return setError(EGL_BAD_NATIVE_PIXMAP, EGL_NO_SURFACE); | 
|  | 1323 | } | 
|  | 1324 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | EGLint configID; | 
|  | 1326 | if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE) | 
|  | 1327 | return EGL_FALSE; | 
|  | 1328 |  | 
|  | 1329 | int32_t depthFormat; | 
|  | 1330 | int32_t pixelFormat; | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1331 | if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1333 | } | 
|  | 1334 |  | 
|  | 1335 | if (pixmap->format != pixelFormat) | 
|  | 1336 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1337 |  | 
|  | 1338 | egl_surface_t* surface = | 
|  | 1339 | new egl_pixmap_surface_t(dpy, config, depthFormat, | 
|  | 1340 | static_cast<egl_native_pixmap_t*>(pixmap)); | 
|  | 1341 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1342 | if (!surface->initCheck()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1343 | // there was a problem in the ctor, the error | 
|  | 1344 | // flag has been set. | 
|  | 1345 | delete surface; | 
|  | 1346 | surface = 0; | 
|  | 1347 | } | 
|  | 1348 | return surface; | 
|  | 1349 | } | 
|  | 1350 |  | 
|  | 1351 | static EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config, | 
|  | 1352 | const EGLint *attrib_list) | 
|  | 1353 | { | 
|  | 1354 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1355 | return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 
|  | 1356 |  | 
|  | 1357 | EGLint surfaceType; | 
|  | 1358 | if (getConfigAttrib(dpy, config, EGL_SURFACE_TYPE, &surfaceType) == EGL_FALSE) | 
|  | 1359 | return EGL_FALSE; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1360 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1361 | if (!(surfaceType & EGL_PBUFFER_BIT)) | 
|  | 1362 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1363 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1364 | EGLint configID; | 
|  | 1365 | if (getConfigAttrib(dpy, config, EGL_CONFIG_ID, &configID) == EGL_FALSE) | 
|  | 1366 | return EGL_FALSE; | 
|  | 1367 |  | 
|  | 1368 | int32_t depthFormat; | 
|  | 1369 | int32_t pixelFormat; | 
| Mathias Agopian | 8b6b95a | 2009-11-03 16:17:55 -0800 | [diff] [blame] | 1370 | if (getConfigFormatInfo(configID, pixelFormat, depthFormat) != NO_ERROR) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1371 | return setError(EGL_BAD_MATCH, EGL_NO_SURFACE); | 
|  | 1372 | } | 
|  | 1373 |  | 
|  | 1374 | int32_t w = 0; | 
|  | 1375 | int32_t h = 0; | 
| Jesse Hall | 2e8ca9d | 2015-08-21 07:41:46 -0700 | [diff] [blame] | 1376 | while (attrib_list[0] != EGL_NONE) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1377 | if (attrib_list[0] == EGL_WIDTH)  w = attrib_list[1]; | 
|  | 1378 | if (attrib_list[0] == EGL_HEIGHT) h = attrib_list[1]; | 
|  | 1379 | attrib_list+=2; | 
|  | 1380 | } | 
|  | 1381 |  | 
|  | 1382 | egl_surface_t* surface = | 
|  | 1383 | new egl_pbuffer_surface_t(dpy, config, depthFormat, w, h, pixelFormat); | 
|  | 1384 |  | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1385 | if (!surface->initCheck()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | // there was a problem in the ctor, the error | 
|  | 1387 | // flag has been set. | 
|  | 1388 | delete surface; | 
|  | 1389 | surface = 0; | 
|  | 1390 | } | 
|  | 1391 | return surface; | 
|  | 1392 | } | 
|  | 1393 |  | 
|  | 1394 | // ---------------------------------------------------------------------------- | 
|  | 1395 | }; // namespace android | 
|  | 1396 | // ---------------------------------------------------------------------------- | 
|  | 1397 |  | 
|  | 1398 | using namespace android; | 
|  | 1399 |  | 
|  | 1400 | // ---------------------------------------------------------------------------- | 
|  | 1401 | // Initialization | 
|  | 1402 | // ---------------------------------------------------------------------------- | 
|  | 1403 |  | 
|  | 1404 | EGLDisplay eglGetDisplay(NativeDisplayType display) | 
|  | 1405 | { | 
| Elliott Hughes | 6071da7 | 2015-08-12 15:27:47 -0700 | [diff] [blame] | 1406 | #ifndef __ANDROID__ | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | // this just needs to be done once | 
|  | 1408 | if (gGLKey == -1) { | 
|  | 1409 | pthread_mutex_lock(&gInitMutex); | 
|  | 1410 | if (gGLKey == -1) | 
|  | 1411 | pthread_key_create(&gGLKey, NULL); | 
|  | 1412 | pthread_mutex_unlock(&gInitMutex); | 
|  | 1413 | } | 
|  | 1414 | #endif | 
|  | 1415 | if (display == EGL_DEFAULT_DISPLAY) { | 
|  | 1416 | EGLDisplay dpy = (EGLDisplay)1; | 
|  | 1417 | egl_display_t& d = egl_display_t::get_display(dpy); | 
|  | 1418 | d.type = display; | 
|  | 1419 | return dpy; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1420 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1421 | return EGL_NO_DISPLAY; | 
|  | 1422 | } | 
|  | 1423 |  | 
|  | 1424 | EGLBoolean eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) | 
|  | 1425 | { | 
|  | 1426 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1427 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1428 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1429 | EGLBoolean res = EGL_TRUE; | 
|  | 1430 | egl_display_t& d = egl_display_t::get_display(dpy); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1431 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1432 | if (android_atomic_inc(&d.initialized) == 0) { | 
|  | 1433 | // initialize stuff here if needed | 
|  | 1434 | //pthread_mutex_lock(&gInitMutex); | 
|  | 1435 | //pthread_mutex_unlock(&gInitMutex); | 
|  | 1436 | } | 
|  | 1437 |  | 
|  | 1438 | if (res == EGL_TRUE) { | 
|  | 1439 | if (major != NULL) *major = VERSION_MAJOR; | 
|  | 1440 | if (minor != NULL) *minor = VERSION_MINOR; | 
|  | 1441 | } | 
|  | 1442 | return res; | 
|  | 1443 | } | 
|  | 1444 |  | 
|  | 1445 | EGLBoolean eglTerminate(EGLDisplay dpy) | 
|  | 1446 | { | 
|  | 1447 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1448 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1449 |  | 
|  | 1450 | EGLBoolean res = EGL_TRUE; | 
|  | 1451 | egl_display_t& d = egl_display_t::get_display(dpy); | 
|  | 1452 | if (android_atomic_dec(&d.initialized) == 1) { | 
|  | 1453 | // TODO: destroy all resources (surfaces, contexts, etc...) | 
|  | 1454 | //pthread_mutex_lock(&gInitMutex); | 
|  | 1455 | //pthread_mutex_unlock(&gInitMutex); | 
|  | 1456 | } | 
|  | 1457 | return res; | 
|  | 1458 | } | 
|  | 1459 |  | 
|  | 1460 | // ---------------------------------------------------------------------------- | 
|  | 1461 | // configuration | 
|  | 1462 | // ---------------------------------------------------------------------------- | 
|  | 1463 |  | 
|  | 1464 | EGLBoolean eglGetConfigs(   EGLDisplay dpy, | 
|  | 1465 | EGLConfig *configs, | 
|  | 1466 | EGLint config_size, EGLint *num_config) | 
|  | 1467 | { | 
|  | 1468 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1469 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1470 |  | 
|  | 1471 | GLint numConfigs = NELEM(gConfigs); | 
|  | 1472 | if (!configs) { | 
|  | 1473 | *num_config = numConfigs; | 
|  | 1474 | return EGL_TRUE; | 
|  | 1475 | } | 
|  | 1476 | GLint i; | 
|  | 1477 | for (i=0 ; i<numConfigs && i<config_size ; i++) { | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 1478 | *configs++ = (EGLConfig)(uintptr_t)i; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1479 | } | 
|  | 1480 | *num_config = i; | 
|  | 1481 | return EGL_TRUE; | 
|  | 1482 | } | 
|  | 1483 |  | 
|  | 1484 | EGLBoolean eglChooseConfig( EGLDisplay dpy, const EGLint *attrib_list, | 
|  | 1485 | EGLConfig *configs, EGLint config_size, | 
|  | 1486 | EGLint *num_config) | 
|  | 1487 | { | 
|  | 1488 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1489 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
| Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1490 |  | 
|  | 1491 | if (ggl_unlikely(num_config==0)) { | 
|  | 1492 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 1493 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 |  | 
| Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1495 | if (ggl_unlikely(attrib_list==0)) { | 
| Mathias Agopian | 04aed21 | 2010-05-17 14:45:43 -0700 | [diff] [blame] | 1496 | /* | 
|  | 1497 | * A NULL attrib_list should be treated as though it was an empty | 
|  | 1498 | * one (terminated with EGL_NONE) as defined in | 
|  | 1499 | * section 3.4.1 "Querying Configurations" in the EGL specification. | 
|  | 1500 | */ | 
|  | 1501 | static const EGLint dummy = EGL_NONE; | 
|  | 1502 | attrib_list = &dummy; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1503 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1504 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | int numAttributes = 0; | 
|  | 1506 | int numConfigs =  NELEM(gConfigs); | 
|  | 1507 | uint32_t possibleMatch = (1<<numConfigs)-1; | 
|  | 1508 | while(possibleMatch && *attrib_list != EGL_NONE) { | 
|  | 1509 | numAttributes++; | 
|  | 1510 | EGLint attr = *attrib_list++; | 
|  | 1511 | EGLint val  = *attrib_list++; | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1512 | for (int i=0 ; possibleMatch && i<numConfigs ; i++) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1513 | if (!(possibleMatch & (1<<i))) | 
|  | 1514 | continue; | 
|  | 1515 | if (isAttributeMatching(i, attr, val) == 0) { | 
|  | 1516 | possibleMatch &= ~(1<<i); | 
|  | 1517 | } | 
|  | 1518 | } | 
|  | 1519 | } | 
|  | 1520 |  | 
|  | 1521 | // now, handle the attributes which have a useful default value | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1522 | for (size_t j=0 ; possibleMatch && j<NELEM(config_defaults) ; j++) { | 
|  | 1523 | // see if this attribute was specified, if not, apply its | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | // default value | 
|  | 1525 | if (binarySearch<config_pair_t>( | 
|  | 1526 | (config_pair_t const*)attrib_list, | 
| Mathias Agopian | dacd7a3 | 2009-07-09 17:33:15 -0700 | [diff] [blame] | 1527 | 0, numAttributes-1, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | config_defaults[j].key) < 0) | 
|  | 1529 | { | 
| Mathias Agopian | 0985f6a | 2009-10-19 14:46:27 -0700 | [diff] [blame] | 1530 | for (int i=0 ; possibleMatch && i<numConfigs ; i++) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | if (!(possibleMatch & (1<<i))) | 
|  | 1532 | continue; | 
|  | 1533 | if (isAttributeMatching(i, | 
|  | 1534 | config_defaults[j].key, | 
|  | 1535 | config_defaults[j].value) == 0) | 
|  | 1536 | { | 
|  | 1537 | possibleMatch &= ~(1<<i); | 
|  | 1538 | } | 
|  | 1539 | } | 
|  | 1540 | } | 
|  | 1541 | } | 
|  | 1542 |  | 
|  | 1543 | // return the configurations found | 
|  | 1544 | int n=0; | 
|  | 1545 | if (possibleMatch) { | 
| Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1546 | if (configs) { | 
|  | 1547 | for (int i=0 ; config_size && i<numConfigs ; i++) { | 
|  | 1548 | if (possibleMatch & (1<<i)) { | 
| Colin Cross | 444839b | 2014-01-24 14:35:39 -0800 | [diff] [blame] | 1549 | *configs++ = (EGLConfig)(uintptr_t)i; | 
| Jack Palevich | 749c63d | 2009-03-25 15:12:17 -0700 | [diff] [blame] | 1550 | config_size--; | 
|  | 1551 | n++; | 
|  | 1552 | } | 
|  | 1553 | } | 
|  | 1554 | } else { | 
|  | 1555 | for (int i=0 ; i<numConfigs ; i++) { | 
|  | 1556 | if (possibleMatch & (1<<i)) { | 
|  | 1557 | n++; | 
|  | 1558 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1559 | } | 
|  | 1560 | } | 
|  | 1561 | } | 
|  | 1562 | *num_config = n; | 
|  | 1563 | return EGL_TRUE; | 
|  | 1564 | } | 
|  | 1565 |  | 
|  | 1566 | EGLBoolean eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, | 
|  | 1567 | EGLint attribute, EGLint *value) | 
|  | 1568 | { | 
|  | 1569 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1570 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1571 |  | 
|  | 1572 | return getConfigAttrib(dpy, config, attribute, value); | 
|  | 1573 | } | 
|  | 1574 |  | 
|  | 1575 | // ---------------------------------------------------------------------------- | 
|  | 1576 | // surfaces | 
|  | 1577 | // ---------------------------------------------------------------------------- | 
|  | 1578 |  | 
|  | 1579 | EGLSurface eglCreateWindowSurface(  EGLDisplay dpy, EGLConfig config, | 
|  | 1580 | NativeWindowType window, | 
|  | 1581 | const EGLint *attrib_list) | 
|  | 1582 | { | 
|  | 1583 | return createWindowSurface(dpy, config, window, attrib_list); | 
|  | 1584 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1585 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | EGLSurface eglCreatePixmapSurface(  EGLDisplay dpy, EGLConfig config, | 
|  | 1587 | NativePixmapType pixmap, | 
|  | 1588 | const EGLint *attrib_list) | 
|  | 1589 | { | 
|  | 1590 | return createPixmapSurface(dpy, config, pixmap, attrib_list); | 
|  | 1591 | } | 
|  | 1592 |  | 
|  | 1593 | EGLSurface eglCreatePbufferSurface( EGLDisplay dpy, EGLConfig config, | 
|  | 1594 | const EGLint *attrib_list) | 
|  | 1595 | { | 
|  | 1596 | return createPbufferSurface(dpy, config, attrib_list); | 
|  | 1597 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1598 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1599 | EGLBoolean eglDestroySurface(EGLDisplay dpy, EGLSurface eglSurface) | 
|  | 1600 | { | 
|  | 1601 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1602 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1603 | if (eglSurface != EGL_NO_SURFACE) { | 
|  | 1604 | egl_surface_t* surface( static_cast<egl_surface_t*>(eglSurface) ); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1605 | if (!surface->isValid()) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1606 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
|  | 1607 | if (surface->dpy != dpy) | 
|  | 1608 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1609 | if (surface->ctx) { | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 1610 | // defer disconnect/delete until no longer current | 
|  | 1611 | surface->zombie = true; | 
|  | 1612 | } else { | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1613 | surface->disconnect(); | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 1614 | delete surface; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1615 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1616 | } | 
|  | 1617 | return EGL_TRUE; | 
|  | 1618 | } | 
|  | 1619 |  | 
|  | 1620 | EGLBoolean eglQuerySurface( EGLDisplay dpy, EGLSurface eglSurface, | 
|  | 1621 | EGLint attribute, EGLint *value) | 
|  | 1622 | { | 
|  | 1623 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1624 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1625 | egl_surface_t* surface = static_cast<egl_surface_t*>(eglSurface); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1626 | if (!surface->isValid()) | 
|  | 1627 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1628 | if (surface->dpy != dpy) | 
|  | 1629 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1630 |  | 
|  | 1631 | EGLBoolean ret = EGL_TRUE; | 
|  | 1632 | switch (attribute) { | 
|  | 1633 | case EGL_CONFIG_ID: | 
|  | 1634 | ret = getConfigAttrib(dpy, surface->config, EGL_CONFIG_ID, value); | 
|  | 1635 | break; | 
|  | 1636 | case EGL_WIDTH: | 
|  | 1637 | *value = surface->getWidth(); | 
|  | 1638 | break; | 
|  | 1639 | case EGL_HEIGHT: | 
|  | 1640 | *value = surface->getHeight(); | 
|  | 1641 | break; | 
|  | 1642 | case EGL_LARGEST_PBUFFER: | 
|  | 1643 | // not modified for a window or pixmap surface | 
|  | 1644 | break; | 
|  | 1645 | case EGL_TEXTURE_FORMAT: | 
|  | 1646 | *value = EGL_NO_TEXTURE; | 
|  | 1647 | break; | 
|  | 1648 | case EGL_TEXTURE_TARGET: | 
|  | 1649 | *value = EGL_NO_TEXTURE; | 
|  | 1650 | break; | 
|  | 1651 | case EGL_MIPMAP_TEXTURE: | 
|  | 1652 | *value = EGL_FALSE; | 
|  | 1653 | break; | 
|  | 1654 | case EGL_MIPMAP_LEVEL: | 
|  | 1655 | *value = 0; | 
|  | 1656 | break; | 
|  | 1657 | case EGL_RENDER_BUFFER: | 
|  | 1658 | // TODO: return the real RENDER_BUFFER here | 
|  | 1659 | *value = EGL_BACK_BUFFER; | 
|  | 1660 | break; | 
|  | 1661 | case EGL_HORIZONTAL_RESOLUTION: | 
|  | 1662 | // pixel/mm * EGL_DISPLAY_SCALING | 
|  | 1663 | *value = surface->getHorizontalResolution(); | 
|  | 1664 | break; | 
|  | 1665 | case EGL_VERTICAL_RESOLUTION: | 
|  | 1666 | // pixel/mm * EGL_DISPLAY_SCALING | 
|  | 1667 | *value = surface->getVerticalResolution(); | 
|  | 1668 | break; | 
|  | 1669 | case EGL_PIXEL_ASPECT_RATIO: { | 
|  | 1670 | // w/h * EGL_DISPLAY_SCALING | 
|  | 1671 | int wr = surface->getHorizontalResolution(); | 
|  | 1672 | int hr = surface->getVerticalResolution(); | 
|  | 1673 | *value = (wr * EGL_DISPLAY_SCALING) / hr; | 
|  | 1674 | } break; | 
|  | 1675 | case EGL_SWAP_BEHAVIOR: | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1676 | *value = surface->getSwapBehavior(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | break; | 
|  | 1678 | default: | 
|  | 1679 | ret = setError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | 
|  | 1680 | } | 
|  | 1681 | return ret; | 
|  | 1682 | } | 
|  | 1683 |  | 
|  | 1684 | EGLContext eglCreateContext(EGLDisplay dpy, EGLConfig config, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1685 | EGLContext /*share_list*/, const EGLint* /*attrib_list*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1686 | { | 
|  | 1687 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1688 | return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 
|  | 1689 |  | 
|  | 1690 | ogles_context_t* gl = ogles_init(sizeof(egl_context_t)); | 
|  | 1691 | if (!gl) return setError(EGL_BAD_ALLOC, EGL_NO_CONTEXT); | 
|  | 1692 |  | 
|  | 1693 | egl_context_t* c = static_cast<egl_context_t*>(gl->rasterizer.base); | 
|  | 1694 | c->flags = egl_context_t::NEVER_CURRENT; | 
|  | 1695 | c->dpy = dpy; | 
|  | 1696 | c->config = config; | 
|  | 1697 | c->read = 0; | 
|  | 1698 | c->draw = 0; | 
|  | 1699 | return (EGLContext)gl; | 
|  | 1700 | } | 
|  | 1701 |  | 
|  | 1702 | EGLBoolean eglDestroyContext(EGLDisplay dpy, EGLContext ctx) | 
|  | 1703 | { | 
|  | 1704 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1705 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1706 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1707 | if (c->flags & egl_context_t::IS_CURRENT) | 
|  | 1708 | setGlThreadSpecific(0); | 
|  | 1709 | ogles_uninit((ogles_context_t*)ctx); | 
|  | 1710 | return EGL_TRUE; | 
|  | 1711 | } | 
|  | 1712 |  | 
|  | 1713 | EGLBoolean eglMakeCurrent(  EGLDisplay dpy, EGLSurface draw, | 
|  | 1714 | EGLSurface read, EGLContext ctx) | 
|  | 1715 | { | 
|  | 1716 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1717 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1718 | if (draw) { | 
|  | 1719 | egl_surface_t* s = (egl_surface_t*)draw; | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1720 | if (!s->isValid()) | 
|  | 1721 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | if (s->dpy != dpy) | 
|  | 1723 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1724 | // TODO: check that draw is compatible with the context | 
|  | 1725 | } | 
|  | 1726 | if (read && read!=draw) { | 
|  | 1727 | egl_surface_t* s = (egl_surface_t*)read; | 
|  | 1728 | if (!s->isValid()) | 
|  | 1729 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
|  | 1730 | if (s->dpy != dpy) | 
|  | 1731 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1732 | // TODO: check that read is compatible with the context | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | } | 
|  | 1734 |  | 
|  | 1735 | EGLContext current_ctx = EGL_NO_CONTEXT; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1736 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1737 | if ((read == EGL_NO_SURFACE && draw == EGL_NO_SURFACE) && (ctx != EGL_NO_CONTEXT)) | 
|  | 1738 | return setError(EGL_BAD_MATCH, EGL_FALSE); | 
|  | 1739 |  | 
|  | 1740 | if ((read != EGL_NO_SURFACE || draw != EGL_NO_SURFACE) && (ctx == EGL_NO_CONTEXT)) | 
|  | 1741 | return setError(EGL_BAD_MATCH, EGL_FALSE); | 
|  | 1742 |  | 
|  | 1743 | if (ctx == EGL_NO_CONTEXT) { | 
|  | 1744 | // if we're detaching, we need the current context | 
|  | 1745 | current_ctx = (EGLContext)getGlThreadSpecific(); | 
|  | 1746 | } else { | 
|  | 1747 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1748 | egl_surface_t* d = (egl_surface_t*)draw; | 
|  | 1749 | egl_surface_t* r = (egl_surface_t*)read; | 
|  | 1750 | if ((d && d->ctx && d->ctx != ctx) || | 
|  | 1751 | (r && r->ctx && r->ctx != ctx)) { | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1752 | // one of the surface is bound to a context in another thread | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1753 | return setError(EGL_BAD_ACCESS, EGL_FALSE); | 
|  | 1754 | } | 
|  | 1755 | } | 
|  | 1756 |  | 
|  | 1757 | ogles_context_t* gl = (ogles_context_t*)ctx; | 
|  | 1758 | if (makeCurrent(gl) == 0) { | 
|  | 1759 | if (ctx) { | 
|  | 1760 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1761 | egl_surface_t* d = (egl_surface_t*)draw; | 
|  | 1762 | egl_surface_t* r = (egl_surface_t*)read; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1763 |  | 
|  | 1764 | if (c->draw) { | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1765 | egl_surface_t* s = reinterpret_cast<egl_surface_t*>(c->draw); | 
|  | 1766 | s->disconnect(); | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 1767 | s->ctx = EGL_NO_CONTEXT; | 
|  | 1768 | if (s->zombie) | 
|  | 1769 | delete s; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1770 | } | 
|  | 1771 | if (c->read) { | 
|  | 1772 | // FIXME: unlock/disconnect the read surface too | 
|  | 1773 | } | 
|  | 1774 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1775 | c->draw = draw; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1776 | c->read = read; | 
|  | 1777 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | if (c->flags & egl_context_t::NEVER_CURRENT) { | 
|  | 1779 | c->flags &= ~egl_context_t::NEVER_CURRENT; | 
|  | 1780 | GLint w = 0; | 
|  | 1781 | GLint h = 0; | 
|  | 1782 | if (draw) { | 
|  | 1783 | w = d->getWidth(); | 
|  | 1784 | h = d->getHeight(); | 
|  | 1785 | } | 
|  | 1786 | ogles_surfaceport(gl, 0, 0); | 
|  | 1787 | ogles_viewport(gl, 0, 0, w, h); | 
|  | 1788 | ogles_scissor(gl, 0, 0, w, h); | 
|  | 1789 | } | 
|  | 1790 | if (d) { | 
| Mathias Agopian | cf81c84 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 1791 | if (d->connect() == EGL_FALSE) { | 
|  | 1792 | return EGL_FALSE; | 
|  | 1793 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | d->ctx = ctx; | 
|  | 1795 | d->bindDrawSurface(gl); | 
|  | 1796 | } | 
|  | 1797 | if (r) { | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1798 | // FIXME: lock/connect the read surface too | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | r->ctx = ctx; | 
|  | 1800 | r->bindReadSurface(gl); | 
|  | 1801 | } | 
|  | 1802 | } else { | 
|  | 1803 | // if surfaces were bound to the context bound to this thread | 
|  | 1804 | // mark then as unbound. | 
|  | 1805 | if (current_ctx) { | 
|  | 1806 | egl_context_t* c = egl_context_t::context(current_ctx); | 
|  | 1807 | egl_surface_t* d = (egl_surface_t*)c->draw; | 
|  | 1808 | egl_surface_t* r = (egl_surface_t*)c->read; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1809 | if (d) { | 
| Mathias Agopian | 9648c1a | 2009-06-03 19:00:53 -0700 | [diff] [blame] | 1810 | c->draw = 0; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1811 | d->disconnect(); | 
| Jesse Hall | 78141e3 | 2013-03-07 09:56:26 -0800 | [diff] [blame] | 1812 | d->ctx = EGL_NO_CONTEXT; | 
|  | 1813 | if (d->zombie) | 
|  | 1814 | delete d; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1815 | } | 
|  | 1816 | if (r) { | 
| Mathias Agopian | 9648c1a | 2009-06-03 19:00:53 -0700 | [diff] [blame] | 1817 | c->read = 0; | 
| Mathias Agopian | e71212b | 2009-05-05 00:37:46 -0700 | [diff] [blame] | 1818 | r->ctx = EGL_NO_CONTEXT; | 
|  | 1819 | // FIXME: unlock/disconnect the read surface too | 
|  | 1820 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1821 | } | 
|  | 1822 | } | 
|  | 1823 | return EGL_TRUE; | 
|  | 1824 | } | 
|  | 1825 | return setError(EGL_BAD_ACCESS, EGL_FALSE); | 
|  | 1826 | } | 
|  | 1827 |  | 
|  | 1828 | EGLContext eglGetCurrentContext(void) | 
|  | 1829 | { | 
|  | 1830 | // eglGetCurrentContext returns the current EGL rendering context, | 
|  | 1831 | // as specified by eglMakeCurrent. If no context is current, | 
|  | 1832 | // EGL_NO_CONTEXT is returned. | 
|  | 1833 | return (EGLContext)getGlThreadSpecific(); | 
|  | 1834 | } | 
|  | 1835 |  | 
|  | 1836 | EGLSurface eglGetCurrentSurface(EGLint readdraw) | 
|  | 1837 | { | 
|  | 1838 | // eglGetCurrentSurface returns the read or draw surface attached | 
|  | 1839 | // to the current EGL rendering context, as specified by eglMakeCurrent. | 
|  | 1840 | // If no context is current, EGL_NO_SURFACE is returned. | 
|  | 1841 | EGLContext ctx = (EGLContext)getGlThreadSpecific(); | 
|  | 1842 | if (ctx == EGL_NO_CONTEXT) return EGL_NO_SURFACE; | 
|  | 1843 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1844 | if (readdraw == EGL_READ) { | 
|  | 1845 | return c->read; | 
|  | 1846 | } else if (readdraw == EGL_DRAW) { | 
|  | 1847 | return c->draw; | 
|  | 1848 | } | 
|  | 1849 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); | 
|  | 1850 | } | 
|  | 1851 |  | 
|  | 1852 | EGLDisplay eglGetCurrentDisplay(void) | 
|  | 1853 | { | 
|  | 1854 | // eglGetCurrentDisplay returns the current EGL display connection | 
|  | 1855 | // for the current EGL rendering context, as specified by eglMakeCurrent. | 
|  | 1856 | // If no context is current, EGL_NO_DISPLAY is returned. | 
|  | 1857 | EGLContext ctx = (EGLContext)getGlThreadSpecific(); | 
|  | 1858 | if (ctx == EGL_NO_CONTEXT) return EGL_NO_DISPLAY; | 
|  | 1859 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1860 | return c->dpy; | 
|  | 1861 | } | 
|  | 1862 |  | 
|  | 1863 | EGLBoolean eglQueryContext( EGLDisplay dpy, EGLContext ctx, | 
|  | 1864 | EGLint attribute, EGLint *value) | 
|  | 1865 | { | 
|  | 1866 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1867 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1868 | egl_context_t* c = egl_context_t::context(ctx); | 
|  | 1869 | switch (attribute) { | 
|  | 1870 | case EGL_CONFIG_ID: | 
|  | 1871 | // Returns the ID of the EGL frame buffer configuration with | 
|  | 1872 | // respect to which the context was created | 
|  | 1873 | return getConfigAttrib(dpy, c->config, EGL_CONFIG_ID, value); | 
|  | 1874 | } | 
|  | 1875 | return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | 
|  | 1876 | } | 
|  | 1877 |  | 
|  | 1878 | EGLBoolean eglWaitGL(void) | 
|  | 1879 | { | 
|  | 1880 | return EGL_TRUE; | 
|  | 1881 | } | 
|  | 1882 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1883 | EGLBoolean eglWaitNative(EGLint /*engine*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1884 | { | 
|  | 1885 | return EGL_TRUE; | 
|  | 1886 | } | 
|  | 1887 |  | 
|  | 1888 | EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface draw) | 
|  | 1889 | { | 
|  | 1890 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1891 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1892 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1893 | egl_surface_t* d = static_cast<egl_surface_t*>(draw); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 1894 | if (!d->isValid()) | 
|  | 1895 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | if (d->dpy != dpy) | 
|  | 1897 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1898 |  | 
|  | 1899 | // post the surface | 
|  | 1900 | d->swapBuffers(); | 
|  | 1901 |  | 
|  | 1902 | // if it's bound to a context, update the buffer | 
|  | 1903 | if (d->ctx != EGL_NO_CONTEXT) { | 
|  | 1904 | d->bindDrawSurface((ogles_context_t*)d->ctx); | 
|  | 1905 | // if this surface is also the read surface of the context | 
|  | 1906 | // it is bound to, make sure to update the read buffer as well. | 
|  | 1907 | // The EGL spec is a little unclear about this. | 
|  | 1908 | egl_context_t* c = egl_context_t::context(d->ctx); | 
|  | 1909 | if (c->read == draw) { | 
|  | 1910 | d->bindReadSurface((ogles_context_t*)d->ctx); | 
|  | 1911 | } | 
|  | 1912 | } | 
|  | 1913 |  | 
|  | 1914 | return EGL_TRUE; | 
|  | 1915 | } | 
|  | 1916 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1917 | EGLBoolean eglCopyBuffers(  EGLDisplay dpy, EGLSurface /*surface*/, | 
|  | 1918 | NativePixmapType /*target*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | { | 
|  | 1920 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1921 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1922 | // TODO: eglCopyBuffers() | 
|  | 1923 | return EGL_FALSE; | 
|  | 1924 | } | 
|  | 1925 |  | 
|  | 1926 | EGLint eglGetError(void) | 
|  | 1927 | { | 
|  | 1928 | return getError(); | 
|  | 1929 | } | 
|  | 1930 |  | 
|  | 1931 | const char* eglQueryString(EGLDisplay dpy, EGLint name) | 
|  | 1932 | { | 
|  | 1933 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1934 | return setError(EGL_BAD_DISPLAY, (const char*)0); | 
|  | 1935 |  | 
|  | 1936 | switch (name) { | 
|  | 1937 | case EGL_VENDOR: | 
|  | 1938 | return gVendorString; | 
|  | 1939 | case EGL_VERSION: | 
|  | 1940 | return gVersionString; | 
|  | 1941 | case EGL_EXTENSIONS: | 
|  | 1942 | return gExtensionsString; | 
|  | 1943 | case EGL_CLIENT_APIS: | 
|  | 1944 | return gClientApiString; | 
|  | 1945 | } | 
|  | 1946 | return setError(EGL_BAD_PARAMETER, (const char *)0); | 
|  | 1947 | } | 
|  | 1948 |  | 
|  | 1949 | // ---------------------------------------------------------------------------- | 
|  | 1950 | // EGL 1.1 | 
|  | 1951 | // ---------------------------------------------------------------------------- | 
|  | 1952 |  | 
|  | 1953 | EGLBoolean eglSurfaceAttrib( | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1954 | EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*attribute*/, EGLint /*value*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | { | 
|  | 1956 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1957 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1958 | // TODO: eglSurfaceAttrib() | 
|  | 1959 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 1960 | } | 
|  | 1961 |  | 
|  | 1962 | EGLBoolean eglBindTexImage( | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1963 | EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*buffer*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1964 | { | 
|  | 1965 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1966 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1967 | // TODO: eglBindTexImage() | 
|  | 1968 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 1969 | } | 
|  | 1970 |  | 
|  | 1971 | EGLBoolean eglReleaseTexImage( | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1972 | EGLDisplay dpy, EGLSurface /*surface*/, EGLint /*buffer*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1973 | { | 
|  | 1974 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1975 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1976 | // TODO: eglReleaseTexImage() | 
|  | 1977 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 1978 | } | 
|  | 1979 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 1980 | EGLBoolean eglSwapInterval(EGLDisplay dpy, EGLint /*interval*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1981 | { | 
|  | 1982 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 1983 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 1984 | // TODO: eglSwapInterval() | 
| Ari Hirvonen | 551dc26 | 2010-10-01 19:00:54 +0300 | [diff] [blame] | 1985 | return EGL_TRUE; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1986 | } | 
|  | 1987 |  | 
|  | 1988 | // ---------------------------------------------------------------------------- | 
|  | 1989 | // EGL 1.2 | 
|  | 1990 | // ---------------------------------------------------------------------------- | 
|  | 1991 |  | 
|  | 1992 | EGLBoolean eglBindAPI(EGLenum api) | 
|  | 1993 | { | 
|  | 1994 | if (api != EGL_OPENGL_ES_API) | 
|  | 1995 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 1996 | return EGL_TRUE; | 
|  | 1997 | } | 
|  | 1998 |  | 
|  | 1999 | EGLenum eglQueryAPI(void) | 
|  | 2000 | { | 
|  | 2001 | return EGL_OPENGL_ES_API; | 
|  | 2002 | } | 
|  | 2003 |  | 
|  | 2004 | EGLBoolean eglWaitClient(void) | 
|  | 2005 | { | 
|  | 2006 | glFinish(); | 
|  | 2007 | return EGL_TRUE; | 
|  | 2008 | } | 
|  | 2009 |  | 
|  | 2010 | EGLBoolean eglReleaseThread(void) | 
|  | 2011 | { | 
|  | 2012 | // TODO: eglReleaseThread() | 
|  | 2013 | return EGL_TRUE; | 
|  | 2014 | } | 
|  | 2015 |  | 
|  | 2016 | EGLSurface eglCreatePbufferFromClientBuffer( | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2017 | EGLDisplay dpy, EGLenum /*buftype*/, EGLClientBuffer /*buffer*/, | 
|  | 2018 | EGLConfig /*config*/, const EGLint* /*attrib_list*/) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2019 | { | 
|  | 2020 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 2021 | return setError(EGL_BAD_DISPLAY, EGL_NO_SURFACE); | 
|  | 2022 | // TODO: eglCreatePbufferFromClientBuffer() | 
|  | 2023 | return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); | 
|  | 2024 | } | 
|  | 2025 |  | 
|  | 2026 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2027 | // EGL_EGLEXT_VERSION 3 | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2028 | // ---------------------------------------------------------------------------- | 
|  | 2029 |  | 
|  | 2030 | void (*eglGetProcAddress (const char *procname))() | 
|  | 2031 | { | 
|  | 2032 | extention_map_t const * const map = gExtentionMap; | 
|  | 2033 | for (uint32_t i=0 ; i<NELEM(gExtentionMap) ; i++) { | 
|  | 2034 | if (!strcmp(procname, map[i].name)) { | 
|  | 2035 | return map[i].address; | 
|  | 2036 | } | 
|  | 2037 | } | 
|  | 2038 | return NULL; | 
|  | 2039 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2040 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2041 | EGLBoolean eglLockSurfaceKHR(EGLDisplay /*dpy*/, EGLSurface /*surface*/, | 
|  | 2042 | const EGLint* /*attrib_list*/) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2043 | { | 
|  | 2044 | EGLBoolean result = EGL_FALSE; | 
|  | 2045 | return result; | 
|  | 2046 | } | 
|  | 2047 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2048 | EGLBoolean eglUnlockSurfaceKHR(EGLDisplay /*dpy*/, EGLSurface /*surface*/) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2049 | { | 
|  | 2050 | EGLBoolean result = EGL_FALSE; | 
|  | 2051 | return result; | 
|  | 2052 | } | 
|  | 2053 |  | 
|  | 2054 | EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2055 | EGLClientBuffer buffer, const EGLint* /*attrib_list*/) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2056 | { | 
|  | 2057 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) { | 
|  | 2058 | return setError(EGL_BAD_DISPLAY, EGL_NO_IMAGE_KHR); | 
|  | 2059 | } | 
|  | 2060 | if (ctx != EGL_NO_CONTEXT) { | 
|  | 2061 | return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR); | 
|  | 2062 | } | 
|  | 2063 | if (target != EGL_NATIVE_BUFFER_ANDROID) { | 
|  | 2064 | return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); | 
|  | 2065 | } | 
|  | 2066 |  | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 2067 | ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)buffer; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2068 |  | 
|  | 2069 | if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) | 
|  | 2070 | return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); | 
|  | 2071 |  | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 2072 | if (native_buffer->common.version != sizeof(ANativeWindowBuffer)) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2073 | return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); | 
| Mathias Agopian | 8dccb26 | 2010-02-04 17:04:53 -0800 | [diff] [blame] | 2074 |  | 
|  | 2075 | switch (native_buffer->format) { | 
|  | 2076 | case HAL_PIXEL_FORMAT_RGBA_8888: | 
|  | 2077 | case HAL_PIXEL_FORMAT_RGBX_8888: | 
|  | 2078 | case HAL_PIXEL_FORMAT_RGB_888: | 
|  | 2079 | case HAL_PIXEL_FORMAT_RGB_565: | 
|  | 2080 | case HAL_PIXEL_FORMAT_BGRA_8888: | 
| Mathias Agopian | 8dccb26 | 2010-02-04 17:04:53 -0800 | [diff] [blame] | 2081 | break; | 
|  | 2082 | default: | 
|  | 2083 | return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR); | 
|  | 2084 | } | 
|  | 2085 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2086 | native_buffer->common.incRef(&native_buffer->common); | 
|  | 2087 | return (EGLImageKHR)native_buffer; | 
|  | 2088 | } | 
|  | 2089 |  | 
|  | 2090 | EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img) | 
|  | 2091 | { | 
|  | 2092 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) { | 
|  | 2093 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 2094 | } | 
|  | 2095 |  | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 2096 | ANativeWindowBuffer* native_buffer = (ANativeWindowBuffer*)img; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2097 |  | 
|  | 2098 | if (native_buffer->common.magic != ANDROID_NATIVE_BUFFER_MAGIC) | 
|  | 2099 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 2100 |  | 
| Iliyan Malchev | 697526b | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 2101 | if (native_buffer->common.version != sizeof(ANativeWindowBuffer)) | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2102 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 2103 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 2104 | native_buffer->common.decRef(&native_buffer->common); | 
|  | 2105 |  | 
|  | 2106 | return EGL_TRUE; | 
|  | 2107 | } | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2108 |  | 
|  | 2109 | // ---------------------------------------------------------------------------- | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 2110 | // EGL_KHR_fence_sync | 
|  | 2111 | // ---------------------------------------------------------------------------- | 
|  | 2112 |  | 
|  | 2113 | #define FENCE_SYNC_HANDLE ((EGLSyncKHR)0xFE4CE) | 
|  | 2114 |  | 
|  | 2115 | EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, | 
|  | 2116 | const EGLint *attrib_list) | 
|  | 2117 | { | 
|  | 2118 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) { | 
|  | 2119 | return setError(EGL_BAD_DISPLAY, EGL_NO_SYNC_KHR); | 
|  | 2120 | } | 
|  | 2121 |  | 
|  | 2122 | if (type != EGL_SYNC_FENCE_KHR || | 
|  | 2123 | (attrib_list != NULL && attrib_list[0] != EGL_NONE)) { | 
|  | 2124 | return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SYNC_KHR); | 
|  | 2125 | } | 
|  | 2126 |  | 
|  | 2127 | if (eglGetCurrentContext() == EGL_NO_CONTEXT) { | 
|  | 2128 | return setError(EGL_BAD_MATCH, EGL_NO_SYNC_KHR); | 
|  | 2129 | } | 
|  | 2130 |  | 
|  | 2131 | // AGL is synchronous; nothing to do here. | 
|  | 2132 |  | 
|  | 2133 | return FENCE_SYNC_HANDLE; | 
|  | 2134 | } | 
|  | 2135 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2136 | EGLBoolean eglDestroySyncKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync) | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 2137 | { | 
|  | 2138 | if (sync != FENCE_SYNC_HANDLE) { | 
|  | 2139 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | return EGL_TRUE; | 
|  | 2143 | } | 
|  | 2144 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2145 | EGLint eglClientWaitSyncKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync, EGLint /*flags*/, | 
|  | 2146 | EGLTimeKHR /*timeout*/) | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 2147 | { | 
|  | 2148 | if (sync != FENCE_SYNC_HANDLE) { | 
|  | 2149 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 2150 | } | 
|  | 2151 |  | 
|  | 2152 | return EGL_CONDITION_SATISFIED_KHR; | 
|  | 2153 | } | 
|  | 2154 |  | 
| Mark Salyzyn | 92dc3fc | 2014-03-12 13:12:44 -0700 | [diff] [blame] | 2155 | EGLBoolean eglGetSyncAttribKHR(EGLDisplay /*dpy*/, EGLSyncKHR sync, | 
| Jesse Hall | 83e7c8c | 2012-05-22 10:42:56 -0700 | [diff] [blame] | 2156 | EGLint attribute, EGLint *value) | 
|  | 2157 | { | 
|  | 2158 | if (sync != FENCE_SYNC_HANDLE) { | 
|  | 2159 | return setError(EGL_BAD_PARAMETER, EGL_FALSE); | 
|  | 2160 | } | 
|  | 2161 |  | 
|  | 2162 | switch (attribute) { | 
|  | 2163 | case EGL_SYNC_TYPE_KHR: | 
|  | 2164 | *value = EGL_SYNC_FENCE_KHR; | 
|  | 2165 | return EGL_TRUE; | 
|  | 2166 | case EGL_SYNC_STATUS_KHR: | 
|  | 2167 | *value = EGL_SIGNALED_KHR; | 
|  | 2168 | return EGL_TRUE; | 
|  | 2169 | case EGL_SYNC_CONDITION_KHR: | 
|  | 2170 | *value = EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR; | 
|  | 2171 | return EGL_TRUE; | 
|  | 2172 | default: | 
|  | 2173 | return setError(EGL_BAD_ATTRIBUTE, EGL_FALSE); | 
|  | 2174 | } | 
|  | 2175 | } | 
|  | 2176 |  | 
|  | 2177 | // ---------------------------------------------------------------------------- | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2178 | // ANDROID extensions | 
|  | 2179 | // ---------------------------------------------------------------------------- | 
|  | 2180 |  | 
|  | 2181 | EGLBoolean eglSetSwapRectangleANDROID(EGLDisplay dpy, EGLSurface draw, | 
|  | 2182 | EGLint left, EGLint top, EGLint width, EGLint height) | 
|  | 2183 | { | 
|  | 2184 | if (egl_display_t::is_valid(dpy) == EGL_FALSE) | 
|  | 2185 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 2186 |  | 
|  | 2187 | egl_surface_t* d = static_cast<egl_surface_t*>(draw); | 
| Mathias Agopian | 0696a57 | 2009-08-20 00:12:56 -0700 | [diff] [blame] | 2188 | if (!d->isValid()) | 
|  | 2189 | return setError(EGL_BAD_SURFACE, EGL_FALSE); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 2190 | if (d->dpy != dpy) | 
|  | 2191 | return setError(EGL_BAD_DISPLAY, EGL_FALSE); | 
|  | 2192 |  | 
|  | 2193 | // post the surface | 
|  | 2194 | d->setSwapRectangle(left, top, width, height); | 
|  | 2195 |  | 
|  | 2196 | return EGL_TRUE; | 
|  | 2197 | } |