John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 17 | #include "EglManager.h" |
| 18 | |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 19 | #include "Caches.h" |
| 20 | #include "Properties.h" |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 21 | #include "RenderThread.h" |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 22 | #include "renderstate/RenderState.h" |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 23 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 24 | #include <cutils/log.h> |
| 25 | #include <cutils/properties.h> |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 26 | #include <EGL/eglext.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 27 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 28 | #define PROPERTY_RENDER_DIRTY_REGIONS "debug.hwui.render_dirty_regions" |
| 29 | #define GLES_VERSION 2 |
| 30 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 31 | #define WAIT_FOR_GPU_COMPLETION 0 |
| 32 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 33 | // Android-specific addition that is used to show when frames began in systrace |
| 34 | EGLAPI void EGLAPIENTRY eglBeginFrame(EGLDisplay dpy, EGLSurface surface); |
| 35 | |
| 36 | namespace android { |
| 37 | namespace uirenderer { |
| 38 | namespace renderthread { |
| 39 | |
| 40 | #define ERROR_CASE(x) case x: return #x; |
| 41 | static const char* egl_error_str(EGLint error) { |
| 42 | switch (error) { |
| 43 | ERROR_CASE(EGL_SUCCESS) |
| 44 | ERROR_CASE(EGL_NOT_INITIALIZED) |
| 45 | ERROR_CASE(EGL_BAD_ACCESS) |
| 46 | ERROR_CASE(EGL_BAD_ALLOC) |
| 47 | ERROR_CASE(EGL_BAD_ATTRIBUTE) |
| 48 | ERROR_CASE(EGL_BAD_CONFIG) |
| 49 | ERROR_CASE(EGL_BAD_CONTEXT) |
| 50 | ERROR_CASE(EGL_BAD_CURRENT_SURFACE) |
| 51 | ERROR_CASE(EGL_BAD_DISPLAY) |
| 52 | ERROR_CASE(EGL_BAD_MATCH) |
| 53 | ERROR_CASE(EGL_BAD_NATIVE_PIXMAP) |
| 54 | ERROR_CASE(EGL_BAD_NATIVE_WINDOW) |
| 55 | ERROR_CASE(EGL_BAD_PARAMETER) |
| 56 | ERROR_CASE(EGL_BAD_SURFACE) |
| 57 | ERROR_CASE(EGL_CONTEXT_LOST) |
| 58 | default: |
| 59 | return "Unknown error"; |
| 60 | } |
| 61 | } |
| 62 | static const char* egl_error_str() { |
| 63 | return egl_error_str(eglGetError()); |
| 64 | } |
| 65 | |
| 66 | static bool load_dirty_regions_property() { |
| 67 | char buf[PROPERTY_VALUE_MAX]; |
| 68 | int len = property_get(PROPERTY_RENDER_DIRTY_REGIONS, buf, "true"); |
| 69 | return !strncasecmp("true", buf, len); |
| 70 | } |
| 71 | |
| 72 | EglManager::EglManager(RenderThread& thread) |
| 73 | : mRenderThread(thread) |
| 74 | , mEglDisplay(EGL_NO_DISPLAY) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 75 | , mEglConfig(nullptr) |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 76 | , mEglContext(EGL_NO_CONTEXT) |
| 77 | , mPBufferSurface(EGL_NO_SURFACE) |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 78 | , mAllowPreserveBuffer(load_dirty_regions_property()) |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 79 | , mHasBufferAgeExt(false) |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 80 | , mCurrentSurface(EGL_NO_SURFACE) |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 81 | , mAtlasMap(nullptr) |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 82 | , mAtlasMapSize(0) { |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 83 | mCanSetPreserveBuffer = mAllowPreserveBuffer; |
| 84 | ALOGD("Use EGL_SWAP_BEHAVIOR_PRESERVED: %s", mAllowPreserveBuffer ? "true" : "false"); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void EglManager::initialize() { |
| 88 | if (hasEglContext()) return; |
| 89 | |
John Reck | fbc8df0 | 2014-11-14 16:18:41 -0800 | [diff] [blame] | 90 | ATRACE_NAME("Creating EGLContext"); |
| 91 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 92 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 93 | LOG_ALWAYS_FATAL_IF(mEglDisplay == EGL_NO_DISPLAY, |
| 94 | "Failed to get EGL_DEFAULT_DISPLAY! err=%s", egl_error_str()); |
| 95 | |
| 96 | EGLint major, minor; |
| 97 | LOG_ALWAYS_FATAL_IF(eglInitialize(mEglDisplay, &major, &minor) == EGL_FALSE, |
| 98 | "Failed to initialize display %p! err=%s", mEglDisplay, egl_error_str()); |
| 99 | |
| 100 | ALOGI("Initialized EGL, version %d.%d", (int)major, (int)minor); |
| 101 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 102 | findExtensions(eglQueryString(mEglDisplay, EGL_EXTENSIONS), mEglExtensionList); |
| 103 | mHasBufferAgeExt = hasEglExtension("EGL_EXT_buffer_age"); |
| 104 | |
| 105 | loadConfig(mHasBufferAgeExt); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 106 | createContext(); |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 107 | createPBufferSurface(); |
| 108 | makeCurrent(mPBufferSurface); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 109 | mRenderThread.renderState().onGLContextCreated(); |
| 110 | initAtlas(); |
| 111 | } |
| 112 | |
| 113 | bool EglManager::hasEglContext() { |
| 114 | return mEglDisplay != EGL_NO_DISPLAY; |
| 115 | } |
| 116 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 117 | bool EglManager::hasEglExtension(const char* extension) const { |
| 118 | const std::string s(extension); |
| 119 | return mEglExtensionList.find(s) != mEglExtensionList.end(); |
| 120 | } |
| 121 | |
| 122 | void EglManager::loadConfig(bool useBufferAgeExt) { |
| 123 | EGLint swapBehavior = (!useBufferAgeExt && mCanSetPreserveBuffer) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 124 | EGLint attribs[] = { |
| 125 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 126 | EGL_RED_SIZE, 8, |
| 127 | EGL_GREEN_SIZE, 8, |
| 128 | EGL_BLUE_SIZE, 8, |
| 129 | EGL_ALPHA_SIZE, 8, |
| 130 | EGL_DEPTH_SIZE, 0, |
| 131 | EGL_CONFIG_CAVEAT, EGL_NONE, |
| 132 | EGL_STENCIL_SIZE, Stencil::getStencilSize(), |
| 133 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | swapBehavior, |
| 134 | EGL_NONE |
| 135 | }; |
| 136 | |
| 137 | EGLint num_configs = 1; |
| 138 | if (!eglChooseConfig(mEglDisplay, attribs, &mEglConfig, num_configs, &num_configs) |
| 139 | || num_configs != 1) { |
| 140 | // Failed to get a valid config |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 141 | if (mCanSetPreserveBuffer) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 142 | ALOGW("Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without..."); |
| 143 | // Try again without dirty regions enabled |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 144 | mCanSetPreserveBuffer = false; |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 145 | loadConfig(useBufferAgeExt); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 146 | } else { |
| 147 | LOG_ALWAYS_FATAL("Failed to choose config, error = %s", egl_error_str()); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void EglManager::createContext() { |
| 153 | EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, GLES_VERSION, EGL_NONE }; |
| 154 | mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, attribs); |
| 155 | LOG_ALWAYS_FATAL_IF(mEglContext == EGL_NO_CONTEXT, |
| 156 | "Failed to create context, error = %s", egl_error_str()); |
| 157 | } |
| 158 | |
| 159 | void EglManager::setTextureAtlas(const sp<GraphicBuffer>& buffer, |
| 160 | int64_t* map, size_t mapSize) { |
| 161 | |
| 162 | // Already initialized |
| 163 | if (mAtlasBuffer.get()) { |
| 164 | ALOGW("Multiple calls to setTextureAtlas!"); |
| 165 | delete map; |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | mAtlasBuffer = buffer; |
| 170 | mAtlasMap = map; |
| 171 | mAtlasMapSize = mapSize; |
| 172 | |
| 173 | if (hasEglContext()) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 174 | initAtlas(); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void EglManager::initAtlas() { |
| 179 | if (mAtlasBuffer.get()) { |
John Reck | ebd5261 | 2014-12-10 16:47:36 -0800 | [diff] [blame] | 180 | mRenderThread.renderState().assetAtlas().init(mAtlasBuffer, |
| 181 | mAtlasMap, mAtlasMapSize); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 185 | void EglManager::createPBufferSurface() { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 186 | LOG_ALWAYS_FATAL_IF(mEglDisplay == EGL_NO_DISPLAY, |
| 187 | "usePBufferSurface() called on uninitialized GlobalContext!"); |
| 188 | |
| 189 | if (mPBufferSurface == EGL_NO_SURFACE) { |
| 190 | EGLint attribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE }; |
| 191 | mPBufferSurface = eglCreatePbufferSurface(mEglDisplay, mEglConfig, attribs); |
| 192 | } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | EGLSurface EglManager::createSurface(EGLNativeWindowType window) { |
| 196 | initialize(); |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 197 | EGLSurface surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, window, nullptr); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 198 | LOG_ALWAYS_FATAL_IF(surface == EGL_NO_SURFACE, |
| 199 | "Failed to create EGLSurface for window %p, eglErr = %s", |
| 200 | (void*) window, egl_error_str()); |
| 201 | return surface; |
| 202 | } |
| 203 | |
| 204 | void EglManager::destroySurface(EGLSurface surface) { |
| 205 | if (isCurrent(surface)) { |
| 206 | makeCurrent(EGL_NO_SURFACE); |
| 207 | } |
| 208 | if (!eglDestroySurface(mEglDisplay, surface)) { |
| 209 | ALOGW("Failed to destroy surface %p, error=%s", (void*)surface, egl_error_str()); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void EglManager::destroy() { |
| 214 | if (mEglDisplay == EGL_NO_DISPLAY) return; |
| 215 | |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 216 | mRenderThread.renderState().onGLContextDestroyed(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 217 | eglDestroyContext(mEglDisplay, mEglContext); |
| 218 | eglDestroySurface(mEglDisplay, mPBufferSurface); |
| 219 | eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 220 | eglTerminate(mEglDisplay); |
| 221 | eglReleaseThread(); |
| 222 | |
| 223 | mEglDisplay = EGL_NO_DISPLAY; |
| 224 | mEglContext = EGL_NO_CONTEXT; |
| 225 | mPBufferSurface = EGL_NO_SURFACE; |
| 226 | mCurrentSurface = EGL_NO_SURFACE; |
| 227 | } |
| 228 | |
John Reck | f2dcc2a | 2015-07-16 09:17:59 -0700 | [diff] [blame] | 229 | bool EglManager::makeCurrent(EGLSurface surface, EGLint* errOut) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 230 | if (isCurrent(surface)) return false; |
| 231 | |
| 232 | if (surface == EGL_NO_SURFACE) { |
John Reck | d7db4d7 | 2015-05-20 07:18:55 -0700 | [diff] [blame] | 233 | // Ensure we always have a valid surface & context |
| 234 | surface = mPBufferSurface; |
| 235 | } |
| 236 | if (!eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)) { |
John Reck | f2dcc2a | 2015-07-16 09:17:59 -0700 | [diff] [blame] | 237 | if (errOut) { |
| 238 | *errOut = eglGetError(); |
| 239 | ALOGW("Failed to make current on surface %p, error=%s", |
| 240 | (void*)surface, egl_error_str(*errOut)); |
| 241 | } else { |
| 242 | LOG_ALWAYS_FATAL("Failed to make current on surface %p, error=%s", |
| 243 | (void*)surface, egl_error_str()); |
| 244 | } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 245 | } |
| 246 | mCurrentSurface = surface; |
| 247 | return true; |
| 248 | } |
| 249 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 250 | void EglManager::beginFrame(EGLSurface surface, EGLint* width, EGLint* height, EGLint* framebufferAge) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 251 | LOG_ALWAYS_FATAL_IF(surface == EGL_NO_SURFACE, |
| 252 | "Tried to beginFrame on EGL_NO_SURFACE!"); |
| 253 | makeCurrent(surface); |
| 254 | if (width) { |
| 255 | eglQuerySurface(mEglDisplay, surface, EGL_WIDTH, width); |
| 256 | } |
| 257 | if (height) { |
| 258 | eglQuerySurface(mEglDisplay, surface, EGL_HEIGHT, height); |
| 259 | } |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 260 | if (useBufferAgeExt()) { |
| 261 | eglQuerySurface(mEglDisplay, surface, EGL_BUFFER_AGE_EXT, framebufferAge); |
| 262 | } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 263 | eglBeginFrame(mEglDisplay, surface); |
| 264 | } |
| 265 | |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 266 | bool EglManager::swapBuffers(EGLSurface surface, const SkRect& dirty, |
| 267 | EGLint width, EGLint height) { |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 268 | |
| 269 | #if WAIT_FOR_GPU_COMPLETION |
| 270 | { |
| 271 | ATRACE_NAME("Finishing GPU work"); |
| 272 | fence(); |
| 273 | } |
| 274 | #endif |
| 275 | |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 276 | #ifdef EGL_KHR_swap_buffers_with_damage |
John Reck | 4cd44f8 | 2015-05-27 10:26:10 -0700 | [diff] [blame] | 277 | if (CC_LIKELY(Properties::swapBuffersWithDamage)) { |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 278 | SkIRect idirty; |
| 279 | dirty.roundOut(&idirty); |
| 280 | /* |
| 281 | * EGL_KHR_swap_buffers_with_damage spec states: |
| 282 | * |
| 283 | * The rectangles are specified relative to the bottom-left of the surface |
| 284 | * and the x and y components of each rectangle specify the bottom-left |
| 285 | * position of that rectangle. |
| 286 | * |
| 287 | * HWUI does everything with 0,0 being top-left, so need to map |
| 288 | * the rect |
| 289 | */ |
| 290 | EGLint y = height - (idirty.y() + idirty.height()); |
| 291 | // layout: {x, y, width, height} |
| 292 | EGLint rects[4] = { idirty.x(), y, idirty.width(), idirty.height() }; |
| 293 | EGLint numrects = dirty.isEmpty() ? 0 : 1; |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 294 | eglSwapBuffersWithDamageKHR(mEglDisplay, surface, rects, numrects); |
| 295 | } else { |
| 296 | eglSwapBuffers(mEglDisplay, surface); |
| 297 | } |
| 298 | #else |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 299 | eglSwapBuffers(mEglDisplay, surface); |
John Reck | d04794a | 2015-05-08 10:04:36 -0700 | [diff] [blame] | 300 | #endif |
| 301 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 302 | EGLint err = eglGetError(); |
John Reck | 2cdbc7d | 2014-09-17 16:06:36 -0700 | [diff] [blame] | 303 | if (CC_LIKELY(err == EGL_SUCCESS)) { |
| 304 | return true; |
| 305 | } |
| 306 | if (err == EGL_BAD_SURFACE) { |
| 307 | // For some reason our surface was destroyed out from under us |
| 308 | // This really shouldn't happen, but if it does we can recover easily |
| 309 | // by just not trying to use the surface anymore |
| 310 | ALOGW("swapBuffers encountered EGL_BAD_SURFACE on %p, halting rendering...", surface); |
| 311 | return false; |
| 312 | } |
| 313 | LOG_ALWAYS_FATAL("Encountered EGL error %d %s during rendering", |
| 314 | err, egl_error_str(err)); |
| 315 | // Impossible to hit this, but the compiler doesn't know that |
| 316 | return false; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 319 | bool EglManager::useBufferAgeExt() { |
| 320 | return mAllowPreserveBuffer && mHasBufferAgeExt; |
| 321 | } |
| 322 | |
John Reck | 5515637 | 2015-01-21 07:46:37 -0800 | [diff] [blame] | 323 | void EglManager::fence() { |
| 324 | EGLSyncKHR fence = eglCreateSyncKHR(mEglDisplay, EGL_SYNC_FENCE_KHR, NULL); |
| 325 | eglClientWaitSyncKHR(mEglDisplay, fence, |
| 326 | EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, EGL_FOREVER_KHR); |
| 327 | eglDestroySyncKHR(mEglDisplay, fence); |
| 328 | } |
| 329 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 330 | bool EglManager::setPreserveBuffer(EGLSurface surface, bool preserve) { |
| 331 | if (CC_UNLIKELY(!mAllowPreserveBuffer)) return false; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 332 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 333 | // Use EGL_EXT_buffer_age instead if supported |
| 334 | if (mHasBufferAgeExt) return true; |
| 335 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 336 | bool preserved = false; |
| 337 | if (mCanSetPreserveBuffer) { |
| 338 | preserved = eglSurfaceAttrib(mEglDisplay, surface, EGL_SWAP_BEHAVIOR, |
| 339 | preserve ? EGL_BUFFER_PRESERVED : EGL_BUFFER_DESTROYED); |
| 340 | if (CC_UNLIKELY(!preserved)) { |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 341 | ALOGW("Failed to set EGL_SWAP_BEHAVIOR on surface %p, error=%s", |
| 342 | (void*) surface, egl_error_str()); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 343 | } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 344 | } |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 345 | if (CC_UNLIKELY(!preserved)) { |
| 346 | // Maybe it's already set? |
| 347 | EGLint swapBehavior; |
| 348 | if (eglQuerySurface(mEglDisplay, surface, EGL_SWAP_BEHAVIOR, &swapBehavior)) { |
| 349 | preserved = (swapBehavior == EGL_BUFFER_PRESERVED); |
| 350 | } else { |
| 351 | ALOGW("Failed to query EGL_SWAP_BEHAVIOR on surface %p, error=%p", |
| 352 | (void*) surface, egl_error_str()); |
| 353 | } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 354 | } |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 355 | |
| 356 | return preserved; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Season Li | 13d1b4a | 2015-07-29 17:16:19 -0700 | [diff] [blame] | 359 | void EglManager::findExtensions(const char* extensions, std::set<std::string>& list) const { |
| 360 | const char* current = extensions; |
| 361 | const char* head = current; |
| 362 | do { |
| 363 | head = strchr(current, ' '); |
| 364 | std::string s(current, head ? head - current : strlen(current)); |
| 365 | if (s.length()) { |
| 366 | list.insert(s); |
| 367 | } |
| 368 | current = head + 1; |
| 369 | } while (head); |
| 370 | } |
| 371 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 372 | } /* namespace renderthread */ |
| 373 | } /* namespace uirenderer */ |
| 374 | } /* namespace android */ |