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