aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkNinePatch.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-28 12:33:41 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-09-28 12:33:41 +0000
commitade907bf9843c626e66c739ee12479024497effe (patch)
tree1b100f49ef2ce9e1101b2f8961aa6121491fe073 /src/utils/SkNinePatch.cpp
parentf8897e8d5b8bce177caeb89abe5d8ccb360da2c1 (diff)
roll in fixes from android when we have to compress sections of "stretchy"
git-svn-id: http://skia.googlecode.com/svn/trunk@2345 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils/SkNinePatch.cpp')
-rw-r--r--src/utils/SkNinePatch.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/utils/SkNinePatch.cpp b/src/utils/SkNinePatch.cpp
index 16e815d4c8..6ee96848a0 100644
--- a/src/utils/SkNinePatch.cpp
+++ b/src/utils/SkNinePatch.cpp
@@ -55,10 +55,18 @@ static void fillRow(SkPoint verts[], SkPoint texs[],
texs->set(0, ty); texs++;
for (int x = 0; x < numXDivs; x++) {
SkScalar tx = SkIntToScalar(xDivs[x]);
- if (x & 1) {
- vx += stretchX;
+ if (stretchX >= 0) {
+ if (x & 1) {
+ vx += stretchX;
+ } else {
+ vx += tx;
+ }
} else {
- vx += tx;
+ if (x & 1) {
+ ; // do nothing
+ } else {
+ vx += SkScalarMul(tx, -stretchX);
+ }
}
verts->set(vx, vy); verts++;
texs->set(tx, ty); texs++;
@@ -110,8 +118,6 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
const int numYStretch = (numYDivs + 1) >> 1;
if (numXStretch < 1 && numYStretch < 1) {
- BITMAP_RECT:
-// SkDebugf("------ drawasamesh revert to bitmaprect\n");
canvas->drawBitmapRect(bitmap, NULL, bounds, paint);
return;
}
@@ -136,7 +142,8 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
int fixed = bitmap.width() - stretchSize;
stretchX = (bounds.width() - SkIntToScalar(fixed)) / numXStretch;
if (stretchX < 0) {
- goto BITMAP_RECT;
+ // reuse stretchX, but keep it negative as a signal
+ stretchX = -bitmap.width() / fixed;
}
}
@@ -148,7 +155,8 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
int fixed = bitmap.height() - stretchSize;
stretchY = (bounds.height() - SkIntToScalar(fixed)) / numYStretch;
if (stretchY < 0) {
- goto BITMAP_RECT;
+ // reuse stretchY, but keep it negative as a signal
+ stretchY = -bitmap.height() / fixed;
}
}
@@ -191,10 +199,18 @@ void SkNinePatch::DrawMesh(SkCanvas* canvas, const SkRect& bounds,
texs += numXDivs + 2;
for (int y = 0; y < numYDivs; y++) {
const SkScalar ty = SkIntToScalar(yDivs[y]);
- if (y & 1) {
- vy += stretchY;
- } else {
- vy += ty;
+ if (stretchY >= 0) {
+ if (y & 1) {
+ vy += stretchY;
+ } else {
+ vy += ty;
+ }
+ } else { // shrink fixed sections, and collaps stretchy sections
+ if (y & 1) {
+ ;// do nothing
+ } else {
+ vy += SkScalarMul(ty, -stretchY);
+ }
}
fillRow(verts, texs, vy, ty, bounds, xDivs, numXDivs,
stretchX, bitmap.width());