Remove dependency to most of libutils
Most of libutils is replaced by using the STL,
this is fine in this case because none of it
leaks out of EGL’s internals.
Test: compiled & run
Bug: vndk-stable
Change-Id: I42ded4043ddc98ed7eaa975fbbb2e754cd3219af
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index c804fa7..a3502f2 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -24,11 +24,10 @@
#include "egl_cache.h"
#include "egl_object.h"
#include "egl_tls.h"
+#include "egl_trace.h"
#include "Loader.h"
#include <cutils/properties.h>
-#include <utils/Trace.h>
-
// ----------------------------------------------------------------------------
namespace android {
// ----------------------------------------------------------------------------
@@ -75,18 +74,18 @@
}
void egl_display_t::addObject(egl_object_t* object) {
- Mutex::Autolock _l(lock);
- objects.add(object);
+ std::lock_guard<std::mutex> _l(lock);
+ objects.insert(object);
}
void egl_display_t::removeObject(egl_object_t* object) {
- Mutex::Autolock _l(lock);
- objects.remove(object);
+ std::lock_guard<std::mutex> _l(lock);
+ objects.erase(object);
}
bool egl_display_t::getObject(egl_object_t* object) const {
- Mutex::Autolock _l(lock);
- if (objects.indexOf(object) >= 0) {
+ std::lock_guard<std::mutex> _l(lock);
+ if (objects.find(object) != objects.end()) {
if (object->getDisplay() == this) {
object->incRef();
return true;
@@ -104,7 +103,7 @@
EGLDisplay egl_display_t::getDisplay(EGLNativeDisplayType display) {
- Mutex::Autolock _l(lock);
+ std::lock_guard<std::mutex> _l(lock);
ATRACE_CALL();
// get our driver loader
@@ -125,24 +124,26 @@
EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {
- {
- Mutex::Autolock _rf(refLock);
-
+ { // scope for refLock
+ std::unique_lock<std::mutex> _l(refLock);
refs++;
if (refs > 1) {
if (major != NULL)
*major = VERSION_MAJOR;
if (minor != NULL)
*minor = VERSION_MINOR;
- while(!eglIsInitialized) refCond.wait(refLock);
+ while(!eglIsInitialized) {
+ refCond.wait(_l);
+ }
return EGL_TRUE;
}
-
- while(eglIsInitialized) refCond.wait(refLock);
+ while(eglIsInitialized) {
+ refCond.wait(_l);
+ }
}
- {
- Mutex::Autolock _l(lock);
+ { // scope for lock
+ std::lock_guard<std::mutex> _l(lock);
setGLHooksThreadSpecific(&gHooksNoContext);
@@ -179,20 +180,19 @@
}
// the query strings are per-display
- mVendorString.setTo(sVendorString);
- mVersionString.setTo(sVersionString);
- mClientApiString.setTo(sClientApiString);
+ mVendorString = sVendorString;
+ mVersionString = sVersionString;
+ mClientApiString = sClientApiString;
- mExtensionString.setTo(gBuiltinExtensionString);
+ mExtensionString = gBuiltinExtensionString;
char const* start = gExtensionString;
do {
// length of the extension name
size_t len = strcspn(start, " ");
if (len) {
// NOTE: we could avoid the copy if we had strnstr.
- const String8 ext(start, len);
- if (findExtension(disp.queryString.extensions, ext.string(),
- len)) {
+ const std::string ext(start, len);
+ if (findExtension(disp.queryString.extensions, ext.c_str(), len)) {
mExtensionString.append(ext + " ");
}
// advance to the next extension name, skipping the space.
@@ -220,10 +220,10 @@
*minor = VERSION_MINOR;
}
- {
- Mutex::Autolock _rf(refLock);
+ { // scope for refLock
+ std::unique_lock<std::mutex> _l(refLock);
eglIsInitialized = true;
- refCond.broadcast();
+ refCond.notify_all();
}
return EGL_TRUE;
@@ -231,8 +231,8 @@
EGLBoolean egl_display_t::terminate() {
- {
- Mutex::Autolock _rl(refLock);
+ { // scope for refLock
+ std::unique_lock<std::mutex> _rl(refLock);
if (refs == 0) {
/*
* From the EGL spec (3.2):
@@ -252,8 +252,8 @@
EGLBoolean res = EGL_FALSE;
- {
- Mutex::Autolock _l(lock);
+ { // scope for lock
+ std::lock_guard<std::mutex> _l(lock);
egl_connection_t* const cnx = &gEGLImpl;
if (cnx->dso && disp.state == egl_display_t::INITIALIZED) {
@@ -268,15 +268,14 @@
// Reset the extension string since it will be regenerated if we get
// reinitialized.
- mExtensionString.setTo("");
+ mExtensionString.clear();
// 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();
ALOGW_IF(count, "eglTerminate() called w/ %zu objects remaining", count);
- for (size_t i=0 ; i<count ; i++) {
- egl_object_t* o = objects.itemAt(i);
+ for (auto o : objects) {
o->destroy();
}
@@ -284,10 +283,10 @@
objects.clear();
}
- {
- Mutex::Autolock _rl(refLock);
+ { // scope for refLock
+ std::unique_lock<std::mutex> _rl(refLock);
eglIsInitialized = false;
- refCond.broadcast();
+ refCond.notify_all();
}
return res;
@@ -312,7 +311,7 @@
SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);
{ // scope for the lock
- Mutex::Autolock _l(lock);
+ std::lock_guard<std::mutex> _l(lock);
cur_c->onLooseCurrent();
}
@@ -338,7 +337,7 @@
SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL);
{ // scope for the lock
- Mutex::Autolock _l(lock);
+ std::lock_guard<std::mutex> _l(lock);
if (c) {
result = c->cnx->egl.eglMakeCurrent(
disp.dpy, impl_draw, impl_read, impl_ctx);
@@ -370,7 +369,7 @@
if (!nameLen) {
nameLen = strlen(name);
}
- return findExtension(mExtensionString.string(), name, nameLen);
+ return findExtension(mExtensionString.c_str(), name, nameLen);
}
// ----------------------------------------------------------------------------