// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////
-FboCache::FboCache(): mMaxSize(DEFAULT_FBO_CACHE_SIZE) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_FBO_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting fbo cache size to %s", property);
- mMaxSize = atoi(property);
- } else {
- INIT_LOGD(" Using default fbo cache size of %d", DEFAULT_FBO_CACHE_SIZE);
- }
-}
+FboCache::FboCache()
+ : mMaxSize(Properties::fboCacheSize) {}
FboCache::~FboCache() {
clear();
GradientCache::GradientCache(Extensions& extensions)
: mCache(LruCache<GradientCacheEntry, Texture*>::kUnlimitedCapacity)
, mSize(0)
- , mMaxSize(MB(DEFAULT_GRADIENT_CACHE_SIZE))
+ , mMaxSize(Properties::gradientCacheSize)
, mUseFloatTexture(extensions.hasFloatTextures())
, mHasNpot(extensions.hasNPot()){
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_GRADIENT_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting gradient cache size to %sMB", property);
- setMaxSize(MB(atof(property)));
- } else {
- INIT_LOGD(" Using default gradient cache size of %.2fMB", DEFAULT_GRADIENT_CACHE_SIZE);
- }
-
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
mCache.setOnEntryRemovedListener(this);
return mMaxSize;
}
-void GradientCache::setMaxSize(uint32_t maxSize) {
- mMaxSize = maxSize;
- while (mSize > mMaxSize) {
- mCache.removeOldest();
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// Callbacks
///////////////////////////////////////////////////////////////////////////////
void clear();
/**
- * Sets the maximum size of the cache in bytes.
- */
- void setMaxSize(uint32_t maxSize);
- /**
* Returns the maximum size of the cache in bytes.
*/
uint32_t getMaxSize();
LruCache<GradientCacheEntry, Texture*> mCache;
uint32_t mSize;
- uint32_t mMaxSize;
+ const uint32_t mMaxSize;
GLint mMaxTextureSize;
bool mUseFloatTexture;
PatchCache::PatchCache(RenderState& renderState)
: mRenderState(renderState)
+ , mMaxSize(Properties::patchCacheSize)
, mSize(0)
, mCache(LruCache<PatchDescription, Patch*>::kUnlimitedCapacity)
, mMeshBuffer(0)
, mFreeBlocks(nullptr)
- , mGenerationId(0) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_PATCH_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting patch cache size to %skB", property);
- mMaxSize = KB(atoi(property));
- } else {
- INIT_LOGD(" Using default patch cache size of %.2fkB", DEFAULT_PATCH_CACHE_SIZE);
- mMaxSize = KB(DEFAULT_PATCH_CACHE_SIZE);
- }
-}
+ , mGenerationId(0) {}
PatchCache::~PatchCache() {
clear();
#endif
RenderState& mRenderState;
- uint32_t mMaxSize;
+ const uint32_t mMaxSize;
uint32_t mSize;
LruCache<PatchDescription, Patch*> mCache;
// Cache constructor/destructor
///////////////////////////////////////////////////////////////////////////////
-PathCache::PathCache():
- mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity),
- mSize(0), mMaxSize(MB(DEFAULT_PATH_CACHE_SIZE)) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_PATH_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting path cache size to %sMB", property);
- mMaxSize = MB(atof(property));
- } else {
- INIT_LOGD(" Using default path cache size of %.2fMB", DEFAULT_PATH_CACHE_SIZE);
- }
-
+PathCache::PathCache()
+ : mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity)
+ , mSize(0)
+ , mMaxSize(Properties::pathCacheSize) {
mCache.setOnEntryRemovedListener(this);
GLint maxTextureSize;
LruCache<PathDescription, PathTexture*> mCache;
uint32_t mSize;
- uint32_t mMaxSize;
+ const uint32_t mMaxSize;
GLuint mMaxTextureSize;
bool mDebugEnabled;
bool Properties::enablePartialUpdates = true;
float Properties::textGamma = DEFAULT_TEXT_GAMMA;
-int Properties::layerPoolSize = DEFAULT_LAYER_CACHE_SIZE;
+
+int Properties::fboCacheSize = DEFAULT_FBO_CACHE_SIZE;
+int Properties::gradientCacheSize = MB(DEFAULT_GRADIENT_CACHE_SIZE);
+int Properties::layerPoolSize = MB(DEFAULT_LAYER_CACHE_SIZE);
+int Properties::patchCacheSize = KB(DEFAULT_PATCH_CACHE_SIZE);
+int Properties::pathCacheSize = MB(DEFAULT_PATH_CACHE_SIZE);
+int Properties::renderBufferCacheSize = MB(DEFAULT_RENDER_BUFFER_CACHE_SIZE);
+int Properties::tessellationCacheSize = MB(DEFAULT_VERTEX_CACHE_SIZE);
+int Properties::textDropShadowCacheSize = MB(DEFAULT_DROP_SHADOW_CACHE_SIZE);
+int Properties::textureCacheSize = MB(DEFAULT_TEXTURE_CACHE_SIZE);
+
+float Properties::textureCacheFlushRate = DEFAULT_TEXTURE_CACHE_FLUSH_RATE;
DebugLevel Properties::debugLevel = kDebugDisabled;
OverdrawColorSet Properties::overdrawColorSet = OverdrawColorSet::Default;
bool prevDebugOverdraw = debugOverdraw;
StencilClipDebug prevDebugStencilClip = debugStencilClip;
-
debugOverdraw = false;
if (property_get(PROPERTY_DEBUG_OVERDRAW, property, nullptr) > 0) {
INIT_LOGD(" Overdraw debug enabled: %s", property);
enablePartialUpdates = property_get_bool(PROPERTY_ENABLE_PARTIAL_UPDATES, true);
textGamma = property_get_float(PROPERTY_TEXT_GAMMA, DEFAULT_TEXT_GAMMA);
+
+ fboCacheSize = property_get_int(PROPERTY_FBO_CACHE_SIZE, DEFAULT_FBO_CACHE_SIZE);
+ gradientCacheSize = MB(property_get_float(PROPERTY_GRADIENT_CACHE_SIZE, DEFAULT_GRADIENT_CACHE_SIZE));
layerPoolSize = MB(property_get_float(PROPERTY_LAYER_CACHE_SIZE, DEFAULT_LAYER_CACHE_SIZE));
+ patchCacheSize = KB(property_get_float(PROPERTY_PATCH_CACHE_SIZE, DEFAULT_PATCH_CACHE_SIZE));
+ pathCacheSize = MB(property_get_float(PROPERTY_PATH_CACHE_SIZE, DEFAULT_PATH_CACHE_SIZE));
+ renderBufferCacheSize = MB(property_get_float(PROPERTY_RENDER_BUFFER_CACHE_SIZE, DEFAULT_RENDER_BUFFER_CACHE_SIZE));
+ tessellationCacheSize = MB(property_get_float(PROPERTY_VERTEX_CACHE_SIZE, DEFAULT_VERTEX_CACHE_SIZE));
+ textDropShadowCacheSize = MB(property_get_float(PROPERTY_DROP_SHADOW_CACHE_SIZE, DEFAULT_DROP_SHADOW_CACHE_SIZE));
+ textureCacheSize = MB(property_get_float(PROPERTY_TEXTURE_CACHE_SIZE, DEFAULT_TEXTURE_CACHE_SIZE));
+ textureCacheFlushRate = std::max(0.0f, std::min(1.0f,
+ property_get_float(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, DEFAULT_TEXTURE_CACHE_FLUSH_RATE)));
return (prevDebugLayersUpdates != debugLayersUpdates)
|| (prevDebugOverdraw != debugOverdraw)
static float textGamma;
+ static int fboCacheSize;
+ static int gradientCacheSize;
static int layerPoolSize;
+ static int patchCacheSize;
+ static int pathCacheSize;
+ static int renderBufferCacheSize;
+ static int tessellationCacheSize;
+ static int textDropShadowCacheSize;
+ static int textureCacheSize;
+ static float textureCacheFlushRate;
static DebugLevel debugLevel;
static OverdrawColorSet overdrawColorSet;
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////
-RenderBufferCache::RenderBufferCache(): mSize(0), mMaxSize(MB(DEFAULT_RENDER_BUFFER_CACHE_SIZE)) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_RENDER_BUFFER_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting render buffer cache size to %sMB", property);
- setMaxSize(MB(atof(property)));
- } else {
- INIT_LOGD(" Using default render buffer cache size of %.2fMB",
- DEFAULT_RENDER_BUFFER_CACHE_SIZE);
- }
-}
+RenderBufferCache::RenderBufferCache()
+ : mSize(0)
+ , mMaxSize(Properties::renderBufferCacheSize) {}
RenderBufferCache::~RenderBufferCache() {
clear();
return mMaxSize;
}
-void RenderBufferCache::setMaxSize(uint32_t maxSize) {
- clear();
- mMaxSize = maxSize;
-}
-
///////////////////////////////////////////////////////////////////////////////
// Caching
///////////////////////////////////////////////////////////////////////////////
void clear();
/**
- * Sets the maximum size of the cache in bytes.
- */
- void setMaxSize(uint32_t maxSize);
- /**
* Returns the maximum size of the cache in bytes.
*/
uint32_t getMaxSize();
///////////////////////////////////////////////////////////////////////////////
TessellationCache::TessellationCache()
- : mSize(0)
- , mMaxSize(MB(DEFAULT_VERTEX_CACHE_SIZE))
+ : mMaxSize(Properties::tessellationCacheSize)
, mCache(LruCache<Description, Buffer*>::kUnlimitedCapacity)
, mShadowCache(LruCache<ShadowDescription, Task<vertexBuffer_pair_t*>*>::kUnlimitedCapacity) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_VERTEX_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting tessellation cache size to %sMB", property);
- setMaxSize(MB(atof(property)));
- } else {
- INIT_LOGD(" Using default tessellation cache size of %.2fMB", DEFAULT_VERTEX_CACHE_SIZE);
- }
-
mCache.setOnEntryRemovedListener(&mBufferRemovedListener);
mShadowCache.setOnEntryRemovedListener(&mBufferPairRemovedListener);
mDebugEnabled = Properties::debugLevel & kDebugCaches;
return mMaxSize;
}
-void TessellationCache::setMaxSize(uint32_t maxSize) {
- mMaxSize = maxSize;
- while (mSize > mMaxSize) {
- mCache.removeOldest();
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// Caching
///////////////////////////////////////////////////////////////////////////////
* Clears the cache. This causes all TessellationBuffers to be deleted.
*/
void clear();
-
- /**
- * Sets the maximum size of the cache in bytes.
- */
- void setMaxSize(uint32_t maxSize);
/**
* Returns the maximum size of the cache in bytes.
*/
Buffer* getOrCreateBuffer(const Description& entry, Tessellator tessellator);
- uint32_t mSize;
- uint32_t mMaxSize;
+ const uint32_t mMaxSize;
bool mDebugEnabled;
// Constructors/destructor
///////////////////////////////////////////////////////////////////////////////
-TextDropShadowCache::TextDropShadowCache():
- mCache(LruCache<ShadowText, ShadowTexture*>::kUnlimitedCapacity),
- mSize(0), mMaxSize(MB(DEFAULT_DROP_SHADOW_CACHE_SIZE)) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_DROP_SHADOW_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting drop shadow cache size to %sMB", property);
- setMaxSize(MB(atof(property)));
- } else {
- INIT_LOGD(" Using default drop shadow cache size of %.2fMB",
- DEFAULT_DROP_SHADOW_CACHE_SIZE);
- }
-
- init();
-}
+TextDropShadowCache::TextDropShadowCache()
+ : TextDropShadowCache(Properties::textDropShadowCacheSize) {}
-TextDropShadowCache::TextDropShadowCache(uint32_t maxByteSize):
- mCache(LruCache<ShadowText, ShadowTexture*>::kUnlimitedCapacity),
- mSize(0), mMaxSize(maxByteSize) {
- init();
+TextDropShadowCache::TextDropShadowCache(uint32_t maxByteSize)
+ : mCache(LruCache<ShadowText, ShadowTexture*>::kUnlimitedCapacity)
+ , mSize(0)
+ , mMaxSize(maxByteSize) {
+ mCache.setOnEntryRemovedListener(this);
+ mDebugEnabled = Properties::debugLevel & kDebugMoreCaches;
}
TextDropShadowCache::~TextDropShadowCache() {
mCache.clear();
}
-void TextDropShadowCache::init() {
- mCache.setOnEntryRemovedListener(this);
- mDebugEnabled = Properties::debugLevel & kDebugMoreCaches;
-}
-
///////////////////////////////////////////////////////////////////////////////
// Size management
///////////////////////////////////////////////////////////////////////////////
return mMaxSize;
}
-void TextDropShadowCache::setMaxSize(uint32_t maxSize) {
- mMaxSize = maxSize;
- while (mSize > mMaxSize) {
- mCache.removeOldest();
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// Callbacks
///////////////////////////////////////////////////////////////////////////////
}
/**
- * Sets the maximum size of the cache in bytes.
- */
- void setMaxSize(uint32_t maxSize);
- /**
* Returns the maximum size of the cache in bytes.
*/
uint32_t getMaxSize();
uint32_t getSize();
private:
- void init();
-
LruCache<ShadowText, ShadowTexture*> mCache;
uint32_t mSize;
- uint32_t mMaxSize;
- FontRenderer* mRenderer;
+ const uint32_t mMaxSize;
+ FontRenderer* mRenderer = nullptr;
bool mDebugEnabled;
}; // class TextDropShadowCache
TextureCache::TextureCache()
: mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity)
, mSize(0)
- , mMaxSize(MB(DEFAULT_TEXTURE_CACHE_SIZE))
- , mFlushRate(DEFAULT_TEXTURE_CACHE_FLUSH_RATE)
+ , mMaxSize(Properties::textureCacheSize)
+ , mFlushRate(Properties::textureCacheFlushRate)
, mAssetAtlas(nullptr) {
- char property[PROPERTY_VALUE_MAX];
- if (property_get(PROPERTY_TEXTURE_CACHE_SIZE, property, nullptr) > 0) {
- INIT_LOGD(" Setting texture cache size to %sMB", property);
- setMaxSize(MB(atof(property)));
- } else {
- INIT_LOGD(" Using default texture cache size of %.2fMB", DEFAULT_TEXTURE_CACHE_SIZE);
- }
-
- if (property_get(PROPERTY_TEXTURE_CACHE_FLUSH_RATE, property, nullptr) > 0) {
- float flushRate = atof(property);
- INIT_LOGD(" Setting texture cache flush rate to %.2f%%", flushRate * 100.0f);
- setFlushRate(flushRate);
- } else {
- INIT_LOGD(" Using default texture cache flush rate of %.2f%%",
- DEFAULT_TEXTURE_CACHE_FLUSH_RATE * 100.0f);
- }
-
mCache.setOnEntryRemovedListener(this);
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
return mMaxSize;
}
-void TextureCache::setMaxSize(uint32_t maxSize) {
- mMaxSize = maxSize;
- while (mSize > mMaxSize) {
- mCache.removeOldest();
- }
-}
-
-void TextureCache::setFlushRate(float flushRate) {
- mFlushRate = std::max(0.0f, std::min(1.0f, flushRate));
-}
-
///////////////////////////////////////////////////////////////////////////////
// Callbacks
///////////////////////////////////////////////////////////////////////////////
void clear();
/**
- * Sets the maximum size of the cache in bytes.
- */
- void setMaxSize(uint32_t maxSize);
- /**
* Returns the maximum size of the cache in bytes.
*/
uint32_t getMaxSize();
* is defined by the flush rate.
*/
void flush();
- /**
- * Indicates the percentage of the cache to retain when a
- * memory trim is requested (see Caches::flush).
- */
- void setFlushRate(float flushRate);
void setAssetAtlas(AssetAtlas* assetAtlas);
LruCache<uint32_t, Texture*> mCache;
uint32_t mSize;
- uint32_t mMaxSize;
+ const uint32_t mMaxSize;
GLint mMaxTextureSize;
- float mFlushRate;
+ const float mFlushRate;
bool mDebugEnabled;