diff options
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index b620b80..1475953 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -170,21 +170,7 @@ void OpenGLRenderer::setViewport(int width, int height) { } void OpenGLRenderer::initViewport(int width, int height) { - if (mCaches.propertyEnable3d) { - // TODO: make view proj app configurable - float dist = std::max(width, height) * 1.5; - dist *= mCaches.propertyCameraDistance; - Matrix4 projection; - projection.loadFrustum(-width / 2, -height / 2, width / 2, height / 2, dist, 0); - Matrix4 view; - view.loadLookAt(0, 0, dist, - 0, 0, 0, - 0, 1, 0); - mViewProjMatrix.loadMultiply(projection, view); - mViewProjMatrix.translate(-width/2, -height/2); - } else { - mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1); - } + mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1); initializeViewport(width, height); } @@ -1926,16 +1912,9 @@ void OpenGLRenderer::setupDrawIndexedVertices(GLvoid* vertices) { // Drawing /////////////////////////////////////////////////////////////////////////////// -status_t OpenGLRenderer::drawDisplayList(DisplayList* displayList, Rect& dirty, +status_t OpenGLRenderer::drawDisplayList(RenderNode* displayList, Rect& dirty, int32_t replayFlags) { status_t status; - - if (mCaches.propertyDirtyViewport) { - // force recalc of view/proj matrices - setViewport(getWidth(), getHeight()); - mCaches.propertyDirtyViewport = false; - } - // All the usual checks and setup operations (quickReject, setupDraw, etc.) // will be performed by the display list itself if (displayList && displayList->isRenderable()) { @@ -3211,8 +3190,16 @@ status_t OpenGLRenderer::drawRects(const float* rects, int count, const SkPaint* return drawColorRects(rects, count, paint, false, true, true); } -status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlpha, - const SkPath* casterOutline) { +static void mapPointFakeZ(Vector3& point, const mat4& transformXY, const mat4& transformZ) { + // map z coordinate with true 3d matrix + point.z = transformZ.mapZ(point); + + // map x,y coordinates with draw/Skia matrix + transformXY.mapPoint(point.x, point.y); +} + +status_t OpenGLRenderer::drawShadow(const mat4& casterTransformXY, const mat4& casterTransformZ, + float casterAlpha, const SkPath* casterOutline) { if (currentSnapshot()->isIgnored()) return DrawGlInfo::kStatusDone; // TODO: use quickRejectWithScissor. For now, always force enable scissor. @@ -3235,10 +3222,12 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp // map 2d caster poly into 3d const int casterVertexCount = casterVertices2d.size(); Vector3 casterPolygon[casterVertexCount]; + float minZ = FLT_MAX; for (int i = 0; i < casterVertexCount; i++) { const Vertex& point2d = casterVertices2d[i]; casterPolygon[i] = Vector3(point2d.x, point2d.y, 0); - casterTransform.mapPoint3d(casterPolygon[i]); + mapPointFakeZ(casterPolygon[i], casterTransformXY, casterTransformZ); + minZ = fmin(minZ, casterPolygon[i].z); } // map the centroid of the caster into 3d @@ -3246,7 +3235,16 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp reinterpret_cast<const Vector2*>(casterVertices2d.array()), casterVertexCount); Vector3 centroid3d(centroid.x, centroid.y, 0); - casterTransform.mapPoint3d(centroid3d); + mapPointFakeZ(centroid3d, casterTransformXY, casterTransformZ); + + // if the caster intersects the z=0 plane, lift it in Z so it doesn't + if (minZ < SHADOW_MIN_CASTER_Z) { + float casterLift = SHADOW_MIN_CASTER_Z - minZ; + for (int i = 0; i < casterVertexCount; i++) { + casterPolygon[i].z += casterLift; + } + centroid3d.z += casterLift; + } // draw caster's shadows if (mCaches.propertyAmbientShadowStrength > 0) { @@ -3265,7 +3263,6 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp ShadowTessellator::tessellateSpotShadow(casterPolygon, casterVertexCount, lightPosScale, *currentTransform(), getWidth(), getHeight(), spotShadowVertexBuffer); - drawVertexBuffer(kVertexBufferMode_Shadow, spotShadowVertexBuffer, &paint); } |
