summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2012-10-10 16:06:04 -0700
committerRomain Guy <romainguy@google.com>2012-10-10 16:06:04 -0700
commit41d35aef06c2a570a45474a01ca95a6cb9c29d9e (patch)
tree0e4d15428b41eef15744027e19a00516bb8edab6 /libs
parent251445667ce045c4425c10fb24e3e23f90a210c0 (diff)
downloadframeworks_base-41d35aef06c2a570a45474a01ca95a6cb9c29d9e.zip
frameworks_base-41d35aef06c2a570a45474a01ca95a6cb9c29d9e.tar.gz
frameworks_base-41d35aef06c2a570a45474a01ca95a6cb9c29d9e.tar.bz2
Allow 9patches to shrink
Bug #7307304 Change-Id: I1fabf6df99c18c86ab1ec0e1e398a3d6d4098496
Diffstat (limited to 'libs')
-rw-r--r--libs/hwui/Patch.cpp24
-rw-r--r--libs/hwui/Patch.h4
2 files changed, 17 insertions, 11 deletions
diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp
index abc88fa..b3631df 100644
--- a/libs/hwui/Patch.cpp
+++ b/libs/hwui/Patch.cpp
@@ -118,7 +118,10 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
const uint32_t yStretchCount = (mYCount + 1) >> 1;
float stretchX = 0.0f;
- float stretchY = 0.0;
+ float stretchY = 0.0f;
+
+ float rescaleX = 1.0f;
+ float rescaleY = 1.0f;
const float meshWidth = right - left;
@@ -129,8 +132,9 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
}
const float xStretchTex = stretchSize;
const float fixed = bitmapWidth - stretchSize;
- const float xStretch = right - left - fixed;
+ const float xStretch = fmaxf(right - left - fixed, 0.0f);
stretchX = xStretch / xStretchTex;
+ rescaleX = fminf(fmaxf(right - left, 0.0f) / fixed, 1.0f);
}
if (yStretchCount > 0) {
@@ -140,8 +144,9 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
}
const float yStretchTex = stretchSize;
const float fixed = bitmapHeight - stretchSize;
- const float yStretch = bottom - top - fixed;
+ const float yStretch = fmaxf(bottom - top - fixed, 0.0f);
stretchY = yStretch / yStretchTex;
+ rescaleY = fminf(fmaxf(bottom - top, 0.0f) / fixed, 1.0f);
}
TextureVertex* vertex = mVertices;
@@ -160,7 +165,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
if (i & 1) {
y2 = y1 + floorf(segment * stretchY + 0.5f);
} else {
- y2 = y1 + segment;
+ y2 = y1 + segment * rescaleY;
}
float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1));
@@ -172,7 +177,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
y1 += i * EXPLODE_GAP;
y2 += i * EXPLODE_GAP;
#endif
- generateRow(vertex, y1, y2, v1, v2, stretchX, right - left,
+ generateRow(vertex, y1, y2, v1, v2, stretchX, rescaleX, right - left,
bitmapWidth, quadCount);
#if DEBUG_EXPLODE_PATCHES
y2 -= i * EXPLODE_GAP;
@@ -191,7 +196,8 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
y1 += mYCount * EXPLODE_GAP;
y2 += mYCount * EXPLODE_GAP;
#endif
- generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount);
+ generateRow(vertex, y1, y2, v1, 1.0f, stretchX, rescaleX, right - left,
+ bitmapWidth, quadCount);
}
if (verticesCount > 0) {
@@ -212,7 +218,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
}
void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, float v2,
- float stretchX, float width, float bitmapWidth, uint32_t& quadCount) {
+ float stretchX, float rescaleX, float width, float bitmapWidth, uint32_t& quadCount) {
float previousStepX = 0.0f;
float x1 = 0.0f;
@@ -227,7 +233,7 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
if (i & 1) {
x2 = x1 + floorf(segment * stretchX + 0.5f);
} else {
- x2 = x1 + segment;
+ x2 = x1 + segment * rescaleX;
}
float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1));
@@ -272,7 +278,7 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
if (y2 < 0.0f) y2 = 0.0f;
// Skip degenerate and transparent (empty) quads
- if ((mColorKey >> oldQuadCount) & 0x1) {
+ if (((mColorKey >> oldQuadCount) & 0x1) || x1 >= x2 || y1 >= y2) {
#if DEBUG_PATCHES_EMPTY_VERTICES
PATCH_LOGD(" quad %d (empty)", oldQuadCount);
PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
diff --git a/libs/hwui/Patch.h b/libs/hwui/Patch.h
index 28c9048..0518d91 100644
--- a/libs/hwui/Patch.h
+++ b/libs/hwui/Patch.h
@@ -75,8 +75,8 @@ private:
void copy(const int32_t* yDivs);
void generateRow(TextureVertex*& vertex, float y1, float y2,
- float v1, float v2, float stretchX, float width, float bitmapWidth,
- uint32_t& quadCount);
+ float v1, float v2, float stretchX, float rescaleX,
+ float width, float bitmapWidth, uint32_t& quadCount);
void generateQuad(TextureVertex*& vertex,
float x1, float y1, float x2, float y2,
float u1, float v1, float u2, float v2,