blob: 70217528fc99a509490c6af8f723d020486725dd [file] [log] [blame]
Jamie Gennisaca51c02011-11-03 17:42:43 -07001/*
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
Jamie Gennis76601082011-11-06 14:14:33 -080017#ifndef ANDROID_EGL_CACHE_H
18#define ANDROID_EGL_CACHE_H
19
20#include <EGL/egl.h>
21#include <EGL/eglext.h>
22
23#include <utils/BlobCache.h>
24#include <utils/StrongPointer.h>
25
Jamie Gennisaca51c02011-11-03 17:42:43 -070026// ----------------------------------------------------------------------------
27namespace android {
28// ----------------------------------------------------------------------------
29
30class egl_display_t;
31
32class egl_cache_t {
33public:
34
Jamie Gennis76601082011-11-06 14:14:33 -080035 // get returns a pointer to the singleton egl_cache_t object. This
36 // singleton object will never be destroyed.
Jamie Gennisaca51c02011-11-03 17:42:43 -070037 static egl_cache_t* get();
38
Jamie Gennis76601082011-11-06 14:14:33 -080039 // initialize puts the egl_cache_t into an initialized state, such that it
40 // is able to insert and retrieve entries from the cache. This should be
41 // called when EGL is initialized. When not in the initialized state the
42 // getBlob and setBlob methods will return without performing any cache
43 // operations.
Jamie Gennisaca51c02011-11-03 17:42:43 -070044 void initialize(egl_display_t* display);
Jamie Gennis76601082011-11-06 14:14:33 -080045
46 // terminate puts the egl_cache_t back into the uninitialized state. When
47 // in this state the getBlob and setBlob methods will return without
48 // performing any cache operations.
49 void terminate();
50
51 // setBlob attempts to insert a new key/value blob pair into the cache.
52 // This will be called by the hardware vendor's EGL implementation via the
53 // EGL_ANDROID_blob_cache extension.
54 void setBlob(const void* key, EGLsizei keySize, const void* value,
55 EGLsizei valueSize);
56
57 // getBlob attempts to retrieve the value blob associated with a given key
58 // blob from cache. This will be called by the hardware vendor's EGL
59 // implementation via the EGL_ANDROID_blob_cache extension.
60 EGLsizei getBlob(const void* key, EGLsizei keySize, void* value,
61 EGLsizei valueSize);
62
63private:
64 // Creation and (the lack of) destruction is handled internally.
65 egl_cache_t();
66 ~egl_cache_t();
67
68 // Copying is disallowed.
69 egl_cache_t(const egl_cache_t&); // not implemented
70 void operator=(const egl_cache_t&); // not implemented
71
72 // getBlobCacheLocked returns the BlobCache object being used to store the
73 // key/value blob pairs. If the BlobCache object has not yet been created,
74 // this will do so, loading the serialized cache contents from disk if
75 // possible.
76 sp<BlobCache> getBlobCacheLocked();
77
78 // saveBlobCache attempts to save the current contents of mBlobCache to
79 // disk.
80 void saveBlobCacheLocked();
81
82 // loadBlobCache attempts to load the saved cache contents from disk into
83 // mBlobCache.
84 void loadBlobCacheLocked();
85
86 // mInitialized indicates whether the egl_cache_t is in the initialized
87 // state. It is initialized to false at construction time, and gets set to
88 // true when initialize is called. It is set back to false when terminate
89 // is called. When in this state, the cache behaves as normal. When not,
90 // the getBlob and setBlob methods will return without performing any cache
91 // operations.
92 bool mInitialized;
93
94 // mBlobCache is the cache in which the key/value blob pairs are stored. It
95 // is initially NULL, and will be initialized by getBlobCacheLocked the
96 // first time it's needed.
97 sp<BlobCache> mBlobCache;
98
99 // mMutex is the mutex used to prevent concurrent access to the member
100 // variables. It must be locked whenever the member variables are accessed.
101 mutable Mutex mMutex;
Jamie Gennisaca51c02011-11-03 17:42:43 -0700102};
103
104// ----------------------------------------------------------------------------
105}; // namespace android
106// ----------------------------------------------------------------------------
Jamie Gennis76601082011-11-06 14:14:33 -0800107
108#endif // ANDROID_EGL_CACHE_H