diff options
Diffstat (limited to 'graphics/java')
-rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 2 | ||||
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 60 | ||||
-rw-r--r-- | graphics/java/android/graphics/CanvasProperty.java | 2 | ||||
-rw-r--r-- | graphics/java/android/graphics/DrawFilter.java | 7 | ||||
-rw-r--r-- | graphics/java/android/graphics/LayerRasterizer.java | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/Movie.java | 12 | ||||
-rw-r--r-- | graphics/java/android/graphics/NinePatch.java | 4 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 36 | ||||
-rw-r--r-- | graphics/java/android/graphics/PaintFlagsDrawFilter.java | 7 | ||||
-rw-r--r-- | graphics/java/android/graphics/Shader.java | 5 |
10 files changed, 74 insertions, 65 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 3090ffd..004d0ae 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -1542,7 +1542,7 @@ public final class Bitmap implements Parcelable { */ public Bitmap extractAlpha(Paint paint, int[] offsetXY) { checkRecycled("Can't extractAlpha on a recycled bitmap"); - long nativePaint = paint != null ? paint.mNativePaint : 0; + long nativePaint = paint != null ? paint.getNativeInstance() : 0; Bitmap bm = nativeExtractAlpha(mNativeBitmap, nativePaint, offsetXY); if (bm == null) { throw new RuntimeException("Failed to extractAlpha on Bitmap"); diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index b0580d5..a0267c8 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -475,7 +475,7 @@ public class Canvas { public int saveLayer(float left, float top, float right, float bottom, @Nullable Paint paint, @Saveflags int saveFlags) { return native_saveLayer(mNativeCanvasWrapper, left, top, right, bottom, - paint != null ? paint.mNativePaint : 0, + paint != null ? paint.getNativeInstance() : 0, saveFlags); } @@ -1031,7 +1031,7 @@ public class Canvas { * @param paint The paint used to draw onto the canvas */ public void drawPaint(@NonNull Paint paint) { - native_drawPaint(mNativeCanvasWrapper, paint.mNativePaint); + native_drawPaint(mNativeCanvasWrapper, paint.getNativeInstance()); } /** @@ -1051,7 +1051,7 @@ public class Canvas { * @param paint The paint used to draw the points */ public void drawPoints(float[] pts, int offset, int count, @NonNull Paint paint) { - native_drawPoints(mNativeCanvasWrapper, pts, offset, count, paint.mNativePaint); + native_drawPoints(mNativeCanvasWrapper, pts, offset, count, paint.getNativeInstance()); } /** @@ -1065,7 +1065,7 @@ public class Canvas { * Helper for drawPoints() for drawing a single point. */ public void drawPoint(float x, float y, @NonNull Paint paint) { - native_drawPoint(mNativeCanvasWrapper, x, y, paint.mNativePaint); + native_drawPoint(mNativeCanvasWrapper, x, y, paint.getNativeInstance()); } /** @@ -1082,7 +1082,7 @@ public class Canvas { */ public void drawLine(float startX, float startY, float stopX, float stopY, @NonNull Paint paint) { - native_drawLine(mNativeCanvasWrapper, startX, startY, stopX, stopY, paint.mNativePaint); + native_drawLine(mNativeCanvasWrapper, startX, startY, stopX, stopY, paint.getNativeInstance()); } /** @@ -1101,7 +1101,7 @@ public class Canvas { * @param paint The paint used to draw the points */ public void drawLines(float[] pts, int offset, int count, Paint paint) { - native_drawLines(mNativeCanvasWrapper, pts, offset, count, paint.mNativePaint); + native_drawLines(mNativeCanvasWrapper, pts, offset, count, paint.getNativeInstance()); } public void drawLines(@NonNull float[] pts, @NonNull Paint paint) { @@ -1117,7 +1117,7 @@ public class Canvas { */ public void drawRect(@NonNull RectF rect, @NonNull Paint paint) { native_drawRect(mNativeCanvasWrapper, - rect.left, rect.top, rect.right, rect.bottom, paint.mNativePaint); + rect.left, rect.top, rect.right, rect.bottom, paint.getNativeInstance()); } /** @@ -1143,7 +1143,7 @@ public class Canvas { * @param paint The paint used to draw the rect */ public void drawRect(float left, float top, float right, float bottom, @NonNull Paint paint) { - native_drawRect(mNativeCanvasWrapper, left, top, right, bottom, paint.mNativePaint); + native_drawRect(mNativeCanvasWrapper, left, top, right, bottom, paint.getNativeInstance()); } /** @@ -1164,7 +1164,7 @@ public class Canvas { * filled or framed based on the Style in the paint. */ public void drawOval(float left, float top, float right, float bottom, @NonNull Paint paint) { - native_drawOval(mNativeCanvasWrapper, left, top, right, bottom, paint.mNativePaint); + native_drawOval(mNativeCanvasWrapper, left, top, right, bottom, paint.getNativeInstance()); } /** @@ -1178,7 +1178,7 @@ public class Canvas { * @param paint The paint used to draw the circle */ public void drawCircle(float cx, float cy, float radius, @NonNull Paint paint) { - native_drawCircle(mNativeCanvasWrapper, cx, cy, radius, paint.mNativePaint); + native_drawCircle(mNativeCanvasWrapper, cx, cy, radius, paint.getNativeInstance()); } /** @@ -1234,7 +1234,7 @@ public class Canvas { public void drawArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean useCenter, @NonNull Paint paint) { native_drawArc(mNativeCanvasWrapper, left, top, right, bottom, startAngle, sweepAngle, - useCenter, paint.mNativePaint); + useCenter, paint.getNativeInstance()); } /** @@ -1260,7 +1260,7 @@ public class Canvas { */ public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, @NonNull Paint paint) { - native_drawRoundRect(mNativeCanvasWrapper, left, top, right, bottom, rx, ry, paint.mNativePaint); + native_drawRoundRect(mNativeCanvasWrapper, left, top, right, bottom, rx, ry, paint.getNativeInstance()); } /** @@ -1271,7 +1271,7 @@ public class Canvas { * @param paint The paint used to draw the path */ public void drawPath(@NonNull Path path, @NonNull Paint paint) { - native_drawPath(mNativeCanvasWrapper, path.ni(), paint.mNativePaint); + native_drawPath(mNativeCanvasWrapper, path.ni(), paint.getNativeInstance()); } /** @@ -1336,7 +1336,7 @@ public class Canvas { public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) { throwIfCannotDraw(bitmap); native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), left, top, - paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, bitmap.mDensity); + paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity, bitmap.mDensity); } /** @@ -1367,7 +1367,7 @@ public class Canvas { throw new NullPointerException(); } throwIfCannotDraw(bitmap); - final long nativePaint = paint == null ? 0 : paint.mNativePaint; + final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); float left, top, right, bottom; if (src == null) { @@ -1414,7 +1414,7 @@ public class Canvas { throw new NullPointerException(); } throwIfCannotDraw(bitmap); - final long nativePaint = paint == null ? 0 : paint.mNativePaint; + final long nativePaint = paint == null ? 0 : paint.getNativeInstance(); int left, top, right, bottom; if (src == null) { @@ -1482,7 +1482,7 @@ public class Canvas { } // punch down to native for the actual draw native_drawBitmap(mNativeCanvasWrapper, colors, offset, stride, x, y, width, height, hasAlpha, - paint != null ? paint.mNativePaint : 0); + paint != null ? paint.getNativeInstance() : 0); } /** @@ -1510,7 +1510,7 @@ public class Canvas { */ public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) { nativeDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.ni(), matrix.ni(), - paint != null ? paint.mNativePaint : 0); + paint != null ? paint.getNativeInstance() : 0); } /** @@ -1566,7 +1566,7 @@ public class Canvas { } nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.ni(), meshWidth, meshHeight, verts, vertOffset, colors, colorOffset, - paint != null ? paint.mNativePaint : 0); + paint != null ? paint.getNativeInstance() : 0); } public enum VertexMode { @@ -1630,7 +1630,7 @@ public class Canvas { } nativeDrawVertices(mNativeCanvasWrapper, mode.nativeInt, vertexCount, verts, vertOffset, texs, texOffset, colors, colorOffset, - indices, indexOffset, indexCount, paint.mNativePaint); + indices, indexOffset, indexCount, paint.getNativeInstance()); } /** @@ -1649,7 +1649,7 @@ public class Canvas { throw new IndexOutOfBoundsException(); } native_drawText(mNativeCanvasWrapper, text, index, count, x, y, paint.mBidiFlags, - paint.mNativePaint, paint.mNativeTypeface); + paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1663,7 +1663,7 @@ public class Canvas { */ public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint) { native_drawText(mNativeCanvasWrapper, text, 0, text.length(), x, y, paint.mBidiFlags, - paint.mNativePaint, paint.mNativeTypeface); + paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1683,7 +1683,7 @@ public class Canvas { throw new IndexOutOfBoundsException(); } native_drawText(mNativeCanvasWrapper, text, start, end, x, y, paint.mBidiFlags, - paint.mNativePaint, paint.mNativeTypeface); + paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1707,7 +1707,7 @@ public class Canvas { if (text instanceof String || text instanceof SpannedString || text instanceof SpannableString) { native_drawText(mNativeCanvasWrapper, text.toString(), start, end, x, y, - paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); + paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface); } else if (text instanceof GraphicsOperations) { ((GraphicsOperations) text).drawText(this, start, end, x, y, paint); @@ -1715,7 +1715,7 @@ public class Canvas { char[] buf = TemporaryBuffer.obtain(end - start); TextUtils.getChars(text, start, end, buf, 0); native_drawText(mNativeCanvasWrapper, buf, 0, end - start, x, y, - paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); + paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface); TemporaryBuffer.recycle(buf); } } @@ -1754,7 +1754,7 @@ public class Canvas { } native_drawTextRun(mNativeCanvasWrapper, text, index, count, - contextIndex, contextCount, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface); + contextIndex, contextCount, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1790,7 +1790,7 @@ public class Canvas { if (text instanceof String || text instanceof SpannedString || text instanceof SpannableString) { native_drawTextRun(mNativeCanvasWrapper, text.toString(), start, end, - contextStart, contextEnd, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface); + contextStart, contextEnd, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); } else if (text instanceof GraphicsOperations) { ((GraphicsOperations) text).drawTextRun(this, start, end, contextStart, contextEnd, x, y, isRtl, paint); @@ -1800,7 +1800,7 @@ public class Canvas { char[] buf = TemporaryBuffer.obtain(contextLen); TextUtils.getChars(text, contextStart, contextEnd, buf, 0); native_drawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len, - 0, contextLen, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface); + 0, contextLen, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface); TemporaryBuffer.recycle(buf); } } @@ -1868,7 +1868,7 @@ public class Canvas { } native_drawTextOnPath(mNativeCanvasWrapper, text, index, count, path.ni(), hOffset, vOffset, - paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); + paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface); } /** @@ -1888,7 +1888,7 @@ public class Canvas { float vOffset, @NonNull Paint paint) { if (text.length() > 0) { native_drawTextOnPath(mNativeCanvasWrapper, text, path.ni(), hOffset, vOffset, - paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface); + paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface); } } diff --git a/graphics/java/android/graphics/CanvasProperty.java b/graphics/java/android/graphics/CanvasProperty.java index be86060..ea3886c 100644 --- a/graphics/java/android/graphics/CanvasProperty.java +++ b/graphics/java/android/graphics/CanvasProperty.java @@ -31,7 +31,7 @@ public final class CanvasProperty<T> { } public static CanvasProperty<Paint> createPaint(Paint initialValue) { - return new CanvasProperty<Paint>(nCreatePaint(initialValue.mNativePaint)); + return new CanvasProperty<Paint>(nCreatePaint(initialValue.getNativeInstance())); } private CanvasProperty(long nativeContainer) { diff --git a/graphics/java/android/graphics/DrawFilter.java b/graphics/java/android/graphics/DrawFilter.java index ed38f37..aaefce9 100644 --- a/graphics/java/android/graphics/DrawFilter.java +++ b/graphics/java/android/graphics/DrawFilter.java @@ -24,8 +24,11 @@ package android.graphics; */ public class DrawFilter { - // this is set by subclasses, but don't make it public - /* package */ long mNativeInt; // pointer to native object + /** + * this is set by subclasses + * @hide + */ + public long mNativeInt; protected void finalize() throws Throwable { try { diff --git a/graphics/java/android/graphics/LayerRasterizer.java b/graphics/java/android/graphics/LayerRasterizer.java index e7a24a4..b692ecf 100644 --- a/graphics/java/android/graphics/LayerRasterizer.java +++ b/graphics/java/android/graphics/LayerRasterizer.java @@ -28,11 +28,11 @@ public class LayerRasterizer extends Rasterizer { object itself, so it may be reused without danger of side-effects. */ public void addLayer(Paint paint, float dx, float dy) { - nativeAddLayer(native_instance, paint.mNativePaint, dx, dy); + nativeAddLayer(native_instance, paint.getNativeInstance(), dx, dy); } public void addLayer(Paint paint) { - nativeAddLayer(native_instance, paint.mNativePaint, 0, 0); + nativeAddLayer(native_instance, paint.getNativeInstance(), 0, 0); } private static native long nativeConstructor(); diff --git a/graphics/java/android/graphics/Movie.java b/graphics/java/android/graphics/Movie.java index b0a4553..dd5b62d 100644 --- a/graphics/java/android/graphics/Movie.java +++ b/graphics/java/android/graphics/Movie.java @@ -35,12 +35,16 @@ public class Movie { public native boolean isOpaque(); public native int duration(); - public native boolean setTime(int relativeMilliseconds); + public native boolean setTime(int relativeMilliseconds); + + private native void nDraw(Canvas canvas, float x, float y, long paintHandle); + + public void draw(Canvas canvas, float x, float y, Paint paint) { + nDraw(canvas, x, y, paint != null ? paint.getNativeInstance() : 0); + } - public native void draw(Canvas canvas, float x, float y, Paint paint); - public void draw(Canvas canvas, float x, float y) { - draw(canvas, x, y, null); + nDraw(canvas, x, y, 0); } public static Movie decodeStream(InputStream is) { diff --git a/graphics/java/android/graphics/NinePatch.java b/graphics/java/android/graphics/NinePatch.java index 6f42046..ebc86aa 100644 --- a/graphics/java/android/graphics/NinePatch.java +++ b/graphics/java/android/graphics/NinePatch.java @@ -200,12 +200,12 @@ public class NinePatch { void drawSoftware(Canvas canvas, RectF location, Paint paint) { nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.ni(), mNativeChunk, - paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity); + paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity); } void drawSoftware(Canvas canvas, Rect location, Paint paint) { nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap.ni(), mNativeChunk, - paint != null ? paint.mNativePaint : 0, canvas.mDensity, mBitmap.mDensity); + paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity); } /** diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 652fe64..91c8dba 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -29,10 +29,9 @@ import java.util.Locale; */ public class Paint { - /** - * @hide - */ - public long mNativePaint; + private long mNativePaint; + private long mNativeShader = 0; + /** * @hide */ @@ -445,7 +444,7 @@ public class Paint { * new paint. */ public Paint(Paint paint) { - mNativePaint = native_initWithPaint(paint.mNativePaint); + mNativePaint = native_initWithPaint(paint.getNativeInstance()); setClassVariablesFrom(paint); } @@ -464,6 +463,7 @@ public class Paint { mPathEffect = null; mRasterizer = null; mShader = null; + mNativeShader = 0; mTypeface = null; mNativeTypeface = 0; mXfermode = null; @@ -500,11 +500,8 @@ public class Paint { mMaskFilter = paint.mMaskFilter; mPathEffect = paint.mPathEffect; mRasterizer = paint.mRasterizer; - if (paint.mShader != null) { - mShader = paint.mShader.copy(); - } else { - mShader = null; - } + mShader = paint.mShader; + mNativeShader = paint.mNativeShader; mTypeface = paint.mTypeface; mNativeTypeface = paint.mNativeTypeface; mXfermode = paint.mXfermode; @@ -531,6 +528,20 @@ public class Paint { } /** + * Return the pointer to the native object while ensuring that any + * mutable objects that are attached to the paint are also up-to-date. + * + * @hide + */ + public long getNativeInstance() { + if (mShader != null && mShader.getNativeInstance() != mNativeShader) { + mNativeShader = mShader.getNativeInstance(); + native_setShader(mNativePaint, mNativeShader); + } + return mNativePaint; + } + + /** * Return the bidi flags on the paint. * * @return the bidi flags on the paint @@ -920,10 +931,7 @@ public class Paint { * @return shader */ public Shader setShader(Shader shader) { - long shaderNative = 0; - if (shader != null) - shaderNative = shader.getNativeInstance(); - native_setShader(mNativePaint, shaderNative); + // Defer setting the shader natively until getNativeInstance() is called mShader = shader; return shader; } diff --git a/graphics/java/android/graphics/PaintFlagsDrawFilter.java b/graphics/java/android/graphics/PaintFlagsDrawFilter.java index 65a6218..2326611 100644 --- a/graphics/java/android/graphics/PaintFlagsDrawFilter.java +++ b/graphics/java/android/graphics/PaintFlagsDrawFilter.java @@ -17,11 +17,6 @@ package android.graphics; public class PaintFlagsDrawFilter extends DrawFilter { - /** @hide **/ - public final int clearBits; - /** @hide **/ - public final int setBits; - /** * Subclass of DrawFilter that affects every paint by first clearing * the specified clearBits in the paint's flags, and then setting the @@ -31,8 +26,6 @@ public class PaintFlagsDrawFilter extends DrawFilter { * @param setBits These bits will be set in the paint's flags */ public PaintFlagsDrawFilter(int clearBits, int setBits) { - this.clearBits = clearBits; - this.setBits = setBits; // our native constructor can return 0, if the specified bits // are effectively a no-op mNativeInt = nativeConstructor(clearBits, setBits); diff --git a/graphics/java/android/graphics/Shader.java b/graphics/java/android/graphics/Shader.java index 6934955..a96d2cb 100644 --- a/graphics/java/android/graphics/Shader.java +++ b/graphics/java/android/graphics/Shader.java @@ -82,7 +82,8 @@ public class Shader { */ public void setLocalMatrix(Matrix localM) { mLocalMatrix = localM; - nativeSetLocalMatrix(native_instance, localM == null ? 0 : localM.native_instance); + native_instance = nativeSetLocalMatrix(native_instance, + localM == null ? 0 : localM.native_instance); } protected void finalize() throws Throwable { @@ -120,5 +121,5 @@ public class Shader { } private static native void nativeDestructor(long native_shader); - private static native void nativeSetLocalMatrix(long native_shader, long matrix_instance); + private static native long nativeSetLocalMatrix(long native_shader, long matrix_instance); } |