1518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian/* 2518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Copyright 2007, The Android Open Source Project 3518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 4518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Licensed under the Apache License, Version 2.0 (the "License"); 5518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** you may not use this file except in compliance with the License. 6518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** You may obtain a copy of the License at 7518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 8518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** http://www.apache.org/licenses/LICENSE-2.0 9518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** 10518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** Unless required by applicable law or agreed to in writing, software 11518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** distributed under the License is distributed on an "AS IS" BASIS, 12518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** See the License for the specific language governing permissions and 14518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian ** limitations under the License. 15518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 16518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 17b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall#define __STDC_LIMIT_MACROS 1 18b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall 194b9511c16195a646242eff833b0af212933b6ecaMathias Agopian#include <string.h> 204b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 21aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis#include "egl_cache.h" 22518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_display.h" 23518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_object.h" 24518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_tls.h" 25518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "egl_impl.h" 26518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#include "Loader.h" 277db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian#include <cutils/properties.h> 28518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 29518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 30518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopiannamespace android { 31518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 32518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 334b9511c16195a646242eff833b0af212933b6ecaMathias Agopianstatic char const * const sVendorString = "Android"; 344b9511c16195a646242eff833b0af212933b6ecaMathias Agopianstatic char const * const sVersionString = "1.4 Android META-EGL"; 35cc2b1560e87369676a2d13f17bd1ff4021a91819Mathias Agopianstatic char const * const sClientApiString = "OpenGL_ES"; 364b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 374b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// this is the list of EGL extensions that are exposed to applications 384b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// some of them are mandatory because used by the ANDROID system. 394b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// 404b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// mandatory extensions are required per the CDD and not explicitly 414b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// checked during EGL initialization. the system *assumes* these extensions 424b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// are present. the system may not function properly if some mandatory 434b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// extensions are missing. 444b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// 454b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// NOTE: sExtensionString MUST be have a single space as the last character. 464b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// 474b9511c16195a646242eff833b0af212933b6ecaMathias Agopianstatic char const * const sExtensionString = 484b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_image " // mandatory 494b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_image_base " // mandatory 504b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_image_pixmap " 514b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_gl_texture_2D_image " 524b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_gl_texture_cubemap_image " 534b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_gl_renderbuffer_image " 544b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_KHR_fence_sync " 5509b11432b64d368dee7be69480ab54256058376aJamie Gennis "EGL_EXT_create_context_robustness " 564b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_NV_system_time " 574b9511c16195a646242eff833b0af212933b6ecaMathias Agopian "EGL_ANDROID_image_native_buffer " // mandatory 584b9511c16195a646242eff833b0af212933b6ecaMathias Agopian ; 594b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 604b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// extensions not exposed to applications but used by the ANDROID system 614b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// "EGL_ANDROID_recordable " // mandatory 623ff48e5e69955b37292446c0f2ac98e8238bdacaJamie Gennis// "EGL_ANDROID_framebuffer_target " // mandatory for HWC 1.1 634b9511c16195a646242eff833b0af212933b6ecaMathias Agopian// "EGL_ANDROID_blob_cache " // strongly recommended 64331841b96b92646c93c87627c03f77b892f711cdJamie Gennis// "EGL_ANDROID_native_fence_sync " // strongly recommended 65258385978c517a47626161b1e644c48bcee28de1Jesse Hall// "EGL_IMG_hibernate_process " // optional 664b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 67518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void initEglTraceLevel(); 68b13c78f8520ef5a96effdee977bbacb881236c66Siva Velusamyextern void initEglDebugLevel(); 69518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianextern void setGLHooksThreadSpecific(gl_hooks_t const *value); 70518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 71518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 72518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 73518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; 74518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 75518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t::egl_display_t() : 76a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0) { 77518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 78518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 79518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t::~egl_display_t() { 80518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian magic = 0; 81766010858ea7696d64f1b559413670bdd8627595Jamie Gennis egl_cache_t::get()->terminate(); 82518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 83518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 84518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianegl_display_t* egl_display_t::get(EGLDisplay dpy) { 85518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian uintptr_t index = uintptr_t(dpy)-1U; 86518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return (index >= NUM_DISPLAYS) ? NULL : &sDisplay[index]; 87518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 88518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 89518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopianvoid egl_display_t::addObject(egl_object_t* object) { 90518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 91518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian objects.add(object); 92518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 93518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 945b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopianvoid egl_display_t::removeObject(egl_object_t* object) { 95518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 965b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian objects.remove(object); 97518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 98518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 99f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopianbool egl_display_t::getObject(egl_object_t* object) const { 100518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 1015b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian if (objects.indexOf(object) >= 0) { 102f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian if (object->getDisplay() == this) { 103f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian object->incRef(); 104f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian return true; 105f0480de37492597a5c5cf1e6f8346f1467e3a552Mathias Agopian } 106518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 107518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return false; 108518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 109518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 110518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp) { 111518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (uintptr_t(disp) >= NUM_DISPLAYS) 112518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return NULL; 113518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 114518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return sDisplay[uintptr_t(disp)].getDisplay(disp); 115518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 116518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 117518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) { 118518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 119518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 120518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 121518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get our driver loader 122518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Loader& loader(Loader::getInstance()); 123518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 124ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 125ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && disp.dpy == EGL_NO_DISPLAY) { 126ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay dpy = cnx->egl.eglGetDisplay(display); 127ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.dpy = dpy; 128ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (dpy == EGL_NO_DISPLAY) { 129ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian loader.close(cnx->dso); 130ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->dso = NULL; 131518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 132518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 133518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 134518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGLDisplay(uintptr_t(display) + 1U); 135518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 136518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 137518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { 138518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 139518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 140518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 141518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (refs > 0) { 142518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (major != NULL) 143518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *major = VERSION_MAJOR; 144518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (minor != NULL) 145518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian *minor = VERSION_MINOR; 146518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian refs++; 147518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 148518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 149518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 150518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if EGL_TRACE 151518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 152518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // Called both at early_init time and at this time. (Early_init is pre-zygote, so 153518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // the information from that call may be stale.) 154518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian initEglTraceLevel(); 155b13c78f8520ef5a96effdee977bbacb881236c66Siva Velusamy initEglDebugLevel(); 156518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 157518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 158518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 159518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian setGLHooksThreadSpecific(&gHooksNoContext); 160518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 161518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // initialize each EGL and 162518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // build our own extension string first, based on the extension we know 163518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // and the extension supported by our client implementation 164ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian 165ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 166ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->major = -1; 167ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian cnx->minor = -1; 168ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso) { 169518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 170518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#if defined(ADRENO130) 171518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#warning "Adreno-130 eglInitialize() workaround" 172518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian /* 173518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * The ADRENO 130 driver returns a different EGLDisplay each time 174518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * eglGetDisplay() is called, but also makes the EGLDisplay invalid 175518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * after eglTerminate() has been called, so that eglInitialize() 176518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * cannot be called again. Therefore, we need to make sure to call 177518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian * eglGetDisplay() before calling eglInitialize(); 178518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian */ 179518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (i == IMPL_HARDWARE) { 180ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp[i].dpy = cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY); 181518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 182518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian#endif 183518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 184ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian EGLDisplay idpy = disp.dpy; 185518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { 186ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p", 187ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // idpy, cnx->major, cnx->minor, cnx); 188518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 189518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // display is now initialized 190ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.state = egl_display_t::INITIALIZED; 191518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 192518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // get the query-strings for this display for each implementation 193ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.queryString.vendor = cnx->egl.eglQueryString(idpy, 194518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGL_VENDOR); 195ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.queryString.version = cnx->egl.eglQueryString(idpy, 196518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGL_VERSION); 197ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.queryString.extensions = cnx->egl.eglQueryString(idpy, 198518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGL_EXTENSIONS); 199ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, 200518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGL_CLIENT_APIS); 201518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 202518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } else { 203ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian ALOGW("eglInitialize(%p) failed (%s)", idpy, 204518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian egl_tls_t::egl_strerror(cnx->egl.eglGetError())); 205518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 206518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 207518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 2084b9511c16195a646242eff833b0af212933b6ecaMathias Agopian // the query strings are per-display 2094b9511c16195a646242eff833b0af212933b6ecaMathias Agopian mVendorString.setTo(sVendorString); 2104b9511c16195a646242eff833b0af212933b6ecaMathias Agopian mVersionString.setTo(sVersionString); 2114b9511c16195a646242eff833b0af212933b6ecaMathias Agopian mClientApiString.setTo(sClientApiString); 2124b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 2137773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian // we only add extensions that exist in the implementation 2144b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const* start = sExtensionString; 2154b9511c16195a646242eff833b0af212933b6ecaMathias Agopian char const* end; 2164b9511c16195a646242eff833b0af212933b6ecaMathias Agopian do { 2174b9511c16195a646242eff833b0af212933b6ecaMathias Agopian // find the space separating this extension for the next one 2184b9511c16195a646242eff833b0af212933b6ecaMathias Agopian end = strchr(start, ' '); 2194b9511c16195a646242eff833b0af212933b6ecaMathias Agopian if (end) { 2204b9511c16195a646242eff833b0af212933b6ecaMathias Agopian // length of the extension string 2214b9511c16195a646242eff833b0af212933b6ecaMathias Agopian const size_t len = end - start; 222f3ae82d8134e7f5a2f0432ef809569bfa418883bMathias Agopian if (len) { 223f3ae82d8134e7f5a2f0432ef809569bfa418883bMathias Agopian // NOTE: we could avoid the copy if we had strnstr. 224f3ae82d8134e7f5a2f0432ef809569bfa418883bMathias Agopian const String8 ext(start, len); 225ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // now look for this extension 226ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (disp.queryString.extensions) { 227ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // if we find it, add this extension string to our list 228ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // (and don't forget the space) 229ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian const char* match = strstr(disp.queryString.extensions, ext.string()); 230ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (match && (match[len] == ' ' || match[len] == 0)) { 231ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian mExtensionString.append(start, len+1); 232f3ae82d8134e7f5a2f0432ef809569bfa418883bMathias Agopian } 2334b9511c16195a646242eff833b0af212933b6ecaMathias Agopian } 2344b9511c16195a646242eff833b0af212933b6ecaMathias Agopian } 2354b9511c16195a646242eff833b0af212933b6ecaMathias Agopian // process the next extension string, and skip the space. 2364b9511c16195a646242eff833b0af212933b6ecaMathias Agopian start = end + 1; 2374b9511c16195a646242eff833b0af212933b6ecaMathias Agopian } 2384b9511c16195a646242eff833b0af212933b6ecaMathias Agopian } while (end); 2394b9511c16195a646242eff833b0af212933b6ecaMathias Agopian 240aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis egl_cache_t::get()->initialize(this); 241aca51c06f38155f1435fbc6944d7fc0a9bf1e4e9Jamie Gennis 2427db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian char value[PROPERTY_VALUE_MAX]; 2437db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian property_get("debug.egl.finish", value, "0"); 2447db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian if (atoi(value)) { 2457db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian finishOnSwap = true; 2467db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian } 2477db993a98b9239bd4e384cc4aa128262fe3cf52cMathias Agopian 24828ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis property_get("debug.egl.traceGpuCompletion", value, "0"); 24928ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis if (atoi(value)) { 25028ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis traceGpuCompletion = true; 25128ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis } 25228ef8d7911dbfd1bf8256fb43acba894d87fc07aJamie Gennis 2537773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian refs++; 2547773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (major != NULL) 2557773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *major = VERSION_MAJOR; 2567773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian if (minor != NULL) 2577773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian *minor = VERSION_MINOR; 258a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 259a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mHibernation.setDisplayValid(true); 260a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 2617773c435bc5da8217433e1b242d3a6712a17b5f7Mathias Agopian return EGL_TRUE; 262518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 263518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 264518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias AgopianEGLBoolean egl_display_t::terminate() { 265518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 266518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian Mutex::Autolock _l(lock); 267518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 268518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (refs == 0) { 269fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian /* 270fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian * From the EGL spec (3.2): 271fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian * "Termination of a display that has already been terminated, 272fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian * (...), is allowed, but the only effect of such a call is 273fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian * to return EGL_TRUE (...) 274fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian */ 275fe98127eaaf82686ba750001e2b771abece44e97Mathias Agopian return EGL_TRUE; 276518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 277518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 278518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian // this is specific to Android, display termination is ref-counted. 279518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian if (refs > 1) { 280518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian refs--; 281518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return EGL_TRUE; 282518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 283518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 284518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian EGLBoolean res = EGL_FALSE; 285ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_connection_t* const cnx = &gEGLImpl; 286ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->dso && disp.state == egl_display_t::INITIALIZED) { 287ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) { 288ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian ALOGW("eglTerminate(%p) failed (%s)", disp.dpy, 289ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian egl_tls_t::egl_strerror(cnx->egl.eglGetError())); 290ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian } 291ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian // REVISIT: it's unclear what to do if eglTerminate() fails 292ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.state = egl_display_t::TERMINATED; 293ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian res = EGL_TRUE; 294518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian } 295518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 296a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mHibernation.setDisplayValid(false); 297a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 298a08cf6e3a4ee045608bc8991a779dedb4f281a3fJamie Gennis // Reset the extension string since it will be regenerated if we get 299a08cf6e3a4ee045608bc8991a779dedb4f281a3fJamie Gennis // reinitialized. 300a08cf6e3a4ee045608bc8991a779dedb4f281a3fJamie Gennis mExtensionString.setTo(""); 301a08cf6e3a4ee045608bc8991a779dedb4f281a3fJamie Gennis 3025b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // Mark all objects remaining in the list as terminated, unless 3035b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // there are no reference to them, it which case, we're free to 3045b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // delete them. 3055b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian size_t count = objects.size(); 30632397c1cd3327905173b36baa6fd1c579bc328ffSteve Block ALOGW_IF(count, "eglTerminate() called w/ %d objects remaining", count); 3075b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian for (size_t i=0 ; i<count ; i++) { 3085b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian egl_object_t* o = objects.itemAt(i); 3095b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian o->destroy(); 3105b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian } 3115b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian 3125b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian // this marks all object handles are "terminated" 3135b287a6ea8dfac7ab3e03ae1e98f9e2214cbae09Mathias Agopian objects.clear(); 314518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 315518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian refs--; 316518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian return res; 317518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian} 318518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 319fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopianvoid egl_display_t::loseCurrent(egl_context_t * cur_c) 320fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian{ 321fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (cur_c) { 322a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian egl_display_t* display = cur_c->getDisplay(); 323a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian if (display) { 324a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian display->loseCurrentImpl(cur_c); 325a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } 326a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } 327a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian} 328fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian 329a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopianvoid egl_display_t::loseCurrentImpl(egl_context_t * cur_c) 330a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian{ 331a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // by construction, these are either 0 or valid (possibly terminated) 332a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // it should be impossible for these to be invalid 333a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian ContextRef _cur_c(cur_c); 334a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); 335a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); 336a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 337a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian { // scope for the lock 338a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian Mutex::Autolock _l(lock); 339fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian cur_c->onLooseCurrent(); 340fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian 341fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian } 342a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 343a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // This cannot be called with the lock held because it might end-up 344a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // calling back into EGL (in particular when a surface is destroyed 345a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // it calls ANativeWindow::disconnect 346a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_c.release(); 347a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_r.release(); 348a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_d.release(); 349fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian} 350fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian 351fb87e54a9af8bc5063ca4deebe81d90126992480Mathias AgopianEGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c, 352fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLSurface draw, EGLSurface read, EGLContext ctx, 353fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx) 354fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian{ 355fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian EGLBoolean result; 356a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 357a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // by construction, these are either 0 or valid (possibly terminated) 358a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // it should be impossible for these to be invalid 359a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian ContextRef _cur_c(cur_c); 360a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); 361a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); 362a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 363a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian { // scope for the lock 364a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian Mutex::Autolock _l(lock); 365fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian if (c) { 366a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian result = c->cnx->egl.eglMakeCurrent( 367ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.dpy, impl_draw, impl_read, impl_ctx); 368a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian if (result == EGL_TRUE) { 369a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian c->onMakeCurrent(draw, read); 370258385978c517a47626161b1e644c48bcee28de1Jesse Hall if (!cur_c) { 371a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mHibernation.incWakeCount(HibernationMachine::STRONG); 372258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 373a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } 374a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } else { 375a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian result = cur_c->cnx->egl.eglMakeCurrent( 376ada798b7ca7cabc255aa159964b64975e7fdb2dfMathias Agopian disp.dpy, impl_draw, impl_read, impl_ctx); 377a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian if (result == EGL_TRUE) { 378a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian cur_c->onLooseCurrent(); 379a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mHibernation.decWakeCount(HibernationMachine::STRONG); 380a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } 381fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian } 382fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian } 383a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 384a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian if (result == EGL_TRUE) { 385a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // This cannot be called with the lock held because it might end-up 386a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // calling back into EGL (in particular when a surface is destroyed 387a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian // it calls ANativeWindow::disconnect 388a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_c.release(); 389a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_r.release(); 390a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian _cur_d.release(); 391a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian } 392a4b2c041828d1074dca3b999407e7dd85568c5aaMathias Agopian 393fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian return result; 394fb87e54a9af8bc5063ca4deebe81d90126992480Mathias Agopian} 395518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian 396a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall// ---------------------------------------------------------------------------- 397a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 398a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hallbool egl_display_t::HibernationMachine::incWakeCount(WakeRefStrength strength) { 399a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall Mutex::Autolock _l(mLock); 400b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ALOGE_IF(mWakeCount < 0 || mWakeCount == INT32_MAX, 401b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall "Invalid WakeCount (%d) on enter\n", mWakeCount); 402a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 403b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall mWakeCount++; 404a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall if (strength == STRONG) 405a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mAttemptHibernation = false; 406a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 407258385978c517a47626161b1e644c48bcee28de1Jesse Hall if (CC_UNLIKELY(mHibernating)) { 408258385978c517a47626161b1e644c48bcee28de1Jesse Hall ALOGV("Awakening\n"); 409258385978c517a47626161b1e644c48bcee28de1Jesse Hall egl_connection_t* const cnx = &gEGLImpl; 410a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 411a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall // These conditions should be guaranteed before entering hibernation; 412a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall // we don't want to get into a state where we can't wake up. 413a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall ALOGD_IF(!mDpyValid || !cnx->egl.eglAwakenProcessIMG, 414a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall "Invalid hibernation state, unable to awaken\n"); 415a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 416258385978c517a47626161b1e644c48bcee28de1Jesse Hall if (!cnx->egl.eglAwakenProcessIMG()) { 417258385978c517a47626161b1e644c48bcee28de1Jesse Hall ALOGE("Failed to awaken EGL implementation\n"); 418258385978c517a47626161b1e644c48bcee28de1Jesse Hall return false; 419258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 420258385978c517a47626161b1e644c48bcee28de1Jesse Hall mHibernating = false; 421258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 422b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall return true; 423b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall} 424b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall 425a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hallvoid egl_display_t::HibernationMachine::decWakeCount(WakeRefStrength strength) { 426a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall Mutex::Autolock _l(mLock); 427b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall ALOGE_IF(mWakeCount <= 0, "Invalid WakeCount (%d) on leave\n", mWakeCount); 428a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 429a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mWakeCount--; 430a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall if (strength == STRONG) 431a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mAttemptHibernation = true; 432a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall 433a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall if (mWakeCount == 0 && CC_UNLIKELY(mAttemptHibernation)) { 434258385978c517a47626161b1e644c48bcee28de1Jesse Hall egl_connection_t* const cnx = &gEGLImpl; 435258385978c517a47626161b1e644c48bcee28de1Jesse Hall mAttemptHibernation = false; 436201f3b2da572eb27b9d4b3131e6d8c3c92a13de8Jesse Hall if (mAllowHibernation && mDpyValid && 437a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall cnx->egl.eglHibernateProcessIMG && 438a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall cnx->egl.eglAwakenProcessIMG) { 439258385978c517a47626161b1e644c48bcee28de1Jesse Hall ALOGV("Hibernating\n"); 440258385978c517a47626161b1e644c48bcee28de1Jesse Hall if (!cnx->egl.eglHibernateProcessIMG()) { 441258385978c517a47626161b1e644c48bcee28de1Jesse Hall ALOGE("Failed to hibernate EGL implementation\n"); 442258385978c517a47626161b1e644c48bcee28de1Jesse Hall return; 443258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 444258385978c517a47626161b1e644c48bcee28de1Jesse Hall mHibernating = true; 445258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 446258385978c517a47626161b1e644c48bcee28de1Jesse Hall } 447258385978c517a47626161b1e644c48bcee28de1Jesse Hall} 448258385978c517a47626161b1e644c48bcee28de1Jesse Hall 449a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hallvoid egl_display_t::HibernationMachine::setDisplayValid(bool valid) { 450a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall Mutex::Autolock _l(mLock); 451a0fef1c8bb22443402fb3aeda7ce70f7d5775b0aJesse Hall mDpyValid = valid; 452b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall} 453b29e5e8c2682ae145e8c56d9afb061f8da7f854cJesse Hall 454518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 455518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian}; // namespace android 456518ec112f468eb67bf681b3eec896d7bfb4ff98dMathias Agopian// ---------------------------------------------------------------------------- 457