egl_cache.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  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. #ifndef ANDROID_EGL_CACHE_H
  17. #define ANDROID_EGL_CACHE_H
  18. #include <EGL/egl.h>
  19. #include <EGL/eglext.h>
  20. #include <utils/BlobCache.h>
  21. #include <utils/String8.h>
  22. #include <utils/StrongPointer.h>
  23. // ----------------------------------------------------------------------------
  24. namespace android {
  25. // ----------------------------------------------------------------------------
  26. class egl_display_t;
  27. class EGLAPI egl_cache_t {
  28. public:
  29. // get returns a pointer to the singleton egl_cache_t object. This
  30. // singleton object will never be destroyed.
  31. static egl_cache_t* get();
  32. // initialize puts the egl_cache_t into an initialized state, such that it
  33. // is able to insert and retrieve entries from the cache. This should be
  34. // called when EGL is initialized. When not in the initialized state the
  35. // getBlob and setBlob methods will return without performing any cache
  36. // operations.
  37. void initialize(egl_display_t* display);
  38. // terminate puts the egl_cache_t back into the uninitialized state. When
  39. // in this state the getBlob and setBlob methods will return without
  40. // performing any cache operations.
  41. void terminate();
  42. // setBlob attempts to insert a new key/value blob pair into the cache.
  43. // This will be called by the hardware vendor's EGL implementation via the
  44. // EGL_ANDROID_blob_cache extension.
  45. void setBlob(const void* key, EGLsizeiANDROID keySize, const void* value,
  46. EGLsizeiANDROID valueSize);
  47. // getBlob attempts to retrieve the value blob associated with a given key
  48. // blob from cache. This will be called by the hardware vendor's EGL
  49. // implementation via the EGL_ANDROID_blob_cache extension.
  50. EGLsizeiANDROID getBlob(const void* key, EGLsizeiANDROID keySize,
  51. void* value, EGLsizeiANDROID valueSize);
  52. // setCacheFilename sets the name of the file that should be used to store
  53. // cache contents from one program invocation to another.
  54. void setCacheFilename(const char* filename);
  55. private:
  56. // Creation and (the lack of) destruction is handled internally.
  57. egl_cache_t();
  58. ~egl_cache_t();
  59. // Copying is disallowed.
  60. egl_cache_t(const egl_cache_t&); // not implemented
  61. void operator=(const egl_cache_t&); // not implemented
  62. // getBlobCacheLocked returns the BlobCache object being used to store the
  63. // key/value blob pairs. If the BlobCache object has not yet been created,
  64. // this will do so, loading the serialized cache contents from disk if
  65. // possible.
  66. sp<BlobCache> getBlobCacheLocked();
  67. // saveBlobCache attempts to save the current contents of mBlobCache to
  68. // disk.
  69. void saveBlobCacheLocked();
  70. // loadBlobCache attempts to load the saved cache contents from disk into
  71. // mBlobCache.
  72. void loadBlobCacheLocked();
  73. // mInitialized indicates whether the egl_cache_t is in the initialized
  74. // state. It is initialized to false at construction time, and gets set to
  75. // true when initialize is called. It is set back to false when terminate
  76. // is called. When in this state, the cache behaves as normal. When not,
  77. // the getBlob and setBlob methods will return without performing any cache
  78. // operations.
  79. bool mInitialized;
  80. // mBlobCache is the cache in which the key/value blob pairs are stored. It
  81. // is initially NULL, and will be initialized by getBlobCacheLocked the
  82. // first time it's needed.
  83. sp<BlobCache> mBlobCache;
  84. // mFilename is the name of the file for storing cache contents in between
  85. // program invocations. It is initialized to an empty string at
  86. // construction time, and can be set with the setCacheFilename method. An
  87. // empty string indicates that the cache should not be saved to or restored
  88. // from disk.
  89. String8 mFilename;
  90. // mSavePending indicates whether or not a deferred save operation is
  91. // pending. Each time a key/value pair is inserted into the cache via
  92. // setBlob, a deferred save is initiated if one is not already pending.
  93. // This will wait some amount of time and then trigger a save of the cache
  94. // contents to disk.
  95. bool mSavePending;
  96. // mMutex is the mutex used to prevent concurrent access to the member
  97. // variables. It must be locked whenever the member variables are accessed.
  98. mutable Mutex mMutex;
  99. // sCache is the singleton egl_cache_t object.
  100. static egl_cache_t sCache;
  101. };
  102. // ----------------------------------------------------------------------------
  103. }; // namespace android
  104. // ----------------------------------------------------------------------------
  105. #endif // ANDROID_EGL_CACHE_H