diff options
Diffstat (limited to 'libs/hwui/Caches.cpp')
-rw-r--r-- | libs/hwui/Caches.cpp | 99 |
1 files changed, 77 insertions, 22 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index b0f4c2c7189d..402f28bd3c5a 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -23,6 +23,7 @@ #include "DisplayListRenderer.h" #include "Properties.h" #include "LayerRenderer.h" +#include "ShadowTessellator.h" namespace android { @@ -55,6 +56,7 @@ Caches::Caches(): Singleton<Caches>(), initProperties(); initStaticProperties(); initExtensions(); + initTempProperties(); mDebugLevel = readDebugLevel(); ALOGD("Enabling debug mode %d", mDebugLevel); @@ -85,7 +87,7 @@ bool Caches::init() { mRegionMesh = NULL; mMeshIndices = 0; - + mShadowStripsIndices = 0; blend = false; lastSrcMode = GL_ZERO; lastDstMode = GL_ZERO; @@ -222,6 +224,9 @@ void Caches::terminate() { mMeshIndices = 0; mRegionMesh = NULL; + glDeleteBuffers(1, &mShadowStripsIndices); + mShadowStripsIndices = 0; + fboCache.clear(); programCache.clear(); @@ -268,6 +273,8 @@ void Caches::dumpMemoryUsage(String8 &log) { 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 +297,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 +318,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 +339,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 +361,7 @@ void Caches::flush(FlushMode mode) { fontRenderer->flush(); textureCache.flush(); pathCache.clear(); + tessellationCache.clear(); // fall through case kFlushMode_Layers: layerCache.clear(); @@ -403,7 +398,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 +407,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 +422,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 +430,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 +484,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 +493,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 +692,49 @@ TextureVertex* Caches::getRegionMesh() { return mRegionMesh; } +/////////////////////////////////////////////////////////////////////////////// +// Temporary Properties +/////////////////////////////////////////////////////////////////////////////// + +void Caches::initTempProperties() { + propertyAmbientShadowStrength = 12; + propertySpotShadowStrength = 48; + + propertyLightDiameter = -1.0f; + propertyLightPosY = -1.0f; + propertyLightPosZ = -1.0f; + propertyAmbientRatio = -1.0f; +} + +void Caches::setTempProperty(const char* name, const char* value) { + ALOGD("setting property %s to %s", name, value); + 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; + } else 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; + } + ALOGD(" failed"); +} + }; // namespace uirenderer }; // namespace android |