diff options
Diffstat (limited to 'opengl')
71 files changed, 1399 insertions, 1535 deletions
diff --git a/opengl/Android.bp b/opengl/Android.bp index b15694bf50..9ca8b0b0fd 100644 --- a/opengl/Android.bp +++ b/opengl/Android.bp @@ -12,18 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - // SPDX-license-identifier-BSD - // SPDX-license-identifier-MIT - // legacy_notice - default_applicable_licenses: ["frameworks_native_license"], -} - ndk_headers { name: "libEGL_headers", from: "include", @@ -64,14 +52,34 @@ ndk_headers { license: "include/KHR/NOTICE", } +llndk_library { + name: "libEGL", + symbol_file: "libs/libEGL.map.txt", + export_include_dirs: ["include"], +} + +llndk_library { + name: "libGLESv1_CM", + symbol_file: "libs/libGLESv1_CM.map.txt", + export_include_dirs: ["include"], +} + +llndk_library { + name: "libGLESv2", + symbol_file: "libs/libGLESv2.map.txt", + export_include_dirs: ["include"], +} + +llndk_library { + name: "libGLESv3", + symbol_file: "libs/libGLESv3.map.txt", + export_include_dirs: ["include"], +} + cc_library_headers { name: "gl_headers", - host_supported: true, vendor_available: true, export_include_dirs: ["include"], - llndk: { - llndk_headers: true, - }, } subdirs = [ diff --git a/opengl/OWNERS b/opengl/OWNERS index a9bd4bb2e2..b505712eb5 100644 --- a/opengl/OWNERS +++ b/opengl/OWNERS @@ -1,6 +1,7 @@ chrisforbes@google.com cnorthrop@google.com +courtneygo@google.com ianelliott@google.com jessehall@google.com lpy@google.com -timvp@google.com +zzyiwei@google.com diff --git a/opengl/include/EGL/eglext_angle.h b/opengl/include/EGL/eglext_angle.h index e753e0d60f..0556ea1342 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,26 +186,6 @@ 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 c9fce8ad52..e8d3684e4e 100644 --- a/opengl/libs/Android.bp +++ b/opengl/libs/Android.bp @@ -1,13 +1,4 @@ // Build the ETC1 library -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_library { name: "libETC1", srcs: ["ETC1/etc1.cpp"], @@ -111,6 +102,11 @@ cc_defaults { "libbacktrace", "libbase", ], + target: { + vendor: { + exclude_shared_libs: ["libgraphicsenv"], + }, + }, } cc_library_static { @@ -137,12 +133,6 @@ cc_library_static { cc_library_shared { name: "libEGL", defaults: ["egl_libs_defaults"], - llndk: { - symbol_file: "libEGL.map.txt", - export_llndk_headers: ["gl_headers"], - // Don't export EGL/include from the LLNDK variant. - override_export_include_dirs: [], - }, srcs: [ "EGL/egl_tls.cpp", "EGL/egl_cache.cpp", @@ -208,12 +198,6 @@ cc_defaults { cc_library_shared { name: "libGLESv1_CM", defaults: ["gles_libs_defaults"], - llndk: { - symbol_file: "libGLESv1_CM.map.txt", - export_llndk_headers: ["gl_headers"], - // Don't export EGL/include from the LLNDK variant. - override_export_include_dirs: [], - }, srcs: ["GLES_CM/gl.cpp"], cflags: ["-DLOG_TAG=\"libGLESv1\""], version_script: "libGLESv1_CM.map.txt", @@ -225,12 +209,6 @@ cc_library_shared { cc_library_shared { name: "libGLESv2", defaults: ["gles_libs_defaults"], - llndk: { - symbol_file: "libGLESv2.map.txt", - export_llndk_headers: ["gl_headers"], - // Don't export EGL/include from the LLNDK variant. - override_export_include_dirs: [], - }, srcs: ["GLES2/gl2.cpp"], cflags: ["-DLOG_TAG=\"libGLESv2\""], @@ -245,12 +223,6 @@ cc_library_shared { cc_library_shared { name: "libGLESv3", defaults: ["gles_libs_defaults"], - llndk: { - symbol_file: "libGLESv3.map.txt", - export_llndk_headers: ["gl_headers"], - // Don't export EGL/include from the LLNDK variant. - override_export_include_dirs: [], - }, srcs: ["GLES2/gl2.cpp"], cflags: ["-DLOG_TAG=\"libGLESv3\""], } diff --git a/opengl/libs/EGL/BlobCache.cpp b/opengl/libs/EGL/BlobCache.cpp index beca7f191a..74fb0194f9 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 <log/log.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) { @@ -78,12 +78,12 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, size_t v return; } - std::shared_ptr<Blob> cacheKey(new Blob(key, keySize, false)); - CacheEntry cacheEntry(cacheKey, nullptr); + std::shared_ptr<Blob> dummyKey(new Blob(key, keySize, false)); + CacheEntry dummyEntry(dummyKey, nullptr); while (true) { - auto index = std::lower_bound(mCacheEntries.begin(), mCacheEntries.end(), cacheEntry); - if (index == mCacheEntries.end() || cacheEntry < *index) { + auto index = std::lower_bound(mCacheEntries.begin(), mCacheEntries.end(), dummyEntry); + if (index == mCacheEntries.end() || dummyEntry < *index) { // Create a new cache entry. std::shared_ptr<Blob> keyBlob(new Blob(key, keySize, true)); std::shared_ptr<Blob> valueBlob(new Blob(value, valueSize, true)); @@ -95,16 +95,16 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, size_t v 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,31 +117,31 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, size_t v 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)); - CacheEntry cacheEntry(cacheKey, nullptr); - auto index = std::lower_bound(mCacheEntries.begin(), mCacheEntries.end(), cacheEntry); - if (index == mCacheEntries.end() || cacheEntry < *index) { + std::shared_ptr<Blob> dummyKey(new Blob(key, keySize, false)); + CacheEntry dummyEntry(dummyKey, nullptr); + auto index = std::lower_bound(mCacheEntries.begin(), mCacheEntries.end(), dummyEntry); + if (index == mCacheEntries.end() || dummyEntry < *index) { ALOGV("get: no cache entry found for key of size %zu", keySize); return 0; } @@ -154,8 +154,8 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value, size_t 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,7 +259,8 @@ 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; @@ -303,8 +304,10 @@ 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); } @@ -332,13 +335,19 @@ 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 50b4e4c6d0..e5c5e5bc25 100644 --- a/opengl/libs/EGL/BlobCache.h +++ b/opengl/libs/EGL/BlobCache.h @@ -54,7 +54,8 @@ 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 @@ -74,6 +75,7 @@ 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; @@ -166,6 +168,7 @@ private: void setValue(const std::shared_ptr<Blob>& value); private: + // mKey is the key that identifies the cache entry. std::shared_ptr<Blob> mKey; @@ -242,6 +245,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 d31373b37a..cf67cf443b 100644 --- a/opengl/libs/EGL/BlobCache_test.cpp +++ b/opengl/libs/EGL/BlobCache_test.cpp @@ -14,24 +14,25 @@ ** 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 { @@ -40,15 +41,19 @@ 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]); @@ -58,7 +63,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)); @@ -70,9 +75,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]); @@ -82,7 +87,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]); @@ -96,7 +101,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)); @@ -107,9 +112,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]); @@ -118,13 +123,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]); @@ -132,16 +137,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]); } @@ -169,7 +174,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'; } @@ -190,7 +195,8 @@ 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]); @@ -217,7 +223,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]); @@ -252,13 +258,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 { @@ -285,7 +291,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)); @@ -353,7 +359,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(); @@ -370,7 +376,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(); @@ -389,7 +395,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(); @@ -408,7 +414,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 b7fdf97cbe..0e2a9b3248 100644 --- a/opengl/libs/EGL/CallStack.h +++ b/opengl/libs/EGL/CallStack.h @@ -16,9 +16,8 @@ #pragma once -#include <backtrace/Backtrace.h> #include <log/log.h> - +#include <backtrace/Backtrace.h> #include <memory> class CallStack { @@ -31,8 +30,9 @@ 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/FileBlobCache.cpp b/opengl/libs/EGL/FileBlobCache.cpp index 751f3be81a..cc42ac7fef 100644 --- a/opengl/libs/EGL/FileBlobCache.cpp +++ b/opengl/libs/EGL/FileBlobCache.cpp @@ -17,13 +17,11 @@ #include "FileBlobCache.h" #include <errno.h> -#include <fcntl.h> #include <inttypes.h> +#include <log/log.h> #include <sys/mman.h> #include <sys/stat.h> -#include <unistd.h> -#include <log/log.h> // Cache file header static const char* cacheFileMagic = "EGL$"; @@ -70,7 +68,7 @@ FileBlobCache::FileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxT return; } - // Check the size before trying to mmap it. + // Sanity check the size before trying to mmap it. size_t fileSize = statBuf.st_size; if (fileSize > mMaxTotalSize * 2) { ALOGE("cache file is too large: %#" PRIx64, diff --git a/opengl/libs/EGL/Loader.cpp b/opengl/libs/EGL/Loader.cpp index 76fd7f0f3f..d66ef2b969 100644 --- a/opengl/libs/EGL/Loader.cpp +++ b/opengl/libs/EGL/Loader.cpp @@ -17,23 +17,27 @@ //#define LOG_NDEBUG 0 #define ATRACE_TAG ATRACE_TAG_GRAPHICS -#include "EGL/Loader.h" +#include <EGL/Loader.h> + +#include <string> -#include <android-base/properties.h> -#include <android/dlext.h> #include <dirent.h> #include <dlfcn.h> -#include <graphicsenv/GraphicsEnv.h> + +#include <android-base/properties.h> +#include <android/dlext.h> #include <log/log.h> #include <utils/Timers.h> -#include <vndksupport/linker.h> -#include <string> +#ifndef __ANDROID_VNDK__ +#include <graphicsenv/GraphicsEnv.h> +#endif +#include <vndksupport/linker.h> -#include "EGL/eglext_angle.h" #include "egl_platform_entries.h" #include "egl_trace.h" #include "egldefs.h" +#include <EGL/eglext_angle.h> namespace android { @@ -155,11 +159,13 @@ 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; } @@ -270,7 +276,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[2], cnx); + init_angle_backend(hnd->dso[0], cnx); } LOG_ALWAYS_FATAL_IF(!hnd, @@ -364,7 +370,7 @@ void Loader::init_api(void* dso, f = (__eglMustCastToProperFunctionPointerType)gl_unimplemented; /* - * GL_EXT_debug_marker is special, we always report it as + * GL_EXT_debug_label 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. */ @@ -514,8 +520,6 @@ 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; } @@ -553,8 +557,12 @@ Loader::driver_t* Loader::attempt_to_load_angle(egl_connection_t* cnx) { } void Loader::init_angle_backend(void* dso, egl_connection_t* cnx) { - void* pANGLEGetDisplayPlatform = dlsym(dso, "ANGLEGetDisplayPlatform"); - if (pANGLEGetDisplayPlatform) { + void* eglCreateDeviceANGLE = nullptr; + + ALOGV("dso: %p", dso); + eglCreateDeviceANGLE = dlsym(dso, "eglCreateDeviceANGLE"); + ALOGV("eglCreateDeviceANGLE: %p", eglCreateDeviceANGLE); + if (eglCreateDeviceANGLE) { ALOGV("ANGLE GLES library in use"); cnx->useAngle = true; } else { @@ -565,7 +573,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; @@ -595,6 +603,9 @@ 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 81742ab9ae..7b2d7c9c27 100644 --- a/opengl/libs/EGL/Loader.h +++ b/opengl/libs/EGL/Loader.h @@ -1,26 +1,29 @@ -/* +/* ** 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 <EGL/egl.h> #include <stdint.h> +#include <EGL/egl.h> + +// ---------------------------------------------------------------------------- namespace android { +// ---------------------------------------------------------------------------- struct egl_connection_t; @@ -59,12 +62,16 @@ 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, const char* const* api, - const char* const* ref_api, - __eglMustCastToProperFunctionPointerType* curr, - getProcAddressType getProcAddress); + static __attribute__((noinline)) + void init_api(void* dso, + char const * const * api, + char const * 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 e5b9e14bd5..43f7a075a7 100644 --- a/opengl/libs/EGL/egl.cpp +++ b/opengl/libs/EGL/egl.cpp @@ -14,35 +14,45 @@ ** 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 "CallStack.h" -#include "Loader.h" + +#include "egldefs.h" +#include "egl_tls.h" #include "egl_display.h" -#include "egl_layers.h" #include "egl_object.h" -#include "egl_tls.h" -#include "egldefs.h" +#include "egl_layers.h" +#include "CallStack.h" +#include "Loader.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()) { - const char* const error = "call to OpenGL ES API with " - "no current context (logged once per thread)"; + char const* const error = "call to OpenGL ES API with " + "no current context (logged once per thread)"; if (LOG_NDEBUG) { ALOGE(error); } else { @@ -55,9 +65,10 @@ 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); } @@ -65,40 +76,75 @@ static void early_egl_init(void) { setGLHooksThreadSpecific(&gHooksNoContext); } -const GLubyte* egl_get_string_for_current_context(GLenum name) { +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) { // 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; - const egl_context_t* const c = get_context(context); + egl_context_t const * 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; - const egl_context_t* const c = get_context(context); + egl_context_t const * 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() { @@ -106,9 +152,10 @@ 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; - const egl_context_t* const c = get_context(context); + egl_context_t const * const c = get_context(context); if (c == nullptr) // this should never happen, by construction return -1; @@ -119,8 +166,7 @@ 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) { @@ -148,6 +194,7 @@ 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; @@ -181,10 +228,13 @@ 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; } @@ -220,4 +270,8 @@ 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 502c14f0f1..c51a1295e7 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -20,6 +20,7 @@ #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 d38f2eff01..97dc0f1370 100644 --- a/opengl/libs/EGL/egl_angle_platform.cpp +++ b/opengl/libs/EGL/egl_angle_platform.cpp @@ -16,6 +16,7 @@ #if defined(__ANDROID__) +#include "Loader.h" #include "egl_angle_platform.h" #pragma GCC diagnostic push @@ -23,20 +24,14 @@ #include <EGL/Platform.h> #pragma GCC diagnostic pop -#include <android-base/properties.h> #include <android/dlext.h> #include <dlfcn.h> #include <graphicsenv/GraphicsEnv.h> -#include <log/log.h> #include <time.h> -#include <vndksupport/linker.h> - -#include "Loader.h" +#include <log/log.h> namespace angle { -constexpr int kAngleDlFlags = RTLD_LOCAL | RTLD_NOW; - static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr; static ResetDisplayPlatformFunc angleResetDisplayPlatform = nullptr; @@ -106,40 +101,11 @@ static void assignAnglePlatformMethods(PlatformMethods* platformMethods) { bool initializeAnglePlatform(EGLDisplay dpy) { // Since we're inside libEGL, use dlsym to lookup fptr for ANGLEGetDisplayPlatform android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace(); - void* so = nullptr; - if (ns) { - // Loading from an APK, so hard-code the suffix to "_angle". - constexpr char kAngleEs2Lib[] = "libGLESv2_angle.so"; - const android_dlextinfo dlextinfo = { - .flags = ANDROID_DLEXT_USE_NAMESPACE, - .library_namespace = ns, - }; - so = android_dlopen_ext(kAngleEs2Lib, kAngleDlFlags, &dlextinfo); - if (so) { - ALOGD("dlopen_ext from APK (%s) success at %p", kAngleEs2Lib, so); - } else { - ALOGE("dlopen_ext(\"%s\") failed: %s", kAngleEs2Lib, dlerror()); - return false; - } - } else { - // If we are here, ANGLE is loaded as built-in gl driver in the sphal. - // Get the specified ANGLE library filename suffix. - std::string angleEs2LibSuffix = android::base::GetProperty("ro.hardware.egl", ""); - if (angleEs2LibSuffix.empty()) { - ALOGE("%s failed to get valid ANGLE library filename suffix!", __FUNCTION__); - return false; - } - - std::string angleEs2LibName = "libGLESv2_" + angleEs2LibSuffix + ".so"; - so = android_load_sphal_library(angleEs2LibName.c_str(), kAngleDlFlags); - if (so) { - ALOGD("dlopen (%s) success at %p", angleEs2LibName.c_str(), so); - } else { - ALOGE("%s failed to dlopen %s!", __FUNCTION__, angleEs2LibName.c_str()); - return false; - } - } - + const android_dlextinfo dlextinfo = { + .flags = ANDROID_DLEXT_USE_NAMESPACE, + .library_namespace = ns, + }; + void* so = android_dlopen_ext("libGLESv2_angle.so", RTLD_LOCAL | RTLD_NOW, &dlextinfo); angleGetDisplayPlatform = reinterpret_cast<GetDisplayPlatformFunc>(dlsym(so, "ANGLEGetDisplayPlatform")); @@ -149,11 +115,13 @@ bool initializeAnglePlatform(EGLDisplay dpy) { } angleResetDisplayPlatform = - reinterpret_cast<ResetDisplayPlatformFunc>(dlsym(so, "ANGLEResetDisplayPlatform")); + reinterpret_cast<ResetDisplayPlatformFunc>( + eglGetProcAddress("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 efa67dbc1c..bcf496164b 100644 --- a/opengl/libs/EGL/egl_cache.cpp +++ b/opengl/libs/EGL/egl_cache.cpp @@ -16,14 +16,17 @@ #include "egl_cache.h" -#include <log/log.h> +#include "../egl_impl.h" + +#include "egl_display.h" + #include <private/EGL/cache.h> + #include <unistd.h> #include <thread> -#include "../egl_impl.h" -#include "egl_display.h" +#include <log/log.h> // Cache size limits. static const size_t maxKeySize = 12 * 1024; @@ -33,7 +36,9 @@ 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" @@ -45,22 +50,25 @@ 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; @@ -68,7 +76,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; @@ -77,26 +85,28 @@ 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); } } } @@ -112,8 +122,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) { @@ -140,8 +150,8 @@ void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize, const void* } } -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) { @@ -168,4 +178,6 @@ 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 d10a6154b7..7382b913fa 100644 --- a/opengl/libs/EGL/egl_cache.h +++ b/opengl/libs/EGL/egl_cache.h @@ -20,18 +20,21 @@ #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(); @@ -114,6 +117,8 @@ 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 0b755aadca..3b1cf712a2 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -14,41 +14,49 @@ ** limitations under the License. */ +#define __STDC_LIMIT_MACROS 1 #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include "egl_display.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 "../egl_impl.h" -#include "EGL/eglext_angle.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 "private/EGL/display.h" + +#include <SurfaceFlingerProperties.h> +#include <android-base/properties.h> +#include <android/dlext.h> +#include <dlfcn.h> +#include <graphicsenv/GraphicsEnv.h> + +#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> +#include <configstore/Utils.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"; -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 char const * const gBuiltinExtensionString; +extern char const * const gExtensionString; -extern const char* const gBuiltinExtensionString; -extern const char* const gExtensionString; +extern void setGLHooksThreadSpecific(gl_hooks_t const *value); -extern void setGLHooksThreadSpecific(gl_hooks_t const* value); +// ---------------------------------------------------------------------------- bool findExtension(const char* exts, const char* name, size_t nameLen) { if (exts) { @@ -74,15 +82,11 @@ int egl_get_init_count(EGLDisplay dpy) { return eglDisplay ? eglDisplay->getRefsCount() : 0; } -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::sDisplay[NUM_DISPLAYS]; -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; @@ -94,12 +98,11 @@ egl_display_t* egl_display_t::get(EGLDisplay dpy) { return nullptr; } - const std::lock_guard<std::mutex> lock(displayMapLock); - auto search = displayMap.find(dpy); - if (search == displayMap.end() || !search->second->isValid()) { + uintptr_t index = uintptr_t(dpy)-1U; + if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) { return nullptr; } - return search->second.get(); + return &sDisplay[index]; } void egl_display_t::addObject(egl_object_t* object) { @@ -125,9 +128,10 @@ 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 getPlatformDisplay(disp, attrib_list); + return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list); } static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx, @@ -143,16 +147,6 @@ 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); @@ -182,6 +176,7 @@ 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 @@ -209,7 +204,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"); } @@ -217,23 +212,17 @@ 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 nullptr; + return EGLDisplay(uintptr_t(display) + 1U); } -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++; @@ -241,7 +230,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; @@ -254,7 +243,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); } } @@ -274,31 +263,40 @@ 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; @@ -393,6 +391,7 @@ 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) { @@ -425,7 +424,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; @@ -458,7 +457,8 @@ 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,7 +467,8 @@ 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); @@ -477,6 +478,7 @@ 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 @@ -487,9 +489,10 @@ 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) @@ -501,12 +504,14 @@ EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c, EG { // 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(); } @@ -532,23 +537,6 @@ 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 87c2176045..e117314d71 100644 --- a/opengl/libs/EGL/egl_display.h +++ b/opengl/libs/EGL/egl_display.h @@ -17,22 +17,26 @@ #ifndef ANDROID_EGL_DISPLAY_H #define ANDROID_EGL_DISPLAY_H -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <stddef.h> + #include <stdint.h> +#include <stddef.h> #include <condition_variable> -#include <map> -#include <memory> #include <mutex> #include <string> #include <unordered_set> -#include "../hooks.h" +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#include <cutils/compiler.h> + #include "egldefs.h" +#include "../hooks.h" +// ---------------------------------------------------------------------------- namespace android { +// ---------------------------------------------------------------------------- class egl_object_t; class egl_context_t; @@ -41,25 +45,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 std::map<EGLDisplay, std::unique_ptr<egl_display_t>> displayMap; - static std::mutex displayMapLock; + static egl_display_t sDisplay[NUM_DISPLAYS]; EGLDisplay getDisplay(EGLNativeDisplayType display); - static EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, - const EGLAttrib* attrib_list); - void loseCurrentImpl(egl_context_t* cur_c); + 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 @@ -72,69 +76,123 @@ 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; + 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; +}; + +// ---------------------------------------------------------------------------- +// 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: - DisplayImpl disp; - bool finishOnSwap; // property: debug.egl.finish - bool traceGpuCompletion; // property: debug.egl.traceGpuCompletion - bool hasColorSpaceSupport; + 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; } private: - 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; + egl_display_t* mDpy; + + // non-assignable + egl_display_ptr& operator=(const egl_display_ptr&); }; -inline egl_display_t* get_display(EGLDisplay dpy) { +// ---------------------------------------------------------------------------- + +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) { return egl_display_t::get(dpy); } -egl_display_t* validate_display(EGLDisplay dpy); -egl_display_t* validate_display_connection(EGLDisplay dpy, egl_connection_t** outCnx); +// ---------------------------------------------------------------------------- + +egl_display_ptr validate_display(EGLDisplay dpy); +egl_display_ptr validate_display_connection(EGLDisplay dpy, + egl_connection_t*& cnx); 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 1c91f1d61b..2921d512f1 100644 --- a/opengl/libs/EGL/egl_entries.in +++ b/opengl/libs/EGL/egl_entries.in @@ -104,6 +104,11 @@ 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 9752e382d9..ea86c9a05b 100644 --- a/opengl/libs/EGL/egl_layers.cpp +++ b/opengl/libs/EGL/egl_layers.cpp @@ -85,21 +85,17 @@ 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 @@ -109,9 +105,7 @@ 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); } @@ -123,26 +117,20 @@ 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++; @@ -392,8 +380,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 705525d857..1e2783fc98 100644 --- a/opengl/libs/EGL/egl_layers.h +++ b/opengl/libs/EGL/egl_layers.h @@ -17,18 +17,19 @@ #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 { @@ -45,8 +46,8 @@ public: void LoadLayers(); void InitLayers(egl_connection_t*); - void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); - void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, const char* const*); + void LayerPlatformEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*); + void LayerDriverEntries(layer_setup_func layer_setup, EGLFuncPointer*, char const* const*); bool Initialized(); std::string GetDebugLayers(); @@ -58,23 +59,18 @@ 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 efbe613542..ff4fe2dd9c 100644 --- a/opengl/libs/EGL/egl_object.cpp +++ b/opengl/libs/EGL/egl_object.cpp @@ -18,14 +18,19 @@ #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" @@ -48,6 +53,8 @@ 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), @@ -59,10 +66,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; @@ -82,13 +89,9 @@ egl_surface_t::~egl_surface_t() { void egl_surface_t::disconnect() { if (win != nullptr && connected) { - // 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); - } + 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; } @@ -170,30 +173,16 @@ 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; } @@ -207,15 +196,13 @@ 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; @@ -224,7 +211,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; @@ -270,7 +257,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; @@ -289,16 +276,13 @@ 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(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_nowake(dpy)), dpy(dpy), context(context), + config(config), read(nullptr), draw(nullptr), cnx(cnx), version(version) { +} void egl_context_t::onLooseCurrent() { read = nullptr; @@ -313,39 +297,31 @@ 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; - } - // 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); + 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); + } + } } } +// ---------------------------------------------------------------------------- }; // namespace android +// ---------------------------------------------------------------------------- diff --git a/opengl/libs/EGL/egl_object.h b/opengl/libs/EGL/egl_object.h index e593b1cf5b..fb2bdf4c51 100644 --- a/opengl/libs/EGL/egl_object.h +++ b/opengl/libs/EGL/egl_object.h @@ -17,25 +17,30 @@ #ifndef ANDROID_EGL_OBJECT_H #define ANDROID_EGL_OBJECT_H -#include <EGL/egl.h> -#include <EGL/eglext.h> -#include <log/log.h> -#include <stddef.h> +#include <atomic> #include <stdint.h> -#include <system/window.h> +#include <stddef.h> -#include <atomic> #include <string> #include <vector> +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#include <system/window.h> + +#include <log/log.h> + #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: @@ -59,7 +64,6 @@ public: egl_object_t* ref; LocalRef() = delete; LocalRef(const LocalRef* rhs) = delete; - public: ~LocalRef(); explicit LocalRef(egl_object_t* rhs); @@ -69,7 +73,9 @@ 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(); @@ -78,7 +84,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(); @@ -86,21 +92,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 @@ -110,7 +116,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(); } @@ -122,7 +128,6 @@ 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; @@ -146,13 +151,10 @@ 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(); @@ -184,15 +186,14 @@ 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); @@ -208,22 +209,30 @@ 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 de36a7aea6..aa24e8ee68 100644 --- a/opengl/libs/EGL/egl_platform_entries.cpp +++ b/opengl/libs/EGL/egl_platform_entries.cpp @@ -18,32 +18,36 @@ #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 <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 <cutils/compiler.h> +#include <log/log.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_layers.h" #include "egl_object.h" +#include "egl_layers.h" #include "egl_tls.h" #include "egl_trace.h" @@ -76,71 +80,71 @@ struct extension_map_t { * NOTE: Both strings MUST have a single space as the last character. */ -extern const char* const gBuiltinExtensionString; -extern const char* const gExtensionString; +extern char const * const gBuiltinExtensionString; +extern char const * const gExtensionString; // clang-format off // Extensions implemented by the EGL wrapper. -const char* const gBuiltinExtensionString = +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 " "EGL_ANDROID_front_buffer_auto_refresh " "EGL_ANDROID_get_frame_timestamps " - "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 " + "EGL_EXT_surface_CTA861_3_metadata " ; // Allowed list of extensions exposed to applications if implemented in the vendor driver. -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 " +char const * const gExtensionString = + "EGL_KHR_image " // mandatory + "EGL_KHR_image_base " // mandatory "EGL_EXT_image_gl_colorspace " - "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_image_pixmap " + "EGL_KHR_lock_surface " "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_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_gl_renderbuffer_image " "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_consumer_gltexture " - "EGL_KHR_stream_cross_process_fd " "EGL_KHR_stream_fifo " "EGL_KHR_stream_producer_eglsurface " - "EGL_KHR_surfaceless_context " - "EGL_KHR_wait_sync " // strongly recommended - "EGL_NV_context_priority_realtime " + "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_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 " ; -const char* const gClientExtensionString = - "EGL_ANDROID_GLES_layers " - "EGL_ANGLE_platform_angle " +char const * const gClientExtensionString = "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 /* @@ -150,69 +154,105 @@ const char* 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")) +#define FILTER_EXTENSIONS(procname) \ + (!strcmp((procname), "eglSetBlobCacheFuncsANDROID") || \ + !strcmp((procname), "eglHibernateProcessIMG") || \ + !strcmp((procname), "eglAwakenProcessIMG")) // accesses protected by sExtensionMapMutex static std::unordered_map<std::string, __eglMustCastToProperFunctionPointerType> sGLExtensionMap; @@ -221,8 +261,9 @@ 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; } @@ -232,17 +273,14 @@ static void (*findProcAddress(const char* name, const extension_map_t* map, size // ---------------------------------------------------------------------------- -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(); } // ---------------------------------------------------------------------------- @@ -275,8 +313,9 @@ EGLDisplay eglGetPlatformDisplayImpl(EGLenum platform, void* native_display, // Initialization // ---------------------------------------------------------------------------- -EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint* major, EGLint* minor) { - egl_display_t* dp = get_display(dpy); +EGLBoolean eglInitializeImpl(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + egl_display_ptr dp = get_display(dpy); if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); EGLBoolean res = dp->initialize(major, minor); @@ -284,12 +323,13 @@ 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_t* dp = get_display(dpy); + egl_display_ptr dp = get_display(dpy); if (!dp) return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); EGLBoolean res = dp->terminate(); @@ -301,12 +341,14 @@ EGLBoolean eglTerminateImpl(EGLDisplay dpy) { // configuration // ---------------------------------------------------------------------------- -EGLBoolean eglGetConfigsImpl(EGLDisplay dpy, EGLConfig* configs, EGLint config_size, - EGLint* num_config) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglGetConfigsImpl(EGLDisplay dpy, + EGLConfig *configs, + EGLint config_size, EGLint *num_config) +{ + const egl_display_ptr 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); } @@ -315,88 +357,96 @@ EGLBoolean eglGetConfigsImpl(EGLDisplay dpy, EGLConfig* configs, EGLint config_s 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_t* dp = validate_display(dpy); +EGLBoolean eglChooseConfigImpl( EGLDisplay dpy, const EGLint *attrib_list, + EGLConfig *configs, EGLint config_size, + EGLint *num_config) +{ + const egl_display_ptr 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) 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++; - } + 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 (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; + // 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; + } + } + } } - } - return cnx->egl.eglChooseConfig(dp->disp.dpy, attrib_list, configs, config_size, num_config); + res = cnx->egl.eglChooseConfig( + dp->disp.dpy, attrib_list, configs, config_size, num_config); + } + return res; } -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_t* dp = validate_display_connection(dpy, &cnx); + const egl_display_ptr 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); } // ---------------------------------------------------------------------------- @@ -434,7 +484,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_t* dp) { +static std::vector<EGLint> getDriverColorSpaces(egl_display_ptr dp) { std::vector<EGLint> colorSpaces; // sRGB and linear are always supported when color space support is present. @@ -459,8 +509,7 @@ static std::vector<EGLint> getDriverColorSpaces(egl_display_t* 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; @@ -470,7 +519,7 @@ static std::vector<EGLint> getDriverColorSpaces(egl_display_t* dp) { // If there is no color space attribute in attrib_list, colorSpace is left // unmodified. template <typename AttrType> -static EGLBoolean processAttributes(egl_display_t* dp, ANativeWindow* window, +static EGLBoolean processAttributes(egl_display_ptr 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) { @@ -650,7 +699,7 @@ EGLBoolean sendSurfaceMetadata(egl_surface_t* s) { } template <typename AttrType, typename CreateFuncType> -EGLSurface eglCreateWindowSurfaceTmpl(egl_display_t* dp, egl_connection_t* cnx, EGLConfig config, +EGLSurface eglCreateWindowSurfaceTmpl(egl_display_ptr dp, egl_connection_t* cnx, EGLConfig config, ANativeWindow* window, const AttrType* attrib_list, CreateFuncType createWindowSurfaceFunc) { const AttrType* origAttribList = attrib_list; @@ -719,7 +768,7 @@ EGLSurface eglCreateWindowSurfaceTmpl(egl_display_t* 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, config, window, surface, + egl_surface_t* s = new egl_surface_t(dp.get(), config, window, surface, getReportedColorSpace(colorSpace), cnx); return s; } @@ -740,8 +789,8 @@ typedef EGLSurface(EGLAPIENTRYP PFNEGLCREATEPLATFORMWINDOWSURFACEPROC)( EGLSurface eglCreateWindowSurfaceImpl(EGLDisplay dpy, EGLConfig config, NativeWindowType window, const EGLint* attrib_list) { - egl_connection_t* cnx = nullptr; - egl_display_t* dp = validate_display_connection(dpy, &cnx); + egl_connection_t* cnx = NULL; + egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { return eglCreateWindowSurfaceTmpl< EGLint, PFNEGLCREATEWINDOWSURFACEPROC>(dp, cnx, config, window, attrib_list, @@ -752,8 +801,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 = nullptr; - egl_display_t* dp = validate_display_connection(dpy, &cnx); + egl_connection_t* cnx = NULL; + egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { if (cnx->driverVersion >= EGL_MAKE_VERSION(1, 5, 0)) { if (cnx->egl.eglCreatePlatformWindowSurface) { @@ -793,8 +842,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 = nullptr; - const egl_display_t* dp = validate_display_connection(dpy, &cnx); + egl_connection_t* cnx = NULL; + egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); } @@ -804,7 +853,7 @@ EGLSurface eglCreatePlatformPixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config EGLSurface eglCreatePixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config*/, NativePixmapType /*pixmap*/, const EGLint* /*attrib_list*/) { egl_connection_t* cnx = nullptr; - const egl_display_t* dp = validate_display_connection(dpy, &cnx); + egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { return setError(EGL_BAD_PARAMETER, EGL_NO_SURFACE); } @@ -814,33 +863,36 @@ EGLSurface eglCreatePixmapSurfaceImpl(EGLDisplay dpy, EGLConfig /*config*/, EGLSurface eglCreatePbufferSurfaceImpl(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list) { egl_connection_t* cnx = nullptr; - egl_display_t* dp = validate_display_connection(dpy, &cnx); - if (!dp) return EGL_NO_SURFACE; - - EGLDisplay iDpy = dp->disp.dpy; - android_pixel_format format; - getNativePixelFormat(iDpy, cnx, config, &format); + 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(); - // 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; + 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; + } } - 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); + return EGL_NO_SURFACE; } EGLBoolean eglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surface) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); egl_surface_t* const s = get_surface(surface); @@ -853,10 +905,10 @@ EGLBoolean eglDestroySurfaceImpl(EGLDisplay dpy, EGLSurface surface) { EGLBoolean eglQuerySurfaceImpl(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), surface); if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); egl_surface_t const* const s = get_surface(surface); @@ -871,12 +923,12 @@ EGLBoolean eglQuerySurfaceImpl(EGLDisplay dpy, EGLSurface surface, EGLint attrib } void EGLAPI eglBeginFrameImpl(EGLDisplay dpy, EGLSurface surface) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return; } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), surface); if (!_s.get()) { setError(EGL_BAD_SURFACE, EGL_FALSE); } @@ -886,13 +938,14 @@ 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_t* dp = validate_display_connection(dpy, &cnx); + const egl_display_ptr dp = validate_display_connection(dpy, cnx); if (dp) { if (share_list != EGL_NO_CONTEXT) { - if (!ContextRef(dp, share_list).get()) { + if (!ContextRef(dp.get(), share_list).get()) { return setError(EGL_BAD_CONTEXT, EGL_NO_CONTEXT); } egl_context_t* const c = get_context(share_list); @@ -914,8 +967,8 @@ EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config, EGLContext sha } }; } - 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; @@ -939,14 +992,17 @@ EGLContext eglCreateContextImpl(EGLDisplay dpy, EGLConfig config, EGLContext sha return EGL_NO_CONTEXT; } -EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx) { - const egl_display_t* dp = validate_display(dpy); - if (!dp) return EGL_FALSE; +EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx) +{ + const egl_display_ptr dp = validate_display(dpy); + if (!dp) + return EGL_FALSE; - ContextRef _c(dp, ctx); - if (!_c.get()) return setError(EGL_BAD_CONTEXT, (EGLBoolean)EGL_FALSE); + ContextRef _c(dp.get(), 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(); @@ -954,21 +1010,24 @@ EGLBoolean eglDestroyContextImpl(EGLDisplay dpy, EGLContext ctx) { return result; } -EGLBoolean eglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) { - egl_display_t* dp = validate_display(dpy); +EGLBoolean eglMakeCurrentImpl( EGLDisplay dpy, EGLSurface draw, + EGLSurface read, EGLContext ctx) +{ + egl_display_ptr 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, ctx); - SurfaceRef _d(dp, draw); - SurfaceRef _r(dp, read); + ContextRef _c(dp.get(), ctx); + SurfaceRef _d(dp.get(), draw); + SurfaceRef _r(dp.get(), read); // validate the context (if not EGL_NO_CONTEXT) if ((ctx != EGL_NO_CONTEXT) && !_c.get()) { @@ -977,17 +1036,17 @@ EGLBoolean eglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw, EGLSurface read, } // 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); @@ -1019,7 +1078,10 @@ EGLBoolean eglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw, EGLSurface read, 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) { @@ -1040,72 +1102,81 @@ EGLBoolean eglMakeCurrentImpl(EGLDisplay dpy, EGLSurface draw, EGLSurface read, return result; } -EGLBoolean eglQueryContextImpl(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglQueryContextImpl( EGLDisplay dpy, EGLContext ctx, + EGLint attribute, EGLint *value) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - ContextRef _c(dp, ctx); + ContextRef _c(dp.get(), 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) { @@ -1117,7 +1188,8 @@ 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; @@ -1133,7 +1205,8 @@ static __eglMustCastToProperFunctionPointerType findBuiltinWrapper(const char* p return nullptr; } -__eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char* procname) { +__eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char *procname) +{ if (FILTER_EXTENSIONS(procname)) { return nullptr; } @@ -1180,10 +1253,13 @@ __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; @@ -1192,7 +1268,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 @@ -1224,7 +1300,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]; } @@ -1234,6 +1310,7 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddressImpl(const char* procn class FrameCompletionThread { public: + static void queueSync(EGLSyncKHR sync) { static FrameCompletionThread thread; @@ -1250,6 +1327,7 @@ public: } private: + FrameCompletionThread() : mFramesQueued(0), mFramesCompleted(0) { std::thread thread(&FrameCompletionThread::loop, this); thread.detach(); @@ -1304,13 +1382,15 @@ private: std::mutex mMutex; }; -EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, EGLint* rects, - EGLint n_rects) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, + EGLint *rects, EGLint n_rects) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, draw); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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); @@ -1326,11 +1406,11 @@ EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, EGLi 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); } } @@ -1365,35 +1445,41 @@ EGLBoolean eglSwapBuffersWithDamageKHRImpl(EGLDisplay dpy, EGLSurface draw, EGLi } if (s->cnx->egl.eglSwapBuffersWithDamageKHR) { - return s->cnx->egl.eglSwapBuffersWithDamageKHR(dp->disp.dpy, s->surface, rects, n_rects); + 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.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_t* dp = validate_display(dpy); +EGLBoolean eglCopyBuffersImpl( EGLDisplay dpy, EGLSurface surface, + NativePixmapType target) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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_t* dp = validate_display(dpy); - if (!dp) return (const char*)nullptr; + const egl_display_ptr dp = validate_display(dpy); + if (!dp) return (const char *) nullptr; switch (name) { case EGL_VENDOR: @@ -1407,12 +1493,13 @@ 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_t* dp = validate_display(dpy); - if (!dp) return (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; switch (name) { case EGL_VENDOR: @@ -1426,22 +1513,24 @@ 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_t* dp = validate_display(dpy); +EGLBoolean eglSurfaceAttribImpl( + EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint value) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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()) { @@ -1453,9 +1542,7 @@ EGLBoolean eglSurfaceAttribImpl(EGLDisplay dpy, EGLSurface surface, EGLint attri if (attribute == EGL_TIMESTAMPS_ANDROID) { if (!s->getNativeWindow()) { - // According to the spec, "if surface is not a window surface this has no - // effect." - return EGL_TRUE; + return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); } int err = native_window_enable_frame_timestamps(s->getNativeWindow(), value != 0); return (err == 0) ? EGL_TRUE : setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); @@ -1466,41 +1553,51 @@ EGLBoolean eglSurfaceAttribImpl(EGLDisplay dpy, EGLSurface surface, EGLint attri } 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_t* dp = validate_display(dpy); +EGLBoolean eglBindTexImageImpl( + EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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_t* dp = validate_display(dpy); +EGLBoolean eglReleaseTexImageImpl( + EGLDisplay dpy, EGLSurface surface, EGLint buffer) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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_t* dp = validate_display(dpy); +EGLBoolean eglSwapIntervalImpl(EGLDisplay dpy, EGLint interval) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLBoolean res = EGL_TRUE; @@ -1512,13 +1609,16 @@ 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) { @@ -1529,7 +1629,8 @@ 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; @@ -1539,7 +1640,8 @@ 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(); @@ -1549,7 +1651,8 @@ 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(); @@ -1562,15 +1665,16 @@ 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_t* dp = validate_display_connection(dpy, &cnx); + const egl_display_ptr 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); } @@ -1579,28 +1683,34 @@ EGLSurface eglCreatePbufferFromClientBufferImpl(EGLDisplay dpy, EGLenum buftype, // EGL_EGLEXT_VERSION 3 // ---------------------------------------------------------------------------- -EGLBoolean eglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface, const EGLint* attrib_list) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglLockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface, + const EGLint *attrib_list) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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_t* dp = validate_display(dpy); +EGLBoolean eglUnlockSurfaceKHRImpl(EGLDisplay dpy, EGLSurface surface) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; - SurfaceRef _s(dp, surface); - if (!_s.get()) return setError(EGL_BAD_SURFACE, (EGLBoolean)EGL_FALSE); + SurfaceRef _s(dp.get(), 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); } @@ -1613,7 +1723,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_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_NO_IMAGE_KHR; std::vector<AttrType> strippedAttribs; @@ -1622,7 +1732,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 && @@ -1636,15 +1746,14 @@ EGLImageKHR eglCreateImageTmpl(EGLDisplay dpy, EGLContext ctx, EGLenum target, strippedAttribs.push_back(EGL_NONE); } - ContextRef _c(dp, ctx); + ContextRef _c(dp.get(), 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; } @@ -1683,7 +1792,7 @@ EGLImage eglCreateImageImpl(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLC EGLBoolean eglDestroyImageTmpl(EGLDisplay dpy, EGLImageKHR img, PFNEGLDESTROYIMAGEKHRPROC destroyImageFunc) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLBoolean result = EGL_FALSE; @@ -1720,7 +1829,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_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_NO_SYNC_KHR; egl_connection_t* const cnx = &gEGLImpl; @@ -1759,7 +1868,7 @@ EGLSync eglCreateSyncImpl(EGLDisplay dpy, EGLenum type, const EGLAttrib* attrib_ EGLBoolean eglDestroySyncTmpl(EGLDisplay dpy, EGLSyncKHR sync, PFNEGLDESTROYSYNCKHRPROC eglDestroySyncFunc) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLBoolean result = EGL_FALSE; @@ -1788,7 +1897,7 @@ EGLBoolean eglDestroySyncImpl(EGLDisplay dpy, EGLSyncKHR sync) { } EGLBoolean eglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLBoolean result = EGL_FALSE; @@ -1801,7 +1910,7 @@ EGLBoolean eglSignalSyncKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLenum mode) { EGLint eglClientWaitSyncTmpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout, PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncFunc) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLint result = EGL_FALSE; @@ -1833,7 +1942,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_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; EGLBoolean result = EGL_FALSE; @@ -1878,93 +1987,106 @@ EGLBoolean eglGetSyncAttribKHRImpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint attri .eglGetSyncAttribKHR); } -EGLStreamKHR eglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint* attrib_list) { - const egl_display_t* dp = validate_display(dpy); +EGLStreamKHR eglCreateStreamKHRImpl(EGLDisplay dpy, const EGLint *attrib_list) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglDestroyStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglStreamAttribKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, + EGLenum attribute, EGLint value) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglQueryStreamKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, + EGLenum attribute, EGLint *value) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglQueryStreamu64KHRImpl(EGLDisplay dpy, EGLStreamKHR stream, + EGLenum attribute, EGLuint64KHR *value) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglQueryStreamTimeKHRImpl(EGLDisplay dpy, EGLStreamKHR stream, + EGLenum attribute, EGLTimeKHR *value) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); + EGLStreamKHR stream, const EGLint *attrib_list) +{ + egl_display_ptr 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, config, nullptr, surface, + egl_surface_t* s = new egl_surface_t(dp.get(), config, nullptr, surface, EGL_GL_COLORSPACE_LINEAR_KHR, cnx); return s; } @@ -1972,63 +2094,77 @@ EGLSurface eglCreateStreamProducerSurfaceKHRImpl(EGLDisplay dpy, EGLConfig confi return EGL_NO_SURFACE; } -EGLBoolean eglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy, EGLStreamKHR stream) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglStreamConsumerGLTextureExternalKHRImpl(EGLDisplay dpy, + EGLStreamKHR stream) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglStreamConsumerAcquireKHRImpl(EGLDisplay dpy, + EGLStreamKHR stream) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLBoolean eglStreamConsumerReleaseKHRImpl(EGLDisplay dpy, + EGLStreamKHR stream) +{ + const egl_display_ptr 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_t* dp = validate_display(dpy); +EGLNativeFileDescriptorKHR eglGetStreamFileDescriptorKHRImpl( + EGLDisplay dpy, EGLStreamKHR stream) +{ + const egl_display_ptr 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(dpy, stream); + result = cnx->egl.eglGetStreamFileDescriptorKHR( + dp->disp.dpy, stream); } return result; } -EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl(EGLDisplay dpy, - EGLNativeFileDescriptorKHR file_descriptor) { - const egl_display_t* dp = validate_display(dpy); +EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl( + EGLDisplay dpy, EGLNativeFileDescriptorKHR file_descriptor) +{ + const egl_display_ptr 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; } @@ -2041,7 +2177,7 @@ EGLStreamKHR eglCreateStreamFromFileDescriptorKHRImpl(EGLDisplay dpy, template <typename ReturnType, typename FuncType> ReturnType eglWaitSyncTmpl(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, FuncType eglWaitSyncFunc) { - const egl_display_t* dp = validate_display(dpy); + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_FALSE; ReturnType result = EGL_FALSE; egl_connection_t* const cnx = &gEGLImpl; @@ -2078,8 +2214,9 @@ EGLBoolean eglWaitSyncImpl(EGLDisplay dpy, EGLSync sync, EGLint flags) { // ANDROID extensions // ---------------------------------------------------------------------------- -EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync) { - const egl_display_t* dp = validate_display(dpy); +EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) return EGL_NO_NATIVE_FENCE_FD_ANDROID; EGLint result = EGL_NO_NATIVE_FENCE_FD_ANDROID; @@ -2091,33 +2228,42 @@ EGLint eglDupNativeFenceFDANDROIDImpl(EGLDisplay dpy, EGLSyncKHR sync) { } EGLBoolean eglPresentationTimeANDROIDImpl(EGLDisplay dpy, EGLSurface surface, - EGLnsecsANDROID time) { - const egl_display_t* dp = validate_display(dpy); + EGLnsecsANDROID time) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return EGL_FALSE; } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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) { +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__ if (!buffer) return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr); - return const_cast<ANativeWindowBuffer*>(AHardwareBuffer_to_ANativeWindowBuffer(buffer)); + return const_cast<ANativeWindowBuffer *>(AHardwareBuffer_to_ANativeWindowBuffer(buffer)); +#else + return setError(EGL_BAD_PARAMETER, (EGLClientBuffer) nullptr); +#endif } // ---------------------------------------------------------------------------- // NVIDIA extensions // ---------------------------------------------------------------------------- -EGLuint64NV eglGetSystemTimeFrequencyNVImpl() { +EGLuint64NV eglGetSystemTimeFrequencyNVImpl() +{ EGLuint64NV ret = 0; egl_connection_t* const cnx = &gEGLImpl; @@ -2128,7 +2274,8 @@ EGLuint64NV eglGetSystemTimeFrequencyNVImpl() { return setErrorQuiet(EGL_BAD_DISPLAY, (EGLuint64NV)0); } -EGLuint64NV eglGetSystemTimeNVImpl() { +EGLuint64NV eglGetSystemTimeNVImpl() +{ EGLuint64NV ret = 0; egl_connection_t* const cnx = &gEGLImpl; @@ -2142,40 +2289,43 @@ EGLuint64NV eglGetSystemTimeNVImpl() { // ---------------------------------------------------------------------------- // Partial update extension // ---------------------------------------------------------------------------- -EGLBoolean eglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surface, EGLint* rects, - EGLint n_rects) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglSetDamageRegionKHRImpl(EGLDisplay dpy, EGLSurface surface, + EGLint *rects, EGLint n_rects) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { setError(EGL_BAD_DISPLAY, EGL_FALSE); return EGL_FALSE; } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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_t* dp = validate_display(dpy); +EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface, + EGLuint64KHR *frameId) { + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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); @@ -2196,19 +2346,19 @@ EGLBoolean eglGetNextFrameIdANDROIDImpl(EGLDisplay dpy, EGLSurface surface, EGLu } EGLBoolean eglGetCompositorTimingANDROIDImpl(EGLDisplay dpy, EGLSurface surface, - EGLint numTimestamps, const EGLint* names, - EGLnsecsANDROID* values) { - const egl_display_t* dp = validate_display(dpy); + EGLint numTimestamps, const EGLint *names, EGLnsecsANDROID *values) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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); @@ -2234,35 +2384,36 @@ 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_t* dp = validate_display(dpy); +EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl( + EGLDisplay dpy, EGLSurface surface, EGLint name) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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) { @@ -2280,19 +2431,20 @@ EGLBoolean eglGetCompositorTimingSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface } EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface, - EGLuint64KHR frameId, EGLint numTimestamps, - const EGLint* timestamps, EGLnsecsANDROID* values) { - const egl_display_t* dp = validate_display(dpy); + EGLuint64KHR frameId, EGLint numTimestamps, const EGLint *timestamps, + EGLnsecsANDROID *values) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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); @@ -2342,11 +2494,10 @@ 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: @@ -2365,19 +2516,20 @@ EGLBoolean eglGetFrameTimestampsANDROIDImpl(EGLDisplay dpy, EGLSurface surface, } } -EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface surface, - EGLint timestamp) { - const egl_display_t* dp = validate_display(dpy); +EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl( + EGLDisplay dpy, EGLSurface surface, EGLint timestamp) +{ + const egl_display_ptr dp = validate_display(dpy); if (!dp) { return setError(EGL_BAD_DISPLAY, (EGLBoolean)EGL_FALSE); } - SurfaceRef _s(dp, surface); + SurfaceRef _s(dp.get(), 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) { @@ -2399,7 +2551,8 @@ EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface s 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: @@ -2407,25 +2560,25 @@ EGLBoolean eglGetFrameTimestampSupportedANDROIDImpl(EGLDisplay dpy, EGLSurface s } } -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) { @@ -2434,11 +2587,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) { @@ -2447,11 +2600,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) { @@ -2460,11 +2613,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) { @@ -2473,7 +2626,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); } @@ -2482,8 +2635,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 }, @@ -2570,10 +2723,11 @@ 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) { @@ -2587,8 +2741,7 @@ 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 dd1dcc275f..8d118e07ed 100644 --- a/opengl/libs/EGL/egl_tls.cpp +++ b/opengl/libs/EGL/egl_tls.cpp @@ -16,10 +16,10 @@ #include "egl_tls.h" -#include <android-base/properties.h> -#include <log/log.h> #include <stdlib.h> +#include <android-base/properties.h> +#include <log/log.h> #include "CallStack.h" #include "egl_platform_entries.h" @@ -28,46 +28,33 @@ 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); } }; @@ -101,12 +88,14 @@ 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); } @@ -122,6 +111,7 @@ bool egl_tls_t::logNoContextCall() { return true; } return false; + } egl_tls_t* egl_tls_t::getTLS() { @@ -171,9 +161,10 @@ 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 b5fcc1a805..86a375c002 100644 --- a/opengl/libs/EGL/egl_tls.h +++ b/opengl/libs/EGL/egl_tls.h @@ -18,9 +18,12 @@ #define ANDROID_EGL_TLS_H #include <EGL/egl.h> + #include <pthread.h> +// ---------------------------------------------------------------------------- namespace android { +// ---------------------------------------------------------------------------- class DbgContext; @@ -29,14 +32,15 @@ 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(); @@ -46,20 +50,24 @@ 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 ffdf6761c6..7664de2231 100644 --- a/opengl/libs/EGL/egl_trace.h +++ b/opengl/libs/EGL/egl_trace.h @@ -18,14 +18,16 @@ #if defined(__ANDROID__) -#include <cutils/trace.h> #include <stdint.h> +#include <cutils/trace.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 ATRACE_NAME(name) android::EglScopedTrace PASTE(___tracer, __LINE__)(ATRACE_TAG, name) +#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) // ATRACE_CALL is an ATRACE_NAME that uses the current function name. #define ATRACE_CALL() ATRACE_NAME(__FUNCTION__) @@ -34,9 +36,13 @@ 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 fcc11f1b55..5fbffbd16c 100644 --- a/opengl/libs/EGL/egldefs.h +++ b/opengl/libs/EGL/egldefs.h @@ -17,32 +17,40 @@ #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) { - const char* 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) { + + char const* const* entries = platform_names; EGLFuncPointer* curr = reinterpret_cast<EGLFuncPointer*>(&platform); while (*entries) { const char* name = *entries; @@ -58,34 +66,41 @@ 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 const char* const gl_names[]; -extern const char* const gl_names_1[]; -extern const char* const egl_names[]; + +extern char const * const gl_names[]; +extern char const * const gl_names_1[]; +extern char const * 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 b3d6f74e86..fedc7893db 100644 --- a/opengl/libs/EGL/getProcAddress.cpp +++ b/opengl/libs/EGL/getProcAddress.cpp @@ -16,12 +16,15 @@ #include <ctype.h> #include <errno.h> -#include <log/log.h> #include <stdlib.h> +#include <log/log.h> + #include "egldefs.h" +// ---------------------------------------------------------------------------- namespace android { +// ---------------------------------------------------------------------------- #undef API_ENTRY #undef CALL_GL_EXTENSION_API @@ -31,7 +34,6 @@ 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" @@ -237,13 +239,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), -// clang-format on +#define GL_EXTENSION_ARRAY(_n) GL_EXTENSION_NAME(_n), -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 @@ -253,4 +255,7 @@ extern const __eglMustCastToProperFunctionPointerType #undef API_ENTRY #undef CALL_GL_EXTENSION_API +// ---------------------------------------------------------------------------- }; // namespace android +// ---------------------------------------------------------------------------- + diff --git a/opengl/tests/Android.bp b/opengl/tests/Android.bp index da717bddf8..639f351c69 100644 --- a/opengl/tests/Android.bp +++ b/opengl/tests/Android.bp @@ -1,16 +1,4 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - // SPDX-license-identifier-BSD - // SPDX-license-identifier-MIT - // legacy_notice - default_applicable_licenses: ["frameworks_native_license"], -} - subdirs = [ "angeles", "configdump", @@ -28,3 +16,4 @@ subdirs = [ "hwc", "lib", ] + diff --git a/opengl/tests/EGLTest/Android.bp b/opengl/tests/EGLTest/Android.bp index 51c937614f..e3912a84e6 100644 --- a/opengl/tests/EGLTest/Android.bp +++ b/opengl/tests/EGLTest/Android.bp @@ -1,13 +1,4 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "EGL_test", diff --git a/opengl/tests/EGLTest/EGL_test.cpp b/opengl/tests/EGLTest/EGL_test.cpp index bbd786d155..510226d051 100644 --- a/opengl/tests/EGLTest/EGL_test.cpp +++ b/opengl/tests/EGLTest/EGL_test.cpp @@ -138,7 +138,7 @@ TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { }; EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -148,7 +148,7 @@ TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -258,7 +258,7 @@ TEST_F(EGLTest, EGLDisplayP3) { EXPECT_EQ(components[2], 8); EXPECT_EQ(components[3], 8); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -268,7 +268,7 @@ TEST_F(EGLTest, EGLDisplayP3) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; EGLint winAttrs[] = { @@ -306,7 +306,7 @@ TEST_F(EGLTest, EGLDisplayP3Passthrough) { get8BitConfig(config); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -316,7 +316,7 @@ TEST_F(EGLTest, EGLDisplayP3Passthrough) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; EGLint winAttrs[] = { @@ -398,7 +398,7 @@ TEST_F(EGLTest, EGLDisplayP31010102) { EXPECT_EQ(components[2], 10); EXPECT_EQ(components[3], 2); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -408,7 +408,7 @@ TEST_F(EGLTest, EGLDisplayP31010102) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; EGLint winAttrs[] = { @@ -570,7 +570,7 @@ TEST_F(EGLTest, EGLBT2020Linear) { ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -580,7 +580,7 @@ TEST_F(EGLTest, EGLBT2020Linear) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -622,7 +622,7 @@ TEST_F(EGLTest, EGLBT2020PQ) { ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -632,7 +632,7 @@ TEST_F(EGLTest, EGLBT2020PQ) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; std::vector<EGLint> winAttrs; @@ -705,7 +705,7 @@ TEST_F(EGLTest, EGLConfigFP16) { EXPECT_GE(components[2], 16); EXPECT_GE(components[3], 16); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -714,7 +714,7 @@ TEST_F(EGLTest, EGLConfigFP16) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -734,7 +734,7 @@ TEST_F(EGLTest, EGLNoConfigContext) { ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_KHR_no_config_context")); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -809,7 +809,7 @@ TEST_F(EGLTest, EGLConfig1010102) { EXPECT_EQ(components[2], 10); EXPECT_EQ(components[3], 2); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -819,7 +819,7 @@ TEST_F(EGLTest, EGLConfig1010102) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -835,7 +835,7 @@ TEST_F(EGLTest, EGLInvalidColorspaceAttribute) { ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -845,7 +845,7 @@ TEST_F(EGLTest, EGLInvalidColorspaceAttribute) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -882,7 +882,7 @@ TEST_F(EGLTest, EGLUnsupportedColorspaceFormatCombo) { ASSERT_EQ(EGL_UNSIGNED_TRUE, success); ASSERT_EQ(1, numConfigs); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -892,7 +892,7 @@ TEST_F(EGLTest, EGLUnsupportedColorspaceFormatCombo) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -913,7 +913,7 @@ TEST_F(EGLTest, EGLCreateWindowFailAndSucceed) { ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -923,7 +923,7 @@ TEST_F(EGLTest, EGLCreateWindowFailAndSucceed) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; @@ -953,7 +953,7 @@ TEST_F(EGLTest, EGLCreateWindowTwoColorspaces) { ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); - struct MockConsumer : public BnConsumerListener { + struct DummyConsumer : public BnConsumerListener { void onFrameAvailable(const BufferItem& /* item */) override {} void onBuffersReleased() override {} void onSidebandStreamChanged() override {} @@ -963,7 +963,7 @@ TEST_F(EGLTest, EGLCreateWindowTwoColorspaces) { sp<IGraphicBufferProducer> producer; sp<IGraphicBufferConsumer> consumer; BufferQueue::createBufferQueue(&producer, &consumer); - consumer->consumerConnect(new MockConsumer, false); + consumer->consumerConnect(new DummyConsumer, false); sp<Surface> mSTC = new Surface(producer); sp<ANativeWindow> mANW = mSTC; diff --git a/opengl/tests/angeles/Android.bp b/opengl/tests/angeles/Android.bp index 5b81501241..5c398a6323 100644 --- a/opengl/tests/angeles/Android.bp +++ b/opengl/tests/angeles/Android.bp @@ -1,50 +1,5 @@ // Copyright 2006 The Android Open Source Project -package { - default_applicable_licenses: [ - "frameworks_native_opengl_tests_angeles_license", - ], -} - -// Added automatically by a large-scale-change that took the approach of -// 'apply every license found to every target'. While this makes sure we respect -// every license restriction, it may not be entirely correct. -// -// e.g. GPL in an MIT project might only apply to the contrib/ directory. -// -// Please consider splitting the single license below into multiple licenses, -// taking care not to lose any license_kind information, and overriding the -// default license using the 'licenses: [...]' property on targets as needed. -// -// For unused files, consider creating a 'fileGroup' with "//visibility:private" -// to attach the license to, and including a comment whether the files may be -// used in the current project. -// -// large-scale-change included anything that looked like it might be a license -// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. -// -// Please consider removing redundant or irrelevant files from 'license_text:'. -// -// large-scale-change filtered out the below license kinds as false-positives: -// SPDX-license-identifier-LGPL -// SPDX-license-identifier-LGPL-2.1 -// SPDX-license-identifier-LGPL-3.0 -// See: http://go/android-license-faq -license { - name: "frameworks_native_opengl_tests_angeles_license", - visibility: [":__subpackages__"], - license_kinds: [ - "SPDX-license-identifier-BSD", - "SPDX-license-identifier-MIT", - "legacy_notice", - ], - license_text: [ - "license-BSD.txt", - "license-LGPL.txt", - "license.txt", - ], -} - cc_test { name: "angeles", diff --git a/opengl/tests/configdump/Android.bp b/opengl/tests/configdump/Android.bp index 1bb5983299..ee96797030 100644 --- a/opengl/tests/configdump/Android.bp +++ b/opengl/tests/configdump/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-configdump", diff --git a/opengl/tests/fillrate/Android.bp b/opengl/tests/fillrate/Android.bp index e4bff014fc..689cee42d5 100644 --- a/opengl/tests/fillrate/Android.bp +++ b/opengl/tests/fillrate/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-fillrate", diff --git a/opengl/tests/filter/Android.bp b/opengl/tests/filter/Android.bp index b93576fd0c..23241e1116 100644 --- a/opengl/tests/filter/Android.bp +++ b/opengl/tests/filter/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-filter", diff --git a/opengl/tests/finish/Android.bp b/opengl/tests/finish/Android.bp index c2dfbc35b9..be20851e8f 100644 --- a/opengl/tests/finish/Android.bp +++ b/opengl/tests/finish/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-finish", diff --git a/opengl/tests/gl2_basic/Android.bp b/opengl/tests/gl2_basic/Android.bp index c54bdf335d..f4538adb54 100644 --- a/opengl/tests/gl2_basic/Android.bp +++ b/opengl/tests/gl2_basic/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl2_basic", diff --git a/opengl/tests/gl2_cameraeye/Android.bp b/opengl/tests/gl2_cameraeye/Android.bp index 6b8ee85d9c..00e00dfc91 100644 --- a/opengl/tests/gl2_cameraeye/Android.bp +++ b/opengl/tests/gl2_cameraeye/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GL2CameraEye", // Only compile source java files in this apk. diff --git a/opengl/tests/gl2_copyTexImage/Android.bp b/opengl/tests/gl2_copyTexImage/Android.bp index 0a84d254a5..87fa7ea37d 100644 --- a/opengl/tests/gl2_copyTexImage/Android.bp +++ b/opengl/tests/gl2_copyTexImage/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl2_copyTexImage", diff --git a/opengl/tests/gl2_java/Android.bp b/opengl/tests/gl2_java/Android.bp index a33075e3b7..a8e5d7d70b 100644 --- a/opengl/tests/gl2_java/Android.bp +++ b/opengl/tests/gl2_java/Android.bp @@ -1,15 +1,6 @@ //######################################################################## // OpenGL ES 2.0 Java sample //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GL2Java", srcs: ["**/*.java"], diff --git a/opengl/tests/gl2_jni/Android.bp b/opengl/tests/gl2_jni/Android.bp index 79773cb05f..65f89b159e 100644 --- a/opengl/tests/gl2_jni/Android.bp +++ b/opengl/tests/gl2_jni/Android.bp @@ -3,15 +3,6 @@ // This makefile builds both an activity and a shared library. //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GL2JNI", srcs: ["**/*.java"], @@ -26,7 +17,6 @@ cc_library_shared { "-Werror", "-Wno-error=unused-parameter", ], - header_libs: ["jni_headers"], srcs: ["jni/gl_code.cpp"], shared_libs: [ "liblog", diff --git a/opengl/tests/gl2_yuvtex/Android.bp b/opengl/tests/gl2_yuvtex/Android.bp index fadf0e8fc5..b64d94d320 100644 --- a/opengl/tests/gl2_yuvtex/Android.bp +++ b/opengl/tests/gl2_yuvtex/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl2_yuvtex", diff --git a/opengl/tests/gl_basic/Android.bp b/opengl/tests/gl_basic/Android.bp index f55cd0dfe5..5eed17e876 100644 --- a/opengl/tests/gl_basic/Android.bp +++ b/opengl/tests/gl_basic/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl_basic", diff --git a/opengl/tests/gl_jni/Android.bp b/opengl/tests/gl_jni/Android.bp index dc46483551..5bec336dd1 100644 --- a/opengl/tests/gl_jni/Android.bp +++ b/opengl/tests/gl_jni/Android.bp @@ -4,15 +4,6 @@ //######################################################################## // Build activity -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GLJNI", srcs: ["**/*.java"], @@ -28,7 +19,6 @@ cc_library_shared { "-Werror", "-Wno-error=unused-parameter", ], - header_libs: ["jni_headers"], srcs: ["jni/gl_code.cpp"], shared_libs: [ "liblog", diff --git a/opengl/tests/gl_perf/Android.bp b/opengl/tests/gl_perf/Android.bp index ca0f7e8e33..25a317c3e3 100644 --- a/opengl/tests/gl_perf/Android.bp +++ b/opengl/tests/gl_perf/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl2_perf", diff --git a/opengl/tests/gl_perfapp/Android.bp b/opengl/tests/gl_perfapp/Android.bp index 2f623462cf..cf899acfee 100644 --- a/opengl/tests/gl_perfapp/Android.bp +++ b/opengl/tests/gl_perfapp/Android.bp @@ -2,15 +2,6 @@ // OpenGL ES Perf App // This makefile builds both an activity and a shared library. //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GLPerf", srcs: ["**/*.java"], @@ -26,7 +17,6 @@ cc_library_shared { "-Werror", "-Wno-error=unused-parameter", ], - header_libs: ["jni_headers"], srcs: ["jni/gl_code.cpp"], shared_libs: [ "liblog", diff --git a/opengl/tests/gl_yuvtex/Android.bp b/opengl/tests/gl_yuvtex/Android.bp index 784418679c..9b4924ab82 100644 --- a/opengl/tests/gl_yuvtex/Android.bp +++ b/opengl/tests/gl_yuvtex/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gl_yuvtex", diff --git a/opengl/tests/gldual/Android.bp b/opengl/tests/gldual/Android.bp index 3d6e677f0d..24325666e6 100644 --- a/opengl/tests/gldual/Android.bp +++ b/opengl/tests/gldual/Android.bp @@ -4,15 +4,6 @@ //######################################################################## // Build activity -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "GLDual", srcs: ["**/*.java"], @@ -29,7 +20,6 @@ cc_library_shared { "-Werror", "-Wno-error=unused-parameter", ], - header_libs: ["jni_headers"], srcs: ["jni/gl_code.cpp"], shared_libs: [ "liblog", diff --git a/opengl/tests/gralloc/Android.bp b/opengl/tests/gralloc/Android.bp index 5fb4556697..33c3dbaa17 100644 --- a/opengl/tests/gralloc/Android.bp +++ b/opengl/tests/gralloc/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_test { name: "test-opengl-gralloc", diff --git a/opengl/tests/hwc/Android.bp b/opengl/tests/hwc/Android.bp index 719eb114a1..55f058f922 100644 --- a/opengl/tests/hwc/Android.bp +++ b/opengl/tests/hwc/Android.bp @@ -12,15 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_defaults { name: "hwc_tests_defaults", diff --git a/opengl/tests/lib/Android.bp b/opengl/tests/lib/Android.bp index 05c9397dfa..2f6095d8e7 100644 --- a/opengl/tests/lib/Android.bp +++ b/opengl/tests/lib/Android.bp @@ -12,15 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_library_static { name: "libglTest", diff --git a/opengl/tests/lib/WindowSurface.cpp b/opengl/tests/lib/WindowSurface.cpp index fd4522e757..dfb9c92b5f 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/DisplayMode.h> +#include <ui/DisplayConfig.h> #include <ui/DisplayState.h> using namespace android; @@ -42,10 +42,10 @@ WindowSurface::WindowSurface() { return; } - ui::DisplayMode displayMode; - err = SurfaceComposerClient::getActiveDisplayMode(displayToken, &displayMode); + DisplayConfig displayConfig; + err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &displayConfig); if (err != NO_ERROR) { - fprintf(stderr, "ERROR: unable to get active display mode\n"); + fprintf(stderr, "ERROR: unable to get active display config\n"); return; } @@ -56,7 +56,7 @@ WindowSurface::WindowSurface() { return; } - const ui::Size& resolution = displayMode.resolution; + const ui::Size& resolution = displayConfig.resolution; auto width = resolution.getWidth(); auto height = resolution.getHeight(); diff --git a/opengl/tests/lighting1709/Android.bp b/opengl/tests/lighting1709/Android.bp index 79daa26096..e734dd1d2c 100644 --- a/opengl/tests/lighting1709/Android.bp +++ b/opengl/tests/lighting1709/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_test { name: "LightingTest", srcs: ["**/*.java"], diff --git a/opengl/tests/linetex/Android.bp b/opengl/tests/linetex/Android.bp index 61976e599f..dbc2cdbd44 100644 --- a/opengl/tests/linetex/Android.bp +++ b/opengl/tests/linetex/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_binary { name: "test-opengl-linetex", srcs: ["linetex.cpp"], diff --git a/opengl/tests/swapinterval/Android.bp b/opengl/tests/swapinterval/Android.bp index a76f4cfb9a..eed4dff3a5 100644 --- a/opengl/tests/swapinterval/Android.bp +++ b/opengl/tests/swapinterval/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_binary { name: "test-opengl-swapinterval", srcs: ["swapinterval.cpp"], diff --git a/opengl/tests/testFramerate/Android.bp b/opengl/tests/testFramerate/Android.bp index 4334d88749..5aa83b0753 100644 --- a/opengl/tests/testFramerate/Android.bp +++ b/opengl/tests/testFramerate/Android.bp @@ -2,15 +2,6 @@ // Test framerate and look for hiccups //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "TestFramerate", srcs: ["**/*.java"], diff --git a/opengl/tests/testLatency/Android.bp b/opengl/tests/testLatency/Android.bp index 473cb426cf..c516dc3d17 100644 --- a/opengl/tests/testLatency/Android.bp +++ b/opengl/tests/testLatency/Android.bp @@ -1,15 +1,6 @@ //######################################################################## // Test end-to-end latency. //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "TestLatency", sdk_version: "8", diff --git a/opengl/tests/testPauseResume/Android.bp b/opengl/tests/testPauseResume/Android.bp index 8171e1fc8e..810e895ce2 100644 --- a/opengl/tests/testPauseResume/Android.bp +++ b/opengl/tests/testPauseResume/Android.bp @@ -1,13 +1,4 @@ // OpenGL ES JNI sample -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "TestEGL", srcs: ["**/*.java"], diff --git a/opengl/tests/testViewport/Android.bp b/opengl/tests/testViewport/Android.bp index 13ce3ad481..629b573a2a 100644 --- a/opengl/tests/testViewport/Android.bp +++ b/opengl/tests/testViewport/Android.bp @@ -2,15 +2,6 @@ // OpenGL ES JNI sample // This makefile builds both an activity and a shared library. //######################################################################## -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - android_app { name: "TestViewport", srcs: ["**/*.java"], diff --git a/opengl/tests/textures/Android.bp b/opengl/tests/textures/Android.bp index f113ff78d2..84adda2aa4 100644 --- a/opengl/tests/textures/Android.bp +++ b/opengl/tests/textures/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_binary { name: "test-opengl-textures", srcs: ["textures.cpp"], diff --git a/opengl/tests/tritex/Android.bp b/opengl/tests/tritex/Android.bp index 87da93f6bc..390397b9da 100644 --- a/opengl/tests/tritex/Android.bp +++ b/opengl/tests/tritex/Android.bp @@ -1,12 +1,3 @@ -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "frameworks_native_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["frameworks_native_license"], -} - cc_binary { name: "test-opengl-tritex", srcs: ["tritex.cpp"], diff --git a/opengl/tools/glgen/gen b/opengl/tools/glgen/gen index 7fd9c3a735..41fcf1bd95 100755 --- a/opengl/tools/glgen/gen +++ b/opengl/tools/glgen/gen @@ -1,23 +1,11 @@ #!/bin/bash set -u set -e - -if [ -z "$ANDROID_BUILD_TOP" ] ; then - echo "ANDROID_BUILD_TOP is not set, did you run lunch?" - exit 1 -fi - -# Avoid spewing files in any location other than the intended one. -if [ ! -x "$PWD/gen" ] ; then - echo "Run this script from its parent directory". - exit 1 -fi - rm -rf out generated mkdir out -# Create stub Java files for Android APIs that are used by the code we generate. +# Create dummy Java files for Android APIs that are used by the code we generate. # This allows us to test the generated code without building the rest of Android. mkdir -p out/javax/microedition/khronos/opengles @@ -104,7 +92,7 @@ rm src/*.class # Add UnsupportedAppUsage.java to known sources. mkdir -p out/android/compat/annotation -cp ${ANDROID_BUILD_TOP}/tools/platform-compat/java/android/compat/annotation/UnsupportedAppUsage.java out/android/compat/annotation +cp ../../../../../tools/platform-compat/annotation/src/java/android/compat/annotation/UnsupportedAppUsage.java out/android/compat/annotation pushd out > /dev/null mkdir classes @@ -165,23 +153,23 @@ compareGenerated() { fi } -compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp -compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java +compareGenerated ../../../../base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp +compareGenerated ../../../../base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java do - compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x + compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x done for x in EGL14 EGL15 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext GLES32 do - compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java - compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/core/jni generated/C android_opengl_${x}.cpp + compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java + compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp done for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface EGLImage EGLSync do - compareGenerated ${ANDROID_BUILD_TOP}/frameworks/base/opengl/java/android/opengl generated/android/opengl ${x}.java + compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java done if [ $KEEP_GENERATED == "0" ] ; then diff --git a/opengl/tools/glgen/src/JniCodeEmitter.java b/opengl/tools/glgen/src/JniCodeEmitter.java index 59ef3c81c2..9c80212011 100644 --- a/opengl/tools/glgen/src/JniCodeEmitter.java +++ b/opengl/tools/glgen/src/JniCodeEmitter.java @@ -15,7 +15,6 @@ */ import java.io.PrintStream; -import java.util.Arrays; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -202,33 +201,6 @@ public class JniCodeEmitter { out.println(iii + ");"); } - // Function to automatically generate properly formatted function calls that - // comply with clang format rules - public static String formatFunctionCall(String indent, String functionCall) { - final int MAXLEN = 100; - String tokens[] = functionCall.split("\\(|\\)", 2); - String params[] = tokens[1].split(",\\s*"); - String formatted = indent + tokens[0] + "("; - char[] chars = new char[indent.length() + tokens[0].length() + 1]; - Arrays.fill(chars, ' '); - String multiIndent = new String(chars); - ArrayList<String> lines = new ArrayList<String>(); - for(int i = 0; i < params.length; i++) { - String terminator = ((i == params.length - 1) ? "" : ","); - if(indent.length() + formatted.length() + params[i].length() > MAXLEN) { - lines.add(formatted); - if (!indent.equals(multiIndent)) { - indent = multiIndent; - } - formatted = indent + params[i] + terminator; - } else { - formatted += (i == 0 ? "" : " ") + params[i] + terminator; - } - } - lines.add(formatted); - return String.join("\n", lines); - } - void printIfcheckPostamble(PrintStream out, boolean isBuffer, boolean emitExceptionCheck, String iii) { printIfcheckPostamble(out, isBuffer, emitExceptionCheck, @@ -1566,19 +1538,14 @@ public class JniCodeEmitter { "_exception ? JNI_ABORT : 0" : "0")) + ");"); } else { - String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" : - "_" + cfunc.getArgName(cIndex) + "BufferOffset"; - String typeCast = "(char *)" + cfunc.getArgName(cIndex); - String withOffset = "(void *)(" + typeCast + " - " + bufferOffset + ")"; - String releasePointerCall = ( + out.println(indent + indent + "releasePointer(_env, " + array + ", " + - withOffset + + cfunc.getArgName(cIndex) + ", " + (cfunc.getArgType(cIndex).isConst() ? "JNI_FALSE" : (emitExceptionCheck ? "_exception ? JNI_FALSE : JNI_TRUE" : "JNI_TRUE")) + ");"); - out.println(formatFunctionCall(indent + indent, releasePointerCall)); } out.println(indent + "}"); } diff --git a/opengl/tools/glgen/stubs/egl/EGL14Header.java-if b/opengl/tools/glgen/stubs/egl/EGL14Header.java-if index 951ecffc32..9932556d27 100644 --- a/opengl/tools/glgen/stubs/egl/EGL14Header.java-if +++ b/opengl/tools/glgen/stubs/egl/EGL14Header.java-if @@ -21,8 +21,8 @@ package android.opengl; import android.compat.annotation.UnsupportedAppUsage; import android.graphics.SurfaceTexture; import android.view.Surface; -import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.view.SurfaceHolder; /** * EGL 1.4 diff --git a/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp b/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp index b2ea041cd5..93203fd529 100644 --- a/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp +++ b/opengl/tools/glgen/stubs/egl/EGL14cHeader.cpp @@ -20,7 +20,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #include "jni.h" -#include <nativehelper/JNIPlatformHelp.h> +#include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/android_view_Surface.h> #include <android_runtime/android_graphics_SurfaceTexture.h> diff --git a/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp b/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp index 6dffac5945..34cb3e1a99 100644 --- a/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp +++ b/opengl/tools/glgen/stubs/egl/EGL15cHeader.cpp @@ -20,7 +20,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #include "jni.h" -#include <nativehelper/JNIPlatformHelp.h> +#include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <utils/misc.h> diff --git a/opengl/tools/glgen/stubs/egl/EGLExtcHeader.cpp b/opengl/tools/glgen/stubs/egl/EGLExtcHeader.cpp index be8b3e3977..b3b069082a 100644 --- a/opengl/tools/glgen/stubs/egl/EGLExtcHeader.cpp +++ b/opengl/tools/glgen/stubs/egl/EGLExtcHeader.cpp @@ -20,7 +20,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #include "jni.h" -#include <nativehelper/JNIPlatformHelp.h> +#include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/android_view_Surface.h> #include <android_runtime/android_graphics_SurfaceTexture.h> diff --git a/opengl/tools/glgen/stubs/gles11/common.cpp b/opengl/tools/glgen/stubs/gles11/common.cpp index d84a693e6c..e763b4e983 100644 --- a/opengl/tools/glgen/stubs/gles11/common.cpp +++ b/opengl/tools/glgen/stubs/gles11/common.cpp @@ -1,5 +1,5 @@ #include <jni.h> -#include <nativehelper/JNIPlatformHelp.h> +#include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <utils/misc.h> #include <assert.h> diff --git a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp index 9cab1d6a59..c12efc3795 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp +++ b/opengl/tools/glgen/stubs/jsr239/GLCHeader.cpp @@ -20,7 +20,7 @@ #pragma GCC diagnostic ignored "-Wunused-function" #include "jni.h" -#include <nativehelper/JNIPlatformHelp.h> +#include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> #include <utils/misc.h> diff --git a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl index 32c9d7d09f..afcc3ebe7f 100644 --- a/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl +++ b/opengl/tools/glgen/stubs/jsr239/GLImplHeader.java-impl @@ -19,7 +19,6 @@ package com.google.android.gles_jni; import android.app.AppGlobals; -import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.os.Build; @@ -27,7 +26,6 @@ import android.os.UserHandle; import android.util.Log; import java.nio.Buffer; - import javax.microedition.khronos.opengles.GL10; import javax.microedition.khronos.opengles.GL10Ext; import javax.microedition.khronos.opengles.GL11; @@ -57,7 +55,6 @@ public class GLImpl implements GL10, GL10Ext, GL11, GL11Ext, GL11ExtensionPack { private boolean have_OES_framebuffer_object; private boolean have_OES_texture_cube_map; - @UnsupportedAppUsage public GLImpl() { } |