Loading opengl/libs/EGL/BlobCache.cpp +35 −44 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ #include "BlobCache.h" #include <android-base/properties.h> #include <errno.h> #include <inttypes.h> #include <android-base/properties.h> #include <log/log.h> #include <chrono> namespace android { Loading @@ -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) { Loading @@ -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) { Loading Loading @@ -103,8 +103,8 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, } 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)); Loading @@ -125,17 +125,17 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, 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)); Loading @@ -154,8 +154,8 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value, ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize); memcpy(value, valueBlob->getData(), valueBlobSize); } else { ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, valueBlobSize); ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, valueBlobSize); } return valueBlobSize; } Loading Loading @@ -259,8 +259,7 @@ int BlobCache::unflatten(void const* buffer, size_t size) { return -EINVAL; } const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>( &byteBuffer[byteOffset]); const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>(&byteBuffer[byteOffset]); size_t keySize = eheader->mKeySize; size_t valueSize = eheader->mValueSize; size_t entrySize = sizeof(EntryHeader) + keySize + valueSize; Loading Loading @@ -304,10 +303,8 @@ bool BlobCache::isCleanable() const { return mTotalSize > mMaxTotalSize / 2; } BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) { BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) { if (data != nullptr && copyData) { memcpy(const_cast<void*>(mData), data, size); } Loading Loading @@ -335,19 +332,13 @@ size_t BlobCache::Blob::getSize() const { return mSize; } BlobCache::CacheEntry::CacheEntry() { } BlobCache::CacheEntry::CacheEntry() {} BlobCache::CacheEntry::CacheEntry( const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value): mKey(key), mValue(value) { } BlobCache::CacheEntry::CacheEntry(const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value) : mKey(key), mValue(value) {} BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce): mKey(ce.mKey), mValue(ce.mValue) { } BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce) : mKey(ce.mKey), mValue(ce.mValue) {} bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const { return *mKey < *rhs.mKey; Loading opengl/libs/EGL/BlobCache.h +2 −5 Original line number Diff line number Diff line Loading @@ -54,8 +54,7 @@ public: // 0 < keySize // value != NULL // 0 < valueSize void set(const void* key, size_t keySize, const void* value, size_t valueSize); void set(const void* key, size_t keySize, const void* value, size_t valueSize); // get retrieves from the cache the binary value associated with a given // binary key. If the key is present in the cache then the length of the Loading @@ -75,7 +74,6 @@ public: // 0 <= valueSize size_t get(const void* key, size_t keySize, void* value, size_t valueSize); // getFlattenedSize returns the number of bytes needed to store the entire // serialized cache. size_t getFlattenedSize() const; Loading Loading @@ -168,7 +166,6 @@ private: void setValue(const std::shared_ptr<Blob>& value); private: // mKey is the key that identifies the cache entry. std::shared_ptr<Blob> mKey; Loading Loading @@ -245,6 +242,6 @@ private: std::vector<CacheEntry> mCacheEntries; }; } } // namespace android #endif // ANDROID_BLOB_CACHE_H opengl/libs/EGL/BlobCache_test.cpp +37 −43 Original line number Diff line number Diff line Loading @@ -14,25 +14,24 @@ ** limitations under the License. */ #include "BlobCache.h" #include <fcntl.h> #include <gtest/gtest.h> #include <stdio.h> #include <memory> #include <gtest/gtest.h> #include "BlobCache.h" namespace android { template<typename T> using sp = std::shared_ptr<T>; template <typename T> using sp = std::shared_ptr<T>; class BlobCacheTest : public ::testing::Test { protected: enum { OK = 0, BAD_VALUE = -EINVAL BAD_VALUE = -EINVAL, }; enum { Loading @@ -41,13 +40,9 @@ 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; }; Loading Loading @@ -195,8 +190,7 @@ TEST_F(BlobCacheTest, CacheMaxValueSizeSucceeds) { for (int i = 0; i < MAX_VALUE_SIZE; i++) { buf[i] = 0xee; } ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE)); ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE)); for (int i = 0; i < MAX_VALUE_SIZE; i++) { SCOPED_TRACE(i); ASSERT_EQ('b', buf[i]); Loading opengl/libs/EGL/CallStack.h +3 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,9 @@ #pragma once #include <log/log.h> #include <backtrace/Backtrace.h> #include <log/log.h> #include <memory> class CallStack { Loading @@ -35,4 +36,3 @@ public: } } }; opengl/libs/EGL/Loader.h +14 −21 Original line number Diff line number Diff line Loading @@ -17,13 +17,10 @@ #ifndef ANDROID_EGL_LOADER_H #define ANDROID_EGL_LOADER_H #include <stdint.h> #include <EGL/egl.h> #include <stdint.h> // ---------------------------------------------------------------------------- namespace android { // ---------------------------------------------------------------------------- struct egl_connection_t; Loading Loading @@ -62,16 +59,12 @@ private: void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask); void init_angle_backend(void* dso, egl_connection_t* cnx); static __attribute__((noinline)) void init_api(void* dso, char const * const * api, char const * const * ref_api, static __attribute__((noinline)) void init_api(void* dso, const char* const* api, const char* const* ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress); }; // ---------------------------------------------------------------------------- }; // namespace android // ---------------------------------------------------------------------------- #endif /* ANDROID_EGL_LOADER_H */ Loading
opengl/libs/EGL/BlobCache.cpp +35 −44 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ #include "BlobCache.h" #include <android-base/properties.h> #include <errno.h> #include <inttypes.h> #include <android-base/properties.h> #include <log/log.h> #include <chrono> namespace android { Loading @@ -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) { Loading @@ -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) { Loading Loading @@ -103,8 +103,8 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, } 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)); Loading @@ -125,17 +125,17 @@ void BlobCache::set(const void* key, size_t keySize, const void* value, 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)); Loading @@ -154,8 +154,8 @@ size_t BlobCache::get(const void* key, size_t keySize, void* value, ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize); memcpy(value, valueBlob->getData(), valueBlobSize); } else { ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, valueBlobSize); ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize, valueBlobSize); } return valueBlobSize; } Loading Loading @@ -259,8 +259,7 @@ int BlobCache::unflatten(void const* buffer, size_t size) { return -EINVAL; } const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>( &byteBuffer[byteOffset]); const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>(&byteBuffer[byteOffset]); size_t keySize = eheader->mKeySize; size_t valueSize = eheader->mValueSize; size_t entrySize = sizeof(EntryHeader) + keySize + valueSize; Loading Loading @@ -304,10 +303,8 @@ bool BlobCache::isCleanable() const { return mTotalSize > mMaxTotalSize / 2; } BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) { BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) { if (data != nullptr && copyData) { memcpy(const_cast<void*>(mData), data, size); } Loading Loading @@ -335,19 +332,13 @@ size_t BlobCache::Blob::getSize() const { return mSize; } BlobCache::CacheEntry::CacheEntry() { } BlobCache::CacheEntry::CacheEntry() {} BlobCache::CacheEntry::CacheEntry( const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value): mKey(key), mValue(value) { } BlobCache::CacheEntry::CacheEntry(const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value) : mKey(key), mValue(value) {} BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce): mKey(ce.mKey), mValue(ce.mValue) { } BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce) : mKey(ce.mKey), mValue(ce.mValue) {} bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const { return *mKey < *rhs.mKey; Loading
opengl/libs/EGL/BlobCache.h +2 −5 Original line number Diff line number Diff line Loading @@ -54,8 +54,7 @@ public: // 0 < keySize // value != NULL // 0 < valueSize void set(const void* key, size_t keySize, const void* value, size_t valueSize); void set(const void* key, size_t keySize, const void* value, size_t valueSize); // get retrieves from the cache the binary value associated with a given // binary key. If the key is present in the cache then the length of the Loading @@ -75,7 +74,6 @@ public: // 0 <= valueSize size_t get(const void* key, size_t keySize, void* value, size_t valueSize); // getFlattenedSize returns the number of bytes needed to store the entire // serialized cache. size_t getFlattenedSize() const; Loading Loading @@ -168,7 +166,6 @@ private: void setValue(const std::shared_ptr<Blob>& value); private: // mKey is the key that identifies the cache entry. std::shared_ptr<Blob> mKey; Loading Loading @@ -245,6 +242,6 @@ private: std::vector<CacheEntry> mCacheEntries; }; } } // namespace android #endif // ANDROID_BLOB_CACHE_H
opengl/libs/EGL/BlobCache_test.cpp +37 −43 Original line number Diff line number Diff line Loading @@ -14,25 +14,24 @@ ** limitations under the License. */ #include "BlobCache.h" #include <fcntl.h> #include <gtest/gtest.h> #include <stdio.h> #include <memory> #include <gtest/gtest.h> #include "BlobCache.h" namespace android { template<typename T> using sp = std::shared_ptr<T>; template <typename T> using sp = std::shared_ptr<T>; class BlobCacheTest : public ::testing::Test { protected: enum { OK = 0, BAD_VALUE = -EINVAL BAD_VALUE = -EINVAL, }; enum { Loading @@ -41,13 +40,9 @@ 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; }; Loading Loading @@ -195,8 +190,7 @@ TEST_F(BlobCacheTest, CacheMaxValueSizeSucceeds) { for (int i = 0; i < MAX_VALUE_SIZE; i++) { buf[i] = 0xee; } ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE)); ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE)); for (int i = 0; i < MAX_VALUE_SIZE; i++) { SCOPED_TRACE(i); ASSERT_EQ('b', buf[i]); Loading
opengl/libs/EGL/CallStack.h +3 −3 Original line number Diff line number Diff line Loading @@ -16,8 +16,9 @@ #pragma once #include <log/log.h> #include <backtrace/Backtrace.h> #include <log/log.h> #include <memory> class CallStack { Loading @@ -35,4 +36,3 @@ public: } } };
opengl/libs/EGL/Loader.h +14 −21 Original line number Diff line number Diff line Loading @@ -17,13 +17,10 @@ #ifndef ANDROID_EGL_LOADER_H #define ANDROID_EGL_LOADER_H #include <stdint.h> #include <EGL/egl.h> #include <stdint.h> // ---------------------------------------------------------------------------- namespace android { // ---------------------------------------------------------------------------- struct egl_connection_t; Loading Loading @@ -62,16 +59,12 @@ private: void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask); void init_angle_backend(void* dso, egl_connection_t* cnx); static __attribute__((noinline)) void init_api(void* dso, char const * const * api, char const * const * ref_api, static __attribute__((noinline)) void init_api(void* dso, const char* const* api, const char* const* ref_api, __eglMustCastToProperFunctionPointerType* curr, getProcAddressType getProcAddress); }; // ---------------------------------------------------------------------------- }; // namespace android // ---------------------------------------------------------------------------- #endif /* ANDROID_EGL_LOADER_H */