Skip to content

Commit e2729d5

Browse files
author
Android Build Coastguard Worker
committed
Snap for 12730913 from c6bc5f5 to 25Q1-release
Change-Id: If31fb9cf3f6772716f7cd0464b09176c1014b648
2 parents a21cbcd + c6bc5f5 commit e2729d5

10 files changed

Lines changed: 684 additions & 40 deletions

File tree

opengl/libs/Android.bp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ ndk_library {
6363
unversioned_until: "current",
6464
}
6565

66+
aconfig_declarations {
67+
name: "egl_flags",
68+
package: "com.android.graphics.egl.flags",
69+
container: "system",
70+
srcs: ["EGL/egl_flags.aconfig"],
71+
}
72+
73+
cc_aconfig_library {
74+
name: "libegl_flags",
75+
aconfig_declarations: "egl_flags",
76+
}
77+
6678
cc_defaults {
6779
name: "gl_libs_defaults",
6880
cflags: [
@@ -136,6 +148,7 @@ cc_library_static {
136148
],
137149
export_include_dirs: ["EGL"],
138150
shared_libs: [
151+
"libegl_flags",
139152
"libz",
140153
],
141154
}
@@ -166,6 +179,7 @@ cc_library_shared {
166179
"android.hardware.configstore@1.0",
167180
"android.hardware.configstore-utils",
168181
"libbase",
182+
"libegl_flags",
169183
"libhidlbase",
170184
"libnativebridge_lazy",
171185
"libnativeloader_lazy",
@@ -202,6 +216,7 @@ cc_test {
202216
"EGL/MultifileBlobCache_test.cpp",
203217
],
204218
shared_libs: [
219+
"libegl_flags",
205220
"libutils",
206221
"libz",
207222
],

opengl/libs/EGL/MultifileBlobCache.cpp

Lines changed: 197 additions & 36 deletions
Large diffs are not rendered by default.

opengl/libs/EGL/MultifileBlobCache.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
#include "FileBlobCache.h"
3434

35+
#include <com_android_graphics_egl_flags.h>
36+
37+
using namespace com::android::graphics::egl;
38+
3539
namespace android {
3640

3741
constexpr uint32_t kMultifileBlobCacheVersion = 2;
@@ -45,9 +49,9 @@ struct MultifileHeader {
4549
};
4650

4751
struct MultifileEntryStats {
52+
uint32_t entryHash;
4853
EGLsizeiANDROID valueSize;
4954
size_t fileSize;
50-
time_t accessTime;
5155
};
5256

5357
struct MultifileStatus {
@@ -100,6 +104,26 @@ class DeferredTask {
100104
size_t mBufferSize;
101105
};
102106

107+
#if COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
108+
struct MultifileTimeLess {
109+
bool operator()(const struct timespec& t1, const struct timespec& t2) const {
110+
if (t1.tv_sec == t2.tv_sec) {
111+
// If seconds are equal, check nanoseconds
112+
return t1.tv_nsec < t2.tv_nsec;
113+
} else {
114+
// Otherwise, compare seconds
115+
return t1.tv_sec < t2.tv_sec;
116+
}
117+
}
118+
};
119+
120+
// The third parameter here causes all entries to be sorted by access time,
121+
// so oldest will be accessed first in applyLRU
122+
using MultifileEntryStatsMap =
123+
std::multimap<struct timespec, MultifileEntryStats, MultifileTimeLess>;
124+
using MultifileEntryStatsMapIter = MultifileEntryStatsMap::iterator;
125+
#endif // COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
126+
103127
class MultifileBlobCache {
104128
public:
105129
MultifileBlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize,
@@ -115,6 +139,7 @@ class MultifileBlobCache {
115139

116140
size_t getTotalSize() const { return mTotalCacheSize; }
117141
size_t getTotalEntries() const { return mTotalCacheEntries; }
142+
size_t getTotalCacheSizeDivisor() const { return mTotalCacheSizeDivisor; }
118143

119144
const std::string& getCurrentBuildId() const { return mBuildId; }
120145
void setCurrentBuildId(const std::string& buildId) { mBuildId = buildId; }
@@ -124,10 +149,11 @@ class MultifileBlobCache {
124149

125150
private:
126151
void trackEntry(uint32_t entryHash, EGLsizeiANDROID valueSize, size_t fileSize,
127-
time_t accessTime);
152+
const timespec& accessTime);
128153
bool contains(uint32_t entryHash) const;
129154
bool removeEntry(uint32_t entryHash);
130155
MultifileEntryStats getEntryStats(uint32_t entryHash);
156+
void updateEntryTime(uint32_t entryHash, const timespec& newTime);
131157

132158
bool createStatus(const std::string& baseDir);
133159
bool checkStatus(const std::string& baseDir);
@@ -151,8 +177,14 @@ class MultifileBlobCache {
151177
std::string mBuildId;
152178
uint32_t mCacheVersion;
153179

180+
#if COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
181+
std::unordered_map<uint32_t, MultifileEntryStatsMapIter> mEntries;
182+
MultifileEntryStatsMap mEntryStats;
183+
#else
154184
std::unordered_set<uint32_t> mEntries;
155185
std::unordered_map<uint32_t, MultifileEntryStats> mEntryStats;
186+
#endif // COM_ANDROID_GRAPHICS_EGL_FLAGS(MULTIFILE_BLOBCACHE_ADVANCED_USAGE)
187+
156188
std::unordered_map<uint32_t, MultifileHotCache> mHotCache;
157189

158190
size_t mMaxKeySize;
@@ -161,6 +193,7 @@ class MultifileBlobCache {
161193
size_t mMaxTotalEntries;
162194
size_t mTotalCacheSize;
163195
size_t mTotalCacheEntries;
196+
size_t mTotalCacheSizeDivisor;
164197
size_t mHotCacheLimit;
165198
size_t mHotCacheEntryLimit;
166199
size_t mHotCacheSize;

0 commit comments

Comments
 (0)