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