2011-05-13 23:21:08 +00:00
|
|
|
/*
|
|
|
|
** Copyright 2007, The Android Open Source Project
|
|
|
|
**
|
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
|
|
|
**
|
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
**
|
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-04-04 23:53:42 +00:00
|
|
|
#define __STDC_LIMIT_MACROS 1
|
|
|
|
|
2011-11-14 07:52:47 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-11-04 00:42:43 +00:00
|
|
|
#include "egl_cache.h"
|
2011-05-13 23:21:08 +00:00
|
|
|
#include "egl_display.h"
|
|
|
|
#include "egl_object.h"
|
|
|
|
#include "egl_tls.h"
|
|
|
|
#include "egl_impl.h"
|
|
|
|
#include "Loader.h"
|
2012-03-25 07:49:46 +00:00
|
|
|
#include <cutils/properties.h>
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
namespace android {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-11-14 07:52:47 +00:00
|
|
|
static char const * const sVendorString = "Android";
|
|
|
|
static char const * const sVersionString = "1.4 Android META-EGL";
|
2012-05-21 21:01:37 +00:00
|
|
|
static char const * const sClientApiString = "OpenGL_ES";
|
2011-11-14 07:52:47 +00:00
|
|
|
|
|
|
|
// this is the list of EGL extensions that are exposed to applications
|
|
|
|
// some of them are mandatory because used by the ANDROID system.
|
|
|
|
//
|
|
|
|
// mandatory extensions are required per the CDD and not explicitly
|
|
|
|
// checked during EGL initialization. the system *assumes* these extensions
|
|
|
|
// are present. the system may not function properly if some mandatory
|
|
|
|
// extensions are missing.
|
|
|
|
//
|
|
|
|
// NOTE: sExtensionString MUST be have a single space as the last character.
|
|
|
|
//
|
|
|
|
static char const * const sExtensionString =
|
|
|
|
"EGL_KHR_image " // mandatory
|
|
|
|
"EGL_KHR_image_base " // mandatory
|
|
|
|
"EGL_KHR_image_pixmap "
|
|
|
|
"EGL_KHR_gl_texture_2D_image "
|
|
|
|
"EGL_KHR_gl_texture_cubemap_image "
|
|
|
|
"EGL_KHR_gl_renderbuffer_image "
|
|
|
|
"EGL_KHR_fence_sync "
|
|
|
|
"EGL_NV_system_time "
|
|
|
|
"EGL_ANDROID_image_native_buffer " // mandatory
|
|
|
|
;
|
|
|
|
|
|
|
|
// extensions not exposed to applications but used by the ANDROID system
|
|
|
|
// "EGL_ANDROID_recordable " // mandatory
|
|
|
|
// "EGL_ANDROID_blob_cache " // strongly recommended
|
2012-09-06 21:52:00 +00:00
|
|
|
// "EGL_ANDROID_native_fence_sync " // strongly recommended
|
2012-04-05 22:53:28 +00:00
|
|
|
// "EGL_IMG_hibernate_process " // optional
|
2011-11-14 07:52:47 +00:00
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
extern void initEglTraceLevel();
|
2012-03-09 22:51:28 +00:00
|
|
|
extern void initEglDebugLevel();
|
2011-05-13 23:21:08 +00:00
|
|
|
extern void setGLHooksThreadSpecific(gl_hooks_t const *value);
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS];
|
|
|
|
|
|
|
|
egl_display_t::egl_display_t() :
|
2012-04-17 19:02:26 +00:00
|
|
|
magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0) {
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
egl_display_t::~egl_display_t() {
|
|
|
|
magic = 0;
|
2011-11-06 22:14:33 +00:00
|
|
|
egl_cache_t::get()->terminate();
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
egl_display_t* egl_display_t::get(EGLDisplay dpy) {
|
|
|
|
uintptr_t index = uintptr_t(dpy)-1U;
|
|
|
|
return (index >= NUM_DISPLAYS) ? NULL : &sDisplay[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void egl_display_t::addObject(egl_object_t* object) {
|
|
|
|
Mutex::Autolock _l(lock);
|
|
|
|
objects.add(object);
|
|
|
|
}
|
|
|
|
|
2011-05-17 01:58:55 +00:00
|
|
|
void egl_display_t::removeObject(egl_object_t* object) {
|
2011-05-13 23:21:08 +00:00
|
|
|
Mutex::Autolock _l(lock);
|
2011-05-17 01:58:55 +00:00
|
|
|
objects.remove(object);
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 04:50:07 +00:00
|
|
|
bool egl_display_t::getObject(egl_object_t* object) const {
|
2011-05-13 23:21:08 +00:00
|
|
|
Mutex::Autolock _l(lock);
|
2011-05-17 01:58:55 +00:00
|
|
|
if (objects.indexOf(object) >= 0) {
|
2011-11-14 04:50:07 +00:00
|
|
|
if (object->getDisplay() == this) {
|
|
|
|
object->incRef();
|
|
|
|
return true;
|
|
|
|
}
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp) {
|
|
|
|
if (uintptr_t(disp) >= NUM_DISPLAYS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return sDisplay[uintptr_t(disp)].getDisplay(disp);
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) {
|
|
|
|
|
|
|
|
Mutex::Autolock _l(lock);
|
|
|
|
|
|
|
|
// get our driver loader
|
|
|
|
Loader& loader(Loader::getInstance());
|
|
|
|
|
2012-02-14 01:09:30 +00:00
|
|
|
egl_connection_t* const cnx = &gEGLImpl;
|
|
|
|
if (cnx->dso && disp.dpy == EGL_NO_DISPLAY) {
|
|
|
|
EGLDisplay dpy = cnx->egl.eglGetDisplay(display);
|
|
|
|
disp.dpy = dpy;
|
|
|
|
if (dpy == EGL_NO_DISPLAY) {
|
|
|
|
loader.close(cnx->dso);
|
|
|
|
cnx->dso = NULL;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EGLDisplay(uintptr_t(display) + 1U);
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
|
|
|
|
|
|
|
|
Mutex::Autolock _l(lock);
|
|
|
|
|
|
|
|
if (refs > 0) {
|
|
|
|
if (major != NULL)
|
|
|
|
*major = VERSION_MAJOR;
|
|
|
|
if (minor != NULL)
|
|
|
|
*minor = VERSION_MINOR;
|
|
|
|
refs++;
|
|
|
|
return EGL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if EGL_TRACE
|
|
|
|
|
|
|
|
// Called both at early_init time and at this time. (Early_init is pre-zygote, so
|
|
|
|
// the information from that call may be stale.)
|
|
|
|
initEglTraceLevel();
|
2012-03-09 22:51:28 +00:00
|
|
|
initEglDebugLevel();
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setGLHooksThreadSpecific(&gHooksNoContext);
|
|
|
|
|
|
|
|
// initialize each EGL and
|
|
|
|
// build our own extension string first, based on the extension we know
|
|
|
|
// and the extension supported by our client implementation
|
2012-02-14 01:09:30 +00:00
|
|
|
|
|
|
|
egl_connection_t* const cnx = &gEGLImpl;
|
|
|
|
cnx->major = -1;
|
|
|
|
cnx->minor = -1;
|
|
|
|
if (cnx->dso) {
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
#if defined(ADRENO130)
|
|
|
|
#warning "Adreno-130 eglInitialize() workaround"
|
|
|
|
/*
|
|
|
|
* The ADRENO 130 driver returns a different EGLDisplay each time
|
|
|
|
* eglGetDisplay() is called, but also makes the EGLDisplay invalid
|
|
|
|
* after eglTerminate() has been called, so that eglInitialize()
|
|
|
|
* cannot be called again. Therefore, we need to make sure to call
|
|
|
|
* eglGetDisplay() before calling eglInitialize();
|
|
|
|
*/
|
|
|
|
if (i == IMPL_HARDWARE) {
|
2012-02-14 01:09:30 +00:00
|
|
|
disp[i].dpy = cnx->egl.eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-14 01:09:30 +00:00
|
|
|
EGLDisplay idpy = disp.dpy;
|
2011-05-13 23:21:08 +00:00
|
|
|
if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) {
|
2012-02-14 01:09:30 +00:00
|
|
|
//ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p",
|
|
|
|
// idpy, cnx->major, cnx->minor, cnx);
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
// display is now initialized
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.state = egl_display_t::INITIALIZED;
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
// get the query-strings for this display for each implementation
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.queryString.vendor = cnx->egl.eglQueryString(idpy,
|
2011-05-13 23:21:08 +00:00
|
|
|
EGL_VENDOR);
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.queryString.version = cnx->egl.eglQueryString(idpy,
|
2011-05-13 23:21:08 +00:00
|
|
|
EGL_VERSION);
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.queryString.extensions = cnx->egl.eglQueryString(idpy,
|
2011-05-13 23:21:08 +00:00
|
|
|
EGL_EXTENSIONS);
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.queryString.clientApi = cnx->egl.eglQueryString(idpy,
|
2011-05-13 23:21:08 +00:00
|
|
|
EGL_CLIENT_APIS);
|
|
|
|
|
|
|
|
} else {
|
2012-02-14 01:09:30 +00:00
|
|
|
ALOGW("eglInitialize(%p) failed (%s)", idpy,
|
2011-05-13 23:21:08 +00:00
|
|
|
egl_tls_t::egl_strerror(cnx->egl.eglGetError()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 07:52:47 +00:00
|
|
|
// the query strings are per-display
|
|
|
|
mVendorString.setTo(sVendorString);
|
|
|
|
mVersionString.setTo(sVersionString);
|
|
|
|
mClientApiString.setTo(sClientApiString);
|
|
|
|
|
2012-02-14 04:06:08 +00:00
|
|
|
// we only add extensions that exist in the implementation
|
2011-11-14 07:52:47 +00:00
|
|
|
char const* start = sExtensionString;
|
|
|
|
char const* end;
|
|
|
|
do {
|
|
|
|
// find the space separating this extension for the next one
|
|
|
|
end = strchr(start, ' ');
|
|
|
|
if (end) {
|
|
|
|
// length of the extension string
|
|
|
|
const size_t len = end - start;
|
2011-11-17 00:49:25 +00:00
|
|
|
if (len) {
|
|
|
|
// NOTE: we could avoid the copy if we had strnstr.
|
|
|
|
const String8 ext(start, len);
|
2012-02-14 01:09:30 +00:00
|
|
|
// now look for this extension
|
|
|
|
if (disp.queryString.extensions) {
|
|
|
|
// if we find it, add this extension string to our list
|
|
|
|
// (and don't forget the space)
|
|
|
|
const char* match = strstr(disp.queryString.extensions, ext.string());
|
|
|
|
if (match && (match[len] == ' ' || match[len] == 0)) {
|
|
|
|
mExtensionString.append(start, len+1);
|
2011-11-17 00:49:25 +00:00
|
|
|
}
|
2011-11-14 07:52:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// process the next extension string, and skip the space.
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
} while (end);
|
|
|
|
|
2011-11-04 00:42:43 +00:00
|
|
|
egl_cache_t::get()->initialize(this);
|
|
|
|
|
2012-03-25 07:49:46 +00:00
|
|
|
char value[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("debug.egl.finish", value, "0");
|
|
|
|
if (atoi(value)) {
|
|
|
|
finishOnSwap = true;
|
|
|
|
}
|
|
|
|
|
2012-04-06 03:34:54 +00:00
|
|
|
property_get("debug.egl.traceGpuCompletion", value, "0");
|
|
|
|
if (atoi(value)) {
|
|
|
|
traceGpuCompletion = true;
|
|
|
|
}
|
|
|
|
|
2012-02-14 04:06:08 +00:00
|
|
|
refs++;
|
|
|
|
if (major != NULL)
|
|
|
|
*major = VERSION_MAJOR;
|
|
|
|
if (minor != NULL)
|
|
|
|
*minor = VERSION_MINOR;
|
2012-04-17 19:02:26 +00:00
|
|
|
|
|
|
|
mHibernation.setDisplayValid(true);
|
|
|
|
|
2012-02-14 04:06:08 +00:00
|
|
|
return EGL_TRUE;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EGLBoolean egl_display_t::terminate() {
|
|
|
|
|
|
|
|
Mutex::Autolock _l(lock);
|
|
|
|
|
|
|
|
if (refs == 0) {
|
2012-06-13 22:21:21 +00:00
|
|
|
/*
|
|
|
|
* From the EGL spec (3.2):
|
|
|
|
* "Termination of a display that has already been terminated,
|
|
|
|
* (...), is allowed, but the only effect of such a call is
|
|
|
|
* to return EGL_TRUE (...)
|
|
|
|
*/
|
|
|
|
return EGL_TRUE;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// this is specific to Android, display termination is ref-counted.
|
|
|
|
if (refs > 1) {
|
|
|
|
refs--;
|
|
|
|
return EGL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLBoolean res = EGL_FALSE;
|
2012-02-14 01:09:30 +00:00
|
|
|
egl_connection_t* const cnx = &gEGLImpl;
|
|
|
|
if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
|
|
|
|
if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {
|
|
|
|
ALOGW("eglTerminate(%p) failed (%s)", disp.dpy,
|
|
|
|
egl_tls_t::egl_strerror(cnx->egl.eglGetError()));
|
|
|
|
}
|
|
|
|
// REVISIT: it's unclear what to do if eglTerminate() fails
|
|
|
|
disp.state = egl_display_t::TERMINATED;
|
|
|
|
res = EGL_TRUE;
|
2011-05-13 23:21:08 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 19:02:26 +00:00
|
|
|
mHibernation.setDisplayValid(false);
|
|
|
|
|
2011-05-17 01:58:55 +00:00
|
|
|
// Mark all objects remaining in the list as terminated, unless
|
|
|
|
// there are no reference to them, it which case, we're free to
|
|
|
|
// delete them.
|
|
|
|
size_t count = objects.size();
|
2012-01-05 23:22:43 +00:00
|
|
|
ALOGW_IF(count, "eglTerminate() called w/ %d objects remaining", count);
|
2011-05-17 01:58:55 +00:00
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
egl_object_t* o = objects.itemAt(i);
|
|
|
|
o->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this marks all object handles are "terminated"
|
|
|
|
objects.clear();
|
2011-05-13 23:21:08 +00:00
|
|
|
|
|
|
|
refs--;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-01-31 02:20:52 +00:00
|
|
|
void egl_display_t::loseCurrent(egl_context_t * cur_c)
|
|
|
|
{
|
|
|
|
if (cur_c) {
|
2012-02-03 23:24:51 +00:00
|
|
|
egl_display_t* display = cur_c->getDisplay();
|
|
|
|
if (display) {
|
|
|
|
display->loseCurrentImpl(cur_c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 02:20:52 +00:00
|
|
|
|
2012-02-03 23:24:51 +00:00
|
|
|
void egl_display_t::loseCurrentImpl(egl_context_t * cur_c)
|
|
|
|
{
|
|
|
|
// by construction, these are either 0 or valid (possibly terminated)
|
|
|
|
// it should be impossible for these to be invalid
|
|
|
|
ContextRef _cur_c(cur_c);
|
|
|
|
SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL);
|
|
|
|
SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);
|
|
|
|
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(lock);
|
2012-01-31 02:20:52 +00:00
|
|
|
cur_c->onLooseCurrent();
|
|
|
|
|
|
|
|
}
|
2012-02-03 23:24:51 +00:00
|
|
|
|
|
|
|
// This cannot be called with the lock held because it might end-up
|
|
|
|
// calling back into EGL (in particular when a surface is destroyed
|
|
|
|
// it calls ANativeWindow::disconnect
|
|
|
|
_cur_c.release();
|
|
|
|
_cur_r.release();
|
|
|
|
_cur_d.release();
|
2012-01-31 02:20:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c,
|
|
|
|
EGLSurface draw, EGLSurface read, EGLContext ctx,
|
|
|
|
EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx)
|
|
|
|
{
|
|
|
|
EGLBoolean result;
|
2012-02-03 23:24:51 +00:00
|
|
|
|
|
|
|
// by construction, these are either 0 or valid (possibly terminated)
|
|
|
|
// it should be impossible for these to be invalid
|
|
|
|
ContextRef _cur_c(cur_c);
|
|
|
|
SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL);
|
|
|
|
SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);
|
|
|
|
|
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock _l(lock);
|
2012-01-31 02:20:52 +00:00
|
|
|
if (c) {
|
2012-02-03 23:24:51 +00:00
|
|
|
result = c->cnx->egl.eglMakeCurrent(
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.dpy, impl_draw, impl_read, impl_ctx);
|
2012-02-03 23:24:51 +00:00
|
|
|
if (result == EGL_TRUE) {
|
|
|
|
c->onMakeCurrent(draw, read);
|
2012-04-05 22:53:28 +00:00
|
|
|
if (!cur_c) {
|
2012-04-17 19:02:26 +00:00
|
|
|
mHibernation.incWakeCount(HibernationMachine::STRONG);
|
2012-04-05 22:53:28 +00:00
|
|
|
}
|
2012-02-03 23:24:51 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = cur_c->cnx->egl.eglMakeCurrent(
|
2012-02-14 01:09:30 +00:00
|
|
|
disp.dpy, impl_draw, impl_read, impl_ctx);
|
2012-02-03 23:24:51 +00:00
|
|
|
if (result == EGL_TRUE) {
|
|
|
|
cur_c->onLooseCurrent();
|
2012-04-17 19:02:26 +00:00
|
|
|
mHibernation.decWakeCount(HibernationMachine::STRONG);
|
2012-02-03 23:24:51 +00:00
|
|
|
}
|
2012-01-31 02:20:52 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 23:24:51 +00:00
|
|
|
|
|
|
|
if (result == EGL_TRUE) {
|
|
|
|
// This cannot be called with the lock held because it might end-up
|
|
|
|
// calling back into EGL (in particular when a surface is destroyed
|
|
|
|
// it calls ANativeWindow::disconnect
|
|
|
|
_cur_c.release();
|
|
|
|
_cur_r.release();
|
|
|
|
_cur_d.release();
|
|
|
|
}
|
|
|
|
|
2012-01-31 02:20:52 +00:00
|
|
|
return result;
|
|
|
|
}
|
2011-05-13 23:21:08 +00:00
|
|
|
|
2012-04-17 19:02:26 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool egl_display_t::HibernationMachine::incWakeCount(WakeRefStrength strength) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
2012-04-04 23:53:42 +00:00
|
|
|
ALOGE_IF(mWakeCount < 0 || mWakeCount == INT32_MAX,
|
|
|
|
"Invalid WakeCount (%d) on enter\n", mWakeCount);
|
2012-04-17 19:02:26 +00:00
|
|
|
|
2012-04-04 23:53:42 +00:00
|
|
|
mWakeCount++;
|
2012-04-17 19:02:26 +00:00
|
|
|
if (strength == STRONG)
|
|
|
|
mAttemptHibernation = false;
|
|
|
|
|
2012-04-05 22:53:28 +00:00
|
|
|
if (CC_UNLIKELY(mHibernating)) {
|
|
|
|
ALOGV("Awakening\n");
|
|
|
|
egl_connection_t* const cnx = &gEGLImpl;
|
2012-04-17 19:02:26 +00:00
|
|
|
|
|
|
|
// These conditions should be guaranteed before entering hibernation;
|
|
|
|
// we don't want to get into a state where we can't wake up.
|
|
|
|
ALOGD_IF(!mDpyValid || !cnx->egl.eglAwakenProcessIMG,
|
|
|
|
"Invalid hibernation state, unable to awaken\n");
|
|
|
|
|
2012-04-05 22:53:28 +00:00
|
|
|
if (!cnx->egl.eglAwakenProcessIMG()) {
|
|
|
|
ALOGE("Failed to awaken EGL implementation\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mHibernating = false;
|
|
|
|
}
|
2012-04-04 23:53:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-17 19:02:26 +00:00
|
|
|
void egl_display_t::HibernationMachine::decWakeCount(WakeRefStrength strength) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
2012-04-04 23:53:42 +00:00
|
|
|
ALOGE_IF(mWakeCount <= 0, "Invalid WakeCount (%d) on leave\n", mWakeCount);
|
2012-04-17 19:02:26 +00:00
|
|
|
|
|
|
|
mWakeCount--;
|
|
|
|
if (strength == STRONG)
|
|
|
|
mAttemptHibernation = true;
|
|
|
|
|
|
|
|
if (mWakeCount == 0 && CC_UNLIKELY(mAttemptHibernation)) {
|
2012-04-05 22:53:28 +00:00
|
|
|
egl_connection_t* const cnx = &gEGLImpl;
|
|
|
|
mAttemptHibernation = false;
|
2012-05-04 21:52:40 +00:00
|
|
|
if (mAllowHibernation && mDpyValid &&
|
2012-04-17 19:02:26 +00:00
|
|
|
cnx->egl.eglHibernateProcessIMG &&
|
|
|
|
cnx->egl.eglAwakenProcessIMG) {
|
2012-04-05 22:53:28 +00:00
|
|
|
ALOGV("Hibernating\n");
|
|
|
|
if (!cnx->egl.eglHibernateProcessIMG()) {
|
|
|
|
ALOGE("Failed to hibernate EGL implementation\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHibernating = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 19:02:26 +00:00
|
|
|
void egl_display_t::HibernationMachine::setDisplayValid(bool valid) {
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
mDpyValid = valid;
|
2012-04-04 23:53:42 +00:00
|
|
|
}
|
|
|
|
|
2011-05-13 23:21:08 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
// ----------------------------------------------------------------------------
|