summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Arun <arun.demeure@imgtec.com> 2017-05-05 19:10:21 +0000
committer android-build-merger <android-build-merger@google.com> 2017-05-05 19:10:21 +0000
commit93cafba790b0210bf05cf1a9db2e94301a7643ff (patch)
tree3f53d824661f87b91a1e6a43a13f5805f96f3da5
parentad2f0735b807987d70f260a04983fe2d63944070 (diff)
parentb5facc7516aff32056a4219608e764658271d328 (diff)
Merge "Reduce hwui CPU time by using glDrawRangeElements" am: 057c7c3164 am: 94f4f5e45f
am: b5facc7516 Change-Id: I9e96bf83ae5ebd4237fc4d78a58e83793de86aad
-rw-r--r--libs/hwui/Glop.h1
-rw-r--r--libs/hwui/GlopBuilder.cpp1
-rw-r--r--libs/hwui/renderstate/RenderState.cpp16
3 files changed, 15 insertions, 3 deletions
diff --git a/libs/hwui/Glop.h b/libs/hwui/Glop.h
index 34c7934db198..e91c08d5a351 100644
--- a/libs/hwui/Glop.h
+++ b/libs/hwui/Glop.h
@@ -110,6 +110,7 @@ public:
} vertices;
int elementCount;
+ int vertexCount; // only used for meshes (for glDrawRangeElements)
TextureVertex mappedVertices[4];
} mesh;
diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp
index 931a55a70fd8..2e9a6e895d8a 100644
--- a/libs/hwui/GlopBuilder.cpp
+++ b/libs/hwui/GlopBuilder.cpp
@@ -199,6 +199,7 @@ GlopBuilder& GlopBuilder::setMeshVertexBuffer(const VertexBuffer& vertexBuffer)
alphaVertex ? kAlphaVertexStride : kVertexStride };
mOutGlop->mesh.elementCount = indices
? vertexBuffer.getIndexCount() : vertexBuffer.getVertexCount();
+ mOutGlop->mesh.vertexCount = vertexBuffer.getVertexCount(); // used for glDrawRangeElements()
return *this;
}
diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp
index c8833d2a7489..8b737bb241cb 100644
--- a/libs/hwui/renderstate/RenderState.cpp
+++ b/libs/hwui/renderstate/RenderState.cpp
@@ -413,18 +413,28 @@ void RenderState::render(const Glop& glop, const Matrix4& orthoMatrix) {
const GLbyte* vertexData = static_cast<const GLbyte*>(vertices.position);
while (elementsCount > 0) {
GLsizei drawCount = std::min(elementsCount, (GLsizei) kMaxNumberOfQuads * 6);
+ GLsizei vertexCount = (drawCount / 6) * 4;
meshState().bindPositionVertexPointer(vertexData, vertices.stride);
if (vertices.attribFlags & VertexAttribFlags::TextureCoord) {
meshState().bindTexCoordsVertexPointer(
vertexData + kMeshTextureOffset, vertices.stride);
}
- glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
+ if (mCaches->extensions().getMajorGlVersion() >= 3) {
+ glDrawRangeElements(mesh.primitiveMode, 0, vertexCount-1, drawCount, GL_UNSIGNED_SHORT, nullptr);
+ } else {
+ glDrawElements(mesh.primitiveMode, drawCount, GL_UNSIGNED_SHORT, nullptr);
+ }
elementsCount -= drawCount;
- vertexData += (drawCount / 6) * 4 * vertices.stride;
+ vertexData += vertexCount * vertices.stride;
}
} else if (indices.bufferObject || indices.indices) {
- glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
+ if (mCaches->extensions().getMajorGlVersion() >= 3) {
+ // use glDrawRangeElements to reduce CPU overhead (otherwise the driver has to determine the min/max index values)
+ glDrawRangeElements(mesh.primitiveMode, 0, mesh.vertexCount-1, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
+ } else {
+ glDrawElements(mesh.primitiveMode, mesh.elementCount, GL_UNSIGNED_SHORT, indices.indices);
+ }
} else {
glDrawArrays(mesh.primitiveMode, 0, mesh.elementCount);
}