return saveLayer(bounds.left, bounds.top, bounds.right, bounds.bottom, paint, saveFlags);
}
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
return nSaveLayer(mRenderer, nativePaint, saveFlags);
}
public int saveLayer(float left, float top, float right, float bottom, Paint paint,
int saveFlags) {
if (left < right && top < bottom) {
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
return nSaveLayer(mRenderer, left, top, right, bottom, nativePaint, saveFlags);
}
return save(saveFlags);
public void drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, boolean useCenter, Paint paint) {
nDrawArc(mRenderer, left, top, right, bottom,
- startAngle, sweepAngle, useCenter, paint.mNativePaint);
+ startAngle, sweepAngle, useCenter, paint.getNativeInstance());
}
private static native void nDrawArc(long renderer, float left, float top,
public void drawPatch(NinePatch patch, Rect dst, Paint paint) {
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
public void drawPatch(NinePatch patch, RectF dst, Paint paint) {
Bitmap bitmap = patch.getBitmap();
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawPatch(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, patch.mNativeChunk,
dst.left, dst.top, dst.right, dst.bottom, nativePaint);
}
@Override
public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, left, top, nativePaint);
}
@Override
public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawBitmap(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer,
matrix.native_instance, nativePaint);
}
@Override
public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
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) {
@Override
public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
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) {
throw new ArrayIndexOutOfBoundsException();
}
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawBitmap(mRenderer, colors, offset, stride, x, y,
width, height, hasAlpha, nativePaint);
}
checkRange(colors.length, colorOffset, count);
}
- final long nativePaint = paint == null ? 0 : paint.mNativePaint;
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
nDrawBitmapMesh(mRenderer, bitmap.mNativeBitmap, bitmap.mBuffer, meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset, nativePaint);
}
@Override
public void drawCircle(float cx, float cy, float radius, Paint paint) {
- nDrawCircle(mRenderer, cx, cy, radius, paint.mNativePaint);
+ nDrawCircle(mRenderer, cx, cy, radius, paint.getNativeInstance());
}
private static native void nDrawCircle(long renderer, float cx, float cy,
if ((offset | count) < 0 || offset + count > pts.length) {
throw new IllegalArgumentException("The lines array must contain 4 elements per line.");
}
- nDrawLines(mRenderer, pts, offset, count, paint.mNativePaint);
+ nDrawLines(mRenderer, pts, offset, count, paint.getNativeInstance());
}
private static native void nDrawLines(long renderer, float[] points,
@Override
public void drawOval(float left, float top, float right, float bottom, Paint paint) {
- nDrawOval(mRenderer, left, top, right, bottom, paint.mNativePaint);
+ nDrawOval(mRenderer, left, top, right, bottom, paint.getNativeInstance());
}
private static native void nDrawOval(long renderer, float left, float top,
public void drawPath(Path path, Paint paint) {
if (path.isSimplePath) {
if (path.rects != null) {
- nDrawRects(mRenderer, path.rects.mNativeRegion, paint.mNativePaint);
+ nDrawRects(mRenderer, path.rects.mNativeRegion, paint.getNativeInstance());
}
} else {
- nDrawPath(mRenderer, path.mNativePath, paint.mNativePaint);
+ nDrawPath(mRenderer, path.mNativePath, paint.getNativeInstance());
}
}
public void drawPoints(float[] pts, int offset, int count, Paint paint) {
if (count < 2) return;
- nDrawPoints(mRenderer, pts, offset, count, paint.mNativePaint);
+ nDrawPoints(mRenderer, pts, offset, count, paint.getNativeInstance());
}
private static native void nDrawPoints(long renderer, float[] points,
@Override
public void drawRect(float left, float top, float right, float bottom, Paint paint) {
if (left == right || top == bottom) return;
- nDrawRect(mRenderer, left, top, right, bottom, paint.mNativePaint);
+ nDrawRect(mRenderer, left, top, right, bottom, paint.getNativeInstance());
}
private static native void nDrawRect(long renderer, float left, float top,
@Override
public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
Paint paint) {
- nDrawRoundRect(mRenderer, left, top, right, bottom, rx, ry, paint.mNativePaint);
+ nDrawRoundRect(mRenderer, left, top, right, bottom, rx, ry, paint.getNativeInstance());
}
private static native void nDrawRoundRect(long renderer, float left, float top,
}
nDrawText(mRenderer, text, index, count, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
private static native void nDrawText(long renderer, char[] text, int index, int count,
if (text instanceof String || text instanceof SpannedString ||
text instanceof SpannableString) {
nDrawText(mRenderer, text.toString(), start, end, x, y, paint.mBidiFlags,
- paint.mNativePaint, paint.mNativeTypeface);
+ paint.getNativeInstance(), paint.mNativeTypeface);
} else if (text instanceof GraphicsOperations) {
((GraphicsOperations) text).drawText(this, start, end, x, y, paint);
} else {
char[] buf = TemporaryBuffer.obtain(end - start);
TextUtils.getChars(text, start, end, buf, 0);
nDrawText(mRenderer, buf, 0, end - start, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
TemporaryBuffer.recycle(buf);
}
}
}
nDrawText(mRenderer, text, start, end, x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
private static native void nDrawText(long renderer, String text, int start, int end,
@Override
public void drawText(String text, float x, float y, Paint paint) {
nDrawText(mRenderer, text, 0, text.length(), x, y,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
@Override
}
nDrawTextOnPath(mRenderer, text, index, count, path.mNativePath, hOffset, vOffset,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
private static native void nDrawTextOnPath(long renderer, char[] text, int index, int count,
if (text.length() == 0) return;
nDrawTextOnPath(mRenderer, text, 0, text.length(), path.mNativePath, hOffset, vOffset,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
private static native void nDrawTextOnPath(long renderer, String text, int start, int end,
}
nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, isRtl,
- paint.mNativePaint, paint.mNativeTypeface);
+ paint.getNativeInstance(), paint.mNativeTypeface);
}
private static native void nDrawTextRun(long renderer, char[] text, int index, int count,
if (text instanceof String || text instanceof SpannedString ||
text instanceof SpannableString) {
nDrawTextRun(mRenderer, text.toString(), start, end, contextStart,
- contextEnd, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
+ 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);
char[] buf = TemporaryBuffer.obtain(contextLen);
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen,
- x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
+ x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface);
TemporaryBuffer.recycle(buf);
}
}
* @see View#setLayerPaint(android.graphics.Paint)
*/
public void setLayerPaint(Paint paint) {
- nSetLayerPaint(mFinalizer.get(), paint.mNativePaint);
+ nSetLayerPaint(mFinalizer.get(), paint.getNativeInstance());
mRenderer.pushLayerUpdate(this);
}
}
public boolean setLayerPaint(Paint paint) {
- return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.mNativePaint : 0);
+ return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
}
public boolean setClipBounds(@Nullable Rect rect) {
SkSafeUnref(shader);
}
-static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, jlong matrixHandle)
+static jlong Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, jlong matrixHandle)
{
- SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle);
+ // ensure we have a valid matrix to use
const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
- if (shader) {
- if (matrix) {
- shader->setLocalMatrix(*matrix);
- } else {
- shader->resetLocalMatrix();
+ if (NULL == matrix) {
+ matrix = &SkMatrix::I();
+ }
+
+ // The current shader will no longer need a direct reference owned by Shader.java
+ // as all the data needed is contained within the newly created LocalMatrixShader.
+ SkASSERT(shaderHandle);
+ SkAutoTUnref<SkShader> currentShader(reinterpret_cast<SkShader*>(shaderHandle));
+
+ SkMatrix currentMatrix;
+ SkAutoTUnref<SkShader> baseShader(currentShader->refAsALocalMatrixShader(¤tMatrix));
+ if (baseShader.get()) {
+ // if the matrices are same then there is no need to allocate a new
+ // shader that is identical to the existing one.
+ if (currentMatrix == *matrix) {
+ return reinterpret_cast<jlong>(currentShader.detach());
}
+ return reinterpret_cast<jlong>(SkShader::CreateLocalMatrixShader(baseShader, *matrix));
}
+
+ return reinterpret_cast<jlong>(SkShader::CreateLocalMatrixShader(currentShader, *matrix));
}
///////////////////////////////////////////////////////////////////////////////////////////////
static JNINativeMethod gShaderMethods[] = {
{ "nativeDestructor", "(J)V", (void*)Shader_destructor },
- { "nativeSetLocalMatrix", "(JJ)V", (void*)Shader_setLocalMatrix }
+ { "nativeSetLocalMatrix", "(JJ)J", (void*)Shader_setLocalMatrix }
};
static JNINativeMethod gBitmapShaderMethods[] = {
*/
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");
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);
}
* @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());
}
/**
* @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());
}
/**
* 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());
}
/**
*/
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());
}
/**
* @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) {
*/
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());
}
/**
* @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());
}
/**
* 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());
}
/**
* @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());
}
/**
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());
}
/**
*/
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());
}
/**
* @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());
}
/**
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);
}
/**
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) {
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) {
}
// 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);
}
/**
*/
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);
}
/**
}
nativeDrawBitmapMesh(mNativeCanvasWrapper, bitmap.ni(), meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset,
- paint != null ? paint.mNativePaint : 0);
+ paint != null ? paint.getNativeInstance() : 0);
}
public enum VertexMode {
}
nativeDrawVertices(mNativeCanvasWrapper, mode.nativeInt, vertexCount, verts,
vertOffset, texs, texOffset, colors, colorOffset,
- indices, indexOffset, indexCount, paint.mNativePaint);
+ indices, indexOffset, indexCount, paint.getNativeInstance());
}
/**
throw new IndexOutOfBoundsException();
}
native_drawText(mNativeCanvasWrapper, text, index, count, x, y, paint.mBidiFlags,
- paint.mNativePaint, paint.mNativeTypeface);
+ paint.getNativeInstance(), paint.mNativeTypeface);
}
/**
*/
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);
}
/**
throw new IndexOutOfBoundsException();
}
native_drawText(mNativeCanvasWrapper, text, start, end, x, y, paint.mBidiFlags,
- paint.mNativePaint, paint.mNativeTypeface);
+ paint.getNativeInstance(), paint.mNativeTypeface);
}
/**
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);
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);
}
}
}
native_drawTextRun(mNativeCanvasWrapper, text, index, count,
- contextIndex, contextCount, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
+ contextIndex, contextCount, x, y, isRtl, paint.getNativeInstance(), paint.mNativeTypeface);
}
/**
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);
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);
}
}
}
native_drawTextOnPath(mNativeCanvasWrapper, text, index, count,
path.ni(), hOffset, vOffset,
- paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
+ paint.mBidiFlags, paint.getNativeInstance(), paint.mNativeTypeface);
}
/**
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);
}
}
}
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) {
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();
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.mNativePaint : 0);
+ nDraw(canvas, x, y, paint != null ? paint.getNativeInstance() : 0);
}
public void draw(Canvas canvas, float x, float y) {
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);
}
/**
*/
public class Paint {
- /**
- * @hide
- */
- public long mNativePaint;
+ private long mNativePaint;
+ private long mNativeShader = 0;
+
/**
* @hide
*/
* new paint.
*/
public Paint(Paint paint) {
- mNativePaint = native_initWithPaint(paint.mNativePaint);
+ mNativePaint = native_initWithPaint(paint.getNativeInstance());
setClassVariablesFrom(paint);
}
mPathEffect = null;
mRasterizer = null;
mShader = null;
+ mNativeShader = 0;
mTypeface = null;
mNativeTypeface = 0;
mXfermode = null;
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;
}
/**
+ * 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) {
+ native_setShader(mNativePaint, mShader.getNativeInstance());
+ }
+ return mNativePaint;
+ }
+
+ /**
* Return the bidi flags on the paint.
*
* @return the bidi flags on the paint
* @return shader
*/
public Shader setShader(Shader shader) {
- long shaderNative = 0;
- if (shader != null)
- shaderNative = shader.getNativeInstance();
- native_setShader(mNativePaint, shaderNative);
+ if (shader != null) {
+ mNativeShader = shader.getNativeInstance();
+ } else {
+ mNativeShader = 0;
+ }
+ native_setShader(mNativePaint, mNativeShader);
mShader = shader;
return 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 {
}
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);
}