diff options
author | Chris Craik <ccraik@google.com> | 2014-01-30 15:43:56 -0800 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2014-01-31 10:43:42 -0800 |
commit | 12d9526dd25915f1957d1a251715e562d14459da (patch) | |
tree | df435b590dd18c6d906ee40872712fdc591466a1 /libs/hwui/SpotShadow.cpp | |
parent | f3560a133e3ec19c698a8c9d6cfc7d17fd95adc5 (diff) | |
download | frameworks_base-12d9526dd25915f1957d1a251715e562d14459da.zip frameworks_base-12d9526dd25915f1957d1a251715e562d14459da.tar.gz frameworks_base-12d9526dd25915f1957d1a251715e562d14459da.tar.bz2 |
Simplify umbra calculation
Reuse pre-computed values
Change-Id: Ia7725be0ec3ac58af477fcb8de375f5faa05abf4
Diffstat (limited to 'libs/hwui/SpotShadow.cpp')
-rw-r--r-- | libs/hwui/SpotShadow.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/libs/hwui/SpotShadow.cpp b/libs/hwui/SpotShadow.cpp index 9b8bf88..09e2058 100644 --- a/libs/hwui/SpotShadow.cpp +++ b/libs/hwui/SpotShadow.cpp @@ -743,9 +743,10 @@ void SpotShadow::generateTriangleStrip(const Vector2* penumbra, int penumbraLeng int stripSize = getStripSize(rays, layers); AlphaVertex* shadowVertices = shadowTriangleStrip.alloc<AlphaVertex>(stripSize); int currentIndex = 0; + int firstInLayer = 0; // Calculate the vertex values in the penumbra area. for (int r = 0; r < layers; r++) { - int firstInEachLayer = currentIndex; + firstInLayer = currentIndex; for (int i = 0; i < rays; i++) { float dx = sinf(step * i); float dy = cosf(step * i); @@ -755,19 +756,17 @@ void SpotShadow::generateTriangleStrip(const Vector2* penumbra, int penumbraLeng float deltaDist = layerRatio * (umbraDistPerRay[i] - penumbraDistPerRay[i]); float currentDist = penumbraDistPerRay[i] + deltaDist; float op = calculateOpacity(layerRatio, deltaDist); - AlphaVertex::set(&shadowVertices[currentIndex], + AlphaVertex::set(&shadowVertices[currentIndex++], dx * currentDist + centroid.x, dy * currentDist + centroid.y, layerRatio * op * strength); - currentIndex++; } } // Duplicate the vertices from one layer to another one to make triangle // strip. - shadowVertices[currentIndex++] = shadowVertices[firstInEachLayer]; - firstInEachLayer++; - shadowVertices[currentIndex++] = shadowVertices[firstInEachLayer]; + shadowVertices[currentIndex++] = shadowVertices[firstInLayer + 0]; + shadowVertices[currentIndex++] = shadowVertices[firstInLayer + 1]; } int lastInPenumbra = currentIndex - 1; @@ -779,23 +778,14 @@ void SpotShadow::generateTriangleStrip(const Vector2* penumbra, int penumbraLeng int firstInUmbra = currentIndex; // traverse the umbra area in a zig zag pattern for strips. + const int innerRingStartIndex = firstInLayer + 1; for (int k = 0; k < rays; k++) { int i = k / 2; if ((k & 1) == 1) { i = rays - i - 1; } - float dx = sinf(step * i); - float dy = cosf(step * i); - - float ratio = 1.0; - float deltaDist = ratio * (umbraDistPerRay[i] - penumbraDistPerRay[i]); - float currentDist = penumbraDistPerRay[i] + deltaDist; - float op = calculateOpacity(ratio, deltaDist); - AlphaVertex::set(&shadowVertices[currentIndex], - dx * currentDist + centroid.x, dy * currentDist + centroid.y, - ratio * op * strength); - currentIndex++; - + // copy already computed values for umbra vertices + shadowVertices[currentIndex++] = shadowVertices[innerRingStartIndex + i * 2]; } // Back fill the one vertex for jumping from penumbra to umbra. |