diff options
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 37 | ||||
-rw-r--r-- | graphics/java/android/graphics/NinePatch.java | 44 | ||||
-rw-r--r-- | libs/hwui/Patch.cpp | 12 |
3 files changed, 48 insertions, 45 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index bd871c4..14ac901 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -61,6 +61,7 @@ public class Canvas { protected int mScreenDensity = Bitmap.DENSITY_NONE; // Used by native code + @SuppressWarnings("UnusedDeclaration") private int mSurfaceFormat; /** @@ -381,8 +382,8 @@ public class Canvas { */ public int saveLayer(RectF bounds, Paint paint, int saveFlags) { return native_saveLayer(mNativeCanvas, bounds, - paint != null ? paint.mNativePaint : 0, - saveFlags); + paint != null ? paint.mNativePaint : 0, + saveFlags); } /** @@ -391,8 +392,8 @@ public class Canvas { public int saveLayer(float left, float top, float right, float bottom, Paint paint, int saveFlags) { return native_saveLayer(mNativeCanvas, left, top, right, bottom, - paint != null ? paint.mNativePaint : 0, - saveFlags); + paint != null ? paint.mNativePaint : 0, + saveFlags); } /** @@ -1039,7 +1040,7 @@ public class Canvas { throw new NullPointerException(); } native_drawArc(mNativeCanvas, oval, startAngle, sweepAngle, - useCenter, paint.mNativePaint); + useCenter, paint.mNativePaint); } /** @@ -1079,8 +1080,6 @@ public class Canvas { /** * Draws the specified bitmap as an N-patch (most often, a 9-patches.) * - * Note: Only supported by hardware accelerated canvas at the moment. - * * @param patch The ninepatch object to render * @param dst The destination rectangle. * @param paint The paint to draw the bitmap with. may be null @@ -1088,13 +1087,12 @@ public class Canvas { * @hide */ public void drawPatch(NinePatch patch, Rect dst, Paint paint) { + patch.drawSoftware(this, dst, paint); } /** * Draws the specified bitmap as an N-patch (most often, a 9-patches.) * - * Note: Only supported by hardware accelerated canvas at the moment. - * * @param patch The ninepatch object to render * @param dst The destination rectangle. * @param paint The paint to draw the bitmap with. may be null @@ -1102,6 +1100,7 @@ public class Canvas { * @hide */ public void drawPatch(NinePatch patch, RectF dst, Paint paint) { + patch.drawSoftware(this, dst, paint); } /** @@ -1188,7 +1187,7 @@ public class Canvas { } throwIfRecycled(bitmap); native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, - paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); + paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity); } /** @@ -1309,8 +1308,8 @@ public class Canvas { checkRange(colors.length, colorOffset, count); } nativeDrawBitmapMesh(mNativeCanvas, bitmap.ni(), meshWidth, meshHeight, - verts, vertOffset, colors, colorOffset, - paint != null ? paint.mNativePaint : 0); + verts, vertOffset, colors, colorOffset, + paint != null ? paint.mNativePaint : 0); } public enum VertexMode { @@ -1372,8 +1371,8 @@ public class Canvas { checkRange(indices.length, indexOffset, indexCount); } nativeDrawVertices(mNativeCanvas, mode.nativeInt, vertexCount, verts, - vertOffset, texs, texOffset, colors, colorOffset, - indices, indexOffset, indexCount, paint.mNativePaint); + vertOffset, texs, texOffset, colors, colorOffset, + indices, indexOffset, indexCount, paint.mNativePaint); } /** @@ -1444,10 +1443,10 @@ public class Canvas { if (text instanceof String || text instanceof SpannedString || text instanceof SpannableString) { native_drawText(mNativeCanvas, text.toString(), start, end, x, y, - paint.mBidiFlags, paint.mNativePaint); + paint.mBidiFlags, paint.mNativePaint); } else if (text instanceof GraphicsOperations) { ((GraphicsOperations) text).drawText(this, start, end, x, y, - paint); + paint); } else { char[] buf = TemporaryBuffer.obtain(end - start); TextUtils.getChars(text, start, end, buf, 0); @@ -1568,7 +1567,7 @@ public class Canvas { throw new IndexOutOfBoundsException(); } native_drawPosText(mNativeCanvas, text, index, count, pos, - paint.mNativePaint); + paint.mNativePaint); } /** @@ -1609,8 +1608,8 @@ public class Canvas { throw new ArrayIndexOutOfBoundsException(); } native_drawTextOnPath(mNativeCanvas, text, index, count, - path.ni(), hOffset, vOffset, - paint.mBidiFlags, paint.mNativePaint); + path.ni(), hOffset, vOffset, + paint.mBidiFlags, paint.mNativePaint); } /** diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java index 932e474..ab1c328 100644 --- a/graphics/java/android/graphics/NinePatch.java +++ b/graphics/java/android/graphics/NinePatch.java @@ -100,16 +100,9 @@ public class NinePatch { * @param location Where to draw the bitmap. */ public void draw(Canvas canvas, RectF location) { - if (canvas.isHardwareAccelerated()) { - canvas.drawPatch(this, location, mPaint); - } else { - nativeDraw(canvas.mNativeCanvas, location, - mBitmap.ni(), mChunk, - mPaint != null ? mPaint.mNativePaint : 0, - canvas.mDensity, mBitmap.mDensity); - } + canvas.drawPatch(this, location, mPaint); } - + /** * Draw a bitmap of nine patches. * @@ -117,14 +110,7 @@ public class NinePatch { * @param location Where to draw the bitmap. */ public void draw(Canvas canvas, Rect location) { - if (canvas.isHardwareAccelerated()) { - canvas.drawPatch(this, location, mPaint); - } else { - nativeDraw(canvas.mNativeCanvas, location, - mBitmap.ni(), mChunk, - mPaint != null ? mPaint.mNativePaint : 0, - canvas.mDensity, mBitmap.mDensity); - } + canvas.drawPatch(this, location, mPaint); } /** @@ -135,13 +121,23 @@ public class NinePatch { * @param paint The Paint to draw through. */ public void draw(Canvas canvas, Rect location, Paint paint) { - if (canvas.isHardwareAccelerated()) { - canvas.drawPatch(this, location, paint); - } else { - nativeDraw(canvas.mNativeCanvas, location, - mBitmap.ni(), mChunk, paint != null ? paint.mNativePaint : 0, - canvas.mDensity, mBitmap.mDensity); - } + canvas.drawPatch(this, location, paint); + } + + /** + * @hide + */ + void drawSoftware(Canvas canvas, RectF location, Paint paint) { + nativeDraw(canvas.mNativeCanvas, location, mBitmap.ni(), mChunk, + paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity); + } + + /** + * @hide + */ + void drawSoftware(Canvas canvas, Rect location, Paint paint) { + nativeDraw(canvas.mNativeCanvas, location, mBitmap.ni(), mChunk, + paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity); } /** diff --git a/libs/hwui/Patch.cpp b/libs/hwui/Patch.cpp index 9e3e701..7656f85 100644 --- a/libs/hwui/Patch.cpp +++ b/libs/hwui/Patch.cpp @@ -79,8 +79,8 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig uint32_t maxVertices = ((xCount + 1) * (yCount + 1) - emptyQuads) * 4; if (maxVertices == 0) return NULL; - vertices = new TextureVertex[maxVertices]; - TextureVertex* vertex = vertices; + TextureVertex* tempVertices = new TextureVertex[maxVertices]; + TextureVertex* vertex = tempVertices; const int32_t* xDivs = patch->xDivs; const int32_t* yDivs = patch->yDivs; @@ -159,6 +159,14 @@ TextureVertex* Patch::createMesh(const float bitmapWidth, const float bitmapHeig width, bitmapWidth, quadCount); } + if (verticesCount == maxVertices) { + vertices = tempVertices; + } else { + vertices = new TextureVertex[verticesCount]; + memcpy(vertices, tempVertices, verticesCount * sizeof(TextureVertex)); + delete[] tempVertices; + } + return vertices; } |