summaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Canvas.java6
-rw-r--r--graphics/java/android/graphics/drawable/GradientDrawable.java7
-rw-r--r--graphics/java/android/graphics/pdf/PdfEditor.java65
-rw-r--r--graphics/java/android/graphics/pdf/PdfRenderer.java49
4 files changed, 101 insertions, 26 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index cb6c92e87172..ddc380e6d293 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -555,6 +555,7 @@ public class Canvas {
* @param dy The distance to translate in Y
*/
public void translate(float dx, float dy) {
+ if (dx == 0.0f && dy == 0.0f) return;
native_translate(mNativeCanvasWrapper, dx, dy);
}
@@ -565,6 +566,7 @@ public class Canvas {
* @param sy The amount to scale in Y
*/
public void scale(float sx, float sy) {
+ if (sx == 1.0f && sy == 1.0f) return;
native_scale(mNativeCanvasWrapper, sx, sy);
}
@@ -577,6 +579,7 @@ public class Canvas {
* @param py The y-coord for the pivot point (unchanged by the scale)
*/
public final void scale(float sx, float sy, float px, float py) {
+ if (sx == 1.0f && sy == 1.0f) return;
translate(px, py);
scale(sx, sy);
translate(-px, -py);
@@ -588,6 +591,7 @@ public class Canvas {
* @param degrees The amount to rotate, in degrees
*/
public void rotate(float degrees) {
+ if (degrees == 0.0f) return;
native_rotate(mNativeCanvasWrapper, degrees);
}
@@ -599,6 +603,7 @@ public class Canvas {
* @param py The y-coord for the pivot point (unchanged by the rotation)
*/
public final void rotate(float degrees, float px, float py) {
+ if (degrees == 0.0f) return;
translate(px, py);
rotate(degrees);
translate(-px, -py);
@@ -611,6 +616,7 @@ public class Canvas {
* @param sy The amount to skew in Y
*/
public void skew(float sx, float sy) {
+ if (sx == 0.0f && sy == 0.0f) return;
native_skew(mNativeCanvasWrapper, sx, sy);
}
diff --git a/graphics/java/android/graphics/drawable/GradientDrawable.java b/graphics/java/android/graphics/drawable/GradientDrawable.java
index 3dbd2a96b00a..7ea466e00052 100644
--- a/graphics/java/android/graphics/drawable/GradientDrawable.java
+++ b/graphics/java/android/graphics/drawable/GradientDrawable.java
@@ -282,10 +282,11 @@ public class GradientDrawable extends Drawable {
}
/**
- * Returns the radius for the corners of the gradient.
+ * Returns the radius for the corners of the gradient, that was previously set with
+ * {@link #setCornerRadius(float)}.
* <p>
- * If the radius was previously set with {@link #setCornerRadii(float[])},
- * or if the corners are not rounded, this method will return {@code null}.
+ * If the radius was previously cleared via passing {@code null}
+ * to {@link #setCornerRadii(float[])}, this method will return 0.
*
* @return the radius in pixels of the corners of the rectangle shape, or 0
* @see #setCornerRadius
diff --git a/graphics/java/android/graphics/pdf/PdfEditor.java b/graphics/java/android/graphics/pdf/PdfEditor.java
index 2b70b6a45f82..cd1f8de6ee0f 100644
--- a/graphics/java/android/graphics/pdf/PdfEditor.java
+++ b/graphics/java/android/graphics/pdf/PdfEditor.java
@@ -79,8 +79,12 @@ public final class PdfEditor {
}
mInput = input;
- mNativeDocument = nativeOpen(mInput.getFd(), size);
- mPageCount = nativeGetPageCount(mNativeDocument);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ mNativeDocument = nativeOpen(mInput.getFd(), size);
+ mPageCount = nativeGetPageCount(mNativeDocument);
+ }
+
mCloseGuard.open("close");
}
@@ -102,7 +106,10 @@ public final class PdfEditor {
public void removePage(int pageIndex) {
throwIfClosed();
throwIfPageNotInDocument(pageIndex);
- mPageCount = nativeRemovePage(mNativeDocument, pageIndex);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ mPageCount = nativeRemovePage(mNativeDocument, pageIndex);
+ }
}
/**
@@ -125,11 +132,16 @@ public final class PdfEditor {
if (clip == null) {
Point size = new Point();
getPageSize(pageIndex, size);
- nativeSetTransformAndClip(mNativeDocument, pageIndex, transform.native_instance,
- 0, 0, size.x, size.y);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeSetTransformAndClip(mNativeDocument, pageIndex, transform.native_instance,
+ 0, 0, size.x, size.y);
+ }
} else {
- nativeSetTransformAndClip(mNativeDocument, pageIndex, transform.native_instance,
- clip.left, clip.top, clip.right, clip.bottom);
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeSetTransformAndClip(mNativeDocument, pageIndex, transform.native_instance,
+ clip.left, clip.top, clip.right, clip.bottom);
+ }
}
}
@@ -143,7 +155,10 @@ public final class PdfEditor {
throwIfClosed();
throwIfOutSizeNull(outSize);
throwIfPageNotInDocument(pageIndex);
- nativeGetPageSize(mNativeDocument, pageIndex, outSize);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeGetPageSize(mNativeDocument, pageIndex, outSize);
+ }
}
/**
@@ -156,7 +171,10 @@ public final class PdfEditor {
throwIfClosed();
throwIfOutMediaBoxNull(outMediaBox);
throwIfPageNotInDocument(pageIndex);
- return nativeGetPageMediaBox(mNativeDocument, pageIndex, outMediaBox);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ return nativeGetPageMediaBox(mNativeDocument, pageIndex, outMediaBox);
+ }
}
/**
@@ -169,7 +187,10 @@ public final class PdfEditor {
throwIfClosed();
throwIfMediaBoxNull(mediaBox);
throwIfPageNotInDocument(pageIndex);
- nativeSetPageMediaBox(mNativeDocument, pageIndex, mediaBox);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeSetPageMediaBox(mNativeDocument, pageIndex, mediaBox);
+ }
}
/**
@@ -182,7 +203,10 @@ public final class PdfEditor {
throwIfClosed();
throwIfOutCropBoxNull(outCropBox);
throwIfPageNotInDocument(pageIndex);
- return nativeGetPageCropBox(mNativeDocument, pageIndex, outCropBox);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ return nativeGetPageCropBox(mNativeDocument, pageIndex, outCropBox);
+ }
}
/**
@@ -195,7 +219,10 @@ public final class PdfEditor {
throwIfClosed();
throwIfCropBoxNull(cropBox);
throwIfPageNotInDocument(pageIndex);
- nativeSetPageCropBox(mNativeDocument, pageIndex, cropBox);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeSetPageCropBox(mNativeDocument, pageIndex, cropBox);
+ }
}
/**
@@ -205,7 +232,10 @@ public final class PdfEditor {
*/
public boolean shouldScaleForPrinting() {
throwIfClosed();
- return nativeScaleForPrinting(mNativeDocument);
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ return nativeScaleForPrinting(mNativeDocument);
+ }
}
/**
@@ -219,7 +249,10 @@ public final class PdfEditor {
public void write(ParcelFileDescriptor output) throws IOException {
try {
throwIfClosed();
- nativeWrite(mNativeDocument, output.getFd());
+
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeWrite(mNativeDocument, output.getFd());
+ }
} finally {
IoUtils.closeQuietly(output);
}
@@ -247,7 +280,9 @@ public final class PdfEditor {
}
private void doClose() {
- nativeClose(mNativeDocument);
+ synchronized (PdfRenderer.sPdfiumLock) {
+ nativeClose(mNativeDocument);
+ }
IoUtils.closeQuietly(mInput);
mInput = null;
mCloseGuard.close();
diff --git a/graphics/java/android/graphics/pdf/PdfRenderer.java b/graphics/java/android/graphics/pdf/PdfRenderer.java
index 520ebe5f2db8..99a042261c4d 100644
--- a/graphics/java/android/graphics/pdf/PdfRenderer.java
+++ b/graphics/java/android/graphics/pdf/PdfRenderer.java
@@ -27,6 +27,7 @@ import android.graphics.Rect;
import android.os.ParcelFileDescriptor;
import android.system.ErrnoException;
import android.system.OsConstants;
+import com.android.internal.util.Preconditions;
import dalvik.system.CloseGuard;
import libcore.io.Libcore;
@@ -99,6 +100,12 @@ import java.lang.annotation.RetentionPolicy;
* @see #close()
*/
public final class PdfRenderer implements AutoCloseable {
+ /**
+ * Any call the native pdfium code has to be single threaded as the library does not support
+ * parallel use.
+ */
+ final static Object sPdfiumLock = new Object();
+
private final CloseGuard mCloseGuard = CloseGuard.get();
private final Point mTempPoint = new Point();
@@ -154,8 +161,17 @@ public final class PdfRenderer implements AutoCloseable {
}
mInput = input;
- mNativeDocument = nativeCreate(mInput.getFd(), size);
- mPageCount = nativeGetPageCount(mNativeDocument);
+
+ synchronized (sPdfiumLock) {
+ mNativeDocument = nativeCreate(mInput.getFd(), size);
+ try {
+ mPageCount = nativeGetPageCount(mNativeDocument);
+ } catch (Throwable t) {
+ nativeClose(mNativeDocument);
+ throw t;
+ }
+ }
+
mCloseGuard.open("close");
}
@@ -189,7 +205,10 @@ public final class PdfRenderer implements AutoCloseable {
*/
public boolean shouldScaleForPrinting() {
throwIfClosed();
- return nativeScaleForPrinting(mNativeDocument);
+
+ synchronized (sPdfiumLock) {
+ return nativeScaleForPrinting(mNativeDocument);
+ }
}
/**
@@ -224,7 +243,9 @@ public final class PdfRenderer implements AutoCloseable {
if (mCurrentPage != null) {
mCurrentPage.close();
}
- nativeClose(mNativeDocument);
+ synchronized (sPdfiumLock) {
+ nativeClose(mNativeDocument);
+ }
try {
mInput.close();
} catch (IOException ioe) {
@@ -277,7 +298,9 @@ public final class PdfRenderer implements AutoCloseable {
private Page(int index) {
Point size = mTempPoint;
- mNativePage = nativeOpenPageAndGetSize(mNativeDocument, index, size);
+ synchronized (sPdfiumLock) {
+ mNativePage = nativeOpenPageAndGetSize(mNativeDocument, index, size);
+ }
mIndex = index;
mWidth = size.x;
mHeight = size.y;
@@ -351,6 +374,12 @@ public final class PdfRenderer implements AutoCloseable {
*/
public void render(@NonNull Bitmap destination, @Nullable Rect destClip,
@Nullable Matrix transform, @RenderMode int renderMode) {
+ if (mNativePage == 0) {
+ throw new NullPointerException();
+ }
+
+ destination = Preconditions.checkNotNull(destination, "bitmap null");
+
if (destination.getConfig() != Config.ARGB_8888) {
throw new IllegalArgumentException("Unsupported pixel format");
}
@@ -384,8 +413,10 @@ public final class PdfRenderer implements AutoCloseable {
final long transformPtr = (transform != null) ? transform.native_instance : 0;
- nativeRenderPage(mNativeDocument, mNativePage, destination, contentLeft,
- contentTop, contentRight, contentBottom, transformPtr, renderMode);
+ synchronized (sPdfiumLock) {
+ nativeRenderPage(mNativeDocument, mNativePage, destination, contentLeft,
+ contentTop, contentRight, contentBottom, transformPtr, renderMode);
+ }
}
/**
@@ -412,7 +443,9 @@ public final class PdfRenderer implements AutoCloseable {
}
private void doClose() {
- nativeClosePage(mNativePage);
+ synchronized (sPdfiumLock) {
+ nativeClosePage(mNativePage);
+ }
mNativePage = 0;
mCloseGuard.close();
mCurrentPage = null;