Fix 9patch rendering
Bug #3253396
Some quads were incorrectly assumed to be degenerate.
Change-Id: I9155699edc3424afe9d5a131886bb9966d46b109
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index fc14777..1a89ca0 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -954,11 +954,11 @@
mSnapshot->region && mesh->hasEmptyQuads) {
const size_t count = mesh->quads.size();
for (size_t i = 0; i < count; i++) {
- Rect bounds = mesh->quads.itemAt(i);
+ const Rect& bounds = mesh->quads.itemAt(i);
if (pureTranslate) {
const float x = (int) floorf(bounds.left + 0.5f);
const float y = (int) floorf(bounds.top + 0.5f);
- dirtyLayer(x, y, x + bounds.getWidth(), y + bounds.getBottom(),
+ dirtyLayer(x, y, x + bounds.getWidth(), y + bounds.getHeight(),
*mSnapshot->transform);
} else {
dirtyLayer(bounds.left, bounds.top, bounds.right, bounds.bottom,
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index 17b1d86..e5cb67b 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -35,7 +35,7 @@
mXCount(xCount), mYCount(yCount), mEmptyQuads(emptyQuads) {
// Initialized with the maximum number of vertices we will need
// 2 triangles per patch, 3 vertices per triangle
- const int maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3;
+ uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 2 * 3;
mVertices = new TextureVertex[maxVertices];
mUploaded = false;
@@ -160,7 +160,7 @@
float y2 = 0.0f;
if (i & 1) {
const float segment = stepY - previousStepY;
- y2 = y1 + segment * stretchY;
+ y2 = y1 + floorf(segment * stretchY + 0.5f);
} else {
y2 = y1 + stepY - previousStepY;
}
@@ -206,7 +206,7 @@
float x2 = 0.0f;
if (i & 1) {
const float segment = stepX - previousStepX;
- x2 = x1 + segment * stretchX;
+ x2 = x1 + floorf(segment * stretchX + 0.5f);
} else {
x2 = x1 + stepX - previousStepX;
}
@@ -226,7 +226,7 @@
void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, float y2,
float u1, float v1, float u2, float v2, uint32_t& quadCount) {
const uint32_t oldQuadCount = quadCount;
- const bool valid = fabs(x2 - x1) > 0.9999f && fabs(y2 - y1) > 0.9999f;
+ const bool valid = x2 - x1 > 0.9999f && y2 - y1 > 0.9999f;
if (valid) {
quadCount++;
}
diff --git a/libs/hwui/Patch.h b/libs/hwui/Patch.h
index 16ad86d..0f0ffa2 100644
--- a/libs/hwui/Patch.h
+++ b/libs/hwui/Patch.h
@@ -52,9 +52,7 @@
GLuint meshBuffer;
uint32_t verticesCount;
bool hasEmptyQuads;
-#if RENDER_LAYERS_AS_REGIONS
Vector<Rect> quads;
-#endif
private:
TextureVertex* mVertices;