| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | ** Copyright 2011, The Android Open Source Project | 
|  | 3 | ** | 
|  | 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | ** you may not use this file except in compliance with the License. | 
|  | 6 | ** You may obtain a copy of the License at | 
|  | 7 | ** | 
|  | 8 | **     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | ** | 
|  | 10 | ** Unless required by applicable law or agreed to in writing, software | 
|  | 11 | ** distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | ** See the License for the specific language governing permissions and | 
|  | 14 | ** limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 17 | // #define LOG_NDEBUG 0 | 
|  | 18 |  | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 19 | #include "egl_cache.h" | 
|  | 20 |  | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 21 | #include <android-base/properties.h> | 
|  | 22 | #include <inttypes.h> | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 23 | #include <log/log.h> | 
| Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 24 | #include <private/EGL/cache.h> | 
| Jiyong Park | a243e5d | 2017-06-21 12:26:51 +0900 | [diff] [blame] | 25 | #include <unistd.h> | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 26 |  | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 27 | #include <thread> | 
|  | 28 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 29 | #include "../egl_impl.h" | 
|  | 30 | #include "egl_display.h" | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 31 |  | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 32 | // Monolithic cache size limits. | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 33 | static const size_t kMaxMonolithicKeySize = 12 * 1024; | 
|  | 34 | static const size_t kMaxMonolithicValueSize = 64 * 1024; | 
|  | 35 | static const size_t kMaxMonolithicTotalSize = 2 * 1024 * 1024; | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 36 |  | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 37 | // The time in seconds to wait before saving newly inserted monolithic cache entries. | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 38 | static const unsigned int kDeferredMonolithicSaveDelay = 4; | 
| Jamie Gennis | 99c3d70 | 2011-11-08 17:59:36 -0800 | [diff] [blame] | 39 |  | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 40 | // Multifile cache size limits | 
| Cody Northrop | 5dbcfa7 | 2023-03-24 15:34:09 -0600 | [diff] [blame] | 41 | constexpr uint32_t kMaxMultifileKeySize = 1 * 1024 * 1024; | 
|  | 42 | constexpr uint32_t kMaxMultifileValueSize = 8 * 1024 * 1024; | 
|  | 43 | constexpr uint32_t kMaxMultifileTotalSize = 32 * 1024 * 1024; | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 44 |  | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 45 | namespace android { | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | #define BC_EXT_STR "EGL_ANDROID_blob_cache" | 
|  | 48 |  | 
| Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 49 | // called from android_view_ThreadedRenderer.cpp | 
|  | 50 | void egl_set_cache_filename(const char* filename) { | 
|  | 51 | egl_cache_t::get()->setCacheFilename(filename); | 
|  | 52 | } | 
|  | 53 |  | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 54 | // | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 55 | // Callback functions passed to EGL. | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 56 | // | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 57 | static void setBlob(const void* key, EGLsizeiANDROID keySize, const void* value, | 
|  | 58 | EGLsizeiANDROID valueSize) { | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 59 | egl_cache_t::get()->setBlob(key, keySize, value, valueSize); | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 60 | } | 
|  | 61 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 62 | static EGLsizeiANDROID getBlob(const void* key, EGLsizeiANDROID keySize, void* value, | 
|  | 63 | EGLsizeiANDROID valueSize) { | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 64 | return egl_cache_t::get()->getBlob(key, keySize, value, valueSize); | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | // | 
|  | 68 | // egl_cache_t definition | 
|  | 69 | // | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 70 | egl_cache_t::egl_cache_t() | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 71 | : mInitialized(false), mMultifileMode(false), mCacheByteLimit(kMaxMonolithicTotalSize) {} | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 72 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 73 | egl_cache_t::~egl_cache_t() {} | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 74 |  | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 75 | egl_cache_t egl_cache_t::sCache; | 
|  | 76 |  | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 77 | egl_cache_t* egl_cache_t::get() { | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 78 | return &sCache; | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 79 | } | 
|  | 80 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 81 | void egl_cache_t::initialize(egl_display_t* display) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 82 | std::lock_guard<std::mutex> lock(mMutex); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 83 |  | 
|  | 84 | egl_connection_t* const cnx = &gEGLImpl; | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 85 | if (display && cnx->dso && cnx->major >= 0 && cnx->minor >= 0) { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 86 | const char* exts = display->disp.queryString.extensions; | 
|  | 87 | size_t bcExtLen = strlen(BC_EXT_STR); | 
|  | 88 | size_t extsLen = strlen(exts); | 
|  | 89 | bool equal = !strcmp(BC_EXT_STR, exts); | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 90 | bool atStart = !strncmp(BC_EXT_STR " ", exts, bcExtLen + 1); | 
|  | 91 | bool atEnd = (bcExtLen + 1) < extsLen && | 
|  | 92 | !strcmp(" " BC_EXT_STR, exts + extsLen - (bcExtLen + 1)); | 
| Mathias Agopian | 311b479 | 2017-02-28 15:00:49 -0800 | [diff] [blame] | 93 | bool inMiddle = strstr(exts, " " BC_EXT_STR " ") != nullptr; | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 94 | if (equal || atStart || atEnd || inMiddle) { | 
|  | 95 | PFNEGLSETBLOBCACHEFUNCSANDROIDPROC eglSetBlobCacheFuncsANDROID; | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 96 | eglSetBlobCacheFuncsANDROID = reinterpret_cast<PFNEGLSETBLOBCACHEFUNCSANDROIDPROC>( | 
|  | 97 | cnx->egl.eglGetProcAddress("eglSetBlobCacheFuncsANDROID")); | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 98 | if (eglSetBlobCacheFuncsANDROID == nullptr) { | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 99 | ALOGE("EGL_ANDROID_blob_cache advertised, " | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 100 | "but unable to get eglSetBlobCacheFuncsANDROID"); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 101 | return; | 
|  | 102 | } | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 103 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 104 | eglSetBlobCacheFuncsANDROID(display->disp.dpy, android::setBlob, android::getBlob); | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 105 | EGLint err = cnx->egl.eglGetError(); | 
|  | 106 | if (err != EGL_SUCCESS) { | 
|  | 107 | ALOGE("eglSetBlobCacheFuncsANDROID resulted in an error: " | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 108 | "%#x", | 
|  | 109 | err); | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 110 | } | 
|  | 111 | } | 
|  | 112 | } | 
| Mathias Agopian | ada798b | 2012-02-13 17:09:30 -0800 | [diff] [blame] | 113 |  | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 114 | mInitialized = true; | 
|  | 115 | } | 
|  | 116 |  | 
|  | 117 | void egl_cache_t::terminate() { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 118 | std::lock_guard<std::mutex> lock(mMutex); | 
| Stan Iliev | 9e7cd07 | 2017-10-09 15:56:10 -0400 | [diff] [blame] | 119 | if (mBlobCache) { | 
|  | 120 | mBlobCache->writeToFile(); | 
|  | 121 | } | 
| Yi Kong | 48a6cd2 | 2018-07-18 10:07:09 -0700 | [diff] [blame] | 122 | mBlobCache = nullptr; | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 123 | if (mMultifileBlobCache) { | 
|  | 124 | mMultifileBlobCache->finish(); | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 125 | } | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 126 | mMultifileBlobCache = nullptr; | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 127 | mInitialized = false; | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 128 | } | 
|  | 129 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 130 | void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize, const void* value, | 
|  | 131 | EGLsizeiANDROID valueSize) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 132 | std::lock_guard<std::mutex> lock(mMutex); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 133 |  | 
|  | 134 | if (keySize < 0 || valueSize < 0) { | 
| Steve Block | 32397c1 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 135 | ALOGW("EGL_ANDROID_blob_cache set: negative sizes are not allowed"); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 136 | return; | 
|  | 137 | } | 
|  | 138 |  | 
| Cody Northrop | 8422727 | 2023-02-27 15:59:27 -0700 | [diff] [blame] | 139 | updateMode(); | 
|  | 140 |  | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 141 | if (mInitialized) { | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 142 | if (mMultifileMode) { | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 143 | MultifileBlobCache* mbc = getMultifileBlobCacheLocked(); | 
|  | 144 | mbc->set(key, keySize, value, valueSize); | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 145 | } else { | 
|  | 146 | BlobCache* bc = getBlobCacheLocked(); | 
|  | 147 | bc->set(key, keySize, value, valueSize); | 
|  | 148 |  | 
|  | 149 | if (!mSavePending) { | 
|  | 150 | mSavePending = true; | 
|  | 151 | std::thread deferredSaveThread([this]() { | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 152 | sleep(kDeferredMonolithicSaveDelay); | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 153 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 154 | if (mInitialized && mBlobCache) { | 
|  | 155 | mBlobCache->writeToFile(); | 
|  | 156 | } | 
|  | 157 | mSavePending = false; | 
|  | 158 | }); | 
|  | 159 | deferredSaveThread.detach(); | 
|  | 160 | } | 
| Jamie Gennis | 99c3d70 | 2011-11-08 17:59:36 -0800 | [diff] [blame] | 161 | } | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 162 | } | 
|  | 163 | } | 
|  | 164 |  | 
| Yiwei Zhang | 8af0306 | 2020-08-12 21:28:15 -0700 | [diff] [blame] | 165 | EGLsizeiANDROID egl_cache_t::getBlob(const void* key, EGLsizeiANDROID keySize, void* value, | 
|  | 166 | EGLsizeiANDROID valueSize) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 167 | std::lock_guard<std::mutex> lock(mMutex); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 168 |  | 
|  | 169 | if (keySize < 0 || valueSize < 0) { | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 170 | ALOGW("EGL_ANDROID_blob_cache get: negative sizes are not allowed"); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 171 | return 0; | 
|  | 172 | } | 
|  | 173 |  | 
| Cody Northrop | 8422727 | 2023-02-27 15:59:27 -0700 | [diff] [blame] | 174 | updateMode(); | 
|  | 175 |  | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 176 | if (mInitialized) { | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 177 | if (mMultifileMode) { | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 178 | MultifileBlobCache* mbc = getMultifileBlobCacheLocked(); | 
|  | 179 | return mbc->get(key, keySize, value, valueSize); | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 180 | } else { | 
|  | 181 | BlobCache* bc = getBlobCacheLocked(); | 
|  | 182 | return bc->get(key, keySize, value, valueSize); | 
|  | 183 | } | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 184 | } | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 185 |  | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 186 | return 0; | 
|  | 187 | } | 
|  | 188 |  | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 189 | void egl_cache_t::setCacheMode(EGLCacheMode cacheMode) { | 
|  | 190 | mMultifileMode = (cacheMode == EGLCacheMode::Multifile); | 
|  | 191 | } | 
|  | 192 |  | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 193 | void egl_cache_t::setCacheFilename(const char* filename) { | 
| Mathias Agopian | 6542143 | 2017-03-08 11:49:05 -0800 | [diff] [blame] | 194 | std::lock_guard<std::mutex> lock(mMutex); | 
| Jamie Gennis | 98c6383 | 2011-11-07 17:03:54 -0800 | [diff] [blame] | 195 | mFilename = filename; | 
|  | 196 | } | 
|  | 197 |  | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 198 | void egl_cache_t::setCacheLimit(int64_t cacheByteLimit) { | 
|  | 199 | std::lock_guard<std::mutex> lock(mMutex); | 
|  | 200 |  | 
|  | 201 | if (!mMultifileMode) { | 
|  | 202 | // If we're not in multifile mode, ensure the cache limit is only being lowered, | 
|  | 203 | // not increasing above the hard coded platform limit | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 204 | if (cacheByteLimit > kMaxMonolithicTotalSize) { | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 205 | return; | 
|  | 206 | } | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 | mCacheByteLimit = cacheByteLimit; | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | size_t egl_cache_t::getCacheSize() { | 
|  | 213 | std::lock_guard<std::mutex> lock(mMutex); | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 214 | if (mMultifileBlobCache) { | 
|  | 215 | return mMultifileBlobCache->getTotalSize(); | 
| Cody Northrop | 2c9085b | 2022-12-12 11:35:54 -0700 | [diff] [blame] | 216 | } | 
|  | 217 | if (mBlobCache) { | 
|  | 218 | return mBlobCache->getSize(); | 
|  | 219 | } | 
|  | 220 | return 0; | 
|  | 221 | } | 
|  | 222 |  | 
| Cody Northrop | 8422727 | 2023-02-27 15:59:27 -0700 | [diff] [blame] | 223 | void egl_cache_t::updateMode() { | 
|  | 224 | // We don't set the mode in the constructor because these checks have | 
|  | 225 | // a non-trivial cost, and not all processes that instantiate egl_cache_t | 
|  | 226 | // will use it. | 
|  | 227 |  | 
|  | 228 | // If we've already set the mode, skip these checks | 
|  | 229 | static bool checked = false; | 
|  | 230 | if (checked) { | 
|  | 231 | return; | 
|  | 232 | } | 
|  | 233 | checked = true; | 
|  | 234 |  | 
|  | 235 | // Check the device config to decide whether multifile should be used | 
|  | 236 | if (base::GetBoolProperty("ro.egl.blobcache.multifile", false)) { | 
|  | 237 | mMultifileMode = true; | 
|  | 238 | ALOGV("Using multifile EGL blobcache"); | 
|  | 239 | } | 
|  | 240 |  | 
|  | 241 | // Allow forcing the mode for debug purposes | 
|  | 242 | std::string mode = base::GetProperty("debug.egl.blobcache.multifile", ""); | 
|  | 243 | if (mode == "true") { | 
|  | 244 | ALOGV("Forcing multifile cache due to debug.egl.blobcache.multifile == %s", mode.c_str()); | 
|  | 245 | mMultifileMode = true; | 
|  | 246 | } else if (mode == "false") { | 
|  | 247 | ALOGV("Forcing monolithic cache due to debug.egl.blobcache.multifile == %s", mode.c_str()); | 
|  | 248 | mMultifileMode = false; | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | if (mMultifileMode) { | 
|  | 252 | mCacheByteLimit = static_cast<size_t>( | 
|  | 253 | base::GetUintProperty<uint32_t>("ro.egl.blobcache.multifile_limit", | 
| Cody Northrop | 5dbcfa7 | 2023-03-24 15:34:09 -0600 | [diff] [blame] | 254 | kMaxMultifileTotalSize)); | 
| Cody Northrop | 8422727 | 2023-02-27 15:59:27 -0700 | [diff] [blame] | 255 |  | 
|  | 256 | // Check for a debug value | 
|  | 257 | int debugCacheSize = base::GetIntProperty("debug.egl.blobcache.multifile_limit", -1); | 
|  | 258 | if (debugCacheSize >= 0) { | 
|  | 259 | ALOGV("Overriding cache limit %zu with %i from debug.egl.blobcache.multifile_limit", | 
|  | 260 | mCacheByteLimit, debugCacheSize); | 
|  | 261 | mCacheByteLimit = debugCacheSize; | 
|  | 262 | } | 
|  | 263 |  | 
|  | 264 | ALOGV("Using multifile EGL blobcache limit of %zu bytes", mCacheByteLimit); | 
|  | 265 | } | 
|  | 266 | } | 
|  | 267 |  | 
| Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 268 | BlobCache* egl_cache_t::getBlobCacheLocked() { | 
|  | 269 | if (mBlobCache == nullptr) { | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 270 | mBlobCache.reset(new FileBlobCache(kMaxMonolithicKeySize, kMaxMonolithicValueSize, | 
|  | 271 | mCacheByteLimit, mFilename)); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 272 | } | 
| Mathias Agopian | b7f9a24 | 2017-03-08 22:29:31 -0800 | [diff] [blame] | 273 | return mBlobCache.get(); | 
| Jamie Gennis | 7660108 | 2011-11-06 14:14:33 -0800 | [diff] [blame] | 274 | } | 
|  | 275 |  | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 276 | MultifileBlobCache* egl_cache_t::getMultifileBlobCacheLocked() { | 
|  | 277 | if (mMultifileBlobCache == nullptr) { | 
| Cody Northrop | 5dbcfa7 | 2023-03-24 15:34:09 -0600 | [diff] [blame] | 278 | mMultifileBlobCache.reset(new MultifileBlobCache(kMaxMultifileKeySize, | 
|  | 279 | kMaxMultifileValueSize, mCacheByteLimit, | 
|  | 280 | mFilename)); | 
| Cody Northrop | 6cca6c2 | 2023-02-08 20:23:13 -0700 | [diff] [blame] | 281 | } | 
|  | 282 | return mMultifileBlobCache.get(); | 
|  | 283 | } | 
|  | 284 |  | 
| Jamie Gennis | aca51c0 | 2011-11-03 17:42:43 -0700 | [diff] [blame] | 285 | }; // namespace android |