summaryrefslogtreecommitdiffstats
path: root/opengl/libagl/egl.cpp
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2009-05-04 14:17:04 -0700
committerMathias Agopian <mathias@google.com>2009-05-04 14:17:04 -0700
commit0926f50664c739eaee60341f8e8c694dc9a4f3eb (patch)
tree642597de2cc52f7636ae74f1a88f3706e3e54a4a /opengl/libagl/egl.cpp
parent7be3e5d2d8101a8f5e12bbdf650431a734f88eba (diff)
downloadframeworks_native-0926f50664c739eaee60341f8e8c694dc9a4f3eb.zip
frameworks_native-0926f50664c739eaee60341f8e8c694dc9a4f3eb.tar.gz
frameworks_native-0926f50664c739eaee60341f8e8c694dc9a4f3eb.tar.bz2
update surfaceflinger, libui and libagl to the new gralloc api
- Currently the lock/unlock path is naive and is done for each drawing operation (glDrawElements and glDrawArrays). this should be improved eventually. - factor all the lock/unlock code in SurfaceBuffer. - fixed "showupdate" so it works even when we don't have preserving eglSwapBuffers(). - improved the situation with the dirty-region and fixed a problem that caused GL apps to not update. - make use of LightRefBase() where needed, instead of duplicating its implementation - add LightRefBase::getStrongCount() - renamed EGLNativeWindowSurface.cpp to FramebufferNativeWindow.cpp - disabled copybits test, since it clashes with the new gralloc api - Camera/Video will be fixed later when we rework the overlay apis
Diffstat (limited to 'opengl/libagl/egl.cpp')
-rw-r--r--opengl/libagl/egl.cpp71
1 files changed, 43 insertions, 28 deletions
diff --git a/opengl/libagl/egl.cpp b/opengl/libagl/egl.cpp
index 9384e18..04ca431 100644
--- a/opengl/libagl/egl.cpp
+++ b/opengl/libagl/egl.cpp
@@ -212,8 +212,11 @@ struct egl_window_surface_v2_t : public egl_surface_t
virtual EGLint getRefreshRate() const;
virtual EGLint getSwapBehavior() const;
private:
+ status_t lock(android_native_buffer_t* buf, int usage);
+ status_t unlock(android_native_buffer_t* buf);
android_native_window_t* nativeWindow;
android_native_buffer_t* buffer;
+ gralloc_module_t const* module;
int width;
int height;
};
@@ -222,8 +225,13 @@ egl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy,
EGLConfig config,
int32_t depthFormat,
android_native_window_t* window)
- : egl_surface_t(dpy, config, depthFormat), nativeWindow(window), buffer(0)
+ : egl_surface_t(dpy, config, depthFormat),
+ nativeWindow(window), buffer(0), module(0)
{
+ hw_module_t const* pModule;
+ hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule);
+ module = reinterpret_cast<gralloc_module_t const*>(pModule);
+
nativeWindow->common.incRef(&nativeWindow->common);
nativeWindow->dequeueBuffer(nativeWindow, &buffer);
@@ -246,13 +254,44 @@ egl_window_surface_v2_t::egl_window_surface_v2_t(EGLDisplay dpy,
buffer->common.incRef(&buffer->common);
nativeWindow->lockBuffer(nativeWindow, buffer);
- // FIXME: we need to gralloc lock the buffer
+ // Lock the buffer
+ lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
+
// FIXME: we need to handle the copy-back if needed, but
// for now we're a "non preserving" implementation.
}
+status_t egl_window_surface_v2_t::lock(
+ android_native_buffer_t* buf, int usage)
+{
+ int err;
+ buffer_handle_t bufferHandle;
+ err = buf->getHandle(buf, &bufferHandle);
+ if (err < 0)
+ return err;
+
+ err = module->lock(module, bufferHandle,
+ usage, 0, 0, buf->width, buf->height, &buf->bits);
+ return err;
+}
+
+status_t egl_window_surface_v2_t::unlock(android_native_buffer_t* buf)
+{
+ int err;
+ buffer_handle_t bufferHandle;
+ err = buf->getHandle(buf, &bufferHandle);
+ if (err < 0)
+ return err;
+
+ err = module->unlock(module, bufferHandle);
+ buf->bits = NULL;
+ return err;
+}
+
+
egl_window_surface_v2_t::~egl_window_surface_v2_t() {
if (buffer) {
+ unlock(buffer);
buffer->common.decRef(&buffer->common);
}
nativeWindow->common.decRef(&nativeWindow->common);
@@ -269,6 +308,7 @@ EGLBoolean egl_window_surface_v2_t::swapBuffers()
//mDisplaySurface->copyFrontToBack(copyback);
+ unlock(buffer);
nativeWindow->queueBuffer(nativeWindow, buffer);
buffer->common.decRef(&buffer->common); buffer = 0;
@@ -278,6 +318,7 @@ EGLBoolean egl_window_surface_v2_t::swapBuffers()
// TODO: lockBuffer should rather be executed when the very first
// direct rendering occurs.
nativeWindow->lockBuffer(nativeWindow, buffer);
+ lock(buffer, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
if ((width != buffer->width) || (height != buffer->height)) {
@@ -1690,20 +1731,6 @@ EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
if (native_buffer->common.version != sizeof(android_native_buffer_t))
return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
-
- hw_module_t const* pModule;
- if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule))
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
- buffer_handle_t bufferHandle;
- gralloc_module_t const* module =
- reinterpret_cast<gralloc_module_t const*>(pModule);
- if (native_buffer->getHandle(native_buffer, &bufferHandle) < 0)
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
- int err = module->map(module, bufferHandle, &native_buffer->bits);
- if (err < 0) {
- LOGW_IF(err, "map(...) failed %d (%s)", err, strerror(-err));
- return setError(EGL_BAD_PARAMETER, EGL_NO_IMAGE_KHR);
- }
native_buffer->common.incRef(&native_buffer->common);
return (EGLImageKHR)native_buffer;
@@ -1723,18 +1750,6 @@ EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
if (native_buffer->common.version != sizeof(android_native_buffer_t))
return setError(EGL_BAD_PARAMETER, EGL_FALSE);
- hw_module_t const* pModule;
- if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule) == 0) {
- buffer_handle_t bufferHandle;
- gralloc_module_t const* module =
- reinterpret_cast<gralloc_module_t const*>(pModule);
- int err = native_buffer->getHandle(native_buffer, &bufferHandle);
- if (err == 0) {
- int err = module->unmap(module, bufferHandle);
- LOGW_IF(err, "unmap(...) failed %d (%s)", err, strerror(-err));
- }
- }
-
native_buffer->common.decRef(&native_buffer->common);
return EGL_TRUE;