diff options
author | Deepanshu Gupta <deepanshu@google.com> | 2014-06-25 17:35:38 -0700 |
---|---|---|
committer | Deepanshu Gupta <deepanshu@google.com> | 2014-07-01 12:22:14 -0700 |
commit | 509d860907691a8eb7ff4c8b949fbee36db70fea (patch) | |
tree | 6f51783d2915a8db702779787331653dfcb5c246 /tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java | |
parent | bb5d0cc4369590ce892cca2f717f5d5568c5f655 (diff) | |
download | frameworks_base-509d860907691a8eb7ff4c8b949fbee36db70fea.zip frameworks_base-509d860907691a8eb7ff4c8b949fbee36db70fea.tar.gz frameworks_base-509d860907691a8eb7ff4c8b949fbee36db70fea.tar.bz2 |
Sort delegates in Canvas_Delegate
The order of the methods match the order of the declaration in the
Canvas file. This makes searching for the methods easier.
Change-Id: I230621d3999024cb2ff42a1aacd60908c7f0b161
Diffstat (limited to 'tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java')
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java | 283 |
1 files changed, 140 insertions, 143 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java index 28eaf85..12e4a85 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java @@ -55,16 +55,19 @@ public final class Canvas_Delegate { private static final DelegateManager<Canvas_Delegate> sManager = new DelegateManager<Canvas_Delegate>(Canvas_Delegate.class); + // ---- delegate helper data ---- private final static boolean[] sBoolOut = new boolean[1]; + // ---- delegate data ---- private Bitmap_Delegate mBitmap; private GcSnapshot mSnapshot; private DrawFilter_Delegate mDrawFilter = null; + // ---- Public Helper methods ---- /** @@ -100,6 +103,60 @@ public final class Canvas_Delegate { // ---- native methods ---- @LayoutlibDelegate + /*package*/ static void freeCaches() { + // nothing to be done here. + } + + @LayoutlibDelegate + /*package*/ static void freeTextLayoutCaches() { + // nothing to be done here yet. + } + + @LayoutlibDelegate + /*package*/ static long initRaster(long nativeBitmapOrZero) { + if (nativeBitmapOrZero > 0) { + // get the Bitmap from the int + Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero); + + // create a new Canvas_Delegate with the given bitmap and return its new native int. + Canvas_Delegate newDelegate = new Canvas_Delegate(bitmapDelegate); + + return sManager.addNewDelegate(newDelegate); + } + + // create a new Canvas_Delegate and return its new native int. + Canvas_Delegate newDelegate = new Canvas_Delegate(); + + return sManager.addNewDelegate(newDelegate); + } + + @LayoutlibDelegate + /*package*/ static long initCanvas(long nativeCanvas) { + // get the delegate from the native int. + Canvas_Delegate nativeCanvasDelegate = sManager.getDelegate(nativeCanvas); + if (nativeCanvasDelegate == null) { + return 0; + } + + Canvas_Delegate newDelegate = new Canvas_Delegate(); + + // TODO: actually copy the canvas state. + return sManager.addNewDelegate(newDelegate); + } + + @LayoutlibDelegate + /*package*/ + static void native_setBitmap(long canvas, long bitmap, boolean copyState) { + Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas); + Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); + if (canvasDelegate == null || bitmapDelegate==null) { + return; + } + canvasDelegate.mBitmap = bitmapDelegate; + canvasDelegate.mSnapshot = GcSnapshot.createDefaultSnapshot(bitmapDelegate); + } + + @LayoutlibDelegate /*package*/ static boolean native_isOpaque(long nativeCanvas) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); @@ -133,82 +190,68 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_translate(long nativeCanvas, float dx, float dy) { + /*package*/ static int native_save(long nativeCanvas, int saveFlags) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - return; + return 0; } - canvasDelegate.getSnapshot().translate(dx, dy); + return canvasDelegate.save(saveFlags); } @LayoutlibDelegate - /*package*/ static void native_rotate(long nativeCanvas, float degrees) { + /*package*/ static int native_saveLayer(long nativeCanvas, float l, + float t, float r, float b, + long paint, int layerFlags) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - return; + return 0; } - canvasDelegate.getSnapshot().rotate(Math.toRadians(degrees)); - } - - @LayoutlibDelegate - /*package*/ static void native_scale(long nativeCanvas, float sx, float sy) { - // get the delegate from the native int. - Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); - if (canvasDelegate == null) { - return; + Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint); + if (paintDelegate == null) { + return 0; } - canvasDelegate.getSnapshot().scale(sx, sy); + return canvasDelegate.saveLayer(new RectF(l, t, r, b), + paintDelegate, layerFlags); } @LayoutlibDelegate - /*package*/ static void native_skew(long nativeCanvas, float kx, float ky) { + /*package*/ static int native_saveLayerAlpha(long nativeCanvas, float l, + float t, float r, float b, + int alpha, int layerFlags) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - return; + return 0; } - // get the current top graphics2D object. - GcSnapshot g = canvasDelegate.getSnapshot(); - - // get its current matrix - AffineTransform currentTx = g.getTransform(); - // get the AffineTransform for the given skew. - float[] mtx = Matrix_Delegate.getSkew(kx, ky); - AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(mtx); - - // combine them so that the given matrix is applied after. - currentTx.preConcatenate(matrixTx); - - // give it to the graphics2D as a new matrix replacing all previous transform - g.setTransform(currentTx); + return canvasDelegate.saveLayerAlpha(new RectF(l, t, r, b), alpha, layerFlags); } @LayoutlibDelegate - /*package*/ static int native_save(long nativeCanvas, int saveFlags) { + /*package*/ static void native_restore(long nativeCanvas) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - return 0; + return; } - return canvasDelegate.save(saveFlags); + canvasDelegate.restore(); } @LayoutlibDelegate - /*package*/ static void native_restore(long nativeCanvas) { + /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { return; } - canvasDelegate.restore(); + canvasDelegate.restoreTo(saveCount); } @LayoutlibDelegate @@ -223,136 +266,62 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_restoreToCount(long nativeCanvas, int saveCount) { + /*package*/ static void native_translate(long nativeCanvas, float dx, float dy) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { return; } - canvasDelegate.restoreTo(saveCount); - } - - @LayoutlibDelegate - /*package*/ static void native_drawPoints(long nativeCanvas, float[] pts, int offset, int count, - long nativePaint) { - // FIXME - Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, - "Canvas.drawPoint is not supported.", null, null /*data*/); - } - - @LayoutlibDelegate - /*package*/ static void native_drawPoint(long nativeCanvas, float x, float y, - long nativePaint) { - // FIXME - Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, - "Canvas.drawPoint is not supported.", null, null /*data*/); - } - - @LayoutlibDelegate - /*package*/ static void native_drawLines(long nativeCanvas, - final float[] pts, final int offset, final int count, - long nativePaint) { - - draw(nativeCanvas, nativePaint, false /*compositeOnly*/, - false /*forceSrcMode*/, new GcSnapshot.Drawable() { - @Override - public void draw(Graphics2D graphics, Paint_Delegate paintDelegate) { - for (int i = 0; i < count; i += 4) { - graphics.drawLine((int) pts[i + offset], (int) pts[i + offset + 1], - (int) pts[i + offset + 2], (int) pts[i + offset + 3]); - } - } - }); - } - - @LayoutlibDelegate - /*package*/ static void freeCaches() { - // nothing to be done here. - } - - @LayoutlibDelegate - /*package*/ static void freeTextLayoutCaches() { - // nothing to be done here yet. + canvasDelegate.getSnapshot().translate(dx, dy); } @LayoutlibDelegate - /*package*/ static long initRaster(long nativeBitmapOrZero) { - if (nativeBitmapOrZero > 0) { - // get the Bitmap from the int - Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nativeBitmapOrZero); - - // create a new Canvas_Delegate with the given bitmap and return its new native int. - Canvas_Delegate newDelegate = new Canvas_Delegate(bitmapDelegate); + /*package*/ static void native_scale(long nativeCanvas, float sx, float sy) { + // get the delegate from the native int. + Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); + if (canvasDelegate == null) { + return; + } - return sManager.addNewDelegate(newDelegate); + canvasDelegate.getSnapshot().scale(sx, sy); } - // create a new Canvas_Delegate and return its new native int. - Canvas_Delegate newDelegate = new Canvas_Delegate(); - - return sManager.addNewDelegate(newDelegate); - } - @LayoutlibDelegate - /*package*/ static long initCanvas(long nativeCanvas) { + /*package*/ static void native_rotate(long nativeCanvas, float degrees) { // get the delegate from the native int. - Canvas_Delegate nativeCanvasDelegate = sManager.getDelegate(nativeCanvas); - if (nativeCanvasDelegate == null) { - return 0; - } - - Canvas_Delegate newDelegate = new Canvas_Delegate(); - - // TODO: actually copy the canvas state. - return sManager.addNewDelegate(newDelegate); - } - - @LayoutlibDelegate - /*package*/ - static void native_setBitmap(long canvas, long bitmap, boolean copyState) { - Canvas_Delegate canvasDelegate = sManager.getDelegate(canvas); - Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); - if (canvasDelegate == null || bitmapDelegate==null) { + Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); + if (canvasDelegate == null) { return; } - canvasDelegate.mBitmap = bitmapDelegate; - canvasDelegate.mSnapshot = GcSnapshot.createDefaultSnapshot(bitmapDelegate); + + canvasDelegate.getSnapshot().rotate(Math.toRadians(degrees)); } @LayoutlibDelegate - /*package*/ static int native_saveLayer(long nativeCanvas, float l, - float t, float r, float b, - long paint, int layerFlags) { + /*package*/ static void native_skew(long nativeCanvas, float kx, float ky) { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - return 0; + return; } - Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint); - if (paintDelegate == null) { - return 0; - } + // get the current top graphics2D object. + GcSnapshot g = canvasDelegate.getSnapshot(); - return canvasDelegate.saveLayer(new RectF(l, t, r, b), - paintDelegate, layerFlags); - } + // get its current matrix + AffineTransform currentTx = g.getTransform(); + // get the AffineTransform for the given skew. + float[] mtx = Matrix_Delegate.getSkew(kx, ky); + AffineTransform matrixTx = Matrix_Delegate.getAffineTransform(mtx); - @LayoutlibDelegate - /*package*/ static int native_saveLayerAlpha(long nativeCanvas, float l, - float t, float r, float b, - int alpha, int layerFlags) { - // get the delegate from the native int. - Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); - if (canvasDelegate == null) { - return 0; - } + // combine them so that the given matrix is applied after. + currentTx.preConcatenate(matrixTx); - return canvasDelegate.saveLayerAlpha(new RectF(l, t, r, b), alpha, layerFlags); + // give it to the graphics2D as a new matrix replacing all previous transform + g.setTransform(currentTx); } - @LayoutlibDelegate /*package*/ static void native_concat(long nCanvas, long nMatrix) { // get the delegate from the native int. @@ -416,7 +385,6 @@ public final class Canvas_Delegate { float left, float top, float right, float bottom, int regionOp) { - // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { @@ -515,8 +483,7 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static boolean native_quickReject(long nativeCanvas, - long path) { + /*package*/ static boolean native_quickReject(long nativeCanvas, long path) { // FIXME properly implement quickReject return false; } @@ -585,10 +552,25 @@ public final class Canvas_Delegate { } @LayoutlibDelegate + /*package*/ static void native_drawPoint(long nativeCanvas, float x, float y, + long nativePaint) { + // FIXME + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPoint is not supported.", null, null /*data*/); + } + + @LayoutlibDelegate + /*package*/ static void native_drawPoints(long nativeCanvas, float[] pts, int offset, int count, + long nativePaint) { + // FIXME + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPoint is not supported.", null, null /*data*/); + } + + @LayoutlibDelegate /*package*/ static void native_drawLine(long nativeCanvas, final float startX, final float startY, final float stopX, final float stopY, long paint) { - draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/, new GcSnapshot.Drawable() { @Override @@ -599,6 +581,22 @@ public final class Canvas_Delegate { } @LayoutlibDelegate + /*package*/ static void native_drawLines(long nativeCanvas, + final float[] pts, final int offset, final int count, + long nativePaint) { + draw(nativeCanvas, nativePaint, false /*compositeOnly*/, + false /*forceSrcMode*/, new GcSnapshot.Drawable() { + @Override + public void draw(Graphics2D graphics, Paint_Delegate paintDelegate) { + for (int i = 0; i < count; i += 4) { + graphics.drawLine((int) pts[i + offset], (int) pts[i + offset + 1], + (int) pts[i + offset + 2], (int) pts[i + offset + 3]); + } + } + }); + } + + @LayoutlibDelegate /*package*/ static void native_drawRect(long nativeCanvas, final float left, final float top, final float right, final float bottom, long paint) { @@ -695,7 +693,6 @@ public final class Canvas_Delegate { /*package*/ static void native_drawRoundRect(long nativeCanvas, final float left, final float top, final float right, final float bottom, final float rx, final float ry, long paint) { - draw(nativeCanvas, paint, false /*compositeOnly*/, false /*forceSrcMode*/, new GcSnapshot.Drawable() { @Override @@ -827,7 +824,6 @@ public final class Canvas_Delegate { final float y, int width, int height, boolean hasAlpha, long nativePaintOrZero) { - // create a temp BufferedImage containing the content. final BufferedImage image = new BufferedImage(width, height, hasAlpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB); @@ -1013,6 +1009,7 @@ public final class Canvas_Delegate { sManager.removeJavaReferenceFor(nativeCanvas); } + // ---- Private delegate/helper methods ---- /** |