Skip to content

Commit 5e7c469

Browse files
author
Romain Guy
committed
Make sure 9patches are not filtered when not necessary
Bug #5383406 Change-Id: I061c8069a4d9f4eaf45671283710b564639eeb32
1 parent a62f172 commit 5e7c469

File tree

9 files changed

+29
-15
lines changed

9 files changed

+29
-15
lines changed

libs/hwui/Patch.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,17 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
157157

158158
for (uint32_t i = 0; i < mYCount; i++) {
159159
float stepY = mYDivs[i];
160+
const float segment = stepY - previousStepY;
160161

161162
if (i & 1) {
162-
const float segment = stepY - previousStepY;
163163
y2 = y1 + floorf(segment * stretchY + 0.5f);
164164
} else {
165-
y2 = y1 + stepY - previousStepY;
165+
y2 = y1 + segment;
166166
}
167-
float v2 = fmax(0.0f, stepY - 0.5f) / bitmapHeight;
167+
168+
float vOffset = y1 == y2 ? 0.0f : 0.5 - (0.5 * segment / (y2 - y1));
169+
float v2 = fmax(0.0f, stepY - vOffset) / bitmapHeight;
170+
v1 += vOffset / bitmapHeight;
168171

169172
if (stepY > 0.0f) {
170173
#if DEBUG_EXPLODE_PATCHES
@@ -179,7 +182,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
179182
}
180183

181184
y1 = y2;
182-
v1 = (stepY + 0.5f) / bitmapHeight;
185+
v1 = stepY / bitmapHeight;
183186

184187
previousStepY = stepY;
185188
}
@@ -190,8 +193,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
190193
y1 += mYCount * EXPLODE_GAP;
191194
y2 += mYCount * EXPLODE_GAP;
192195
#endif
193-
generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left,
194-
bitmapWidth, quadCount);
196+
generateRow(vertex, y1, y2, v1, 1.0f, stretchX, right - left, bitmapWidth, quadCount);
195197
}
196198

197199
if (verticesCount > 0) {
@@ -220,14 +222,17 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
220222
// Generate the row quad by quad
221223
for (uint32_t i = 0; i < mXCount; i++) {
222224
float stepX = mXDivs[i];
225+
const float segment = stepX - previousStepX;
223226

224227
if (i & 1) {
225-
const float segment = stepX - previousStepX;
226228
x2 = x1 + floorf(segment * stretchX + 0.5f);
227229
} else {
228-
x2 = x1 + stepX - previousStepX;
230+
x2 = x1 + segment;
229231
}
230-
float u2 = fmax(0.0f, stepX - 0.5f) / bitmapWidth;
232+
233+
float uOffset = x1 == x2 ? 0.0f : 0.5 - (0.5 * segment / (x2 - x1));
234+
float u2 = fmax(0.0f, stepX - uOffset) / bitmapWidth;
235+
u1 += uOffset / bitmapWidth;
231236

232237
if (stepX > 0.0f) {
233238
#if DEBUG_EXPLODE_PATCHES
@@ -241,7 +246,7 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
241246
}
242247

243248
x1 = x2;
244-
u1 = (stepX + 0.5f) / bitmapWidth;
249+
u1 = stepX / bitmapWidth;
245250

246251
previousStepX = stepX;
247252
}
@@ -265,8 +270,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
265270
if ((mColorKey >> oldQuadCount) & 0x1) {
266271
#if DEBUG_PATCHES_EMPTY_VERTICES
267272
PATCH_LOGD(" quad %d (empty)", oldQuadCount);
268-
PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1);
269-
PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2);
273+
PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
274+
PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2);
270275
#endif
271276
return;
272277
}
@@ -294,8 +299,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
294299

295300
#if DEBUG_PATCHES_VERTICES
296301
PATCH_LOGD(" quad %d", oldQuadCount);
297-
PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.2f, %.2f", x1, y1, u1, v1);
298-
PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.2f, %.2f", x2, y2, u2, v2);
302+
PATCH_LOGD(" left, top = %.2f, %.2f\t\tu1, v1 = %.4f, %.4f", x1, y1, u1, v1);
303+
PATCH_LOGD(" right, bottom = %.2f, %.2f\t\tu2, v2 = %.4f, %.4f", x2, y2, u2, v2);
299304
#endif
300305
}
301306

tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg.9.png

File renamed without changes.

tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_focus.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_focus.9.png

File renamed without changes.

tests/HwAccelerationTest/res/drawable-hdpi/appwidget_bg_press.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/appwidget_bg_press.9.png

File renamed without changes.

tests/HwAccelerationTest/res/drawable-hdpi/green_gradient.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/green_gradient.9.png

File renamed without changes.

tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/patch.9.png

File renamed without changes.
2.76 KB
Loading

tests/HwAccelerationTest/res/drawable-hdpi/widget_title_bg.9.png renamed to tests/HwAccelerationTest/res/drawable-nodpi/widget_title_bg.9.png

File renamed without changes.

tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4444
}
4545

4646
private class PatchView extends View {
47-
private Drawable mPatch1, mPatch2;
47+
private Drawable mPatch1, mPatch2, mPatch3;
4848
private Bitmap mTexture;
4949

5050
public PatchView(Activity activity) {
@@ -53,6 +53,7 @@ public PatchView(Activity activity) {
5353
final Resources resources = activity.getResources();
5454
mPatch1 = resources.getDrawable(R.drawable.patch);
5555
mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);
56+
mPatch3 = resources.getDrawable(R.drawable.patch2);
5657

5758
mTexture = Bitmap.createBitmap(4, 3, Bitmap.Config.ARGB_8888);
5859
mTexture.setPixel(0, 0, 0xffff0000);
@@ -77,6 +78,14 @@ protected void onDraw(Canvas canvas) {
7778
final int left = (getWidth() - width) / 2;
7879
final int top = (getHeight() - height) / 2;
7980

81+
canvas.save();
82+
canvas.translate(0.0f, -height * 2 - 20.0f);
83+
84+
mPatch3.setBounds(left, top, left + height, top + width);
85+
mPatch3.draw(canvas);
86+
87+
canvas.restore();
88+
8089
mPatch1.setBounds(left, top, left + width, top + height);
8190
mPatch1.draw(canvas);
8291

0 commit comments

Comments
 (0)