diff options
| author | 2021-10-06 22:53:36 +0000 | |
|---|---|---|
| committer | 2021-10-06 22:53:36 +0000 | |
| commit | 097d2a50873100486d65a69cb1cbabf37fb3b188 (patch) | |
| tree | c2f19f92e4503b2de0afeebdd9bf7aeb1bb2e9c1 /opengl | |
| parent | cbfb18e134845deeace954bbba818acda48cb80f (diff) | |
| parent | adcb6a2733c1baf66e5ad72365965ab504f5f959 (diff) | |
Merge Android 12
Bug: 202323961
Merged-In: Ifb27b3eb12454fa96f07e6797745c697b4f831c4
Change-Id: I2a7f5931477fddb51564c2eabcdc96ce58888ce8
Diffstat (limited to 'opengl')
31 files changed, 1022 insertions, 1321 deletions
diff --git a/opengl/include/EGL/eglext_angle.h b/opengl/include/EGL/eglext_angle.h index 0556ea1342..e753e0d60f 100644 --- a/opengl/include/EGL/eglext_angle.h +++ b/opengl/include/EGL/eglext_angle.h @@ -4,12 +4,12 @@  // found in the LICENSE file.  //  // eglext_angle.h: ANGLE modifications to the eglext.h header file. -//   Currently we don't include this file directly, we patch eglext.h -//   to include it implicitly so it is visible throughout our code.  #ifndef INCLUDE_EGL_EGLEXT_ANGLE_  #define INCLUDE_EGL_EGLEXT_ANGLE_ +#include <EGL/eglext.h> +  // clang-format off  #ifndef EGL_ANGLE_robust_resource_initialization @@ -186,6 +186,26 @@ EGLAPI EGLint EGLAPIENTRY eglProgramCacheResizeANGLE(EGLDisplay dpy, EGLint limi  #define EGL_EXTENSIONS_ENABLED_ANGLE 0x345F  #endif /* EGL_ANGLE_create_context_extensions_enabled */ +#ifndef EGL_ANGLE_feature_control +#define EGL_ANGLE_feature_control 1 +#define EGL_FEATURE_NAME_ANGLE 0x3460 +#define EGL_FEATURE_CATEGORY_ANGLE 0x3461 +#define EGL_FEATURE_DESCRIPTION_ANGLE 0x3462 +#define EGL_FEATURE_BUG_ANGLE 0x3463 +#define EGL_FEATURE_STATUS_ANGLE 0x3464 +#define EGL_FEATURE_COUNT_ANGLE 0x3465 +#define EGL_FEATURE_OVERRIDES_ENABLED_ANGLE 0x3466 +#define EGL_FEATURE_OVERRIDES_DISABLED_ANGLE 0x3467 +#define EGL_FEATURE_CONDITION_ANGLE 0x3468 +#define EGL_FEATURE_ALL_DISABLED_ANGLE 0x3469 +typedef const char *(EGLAPIENTRYP PFNEGLQUERYSTRINGIANGLEPROC) (EGLDisplay dpy, EGLint name, EGLint index); +typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDISPLAYATTRIBANGLEPROC) (EGLDisplay dpy, EGLint attribute, EGLAttrib *value); +#ifdef EGL_EGLEXT_PROTOTYPES +EGLAPI const char *EGLAPIENTRY eglQueryStringiANGLE(EGLDisplay dpy, EGLint name, EGLint index); +EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribANGLE(EGLDisplay dpy, EGLint attribute, EGLAttrib *value); +#endif +#endif /* EGL_ANGLE_feature_control */ +  // clang-format on  #endif // INCLUDE_EGL_EGLEXT_ANGLE_ diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp index daaaf88bbb..c9fce8ad52 100644 --- a/opengl/libs/Android.bp +++ b/opengl/libs/Android.bp @@ -111,11 +111,6 @@ cc_defaults {          "libbacktrace",          "libbase",      ], -    target: { -        vendor: { -            exclude_shared_libs: ["libgraphicsenv"], -        }, -    },  }  cc_library_static { diff --git a/opengl/libs/EGL/BlobCache.cpp b/opengl/libs/EGL/BlobCache.cpp index a27c09f0fe..beca7f191a 100644 --- a/opengl/libs/EGL/BlobCache.cpp +++ b/opengl/libs/EGL/BlobCache.cpp @@ -18,11 +18,11 @@  #include "BlobCache.h" +#include <android-base/properties.h>  #include <errno.h>  #include <inttypes.h> - -#include <android-base/properties.h>  #include <log/log.h> +  #include <chrono>  namespace android { @@ -36,8 +36,8 @@ static const uint32_t blobCacheVersion = 3;  // BlobCache::Header::mDeviceVersion value  static const uint32_t blobCacheDeviceVersion = 1; -BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize): -        mMaxTotalSize(maxTotalSize), +BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize) +      : mMaxTotalSize(maxTotalSize),          mMaxKeySize(maxKeySize),          mMaxValueSize(maxValueSize),          mTotalSize(0) { @@ -52,21 +52,21 @@ BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize      ALOGV("initializing random seed using %lld", (unsigned long long)now);  } -void BlobCache::set(const void* key, size_t keySize, const void* value, -        size_t valueSize) { +void BlobCache::set(const void* key, size_t keySize, const void* value, size_t valueSize) {      if (mMaxKeySize < keySize) { -        ALOGV("set: not caching because the key is too large: %zu (limit: %zu)", -                keySize, mMaxKeySize); +        ALOGV("set: not caching because the key is too large: %zu (limit: %zu)", keySize, +              mMaxKeySize);          return;      }      if (mMaxValueSize < valueSize) { -        ALOGV("set: not caching because the value is too large: %zu (limit: %zu)", -                valueSize, mMaxValueSize); +        ALOGV("set: not caching because the value is too large: %zu (limit: %zu)", valueSize, +              mMaxValueSize);          return;      }      if (mMaxTotalSize < keySize + valueSize) {          ALOGV("set: not caching because the combined key/value size is too " -                "large: %zu (limit: %zu)", keySize + valueSize, mMaxTotalSize); +              "large: %zu (limit: %zu)", +              keySize + valueSize, mMaxTotalSize);          return;      }      if (keySize == 0) { @@ -95,16 +95,16 @@ void BlobCache::set(const void* key, size_t keySize, const void* value,                      continue;                  } else {                      ALOGV("set: not caching new key/value pair because the " -                            "total cache size limit would be exceeded: %zu " -                            "(limit: %zu)", -                            keySize + valueSize, mMaxTotalSize); +                          "total cache size limit would be exceeded: %zu " +                          "(limit: %zu)", +                          keySize + valueSize, mMaxTotalSize);                      break;                  }              }              mCacheEntries.insert(index, CacheEntry(keyBlob, valueBlob));              mTotalSize = newTotalSize; -            ALOGV("set: created new cache entry with %zu byte key and %zu byte value", -                    keySize, valueSize); +            ALOGV("set: created new cache entry with %zu byte key and %zu byte value", keySize, +                  valueSize);          } else {              // Update the existing cache entry.              std::shared_ptr<Blob> valueBlob(new Blob(value, valueSize, true)); @@ -117,25 +117,25 @@ void BlobCache::set(const void* key, size_t keySize, const void* value,                      continue;                  } else {                      ALOGV("set: not caching new value because the total cache " -                            "size limit would be exceeded: %zu (limit: %zu)", -                            keySize + valueSize, mMaxTotalSize); +                          "size limit would be exceeded: %zu (limit: %zu)", +                          keySize + valueSize, mMaxTotalSize);                      break;                  }              }              index->setValue(valueBlob);              mTotalSize = newTotalSize;              ALOGV("set: updated existing cache entry with %zu byte key and %zu byte " -                    "value", keySize, valueSize); +                  "value", +                  keySize, valueSize);          }          break;      }  } -size_t BlobCache::get(const void* key, size_t keySize, void* value, -        size_t valueSize) { +size_t BlobCache::get(const void* key, size_t keySize, void* value, size_t valueSize) {      if (mMaxKeySize < keySize) { -        ALOGV("get: not searching because the key is too large: %zu (limit %zu)", -                keySize, mMaxKeySize); +        ALOGV("get: not searching because the key is too large: %zu (limit %zu)", keySize, +              mMaxKeySize);          return 0;      }      std::shared_ptr<Blob> cacheKey(new Blob(key, keySize, false)); @@ -154,8 +154,8 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value,          ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize);          memcpy(value, valueBlob->getData(), valueBlobSize);      } else { -        ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", -                valueSize, valueBlobSize); +        ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, +              valueBlobSize);      }      return valueBlobSize;  } @@ -167,7 +167,7 @@ static inline size_t align4(size_t size) {  size_t BlobCache::getFlattenedSize() const {      auto buildId = base::GetProperty("ro.build.id", "");      size_t size = align4(sizeof(Header) + buildId.size()); -    for (const CacheEntry& e :  mCacheEntries) { +    for (const CacheEntry& e : mCacheEntries) {          std::shared_ptr<Blob> const& keyBlob = e.getKey();          std::shared_ptr<Blob> const& valueBlob = e.getValue();          size += align4(sizeof(EntryHeader) + keyBlob->getSize() + valueBlob->getSize()); @@ -193,7 +193,7 @@ int BlobCache::flatten(void* buffer, size_t size) const {      // Write cache entries      uint8_t* byteBuffer = reinterpret_cast<uint8_t*>(buffer);      off_t byteOffset = align4(sizeof(Header) + header->mBuildIdLength); -    for (const CacheEntry& e :  mCacheEntries) { +    for (const CacheEntry& e : mCacheEntries) {          std::shared_ptr<Blob> const& keyBlob = e.getKey();          std::shared_ptr<Blob> const& valueBlob = e.getValue();          size_t keySize = keyBlob->getSize(); @@ -259,8 +259,7 @@ int BlobCache::unflatten(void const* buffer, size_t size) {              return -EINVAL;          } -        const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>( -                &byteBuffer[byteOffset]); +        const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>(&byteBuffer[byteOffset]);          size_t keySize = eheader->mKeySize;          size_t valueSize = eheader->mValueSize;          size_t entrySize = sizeof(EntryHeader) + keySize + valueSize; @@ -304,10 +303,8 @@ bool BlobCache::isCleanable() const {      return mTotalSize > mMaxTotalSize / 2;  } -BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) : -        mData(copyData ? malloc(size) : data), -        mSize(size), -        mOwnsData(copyData) { +BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) +      : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) {      if (data != nullptr && copyData) {          memcpy(const_cast<void*>(mData), data, size);      } @@ -335,19 +332,13 @@ size_t BlobCache::Blob::getSize() const {      return mSize;  } -BlobCache::CacheEntry::CacheEntry() { -} +BlobCache::CacheEntry::CacheEntry() {} -BlobCache::CacheEntry::CacheEntry( -        const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value): -        mKey(key), -        mValue(value) { -} +BlobCache::CacheEntry::CacheEntry(const std::shared_ptr<Blob>& key, +                                  const std::shared_ptr<Blob>& value) +      : mKey(key), mValue(value) {} -BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce): -        mKey(ce.mKey), -        mValue(ce.mValue) { -} +BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce) : mKey(ce.mKey), mValue(ce.mValue) {}  bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const {      return *mKey < *rhs.mKey; diff --git a/opengl/libs/EGL/BlobCache.h b/opengl/libs/EGL/BlobCache.h index e5c5e5bc25..50b4e4c6d0 100644 --- a/opengl/libs/EGL/BlobCache.h +++ b/opengl/libs/EGL/BlobCache.h @@ -54,8 +54,7 @@ public:      //   0 < keySize      //   value != NULL      //   0 < valueSize -    void set(const void* key, size_t keySize, const void* value, -            size_t valueSize); +    void set(const void* key, size_t keySize, const void* value, size_t valueSize);      // get retrieves from the cache the binary value associated with a given      // binary key.  If the key is present in the cache then the length of the @@ -75,7 +74,6 @@ public:      //   0 <= valueSize      size_t get(const void* key, size_t keySize, void* value, size_t valueSize); -      // getFlattenedSize returns the number of bytes needed to store the entire      // serialized cache.      size_t getFlattenedSize() const; @@ -168,7 +166,6 @@ private:          void setValue(const std::shared_ptr<Blob>& value);      private: -          // mKey is the key that identifies the cache entry.          std::shared_ptr<Blob> mKey; @@ -245,6 +242,6 @@ private:      std::vector<CacheEntry> mCacheEntries;  }; -} +} // namespace android  #endif // ANDROID_BLOB_CACHE_H diff --git a/opengl/libs/EGL/BlobCache_test.cpp b/opengl/libs/EGL/BlobCache_test.cpp index cf67cf443b..d31373b37a 100644 --- a/opengl/libs/EGL/BlobCache_test.cpp +++ b/opengl/libs/EGL/BlobCache_test.cpp @@ -14,25 +14,24 @@   ** limitations under the License.   */ +#include "BlobCache.h" +  #include <fcntl.h> +#include <gtest/gtest.h>  #include <stdio.h>  #include <memory> -#include <gtest/gtest.h> - -#include "BlobCache.h" -  namespace android { -template<typename T> using sp = std::shared_ptr<T>; +template <typename T> +using sp = std::shared_ptr<T>;  class BlobCacheTest : public ::testing::Test {  protected: -      enum {          OK = 0, -        BAD_VALUE = -EINVAL +        BAD_VALUE = -EINVAL,      };      enum { @@ -41,19 +40,15 @@ protected:          MAX_TOTAL_SIZE = 13,      }; -    virtual void SetUp() { -        mBC.reset(new BlobCache(MAX_KEY_SIZE, MAX_VALUE_SIZE, MAX_TOTAL_SIZE)); -    } +    virtual void SetUp() { mBC.reset(new BlobCache(MAX_KEY_SIZE, MAX_VALUE_SIZE, MAX_TOTAL_SIZE)); } -    virtual void TearDown() { -        mBC.reset(); -    } +    virtual void TearDown() { mBC.reset(); }      std::unique_ptr<BlobCache> mBC;  };  TEST_F(BlobCacheTest, CacheSingleValueSucceeds) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));      ASSERT_EQ('e', buf[0]); @@ -63,7 +58,7 @@ TEST_F(BlobCacheTest, CacheSingleValueSucceeds) {  }  TEST_F(BlobCacheTest, CacheTwoValuesSucceeds) { -    unsigned char buf[2] = { 0xee, 0xee }; +    unsigned char buf[2] = {0xee, 0xee};      mBC->set("ab", 2, "cd", 2);      mBC->set("ef", 2, "gh", 2);      ASSERT_EQ(size_t(2), mBC->get("ab", 2, buf, 2)); @@ -75,9 +70,9 @@ TEST_F(BlobCacheTest, CacheTwoValuesSucceeds) {  }  TEST_F(BlobCacheTest, GetOnlyWritesInsideBounds) { -    unsigned char buf[6] = { 0xee, 0xee, 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[6] = {0xee, 0xee, 0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4); -    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf+1, 4)); +    ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf + 1, 4));      ASSERT_EQ(0xee, buf[0]);      ASSERT_EQ('e', buf[1]);      ASSERT_EQ('f', buf[2]); @@ -87,7 +82,7 @@ TEST_F(BlobCacheTest, GetOnlyWritesInsideBounds) {  }  TEST_F(BlobCacheTest, GetOnlyWritesIfBufferIsLargeEnough) { -    unsigned char buf[3] = { 0xee, 0xee, 0xee }; +    unsigned char buf[3] = {0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 3));      ASSERT_EQ(0xee, buf[0]); @@ -101,7 +96,7 @@ TEST_F(BlobCacheTest, GetDoesntAccessNullBuffer) {  }  TEST_F(BlobCacheTest, MultipleSetsCacheLatestValue) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      mBC->set("abcd", 4, "ijkl", 4);      ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4)); @@ -112,9 +107,9 @@ TEST_F(BlobCacheTest, MultipleSetsCacheLatestValue) {  }  TEST_F(BlobCacheTest, SecondSetKeepsFirstValueIfTooLarge) { -    unsigned char buf[MAX_VALUE_SIZE+1] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[MAX_VALUE_SIZE + 1] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4); -    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE+1); +    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE + 1);      ASSERT_EQ(size_t(4), mBC->get("abcd", 4, buf, 4));      ASSERT_EQ('e', buf[0]);      ASSERT_EQ('f', buf[1]); @@ -123,13 +118,13 @@ TEST_F(BlobCacheTest, SecondSetKeepsFirstValueIfTooLarge) {  }  TEST_F(BlobCacheTest, DoesntCacheIfKeyIsTooBig) { -    char key[MAX_KEY_SIZE+1]; -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; -    for (int i = 0; i < MAX_KEY_SIZE+1; i++) { +    char key[MAX_KEY_SIZE + 1]; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee}; +    for (int i = 0; i < MAX_KEY_SIZE + 1; i++) {          key[i] = 'a';      } -    mBC->set(key, MAX_KEY_SIZE+1, "bbbb", 4); -    ASSERT_EQ(size_t(0), mBC->get(key, MAX_KEY_SIZE+1, buf, 4)); +    mBC->set(key, MAX_KEY_SIZE + 1, "bbbb", 4); +    ASSERT_EQ(size_t(0), mBC->get(key, MAX_KEY_SIZE + 1, buf, 4));      ASSERT_EQ(0xee, buf[0]);      ASSERT_EQ(0xee, buf[1]);      ASSERT_EQ(0xee, buf[2]); @@ -137,16 +132,16 @@ TEST_F(BlobCacheTest, DoesntCacheIfKeyIsTooBig) {  }  TEST_F(BlobCacheTest, DoesntCacheIfValueIsTooBig) { -    char buf[MAX_VALUE_SIZE+1]; -    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) { +    char buf[MAX_VALUE_SIZE + 1]; +    for (int i = 0; i < MAX_VALUE_SIZE + 1; i++) {          buf[i] = 'b';      } -    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE+1); -    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) { +    mBC->set("abcd", 4, buf, MAX_VALUE_SIZE + 1); +    for (int i = 0; i < MAX_VALUE_SIZE + 1; i++) {          buf[i] = 0xee;      } -    ASSERT_EQ(size_t(0), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE+1)); -    for (int i = 0; i < MAX_VALUE_SIZE+1; i++) { +    ASSERT_EQ(size_t(0), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE + 1)); +    for (int i = 0; i < MAX_VALUE_SIZE + 1; i++) {          SCOPED_TRACE(i);          ASSERT_EQ(0xee, buf[i]);      } @@ -174,7 +169,7 @@ TEST_F(BlobCacheTest, DoesntCacheIfKeyValuePairIsTooBig) {  TEST_F(BlobCacheTest, CacheMaxKeySizeSucceeds) {      char key[MAX_KEY_SIZE]; -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      for (int i = 0; i < MAX_KEY_SIZE; i++) {          key[i] = 'a';      } @@ -195,8 +190,7 @@ TEST_F(BlobCacheTest, CacheMaxValueSizeSucceeds) {      for (int i = 0; i < MAX_VALUE_SIZE; i++) {          buf[i] = 0xee;      } -    ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, -            MAX_VALUE_SIZE)); +    ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE));      for (int i = 0; i < MAX_VALUE_SIZE; i++) {          SCOPED_TRACE(i);          ASSERT_EQ('b', buf[i]); @@ -223,7 +217,7 @@ TEST_F(BlobCacheTest, CacheMaxKeyValuePairSizeSucceeds) {  }  TEST_F(BlobCacheTest, CacheMinKeyAndValueSizeSucceeds) { -    unsigned char buf[1] = { 0xee }; +    unsigned char buf[1] = {0xee};      mBC->set("x", 1, "y", 1);      ASSERT_EQ(size_t(1), mBC->get("x", 1, buf, 1));      ASSERT_EQ('y', buf[0]); @@ -258,13 +252,13 @@ TEST_F(BlobCacheTest, ExceedingTotalLimitHalvesCacheSize) {      }      // Count the number of entries in the cache.      int numCached = 0; -    for (int i = 0; i < maxEntries+1; i++) { +    for (int i = 0; i < maxEntries + 1; i++) {          uint8_t k = i;          if (mBC->get(&k, 1, nullptr, 0) == 1) {              numCached++;          }      } -    ASSERT_EQ(maxEntries/2 + 1, numCached); +    ASSERT_EQ(maxEntries / 2 + 1, numCached);  }  class BlobCacheFlattenTest : public BlobCacheTest { @@ -291,7 +285,7 @@ protected:  };  TEST_F(BlobCacheFlattenTest, FlattenOneValue) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      roundTrip();      ASSERT_EQ(size_t(4), mBC2->get("abcd", 4, buf, 4)); @@ -359,7 +353,7 @@ TEST_F(BlobCacheFlattenTest, FlattenCatchesBufferTooSmall) {  }  TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadMagic) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      size_t size = mBC->getFlattenedSize(); @@ -376,7 +370,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadMagic) {  }  TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheVersion) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      size_t size = mBC->getFlattenedSize(); @@ -395,7 +389,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheVersion) {  }  TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheDeviceVersion) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      size_t size = mBC->getFlattenedSize(); @@ -414,7 +408,7 @@ TEST_F(BlobCacheFlattenTest, UnflattenCatchesBadBlobCacheDeviceVersion) {  }  TEST_F(BlobCacheFlattenTest, UnflattenCatchesBufferTooSmall) { -    unsigned char buf[4] = { 0xee, 0xee, 0xee, 0xee }; +    unsigned char buf[4] = {0xee, 0xee, 0xee, 0xee};      mBC->set("abcd", 4, "efgh", 4);      size_t size = mBC->getFlattenedSize(); diff --git a/opengl/libs/EGL/CallStack.h b/opengl/libs/EGL/CallStack.h index 0e2a9b3248..b7fdf97cbe 100644 --- a/opengl/libs/EGL/CallStack.h +++ b/opengl/libs/EGL/CallStack.h @@ -16,8 +16,9 @@  #pragma once -#include <log/log.h>  #include <backtrace/Backtrace.h> +#include <log/log.h> +  #include <memory>  class CallStack { @@ -30,9 +31,8 @@ public:          if (backtrace->Unwind(2)) {              for (size_t i = 0, c = backtrace->NumFrames(); i < c; i++) {                  __android_log_print(ANDROID_LOG_DEBUG, logtag, "%s", -                        backtrace->FormatFrameData(i).c_str()); +                                    backtrace->FormatFrameData(i).c_str());              }          }      }  }; - diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index d66ef2b969..76fd7f0f3f 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -17,27 +17,23 @@  //#define LOG_NDEBUG 0  #define ATRACE_TAG ATRACE_TAG_GRAPHICS -#include <EGL/Loader.h> - -#include <string> - -#include <dirent.h> -#include <dlfcn.h> +#include "EGL/Loader.h"  #include <android-base/properties.h>  #include <android/dlext.h> +#include <dirent.h> +#include <dlfcn.h> +#include <graphicsenv/GraphicsEnv.h>  #include <log/log.h>  #include <utils/Timers.h> - -#ifndef __ANDROID_VNDK__ -#include <graphicsenv/GraphicsEnv.h> -#endif  #include <vndksupport/linker.h> +#include <string> + +#include "EGL/eglext_angle.h"  #include "egl_platform_entries.h"  #include "egl_trace.h"  #include "egldefs.h" -#include <EGL/eglext_angle.h>  namespace android { @@ -159,13 +155,11 @@ static bool should_unload_system_driver(egl_connection_t* cnx) {          return true;      } -#ifndef __ANDROID_VNDK__      // Return true if updated driver namespace is set.      ns = android::GraphicsEnv::getInstance().getDriverNamespace();      if (ns) {          return true;      } -#endif      return false;  } @@ -276,7 +270,7 @@ void* Loader::open(egl_connection_t* cnx)          // will set cnx->useAngle appropriately.          // Do this here so that we use ANGLE path when driver is ANGLE (e.g. loaded as native),          // not just loading ANGLE as option. -        init_angle_backend(hnd->dso[0], cnx); +        init_angle_backend(hnd->dso[2], cnx);      }      LOG_ALWAYS_FATAL_IF(!hnd, @@ -370,7 +364,7 @@ void Loader::init_api(void* dso,              f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented;              /* -             * GL_EXT_debug_label is special, we always report it as +             * GL_EXT_debug_marker is special, we always report it as               * supported, it's handled by GLES_trace. If GLES_trace is not               * enabled, then these are no-ops.               */ @@ -520,6 +514,8 @@ static void* load_updated_driver(const char* kind, android_namespace_t* ns) {          if (so) {              return so;          } +        ALOGE("Could not load %s from updatable gfx driver namespace: %s.", name.c_str(), +              dlerror());      }      return nullptr;  } @@ -557,12 +553,8 @@ Loader::driver_t* Loader::attempt_to_load_angle(egl_connection_t* cnx) {  }  void Loader::init_angle_backend(void* dso, egl_connection_t* cnx) { -    void* eglCreateDeviceANGLE = nullptr; - -    ALOGV("dso: %p", dso); -    eglCreateDeviceANGLE = dlsym(dso, "eglCreateDeviceANGLE"); -    ALOGV("eglCreateDeviceANGLE: %p", eglCreateDeviceANGLE); -    if (eglCreateDeviceANGLE) { +    void* pANGLEGetDisplayPlatform = dlsym(dso, "ANGLEGetDisplayPlatform"); +    if (pANGLEGetDisplayPlatform) {          ALOGV("ANGLE GLES library in use");          cnx->useAngle = true;      } else { @@ -573,7 +565,7 @@ void Loader::init_angle_backend(void* dso, egl_connection_t* cnx) {  Loader::driver_t* Loader::attempt_to_load_updated_driver(egl_connection_t* cnx) {      ATRACE_CALL(); -#ifndef __ANDROID_VNDK__ +      android_namespace_t* ns = android::GraphicsEnv::getInstance().getDriverNamespace();      if (!ns) {          return nullptr; @@ -603,9 +595,6 @@ Loader::driver_t* Loader::attempt_to_load_updated_driver(egl_connection_t* cnx)          hnd->set(dso, GLESv2);      }      return hnd; -#else -    return nullptr; -#endif  }  Loader::driver_t* Loader::attempt_to_load_system_driver(egl_connection_t* cnx, const char* suffix, diff --git a/opengl/libs/EGL/Loader.h b/opengl/libs/EGL/Loader.h index 7b2d7c9c27..81742ab9ae 100644 --- a/opengl/libs/EGL/Loader.h +++ b/opengl/libs/EGL/Loader.h @@ -1,29 +1,26 @@ -/*  +/*   ** Copyright 2009, 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  + ** 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  + **     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  + ** 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.   */  #ifndef ANDROID_EGL_LOADER_H  #define ANDROID_EGL_LOADER_H -#include <stdint.h> -  #include <EGL/egl.h> +#include <stdint.h> -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  struct egl_connection_t; @@ -62,16 +59,12 @@ private:      void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);      void init_angle_backend(void* dso, egl_connection_t* cnx); -    static __attribute__((noinline)) -    void init_api(void* dso, -            char const * const * api, -            char const * const * ref_api, -            __eglMustCastToProperFunctionPointerType* curr, -            getProcAddressType getProcAddress); +    static __attribute__((noinline)) void init_api(void* dso, const char* const* api, +                                                   const char* const* ref_api, +                                                   __eglMustCastToProperFunctionPointerType* curr, +                                                   getProcAddressType getProcAddress);  }; -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif /* ANDROID_EGL_LOADER_H */ diff --git a/opengl/libs/EGL/egl.cpp b/opengl/libs/EGL/egl.cpp index 43f7a075a7..e5b9e14bd5 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -14,45 +14,35 @@   ** limitations under the License.   */ -#include <stdlib.h> -  #include <EGL/egl.h> -  #include <android-base/properties.h> -  #include <log/log.h> +#include <stdlib.h>  #include "../egl_impl.h" - -#include "egldefs.h" -#include "egl_tls.h" -#include "egl_display.h" -#include "egl_object.h" -#include "egl_layers.h"  #include "CallStack.h"  #include "Loader.h" +#include "egl_display.h" +#include "egl_layers.h" +#include "egl_object.h" +#include "egl_tls.h" +#include "egldefs.h" -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  egl_connection_t gEGLImpl;  gl_hooks_t gHooks[2];  gl_hooks_t gHooksNoContext;  pthread_key_t gGLWrapperKey = -1; -// ---------------------------------------------------------------------------- - -void setGLHooksThreadSpecific(gl_hooks_t const *value) { +void setGLHooksThreadSpecific(gl_hooks_t const* value) {      setGlThreadSpecific(value);  } -/*****************************************************************************/ -  static int gl_no_context() {      if (egl_tls_t::logNoContextCall()) { -        char const* const error = "call to OpenGL ES API with " -                "no current context (logged once per thread)"; +        const char* const error = "call to OpenGL ES API with " +                                  "no current context (logged once per thread)";          if (LOG_NDEBUG) {              ALOGE(error);          } else { @@ -65,10 +55,9 @@ static int gl_no_context() {      return 0;  } -static void early_egl_init(void) -{ +static void early_egl_init(void) {      int numHooks = sizeof(gHooksNoContext) / sizeof(EGLFuncPointer); -    EGLFuncPointer *iter = reinterpret_cast<EGLFuncPointer*>(&gHooksNoContext); +    EGLFuncPointer* iter = reinterpret_cast<EGLFuncPointer*>(&gHooksNoContext);      for (int hook = 0; hook < numHooks; ++hook) {          *(iter++) = reinterpret_cast<EGLFuncPointer>(gl_no_context);      } @@ -76,75 +65,40 @@ static void early_egl_init(void)      setGLHooksThreadSpecific(&gHooksNoContext);  } -static pthread_once_t once_control = PTHREAD_ONCE_INIT; -static int sEarlyInitState = pthread_once(&once_control, &early_egl_init); - -// ---------------------------------------------------------------------------- - -egl_display_ptr validate_display(EGLDisplay dpy) { -    egl_display_ptr dp = get_display(dpy); -    if (!dp) -        return setError(EGL_BAD_DISPLAY, egl_display_ptr(nullptr)); -    if (!dp->isReady()) -        return setError(EGL_NOT_INITIALIZED, egl_display_ptr(nullptr)); - -    return dp; -} - -egl_display_ptr validate_display_connection(EGLDisplay dpy, -        egl_connection_t*& cnx) { -    cnx = nullptr; -    egl_display_ptr dp = validate_display(dpy); -    if (!dp) -        return dp; -    cnx = &gEGLImpl; -    if (cnx->dso == nullptr) { -        return setError(EGL_BAD_CONFIG, egl_display_ptr(nullptr)); -    } -    return dp; -} - -// ---------------------------------------------------------------------------- - -const GLubyte * egl_get_string_for_current_context(GLenum name) { +const GLubyte* egl_get_string_for_current_context(GLenum name) {      // NOTE: returning NULL here will fall-back to the default      // implementation.      EGLContext context = egl_tls_t::getContext(); -    if (context == EGL_NO_CONTEXT) -        return nullptr; +    if (context == EGL_NO_CONTEXT) return nullptr; -    egl_context_t const * const c = get_context(context); +    const egl_context_t* const c = get_context(context);      if (c == nullptr) // this should never happen, by construction          return nullptr; -    if (name != GL_EXTENSIONS) -        return nullptr; +    if (name != GL_EXTENSIONS) return nullptr; -    return (const GLubyte *)c->gl_extensions.c_str(); +    return (const GLubyte*)c->gl_extensions.c_str();  } -const GLubyte * egl_get_string_for_current_context(GLenum name, GLuint index) { +const GLubyte* egl_get_string_for_current_context(GLenum name, GLuint index) {      // NOTE: returning NULL here will fall-back to the default      // implementation.      EGLContext context = egl_tls_t::getContext(); -    if (context == EGL_NO_CONTEXT) -        return nullptr; +    if (context == EGL_NO_CONTEXT) return nullptr; -    egl_context_t const * const c = get_context(context); +    const egl_context_t* const c = get_context(context);      if (c == nullptr) // this should never happen, by construction          return nullptr; -    if (name != GL_EXTENSIONS) -        return nullptr; +    if (name != GL_EXTENSIONS) return nullptr;      // if index is out of bounds, assume it will be in the default      // implementation too, so we don't have to generate a GL error here -    if (index >= c->tokenized_gl_extensions.size()) -        return nullptr; +    if (index >= c->tokenized_gl_extensions.size()) return nullptr; -    return (const GLubyte *)c->tokenized_gl_extensions[index].c_str(); +    return (const GLubyte*)c->tokenized_gl_extensions[index].c_str();  }  GLint egl_get_num_extensions_for_current_context() { @@ -152,10 +106,9 @@ GLint egl_get_num_extensions_for_current_context() {      // implementation.      EGLContext context = egl_tls_t::getContext(); -    if (context == EGL_NO_CONTEXT) -        return -1; +    if (context == EGL_NO_CONTEXT) return -1; -    egl_context_t const * const c = get_context(context); +    const egl_context_t* const c = get_context(context);      if (c == nullptr) // this should never happen, by construction          return -1; @@ -166,7 +119,8 @@ egl_connection_t* egl_get_connection() {      return &gEGLImpl;  } -// ---------------------------------------------------------------------------- +static pthread_once_t once_control = PTHREAD_ONCE_INIT; +static int sEarlyInitState = pthread_once(&once_control, &early_egl_init);  static EGLBoolean egl_init_drivers_locked() {      if (sEarlyInitState) { @@ -194,7 +148,6 @@ static EGLBoolean egl_init_drivers_locked() {      return cnx->dso ? EGL_TRUE : EGL_FALSE;  } -  // this mutex protects driver load logic as a critical section since it accesses to global variable  // like gEGLImpl  static pthread_mutex_t sInitDriverMutex = PTHREAD_MUTEX_INITIALIZER; @@ -228,13 +181,10 @@ void gl_unimplemented() {      }  } -void gl_noop() { -} - -// ---------------------------------------------------------------------------- +void gl_noop() {} -void setGlThreadSpecific(gl_hooks_t const *value) { -    gl_hooks_t const * volatile * tls_hooks = get_tls_hooks(); +void setGlThreadSpecific(gl_hooks_t const* value) { +    gl_hooks_t const* volatile* tls_hooks = get_tls_hooks();      tls_hooks[TLS_SLOT_OPENGL_API] = value;  } @@ -270,8 +220,4 @@ char const * const platform_names[] = {  #undef GL_ENTRY  #undef EGL_ENTRY - -// ----------------------------------------------------------------------------  }; // namespace android -// ---------------------------------------------------------------------------- - diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index c51a1295e7..502c14f0f1 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -20,7 +20,6 @@  #include <EGL/eglext.h>  #include "../egl_impl.h" -  #include "egl_layers.h"  #include "egl_platform_entries.h"  #include "egl_tls.h" diff --git a/opengl/libs/EGL/egl_angle_platform.cpp b/opengl/libs/EGL/egl_angle_platform.cpp index 4f85eff93d..d38f2eff01 100644 --- a/opengl/libs/EGL/egl_angle_platform.cpp +++ b/opengl/libs/EGL/egl_angle_platform.cpp @@ -16,7 +16,6 @@  #if defined(__ANDROID__) -#include "Loader.h"  #include "egl_angle_platform.h"  #pragma GCC diagnostic push @@ -32,6 +31,8 @@  #include <time.h>  #include <vndksupport/linker.h> +#include "Loader.h" +  namespace angle {  constexpr int kAngleDlFlags = RTLD_LOCAL | RTLD_NOW; @@ -151,9 +152,8 @@ bool initializeAnglePlatform(EGLDisplay dpy) {              reinterpret_cast<ResetDisplayPlatformFunc>(dlsym(so, "ANGLEResetDisplayPlatform"));      PlatformMethods* platformMethods = nullptr; -    if (!((angleGetDisplayPlatform)(dpy, g_PlatformMethodNames, -                                                              g_NumPlatformMethods, nullptr, -                                                              &platformMethods))) { +    if (!((angleGetDisplayPlatform)(dpy, g_PlatformMethodNames, g_NumPlatformMethods, nullptr, +                                    &platformMethods))) {          ALOGE("ANGLEGetDisplayPlatform call failed!");          return false;      } diff --git a/opengl/libs/EGL/egl_cache.cpp b/opengl/libs/EGL/egl_cache.cpp index bcf496164b..efa67dbc1c 100644 --- a/opengl/libs/EGL/egl_cache.cpp +++ b/opengl/libs/EGL/egl_cache.cpp @@ -16,17 +16,14 @@  #include "egl_cache.h" -#include "../egl_impl.h" - -#include "egl_display.h" - +#include <log/log.h>  #include <private/EGL/cache.h> -  #include <unistd.h>  #include <thread> -#include <log/log.h> +#include "../egl_impl.h" +#include "egl_display.h"  // Cache size limits.  static const size_t maxKeySize = 12 * 1024; @@ -36,9 +33,7 @@ static const size_t maxTotalSize = 2 * 1024 * 1024;  // The time in seconds to wait before saving newly inserted cache entries.  static const unsigned int deferredSaveDelay = 4; -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  #define BC_EXT_STR "EGL_ANDROID_blob_cache" @@ -50,25 +45,22 @@ void egl_set_cache_filename(const char* filename) {  //  // Callback functions passed to EGL.  // -static void setBlob(const void* key, EGLsizeiANDROID keySize, -        const void* value, EGLsizeiANDROID valueSize) { +static void setBlob(const void* key, EGLsizeiANDROID keySize, const void* value, +                    EGLsizeiANDROID valueSize) {      egl_cache_t::get()->setBlob(key, keySize, value, valueSize);  } -static EGLsizeiANDROID getBlob(const void* key, EGLsizeiANDROID keySize, -        void* value, EGLsizeiANDROID valueSize) { +static EGLsizeiANDROID getBlob(const void* key, EGLsizeiANDROID keySize, void* value, +                               EGLsizeiANDROID valueSize) {      return egl_cache_t::get()->getBlob(key, keySize, value, valueSize);  }  //  // egl_cache_t definition  // -egl_cache_t::egl_cache_t() : -        mInitialized(false) { -} +egl_cache_t::egl_cache_t() : mInitialized(false) {} -egl_cache_t::~egl_cache_t() { -} +egl_cache_t::~egl_cache_t() {}  egl_cache_t egl_cache_t::sCache; @@ -76,7 +68,7 @@ egl_cache_t* egl_cache_t::get() {      return &sCache;  } -void egl_cache_t::initialize(egl_display_t *display) { +void egl_cache_t::initialize(egl_display_t* display) {      std::lock_guard<std::mutex> lock(mMutex);      egl_connection_t* const cnx = &gEGLImpl; @@ -85,28 +77,26 @@ void egl_cache_t::initialize(egl_display_t *display) {          size_t bcExtLen = strlen(BC_EXT_STR);          size_t extsLen = strlen(exts);          bool equal = !strcmp(BC_EXT_STR, exts); -        bool atStart = !strncmp(BC_EXT_STR " ", exts, bcExtLen+1); -        bool atEnd = (bcExtLen+1) < extsLen && -                !strcmp(" " BC_EXT_STR, exts + extsLen - (bcExtLen+1)); +        bool atStart = !strncmp(BC_EXT_STR " ", exts, bcExtLen + 1); +        bool atEnd = (bcExtLen + 1) < extsLen && +                !strcmp(" " BC_EXT_STR, exts + extsLen - (bcExtLen + 1));          bool inMiddle = strstr(exts, " " BC_EXT_STR " ") != nullptr;          if (equal || atStart || atEnd || inMiddle) {              PFNEGLSETBLOBCACHEFUNCSANDROIDPROC eglSetBlobCacheFuncsANDROID; -            eglSetBlobCacheFuncsANDROID = -                    reinterpret_cast<PFNEGLSETBLOBCACHEFUNCSANDROIDPROC>( -                            cnx->egl.eglGetProcAddress( -                                    "eglSetBlobCacheFuncsANDROID")); +            eglSetBlobCacheFuncsANDROID = reinterpret_cast<PFNEGLSETBLOBCACHEFUNCSANDROIDPROC>( +                    cnx->egl.eglGetProcAddress("eglSetBlobCacheFuncsANDROID"));              if (eglSetBlobCacheFuncsANDROID == nullptr) {                  ALOGE("EGL_ANDROID_blob_cache advertised, " -                        "but unable to get eglSetBlobCacheFuncsANDROID"); +                      "but unable to get eglSetBlobCacheFuncsANDROID");                  return;              } -            eglSetBlobCacheFuncsANDROID(display->disp.dpy, -                    android::setBlob, android::getBlob); +            eglSetBlobCacheFuncsANDROID(display->disp.dpy, android::setBlob, android::getBlob);              EGLint err = cnx->egl.eglGetError();              if (err != EGL_SUCCESS) {                  ALOGE("eglSetBlobCacheFuncsANDROID resulted in an error: " -                        "%#x", err); +                      "%#x", +                      err);              }          }      } @@ -122,8 +112,8 @@ void egl_cache_t::terminate() {      mBlobCache = nullptr;  } -void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize, -        const void* value, EGLsizeiANDROID valueSize) { +void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize, const void* value, +                          EGLsizeiANDROID valueSize) {      std::lock_guard<std::mutex> lock(mMutex);      if (keySize < 0 || valueSize < 0) { @@ -150,8 +140,8 @@ void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize,      }  } -EGLsizeiANDROID egl_cache_t::getBlob(const void* key, EGLsizeiANDROID keySize, -        void* value, EGLsizeiANDROID valueSize) { +EGLsizeiANDROID egl_cache_t::getBlob(const void* key, EGLsizeiANDROID keySize, void* value, +                                     EGLsizeiANDROID valueSize) {      std::lock_guard<std::mutex> lock(mMutex);      if (keySize < 0 || valueSize < 0) { @@ -178,6 +168,4 @@ BlobCache* egl_cache_t::getBlobCacheLocked() {      return mBlobCache.get();  } -// ----------------------------------------------------------------------------  }; // namespace android -// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/egl_cache.h b/opengl/libs/EGL/egl_cache.h index 7382b913fa..d10a6154b7 100644 --- a/opengl/libs/EGL/egl_cache.h +++ b/opengl/libs/EGL/egl_cache.h @@ -20,21 +20,18 @@  #include <EGL/egl.h>  #include <EGL/eglext.h> -#include "FileBlobCache.h" -  #include <memory>  #include <mutex>  #include <string> -// ---------------------------------------------------------------------------- +#include "FileBlobCache.h" +  namespace android { -// ----------------------------------------------------------------------------  class egl_display_t;  class EGLAPI egl_cache_t {  public: -      // get returns a pointer to the singleton egl_cache_t object.  This      // singleton object will never be destroyed.      static egl_cache_t* get(); @@ -117,8 +114,6 @@ private:      static egl_cache_t sCache;  }; -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif // ANDROID_EGL_CACHE_H diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index 3b1cf712a2..0b755aadca 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -14,49 +14,41 @@   ** limitations under the License.   */ -#define __STDC_LIMIT_MACROS 1  #define ATRACE_TAG ATRACE_TAG_GRAPHICS  #include "egl_display.h" -#include "../egl_impl.h" - -#include <EGL/eglext_angle.h> -#include <private/EGL/display.h> - -#include "Loader.h" -#include "egl_angle_platform.h" -#include "egl_cache.h" -#include "egl_object.h" -#include "egl_tls.h" -  #include <SurfaceFlingerProperties.h>  #include <android-base/properties.h>  #include <android/dlext.h> +#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> +#include <configstore/Utils.h>  #include <dlfcn.h>  #include <graphicsenv/GraphicsEnv.h> -#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> -#include <configstore/Utils.h> +#include "../egl_impl.h" +#include "EGL/eglext_angle.h" +#include "Loader.h" +#include "egl_angle_platform.h" +#include "egl_cache.h" +#include "egl_object.h" +#include "egl_tls.h" +#include "private/EGL/display.h"  using namespace android::hardware::configstore;  using namespace android::hardware::configstore::V1_0; -// ----------------------------------------------------------------------------  namespace android { -// ---------------------------------------------------------------------------- - -static char const * const sVendorString     = "Android"; -static char const* const sVersionString14 = "1.4 Android META-EGL"; -static char const* const sVersionString15 = "1.5 Android META-EGL"; -static char const * const sClientApiString  = "OpenGL_ES"; -extern char const * const gBuiltinExtensionString; -extern char const * const gExtensionString; +static const char* const sVendorString = "Android"; +static const char* const sVersionString14 = "1.4 Android META-EGL"; +static const char* const sVersionString15 = "1.5 Android META-EGL"; +static const char* const sClientApiString = "OpenGL_ES"; -extern void setGLHooksThreadSpecific(gl_hooks_t const *value); +extern const char* const gBuiltinExtensionString; +extern const char* const gExtensionString; -// ---------------------------------------------------------------------------- +extern void setGLHooksThreadSpecific(gl_hooks_t const* value);  bool findExtension(const char* exts, const char* name, size_t nameLen) {      if (exts) { @@ -82,11 +74,15 @@ int egl_get_init_count(EGLDisplay dpy) {      return eglDisplay ? eglDisplay->getRefsCount() : 0;  } -egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS]; +std::map<EGLDisplay, std::unique_ptr<egl_display_t>> egl_display_t::displayMap; +std::mutex egl_display_t::displayMapLock; -egl_display_t::egl_display_t() : -    magic('_dpy'), finishOnSwap(false), traceGpuCompletion(false), refs(0), eglIsInitialized(false) { -} +egl_display_t::egl_display_t() +      : magic('_dpy'), +        finishOnSwap(false), +        traceGpuCompletion(false), +        refs(0), +        eglIsInitialized(false) {}  egl_display_t::~egl_display_t() {      magic = 0; @@ -98,11 +94,12 @@ egl_display_t* egl_display_t::get(EGLDisplay dpy) {          return nullptr;      } -    uintptr_t index = uintptr_t(dpy)-1U; -    if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { +    const std::lock_guard<std::mutex> lock(displayMapLock); +    auto search = displayMap.find(dpy); +    if (search == displayMap.end() || !search->second->isValid()) {          return nullptr;      } -    return &sDisplay[index]; +    return search->second.get();  }  void egl_display_t::addObject(egl_object_t* object) { @@ -128,10 +125,9 @@ bool egl_display_t::getObject(egl_object_t* object) const {  EGLDisplay egl_display_t::getFromNativeDisplay(EGLNativeDisplayType disp,                                                 const EGLAttrib* attrib_list) { -    if (uintptr_t(disp) >= NUM_DISPLAYS) -        return nullptr; +    if (uintptr_t(disp) >= NUM_DISPLAYS) return nullptr; -    return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list); +    return getPlatformDisplay(disp, attrib_list);  }  static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx, @@ -147,6 +143,16 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn                  attrs.push_back(attr[1]);              }          } +        const auto& eglFeatures = GraphicsEnv::getInstance().getAngleEglFeatures(); +        std::vector<const char*> features; +        if (eglFeatures.size() > 0) { +            for (const std::string& eglFeature : eglFeatures) { +                features.push_back(eglFeature.c_str()); +            } +            features.push_back(0); +            attrs.push_back(EGL_FEATURE_OVERRIDES_ENABLED_ANGLE); +            attrs.push_back(reinterpret_cast<EGLAttrib>(features.data())); +        }          attrs.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);          attrs.push_back(EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE); @@ -176,7 +182,6 @@ static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_conn  EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display,                                               const EGLAttrib* attrib_list) { -    std::lock_guard<std::mutex> _l(lock);      ATRACE_CALL();      // get our driver loader @@ -204,7 +209,7 @@ EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display,              // It is possible that eglGetPlatformDisplay does not have a              // working implementation for Android platform; in that case,              // one last fallback to eglGetDisplay -            if(dpy == EGL_NO_DISPLAY) { +            if (dpy == EGL_NO_DISPLAY) {                  if (attrib_list) {                      ALOGW("getPlatformDisplay: unexpected attribute list, attributes ignored");                  } @@ -212,17 +217,23 @@ EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display,              }          } -        disp.dpy = dpy;          if (dpy == EGL_NO_DISPLAY) {              loader.close(cnx); +        } else { +            const std::lock_guard<std::mutex> lock(displayMapLock); +            if (displayMap.find(dpy) == displayMap.end()) { +                auto d = std::make_unique<egl_display_t>(); +                d->disp.dpy = dpy; +                displayMap[dpy] = std::move(d); +            } +            return dpy;          }      } -    return EGLDisplay(uintptr_t(display) + 1U); +    return nullptr;  } -EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { - +EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) {      { // scope for refLock          std::unique_lock<std::mutex> _l(refLock);          refs++; @@ -230,7 +241,7 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {              // We don't know what to report until we know what the              // driver supports. Make sure we are initialized before              // returning the version info. -            while(!eglIsInitialized) { +            while (!eglIsInitialized) {                  refCond.wait(_l);              }              egl_connection_t* const cnx = &gEGLImpl; @@ -243,7 +254,7 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {              if (minor != nullptr) *minor = cnx->minor;              return EGL_TRUE;          } -        while(eglIsInitialized) { +        while (eglIsInitialized) {              refCond.wait(_l);          }      } @@ -263,40 +274,31 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {          if (cnx->dso) {              EGLDisplay idpy = disp.dpy;              if (cnx->egl.eglInitialize(idpy, &cnx->major, &cnx->minor)) { -                //ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p", +                // ALOGD("initialized dpy=%p, ver=%d.%d, cnx=%p",                  //        idpy, cnx->major, cnx->minor, cnx);                  // display is now initialized                  disp.state = egl_display_t::INITIALIZED;                  // get the query-strings for this display for each implementation -                disp.queryString.vendor = cnx->egl.eglQueryString(idpy, -                        EGL_VENDOR); -                disp.queryString.version = cnx->egl.eglQueryString(idpy, -                        EGL_VERSION); -                disp.queryString.extensions = cnx->egl.eglQueryString(idpy, -                        EGL_EXTENSIONS); -                disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, -                        EGL_CLIENT_APIS); +                disp.queryString.vendor = cnx->egl.eglQueryString(idpy, EGL_VENDOR); +                disp.queryString.version = cnx->egl.eglQueryString(idpy, EGL_VERSION); +                disp.queryString.extensions = cnx->egl.eglQueryString(idpy, EGL_EXTENSIONS); +                disp.queryString.clientApi = cnx->egl.eglQueryString(idpy, EGL_CLIENT_APIS);              } else {                  ALOGW("eglInitialize(%p) failed (%s)", idpy, -                        egl_tls_t::egl_strerror(cnx->egl.eglGetError())); +                      egl_tls_t::egl_strerror(cnx->egl.eglGetError()));              }          }          if (cnx->minor == 5) {              // full list in egl_entries.in -            if (!cnx->egl.eglCreateImage || -                !cnx->egl.eglDestroyImage || -                !cnx->egl.eglGetPlatformDisplay || -                !cnx->egl.eglCreatePlatformWindowSurface || -                !cnx->egl.eglCreatePlatformPixmapSurface || -                !cnx->egl.eglCreateSync || -                !cnx->egl.eglDestroySync || -                !cnx->egl.eglClientWaitSync || -                !cnx->egl.eglGetSyncAttrib || -                !cnx->egl.eglWaitSync) { +            if (!cnx->egl.eglCreateImage || !cnx->egl.eglDestroyImage || +                !cnx->egl.eglGetPlatformDisplay || !cnx->egl.eglCreatePlatformWindowSurface || +                !cnx->egl.eglCreatePlatformPixmapSurface || !cnx->egl.eglCreateSync || +                !cnx->egl.eglDestroySync || !cnx->egl.eglClientWaitSync || +                !cnx->egl.eglGetSyncAttrib || !cnx->egl.eglWaitSync) {                  ALOGE("Driver indicates EGL 1.5 support, but does not have "                        "a critical API");                  cnx->minor = 4; @@ -391,7 +393,6 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) {  }  EGLBoolean egl_display_t::terminate() { -      { // scope for refLock          std::unique_lock<std::mutex> _rl(refLock);          if (refs == 0) { @@ -424,7 +425,7 @@ EGLBoolean egl_display_t::terminate() {              }              if (cnx->egl.eglTerminate(disp.dpy) == EGL_FALSE) {                  ALOGW("eglTerminate(%p) failed (%s)", disp.dpy, -                        egl_tls_t::egl_strerror(cnx->egl.eglGetError())); +                      egl_tls_t::egl_strerror(cnx->egl.eglGetError()));              }              // REVISIT: it's unclear what to do if eglTerminate() fails              disp.state = egl_display_t::TERMINATED; @@ -457,8 +458,7 @@ EGLBoolean egl_display_t::terminate() {      return res;  } -void egl_display_t::loseCurrent(egl_context_t * cur_c) -{ +void egl_display_t::loseCurrent(egl_context_t* cur_c) {      if (cur_c) {          egl_display_t* display = cur_c->getDisplay();          if (display) { @@ -467,8 +467,7 @@ void egl_display_t::loseCurrent(egl_context_t * cur_c)      }  } -void egl_display_t::loseCurrentImpl(egl_context_t * cur_c) -{ +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); @@ -478,7 +477,6 @@ void egl_display_t::loseCurrentImpl(egl_context_t * cur_c)      { // scope for the lock          std::lock_guard<std::mutex> _l(lock);          cur_c->onLooseCurrent(); -      }      // This cannot be called with the lock held because it might end-up @@ -489,10 +487,9 @@ void egl_display_t::loseCurrentImpl(egl_context_t * cur_c)      _cur_d.release();  } -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 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;      // by construction, these are either 0 or valid (possibly terminated) @@ -504,14 +501,12 @@ EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c,      { // scope for the lock          std::lock_guard<std::mutex> _l(lock);          if (c) { -            result = c->cnx->egl.eglMakeCurrent( -                    disp.dpy, impl_draw, impl_read, impl_ctx); +            result = c->cnx->egl.eglMakeCurrent(disp.dpy, impl_draw, impl_read, impl_ctx);              if (result == EGL_TRUE) {                  c->onMakeCurrent(draw, read);              }          } else { -            result = cur_c->cnx->egl.eglMakeCurrent( -                    disp.dpy, impl_draw, impl_read, impl_ctx); +            result = cur_c->cnx->egl.eglMakeCurrent(disp.dpy, impl_draw, impl_read, impl_ctx);              if (result == EGL_TRUE) {                  cur_c->onLooseCurrent();              } @@ -537,6 +532,23 @@ bool egl_display_t::haveExtension(const char* name, size_t nameLen) const {      return findExtension(mExtensionString.c_str(), name, nameLen);  } -// ---------------------------------------------------------------------------- +egl_display_t* validate_display(EGLDisplay dpy) { +    egl_display_t* const dp = get_display(dpy); +    if (!dp) return setError(EGL_BAD_DISPLAY, (egl_display_t*)nullptr); +    if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (egl_display_t*)nullptr); + +    return dp; +} + +egl_display_t* validate_display_connection(EGLDisplay dpy, egl_connection_t** outCnx) { +    *outCnx = nullptr; +    egl_display_t* dp = validate_display(dpy); +    if (!dp) return dp; +    *outCnx = &gEGLImpl; +    if ((*outCnx)->dso == nullptr) { +        return setError(EGL_BAD_CONFIG, (egl_display_t*)nullptr); +    } +    return dp; +} +  }; // namespace android -// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/egl_display.h b/opengl/libs/EGL/egl_display.h index e117314d71..87c2176045 100644 --- a/opengl/libs/EGL/egl_display.h +++ b/opengl/libs/EGL/egl_display.h @@ -17,26 +17,22 @@  #ifndef ANDROID_EGL_DISPLAY_H  #define ANDROID_EGL_DISPLAY_H - -#include <stdint.h> +#include <EGL/egl.h> +#include <EGL/eglext.h>  #include <stddef.h> +#include <stdint.h>  #include <condition_variable> +#include <map> +#include <memory>  #include <mutex>  #include <string>  #include <unordered_set> -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include <cutils/compiler.h> - -#include "egldefs.h"  #include "../hooks.h" +#include "egldefs.h" -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  class egl_object_t;  class egl_context_t; @@ -45,25 +41,25 @@ struct egl_connection_t;  bool findExtension(const char* exts, const char* name, size_t nameLen = 0);  bool needsAndroidPEglMitigation(); -// ---------------------------------------------------------------------------- -  class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes -    static egl_display_t sDisplay[NUM_DISPLAYS]; +    static std::map<EGLDisplay, std::unique_ptr<egl_display_t>> displayMap; +    static std::mutex displayMapLock;      EGLDisplay getDisplay(EGLNativeDisplayType display); -    EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, const EGLAttrib* attrib_list); -    void loseCurrentImpl(egl_context_t * cur_c); +    static EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, +                                         const EGLAttrib* attrib_list); +    void loseCurrentImpl(egl_context_t* cur_c);  public:      enum {          NOT_INITIALIZED = 0, -        INITIALIZED     = 1, -        TERMINATED      = 2 +        INITIALIZED = 1, +        TERMINATED = 2,      };      egl_display_t();      ~egl_display_t(); -    EGLBoolean initialize(EGLint *major, EGLint *minor); +    EGLBoolean initialize(EGLint* major, EGLint* minor);      EGLBoolean terminate();      // add object to this display's list @@ -76,123 +72,69 @@ public:      static egl_display_t* get(EGLDisplay dpy);      static EGLDisplay getFromNativeDisplay(EGLNativeDisplayType disp, const EGLAttrib* attrib_list); -    EGLBoolean 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); -    static void loseCurrent(egl_context_t * cur_c); +    EGLBoolean 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); +    static void loseCurrent(egl_context_t* cur_c);      inline bool isReady() const { return (refs > 0); }      inline bool isValid() const { return magic == '_dpy'; }      inline bool isAlive() const { return isValid(); } -    char const * getVendorString() const { return mVendorString.c_str(); } -    char const * getVersionString() const { return mVersionString.c_str(); } -    char const * getClientApiString() const { return mClientApiString.c_str(); } -    char const * getExtensionString() const { return mExtensionString.c_str(); } +    char const* getVendorString() const { return mVendorString.c_str(); } +    char const* getVersionString() const { return mVersionString.c_str(); } +    char const* getClientApiString() const { return mClientApiString.c_str(); } +    char const* getExtensionString() const { return mExtensionString.c_str(); }      bool haveExtension(const char* name, size_t nameLen = 0) const;      inline uint32_t getRefsCount() const { return refs; }      struct strings_t { -        char const * vendor; -        char const * version; -        char const * clientApi; -        char const * extensions; +        char const* vendor; +        char const* version; +        char const* clientApi; +        char const* extensions;      };      struct DisplayImpl { -        DisplayImpl() : dpy(EGL_NO_DISPLAY), state(NOT_INITIALIZED) { } -        EGLDisplay  dpy; -        EGLint      state; -        strings_t   queryString; +        DisplayImpl() : dpy(EGL_NO_DISPLAY), state(NOT_INITIALIZED) {} +        EGLDisplay dpy; +        EGLint state; +        strings_t queryString;      };  private: -    uint32_t        magic; - -public: -    DisplayImpl     disp; -    bool    finishOnSwap;       // property: debug.egl.finish -    bool    traceGpuCompletion; // property: debug.egl.traceGpuCompletion -    bool    hasColorSpaceSupport; - -private: -    friend class egl_display_ptr; - -            uint32_t                    refs; -            bool                        eglIsInitialized; -    mutable std::mutex                  lock; -    mutable std::mutex                  refLock; -    mutable std::condition_variable     refCond; -            std::unordered_set<egl_object_t*> objects; -            std::string mVendorString; -            std::string mVersionString; -            std::string mClientApiString; -            std::string mExtensionString; -}; - -// ---------------------------------------------------------------------------- +    uint32_t magic; -// An egl_display_ptr is a kind of smart pointer for egl_display_t objects. -// It doesn't refcount the egl_display_t, but does ensure that the underlying -// EGL implementation is "awake" (not hibernating) and ready for use as long -// as the egl_display_ptr exists. -class egl_display_ptr {  public: -    explicit egl_display_ptr(egl_display_t* dpy): mDpy(dpy) {} - -    // We only really need a C++11 move constructor, not a copy constructor. -    // A move constructor would save an enter()/leave() pair on every EGL API -    // call. But enabling -std=c++0x causes lots of errors elsewhere, so I -    // can't use a move constructor until those are cleaned up. -    // -    // egl_display_ptr(egl_display_ptr&& other) { -    //     mDpy = other.mDpy; -    //     other.mDpy = NULL; -    // } -    // -    egl_display_ptr(const egl_display_ptr& other): mDpy(other.mDpy) {} - -    ~egl_display_ptr() {} - -    const egl_display_t* operator->() const { return mDpy; } -          egl_display_t* operator->()       { return mDpy; } - -    const egl_display_t* get() const { return mDpy; } -          egl_display_t* get()       { return mDpy; } - -    operator bool() const { return mDpy != nullptr; } +    DisplayImpl disp; +    bool finishOnSwap;       // property: debug.egl.finish +    bool traceGpuCompletion; // property: debug.egl.traceGpuCompletion +    bool hasColorSpaceSupport;  private: -    egl_display_t* mDpy; - -    // non-assignable -    egl_display_ptr& operator=(const egl_display_ptr&); +    uint32_t refs; +    bool eglIsInitialized; +    mutable std::mutex lock; +    mutable std::mutex refLock; +    mutable std::condition_variable refCond; +    std::unordered_set<egl_object_t*> objects; +    std::string mVendorString; +    std::string mVersionString; +    std::string mClientApiString; +    std::string mExtensionString;  }; -// ---------------------------------------------------------------------------- - -inline egl_display_ptr get_display(EGLDisplay dpy) { -    return egl_display_ptr(egl_display_t::get(dpy)); -} - -// Does not ensure EGL is unhibernated. Use with caution: calls into the -// underlying EGL implementation are not safe. -inline egl_display_t* get_display_nowake(EGLDisplay dpy) { +inline egl_display_t* get_display(EGLDisplay dpy) {      return egl_display_t::get(dpy);  } -// ---------------------------------------------------------------------------- - -egl_display_ptr validate_display(EGLDisplay dpy); -egl_display_ptr validate_display_connection(EGLDisplay dpy, -        egl_connection_t*& cnx); +egl_display_t* validate_display(EGLDisplay dpy); +egl_display_t* validate_display_connection(EGLDisplay dpy, egl_connection_t** outCnx);  EGLBoolean validate_display_context(EGLDisplay dpy, EGLContext ctx);  EGLBoolean validate_display_surface(EGLDisplay dpy, EGLSurface surface); -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif // ANDROID_EGL_DISPLAY_H diff --git a/opengl/libs/EGL/egl_entries.in b/opengl/libs/EGL/egl_entries.in index 2921d512f1..1c91f1d61b 100644 --- a/opengl/libs/EGL/egl_entries.in +++ b/opengl/libs/EGL/egl_entries.in @@ -104,11 +104,6 @@ EGL_ENTRY(EGLClientBuffer, eglGetNativeClientBufferANDROID, const AHardwareBuffe  EGL_ENTRY(EGLuint64NV, eglGetSystemTimeFrequencyNV, void)  EGL_ENTRY(EGLuint64NV, eglGetSystemTimeNV, void) -/* IMG extensions */ - -EGL_ENTRY(EGLBoolean, eglHibernateProcessIMG, void) -EGL_ENTRY(EGLBoolean, eglAwakenProcessIMG, void) -  /* Partial update extensions */  EGL_ENTRY(EGLBoolean, eglSwapBuffersWithDamageKHR, EGLDisplay, EGLSurface, EGLint *, EGLint) diff --git a/opengl/libs/EGL/egl_layers.cpp b/opengl/libs/EGL/egl_layers.cpp index ea86c9a05b..9752e382d9 100644 --- a/opengl/libs/EGL/egl_layers.cpp +++ b/opengl/libs/EGL/egl_layers.cpp @@ -85,17 +85,21 @@ const void* getNextLayerProcAddress(void* layer_id, const char* name) {          // Look up which GPA we should use          int gpaIndex = func_indices["eglGetProcAddress"]; -        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) <- using GPA from this index", name, gpaIndex); +        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) <- using GPA from this index", name, +              gpaIndex);          EGLFuncPointer gpaNext = (*next_layer_funcs)[gpaIndex]; -        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) gpaNext(%llu) <- using GPA at this address", name, gpaIndex, (unsigned long long)gpaNext); - +        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) gpaNext(%llu) <- using GPA at this " +              "address", +              name, gpaIndex, (unsigned long long)gpaNext);          // Call it for the requested function          typedef void* (*PFNEGLGETPROCADDRESSPROC)(const char*);          PFNEGLGETPROCADDRESSPROC next = reinterpret_cast<PFNEGLGETPROCADDRESSPROC>(gpaNext);          val = reinterpret_cast<EGLFuncPointer>(next(name)); -        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) gpaNext(%llu) Got back (%llu) from GPA", name, gpaIndex, (unsigned long long)gpaNext, (unsigned long long)val); +        ALOGV("getNextLayerProcAddress - name(%s) gpaIndex(%i) gpaNext(%llu) Got back (%llu) from " +              "GPA", +              name, gpaIndex, (unsigned long long)gpaNext, (unsigned long long)val);          // We should store it now, but to do that, we need to move func_idx to the class so we can          // increment it separately @@ -105,7 +109,9 @@ const void* getNextLayerProcAddress(void* layer_id, const char* name) {      int index = func_indices[name];      val = (*next_layer_funcs)[index]; -    ALOGV("getNextLayerProcAddress - name(%s) index(%i) entry(%llu) - Got a hit, returning known entry", name, index, (unsigned long long)val); +    ALOGV("getNextLayerProcAddress - name(%s) index(%i) entry(%llu) - Got a hit, returning known " +          "entry", +          name, index, (unsigned long long)val);      return reinterpret_cast<void*>(val);  } @@ -117,20 +123,26 @@ void SetupFuncMaps(FunctionTable& functions, char const* const* entries, EGLFunc          // Some names overlap, only fill with initial entry          // This does mean that some indices will not be used          if (func_indices.find(name) == func_indices.end()) { -            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), No entry for func_indices, assigning now", name, func_idx); +            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), No entry for func_indices, assigning " +                  "now", +                  name, func_idx);              func_names[func_idx] = name;              func_indices[name] = func_idx;          } else { -            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), Found entry for func_indices", name, func_idx); +            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), Found entry for func_indices", name, +                  func_idx);          }          // Populate layer_functions once with initial value          // These values will arrive in priority order, starting with platform entries          if (functions[func_idx] == nullptr) { -            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), No entry for functions, assigning (%llu)", name, func_idx, (unsigned long long) *curr); +            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), No entry for functions, assigning " +                  "(%llu)", +                  name, func_idx, (unsigned long long)*curr);              functions[func_idx] = *curr;          } else { -            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), Found entry for functions (%llu)", name, func_idx, (unsigned long long) functions[func_idx]); +            ALOGV("SetupFuncMaps - name(%s), func_idx(%i), Found entry for functions (%llu)", name, +                  func_idx, (unsigned long long)functions[func_idx]);          }          entries++; @@ -380,8 +392,8 @@ void LayerLoader::LoadLayers() {                  auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace();                  if (app_namespace && !android::base::StartsWith(layer, kSystemLayerLibraryDir)) {                      char* error_message = nullptr; -                    dlhandle_ = OpenNativeLibraryInNamespace( -                        app_namespace, layer.c_str(), &native_bridge_, &error_message); +                    dlhandle_ = OpenNativeLibraryInNamespace(app_namespace, layer.c_str(), +                                                             &native_bridge_, &error_message);                      if (!dlhandle_) {                          ALOGE("Failed to load layer %s with error: %s", layer.c_str(),                                error_message); diff --git a/opengl/libs/EGL/egl_layers.h b/opengl/libs/EGL/egl_layers.h index 1e2783fc98..705525d857 100644 --- a/opengl/libs/EGL/egl_layers.h +++ b/opengl/libs/EGL/egl_layers.h @@ -17,19 +17,18 @@  #ifndef ANDROID_EGL_LAYERS_H  #define ANDROID_EGL_LAYERS_H +#include <EGL/egldefs.h> +#include <android/dlext.h> +#include <dlfcn.h> +#include <nativebridge/native_bridge.h> +#include <nativeloader/native_loader.h> +  #include <string>  #include <unordered_map>  #include <vector> -#include <android/dlext.h> -#include <dlfcn.h> - -#include <EGL/egldefs.h>  #include "egl_platform_entries.h" -#include <nativebridge/native_bridge.h> -#include <nativeloader/native_loader.h> -  typedef __eglMustCastToProperFunctionPointerType EGLFuncPointer;  namespace android { @@ -46,8 +45,8 @@ public:      void LoadLayers();      void InitLayers(egl_connection_t*); -    void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*); -    void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*); +    void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); +    void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*);      bool Initialized();      std::string GetDebugLayers(); @@ -59,18 +58,23 @@ public:      std::vector<layer_setup_func> layer_setup_;  private: -    LayerLoader() : layers_loaded_(false), initialized_(false), current_layer_(0), dlhandle_(nullptr), native_bridge_(false){}; +    LayerLoader() +          : layers_loaded_(false), +            initialized_(false), +            current_layer_(0), +            dlhandle_(nullptr), +            native_bridge_(false){};      bool layers_loaded_;      bool initialized_;      unsigned current_layer_;      void* dlhandle_;      bool native_bridge_; -    template<typename Func = void*> +    template <typename Func = void*>      Func GetTrampoline(const char* name) const {          if (native_bridge_) { -            return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline( -                dlhandle_, name, nullptr, 0)); +            return reinterpret_cast<Func>( +                    android::NativeBridgeGetTrampoline(dlhandle_, name, nullptr, 0));          }          return reinterpret_cast<Func>(dlsym(dlhandle_, name));      } diff --git a/opengl/libs/EGL/egl_object.cpp b/opengl/libs/EGL/egl_object.cpp index ff4fe2dd9c..efbe613542 100644 --- a/opengl/libs/EGL/egl_object.cpp +++ b/opengl/libs/EGL/egl_object.cpp @@ -18,19 +18,14 @@  #include <sstream> - -// ----------------------------------------------------------------------------  namespace android { -// ---------------------------------------------------------------------------- -egl_object_t::egl_object_t(egl_display_t* disp) : -    display(disp), count(1) { +egl_object_t::egl_object_t(egl_display_t* disp) : display(disp), count(1) {      // NOTE: this does an implicit incRef      display->addObject(this);  } -egl_object_t::~egl_object_t() { -} +egl_object_t::~egl_object_t() {}  void egl_object_t::terminate() {      // this marks the object as "terminated" @@ -53,8 +48,6 @@ bool egl_object_t::get(egl_display_t const* display, egl_object_t* object) {      return display->getObject(object);  } -// ---------------------------------------------------------------------------- -  egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWindowType win,                               EGLSurface surface, EGLint colorSpace, egl_connection_t const* cnx)        : egl_object_t(dpy), @@ -66,10 +59,10 @@ egl_surface_t::egl_surface_t(egl_display_t* dpy, EGLConfig config, EGLNativeWind          colorSpace(colorSpace),          egl_smpte2086_dirty(false),          egl_cta861_3_dirty(false) { -    egl_smpte2086_metadata.displayPrimaryRed = { EGL_DONT_CARE, EGL_DONT_CARE }; -    egl_smpte2086_metadata.displayPrimaryGreen = { EGL_DONT_CARE, EGL_DONT_CARE }; -    egl_smpte2086_metadata.displayPrimaryBlue = { EGL_DONT_CARE, EGL_DONT_CARE }; -    egl_smpte2086_metadata.whitePoint = { EGL_DONT_CARE, EGL_DONT_CARE }; +    egl_smpte2086_metadata.displayPrimaryRed = {EGL_DONT_CARE, EGL_DONT_CARE}; +    egl_smpte2086_metadata.displayPrimaryGreen = {EGL_DONT_CARE, EGL_DONT_CARE}; +    egl_smpte2086_metadata.displayPrimaryBlue = {EGL_DONT_CARE, EGL_DONT_CARE}; +    egl_smpte2086_metadata.whitePoint = {EGL_DONT_CARE, EGL_DONT_CARE};      egl_smpte2086_metadata.maxLuminance = EGL_DONT_CARE;      egl_smpte2086_metadata.minLuminance = EGL_DONT_CARE;      egl_cta861_3_metadata.maxFrameAverageLightLevel = EGL_DONT_CARE; @@ -89,9 +82,13 @@ egl_surface_t::~egl_surface_t() {  void egl_surface_t::disconnect() {      if (win != nullptr && connected) { -        native_window_set_buffers_format(win, 0); -        if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) { -            ALOGW("EGLNativeWindowType %p disconnect failed", win); +        // NOTE: When using Vulkan backend, the Vulkan runtime makes all the +        // native_window_* calls, so don't do them here. +        if (!cnx->useAngle) { +            native_window_set_buffers_format(win, 0); +            if (native_window_api_disconnect(win, NATIVE_WINDOW_API_EGL)) { +                ALOGW("EGLNativeWindowType %p disconnect failed", win); +            }          }          connected = false;      } @@ -173,16 +170,30 @@ EGLBoolean egl_surface_t::getSmpte2086Metadata(android_smpte2086_metadata& metad          return EGL_FALSE;      } -    metadata.displayPrimaryRed.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.x) / EGL_METADATA_SCALING_EXT; -    metadata.displayPrimaryRed.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.y) / EGL_METADATA_SCALING_EXT; -    metadata.displayPrimaryGreen.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.x) / EGL_METADATA_SCALING_EXT; -    metadata.displayPrimaryGreen.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.y) / EGL_METADATA_SCALING_EXT; -    metadata.displayPrimaryBlue.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.x) / EGL_METADATA_SCALING_EXT; -    metadata.displayPrimaryBlue.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.y) / EGL_METADATA_SCALING_EXT; -    metadata.whitePoint.x = static_cast<float>(egl_smpte2086_metadata.whitePoint.x) / EGL_METADATA_SCALING_EXT; -    metadata.whitePoint.y = static_cast<float>(egl_smpte2086_metadata.whitePoint.y) / EGL_METADATA_SCALING_EXT; -    metadata.maxLuminance = static_cast<float>(egl_smpte2086_metadata.maxLuminance) / EGL_METADATA_SCALING_EXT; -    metadata.minLuminance = static_cast<float>(egl_smpte2086_metadata.minLuminance) / EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryRed.x = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.x) / +            EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryRed.y = static_cast<float>(egl_smpte2086_metadata.displayPrimaryRed.y) / +            EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryGreen.x = +            static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.x) / +            EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryGreen.y = +            static_cast<float>(egl_smpte2086_metadata.displayPrimaryGreen.y) / +            EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryBlue.x = +            static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.x) / +            EGL_METADATA_SCALING_EXT; +    metadata.displayPrimaryBlue.y = +            static_cast<float>(egl_smpte2086_metadata.displayPrimaryBlue.y) / +            EGL_METADATA_SCALING_EXT; +    metadata.whitePoint.x = +            static_cast<float>(egl_smpte2086_metadata.whitePoint.x) / EGL_METADATA_SCALING_EXT; +    metadata.whitePoint.y = +            static_cast<float>(egl_smpte2086_metadata.whitePoint.y) / EGL_METADATA_SCALING_EXT; +    metadata.maxLuminance = +            static_cast<float>(egl_smpte2086_metadata.maxLuminance) / EGL_METADATA_SCALING_EXT; +    metadata.minLuminance = +            static_cast<float>(egl_smpte2086_metadata.minLuminance) / EGL_METADATA_SCALING_EXT;      return EGL_TRUE;  } @@ -196,13 +207,15 @@ EGLBoolean egl_surface_t::getCta8613Metadata(android_cta861_3_metadata& metadata          return EGL_FALSE;      } -    metadata.maxContentLightLevel = static_cast<float>(egl_cta861_3_metadata.maxContentLightLevel) / EGL_METADATA_SCALING_EXT; -    metadata.maxFrameAverageLightLevel = static_cast<float>(egl_cta861_3_metadata.maxFrameAverageLightLevel) / EGL_METADATA_SCALING_EXT; +    metadata.maxContentLightLevel = static_cast<float>(egl_cta861_3_metadata.maxContentLightLevel) / +            EGL_METADATA_SCALING_EXT; +    metadata.maxFrameAverageLightLevel = +            static_cast<float>(egl_cta861_3_metadata.maxFrameAverageLightLevel) / +            EGL_METADATA_SCALING_EXT;      return EGL_TRUE;  } -  EGLBoolean egl_surface_t::getColorSpaceAttribute(EGLint attribute, EGLint* value) const {      if (attribute == EGL_GL_COLORSPACE_KHR) {          *value = colorSpace; @@ -211,7 +224,7 @@ EGLBoolean egl_surface_t::getColorSpaceAttribute(EGLint attribute, EGLint* value      return EGL_FALSE;  } -EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint *value) const { +EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint* value) const {      switch (attribute) {          case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:              *value = egl_smpte2086_metadata.displayPrimaryRed.x; @@ -257,7 +270,7 @@ EGLBoolean egl_surface_t::getSmpte2086Attribute(EGLint attribute, EGLint *value)      return EGL_FALSE;  } -EGLBoolean egl_surface_t::getCta8613Attribute(EGLint attribute, EGLint *value) const { +EGLBoolean egl_surface_t::getCta8613Attribute(EGLint attribute, EGLint* value) const {      switch (attribute) {          case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:              *value = egl_cta861_3_metadata.maxContentLightLevel; @@ -276,13 +289,16 @@ void egl_surface_t::terminate() {      egl_object_t::terminate();  } -// ---------------------------------------------------------------------------- -  egl_context_t::egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, -        egl_connection_t const* cnx, int version) : -    egl_object_t(get_display_nowake(dpy)), dpy(dpy), context(context), -            config(config), read(nullptr), draw(nullptr), cnx(cnx), version(version) { -} +                             egl_connection_t const* cnx, int version) +      : egl_object_t(get_display(dpy)), +        dpy(dpy), +        context(context), +        config(config), +        read(nullptr), +        draw(nullptr), +        cnx(cnx), +        version(version) {}  void egl_context_t::onLooseCurrent() {      read = nullptr; @@ -297,31 +313,39 @@ void egl_context_t::onMakeCurrent(EGLSurface draw, EGLSurface read) {       * Here we cache the GL_EXTENSIONS string for this context and we       * add the extensions always handled by the wrapper       */ +    if (!gl_extensions.empty()) return; + +    // call the implementation's glGetString(GL_EXTENSIONS) +    const char* exts = (const char*)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); +    if (!exts) return; + +    // If this context is sharing with another context, and the other context was reset +    // e.g. due to robustness failure, this context might also be reset and glGetString can +    // return NULL. +    gl_extensions = exts; +    if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) { +        gl_extensions.insert(0, "GL_EXT_debug_marker "); +        // eglGetProcAddress could return function pointers to these +        // functions while they actually don't work. Fix them now. +        __eglMustCastToProperFunctionPointerType* f; +        f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] +                    ->gl.glInsertEventMarkerEXT; +        if (*f != gl_noop) *f = gl_noop; +        f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] +                    ->gl.glPushGroupMarkerEXT; +        if (*f != gl_noop) *f = gl_noop; +        f = (__eglMustCastToProperFunctionPointerType*)&gEGLImpl.hooks[version] +                    ->gl.glPopGroupMarkerEXT; +        if (*f != gl_noop) *f = gl_noop; +    } -    if (gl_extensions.empty()) { -        // call the implementation's glGetString(GL_EXTENSIONS) -        const char* exts = (const char *)gEGLImpl.hooks[version]->gl.glGetString(GL_EXTENSIONS); - -        // If this context is sharing with another context, and the other context was reset -        // e.g. due to robustness failure, this context might also be reset and glGetString can -        // return NULL. -        if (exts) { -            gl_extensions = exts; -            if (gl_extensions.find("GL_EXT_debug_marker") == std::string::npos) { -                gl_extensions.insert(0, "GL_EXT_debug_marker "); -            } - -            // tokenize the supported extensions for the glGetStringi() wrapper -            std::stringstream ss; -            std::string str; -            ss << gl_extensions; -            while (ss >> str) { -                tokenized_gl_extensions.push_back(str); -            } -        } +    // tokenize the supported extensions for the glGetStringi() wrapper +    std::stringstream ss; +    std::string str; +    ss << gl_extensions; +    while (ss >> str) { +        tokenized_gl_extensions.push_back(str);      }  } -// ----------------------------------------------------------------------------  }; // namespace android -// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/egl_object.h b/opengl/libs/EGL/egl_object.h index fb2bdf4c51..e593b1cf5b 100644 --- a/opengl/libs/EGL/egl_object.h +++ b/opengl/libs/EGL/egl_object.h @@ -17,30 +17,25 @@  #ifndef ANDROID_EGL_OBJECT_H  #define ANDROID_EGL_OBJECT_H -#include <atomic> -#include <stdint.h> -#include <stddef.h> - -#include <string> -#include <vector> -  #include <EGL/egl.h>  #include <EGL/eglext.h> - +#include <log/log.h> +#include <stddef.h> +#include <stdint.h>  #include <system/window.h> -#include <log/log.h> +#include <atomic> +#include <string> +#include <vector>  #include "egl_display.h" -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  class egl_display_t;  class egl_object_t { -    egl_display_t *display; +    egl_display_t* display;      mutable std::atomic_size_t count;  protected: @@ -64,6 +59,7 @@ public:          egl_object_t* ref;          LocalRef() = delete;          LocalRef(const LocalRef* rhs) = delete; +      public:          ~LocalRef();          explicit LocalRef(egl_object_t* rhs); @@ -73,9 +69,7 @@ public:                  ref = native;              }          } -        inline N* get() { -            return static_cast<N*>(ref); -        } +        inline N* get() { return static_cast<N*>(ref); }          void acquire() const;          void release() const;          void terminate(); @@ -84,7 +78,7 @@ public:      friend class LocalRef;  }; -template<typename N, typename T> +template <typename N, typename T>  egl_object_t::LocalRef<N, T>::LocalRef(egl_object_t* rhs) : ref(rhs) {      if (ref) {          ref->incRef(); @@ -92,21 +86,21 @@ egl_object_t::LocalRef<N, T>::LocalRef(egl_object_t* rhs) : ref(rhs) {  }  template <typename N, typename T> -egl_object_t::LocalRef<N,T>::~LocalRef() { +egl_object_t::LocalRef<N, T>::~LocalRef() {      if (ref) {          ref->destroy();      }  }  template <typename N, typename T> -void egl_object_t::LocalRef<N,T>::acquire() const { +void egl_object_t::LocalRef<N, T>::acquire() const {      if (ref) {          ref->incRef();      }  }  template <typename N, typename T> -void egl_object_t::LocalRef<N,T>::release() const { +void egl_object_t::LocalRef<N, T>::release() const {      if (ref) {          if (ref->decRef() == 1) {              // shouldn't happen because this is called from LocalRef @@ -116,7 +110,7 @@ void egl_object_t::LocalRef<N,T>::release() const {  }  template <typename N, typename T> -void egl_object_t::LocalRef<N,T>::terminate() { +void egl_object_t::LocalRef<N, T>::terminate() {      if (ref) {          ref->terminate();      } @@ -128,6 +122,7 @@ class egl_surface_t : public egl_object_t {  protected:      ~egl_surface_t();      void terminate() override; +  public:      typedef egl_object_t::LocalRef<egl_surface_t, EGLSurface> Ref; @@ -151,10 +146,13 @@ public:      // it's not hard to imagine native games accessing them.      EGLSurface surface;      EGLConfig config; +  private:      ANativeWindow* win; +  public:      egl_connection_t const* cnx; +  private:      bool connected;      void disconnect(); @@ -186,14 +184,15 @@ private:      egl_cta861_3_metadata egl_cta861_3_metadata;  }; -class egl_context_t: public egl_object_t { +class egl_context_t : public egl_object_t {  protected:      ~egl_context_t() {} +  public:      typedef egl_object_t::LocalRef<egl_context_t, EGLContext> Ref; -    egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, -            egl_connection_t const* cnx, int version); +    egl_context_t(EGLDisplay dpy, EGLContext context, EGLConfig config, egl_connection_t const* cnx, +                  int version);      void onLooseCurrent();      void onMakeCurrent(EGLSurface draw, EGLSurface read); @@ -209,30 +208,22 @@ public:      std::vector<std::string> tokenized_gl_extensions;  }; -// ---------------------------------------------------------------------------- - -typedef egl_surface_t::Ref  SurfaceRef; -typedef egl_context_t::Ref  ContextRef; +typedef egl_surface_t::Ref SurfaceRef; +typedef egl_context_t::Ref ContextRef; -// ---------------------------------------------------------------------------- - -template<typename NATIVE, typename EGL> +template <typename NATIVE, typename EGL>  static inline NATIVE* egl_to_native_cast(EGL arg) {      return reinterpret_cast<NATIVE*>(arg);  } -static inline -egl_surface_t* get_surface(EGLSurface surface) { +static inline egl_surface_t* get_surface(EGLSurface surface) {      return egl_to_native_cast<egl_surface_t>(surface);  } -static inline -egl_context_t* get_context(EGLContext context) { +static inline egl_context_t* get_context(EGLContext context) {      return egl_to_native_cast<egl_context_t>(context);  } -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif // ANDROID_EGL_OBJECT_H diff --git a/opengl/libs/EGL/egl_platform_entries.cpp b/opengl/libs/EGL/egl_platform_entries.cpp index aa24e8ee68..de36a7aea6 100644 --- a/opengl/libs/EGL/egl_platform_entries.cpp +++ b/opengl/libs/EGL/egl_platform_entries.cpp @@ -18,36 +18,32 @@  #include "egl_platform_entries.h" -#include <ctype.h> -#include <dlfcn.h> -#include <stdlib.h> -#include <string.h> - -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <EGL/eglext_angle.h> -  #include <android-base/properties.h>  #include <android-base/strings.h>  #include <android/hardware_buffer.h> -#include <graphicsenv/GraphicsEnv.h> -#include <private/android/AHardwareBufferHelpers.h> - +#include <ctype.h>  #include <cutils/compiler.h> +#include <dlfcn.h> +#include <graphicsenv/GraphicsEnv.h>  #include <log/log.h> +#include <private/android/AHardwareBufferHelpers.h> +#include <stdlib.h> +#include <string.h>  #include <condition_variable>  #include <deque>  #include <mutex> -#include <unordered_map>  #include <string>  #include <thread> +#include <unordered_map>  #include "../egl_impl.h" - +#include "EGL/egl.h" +#include "EGL/eglext.h" +#include "EGL/eglext_angle.h"  #include "egl_display.h" -#include "egl_object.h"  #include "egl_layers.h" +#include "egl_object.h"  #include "egl_tls.h"  #include "egl_trace.h" @@ -80,71 +76,71 @@ struct extension_map_t {   * NOTE: Both strings MUST have a single space as the last character.   */ -extern char const * const gBuiltinExtensionString; -extern char const * const gExtensionString; +extern const char* const gBuiltinExtensionString; +extern const char* const gExtensionString;  // clang-format off  // Extensions implemented by the EGL wrapper. -char const * const gBuiltinExtensionString = -        "EGL_KHR_get_all_proc_addresses " -        "EGL_ANDROID_presentation_time " -        "EGL_KHR_swap_buffers_with_damage " -        "EGL_ANDROID_get_native_client_buffer " +const char* const gBuiltinExtensionString =          "EGL_ANDROID_front_buffer_auto_refresh "          "EGL_ANDROID_get_frame_timestamps " -        "EGL_EXT_surface_SMPTE2086_metadata " +        "EGL_ANDROID_get_native_client_buffer " +        "EGL_ANDROID_presentation_time "          "EGL_EXT_surface_CTA861_3_metadata " +        "EGL_EXT_surface_SMPTE2086_metadata " +        "EGL_KHR_get_all_proc_addresses " +        "EGL_KHR_swap_buffers_with_damage "          ;  // Allowed list of extensions exposed to applications if implemented in the vendor driver. -char const * const gExtensionString  = -        "EGL_KHR_image "                        // mandatory -        "EGL_KHR_image_base "                   // mandatory +const char* const gExtensionString  = +        "EGL_ANDROID_image_native_buffer "      // mandatory +        "EGL_ANDROID_native_fence_sync "        // strongly recommended +        "EGL_ANDROID_recordable "               // mandatory +        "EGL_EXT_buffer_age "                   // strongly recommended with partial_update +        "EGL_EXT_create_context_robustness "          "EGL_EXT_image_gl_colorspace " -        "EGL_KHR_image_pixmap " -        "EGL_KHR_lock_surface " +        "EGL_EXT_pixel_format_float " +        "EGL_EXT_protected_content " +        "EGL_EXT_yuv_surface " +        "EGL_IMG_context_priority " +        "EGL_KHR_config_attribs " +        "EGL_KHR_create_context " +        "EGL_KHR_create_context_no_error " +        "EGL_KHR_fence_sync "          "EGL_KHR_gl_colorspace " +        "EGL_KHR_gl_renderbuffer_image "          "EGL_KHR_gl_texture_2D_image "          "EGL_KHR_gl_texture_3D_image "          "EGL_KHR_gl_texture_cubemap_image " -        "EGL_KHR_gl_renderbuffer_image " +        "EGL_KHR_image "                        // mandatory +        "EGL_KHR_image_base "                   // mandatory +        "EGL_KHR_image_pixmap " +        "EGL_KHR_lock_surface " +        "EGL_KHR_mutable_render_buffer " +        "EGL_KHR_no_config_context " +        "EGL_KHR_partial_update "               // strongly recommended          "EGL_KHR_reusable_sync " -        "EGL_KHR_fence_sync " -        "EGL_KHR_create_context " -        "EGL_KHR_config_attribs " -        "EGL_KHR_surfaceless_context "          "EGL_KHR_stream " -        "EGL_KHR_stream_fifo " -        "EGL_KHR_stream_producer_eglsurface "          "EGL_KHR_stream_consumer_gltexture "          "EGL_KHR_stream_cross_process_fd " -        "EGL_EXT_create_context_robustness " -        "EGL_NV_system_time " -        "EGL_ANDROID_image_native_buffer "      // mandatory +        "EGL_KHR_stream_fifo " +        "EGL_KHR_stream_producer_eglsurface " +        "EGL_KHR_surfaceless_context "          "EGL_KHR_wait_sync "                    // strongly recommended -        "EGL_ANDROID_recordable "               // mandatory -        "EGL_KHR_partial_update "               // strongly recommended -        "EGL_EXT_pixel_format_float " -        "EGL_EXT_buffer_age "                   // strongly recommended with partial_update -        "EGL_KHR_create_context_no_error " -        "EGL_KHR_mutable_render_buffer " -        "EGL_EXT_yuv_surface " -        "EGL_EXT_protected_content " -        "EGL_IMG_context_priority " -        "EGL_KHR_no_config_context " +        "EGL_NV_context_priority_realtime " +        "EGL_NV_system_time "          ; -char const * const gClientExtensionString = +const char* const gClientExtensionString = +        "EGL_ANDROID_GLES_layers " +        "EGL_ANGLE_platform_angle "          "EGL_EXT_client_extensions "          "EGL_KHR_platform_android " -        "EGL_ANGLE_platform_angle " -        "EGL_ANDROID_GLES_layers"; -// clang-format on +        ;  // extensions not exposed to applications but used by the ANDROID system  //      "EGL_ANDROID_blob_cache "               // strongly recommended -//      "EGL_IMG_hibernate_process "            // optional -//      "EGL_ANDROID_native_fence_sync "        // strongly recommended  //      "EGL_ANDROID_framebuffer_target "       // mandatory for HWC 1.1  /* @@ -154,105 +150,69 @@ char const * const gClientExtensionString =   */  static const extension_map_t sExtensionMap[] = {      // EGL_KHR_lock_surface -    { "eglLockSurfaceKHR", -            (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, -    { "eglUnlockSurfaceKHR", -            (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR }, +    { "eglLockSurfaceKHR", (__eglMustCastToProperFunctionPointerType)&eglLockSurfaceKHR }, +    { "eglUnlockSurfaceKHR", (__eglMustCastToProperFunctionPointerType)&eglUnlockSurfaceKHR },      // EGL_KHR_image, EGL_KHR_image_base -    { "eglCreateImageKHR", -            (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, -    { "eglDestroyImageKHR", -            (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR }, +    { "eglCreateImageKHR", (__eglMustCastToProperFunctionPointerType)&eglCreateImageKHR }, +    { "eglDestroyImageKHR", (__eglMustCastToProperFunctionPointerType)&eglDestroyImageKHR },      // EGL_KHR_reusable_sync, EGL_KHR_fence_sync -    { "eglCreateSyncKHR", -            (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, -    { "eglDestroySyncKHR", -            (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, -    { "eglClientWaitSyncKHR", -            (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, -    { "eglSignalSyncKHR", -            (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, -    { "eglGetSyncAttribKHR", -            (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR }, +    { "eglCreateSyncKHR", (__eglMustCastToProperFunctionPointerType)&eglCreateSyncKHR }, +    { "eglDestroySyncKHR", (__eglMustCastToProperFunctionPointerType)&eglDestroySyncKHR }, +    { "eglClientWaitSyncKHR", (__eglMustCastToProperFunctionPointerType)&eglClientWaitSyncKHR }, +    { "eglSignalSyncKHR", (__eglMustCastToProperFunctionPointerType)&eglSignalSyncKHR }, +    { "eglGetSyncAttribKHR", (__eglMustCastToProperFunctionPointerType)&eglGetSyncAttribKHR },      // EGL_NV_system_time -    { "eglGetSystemTimeFrequencyNV", -            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, -    { "eglGetSystemTimeNV", -            (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV }, +    { "eglGetSystemTimeFrequencyNV", (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeFrequencyNV }, +    { "eglGetSystemTimeNV", (__eglMustCastToProperFunctionPointerType)&eglGetSystemTimeNV },      // EGL_KHR_wait_sync -    { "eglWaitSyncKHR", -            (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR }, +    { "eglWaitSyncKHR", (__eglMustCastToProperFunctionPointerType)&eglWaitSyncKHR },      // EGL_ANDROID_presentation_time -    { "eglPresentationTimeANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID }, +    { "eglPresentationTimeANDROID", (__eglMustCastToProperFunctionPointerType)&eglPresentationTimeANDROID },      // EGL_KHR_swap_buffers_with_damage -    { "eglSwapBuffersWithDamageKHR", -            (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR }, +    { "eglSwapBuffersWithDamageKHR", (__eglMustCastToProperFunctionPointerType)&eglSwapBuffersWithDamageKHR },      // EGL_ANDROID_get_native_client_buffer -    { "eglGetNativeClientBufferANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetNativeClientBufferANDROID }, +    { "eglGetNativeClientBufferANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetNativeClientBufferANDROID },      // EGL_KHR_partial_update -    { "eglSetDamageRegionKHR", -            (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, - -    { "eglCreateStreamKHR", -            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR }, -    { "eglDestroyStreamKHR", -            (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR }, -    { "eglStreamAttribKHR", -            (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR }, -    { "eglQueryStreamKHR", -            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR }, -    { "eglQueryStreamu64KHR", -            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR }, -    { "eglQueryStreamTimeKHR", -            (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR }, -    { "eglCreateStreamProducerSurfaceKHR", -            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR }, -    { "eglStreamConsumerGLTextureExternalKHR", -            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR }, -    { "eglStreamConsumerAcquireKHR", -            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR }, -    { "eglStreamConsumerReleaseKHR", -            (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR }, -    { "eglGetStreamFileDescriptorKHR", -            (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR }, -    { "eglCreateStreamFromFileDescriptorKHR", -            (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR }, +    { "eglSetDamageRegionKHR", (__eglMustCastToProperFunctionPointerType)&eglSetDamageRegionKHR }, + +    { "eglCreateStreamKHR", (__eglMustCastToProperFunctionPointerType)&eglCreateStreamKHR }, +    { "eglDestroyStreamKHR", (__eglMustCastToProperFunctionPointerType)&eglDestroyStreamKHR }, +    { "eglStreamAttribKHR", (__eglMustCastToProperFunctionPointerType)&eglStreamAttribKHR }, +    { "eglQueryStreamKHR", (__eglMustCastToProperFunctionPointerType)&eglQueryStreamKHR }, +    { "eglQueryStreamu64KHR", (__eglMustCastToProperFunctionPointerType)&eglQueryStreamu64KHR }, +    { "eglQueryStreamTimeKHR", (__eglMustCastToProperFunctionPointerType)&eglQueryStreamTimeKHR }, +    { "eglCreateStreamProducerSurfaceKHR", (__eglMustCastToProperFunctionPointerType)&eglCreateStreamProducerSurfaceKHR }, +    { "eglStreamConsumerGLTextureExternalKHR", (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerGLTextureExternalKHR }, +    { "eglStreamConsumerAcquireKHR", (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerAcquireKHR }, +    { "eglStreamConsumerReleaseKHR", (__eglMustCastToProperFunctionPointerType)&eglStreamConsumerReleaseKHR }, +    { "eglGetStreamFileDescriptorKHR", (__eglMustCastToProperFunctionPointerType)&eglGetStreamFileDescriptorKHR }, +    { "eglCreateStreamFromFileDescriptorKHR", (__eglMustCastToProperFunctionPointerType)&eglCreateStreamFromFileDescriptorKHR },      // EGL_ANDROID_get_frame_timestamps -    { "eglGetNextFrameIdANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetNextFrameIdANDROID }, -    { "eglGetCompositorTimingANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingANDROID }, -    { "eglGetCompositorTimingSupportedANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingSupportedANDROID }, -    { "eglGetFrameTimestampsANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID }, -    { "eglGetFrameTimestampSupportedANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampSupportedANDROID }, +    { "eglGetNextFrameIdANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetNextFrameIdANDROID }, +    { "eglGetCompositorTimingANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingANDROID }, +    { "eglGetCompositorTimingSupportedANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetCompositorTimingSupportedANDROID }, +    { "eglGetFrameTimestampsANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampsANDROID }, +    { "eglGetFrameTimestampSupportedANDROID", (__eglMustCastToProperFunctionPointerType)&eglGetFrameTimestampSupportedANDROID },      // EGL_ANDROID_native_fence_sync -    { "eglDupNativeFenceFDANDROID", -            (__eglMustCastToProperFunctionPointerType)&eglDupNativeFenceFDANDROID }, +    { "eglDupNativeFenceFDANDROID", (__eglMustCastToProperFunctionPointerType)&eglDupNativeFenceFDANDROID },  }; +// clang-format on  /*   * These extensions entry-points should not be exposed to applications.   * They're used internally by the Android EGL layer.   */ -#define FILTER_EXTENSIONS(procname) \ -        (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") ||    \ -         !strcmp((procname), "eglHibernateProcessIMG")      ||    \ -         !strcmp((procname), "eglAwakenProcessIMG")) +#define FILTER_EXTENSIONS(procname) (!strcmp((procname), "eglSetBlobCacheFuncsANDROID"))  // accesses protected by sExtensionMapMutex  static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtensionMap; @@ -261,9 +221,8 @@ static std::unordered_map<std::string, int> sGLExtensionSlotMap;  static int sGLExtensionSlot = 0;  static pthread_mutex_t sExtensionMapMutex = PTHREAD_MUTEX_INITIALIZER; -static void(*findProcAddress(const char* name, -        const extension_map_t* map, size_t n))() { -    for (uint32_t i=0 ; i<n ; i++) { +static void (*findProcAddress(const char* name, const extension_map_t* map, size_t n))() { +    for (uint32_t i = 0; i < n; i++) {          if (!strcmp(name, map[i].name)) {              return map[i].address;          } @@ -273,14 +232,17 @@ static void(*findProcAddress(const char* name,  // ---------------------------------------------------------------------------- -extern void setGLHooksThreadSpecific(gl_hooks_t const *value); +extern void setGLHooksThreadSpecific(gl_hooks_t const* value);  extern EGLBoolean egl_init_drivers(); -extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS]; +extern const __eglMustCastToProperFunctionPointerType +        gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS];  extern gl_hooks_t gHooksTrace;  // ---------------------------------------------------------------------------- -static inline EGLContext getContext() { return egl_tls_t::getContext(); } +static inline EGLContext getContext() { +    return egl_tls_t::getContext(); +}  // ---------------------------------------------------------------------------- @@ -313,9 +275,8 @@ EGLDisplay eglGetPlatformDisplayImpl(EGLenum platform, void* native_display,  // Initialization  // ---------------------------------------------------------------------------- -EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint *major, EGLint *minor) -{ -    egl_display_ptr dp = get_display(dpy); +EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint* major, EGLint* minor) { +    egl_display_t* dp = get_display(dpy);      if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      EGLBoolean res = dp->initialize(major, minor); @@ -323,13 +284,12 @@ EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint *major, EGLint *minor)      return res;  } -EGLBoolean eglTerminateImpl(EGLDisplay dpy) -{ +EGLBoolean eglTerminateImpl(EGLDisplay dpy) {      // NOTE: don't unload the drivers b/c some APIs can be called      // after eglTerminate() has been called. eglTerminate() only      // terminates an EGLDisplay, not a EGL itself. -    egl_display_ptr dp = get_display(dpy); +    egl_display_t* dp = get_display(dpy);      if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      EGLBoolean res = dp->terminate(); @@ -341,14 +301,12 @@ EGLBoolean eglTerminateImpl(EGLDisplay dpy)  // configuration  // ---------------------------------------------------------------------------- -EGLBoolean eglGetConfigsImpl(EGLDisplay dpy, -                             EGLConfig *configs, -                             EGLint config_size, EGLint *num_config) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglGetConfigsImpl(EGLDisplay dpy, EGLConfig* configs, EGLint config_size, +                             EGLint* num_config) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    if (num_config==nullptr) { +    if (num_config == nullptr) {          return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);      } @@ -357,96 +315,88 @@ EGLBoolean eglGetConfigsImpl(EGLDisplay dpy,      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso) { -        res = cnx->egl.eglGetConfigs( -                dp->disp.dpy, configs, config_size, num_config); +        res = cnx->egl.eglGetConfigs(dp->disp.dpy, configs, config_size, num_config);      }      return res;  } -EGLBoolean eglChooseConfigImpl( EGLDisplay dpy, const EGLint *attrib_list, -                                EGLConfig *configs, EGLint config_size, -                                EGLint *num_config) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglChooseConfigImpl(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, +                               EGLint config_size, EGLint* num_config) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    if (num_config==nullptr) { +    if (num_config == nullptr) {          return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);      } -    EGLBoolean res = EGL_FALSE;      *num_config = 0;      egl_connection_t* const cnx = &gEGLImpl; -    if (cnx->dso) { -        if (attrib_list) { -            if (base::GetBoolProperty("debug.egl.force_msaa", false)) { -                size_t attribCount = 0; -                EGLint attrib = attrib_list[0]; - -                // Only enable MSAA if the context is OpenGL ES 2.0 and -                // if no caveat is requested -                const EGLint *attribRendererable = nullptr; -                const EGLint *attribCaveat = nullptr; - -                // Count the number of attributes and look for -                // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT -                while (attrib != EGL_NONE) { -                    attrib = attrib_list[attribCount]; -                    switch (attrib) { -                        case EGL_RENDERABLE_TYPE: -                            attribRendererable = &attrib_list[attribCount]; -                            break; -                        case EGL_CONFIG_CAVEAT: -                            attribCaveat = &attrib_list[attribCount]; -                            break; -                        default: -                            break; -                    } -                    attribCount++; -                } - -                if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && -                        (!attribCaveat || attribCaveat[1] != EGL_NONE)) { +    if (!cnx->dso) return EGL_FALSE; + +    if (!attrib_list || !base::GetBoolProperty("debug.egl.force_msaa", false)) +        return cnx->egl.eglChooseConfig(dp->disp.dpy, attrib_list, configs, config_size, +                                        num_config); + +    // Force 4x MSAA +    size_t attribCount = 0; +    EGLint attrib = attrib_list[0]; + +    // Only enable MSAA if the context is OpenGL ES 2.0 and +    // if no caveat is requested +    const EGLint* attribRendererable = nullptr; +    const EGLint* attribCaveat = nullptr; + +    // Count the number of attributes and look for +    // EGL_RENDERABLE_TYPE and EGL_CONFIG_CAVEAT +    while (attrib != EGL_NONE) { +        attrib = attrib_list[attribCount]; +        switch (attrib) { +            case EGL_RENDERABLE_TYPE: +                attribRendererable = &attrib_list[attribCount]; +                break; +            case EGL_CONFIG_CAVEAT: +                attribCaveat = &attrib_list[attribCount]; +                break; +            default: +                break; +        } +        attribCount++; +    } -                    // Insert 2 extra attributes to force-enable MSAA 4x -                    EGLint aaAttribs[attribCount + 4]; -                    aaAttribs[0] = EGL_SAMPLE_BUFFERS; -                    aaAttribs[1] = 1; -                    aaAttribs[2] = EGL_SAMPLES; -                    aaAttribs[3] = 4; +    if (attribRendererable && attribRendererable[1] == EGL_OPENGL_ES2_BIT && +        (!attribCaveat || attribCaveat[1] != EGL_NONE)) { +        // Insert 2 extra attributes to force-enable MSAA 4x +        EGLint aaAttribs[attribCount + 4]; +        aaAttribs[0] = EGL_SAMPLE_BUFFERS; +        aaAttribs[1] = 1; +        aaAttribs[2] = EGL_SAMPLES; +        aaAttribs[3] = 4; -                    memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); +        memcpy(&aaAttribs[4], attrib_list, attribCount * sizeof(EGLint)); -                    EGLint numConfigAA; -                    EGLBoolean resAA = cnx->egl.eglChooseConfig( -                            dp->disp.dpy, aaAttribs, configs, config_size, &numConfigAA); +        EGLint numConfigAA; +        EGLBoolean resAA = cnx->egl.eglChooseConfig(dp->disp.dpy, aaAttribs, configs, config_size, +                                                    &numConfigAA); -                    if (resAA == EGL_TRUE && numConfigAA > 0) { -                        ALOGD("Enabling MSAA 4x"); -                        *num_config = numConfigAA; -                        return resAA; -                    } -                } -            } +        if (resAA == EGL_TRUE && numConfigAA > 0) { +            ALOGD("Enabling MSAA 4x"); +            *num_config = numConfigAA; +            return resAA;          } - -        res = cnx->egl.eglChooseConfig( -                dp->disp.dpy, attrib_list, configs, config_size, num_config);      } -    return res; + +    return cnx->egl.eglChooseConfig(dp->disp.dpy, attrib_list, configs, config_size, num_config);  } -EGLBoolean eglGetConfigAttribImpl(EGLDisplay dpy, EGLConfig config, -        EGLint attribute, EGLint *value) -{ +EGLBoolean eglGetConfigAttribImpl(EGLDisplay dpy, EGLConfig config, EGLint attribute, +                                  EGLint* value) {      egl_connection_t* cnx = nullptr; -    const egl_display_ptr dp = validate_display_connection(dpy, cnx); +    const egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (!dp) return EGL_FALSE; -    return cnx->egl.eglGetConfigAttrib( -            dp->disp.dpy, config, attribute, value); +    return cnx->egl.eglGetConfigAttrib(dp->disp.dpy, config, attribute, value);  }  // ---------------------------------------------------------------------------- @@ -484,7 +434,7 @@ static EGLint getReportedColorSpace(EGLint colorspace) {  }  // Returns a list of color spaces understood by the vendor EGL driver. -static std::vector<EGLint> getDriverColorSpaces(egl_display_ptr dp) { +static std::vector<EGLint> getDriverColorSpaces(egl_display_t* dp) {      std::vector<EGLint> colorSpaces;      // sRGB and linear are always supported when color space support is present. @@ -509,7 +459,8 @@ static std::vector<EGLint> getDriverColorSpaces(egl_display_ptr dp) {      if (findExtension(dp->disp.queryString.extensions, "EGL_EXT_gl_colorspace_display_p3_linear")) {          colorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_LINEAR_EXT);      } -    if (findExtension(dp->disp.queryString.extensions, "EGL_EXT_gl_colorspace_display_p3_passthrough")) { +    if (findExtension(dp->disp.queryString.extensions, +                      "EGL_EXT_gl_colorspace_display_p3_passthrough")) {          colorSpaces.push_back(EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT);      }      return colorSpaces; @@ -519,7 +470,7 @@ static std::vector<EGLint> getDriverColorSpaces(egl_display_ptr dp) {  // If there is no color space attribute in attrib_list, colorSpace is left  // unmodified.  template <typename AttrType> -static EGLBoolean processAttributes(egl_display_ptr dp, ANativeWindow* window, +static EGLBoolean processAttributes(egl_display_t* dp, ANativeWindow* window,                                      const AttrType* attrib_list, EGLint* colorSpace,                                      std::vector<AttrType>* strippedAttribList) {      for (const AttrType* attr = attrib_list; attr && attr[0] != EGL_NONE; attr += 2) { @@ -699,7 +650,7 @@ EGLBoolean sendSurfaceMetadata(egl_surface_t* s) {  }  template <typename AttrType, typename CreateFuncType> -EGLSurface eglCreateWindowSurfaceTmpl(egl_display_ptr dp, egl_connection_t* cnx, EGLConfig config, +EGLSurface eglCreateWindowSurfaceTmpl(egl_display_t* dp, egl_connection_t* cnx, EGLConfig config,                                        ANativeWindow* window, const AttrType* attrib_list,                                        CreateFuncType createWindowSurfaceFunc) {      const AttrType* origAttribList = attrib_list; @@ -768,7 +719,7 @@ EGLSurface eglCreateWindowSurfaceTmpl(egl_display_ptr dp, egl_connection_t* cnx,      EGLSurface surface = createWindowSurfaceFunc(iDpy, config, window, attrib_list);      if (surface != EGL_NO_SURFACE) { -        egl_surface_t* s = new egl_surface_t(dp.get(), config, window, surface, +        egl_surface_t* s = new egl_surface_t(dp, config, window, surface,                                               getReportedColorSpace(colorSpace), cnx);          return s;      } @@ -789,8 +740,8 @@ typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEPROC)(  EGLSurface eglCreateWindowSurfaceImpl(EGLDisplay dpy, EGLConfig config, NativeWindowType window,                                        const EGLint* attrib_list) { -    egl_connection_t* cnx = NULL; -    egl_display_ptr dp = validate_display_connection(dpy, cnx); +    egl_connection_t* cnx = nullptr; +    egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (dp) {          return eglCreateWindowSurfaceTmpl<                  EGLint, PFNEGLCREATEWINDOWSURFACEPROC>(dp, cnx, config, window, attrib_list, @@ -801,8 +752,8 @@ EGLSurface eglCreateWindowSurfaceImpl(EGLDisplay dpy, EGLConfig config, NativeWi  EGLSurface eglCreatePlatformWindowSurfaceImpl(EGLDisplay dpy, EGLConfig config, void* native_window,                                                const EGLAttrib* attrib_list) { -    egl_connection_t* cnx = NULL; -    egl_display_ptr dp = validate_display_connection(dpy, cnx); +    egl_connection_t* cnx = nullptr; +    egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (dp) {          if (cnx->driverVersion >= EGL_MAKE_VERSION(1, 5, 0)) {              if (cnx->egl.eglCreatePlatformWindowSurface) { @@ -842,8 +793,8 @@ EGLSurface eglCreatePlatformPixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config      // belongs to the Android platform. Any such call fails and generates      // an EGL_BAD_PARAMETER error. -    egl_connection_t* cnx = NULL; -    egl_display_ptr dp = validate_display_connection(dpy, cnx); +    egl_connection_t* cnx = nullptr; +    const egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (dp) {          return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);      } @@ -853,7 +804,7 @@ EGLSurface eglCreatePlatformPixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config  EGLSurface eglCreatePixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config*/,                                        NativePixmapType /*pixmap*/, const EGLint* /*attrib_list*/) {      egl_connection_t* cnx = nullptr; -    egl_display_ptr dp = validate_display_connection(dpy, cnx); +    const egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (dp) {          return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);      } @@ -863,36 +814,33 @@ EGLSurface eglCreatePixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config*/,  EGLSurface eglCreatePbufferSurfaceImpl(EGLDisplay dpy, EGLConfig config,                                         const EGLint* attrib_list) {      egl_connection_t* cnx = nullptr; -    egl_display_ptr dp = validate_display_connection(dpy, cnx); -    if (dp) { -        EGLDisplay iDpy = dp->disp.dpy; -        android_pixel_format format; -        getNativePixelFormat(iDpy, cnx, config, &format); - -        // Select correct colorspace based on user's attribute list -        EGLint colorSpace = EGL_UNKNOWN; -        std::vector<EGLint> strippedAttribList; -        if (!processAttributes(dp, nullptr, attrib_list, &colorSpace, &strippedAttribList)) { -            ALOGE("error invalid colorspace: %d", colorSpace); -            return EGL_NO_SURFACE; -        } -        attrib_list = strippedAttribList.data(); +    egl_display_t* dp = validate_display_connection(dpy, &cnx); +    if (!dp) return EGL_NO_SURFACE; -        EGLSurface surface = cnx->egl.eglCreatePbufferSurface(dp->disp.dpy, config, attrib_list); -        if (surface != EGL_NO_SURFACE) { -            egl_surface_t* s = new egl_surface_t(dp.get(), config, nullptr, surface, -                                                 getReportedColorSpace(colorSpace), cnx); -            return s; -        } +    EGLDisplay iDpy = dp->disp.dpy; +    android_pixel_format format; +    getNativePixelFormat(iDpy, cnx, config, &format); + +    // Select correct colorspace based on user's attribute list +    EGLint colorSpace = EGL_UNKNOWN; +    std::vector<EGLint> strippedAttribList; +    if (!processAttributes(dp, nullptr, attrib_list, &colorSpace, &strippedAttribList)) { +        ALOGE("error invalid colorspace: %d", colorSpace); +        return EGL_NO_SURFACE;      } -    return EGL_NO_SURFACE; +    attrib_list = strippedAttribList.data(); + +    EGLSurface surface = cnx->egl.eglCreatePbufferSurface(iDpy, config, attrib_list); +    if (surface == EGL_NO_SURFACE) return surface; + +    return new egl_surface_t(dp, config, nullptr, surface, getReportedColorSpace(colorSpace), cnx);  }  EGLBoolean eglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surface) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      egl_surface_t* const s = get_surface(surface); @@ -905,10 +853,10 @@ EGLBoolean eglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surface) {  EGLBoolean eglQuerySurfaceImpl(EGLDisplay dpy, EGLSurface surface, EGLint attribute,                                 EGLint* value) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      egl_surface_t const* const s = get_surface(surface); @@ -923,12 +871,12 @@ EGLBoolean eglQuerySurfaceImpl(EGLDisplay dpy, EGLSurface surface, EGLint attrib  }  void EGLAPI eglBeginFrameImpl(EGLDisplay dpy, EGLSurface surface) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return;      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          setError(EGL_BAD_SURFACE, EGL_FALSE);      } @@ -938,14 +886,13 @@ void EGLAPI eglBeginFrameImpl(EGLDisplay dpy, EGLSurface surface) {  // Contexts  // ---------------------------------------------------------------------------- -EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config, -                                EGLContext share_list, const EGLint *attrib_list) -{ +EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config, EGLContext share_list, +                                const EGLint* attrib_list) {      egl_connection_t* cnx = nullptr; -    const egl_display_ptr dp = validate_display_connection(dpy, cnx); +    const egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (dp) {          if (share_list != EGL_NO_CONTEXT) { -            if (!ContextRef(dp.get(), share_list).get()) { +            if (!ContextRef(dp, share_list).get()) {                  return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT);              }              egl_context_t* const c = get_context(share_list); @@ -967,8 +914,8 @@ EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config,                  }              };          } -        EGLContext context = cnx->egl.eglCreateContext( -                dp->disp.dpy, config, share_list, attrib_list); +        EGLContext context = +                cnx->egl.eglCreateContext(dp->disp.dpy, config, share_list, attrib_list);          if (context != EGL_NO_CONTEXT) {              // figure out if it's a GLESv1 or GLESv2              int version = egl_connection_t::GLESv1_INDEX; @@ -992,17 +939,14 @@ EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config,      return EGL_NO_CONTEXT;  } -EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx) -{ -    const egl_display_ptr dp = validate_display(dpy); -    if (!dp) -        return EGL_FALSE; +EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx) { +    const egl_display_t* dp = validate_display(dpy); +    if (!dp) return EGL_FALSE; -    ContextRef _c(dp.get(), ctx); -    if (!_c.get()) -        return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); +    ContextRef _c(dp, ctx); +    if (!_c.get()) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); -    egl_context_t * const c = get_context(ctx); +    egl_context_t* const c = get_context(ctx);      EGLBoolean result = c->cnx->egl.eglDestroyContext(dp->disp.dpy, c->context);      if (result == EGL_TRUE) {          _c.terminate(); @@ -1010,24 +954,21 @@ EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx)      return result;  } -EGLBoolean eglMakeCurrentImpl(  EGLDisplay dpy, EGLSurface draw, -                                EGLSurface read, EGLContext ctx) -{ -    egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) { +    egl_display_t* dp = validate_display(dpy);      if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      // If ctx is not EGL_NO_CONTEXT, read is not EGL_NO_SURFACE, or draw is not      // EGL_NO_SURFACE, then an EGL_NOT_INITIALIZED error is generated if dpy is      // a valid but uninitialized display. -    if ( (ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || -         (draw != EGL_NO_SURFACE) ) { +    if ((ctx != EGL_NO_CONTEXT) || (read != EGL_NO_SURFACE) || (draw != EGL_NO_SURFACE)) {          if (!dp->isReady()) return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);      }      // get a reference to the object passed in -    ContextRef _c(dp.get(), ctx); -    SurfaceRef _d(dp.get(), draw); -    SurfaceRef _r(dp.get(), read); +    ContextRef _c(dp, ctx); +    SurfaceRef _d(dp, draw); +    SurfaceRef _r(dp, read);      // validate the context (if not EGL_NO_CONTEXT)      if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { @@ -1036,17 +977,17 @@ EGLBoolean eglMakeCurrentImpl(  EGLDisplay dpy, EGLSurface draw,      }      // these are the underlying implementation's object -    EGLContext impl_ctx  = EGL_NO_CONTEXT; +    EGLContext impl_ctx = EGL_NO_CONTEXT;      EGLSurface impl_draw = EGL_NO_SURFACE;      EGLSurface impl_read = EGL_NO_SURFACE;      // these are our objects structs passed in -    egl_context_t       * c = nullptr; -    egl_surface_t const * d = nullptr; -    egl_surface_t const * r = nullptr; +    egl_context_t* c = nullptr; +    egl_surface_t const* d = nullptr; +    egl_surface_t const* r = nullptr;      // these are the current objects structs -    egl_context_t * cur_c = get_context(getContext()); +    egl_context_t* cur_c = get_context(getContext());      if (ctx != EGL_NO_CONTEXT) {          c = get_context(ctx); @@ -1078,10 +1019,7 @@ EGLBoolean eglMakeCurrentImpl(  EGLDisplay dpy, EGLSurface draw,          impl_read = r->surface;      } - -    EGLBoolean result = dp->makeCurrent(c, cur_c, -            draw, read, ctx, -            impl_draw, impl_read, impl_ctx); +    EGLBoolean result = dp->makeCurrent(c, cur_c, draw, read, ctx, impl_draw, impl_read, impl_ctx);      if (result == EGL_TRUE) {          if (c) { @@ -1102,81 +1040,72 @@ EGLBoolean eglMakeCurrentImpl(  EGLDisplay dpy, EGLSurface draw,      return result;  } -EGLBoolean eglQueryContextImpl( EGLDisplay dpy, EGLContext ctx, -                                EGLint attribute, EGLint *value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglQueryContextImpl(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    ContextRef _c(dp.get(), ctx); +    ContextRef _c(dp, ctx);      if (!_c.get()) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); -    egl_context_t * const c = get_context(ctx); -    return c->cnx->egl.eglQueryContext( -            dp->disp.dpy, c->context, attribute, value); - +    egl_context_t* const c = get_context(ctx); +    return c->cnx->egl.eglQueryContext(dp->disp.dpy, c->context, attribute, value);  } -EGLContext eglGetCurrentContextImpl(void) -{ +EGLContext eglGetCurrentContextImpl(void) {      // could be called before eglInitialize(), but we wouldn't have a context      // then, and this function would correctly return EGL_NO_CONTEXT.      EGLContext ctx = getContext();      return ctx;  } -EGLSurface eglGetCurrentSurfaceImpl(EGLint readdraw) -{ +EGLSurface eglGetCurrentSurfaceImpl(EGLint readdraw) {      // could be called before eglInitialize(), but we wouldn't have a context      // then, and this function would correctly return EGL_NO_SURFACE.      EGLContext ctx = getContext();      if (ctx) { -        egl_context_t const * const c = get_context(ctx); +        egl_context_t const* const c = get_context(ctx);          if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);          switch (readdraw) { -            case EGL_READ: return c->read; -            case EGL_DRAW: return c->draw; -            default: return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); +            case EGL_READ: +                return c->read; +            case EGL_DRAW: +                return c->draw; +            default: +                return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE);          }      }      return EGL_NO_SURFACE;  } -EGLDisplay eglGetCurrentDisplayImpl(void) -{ +EGLDisplay eglGetCurrentDisplayImpl(void) {      // could be called before eglInitialize(), but we wouldn't have a context      // then, and this function would correctly return EGL_NO_DISPLAY.      EGLContext ctx = getContext();      if (ctx) { -        egl_context_t const * const c = get_context(ctx); +        egl_context_t const* const c = get_context(ctx);          if (!c) return setError(EGL_BAD_CONTEXT, EGL_NO_SURFACE);          return c->dpy;      }      return EGL_NO_DISPLAY;  } -EGLBoolean eglWaitGLImpl(void) -{ +EGLBoolean eglWaitGLImpl(void) {      egl_connection_t* const cnx = &gEGLImpl; -    if (!cnx->dso) -        return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); +    if (!cnx->dso) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);      return cnx->egl.eglWaitGL();  } -EGLBoolean eglWaitNativeImpl(EGLint engine) -{ +EGLBoolean eglWaitNativeImpl(EGLint engine) {      egl_connection_t* const cnx = &gEGLImpl; -    if (!cnx->dso) -        return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); +    if (!cnx->dso) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);      return cnx->egl.eglWaitNative(engine);  } -EGLint eglGetErrorImpl(void) -{ +EGLint eglGetErrorImpl(void) {      EGLint err = EGL_SUCCESS;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso) { @@ -1188,8 +1117,7 @@ EGLint eglGetErrorImpl(void)      return err;  } -static __eglMustCastToProperFunctionPointerType findBuiltinWrapper( -        const char* procname) { +static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(const char* procname) {      const egl_connection_t* cnx = &gEGLImpl;      void* proc = nullptr; @@ -1205,8 +1133,7 @@ static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(      return nullptr;  } -__eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procname) -{ +__eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char* procname) {      if (FILTER_EXTENSIONS(procname)) {          return nullptr;      } @@ -1253,13 +1180,10 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn          // Ensure we have room to track it          const int slot = sGLExtensionSlot;          if (slot < MAX_NUMBER_OF_GL_EXTENSIONS) { -              if (cnx->dso && cnx->egl.eglGetProcAddress) { -                  // Extensions are independent of the bound context                  addr = cnx->egl.eglGetProcAddress(procname);                  if (addr) { -                      // purposefully track the bottom of the stack in extensionMap                      extensionMap[name] = addr; @@ -1268,7 +1192,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn                      // Track the top most entry point return the extension forwarder                      cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[slot] = -                    cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = addr; +                            cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[slot] = addr;                      addr = gExtensionForwarders[slot];                      // Remember the slot for this extension @@ -1300,7 +1224,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn          // Track the top most entry point and return the extension forwarder          cnx->hooks[egl_connection_t::GLESv1_INDEX]->ext.extensions[ext_slot] = -        cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[ext_slot] = addr; +                cnx->hooks[egl_connection_t::GLESv2_INDEX]->ext.extensions[ext_slot] = addr;          addr = gExtensionForwarders[ext_slot];      } @@ -1310,7 +1234,6 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procn  class FrameCompletionThread {  public: -      static void queueSync(EGLSyncKHR sync) {          static FrameCompletionThread thread; @@ -1327,7 +1250,6 @@ public:      }  private: -      FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) {          std::thread thread(&FrameCompletionThread::loop, this);          thread.detach(); @@ -1382,15 +1304,13 @@ private:      std::mutex mMutex;  }; -EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, -        EGLint *rects, EGLint n_rects) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, EGLint* rects, +                                           EGLint n_rects) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), draw); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, draw); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      if (n_rects < 0 || (n_rects > 0 && rects == NULL))          return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE); @@ -1406,11 +1326,11 @@ EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw,      if (CC_UNLIKELY(dp->finishOnSwap)) {          uint32_t pixel; -        egl_context_t * const c = get_context( egl_tls_t::getContext() ); +        egl_context_t* const c = get_context(egl_tls_t::getContext());          if (c) {              // glReadPixels() ensures that the frame is complete -            s->cnx->hooks[c->version]->gl.glReadPixels(0,0,1,1, -                    GL_RGBA,GL_UNSIGNED_BYTE,&pixel); +            s->cnx->hooks[c->version]->gl.glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, +                                                       &pixel);          }      } @@ -1445,41 +1365,35 @@ EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw,      }      if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { -        return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, -                rects, n_rects); -    } else { -        return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface); +        return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, rects, n_rects);      } + +    return s->cnx->egl.eglSwapBuffers(dp->disp.dpy, s->surface);  } -EGLBoolean eglSwapBuffersImpl(EGLDisplay dpy, EGLSurface surface) -{ +EGLBoolean eglSwapBuffersImpl(EGLDisplay dpy, EGLSurface surface) {      return eglSwapBuffersWithDamageKHRImpl(dpy, surface, nullptr, 0);  } -EGLBoolean eglCopyBuffersImpl(  EGLDisplay dpy, EGLSurface surface, -                                NativePixmapType target) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglCopyBuffersImpl(EGLDisplay dpy, EGLSurface surface, NativePixmapType target) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      return s->cnx->egl.eglCopyBuffers(dp->disp.dpy, s->surface, target);  } -const char* eglQueryStringImpl(EGLDisplay dpy, EGLint name) -{ +const char* eglQueryStringImpl(EGLDisplay dpy, EGLint name) {      if (dpy == EGL_NO_DISPLAY && name == EGL_EXTENSIONS) {          // Return list of client extensions          return gClientExtensionString;      } -    const egl_display_ptr dp = validate_display(dpy); -    if (!dp) return (const char *) nullptr; +    const egl_display_t* dp = validate_display(dpy); +    if (!dp) return (const char*)nullptr;      switch (name) {          case EGL_VENDOR: @@ -1493,13 +1407,12 @@ const char* eglQueryStringImpl(EGLDisplay dpy, EGLint name)          default:              break;      } -    return setError(EGL_BAD_PARAMETER, (const char *)nullptr); +    return setError(EGL_BAD_PARAMETER, (const char*)nullptr);  } -EGLAPI const char* eglQueryStringImplementationANDROIDImpl(EGLDisplay dpy, EGLint name) -{ -    const egl_display_ptr dp = validate_display(dpy); -    if (!dp) return (const char *) nullptr; +EGLAPI const char* eglQueryStringImplementationANDROIDImpl(EGLDisplay dpy, EGLint name) { +    const egl_display_t* dp = validate_display(dpy); +    if (!dp) return (const char*)nullptr;      switch (name) {          case EGL_VENDOR: @@ -1513,24 +1426,22 @@ EGLAPI const char* eglQueryStringImplementationANDROIDImpl(EGLDisplay dpy, EGLin          default:              break;      } -    return setError(EGL_BAD_PARAMETER, (const char *)nullptr); +    return setError(EGL_BAD_PARAMETER, (const char*)nullptr);  }  // ----------------------------------------------------------------------------  // EGL 1.1  // ---------------------------------------------------------------------------- -EGLBoolean eglSurfaceAttribImpl( -        EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglSurfaceAttribImpl(EGLDisplay dpy, EGLSurface surface, EGLint attribute, +                                EGLint value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t * const s = get_surface(surface); +    egl_surface_t* const s = get_surface(surface);      if (attribute == EGL_FRONT_BUFFER_AUTO_REFRESH_ANDROID) {          if (!s->getNativeWindow()) { @@ -1542,7 +1453,9 @@ EGLBoolean eglSurfaceAttribImpl(      if (attribute == EGL_TIMESTAMPS_ANDROID) {          if (!s->getNativeWindow()) { -            return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +            // According to the spec, "if surface is not a window surface this has no +            // effect." +            return EGL_TRUE;          }          int err = native_window_enable_frame_timestamps(s->getNativeWindow(), value != 0);          return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); @@ -1553,51 +1466,41 @@ EGLBoolean eglSurfaceAttribImpl(      } else if (s->setCta8613Attribute(attribute, value)) {          return EGL_TRUE;      } else if (s->cnx->egl.eglSurfaceAttrib) { -        return s->cnx->egl.eglSurfaceAttrib( -                dp->disp.dpy, s->surface, attribute, value); +        return s->cnx->egl.eglSurfaceAttrib(dp->disp.dpy, s->surface, attribute, value);      }      return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);  } -EGLBoolean eglBindTexImageImpl( -        EGLDisplay dpy, EGLSurface surface, EGLint buffer) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglBindTexImageImpl(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (s->cnx->egl.eglBindTexImage) { -        return s->cnx->egl.eglBindTexImage( -                dp->disp.dpy, s->surface, buffer); +        return s->cnx->egl.eglBindTexImage(dp->disp.dpy, s->surface, buffer);      }      return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);  } -EGLBoolean eglReleaseTexImageImpl( -        EGLDisplay dpy, EGLSurface surface, EGLint buffer) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglReleaseTexImageImpl(EGLDisplay dpy, EGLSurface surface, EGLint buffer) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (s->cnx->egl.eglReleaseTexImage) { -        return s->cnx->egl.eglReleaseTexImage( -                dp->disp.dpy, s->surface, buffer); +        return s->cnx->egl.eglReleaseTexImage(dp->disp.dpy, s->surface, buffer);      }      return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);  } -EGLBoolean eglSwapIntervalImpl(EGLDisplay dpy, EGLint interval) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglSwapIntervalImpl(EGLDisplay dpy, EGLint interval) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean res = EGL_TRUE; @@ -1609,16 +1512,13 @@ EGLBoolean eglSwapIntervalImpl(EGLDisplay dpy, EGLint interval)      return res;  } -  // ----------------------------------------------------------------------------  // EGL 1.2  // ---------------------------------------------------------------------------- -EGLBoolean eglWaitClientImpl(void) -{ +EGLBoolean eglWaitClientImpl(void) {      egl_connection_t* const cnx = &gEGLImpl; -    if (!cnx->dso) -        return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); +    if (!cnx->dso) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE);      EGLBoolean res;      if (cnx->egl.eglWaitClient) { @@ -1629,8 +1529,7 @@ EGLBoolean eglWaitClientImpl(void)      return res;  } -EGLBoolean eglBindAPIImpl(EGLenum api) -{ +EGLBoolean eglBindAPIImpl(EGLenum api) {      // bind this API on all EGLs      EGLBoolean res = EGL_TRUE;      egl_connection_t* const cnx = &gEGLImpl; @@ -1640,8 +1539,7 @@ EGLBoolean eglBindAPIImpl(EGLenum api)      return res;  } -EGLenum eglQueryAPIImpl(void) -{ +EGLenum eglQueryAPIImpl(void) {      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglQueryAPI) {          return cnx->egl.eglQueryAPI(); @@ -1651,8 +1549,7 @@ EGLenum eglQueryAPIImpl(void)      return EGL_OPENGL_ES_API;  } -EGLBoolean eglReleaseThreadImpl(void) -{ +EGLBoolean eglReleaseThreadImpl(void) {      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglReleaseThread) {          cnx->egl.eglReleaseThread(); @@ -1665,16 +1562,15 @@ EGLBoolean eglReleaseThreadImpl(void)      return EGL_TRUE;  } -EGLSurface eglCreatePbufferFromClientBufferImpl( -          EGLDisplay dpy, EGLenum buftype, EGLClientBuffer buffer, -          EGLConfig config, const EGLint *attrib_list) -{ +EGLSurface eglCreatePbufferFromClientBufferImpl(EGLDisplay dpy, EGLenum buftype, +                                                EGLClientBuffer buffer, EGLConfig config, +                                                const EGLint* attrib_list) {      egl_connection_t* cnx = nullptr; -    const egl_display_ptr dp = validate_display_connection(dpy, cnx); +    const egl_display_t* dp = validate_display_connection(dpy, &cnx);      if (!dp) return EGL_FALSE;      if (cnx->egl.eglCreatePbufferFromClientBuffer) { -        return cnx->egl.eglCreatePbufferFromClientBuffer( -                dp->disp.dpy, buftype, buffer, config, attrib_list); +        return cnx->egl.eglCreatePbufferFromClientBuffer(dp->disp.dpy, buftype, buffer, config, +                                                         attrib_list);      }      return setError(EGL_BAD_CONFIG, EGL_NO_SURFACE);  } @@ -1683,34 +1579,28 @@ EGLSurface eglCreatePbufferFromClientBufferImpl(  // EGL_EGLEXT_VERSION 3  // ---------------------------------------------------------------------------- -EGLBoolean eglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface, -        const EGLint *attrib_list) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface, const EGLint* attrib_list) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (s->cnx->egl.eglLockSurfaceKHR) { -        return s->cnx->egl.eglLockSurfaceKHR( -                dp->disp.dpy, s->surface, attrib_list); +        return s->cnx->egl.eglLockSurfaceKHR(dp->disp.dpy, s->surface, attrib_list);      }      return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);  } -EGLBoolean eglUnlockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglUnlockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE; -    SurfaceRef _s(dp.get(), surface); -    if (!_s.get()) -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +    SurfaceRef _s(dp, surface); +    if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (s->cnx->egl.eglUnlockSurfaceKHR) {          return s->cnx->egl.eglUnlockSurfaceKHR(dp->disp.dpy, s->surface);      } @@ -1723,7 +1613,7 @@ template <typename AttrType, typename FuncType>  EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,                                 EGLClientBuffer buffer, const AttrType* attrib_list,                                 FuncType eglCreateImageFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_IMAGE_KHR;      std::vector<AttrType> strippedAttribs; @@ -1732,7 +1622,7 @@ EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,          // EGL_GL_COLORSPACE_LINEAR_KHR, EGL_GL_COLORSPACE_SRGB_KHR and          // EGL_GL_COLORSPACE_DEFAULT_EXT if EGL_EXT_image_gl_colorspace is supported,          // but some drivers don't like the DEFAULT value and generate an error. -        for (const AttrType *attr = attrib_list; attr && attr[0] != EGL_NONE; attr += 2) { +        for (const AttrType* attr = attrib_list; attr && attr[0] != EGL_NONE; attr += 2) {              if (attr[0] == EGL_GL_COLORSPACE_KHR &&                  dp->haveExtension("EGL_EXT_image_gl_colorspace")) {                  if (attr[1] != EGL_GL_COLORSPACE_LINEAR_KHR && @@ -1746,14 +1636,15 @@ EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target,          strippedAttribs.push_back(EGL_NONE);      } -    ContextRef _c(dp.get(), ctx); +    ContextRef _c(dp, ctx);      egl_context_t* const c = _c.get();      EGLImageKHR result = EGL_NO_IMAGE_KHR;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && eglCreateImageFunc) {          result = eglCreateImageFunc(dp->disp.dpy, c ? c->context : EGL_NO_CONTEXT, target, buffer, -                                    needsAndroidPEglMitigation() ? strippedAttribs.data() : attrib_list); +                                    needsAndroidPEglMitigation() ? strippedAttribs.data() +                                                                 : attrib_list);      }      return result;  } @@ -1792,7 +1683,7 @@ EGLImage eglCreateImageImpl(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLC  EGLBoolean eglDestroyImageTmpl(EGLDisplay dpy, EGLImageKHR img,                                 PFNEGLDESTROYIMAGEKHRPROC destroyImageFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE; @@ -1829,7 +1720,7 @@ EGLBoolean eglDestroyImageImpl(EGLDisplay dpy, EGLImageKHR img) {  template <typename AttrType, typename FuncType>  EGLSyncKHR eglCreateSyncTmpl(EGLDisplay dpy, EGLenum type, const AttrType* attrib_list,                               FuncType eglCreateSyncFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_SYNC_KHR;      egl_connection_t* const cnx = &gEGLImpl; @@ -1868,7 +1759,7 @@ EGLSync eglCreateSyncImpl(EGLDisplay dpy, EGLenum type, const EGLAttrib* attrib_  EGLBoolean eglDestroySyncTmpl(EGLDisplay dpy, EGLSyncKHR sync,                                PFNEGLDESTROYSYNCKHRPROC eglDestroySyncFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE; @@ -1897,7 +1788,7 @@ EGLBoolean eglDestroySyncImpl(EGLDisplay dpy, EGLSyncKHR sync) {  }  EGLBoolean eglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE; @@ -1910,7 +1801,7 @@ EGLBoolean eglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) {  EGLint eglClientWaitSyncTmpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout,                               PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLint result = EGL_FALSE; @@ -1942,7 +1833,7 @@ EGLint eglClientWaitSyncImpl(EGLDisplay dpy, EGLSync sync, EGLint flags, EGLTime  template <typename AttrType, typename FuncType>  EGLBoolean eglGetSyncAttribTmpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, AttrType* value,                                  FuncType eglGetSyncAttribFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE; @@ -1987,106 +1878,93 @@ EGLBoolean eglGetSyncAttribKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint attri                                                                              .eglGetSyncAttribKHR);  } -EGLStreamKHR eglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint *attrib_list) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLStreamKHR eglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint* attrib_list) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_STREAM_KHR;      EGLStreamKHR result = EGL_NO_STREAM_KHR;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglCreateStreamKHR) { -        result = cnx->egl.eglCreateStreamKHR( -                dp->disp.dpy, attrib_list); +        result = cnx->egl.eglCreateStreamKHR(dp->disp.dpy, attrib_list);      }      return result;  } -EGLBoolean eglDestroyStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglDestroyStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglDestroyStreamKHR) { -        result = cnx->egl.eglDestroyStreamKHR( -                dp->disp.dpy, stream); +        result = cnx->egl.eglDestroyStreamKHR(dp->disp.dpy, stream);      }      return result;  } -EGLBoolean eglStreamAttribKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, -        EGLenum attribute, EGLint value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglStreamAttribKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, +                                  EGLint value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglStreamAttribKHR) { -        result = cnx->egl.eglStreamAttribKHR( -                dp->disp.dpy, stream, attribute, value); +        result = cnx->egl.eglStreamAttribKHR(dp->disp.dpy, stream, attribute, value);      }      return result;  } -EGLBoolean eglQueryStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, -        EGLenum attribute, EGLint *value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglQueryStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, +                                 EGLint* value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglQueryStreamKHR) { -        result = cnx->egl.eglQueryStreamKHR( -                dp->disp.dpy, stream, attribute, value); +        result = cnx->egl.eglQueryStreamKHR(dp->disp.dpy, stream, attribute, value);      }      return result;  } -EGLBoolean eglQueryStreamu64KHRImpl(EGLDisplay dpy, EGLStreamKHR stream, -        EGLenum attribute, EGLuint64KHR *value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglQueryStreamu64KHRImpl(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, +                                    EGLuint64KHR* value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglQueryStreamu64KHR) { -        result = cnx->egl.eglQueryStreamu64KHR( -                dp->disp.dpy, stream, attribute, value); +        result = cnx->egl.eglQueryStreamu64KHR(dp->disp.dpy, stream, attribute, value);      }      return result;  } -EGLBoolean eglQueryStreamTimeKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, -        EGLenum attribute, EGLTimeKHR *value) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglQueryStreamTimeKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, EGLenum attribute, +                                     EGLTimeKHR* value) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglQueryStreamTimeKHR) { -        result = cnx->egl.eglQueryStreamTimeKHR( -                dp->disp.dpy, stream, attribute, value); +        result = cnx->egl.eglQueryStreamTimeKHR(dp->disp.dpy, stream, attribute, value);      }      return result;  }  EGLSurface eglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy, EGLConfig config, -        EGLStreamKHR stream, const EGLint *attrib_list) -{ -    egl_display_ptr dp = validate_display(dpy); +                                                 EGLStreamKHR stream, const EGLint* attrib_list) { +    egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_SURFACE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglCreateStreamProducerSurfaceKHR) { -        EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR( -                dp->disp.dpy, config, stream, attrib_list); +        EGLSurface surface = cnx->egl.eglCreateStreamProducerSurfaceKHR(dp->disp.dpy, config, +                                                                        stream, attrib_list);          if (surface != EGL_NO_SURFACE) { -            egl_surface_t* s = new egl_surface_t(dp.get(), config, nullptr, surface, +            egl_surface_t* s = new egl_surface_t(dp, config, nullptr, surface,                                                   EGL_GL_COLORSPACE_LINEAR_KHR, cnx);              return s;          } @@ -2094,77 +1972,63 @@ EGLSurface eglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy, EGLConfig confi      return EGL_NO_SURFACE;  } -EGLBoolean eglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy, -        EGLStreamKHR stream) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglStreamConsumerGLTextureExternalKHR) { -        result = cnx->egl.eglStreamConsumerGLTextureExternalKHR( -                dp->disp.dpy, stream); +        result = cnx->egl.eglStreamConsumerGLTextureExternalKHR(dp->disp.dpy, stream);      }      return result;  } -EGLBoolean eglStreamConsumerAcquireKHRImpl(EGLDisplay dpy, -        EGLStreamKHR stream) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglStreamConsumerAcquireKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglStreamConsumerAcquireKHR) { -        result = cnx->egl.eglStreamConsumerAcquireKHR( -                dp->disp.dpy, stream); +        result = cnx->egl.eglStreamConsumerAcquireKHR(dp->disp.dpy, stream);      }      return result;  } -EGLBoolean eglStreamConsumerReleaseKHRImpl(EGLDisplay dpy, -        EGLStreamKHR stream) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglStreamConsumerReleaseKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      EGLBoolean result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglStreamConsumerReleaseKHR) { -        result = cnx->egl.eglStreamConsumerReleaseKHR( -                dp->disp.dpy, stream); +        result = cnx->egl.eglStreamConsumerReleaseKHR(dp->disp.dpy, stream);      }      return result;  } -EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHRImpl( -        EGLDisplay dpy, EGLStreamKHR stream) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_FILE_DESCRIPTOR_KHR;      EGLNativeFileDescriptorKHR result = EGL_NO_FILE_DESCRIPTOR_KHR;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglGetStreamFileDescriptorKHR) { -        result = cnx->egl.eglGetStreamFileDescriptorKHR( -                dp->disp.dpy, stream); +        result = cnx->egl.eglGetStreamFileDescriptorKHR(dpy, stream);      }      return result;  } -EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl( -        EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl(EGLDisplay dpy, +                                                      EGLNativeFileDescriptorKHR file_descriptor) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_STREAM_KHR;      EGLStreamKHR result = EGL_NO_STREAM_KHR;      egl_connection_t* const cnx = &gEGLImpl;      if (cnx->dso && cnx->egl.eglCreateStreamFromFileDescriptorKHR) { -        result = cnx->egl.eglCreateStreamFromFileDescriptorKHR( -                dp->disp.dpy, file_descriptor); +        result = cnx->egl.eglCreateStreamFromFileDescriptorKHR(dp->disp.dpy, file_descriptor);      }      return result;  } @@ -2177,7 +2041,7 @@ EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl(  template <typename ReturnType, typename FuncType>  ReturnType eglWaitSyncTmpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags,                             FuncType eglWaitSyncFunc) { -    const egl_display_ptr dp = validate_display(dpy); +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_FALSE;      ReturnType result = EGL_FALSE;      egl_connection_t* const cnx = &gEGLImpl; @@ -2214,9 +2078,8 @@ EGLBoolean eglWaitSyncImpl(EGLDisplay dpy, EGLSync sync, EGLint flags) {  // ANDROID extensions  // ---------------------------------------------------------------------------- -EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID;      EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; @@ -2228,42 +2091,33 @@ EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync)  }  EGLBoolean eglPresentationTimeANDROIDImpl(EGLDisplay dpy, EGLSurface surface, -        EGLnsecsANDROID time) -{ -    const egl_display_ptr dp = validate_display(dpy); +                                          EGLnsecsANDROID time) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return EGL_FALSE;      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          setError(EGL_BAD_SURFACE, EGL_FALSE);          return EGL_FALSE;      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      native_window_set_buffers_timestamp(s->getNativeWindow(), time);      return EGL_TRUE;  } -EGLClientBuffer eglGetNativeClientBufferANDROIDImpl(const AHardwareBuffer *buffer) { -    // AHardwareBuffer_to_ANativeWindowBuffer is a platform-only symbol and thus -    // this function cannot be implemented when this libEGL is built for -    // vendors. -#ifndef __ANDROID_VNDK__ +EGLClientBuffer eglGetNativeClientBufferANDROIDImpl(const AHardwareBuffer* buffer) {      if (!buffer) return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr); -    return const_cast<ANativeWindowBuffer *>(AHardwareBuffer_to_ANativeWindowBuffer(buffer)); -#else -    return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr); -#endif +    return const_cast<ANativeWindowBuffer*>(AHardwareBuffer_to_ANativeWindowBuffer(buffer));  }  // ----------------------------------------------------------------------------  // NVIDIA extensions  // ---------------------------------------------------------------------------- -EGLuint64NV eglGetSystemTimeFrequencyNVImpl() -{ +EGLuint64NV eglGetSystemTimeFrequencyNVImpl() {      EGLuint64NV ret = 0;      egl_connection_t* const cnx = &gEGLImpl; @@ -2274,8 +2128,7 @@ EGLuint64NV eglGetSystemTimeFrequencyNVImpl()      return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0);  } -EGLuint64NV eglGetSystemTimeNVImpl() -{ +EGLuint64NV eglGetSystemTimeNVImpl() {      EGLuint64NV ret = 0;      egl_connection_t* const cnx = &gEGLImpl; @@ -2289,43 +2142,40 @@ EGLuint64NV eglGetSystemTimeNVImpl()  // ----------------------------------------------------------------------------  // Partial update extension  // ---------------------------------------------------------------------------- -EGLBoolean eglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surface, -        EGLint *rects, EGLint n_rects) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surface, EGLint* rects, +                                     EGLint n_rects) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          setError(EGL_BAD_DISPLAY, EGL_FALSE);          return EGL_FALSE;      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          setError(EGL_BAD_SURFACE, EGL_FALSE);          return EGL_FALSE;      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (s->cnx->egl.eglSetDamageRegionKHR) { -        return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, -                rects, n_rects); +        return s->cnx->egl.eglSetDamageRegionKHR(dp->disp.dpy, s->surface, rects, n_rects);      }      return EGL_FALSE;  } -EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface, -            EGLuint64KHR *frameId) { -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface, EGLuint64KHR* frameId) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (!s->getNativeWindow()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); @@ -2346,19 +2196,19 @@ EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface,  }  EGLBoolean eglGetCompositorTimingANDROIDImpl(EGLDisplay dpy, EGLSurface surface, -        EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values) -{ -    const egl_display_ptr dp = validate_display(dpy); +                                             EGLint numTimestamps, const EGLint* names, +                                             EGLnsecsANDROID* values) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (!s->getNativeWindow()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); @@ -2384,36 +2234,35 @@ EGLBoolean eglGetCompositorTimingANDROIDImpl(EGLDisplay dpy, EGLSurface surface,          }      } -    int ret = native_window_get_compositor_timing(s->getNativeWindow(), -            compositeDeadline, compositeInterval, compositeToPresentLatency); +    int ret = native_window_get_compositor_timing(s->getNativeWindow(), compositeDeadline, +                                                  compositeInterval, compositeToPresentLatency);      switch (ret) { -      case 0: -        return EGL_TRUE; -      case -ENOSYS: -        return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); -      default: -        // This should not happen. Return an error that is not in the spec -        // so it's obvious something is very wrong. -        ALOGE("eglGetCompositorTiming: Unexpected error."); -        return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE); +        case 0: +            return EGL_TRUE; +        case -ENOSYS: +            return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); +        default: +            // This should not happen. Return an error that is not in the spec +            // so it's obvious something is very wrong. +            ALOGE("eglGetCompositorTiming: Unexpected error."); +            return setError(EGL_NOT_INITIALIZED, (EGLBoolean)EGL_FALSE);      }  } -EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl( -        EGLDisplay dpy, EGLSurface surface, EGLint name) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface surface, +                                                      EGLint name) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      ANativeWindow* window = s->getNativeWindow();      if (!window) { @@ -2431,20 +2280,19 @@ EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl(  }  EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface, -        EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps, -        EGLnsecsANDROID *values) -{ -    const egl_display_ptr dp = validate_display(dpy); +                                            EGLuint64KHR frameId, EGLint numTimestamps, +                                            const EGLint* timestamps, EGLnsecsANDROID* values) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      if (!s->getNativeWindow()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); @@ -2494,10 +2342,11 @@ EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface,          }      } -    int ret = native_window_get_frame_timestamps(s->getNativeWindow(), frameId, -            requestedPresentTime, acquireTime, latchTime, firstRefreshStartTime, -            lastRefreshStartTime, gpuCompositionDoneTime, displayPresentTime, -            dequeueReadyTime, releaseTime); +    int ret = +            native_window_get_frame_timestamps(s->getNativeWindow(), frameId, requestedPresentTime, +                                               acquireTime, latchTime, firstRefreshStartTime, +                                               lastRefreshStartTime, gpuCompositionDoneTime, +                                               displayPresentTime, dequeueReadyTime, releaseTime);      switch (ret) {          case 0: @@ -2516,20 +2365,19 @@ EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface,      }  } -EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl( -        EGLDisplay dpy, EGLSurface surface, EGLint timestamp) -{ -    const egl_display_ptr dp = validate_display(dpy); +EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface surface, +                                                    EGLint timestamp) { +    const egl_display_t* dp = validate_display(dpy);      if (!dp) {          return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE);      } -    SurfaceRef _s(dp.get(), surface); +    SurfaceRef _s(dp, surface);      if (!_s.get()) {          return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE);      } -    egl_surface_t const * const s = get_surface(surface); +    egl_surface_t const* const s = get_surface(surface);      ANativeWindow* window = s->getNativeWindow();      if (!window) { @@ -2551,8 +2399,7 @@ EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(              return EGL_TRUE;          case EGL_DISPLAY_PRESENT_TIME_ANDROID: {              int value = 0; -            window->query(window, -                    NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &value); +            window->query(window, NATIVE_WINDOW_FRAME_TIMESTAMPS_SUPPORTS_PRESENT, &value);              return value == 0 ? EGL_FALSE : EGL_TRUE;          }          default: @@ -2560,25 +2407,25 @@ EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(      }  } -const GLubyte * glGetStringImpl(GLenum name) { -    const GLubyte * ret = egl_get_string_for_current_context(name); +const GLubyte* glGetStringImpl(GLenum name) { +    const GLubyte* ret = egl_get_string_for_current_context(name);      if (ret == NULL) { -        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; -        if(_c) ret = _c->glGetString(name); +        gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl; +        if (_c) ret = _c->glGetString(name);      }      return ret;  } -const GLubyte * glGetStringiImpl(GLenum name, GLuint index) { -    const GLubyte * ret = egl_get_string_for_current_context(name, index); +const GLubyte* glGetStringiImpl(GLenum name, GLuint index) { +    const GLubyte* ret = egl_get_string_for_current_context(name, index);      if (ret == NULL) { -        gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; -        if(_c) ret = _c->glGetStringi(name, index); +        gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl; +        if (_c) ret = _c->glGetStringi(name, index);      }      return ret;  } -void glGetBooleanvImpl(GLenum pname, GLboolean * data) { +void glGetBooleanvImpl(GLenum pname, GLboolean* data) {      if (pname == GL_NUM_EXTENSIONS) {          int num_exts = egl_get_num_extensions_for_current_context();          if (num_exts >= 0) { @@ -2587,11 +2434,11 @@ void glGetBooleanvImpl(GLenum pname, GLboolean * data) {          }      } -    gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; +    gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl;      if (_c) _c->glGetBooleanv(pname, data);  } -void glGetFloatvImpl(GLenum pname, GLfloat * data) { +void glGetFloatvImpl(GLenum pname, GLfloat* data) {      if (pname == GL_NUM_EXTENSIONS) {          int num_exts = egl_get_num_extensions_for_current_context();          if (num_exts >= 0) { @@ -2600,11 +2447,11 @@ void glGetFloatvImpl(GLenum pname, GLfloat * data) {          }      } -    gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; +    gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl;      if (_c) _c->glGetFloatv(pname, data);  } -void glGetIntegervImpl(GLenum pname, GLint * data) { +void glGetIntegervImpl(GLenum pname, GLint* data) {      if (pname == GL_NUM_EXTENSIONS) {          int num_exts = egl_get_num_extensions_for_current_context();          if (num_exts >= 0) { @@ -2613,11 +2460,11 @@ void glGetIntegervImpl(GLenum pname, GLint * data) {          }      } -    gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; +    gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl;      if (_c) _c->glGetIntegerv(pname, data);  } -void glGetInteger64vImpl(GLenum pname, GLint64 * data) { +void glGetInteger64vImpl(GLenum pname, GLint64* data) {      if (pname == GL_NUM_EXTENSIONS) {          int num_exts = egl_get_num_extensions_for_current_context();          if (num_exts >= 0) { @@ -2626,7 +2473,7 @@ void glGetInteger64vImpl(GLenum pname, GLint64 * data) {          }      } -    gl_hooks_t::gl_t const * const _c = &getGlThreadSpecific()->gl; +    gl_hooks_t::gl_t const* const _c = &getGlThreadSpecific()->gl;      if (_c) _c->glGetInteger64v(pname, data);  } @@ -2635,8 +2482,8 @@ struct implementation_map_t {      EGLFuncPointer address;  }; +// clang-format off  static const implementation_map_t sPlatformImplMap[] = { -        // clang-format off      { "eglGetDisplay", (EGLFuncPointer)&eglGetDisplayImpl },      { "eglGetPlatformDisplay", (EGLFuncPointer)&eglGetPlatformDisplayImpl },      { "eglInitialize", (EGLFuncPointer)&eglInitializeImpl }, @@ -2723,11 +2570,10 @@ static const implementation_map_t sPlatformImplMap[] = {      { "glGetFloatv", (EGLFuncPointer)&glGetFloatvImpl },      { "glGetIntegerv", (EGLFuncPointer)&glGetIntegervImpl },      { "glGetInteger64v", (EGLFuncPointer)&glGetInteger64vImpl }, -        // clang-format on  }; +// clang-format on -EGLFuncPointer FindPlatformImplAddr(const char* name) -{ +EGLFuncPointer FindPlatformImplAddr(const char* name) {      static const bool DEBUG = false;      if (name == nullptr) { @@ -2741,7 +2587,8 @@ EGLFuncPointer FindPlatformImplAddr(const char* name)              return nullptr;          }          if (!strcmp(name, sPlatformImplMap[i].name)) { -            ALOGV("FindPlatformImplAddr found %llu for sPlatformImplMap[%i].address (%s)", (unsigned long long)sPlatformImplMap[i].address, i, name); +            ALOGV("FindPlatformImplAddr found %llu for sPlatformImplMap[%i].address (%s)", +                  (unsigned long long)sPlatformImplMap[i].address, i, name);              return sPlatformImplMap[i].address;          }      } diff --git a/opengl/libs/EGL/egl_tls.cpp b/opengl/libs/EGL/egl_tls.cpp index 8d118e07ed..dd1dcc275f 100644 --- a/opengl/libs/EGL/egl_tls.cpp +++ b/opengl/libs/EGL/egl_tls.cpp @@ -16,10 +16,10 @@  #include "egl_tls.h" -#include <stdlib.h> -  #include <android-base/properties.h>  #include <log/log.h> +#include <stdlib.h> +  #include "CallStack.h"  #include "egl_platform_entries.h" @@ -28,33 +28,46 @@ namespace android {  pthread_key_t egl_tls_t::sKey = TLS_KEY_NOT_INITIALIZED;  pthread_once_t egl_tls_t::sOnceKey = PTHREAD_ONCE_INIT; -egl_tls_t::egl_tls_t() -    : error(EGL_SUCCESS), ctx(nullptr), logCallWithNoContext(true) { -} +egl_tls_t::egl_tls_t() : error(EGL_SUCCESS), ctx(nullptr), logCallWithNoContext(true) {} -const char *egl_tls_t::egl_strerror(EGLint err) { +const char* egl_tls_t::egl_strerror(EGLint err) {      switch (err) { -        case EGL_SUCCESS:               return "EGL_SUCCESS"; -        case EGL_NOT_INITIALIZED:       return "EGL_NOT_INITIALIZED"; -        case EGL_BAD_ACCESS:            return "EGL_BAD_ACCESS"; -        case EGL_BAD_ALLOC:             return "EGL_BAD_ALLOC"; -        case EGL_BAD_ATTRIBUTE:         return "EGL_BAD_ATTRIBUTE"; -        case EGL_BAD_CONFIG:            return "EGL_BAD_CONFIG"; -        case EGL_BAD_CONTEXT:           return "EGL_BAD_CONTEXT"; -        case EGL_BAD_CURRENT_SURFACE:   return "EGL_BAD_CURRENT_SURFACE"; -        case EGL_BAD_DISPLAY:           return "EGL_BAD_DISPLAY"; -        case EGL_BAD_MATCH:             return "EGL_BAD_MATCH"; -        case EGL_BAD_NATIVE_PIXMAP:     return "EGL_BAD_NATIVE_PIXMAP"; -        case EGL_BAD_NATIVE_WINDOW:     return "EGL_BAD_NATIVE_WINDOW"; -        case EGL_BAD_PARAMETER:         return "EGL_BAD_PARAMETER"; -        case EGL_BAD_SURFACE:           return "EGL_BAD_SURFACE"; -        case EGL_CONTEXT_LOST:          return "EGL_CONTEXT_LOST"; -        default: return "UNKNOWN"; +        case EGL_SUCCESS: +            return "EGL_SUCCESS"; +        case EGL_NOT_INITIALIZED: +            return "EGL_NOT_INITIALIZED"; +        case EGL_BAD_ACCESS: +            return "EGL_BAD_ACCESS"; +        case EGL_BAD_ALLOC: +            return "EGL_BAD_ALLOC"; +        case EGL_BAD_ATTRIBUTE: +            return "EGL_BAD_ATTRIBUTE"; +        case EGL_BAD_CONFIG: +            return "EGL_BAD_CONFIG"; +        case EGL_BAD_CONTEXT: +            return "EGL_BAD_CONTEXT"; +        case EGL_BAD_CURRENT_SURFACE: +            return "EGL_BAD_CURRENT_SURFACE"; +        case EGL_BAD_DISPLAY: +            return "EGL_BAD_DISPLAY"; +        case EGL_BAD_MATCH: +            return "EGL_BAD_MATCH"; +        case EGL_BAD_NATIVE_PIXMAP: +            return "EGL_BAD_NATIVE_PIXMAP"; +        case EGL_BAD_NATIVE_WINDOW: +            return "EGL_BAD_NATIVE_WINDOW"; +        case EGL_BAD_PARAMETER: +            return "EGL_BAD_PARAMETER"; +        case EGL_BAD_SURFACE: +            return "EGL_BAD_SURFACE"; +        case EGL_CONTEXT_LOST: +            return "EGL_CONTEXT_LOST"; +        default: +            return "UNKNOWN";      }  } -void egl_tls_t::validateTLSKey() -{ +void egl_tls_t::validateTLSKey() {      struct TlsKeyInitializer {          static void create() { pthread_key_create(&sKey, destructTLSData); }      }; @@ -88,14 +101,12 @@ void egl_tls_t::destructTLSData(void* data) {               "EGL TLS data still exists after eglReleaseThread");  } -void egl_tls_t::setErrorEtcImpl( -        const char* caller, int line, EGLint error, bool quiet) { +void egl_tls_t::setErrorEtcImpl(const char* caller, int line, EGLint error, bool quiet) {      validateTLSKey();      egl_tls_t* tls = getTLS();      if (tls->error != error) {          if (!quiet) { -            ALOGE("%s:%d error %x (%s)", -                    caller, line, error, egl_strerror(error)); +            ALOGE("%s:%d error %x (%s)", caller, line, error, egl_strerror(error));              if (base::GetBoolProperty("debug.egl.callstack", false)) {                  CallStack::log(LOG_TAG);              } @@ -111,7 +122,6 @@ bool egl_tls_t::logNoContextCall() {          return true;      }      return false; -  }  egl_tls_t* egl_tls_t::getTLS() { @@ -161,10 +171,9 @@ EGLContext egl_tls_t::getContext() {      if (sKey == TLS_KEY_NOT_INITIALIZED) {          return EGL_NO_CONTEXT;      } -    egl_tls_t* tls = (egl_tls_t *)pthread_getspecific(sKey); +    egl_tls_t* tls = (egl_tls_t*)pthread_getspecific(sKey);      if (!tls) return EGL_NO_CONTEXT;      return tls->ctx;  } -  } // namespace android diff --git a/opengl/libs/EGL/egl_tls.h b/opengl/libs/EGL/egl_tls.h index 86a375c002..b5fcc1a805 100644 --- a/opengl/libs/EGL/egl_tls.h +++ b/opengl/libs/EGL/egl_tls.h @@ -18,12 +18,9 @@  #define ANDROID_EGL_TLS_H  #include <EGL/egl.h> -  #include <pthread.h> -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  class DbgContext; @@ -32,15 +29,14 @@ class egl_tls_t {      static pthread_key_t sKey;      static pthread_once_t sOnceKey; -    EGLint      error; -    EGLContext  ctx; -    bool        logCallWithNoContext; +    EGLint error; +    EGLContext ctx; +    bool logCallWithNoContext;      egl_tls_t();      static void validateTLSKey();      static void destructTLSData(void* data); -    static void setErrorEtcImpl( -            const char* caller, int line, EGLint error, bool quiet); +    static void setErrorEtcImpl(const char* caller, int line, EGLint error, bool quiet);  public:      static egl_tls_t* getTLS(); @@ -50,24 +46,20 @@ public:      static void setContext(EGLContext ctx);      static EGLContext getContext();      static bool logNoContextCall(); -    static const char *egl_strerror(EGLint err); +    static const char* egl_strerror(EGLint err); -    template<typename T> -    static T setErrorEtc(const char* caller, -            int line, EGLint error, T returnValue, bool quiet = false) { +    template <typename T> +    static T setErrorEtc(const char* caller, int line, EGLint error, T returnValue, +                         bool quiet = false) {          setErrorEtcImpl(caller, line, error, quiet);          return returnValue;      }  }; -#define setError(_e, _r)        \ -    egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r) +#define setError(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r) -#define setErrorQuiet(_e, _r)   \ -    egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true) +#define setErrorQuiet(_e, _r) egl_tls_t::setErrorEtc(__FUNCTION__, __LINE__, _e, _r, true) -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif // ANDROID_EGL_TLS_H diff --git a/opengl/libs/EGL/egl_trace.h b/opengl/libs/EGL/egl_trace.h index 7664de2231..ffdf6761c6 100644 --- a/opengl/libs/EGL/egl_trace.h +++ b/opengl/libs/EGL/egl_trace.h @@ -18,16 +18,14 @@  #if defined(__ANDROID__) -#include <stdint.h> -  #include <cutils/trace.h> +#include <stdint.h>  // See <cutils/trace.h> for more ATRACE_* macros.  // ATRACE_NAME traces from its location until the end of its enclosing scope. -#define _PASTE(x, y) x ## y -#define PASTE(x, y) _PASTE(x,y) -#define ATRACE_NAME(name) android::EglScopedTrace PASTE(___tracer, __LINE__) (ATRACE_TAG, name) +#define PASTE(x, y) x##y +#define ATRACE_NAME(name) android::EglScopedTrace PASTE(___tracer, __LINE__)(ATRACE_TAG, name)  // ATRACE_CALL is an ATRACE_NAME that uses the current function name.  #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__) @@ -36,13 +34,9 @@ namespace android {  class EglScopedTrace {  public: -    inline EglScopedTrace(uint64_t tag, const char* name) : mTag(tag) { -        atrace_begin(mTag, name); -    } +    inline EglScopedTrace(uint64_t tag, const char* name) : mTag(tag) { atrace_begin(mTag, name); } -    inline ~EglScopedTrace() { -        atrace_end(mTag); -    } +    inline ~EglScopedTrace() { atrace_end(mTag); }  private:      uint64_t mTag; diff --git a/opengl/libs/EGL/egldefs.h b/opengl/libs/EGL/egldefs.h index 5fbffbd16c..fcc11f1b55 100644 --- a/opengl/libs/EGL/egldefs.h +++ b/opengl/libs/EGL/egldefs.h @@ -17,40 +17,32 @@  #ifndef ANDROID_EGLDEFS_H  #define ANDROID_EGLDEFS_H +#include <log/log.h> +  #include "../hooks.h"  #include "egl_platform_entries.h" -#include <log/log.h> -  #define VERSION_MAJOR 1  #define VERSION_MINOR 4  #define EGL_MAKE_VERSION(major, minor, patch) (((major) << 22) | ((minor) << 12) | (patch)) -// ----------------------------------------------------------------------------  namespace android { -// ---------------------------------------------------------------------------- -//  EGLDisplay are global, not attached to a given thread +// EGLDisplay are global, not attached to a given thread  const unsigned int NUM_DISPLAYS = 1; -// ---------------------------------------------------------------------------- +extern const char* const platform_names[]; -extern char const * const platform_names[]; - -// clang-format off  struct egl_connection_t { -    enum { -        GLESv1_INDEX = 0, -        GLESv2_INDEX = 1 -    }; - -    inline egl_connection_t() : dso(nullptr), -                                libEgl(nullptr), -                                libGles1(nullptr), -                                libGles2(nullptr), -                                systemDriverUnloaded(false) { - -        char const* const* entries = platform_names; +    enum { GLESv1_INDEX = 0, GLESv2_INDEX = 1 }; + +    inline egl_connection_t() +          : dso(nullptr), +            libEgl(nullptr), +            libGles1(nullptr), +            libGles2(nullptr), +            systemDriverUnloaded(false) { +        const char* const* entries = platform_names;          EGLFuncPointer* curr = reinterpret_cast<EGLFuncPointer*>(&platform);          while (*entries) {              const char* name = *entries; @@ -66,41 +58,34 @@ struct egl_connection_t {          }      } -    void *              dso; -    gl_hooks_t *        hooks[2]; -    EGLint              major; -    EGLint              minor; -    EGLint              driverVersion; -    egl_t               egl; +    void* dso; +    gl_hooks_t* hooks[2]; +    EGLint major; +    EGLint minor; +    EGLint driverVersion; +    egl_t egl;      // Functions implemented or redirected by platform libraries -    platform_impl_t     platform; +    platform_impl_t platform; -    void*               libEgl; -    void*               libGles1; -    void*               libGles2; +    void* libEgl; +    void* libGles1; +    void* libGles2; -    bool                systemDriverUnloaded; -    bool                useAngle;       // Was ANGLE successfully loaded +    bool systemDriverUnloaded; +    bool useAngle; // Was ANGLE successfully loaded  }; -// clang-format on - -// ----------------------------------------------------------------------------  extern gl_hooks_t gHooks[2];  extern gl_hooks_t gHooksNoContext;  extern pthread_key_t gGLWrapperKey;  extern "C" void gl_unimplemented();  extern "C" void gl_noop(); - -extern char const * const gl_names[]; -extern char const * const gl_names_1[]; -extern char const * const egl_names[]; - +extern const char* const gl_names[]; +extern const char* const gl_names_1[]; +extern const char* const egl_names[];  extern egl_connection_t gEGLImpl; -// ----------------------------------------------------------------------------  }; // namespace android -// ----------------------------------------------------------------------------  #endif /* ANDROID_EGLDEFS_H */ diff --git a/opengl/libs/EGL/getProcAddress.cpp b/opengl/libs/EGL/getProcAddress.cpp index fedc7893db..b3d6f74e86 100644 --- a/opengl/libs/EGL/getProcAddress.cpp +++ b/opengl/libs/EGL/getProcAddress.cpp @@ -16,15 +16,12 @@  #include <ctype.h>  #include <errno.h> -#include <stdlib.h> -  #include <log/log.h> +#include <stdlib.h>  #include "egldefs.h" -// ----------------------------------------------------------------------------  namespace android { -// ----------------------------------------------------------------------------  #undef API_ENTRY  #undef CALL_GL_EXTENSION_API @@ -34,6 +31,7 @@ namespace android {  #undef GL_EXTENSION_LIST  #undef GET_TLS +// clang-format off  #if defined(__arm__)      #define GET_TLS(reg) "mrc p15, 0, " #reg ", c13, c0, 3 \n" @@ -239,13 +237,13 @@ namespace android {      name(248) name(249) name(250) name(251) name(252) name(253) name(254) name(255) -GL_EXTENSION_LIST( GL_EXTENSION ) +GL_EXTENSION_LIST(GL_EXTENSION) -#define GL_EXTENSION_ARRAY(_n)  GL_EXTENSION_NAME(_n), +#define GL_EXTENSION_ARRAY(_n) GL_EXTENSION_NAME(_n), +// clang-format on -extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = { -        GL_EXTENSION_LIST( GL_EXTENSION_ARRAY ) - }; +extern const __eglMustCastToProperFunctionPointerType +        gExtensionForwarders[MAX_NUMBER_OF_GL_EXTENSIONS] = {GL_EXTENSION_LIST(GL_EXTENSION_ARRAY)};  #undef GET_TLS  #undef GL_EXTENSION_LIST @@ -255,7 +253,4 @@ extern const __eglMustCastToProperFunctionPointerType gExtensionForwarders[MAX_N  #undef API_ENTRY  #undef CALL_GL_EXTENSION_API -// ----------------------------------------------------------------------------  }; // namespace android -// ---------------------------------------------------------------------------- - diff --git a/opengl/tests/configdump/Android.bp b/opengl/tests/configdump/Android.bp index ffb0c1f0c4..1bb5983299 100644 --- a/opengl/tests/configdump/Android.bp +++ b/opengl/tests/configdump/Android.bp @@ -4,8 +4,6 @@ package {      // all of the 'license_kinds' from "frameworks_native_license"      // to get the below license kinds:      //   SPDX-license-identifier-Apache-2.0 -    //   SPDX-license-identifier-MIT -    //   SPDX-license-identifier-Unicode-DFS      default_applicable_licenses: ["frameworks_native_license"],  } diff --git a/opengl/tests/filter/Android.bp b/opengl/tests/filter/Android.bp index 3b92b37634..b93576fd0c 100644 --- a/opengl/tests/filter/Android.bp +++ b/opengl/tests/filter/Android.bp @@ -4,8 +4,6 @@ package {      // all of the 'license_kinds' from "frameworks_native_license"      // to get the below license kinds:      //   SPDX-license-identifier-Apache-2.0 -    //   SPDX-license-identifier-MIT -    //   SPDX-license-identifier-Unicode-DFS      default_applicable_licenses: ["frameworks_native_license"],  } diff --git a/opengl/tests/gl_basic/Android.bp b/opengl/tests/gl_basic/Android.bp index f777401b6f..f55cd0dfe5 100644 --- a/opengl/tests/gl_basic/Android.bp +++ b/opengl/tests/gl_basic/Android.bp @@ -4,8 +4,6 @@ package {      // all of the 'license_kinds' from "frameworks_native_license"      // to get the below license kinds:      //   SPDX-license-identifier-Apache-2.0 -    //   SPDX-license-identifier-MIT -    //   SPDX-license-identifier-Unicode-DFS      default_applicable_licenses: ["frameworks_native_license"],  } diff --git a/opengl/tests/lib/WindowSurface.cpp b/opengl/tests/lib/WindowSurface.cpp index dfb9c92b5f..fd4522e757 100644 --- a/opengl/tests/lib/WindowSurface.cpp +++ b/opengl/tests/lib/WindowSurface.cpp @@ -21,7 +21,7 @@  #include <gui/ISurfaceComposer.h>  #include <gui/Surface.h>  #include <gui/SurfaceComposerClient.h> -#include <ui/DisplayConfig.h> +#include <ui/DisplayMode.h>  #include <ui/DisplayState.h>  using namespace android; @@ -42,10 +42,10 @@ WindowSurface::WindowSurface() {          return;      } -    DisplayConfig displayConfig; -    err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); +    ui::DisplayMode displayMode; +    err = SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode);      if (err != NO_ERROR) { -        fprintf(stderr, "ERROR: unable to get active display config\n"); +        fprintf(stderr, "ERROR: unable to get active display mode\n");          return;      } @@ -56,7 +56,7 @@ WindowSurface::WindowSurface() {          return;      } -    const ui::Size& resolution = displayConfig.resolution; +    const ui::Size& resolution = displayMode.resolution;      auto width = resolution.getWidth();      auto height = resolution.getHeight(); diff --git a/opengl/tests/tritex/Android.bp b/opengl/tests/tritex/Android.bp index 759582cab6..87da93f6bc 100644 --- a/opengl/tests/tritex/Android.bp +++ b/opengl/tests/tritex/Android.bp @@ -4,8 +4,6 @@ package {      // all of the 'license_kinds' from "frameworks_native_license"      // to get the below license kinds:      //   SPDX-license-identifier-Apache-2.0 -    //   SPDX-license-identifier-MIT -    //   SPDX-license-identifier-Unicode-DFS      default_applicable_licenses: ["frameworks_native_license"],  }  |