diff options
Diffstat (limited to 'libs/hwui/Caches.cpp')
| -rw-r--r-- | libs/hwui/Caches.cpp | 110 |
1 files changed, 85 insertions, 25 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index b0f4c2c..9855f71 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -23,6 +23,8 @@ #include "DisplayListRenderer.h" #include "Properties.h" #include "LayerRenderer.h" +#include "ShadowTessellator.h" +#include "RenderState.h" namespace android { @@ -48,13 +50,14 @@ namespace uirenderer { /////////////////////////////////////////////////////////////////////////////// Caches::Caches(): Singleton<Caches>(), - mExtensions(Extensions::getInstance()), mInitialized(false) { + mExtensions(Extensions::getInstance()), mInitialized(false), mRenderState(NULL) { init(); initFont(); initConstraints(); initProperties(); initStaticProperties(); initExtensions(); + initTempProperties(); mDebugLevel = readDebugLevel(); ALOGD("Enabling debug mode %d", mDebugLevel); @@ -85,7 +88,7 @@ bool Caches::init() { mRegionMesh = NULL; mMeshIndices = 0; - + mShadowStripsIndices = 0; blend = false; lastSrcMode = GL_ZERO; lastDstMode = GL_ZERO; @@ -196,6 +199,7 @@ bool Caches::initProperties() { drawDeferDisabled = !strcasecmp(property, "true"); INIT_LOGD(" Draw defer %s", drawDeferDisabled ? "disabled" : "enabled"); } else { + drawDeferDisabled = false; INIT_LOGD(" Draw defer enabled"); } @@ -203,6 +207,7 @@ bool Caches::initProperties() { drawReorderDisabled = !strcasecmp(property, "true"); INIT_LOGD(" Draw reorder %s", drawReorderDisabled ? "disabled" : "enabled"); } else { + drawReorderDisabled = false; INIT_LOGD(" Draw reorder enabled"); } @@ -222,6 +227,9 @@ void Caches::terminate() { mMeshIndices = 0; mRegionMesh = NULL; + glDeleteBuffers(1, &mShadowStripsIndices); + mShadowStripsIndices = 0; + fboCache.clear(); programCache.clear(); @@ -260,14 +268,19 @@ void Caches::dumpMemoryUsage(String8 &log) { log.appendFormat("Current memory usage / total memory usage (bytes):\n"); log.appendFormat(" TextureCache %8d / %8d\n", textureCache.getSize(), textureCache.getMaxSize()); - log.appendFormat(" LayerCache %8d / %8d\n", - layerCache.getSize(), layerCache.getMaxSize()); + log.appendFormat(" LayerCache %8d / %8d (numLayers = %zu)\n", + layerCache.getSize(), layerCache.getMaxSize(), layerCache.getCount()); + log.appendFormat(" Garbage layers %8zu\n", mLayerGarbage.size()); + log.appendFormat(" Active layers %8zu\n", + mRenderState ? mRenderState->mActiveLayers.size() : 0); log.appendFormat(" RenderBufferCache %8d / %8d\n", renderBufferCache.getSize(), renderBufferCache.getMaxSize()); log.appendFormat(" GradientCache %8d / %8d\n", gradientCache.getSize(), gradientCache.getMaxSize()); log.appendFormat(" PathCache %8d / %8d\n", pathCache.getSize(), pathCache.getMaxSize()); + log.appendFormat(" TessellationCache %8d / %8d\n", + tessellationCache.getSize(), tessellationCache.getMaxSize()); log.appendFormat(" TextDropShadowCache %8d / %8d\n", dropShadowCache.getSize(), dropShadowCache.getMaxSize()); log.appendFormat(" PatchCache %8d / %8d\n", @@ -290,6 +303,7 @@ void Caches::dumpMemoryUsage(String8 &log) { total += renderBufferCache.getSize(); total += gradientCache.getSize(); total += pathCache.getSize(); + total += tessellationCache.getSize(); total += dropShadowCache.getSize(); total += patchCache.getSize(); for (uint32_t i = 0; i < fontRenderer->getFontRendererCount(); i++) { @@ -310,24 +324,15 @@ void Caches::clearGarbage() { pathCache.clearGarbage(); patchCache.clearGarbage(); - Vector<DisplayList*> displayLists; Vector<Layer*> layers; { // scope for the lock Mutex::Autolock _l(mGarbageLock); - displayLists = mDisplayListGarbage; layers = mLayerGarbage; - mDisplayListGarbage.clear(); mLayerGarbage.clear(); } - size_t count = displayLists.size(); - for (size_t i = 0; i < count; i++) { - DisplayList* displayList = displayLists.itemAt(i); - delete displayList; - } - - count = layers.size(); + size_t count = layers.size(); for (size_t i = 0; i < count; i++) { Layer* layer = layers.itemAt(i); delete layer; @@ -340,11 +345,6 @@ void Caches::deleteLayerDeferred(Layer* layer) { mLayerGarbage.push(layer); } -void Caches::deleteDisplayListDeferred(DisplayList* displayList) { - Mutex::Autolock _l(mGarbageLock); - mDisplayListGarbage.push(displayList); -} - void Caches::flush(FlushMode mode) { FLUSH_LOGD("Flushing caches (mode %d)", mode); @@ -367,6 +367,7 @@ void Caches::flush(FlushMode mode) { fontRenderer->flush(); textureCache.flush(); pathCache.clear(); + tessellationCache.clear(); // fall through case kFlushMode_Layers: layerCache.clear(); @@ -403,7 +404,7 @@ bool Caches::unbindMeshBuffer() { return false; } -bool Caches::bindIndicesBuffer(const GLuint buffer) { +bool Caches::bindIndicesBufferInternal(const GLuint buffer) { if (mCurrentIndicesBuffer != buffer) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer); mCurrentIndicesBuffer = buffer; @@ -412,7 +413,7 @@ bool Caches::bindIndicesBuffer(const GLuint buffer) { return false; } -bool Caches::bindIndicesBuffer() { +bool Caches::bindQuadIndicesBuffer() { if (!mMeshIndices) { uint16_t* regionIndices = new uint16_t[gMaxNumberOfQuads * 6]; for (uint32_t i = 0; i < gMaxNumberOfQuads; i++) { @@ -427,7 +428,7 @@ bool Caches::bindIndicesBuffer() { } glGenBuffers(1, &mMeshIndices); - bool force = bindIndicesBuffer(mMeshIndices); + bool force = bindIndicesBufferInternal(mMeshIndices); glBufferData(GL_ELEMENT_ARRAY_BUFFER, gMaxNumberOfQuads * 6 * sizeof(uint16_t), regionIndices, GL_STATIC_DRAW); @@ -435,7 +436,23 @@ bool Caches::bindIndicesBuffer() { return force; } - return bindIndicesBuffer(mMeshIndices); + return bindIndicesBufferInternal(mMeshIndices); +} + +bool Caches::bindShadowIndicesBuffer() { + if (!mShadowStripsIndices) { + uint16_t* shadowIndices = new uint16_t[MAX_SHADOW_INDEX_COUNT]; + ShadowTessellator::generateShadowIndices(shadowIndices); + glGenBuffers(1, &mShadowStripsIndices); + bool force = bindIndicesBufferInternal(mShadowStripsIndices); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_SHADOW_INDEX_COUNT * sizeof(uint16_t), + shadowIndices, GL_STATIC_DRAW); + + delete[] shadowIndices; + return force; + } + + return bindIndicesBufferInternal(mShadowStripsIndices); } bool Caches::unbindIndicesBuffer() { @@ -473,7 +490,7 @@ bool Caches::unbindPixelBuffer() { // Meshes and textures /////////////////////////////////////////////////////////////////////////////// -void Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei stride) { +void Caches::bindPositionVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentPositionPointer || stride != mCurrentPositionStride) { GLuint slot = currentProgram->position; glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); @@ -482,7 +499,7 @@ void Caches::bindPositionVertexPointer(bool force, GLvoid* vertices, GLsizei str } } -void Caches::bindTexCoordsVertexPointer(bool force, GLvoid* vertices, GLsizei stride) { +void Caches::bindTexCoordsVertexPointer(bool force, const GLvoid* vertices, GLsizei stride) { if (force || vertices != mCurrentTexCoordsPointer || stride != mCurrentTexCoordsStride) { GLuint slot = currentProgram->texCoords; glVertexAttribPointer(slot, 2, GL_FLOAT, GL_FALSE, stride, vertices); @@ -681,5 +698,48 @@ TextureVertex* Caches::getRegionMesh() { return mRegionMesh; } +/////////////////////////////////////////////////////////////////////////////// +// Temporary Properties +/////////////////////////////////////////////////////////////////////////////// + +void Caches::initTempProperties() { + propertyLightDiameter = -1.0f; + propertyLightPosY = -1.0f; + propertyLightPosZ = -1.0f; + propertyAmbientRatio = -1.0f; + propertyAmbientShadowStrength = -1; + propertySpotShadowStrength = -1; +} + +void Caches::setTempProperty(const char* name, const char* value) { + ALOGD("setting property %s to %s", name, value); + if (!strcmp(name, "ambientRatio")) { + propertyAmbientRatio = fmin(fmax(atof(value), 0.0), 10.0); + ALOGD("ambientRatio = %.2f", propertyAmbientRatio); + return; + } else if (!strcmp(name, "lightDiameter")) { + propertyLightDiameter = fmin(fmax(atof(value), 0.0), 3000.0); + ALOGD("lightDiameter = %.2f", propertyLightDiameter); + return; + } else if (!strcmp(name, "lightPosY")) { + propertyLightPosY = fmin(fmax(atof(value), 0.0), 3000.0); + ALOGD("lightPos Y = %.2f", propertyLightPosY); + return; + } else if (!strcmp(name, "lightPosZ")) { + propertyLightPosZ = fmin(fmax(atof(value), 0.0), 3000.0); + ALOGD("lightPos Z = %.2f", propertyLightPosZ); + return; + } else if (!strcmp(name, "ambientShadowStrength")) { + propertyAmbientShadowStrength = atoi(value); + ALOGD("ambient shadow strength = 0x%x out of 0xff", propertyAmbientShadowStrength); + return; + } else if (!strcmp(name, "spotShadowStrength")) { + propertySpotShadowStrength = atoi(value); + ALOGD("spot shadow strength = 0x%x out of 0xff", propertySpotShadowStrength); + return; + } + ALOGD(" failed"); +} + }; // namespace uirenderer }; // namespace android |
