Skip to content

Commit 827dde0

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Support clipping in Canvas.drawBitmapMesh() Bug #7354162" into jb-mr1-dev
2 parents dc9e13b + a92bb4d commit 827dde0

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,35 +1730,22 @@ status_t OpenGLRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
17301730

17311731
status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
17321732
float* vertices, int* colors, SkPaint* paint) {
1733-
// TODO: Do a quickReject
17341733
if (!vertices || mSnapshot->isIgnored()) {
17351734
return DrawGlInfo::kStatusDone;
17361735
}
17371736

1738-
mCaches.activeTexture(0);
1739-
Texture* texture = mCaches.textureCache.get(bitmap);
1740-
if (!texture) return DrawGlInfo::kStatusDone;
1741-
const AutoTexture autoCleanup(texture);
1742-
1743-
texture->setWrap(GL_CLAMP_TO_EDGE, true);
1744-
texture->setFilter(FILTER(paint), true);
1745-
1746-
int alpha;
1747-
SkXfermode::Mode mode;
1748-
getAlphaAndMode(paint, &alpha, &mode);
1749-
1750-
const uint32_t count = meshWidth * meshHeight * 6;
1751-
1737+
// TODO: We should compute the bounding box when recording the display list
17521738
float left = FLT_MAX;
17531739
float top = FLT_MAX;
17541740
float right = FLT_MIN;
17551741
float bottom = FLT_MIN;
17561742

1757-
const bool hasActiveLayer = hasLayer();
1743+
const uint32_t count = meshWidth * meshHeight * 6;
17581744

17591745
// TODO: Support the colors array
17601746
TextureVertex mesh[count];
17611747
TextureVertex* vertex = mesh;
1748+
17621749
for (int32_t y = 0; y < meshHeight; y++) {
17631750
for (int32_t x = 0; x < meshWidth; x++) {
17641751
uint32_t i = (y * (meshWidth + 1) + x) * 2;
@@ -1785,17 +1772,31 @@ status_t OpenGLRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int mes
17851772
TextureVertex::set(vertex++, vertices[cx], vertices[cy], u2, v1);
17861773
TextureVertex::set(vertex++, vertices[dx], vertices[dy], u2, v2);
17871774

1788-
if (hasActiveLayer) {
1789-
// TODO: This could be optimized to avoid unnecessary ops
1790-
left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
1791-
top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
1792-
right = fmaxf(right, fmaxf(vertices[ax], fmaxf(vertices[bx], vertices[cx])));
1793-
bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy])));
1794-
}
1775+
// TODO: This could be optimized to avoid unnecessary ops
1776+
left = fminf(left, fminf(vertices[ax], fminf(vertices[bx], vertices[cx])));
1777+
top = fminf(top, fminf(vertices[ay], fminf(vertices[by], vertices[cy])));
1778+
right = fmaxf(right, fmaxf(vertices[ax], fmaxf(vertices[bx], vertices[cx])));
1779+
bottom = fmaxf(bottom, fmaxf(vertices[ay], fmaxf(vertices[by], vertices[cy])));
17951780
}
17961781
}
17971782

1798-
if (hasActiveLayer) {
1783+
if (quickReject(left, top, right, bottom)) {
1784+
return DrawGlInfo::kStatusDone;
1785+
}
1786+
1787+
mCaches.activeTexture(0);
1788+
Texture* texture = mCaches.textureCache.get(bitmap);
1789+
if (!texture) return DrawGlInfo::kStatusDone;
1790+
const AutoTexture autoCleanup(texture);
1791+
1792+
texture->setWrap(GL_CLAMP_TO_EDGE, true);
1793+
texture->setFilter(FILTER(paint), true);
1794+
1795+
int alpha;
1796+
SkXfermode::Mode mode;
1797+
getAlphaAndMode(paint, &alpha, &mode);
1798+
1799+
if (hasLayer()) {
17991800
dirtyLayer(left, top, right, bottom, *mSnapshot->transform);
18001801
}
18011802

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,16 @@ protected void onDraw(Canvas canvas) {
6868
super.onDraw(canvas);
6969

7070
canvas.drawARGB(255, 255, 255, 255);
71+
7172
canvas.translate(100, 100);
7273
canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);
7374

75+
canvas.save();
76+
canvas.translate(0, 400);
77+
canvas.clipRect(0.0f, 0.0f, 80.0f, 80.0f);
78+
canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);
79+
canvas.restore();
80+
7481
canvas.translate(400, 0);
7582
canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, mColors, 0, null);
7683
}

0 commit comments

Comments
 (0)