diff options
| author | 2014-01-26 13:43:53 -0800 | |
|---|---|---|
| committer | 2014-01-26 13:43:53 -0800 | |
| commit | 15a07a21eb33e8ca1c7444944fe0541a53380c0c (patch) | |
| tree | fa5dd5158982a1ef11d105ac463fb34b07087147 /libs/hwui/OpenGLRenderer.cpp | |
| parent | bb615a6ffbc8a051007163916f1ed085d10b5327 (diff) | |
Use path outlines to define shadow shapes
Fixes the simplifying assumption that shadow casters were always
rectangular.
Java side APIs + plumbing to pass down correct shapes still need to be added.
Change-Id: Ic4fee90af15679951a44bb5cc6ae454b98c4c194
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 31 | 
1 files changed, 23 insertions, 8 deletions
| diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 741e953e3eba..41f34e5e4eb8 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -3185,28 +3185,43 @@ status_t OpenGLRenderer::drawRects(const float* rects, int count, const SkPaint*  }  status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlpha, -        float width, float height) { +        const SkPath* casterOutline) {      if (currentSnapshot()->isIgnored()) return DrawGlInfo::kStatusDone; -    // For now, always and scissor -    // TODO: use quickReject +    // TODO: use quickRejectWithScissor. For now, always force enable scissor.      mCaches.enableScissor();      SkPaint paint; -    paint.setColor(mCaches.propertyShadowStrength << 24); +    paint.setARGB(mCaches.propertyShadowStrength, 0, 0, 0);      paint.setAntiAlias(true); // want to use AlphaVertex +    // tessellate caster outline into a 2d polygon +    Vector<Vertex> casterVertices2d; +    const float casterRefinementThresholdSquared = 20.0f; // TODO: experiment with this value +    PathTessellator::approximatePathOutlineVertices(*casterOutline, +            casterRefinementThresholdSquared, casterVertices2d); + +    // map 2d caster poly into 3d +    const int casterVertexCount = casterVertices2d.size(); +    Vector3 casterPolygon[casterVertexCount]; +    for (int i = 0; i < casterVertexCount; i++) { +        const Vertex& point2d = casterVertices2d[i]; +        casterPolygon[i] = Vector3(point2d.x, point2d.y, 0); +        casterTransform.mapPoint3d(casterPolygon[i]); +    } + +    // draw caster's shadows      VertexBuffer ambientShadowVertexBuffer; -    ShadowTessellator::tessellateAmbientShadow(width, height, casterTransform, +    ShadowTessellator::tessellateAmbientShadow(casterPolygon, casterVertexCount,              ambientShadowVertexBuffer);      drawVertexBuffer(ambientShadowVertexBuffer, &paint);      VertexBuffer spotShadowVertexBuffer;      Vector3 lightPosScale(mCaches.propertyLightPosXScale,              mCaches.propertyLightPosYScale, mCaches.propertyLightPosZScale); -    ShadowTessellator::tessellateSpotShadow(width, height, lightPosScale, -            *currentTransform(), getWidth(), getHeight(), -            casterTransform, spotShadowVertexBuffer); +    ShadowTessellator::tessellateSpotShadow(casterPolygon, casterVertexCount, +            lightPosScale, *currentTransform(), getWidth(), getHeight(), +            spotShadowVertexBuffer);      drawVertexBuffer(spotShadowVertexBuffer, &paint); |