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

Commit 8af03060 authored by Yiwei Zhang's avatar Yiwei Zhang
Browse files

EGL: refactor and enforce clang-format

Test: build, flash and boot
Change-Id: Idbc4426ef485f7fc18a6a499f5933437af14fac8
parent 0657fba1
Loading
Loading
Loading
Loading
+35 −44
Original line number Diff line number Diff line
@@ -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 {
@@ -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) {
@@ -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));
@@ -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));
@@ -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;
}
@@ -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;
@@ -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);
    }
@@ -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;
+2 −5
Original line number Diff line number Diff line
@@ -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
@@ -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;
@@ -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;

@@ -245,6 +242,6 @@ private:
    std::vector<CacheEntry> mCacheEntries;
};

}
} // namespace android

#endif // ANDROID_BLOB_CACHE_H
+37 −43
Original line number Diff line number Diff line
@@ -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 {
@@ -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;
};
@@ -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]);
+3 −3
Original line number Diff line number Diff line
@@ -16,8 +16,9 @@

#pragma once

#include <log/log.h>
#include <backtrace/Backtrace.h>
#include <log/log.h>

#include <memory>

class CallStack {
@@ -35,4 +36,3 @@ public:
        }
    }
};
+14 −21
Original line number Diff line number Diff line
@@ -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;

@@ -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