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

Commit d1781cb7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "EGL: refactor and enforce clang-format"

parents 3d393f2e 8af03060
Loading
Loading
Loading
Loading
+35 −44
Original line number Original line Diff line number Diff line
@@ -18,11 +18,11 @@


#include "BlobCache.h"
#include "BlobCache.h"


#include <android-base/properties.h>
#include <errno.h>
#include <errno.h>
#include <inttypes.h>
#include <inttypes.h>

#include <android-base/properties.h>
#include <log/log.h>
#include <log/log.h>

#include <chrono>
#include <chrono>


namespace android {
namespace android {
@@ -36,8 +36,8 @@ static const uint32_t blobCacheVersion = 3;
// BlobCache::Header::mDeviceVersion value
// BlobCache::Header::mDeviceVersion value
static const uint32_t blobCacheDeviceVersion = 1;
static const uint32_t blobCacheDeviceVersion = 1;


BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize):
BlobCache::BlobCache(size_t maxKeySize, size_t maxValueSize, size_t maxTotalSize)
        mMaxTotalSize(maxTotalSize),
      : mMaxTotalSize(maxTotalSize),
        mMaxKeySize(maxKeySize),
        mMaxKeySize(maxKeySize),
        mMaxValueSize(maxValueSize),
        mMaxValueSize(maxValueSize),
        mTotalSize(0) {
        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);
    ALOGV("initializing random seed using %lld", (unsigned long long)now);
}
}


void BlobCache::set(const void* key, size_t keySize, const void* value,
void BlobCache::set(const void* key, size_t keySize, const void* value, size_t valueSize) {
        size_t valueSize) {
    if (mMaxKeySize < keySize) {
    if (mMaxKeySize < keySize) {
        ALOGV("set: not caching because the key is too large: %zu (limit: %zu)",
        ALOGV("set: not caching because the key is too large: %zu (limit: %zu)", keySize,
                keySize, mMaxKeySize);
              mMaxKeySize);
        return;
        return;
    }
    }
    if (mMaxValueSize < valueSize) {
    if (mMaxValueSize < valueSize) {
        ALOGV("set: not caching because the value is too large: %zu (limit: %zu)",
        ALOGV("set: not caching because the value is too large: %zu (limit: %zu)", valueSize,
                valueSize, mMaxValueSize);
              mMaxValueSize);
        return;
        return;
    }
    }
    if (mMaxTotalSize < keySize + valueSize) {
    if (mMaxTotalSize < keySize + valueSize) {
        ALOGV("set: not caching because the combined key/value size is too "
        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;
        return;
    }
    }
    if (keySize == 0) {
    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));
            mCacheEntries.insert(index, CacheEntry(keyBlob, valueBlob));
            mTotalSize = newTotalSize;
            mTotalSize = newTotalSize;
            ALOGV("set: created new cache entry with %zu byte key and %zu byte value",
            ALOGV("set: created new cache entry with %zu byte key and %zu byte value", keySize,
                    keySize, valueSize);
                  valueSize);
        } else {
        } else {
            // Update the existing cache entry.
            // Update the existing cache entry.
            std::shared_ptr<Blob> valueBlob(new Blob(value, valueSize, true));
            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);
            index->setValue(valueBlob);
            mTotalSize = newTotalSize;
            mTotalSize = newTotalSize;
            ALOGV("set: updated existing cache entry with %zu byte key and %zu byte "
            ALOGV("set: updated existing cache entry with %zu byte key and %zu byte "
                    "value", keySize, valueSize);
                  "value",
                  keySize, valueSize);
        }
        }
        break;
        break;
    }
    }
}
}


