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