EGL: use an in-memory the blob cache

This change makes the makes the stub EGL_ANDROID_blob_cache callbacks
actually use a BlobCache object.

Bug: 5474671
Change-Id: I5cbaae2dea3aad2fe306c9f57029c3f215a0863a
diff --git a/opengl/libs/EGL/egl_cache.h b/opengl/libs/EGL/egl_cache.h
index 1fcfacc..7021752 100644
--- a/opengl/libs/EGL/egl_cache.h
+++ b/opengl/libs/EGL/egl_cache.h
@@ -14,6 +14,15 @@
  ** limitations under the License.
  */
 
+#ifndef ANDROID_EGL_CACHE_H
+#define ANDROID_EGL_CACHE_H
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include <utils/BlobCache.h>
+#include <utils/StrongPointer.h>
+
 // ----------------------------------------------------------------------------
 namespace android {
 // ----------------------------------------------------------------------------
@@ -23,11 +32,77 @@
 class egl_cache_t {
 public:
 
+    // get returns a pointer to the singleton egl_cache_t object.  This
+    // singleton object will never be destroyed.
     static egl_cache_t* get();
 
+    // initialize puts the egl_cache_t into an initialized state, such that it
+    // is able to insert and retrieve entries from the cache.  This should be
+    // called when EGL is initialized.  When not in the initialized state the
+    // getBlob and setBlob methods will return without performing any cache
+    // operations.
     void initialize(egl_display_t* display);
+
+    // terminate puts the egl_cache_t back into the uninitialized state.  When
+    // in this state the getBlob and setBlob methods will return without
+    // performing any cache operations.
+    void terminate();
+
+    // setBlob attempts to insert a new key/value blob pair into the cache.
+    // This will be called by the hardware vendor's EGL implementation via the
+    // EGL_ANDROID_blob_cache extension.
+    void setBlob(const void* key, EGLsizei keySize, const void* value,
+        EGLsizei valueSize);
+
+    // getBlob attempts to retrieve the value blob associated with a given key
+    // blob from cache.  This will be called by the hardware vendor's EGL
+    // implementation via the EGL_ANDROID_blob_cache extension.
+    EGLsizei getBlob(const void* key, EGLsizei keySize, void* value,
+        EGLsizei valueSize);
+
+private:
+    // Creation and (the lack of) destruction is handled internally.
+    egl_cache_t();
+    ~egl_cache_t();
+
+    // Copying is disallowed.
+    egl_cache_t(const egl_cache_t&); // not implemented
+    void operator=(const egl_cache_t&); // not implemented
+
+    // 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
+    // possible.
+    sp<BlobCache> getBlobCacheLocked();
+
+    // saveBlobCache attempts to save the current contents of mBlobCache to
+    // disk.
+    void saveBlobCacheLocked();
+
+    // loadBlobCache attempts to load the saved cache contents from disk into
+    // mBlobCache.
+    void loadBlobCacheLocked();
+
+    // mInitialized indicates whether the egl_cache_t is in the initialized
+    // state.  It is initialized to false at construction time, and gets set to
+    // true when initialize is called.  It is set back to false when terminate
+    // is called.  When in this state, the cache behaves as normal.  When not,
+    // the getBlob and setBlob methods will return without performing any cache
+    // operations.
+    bool mInitialized;
+
+    // mBlobCache is the cache in which the key/value blob pairs are stored.  It
+    // is initially NULL, and will be initialized by getBlobCacheLocked the
+    // first time it's needed.
+    sp<BlobCache> mBlobCache;
+
+    // mMutex is the mutex used to prevent concurrent access to the member
+    // variables. It must be locked whenever the member variables are accessed.
+    mutable Mutex mMutex;
 };
 
 // ----------------------------------------------------------------------------
 }; // namespace android
 // ----------------------------------------------------------------------------
+
+#endif // ANDROID_EGL_CACHE_H