size_t BlobCache::get(const void* key, size_t keySize, void* value,
size_t BlobCache::get(const void* key, size_t keySize, void* value, size_t valueSize) {
        size_t valueSize) {
    if (mMaxKeySize < keySize) {
    if (mMaxKeySize < keySize) {
        ALOGV("get: not searching because the key is too large: %zu (limit %zu)",
        ALOGV("get: not searching because the key is too large: %zu (limit %zu)", keySize,
                keySize, mMaxKeySize);
              mMaxKeySize);
        return 0;
        return 0;
    }
    }
    std::shared_ptr<Blob> cacheKey(new Blob(key, keySize, false));
    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);
        ALOGV("get: copying %zu bytes to caller's buffer", valueBlobSize);
        memcpy(value, valueBlob->getData(), valueBlobSize);
        memcpy(value, valueBlob->getData(), valueBlobSize);
    } else {
    } else {
        ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)",
        ALOGV("get: caller's buffer is too small for value: %zu (needs %zu)", valueSize,
                valueSize, valueBlobSize);
              valueBlobSize);
    }
    }
    return valueBlobSize;
    return valueBlobSize;
}
}
@@ -259,8 +259,7 @@ int BlobCache::unflatten(void const* buffer, size_t size) {
            return -EINVAL;
            return -EINVAL;
        }
        }


        const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>(
        const EntryHeader* eheader = reinterpret_cast<const EntryHeader*>(&byteBuffer[byteOffset]);
                &byteBuffer[byteOffset]);
        size_t keySize = eheader->mKeySize;
        size_t keySize = eheader->mKeySize;
        size_t valueSize = eheader->mValueSize;
        size_t valueSize = eheader->mValueSize;
        size_t entrySize = sizeof(EntryHeader) + keySize + valueSize;
        size_t entrySize = sizeof(EntryHeader) + keySize + valueSize;
@@ -304,10 +303,8 @@ bool BlobCache::isCleanable() const {
    return mTotalSize > mMaxTotalSize / 2;
    return mTotalSize > mMaxTotalSize / 2;
}
}


BlobCache::Blob::Blob(const void* data, size_t size, bool copyData) :
BlobCache::Blob::Blob(const void* data, size_t size, bool copyData)
        mData(copyData ? malloc(size) : data),
      : mData(copyData ? malloc(size) : data), mSize(size), mOwnsData(copyData) {
        mSize(size),
        mOwnsData(copyData) {
    if (data != nullptr && copyData) {
    if (data != nullptr && copyData) {
        memcpy(const_cast<void*>(mData), data, size);
        memcpy(const_cast<void*>(mData), data, size);
    }
    }
@@ -335,19 +332,13 @@ size_t BlobCache::Blob::getSize() const {
    return mSize;
    return mSize;
}
}


BlobCache::CacheEntry::CacheEntry() {
BlobCache::CacheEntry::CacheEntry() {}
}


BlobCache::CacheEntry::CacheEntry(
BlobCache::CacheEntry::CacheEntry(const std::shared_ptr<Blob>& key,
        const std::shared_ptr<Blob>& key, const std::shared_ptr<Blob>& value):
                                  const std::shared_ptr<Blob>& value)
        mKey(key),
      : mKey(key), mValue(value) {}
        mValue(value) {
}


BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce):
BlobCache::CacheEntry::CacheEntry(const CacheEntry& ce) : mKey(ce.mKey), mValue(ce.mValue) {}
        mKey(ce.mKey),
        mValue(ce.mValue) {
}


bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const {
bool BlobCache::CacheEntry::operator<(const CacheEntry& rhs) const {
    return *mKey < *rhs.mKey;
    return *mKey < *rhs.mKey;
+2 −5
Original line number Original line Diff line number Diff line
@@ -54,8 +54,7 @@ public:
    //   0 < keySize
    //   0 < keySize
    //   value != NULL
    //   value != NULL
    //   0 < valueSize
    //   0 < valueSize
    void set(const void* key, size_t keySize, const void* value,
    void set(const void* key, size_t keySize, const void* value, size_t valueSize);
            size_t valueSize);


    // get retrieves from the cache the binary value associated with a given
    // 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
    // binary key.  If the key is present in the cache then the length of the
@@ -75,7 +74,6 @@ public:
    //   0 <= valueSize
    //   0 <= valueSize
    size_t get(const void* key, size_t keySize, void* value, size_t 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
    // getFlattenedSize returns the number of bytes needed to store the entire
    // serialized cache.
    // serialized cache.
    size_t getFlattenedSize() const;
    size_t getFlattenedSize() const;
@@ -168,7 +166,6 @@ private:
        void setValue(const std::shared_ptr<Blob>& value);
        void setValue(const std::shared_ptr<Blob>& value);


    private:
    private:

        // mKey is the key that identifies the cache entry.
        // mKey is the key that identifies the cache entry.
        std::shared_ptr<Blob> mKey;
        std::shared_ptr<Blob> mKey;


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


}
} // namespace android


#endif // ANDROID_BLOB_CACHE_H
#endif // ANDROID_BLOB_CACHE_H
+37 −43
Original line number Original line Diff line number Diff line
@@ -14,25 +14,24 @@
 ** limitations under the License.
 ** limitations under the License.
 */
 */


#include "BlobCache.h"

#include <fcntl.h>
#include <fcntl.h>
#include <gtest/gtest.h>
#include <stdio.h>
#include <stdio.h>


#include <memory>
#include <memory>


#include <gtest/gtest.h>

#include "BlobCache.h"

namespace android {
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 {
class BlobCacheTest : public ::testing::Test {
protected:
protected:

    enum {
    enum {
        OK = 0,
        OK = 0,
        BAD_VALUE = -EINVAL
        BAD_VALUE = -EINVAL,
    };
    };


    enum {
    enum {
@@ -41,13 +40,9 @@ protected:
        MAX_TOTAL_SIZE = 13,
        MAX_TOTAL_SIZE = 13,
    };
    };


    virtual void SetUp() {
    virtual void SetUp() { mBC.reset(new BlobCache(MAX_KEY_SIZE, MAX_VALUE_SIZE, MAX_TOTAL_SIZE)); }
        mBC.reset(new BlobCache(MAX_KEY_SIZE, MAX_VALUE_SIZE, MAX_TOTAL_SIZE));
    }


    virtual void TearDown() {
    virtual void TearDown() { mBC.reset(); }
        mBC.reset();
    }


    std::unique_ptr<BlobCache> mBC;
    std::unique_ptr<BlobCache> mBC;
};
};
@@ -195,8 +190,7 @@ TEST_F(BlobCacheTest, CacheMaxValueSizeSucceeds) {
    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
        buf[i] = 0xee;
        buf[i] = 0xee;
    }
    }
    ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf,
    ASSERT_EQ(size_t(MAX_VALUE_SIZE), mBC->get("abcd", 4, buf, MAX_VALUE_SIZE));
            MAX_VALUE_SIZE));
    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
    for (int i = 0; i < MAX_VALUE_SIZE; i++) {
        SCOPED_TRACE(i);
        SCOPED_TRACE(i);
        ASSERT_EQ('b', buf[i]);
        ASSERT_EQ('b', buf[i]);
+3 −3
Original line number Original line Diff line number Diff line
@@ -16,8 +16,9 @@


#pragma once
#pragma once


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

#include <memory>
#include <memory>


class CallStack {
class CallStack {
@@ -35,4 +36,3 @@ public:
        }
        }
    }
    }
};
};
+14 −21
Original line number Original line Diff line number Diff line
@@ -17,13 +17,10 @@
#ifndef ANDROID_EGL_LOADER_H
#ifndef ANDROID_EGL_LOADER_H
#define ANDROID_EGL_LOADER_H
#define ANDROID_EGL_LOADER_H


#include <stdint.h>

#include <EGL/egl.h>
#include <EGL/egl.h>
#include <stdint.h>


// ----------------------------------------------------------------------------
namespace android {
namespace android {
// ----------------------------------------------------------------------------


struct egl_connection_t;
struct egl_connection_t;


@@ -62,16 +59,12 @@ private:
    void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);
    void initialize_api(void* dso, egl_connection_t* cnx, uint32_t mask);
    void init_angle_backend(void* dso, egl_connection_t* cnx);
    void init_angle_backend(void* dso, egl_connection_t* cnx);


    static __attribute__((noinline))
    static __attribute__((noinline)) void init_api(void* dso, const char* const* api,
    void init_api(void* dso,
                                                   const char* const* ref_api,
            char const * const * api,
            char const * const * ref_api,
                                                   __eglMustCastToProperFunctionPointerType* curr,
                                                   __eglMustCastToProperFunctionPointerType* curr,
                                                   getProcAddressType getProcAddress);
                                                   getProcAddressType getProcAddress);
};
};


// ----------------------------------------------------------------------------
}; // namespace android
}; // namespace android
// ----------------------------------------------------------------------------


#endif /* ANDROID_EGL_LOADER_H */
#endif /* ANDROID_EGL_LOADER_H */
Loading