diff options
author | ztenghui <ztenghui@google.com> | 2014-02-25 23:20:06 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-02-25 23:20:06 +0000 |
commit | 8198c3a8f525c07e2b848852f6ad3e351e3b5461 (patch) | |
tree | 342d10b2f40fd3db65e41cb98b7ee29412b34683 /libs/hwui/OpenGLRenderer.cpp | |
parent | a1f1a3c573acd91024fda0ceb3b921c73b186963 (diff) | |
parent | 63d41abb40b3ce40d8b9bccb1cf186e8158a3687 (diff) | |
download | frameworks_base-8198c3a8f525c07e2b848852f6ad3e351e3b5461.zip frameworks_base-8198c3a8f525c07e2b848852f6ad3e351e3b5461.tar.gz frameworks_base-8198c3a8f525c07e2b848852f6ad3e351e3b5461.tar.bz2 |
Merge "Use pre-computed index to draw the shadow."
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 75bf716..9ac2792 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -1902,7 +1902,7 @@ void OpenGLRenderer::setupDrawMeshIndices(const GLvoid* vertices, } else { force = mCaches.unbindMeshBuffer(); } - mCaches.bindIndicesBuffer(); + mCaches.bindQuadIndicesBuffer(); mCaches.bindPositionVertexPointer(force, vertices); if (mCaches.currentProgram->texCoords >= 0) { @@ -1912,7 +1912,7 @@ void OpenGLRenderer::setupDrawMeshIndices(const GLvoid* vertices, void OpenGLRenderer::setupDrawIndexedVertices(GLvoid* vertices) { bool force = mCaches.unbindMeshBuffer(); - mCaches.bindIndicesBuffer(); + mCaches.bindQuadIndicesBuffer(); mCaches.bindPositionVertexPointer(force, vertices, gVertexStride); } @@ -2387,10 +2387,9 @@ status_t OpenGLRenderer::drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* return DrawGlInfo::kStatusDrew; } -status_t OpenGLRenderer::drawVertexBuffer(const VertexBuffer& vertexBuffer, const SkPaint* paint, - bool useOffset) { +status_t OpenGLRenderer::drawVertexBuffer(VertexBufferMode mode, + const VertexBuffer& vertexBuffer, const SkPaint* paint, bool useOffset) { // not missing call to quickReject/dirtyLayer, always done at a higher level - if (!vertexBuffer.getVertexCount()) { // no vertices to draw return DrawGlInfo::kStatusDone; @@ -2416,19 +2415,24 @@ status_t OpenGLRenderer::drawVertexBuffer(const VertexBuffer& vertexBuffer, cons bool force = mCaches.unbindMeshBuffer(); mCaches.bindPositionVertexPointer(true, vertices, isAA ? gAlphaVertexStride : gVertexStride); mCaches.resetTexCoordsVertexPointer(); - mCaches.unbindIndicesBuffer(); + int alphaSlot = -1; if (isAA) { void* alphaCoords = ((GLbyte*) vertices) + gVertexAlphaOffset; alphaSlot = mCaches.currentProgram->getAttrib("vtxAlpha"); - // TODO: avoid enable/disable in back to back uses of the alpha attribute glEnableVertexAttribArray(alphaSlot); glVertexAttribPointer(alphaSlot, 1, GL_FLOAT, GL_FALSE, gAlphaVertexStride, alphaCoords); } - glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexBuffer.getVertexCount()); + if (mode == kVertexBufferMode_Standard) { + mCaches.unbindIndicesBuffer(); + glDrawArrays(GL_TRIANGLE_STRIP, 0, vertexBuffer.getVertexCount()); + } else { + mCaches.bindShadowIndicesBuffer(); + glDrawElements(GL_TRIANGLE_STRIP, SHADOW_INDEX_COUNT, GL_UNSIGNED_SHORT, 0); + } if (isAA) { glDisableVertexAttribArray(alphaSlot); @@ -2457,7 +2461,7 @@ status_t OpenGLRenderer::drawConvexPath(const SkPath& path, const SkPaint* paint dirtyLayer(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, *currentTransform()); } - return drawVertexBuffer(vertexBuffer, paint); + return drawVertexBuffer(kVertexBufferMode_Standard, vertexBuffer, paint); } /** @@ -2488,7 +2492,7 @@ status_t OpenGLRenderer::drawLines(const float* points, int count, const SkPaint dirtyLayer(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, *currentTransform()); bool useOffset = !paint->isAntiAlias(); - return drawVertexBuffer(buffer, paint, useOffset); + return drawVertexBuffer(kVertexBufferMode_Standard, buffer, paint, useOffset); } status_t OpenGLRenderer::drawPoints(const float* points, int count, const SkPaint* paint) { @@ -2508,7 +2512,7 @@ status_t OpenGLRenderer::drawPoints(const float* points, int count, const SkPain dirtyLayer(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, *currentTransform()); bool useOffset = !paint->isAntiAlias(); - return drawVertexBuffer(buffer, paint, useOffset); + return drawVertexBuffer(kVertexBufferMode_Standard, buffer, paint, useOffset); } status_t OpenGLRenderer::drawColor(int color, SkXfermode::Mode mode) { @@ -3231,13 +3235,20 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp casterTransform.mapPoint3d(casterPolygon[i]); } + // map the centroid of the caster into 3d + Vector2 centroid = ShadowTessellator::centroid2d( + reinterpret_cast<const Vector2*>(casterVertices2d.array()), + casterVertexCount); + Vector3 centroid3d(centroid.x, centroid.y, 0); + casterTransform.mapPoint3d(centroid3d); + // draw caster's shadows if (mCaches.propertyAmbientShadowStrength > 0) { paint.setARGB(casterAlpha * mCaches.propertyAmbientShadowStrength, 0, 0, 0); VertexBuffer ambientShadowVertexBuffer; ShadowTessellator::tessellateAmbientShadow(casterPolygon, casterVertexCount, - ambientShadowVertexBuffer); - drawVertexBuffer(ambientShadowVertexBuffer, &paint); + centroid3d, ambientShadowVertexBuffer); + drawVertexBuffer(kVertexBufferMode_Shadow, ambientShadowVertexBuffer, &paint); } if (mCaches.propertySpotShadowStrength > 0) { @@ -3249,7 +3260,7 @@ status_t OpenGLRenderer::drawShadow(const mat4& casterTransform, float casterAlp lightPosScale, *currentTransform(), getWidth(), getHeight(), spotShadowVertexBuffer); - drawVertexBuffer(spotShadowVertexBuffer, &paint); + drawVertexBuffer(kVertexBufferMode_Shadow, spotShadowVertexBuffer, &paint); } return DrawGlInfo::kStatusDrew; |