diff options
Diffstat (limited to 'opengl')
| -rw-r--r-- | opengl/libagl/egl.cpp | 75 | ||||
| -rw-r--r-- | opengl/libs/EGL/egl.cpp | 11 |
2 files changed, 57 insertions, 29 deletions
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp index 7afcae7504f8..cf66be33729f 100644 --- a/opengl/libagl/egl.cpp +++ b/opengl/libagl/egl.cpp @@ -145,7 +145,7 @@ struct egl_surface_t virtual EGLBoolean bindDrawSurface(ogles_context_t* gl) = 0; virtual EGLBoolean bindReadSurface(ogles_context_t* gl) = 0; - virtual void connect() {} + virtual EGLBoolean connect() { return EGL_TRUE; } virtual void disconnect() {} virtual EGLint getWidth() const = 0; virtual EGLint getHeight() const = 0; @@ -214,10 +214,10 @@ struct egl_window_surface_v2_t : public egl_surface_t virtual EGLBoolean swapBuffers(); virtual EGLBoolean bindDrawSurface(ogles_context_t* gl); virtual EGLBoolean bindReadSurface(ogles_context_t* gl); - virtual void connect(); + virtual EGLBoolean connect(); virtual void disconnect(); - virtual EGLint getWidth() const { return buffer->width; } - virtual EGLint getHeight() const { return buffer->height; } + virtual EGLint getWidth() const { return width; } + virtual EGLint getHeight() const { return height; } virtual EGLint getHorizontalResolution() const; virtual EGLint getVerticalResolution() const; virtual EGLint getRefreshRate() const; @@ -365,43 +365,46 @@ egl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy, // keep a reference on the window nativeWindow->common.incRef(&nativeWindow->common); + nativeWindow->query(nativeWindow, NATIVE_WINDOW_WIDTH, &width); + nativeWindow->query(nativeWindow, NATIVE_WINDOW_HEIGHT, &height); +} + +egl_window_surface_v2_t::~egl_window_surface_v2_t() { + if (buffer) { + buffer->common.decRef(&buffer->common); + } + if (previousBuffer) { + previousBuffer->common.decRef(&previousBuffer->common); + } + nativeWindow->common.decRef(&nativeWindow->common); + if (blitengine) { + copybit_close(blitengine); + } +} +EGLBoolean egl_window_surface_v2_t::connect() +{ // dequeue a buffer - nativeWindow->dequeueBuffer(nativeWindow, &buffer); + if (nativeWindow->dequeueBuffer(nativeWindow, &buffer) != NO_ERROR) { + return setError(EGL_BAD_ALLOC, EGL_FALSE); + } // allocate a corresponding depth-buffer width = buffer->width; height = buffer->height; - if (depthFormat) { + if (depth.format) { depth.width = width; depth.height = height; depth.stride = depth.width; // use the width here depth.data = (GGLubyte*)malloc(depth.stride*depth.height*2); if (depth.data == 0) { - setError(EGL_BAD_ALLOC, EGL_NO_SURFACE); - return; + return setError(EGL_BAD_ALLOC, EGL_FALSE); } } // keep a reference on the buffer buffer->common.incRef(&buffer->common); -} -egl_window_surface_v2_t::~egl_window_surface_v2_t() { - if (buffer) { - buffer->common.decRef(&buffer->common); - } - if (previousBuffer) { - previousBuffer->common.decRef(&previousBuffer->common); - } - nativeWindow->common.decRef(&nativeWindow->common); - if (blitengine) { - copybit_close(blitengine); - } -} - -void egl_window_surface_v2_t::connect() -{ // Lock the buffer nativeWindow->lockBuffer(nativeWindow, buffer); // pin the buffer down @@ -409,9 +412,10 @@ void egl_window_surface_v2_t::connect() GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) { LOGE("connect() failed to lock buffer %p (%ux%u)", buffer, buffer->width, buffer->height); - setError(EGL_BAD_ACCESS, EGL_NO_SURFACE); + return setError(EGL_BAD_ACCESS, EGL_FALSE); // FIXME: we should make sure we're not accessing the buffer anymore } + return EGL_TRUE; } void egl_window_surface_v2_t::disconnect() @@ -420,6 +424,16 @@ void egl_window_surface_v2_t::disconnect() bits = NULL; unlock(buffer); } + // enqueue the last frame + nativeWindow->queueBuffer(nativeWindow, buffer); + if (buffer) { + buffer->common.decRef(&buffer->common); + buffer = 0; + } + if (previousBuffer) { + previousBuffer->common.decRef(&previousBuffer->common); + previousBuffer = 0; + } } status_t egl_window_surface_v2_t::lock( @@ -432,6 +446,7 @@ status_t egl_window_surface_v2_t::lock( status_t egl_window_surface_v2_t::unlock(android_native_buffer_t* buf) { + if (!buf) return BAD_VALUE; int err = module->unlock(module, buf->handle); return err; } @@ -503,6 +518,10 @@ void egl_window_surface_v2_t::copyBlt( EGLBoolean egl_window_surface_v2_t::swapBuffers() { + if (!buffer) { + return setError(EGL_BAD_ACCESS, EGL_FALSE); + } + /* * Handle eglSetSwapRectangleANDROID() * We copyback from the front buffer @@ -568,7 +587,7 @@ EGLBoolean egl_window_surface_v2_t::swapBuffers() GRALLOC_USAGE_SW_WRITE_OFTEN, &bits) != NO_ERROR) { LOGE("eglSwapBuffers() failed to lock buffer %p (%ux%u)", buffer, buffer->width, buffer->height); - setError(EGL_BAD_ACCESS, EGL_NO_SURFACE); + return setError(EGL_BAD_ACCESS, EGL_FALSE); // FIXME: we should make sure we're not accessing the buffer anymore } @@ -1736,7 +1755,9 @@ EGLBoolean eglMakeCurrent( EGLDisplay dpy, EGLSurface draw, ogles_scissor(gl, 0, 0, w, h); } if (d) { - d->connect(); + if (d->connect() == EGL_FALSE) { + return EGL_FALSE; + } d->ctx = ctx; d->bindDrawSurface(gl); } diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index c2003dd4e48d..236d24723c6e 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -135,9 +135,10 @@ struct egl_image_t : public egl_object_t<'_img'> struct tls_t { - tls_t() : error(EGL_SUCCESS), ctx(0) { } + tls_t() : error(EGL_SUCCESS), ctx(0), logCallWithNoContext(EGL_TRUE) { } EGLint error; EGLContext ctx; + EGLBoolean logCallWithNoContext; }; @@ -352,8 +353,14 @@ static int ext_context_lost() { } static void gl_no_context() { - LOGE("call to OpenGL ES API with no current context"); + tls_t* tls = getTLS(); + if (tls->logCallWithNoContext == EGL_TRUE) { + tls->logCallWithNoContext = EGL_FALSE; + LOGE("call to OpenGL ES API with no current context " + "(logged once per thread)"); + } } + static void early_egl_init(void) { #if !USE_FAST_TLS_KEY |