OSDN Git Service

Add floats-only drawRoundRect to Canvas
authorChris Craik <ccraik@google.com>
Thu, 24 Apr 2014 21:13:40 +0000 (14:13 -0700)
committerChris Craik <ccraik@google.com>
Thu, 24 Apr 2014 21:23:52 +0000 (14:23 -0700)
Change-Id: Ib0033a2d2486a808a44984ec4adf7fef76d9ea17

api/current.txt
core/java/android/view/GLES20Canvas.java
core/jni/android/graphics/Canvas.cpp
graphics/java/android/graphics/Canvas.java

index ef6aed7..de47e62 100644 (file)
@@ -9709,6 +9709,7 @@ package android.graphics {
     method public void drawRect(android.graphics.Rect, android.graphics.Paint);
     method public void drawRect(float, float, float, float, android.graphics.Paint);
     method public void drawRoundRect(android.graphics.RectF, float, float, android.graphics.Paint);
+    method public void drawRoundRect(float, float, float, float, float, float, android.graphics.Paint);
     method public void drawText(char[], int, int, float, float, android.graphics.Paint);
     method public void drawText(java.lang.String, float, float, android.graphics.Paint);
     method public void drawText(java.lang.String, int, int, float, float, android.graphics.Paint);
index f0d8a61..34b85d9 100644 (file)
@@ -1117,11 +1117,11 @@ class GLES20Canvas extends HardwareCanvas {
     }
 
     @Override
-    public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
+    public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
+            Paint paint) {
         int modifiers = setupModifiers(paint, MODIFIER_SHADER);
         try {
-            nDrawRoundRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
-                    rx, ry, paint.mNativePaint);
+            nDrawRoundRect(mRenderer, left, top, right, bottom, rx, ry, paint.mNativePaint);
         } finally {
             if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
         }
index 5148266..2adbf3a 100644 (file)
@@ -509,12 +509,11 @@ public:
     }
 
     static void drawRoundRect(JNIEnv* env, jobject, jlong canvasHandle,
-                              jobject jrect, jfloat rx, jfloat ry,
-                              jlong paintHandle) {
+            jfloat left, jfloat top, jfloat right, jfloat bottom, jfloat rx, jfloat ry,
+            jlong paintHandle) {
         SkCanvas* canvas = reinterpret_cast<SkCanvas*>(canvasHandle);
         SkPaint* paint = reinterpret_cast<SkPaint*>(paintHandle);
-        SkRect rect;
-        GraphicsJNI::jrectf_to_rect(env, jrect, &rect);
+        SkRect rect = SkRect::MakeLTRB(left, top, right, bottom);
         canvas->drawRoundRect(rect, rx, ry, *paint);
     }
 
@@ -1176,7 +1175,7 @@ static JNINativeMethod gCanvasMethods[] = {
     {"native_drawCircle","(JFFFJ)V", (void*) SkCanvasGlue::drawCircle},
     {"native_drawArc","(JLandroid/graphics/RectF;FFZJ)V",
         (void*) SkCanvasGlue::drawArc},
-    {"native_drawRoundRect","(JLandroid/graphics/RectF;FFJ)V",
+    {"native_drawRoundRect","(JFFFFFFJ)V",
         (void*) SkCanvasGlue::drawRoundRect},
     {"native_drawPath","(JJJ)V", (void*) SkCanvasGlue::drawPath},
     {"native_drawBitmap","(JJFFJIII)V",
index f80ce28..ae3eae1 100644 (file)
@@ -1075,11 +1075,20 @@ public class Canvas {
      * @param paint The paint used to draw the roundRect
      */
     public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
-        if (rect == null) {
-            throw new NullPointerException();
-        }
-        native_drawRoundRect(mNativeCanvas, rect, rx, ry,
-                             paint.mNativePaint);
+        drawRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, paint);
+    }
+
+    /**
+     * Draw the specified round-rect using the specified paint. The roundrect
+     * will be filled or framed based on the Style in the paint.
+     *
+     * @param rx    The x-radius of the oval used to round the corners
+     * @param ry    The y-radius of the oval used to round the corners
+     * @param paint The paint used to draw the roundRect
+     */
+    public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry,
+            Paint paint) {
+        native_drawRoundRect(mNativeCanvas, left, top, right, bottom, rx, ry, paint.mNativePaint);
     }
 
     /**
@@ -1816,8 +1825,8 @@ public class Canvas {
                                               boolean useCenter,
                                               long nativePaint);
     private static native void native_drawRoundRect(long nativeCanvas,
-                                                    RectF rect, float rx,
-                                                    float ry, long nativePaint);
+            float left, float top, float right, float bottom,
+            float rx, float ry, long nativePaint);
     private static native void native_drawPath(long nativeCanvas,
                                                long nativePath,
                                                long nativePaint);