From 15a07a21eb33e8ca1c7444944fe0541a53380c0c Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Sun, 26 Jan 2014 13:43:53 -0800 Subject: 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 --- libs/hwui/OpenGLRenderer.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'libs/hwui/OpenGLRenderer.cpp') 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 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); -- cgit v1.2.3-59-g8ed1b