Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d35dbe9e authored by Cody Northrop's avatar Cody Northrop Committed by Android (Google) Code Review
Browse files

Merge changes from topic "blobcache_enable_20230227" into udc-dev

* changes:
  EGL BlobCache: Check properties on use
  EGL BlobCache: Don't check system property during init
parents d5969792 8422727f
Loading
Loading
Loading
Loading
+49 −32
Original line number Diff line number Diff line
@@ -110,38 +110,6 @@ void egl_cache_t::initialize(egl_display_t* display) {
        }
    }

    // Check the device config to decide whether multifile should be used
    if (base::GetBoolProperty("ro.egl.blobcache.multifile", false)) {
        mMultifileMode = true;
        ALOGV("Using multifile EGL blobcache");
    }

    // Allow forcing the mode for debug purposes
    std::string mode = base::GetProperty("debug.egl.blobcache.multifile", "");
    if (mode == "true") {
        ALOGV("Forcing multifile cache due to debug.egl.blobcache.multifile == %s", mode.c_str());
        mMultifileMode = true;
    } else if (mode == "false") {
        ALOGV("Forcing monolithic cache due to debug.egl.blobcache.multifile == %s", mode.c_str());
        mMultifileMode = false;
    }

    if (mMultifileMode) {
        mCacheByteLimit = static_cast<size_t>(
                base::GetUintProperty<uint32_t>("ro.egl.blobcache.multifile_limit",
                                                kMultifileCacheByteLimit));

        // Check for a debug value
        int debugCacheSize = base::GetIntProperty("debug.egl.blobcache.multifile_limit", -1);
        if (debugCacheSize >= 0) {
            ALOGV("Overriding cache limit %zu with %i from debug.egl.blobcache.multifile_limit",
                  mCacheByteLimit, debugCacheSize);
            mCacheByteLimit = debugCacheSize;
        }

        ALOGV("Using multifile EGL blobcache limit of %zu bytes", mCacheByteLimit);
    }

    mInitialized = true;
}

@@ -167,6 +135,8 @@ void egl_cache_t::setBlob(const void* key, EGLsizeiANDROID keySize, const void*
        return;
    }

    updateMode();

    if (mInitialized) {
        if (mMultifileMode) {
            MultifileBlobCache* mbc = getMultifileBlobCacheLocked();
@@ -200,6 +170,8 @@ EGLsizeiANDROID egl_cache_t::getBlob(const void* key, EGLsizeiANDROID keySize, v
        return 0;
    }

    updateMode();

    if (mInitialized) {
        if (mMultifileMode) {
            MultifileBlobCache* mbc = getMultifileBlobCacheLocked();
@@ -247,6 +219,51 @@ size_t egl_cache_t::getCacheSize() {
    return 0;
}

void egl_cache_t::updateMode() {
    // We don't set the mode in the constructor because these checks have
    // a non-trivial cost, and not all processes that instantiate egl_cache_t
    // will use it.

    // If we've already set the mode, skip these checks
    static bool checked = false;
    if (checked) {
        return;
    }
    checked = true;

    // Check the device config to decide whether multifile should be used
    if (base::GetBoolProperty("ro.egl.blobcache.multifile", false)) {
        mMultifileMode = true;
        ALOGV("Using multifile EGL blobcache");
    }

    // Allow forcing the mode for debug purposes
    std::string mode = base::GetProperty("debug.egl.blobcache.multifile", "");
    if (mode == "true") {
        ALOGV("Forcing multifile cache due to debug.egl.blobcache.multifile == %s", mode.c_str());
        mMultifileMode = true;
    } else if (mode == "false") {
        ALOGV("Forcing monolithic cache due to debug.egl.blobcache.multifile == %s", mode.c_str());
        mMultifileMode = false;
    }

    if (mMultifileMode) {
        mCacheByteLimit = static_cast<size_t>(
                base::GetUintProperty<uint32_t>("ro.egl.blobcache.multifile_limit",
                                                kMultifileCacheByteLimit));

        // Check for a debug value
        int debugCacheSize = base::GetIntProperty("debug.egl.blobcache.multifile_limit", -1);
        if (debugCacheSize >= 0) {
            ALOGV("Overriding cache limit %zu with %i from debug.egl.blobcache.multifile_limit",
                  mCacheByteLimit, debugCacheSize);
            mCacheByteLimit = debugCacheSize;
        }

        ALOGV("Using multifile EGL blobcache limit of %zu bytes", mCacheByteLimit);
    }
}

BlobCache* egl_cache_t::getBlobCacheLocked() {
    if (mBlobCache == nullptr) {
        mBlobCache.reset(new FileBlobCache(kMaxMonolithicKeySize, kMaxMonolithicValueSize,
+3 −0
Original line number Diff line number Diff line
@@ -88,6 +88,9 @@ private:
    egl_cache_t(const egl_cache_t&); // not implemented
    void operator=(const egl_cache_t&); // not implemented

    // Check system properties to determine which blobcache mode should be used
    void updateMode();

    // getBlobCacheLocked returns the BlobCache object being used to store the
    // key/value blob pairs.  If the BlobCache object has not yet been created,
    // this will do so, loading the serialized cache contents from disk if