diff options
Diffstat (limited to 'tools/layoutlib/bridge')
22 files changed, 895 insertions, 334 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java index b660ae6..75b8f99 100644 --- a/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/BitmapShader_Delegate.java @@ -65,7 +65,6 @@ public class BitmapShader_Delegate extends Shader_Delegate { /*package*/ static int nativeCreate(int native_bitmap, int shaderTileModeX, int shaderTileModeY) { Bitmap_Delegate bitmap = Bitmap_Delegate.getDelegate(native_bitmap); - assert bitmap != null; if (bitmap == null) { return 0; } diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index 2ce6a36..1e1b2cf 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -139,7 +139,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(bitmap.mNativeBitmap); if (delegate == null) { - assert false; return null; } @@ -215,7 +214,6 @@ public final class Bitmap_Delegate { /*package*/ static Bitmap nativeCopy(int srcBitmap, int nativeConfig, boolean isMutable) { Bitmap_Delegate srcBmpDelegate = sManager.getDelegate(srcBitmap); if (srcBmpDelegate == null) { - assert false; return null; } @@ -258,7 +256,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return; } @@ -278,7 +275,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -289,7 +285,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -300,7 +295,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -311,7 +305,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -322,7 +315,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return true; } @@ -333,7 +325,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -344,7 +335,6 @@ public final class Bitmap_Delegate { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return; } @@ -355,7 +345,6 @@ public final class Bitmap_Delegate { /*package*/ static void nativeSetPixel(int nativeBitmap, int x, int y, int color) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return; } @@ -366,7 +355,6 @@ public final class Bitmap_Delegate { int stride, int x, int y, int width, int height) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return; } @@ -386,7 +374,6 @@ public final class Bitmap_Delegate { /*package*/ static int nativeGenerationId(int nativeBitmap) { Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return 0; } @@ -414,20 +401,13 @@ public final class Bitmap_Delegate { int[] offsetXY) { Bitmap_Delegate bitmap = sManager.getDelegate(nativeBitmap); if (bitmap == null) { - assert false; return null; } - Paint_Delegate paint = null; - if (nativePaint > 0) { - paint = Paint_Delegate.getDelegate(nativePaint); - if (paint == null) { - assert false; - return null; - } - } + // get the paint which can be null if nativePaint is 0. + Paint_Delegate paint = Paint_Delegate.getDelegate(nativePaint); - if (paint != null && paint.getMaskFilter() != 0) { + if (paint != null && paint.getMaskFilter() != null) { Bridge.getLog().fidelityWarning(null, "MaskFilter not supported in Bitmap.extractAlpha", null); @@ -452,7 +432,6 @@ public final class Bitmap_Delegate { // get the delegate from the native int. Bitmap_Delegate delegate = sManager.getDelegate(nativeBitmap); if (delegate == null) { - assert false; return; } @@ -462,13 +441,11 @@ public final class Bitmap_Delegate { /*package*/ static boolean nativeSameAs(int nb0, int nb1) { Bitmap_Delegate delegate1 = sManager.getDelegate(nb0); if (delegate1 == null) { - assert false; return false; } Bitmap_Delegate delegate2 = sManager.getDelegate(nb1); if (delegate2 == null) { - assert false; return false; } diff --git a/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java new file mode 100644 index 0000000..34824b4 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/BlurMaskFilter_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.BlurMaskFilter + * + * Through the layoutlib_create tool, the original native methods of BlurMaskFilter have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original BlurMaskFilter class. + * + * Because this extends {@link MaskFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link MaskFilter_Delegate}. + * + * @see MaskFilter_Delegate + * + */ +public class BlurMaskFilter_Delegate extends MaskFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "Blur Mask Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int nativeConstructor(float radius, int style) { + BlurMaskFilter_Delegate newDelegate = new BlurMaskFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java index 88ec88e..b3a490f 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java @@ -61,6 +61,8 @@ public final class Canvas_Delegate { private Bitmap_Delegate mBitmap; private GcSnapshot mSnapshot; + private int mDrawFilter = 0; + // ---- Public Helper methods ---- /** @@ -84,6 +86,15 @@ public final class Canvas_Delegate { return mSnapshot; } + /** + * Returns the {@link DrawFilter} delegate or null if none have been set. + * + * @return the delegate or null. + */ + public DrawFilter_Delegate getDrawFilter() { + return DrawFilter_Delegate.getDelegate(mDrawFilter); + } + // ---- native methods ---- /*package*/ static boolean isOpaque(Canvas thisCanvas) { @@ -95,7 +106,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -106,7 +116,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -117,7 +126,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -128,7 +136,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -139,7 +146,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -150,7 +156,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -184,7 +189,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return false; } @@ -205,7 +209,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -216,7 +219,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -227,7 +229,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -238,7 +239,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(thisCanvas.mNativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -296,14 +296,12 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return; } // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { - assert false; return; } @@ -315,13 +313,11 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint); if (paintDelegate == null) { - assert false; return 0; } @@ -334,13 +330,11 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(paint); if (paintDelegate == null) { - assert false; return 0; } @@ -354,7 +348,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -367,7 +360,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return 0; } @@ -379,13 +371,11 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; return; } Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix); if (matrixDelegate == null) { - assert false; return; } @@ -408,12 +398,12 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; + return; } Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix); if (matrixDelegate == null) { - assert false; + return; } // get the current top graphics2D object. @@ -441,7 +431,7 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; + return false; } return canvasDelegate.clipRect(left, top, right, bottom, regionOp); @@ -463,8 +453,24 @@ public final class Canvas_Delegate { /*package*/ static void nativeSetDrawFilter(int nativeCanvas, int nativeFilter) { - // FIXME - throw new UnsupportedOperationException(); + Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); + if (canvasDelegate == null) { + return; + } + + canvasDelegate.mDrawFilter = nativeFilter; + + // get the delegate only because we don't support them at all for the moment, so + // we can display the message now. + + DrawFilter_Delegate filterDelegate = DrawFilter_Delegate.getDelegate(nativeFilter); + if (canvasDelegate == null) { + return; + } + + if (filterDelegate.isSupported() == false) { + Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null); + } } /*package*/ static boolean native_getClipBounds(int nativeCanvas, @@ -472,7 +478,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return false; } @@ -533,7 +538,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -676,7 +680,6 @@ public final class Canvas_Delegate { int paint) { final Path_Delegate pathDelegate = Path_Delegate.getDelegate(path); if (pathDelegate == null) { - assert false; return; } @@ -708,7 +711,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { - assert false; return; } @@ -729,7 +731,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { - assert false; return; } @@ -754,7 +755,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(bitmap); if (bitmapDelegate == null) { - assert false; return; } @@ -800,24 +800,15 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; return; } - // get the delegate from the native int. - Paint_Delegate paintDelegate = null; - if (nPaint > 0) { - paintDelegate = Paint_Delegate.getDelegate(nPaint); - if (paintDelegate == null) { - assert false; - return; - } - } + // get the delegate from the native int, which can be null + Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint); // get the delegate from the native int. Bitmap_Delegate bitmapDelegate = Bitmap_Delegate.getDelegate(nBitmap); if (bitmapDelegate == null) { - assert false; return; } @@ -825,7 +816,6 @@ public final class Canvas_Delegate { Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(nMatrix); if (matrixDelegate == null) { - assert false; return; } @@ -1029,7 +1019,6 @@ public final class Canvas_Delegate { // get the delegate from the native int so that it can be disposed. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -1051,19 +1040,11 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; return; } - // paint could be 0 meaning no paint - Paint_Delegate paintDelegate = null; - if (nPaint > 0) { - paintDelegate = Paint_Delegate.getDelegate(nPaint); - if (paintDelegate == null) { - assert false; - return; - } - } + // get the paint which can be null if nPaint is 0; + Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nPaint); canvasDelegate.getSnapshot().draw(drawable, paintDelegate, compositeOnly, forceSrcMode); } @@ -1078,7 +1059,6 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nCanvas); if (canvasDelegate == null) { - assert false; return; } @@ -1161,19 +1141,11 @@ public final class Canvas_Delegate { // get the delegate from the native int. Canvas_Delegate canvasDelegate = sManager.getDelegate(nativeCanvas); if (canvasDelegate == null) { - assert false; return; } - // get the delegate from the native int. - Paint_Delegate paintDelegate = null; - if (nativePaintOrZero > 0) { - paintDelegate = Paint_Delegate.getDelegate(nativePaintOrZero); - if (paintDelegate == null) { - assert false; - return; - } - } + // get the paint, which could be null if the int is 0 + Paint_Delegate paintDelegate = Paint_Delegate.getDelegate(nativePaintOrZero); final BufferedImage image = getImageToDraw(bitmap, paintDelegate, sBoolOut); @@ -1221,16 +1193,13 @@ public final class Canvas_Delegate { // - Create a different bitmap to draw in which all the alpha channel values is set // to 0xFF. if (paint != null) { - int xfermode = paint.getXfermode(); - if (xfermode > 0) { - Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(xfermode); - if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) { - PorterDuff.Mode mode = - ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode(); - - forceSrcMode[0] = mode == PorterDuff.Mode.SRC_OVER || - mode == PorterDuff.Mode.SRC; - } + Xfermode_Delegate xfermodeDelegate = paint.getXfermode(); + if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) { + PorterDuff.Mode mode = + ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode(); + + forceSrcMode[0] = mode == PorterDuff.Mode.SRC_OVER || + mode == PorterDuff.Mode.SRC; } } diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java new file mode 100644 index 0000000..3df170f --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/ColorFilter_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.ColorFilter + * + * Through the layoutlib_create tool, the original native methods of ColorFilter have been replaced + * by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original ColorFilter class. + * + * This also serve as a base class for all ColorFilter delegate classes. + * + * @see DelegateManager + * + */ +public abstract class ColorFilter_Delegate { + + // ---- delegate manager ---- + protected static final DelegateManager<ColorFilter_Delegate> sManager = + new DelegateManager<ColorFilter_Delegate>(); + + // ---- delegate helper data ---- + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + public static ColorFilter_Delegate getDelegate(int nativeShader) { + return sManager.getDelegate(nativeShader); + } + + public abstract boolean isSupported(); + public abstract String getSupportMessage(); + + // ---- native methods ---- + + /*package*/ static void finalizer(int native_instance, int nativeColorFilter) { + sManager.removeDelegate(native_instance); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java new file mode 100644 index 0000000..4284327 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/ColorMatrixColorFilter_Delegate.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.ColorMatrixColorFilter + * + * Through the layoutlib_create tool, the original native methods of ColorMatrixColorFilter have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original ColorMatrixColorFilter class. + * + * Because this extends {@link ColorFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link ColorFilter_Delegate}. + * + * @see ColorFilter_Delegate + * + */ +public class ColorMatrixColorFilter_Delegate extends ColorFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "ColorMatrix Color Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int nativeColorMatrixFilter(float[] array) { + ColorMatrixColorFilter_Delegate newDelegate = new ColorMatrixColorFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + /*package*/ static int nColorMatrixFilter(int nativeFilter, float[] array) { + // pass + return 0; + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java new file mode 100644 index 0000000..ddf20b6 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/DrawFilter_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.DrawFilter + * + * Through the layoutlib_create tool, the original native methods of DrawFilter have been replaced + * by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original DrawFilter class. + * + * This also serve as a base class for all DrawFilter delegate classes. + * + * @see DelegateManager + * + */ +public abstract class DrawFilter_Delegate { + + // ---- delegate manager ---- + protected static final DelegateManager<DrawFilter_Delegate> sManager = + new DelegateManager<DrawFilter_Delegate>(); + + // ---- delegate helper data ---- + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + public static DrawFilter_Delegate getDelegate(int nativeDrawFilter) { + return sManager.getDelegate(nativeDrawFilter); + } + + public abstract boolean isSupported(); + public abstract String getSupportMessage(); + + // ---- native methods ---- + + /*package*/ static void nativeDestructor(int nativeDrawFilter) { + sManager.removeDelegate(nativeDrawFilter); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java new file mode 100644 index 0000000..82f1da3 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/EmbossMaskFilter_Delegate.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.EmbossMaskFilter + * + * Through the layoutlib_create tool, the original native methods of EmbossMaskFilter have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original EmbossMaskFilter class. + * + * Because this extends {@link MaskFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link MaskFilter_Delegate}. + * + * @see MaskFilter_Delegate + * + */ +public class EmbossMaskFilter_Delegate extends MaskFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "Emboss Mask Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int nativeConstructor(float[] direction, float ambient, + float specular, float blurRadius) { + EmbossMaskFilter_Delegate newDelegate = new EmbossMaskFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java new file mode 100644 index 0000000..132004f9 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/LayerRasterizer_Delegate.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.LayerRasterizer + * + * Through the layoutlib_create tool, the original native methods of LayerRasterizer have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original LayerRasterizer class. + * + * Because this extends {@link Rasterizer_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link Rasterizer_Delegate}. + * + * @see Rasterizer_Delegate + * + */ +public class LayerRasterizer_Delegate extends Rasterizer_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "Layer Rasterizers are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int nativeConstructor() { + LayerRasterizer_Delegate newDelegate = new LayerRasterizer_Delegate(); + return sManager.addDelegate(newDelegate); + } + + /*package*/ static void nativeAddLayer(int native_layer, int native_paint, float dx, float dy) { + + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java new file mode 100644 index 0000000..ba2cfad --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/LightingColorFilter_Delegate.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.LightingColorFilter + * + * Through the layoutlib_create tool, the original native methods of LightingColorFilter have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original LightingColorFilter class. + * + * Because this extends {@link ColorFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link ColorFilter_Delegate}. + * + * @see ColorFilter_Delegate + * + */ +public class LightingColorFilter_Delegate extends ColorFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "Lighting Color Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int native_CreateLightingFilter(int mul, int add) { + LightingColorFilter_Delegate newDelegate = new LightingColorFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + /*package*/ static int nCreateLightingFilter(int nativeFilter, int mul, int add) { + // pass + return 0; + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java new file mode 100644 index 0000000..c582a91 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/MaskFilter_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.MaskFilter + * + * Through the layoutlib_create tool, the original native methods of MaskFilter have been replaced + * by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original MaskFilter class. + * + * This also serve as a base class for all MaskFilter delegate classes. + * + * @see DelegateManager + * + */ +public abstract class MaskFilter_Delegate { + + // ---- delegate manager ---- + protected static final DelegateManager<MaskFilter_Delegate> sManager = + new DelegateManager<MaskFilter_Delegate>(); + + // ---- delegate helper data ---- + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + public static MaskFilter_Delegate getDelegate(int nativeShader) { + return sManager.getDelegate(nativeShader); + } + + public abstract boolean isSupported(); + public abstract String getSupportMessage(); + + // ---- native methods ---- + + /*package*/ static void nativeDestructor(int native_filter) { + sManager.removeDelegate(native_filter); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java index 463f4e9..94beef3 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Matrix_Delegate.java @@ -60,7 +60,6 @@ public final class Matrix_Delegate { public static AffineTransform getAffineTransform(Matrix m) { Matrix_Delegate delegate = sManager.getDelegate(m.native_instance); if (delegate == null) { - assert false; return null; } @@ -70,7 +69,6 @@ public final class Matrix_Delegate { public static boolean hasPerspective(Matrix m) { Matrix_Delegate delegate = sManager.getDelegate(m.native_instance); if (delegate == null) { - assert false; return false; } @@ -181,7 +179,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_isIdentity(int native_object) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -191,7 +188,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_rectStaysRect(int native_object) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return true; } @@ -201,7 +197,6 @@ public final class Matrix_Delegate { /*package*/ static void native_reset(int native_object) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -211,13 +206,11 @@ public final class Matrix_Delegate { /*package*/ static void native_set(int native_object, int other) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } Matrix_Delegate src = sManager.getDelegate(other); if (src == null) { - assert false; return; } @@ -227,7 +220,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setTranslate(int native_object, float dx, float dy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -238,7 +230,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -248,7 +239,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setScale(int native_object, float sx, float sy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -266,7 +256,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setRotate(int native_object, float degrees, float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -276,7 +265,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setRotate(int native_object, float degrees) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -287,7 +275,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -305,7 +292,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setSinCos(int native_object, float sinValue, float cosValue) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -316,7 +302,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -326,7 +311,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setSkew(int native_object, float kx, float ky) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -350,19 +334,16 @@ public final class Matrix_Delegate { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } Matrix_Delegate a_mtx = sManager.getDelegate(a); if (a_mtx == null) { - assert false; return false; } Matrix_Delegate b_mtx = sManager.getDelegate(b); if (b_mtx == null) { - assert false; return false; } @@ -374,7 +355,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_preTranslate(int native_object, float dx, float dy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -386,7 +366,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -397,7 +376,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_preScale(int native_object, float sx, float sy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -409,7 +387,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -420,7 +397,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_preRotate(int native_object, float degrees) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -436,7 +412,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -447,7 +422,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_preSkew(int native_object, float kx, float ky) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -458,13 +432,11 @@ public final class Matrix_Delegate { /*package*/ static boolean native_preConcat(int native_object, int other_matrix) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } Matrix_Delegate other = sManager.getDelegate(other_matrix); if (d == null) { - assert false; return false; } @@ -475,7 +447,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_postTranslate(int native_object, float dx, float dy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -487,7 +458,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -498,7 +468,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_postScale(int native_object, float sx, float sy) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -510,7 +479,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -521,7 +489,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_postRotate(int native_object, float degrees) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -533,7 +500,6 @@ public final class Matrix_Delegate { float px, float py) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -544,7 +510,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_postSkew(int native_object, float kx, float ky) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -555,13 +520,11 @@ public final class Matrix_Delegate { /*package*/ static boolean native_postConcat(int native_object, int other_matrix) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } Matrix_Delegate other = sManager.getDelegate(other_matrix); if (d == null) { - assert false; return false; } @@ -573,7 +536,6 @@ public final class Matrix_Delegate { RectF dst, int stf) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -643,17 +605,14 @@ public final class Matrix_Delegate { /*package*/ static boolean native_invert(int native_object, int inverse) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } Matrix_Delegate inv_mtx = sManager.getDelegate(inverse); if (inv_mtx == null) { - assert false; return false; } - try { AffineTransform affineTransform = d.getAffineTransform(); AffineTransform inverseTransform = affineTransform.createInverse(); @@ -674,7 +633,6 @@ public final class Matrix_Delegate { float[] src, int srcIndex, int ptCount, boolean isPts) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -690,7 +648,6 @@ public final class Matrix_Delegate { /*package*/ static boolean native_mapRect(int native_object, RectF dst, RectF src) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return false; } @@ -705,7 +662,6 @@ public final class Matrix_Delegate { /*package*/ static void native_getValues(int native_object, float[] values) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -715,7 +671,6 @@ public final class Matrix_Delegate { /*package*/ static void native_setValues(int native_object, float[] values) { Matrix_Delegate d = sManager.getDelegate(native_object); if (d == null) { - assert false; return; } @@ -725,13 +680,11 @@ public final class Matrix_Delegate { /*package*/ static boolean native_equals(int native_a, int native_b) { Matrix_Delegate a = sManager.getDelegate(native_a); if (a == null) { - assert false; return false; } Matrix_Delegate b = sManager.getDelegate(native_b); if (b == null) { - assert false; return false; } diff --git a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java index 25e0795..e9fb30a 100644 --- a/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/NinePatch_Delegate.java @@ -130,7 +130,6 @@ public final class NinePatch_Delegate { // get the delegate from the native int. final Bitmap_Delegate bitmap_delegate = Bitmap_Delegate.getDelegate(bitmap_instance); if (bitmap_delegate == null) { - assert false; return; } @@ -152,7 +151,6 @@ public final class NinePatch_Delegate { Canvas_Delegate canvas_delegate = Canvas_Delegate.getDelegate(canvas_instance); if (canvas_delegate == null) { - assert false; return; } diff --git a/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java new file mode 100644 index 0000000..ec92507 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/PaintFlagsDrawFilter_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.PaintFlagsDrawFilter + * + * Through the layoutlib_create tool, the original native methods of PaintFlagsDrawFilter have been + * replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original PaintFlagsDrawFilter class. + * + * Because this extends {@link DrawFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the DrawFilter classes will be added to the manager owned by + * {@link DrawFilter_Delegate}. + * + * @see DrawFilter_Delegate + * + */ +public class PaintFlagsDrawFilter_Delegate extends DrawFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "Paint Flags Draw Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int nativeConstructor(int clearBits, int setBits) { + PaintFlagsDrawFilter_Delegate newDelegate = new PaintFlagsDrawFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java index 7cb30dd..fc58475 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java @@ -16,6 +16,7 @@ package android.graphics; +import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.impl.DelegateManager; import android.graphics.Paint.FontMetrics; @@ -82,6 +83,7 @@ public class Paint_Delegate { private int mShader; private int mPathEffect; private int mMaskFilter; + private int mRasterizer; // ---- Public Helper methods ---- @@ -165,24 +167,58 @@ public class Paint_Delegate { } } - public int getXfermode() { - return mXfermode; + /** + * Returns the {@link Xfermode} delegate or null if none have been set + * + * @return the delegate or null. + */ + public Xfermode_Delegate getXfermode() { + return Xfermode_Delegate.getDelegate(mXfermode); } - public int getColorFilter() { - return mColorFilter; + /** + * Returns the {@link ColorFilter} delegate or null if none have been set + * + * @return the delegate or null. + */ + public ColorFilter_Delegate getColorFilter() { + return ColorFilter_Delegate.getDelegate(mColorFilter); } - public int getShader() { - return mShader; + /** + * Returns the {@link Shader} delegate or null if none have been set + * + * @return the delegate or null. + */ + public Shader_Delegate getShader() { + return Shader_Delegate.getDelegate(mShader); } - public int getPathEffect() { - return mPathEffect; + /** + * Returns the {@link PathEffect} delegate or null if none have been set + * + * @return the delegate or null. + */ + public PathEffect_Delegate getPathEffect() { + return PathEffect_Delegate.getDelegate(mPathEffect); } - public int getMaskFilter() { - return mMaskFilter; + /** + * Returns the {@link MaskFilter} delegate or null if none have been set + * + * @return the delegate or null. + */ + public MaskFilter_Delegate getMaskFilter() { + return MaskFilter_Delegate.getDelegate(mMaskFilter); + } + + /** + * Returns the {@link Rasterizer} delegate or null if none have been set + * + * @return the delegate or null. + */ + public Rasterizer_Delegate getRasterizer() { + return Rasterizer_Delegate.getDelegate(mRasterizer); } // ---- native methods ---- @@ -191,7 +227,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -202,7 +237,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -245,7 +279,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -256,7 +289,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -267,7 +299,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -278,7 +309,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -289,7 +319,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 1.f; } @@ -300,7 +329,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -311,7 +339,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 1.f; } @@ -322,7 +349,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -339,7 +365,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 1.f; } @@ -350,7 +375,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -362,7 +386,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 1.f; } @@ -373,7 +396,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -385,7 +407,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 1.f; } @@ -396,7 +417,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } @@ -408,7 +428,6 @@ public class Paint_Delegate { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -425,7 +444,6 @@ public class Paint_Delegate { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -442,7 +460,6 @@ public class Paint_Delegate { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -453,7 +470,6 @@ public class Paint_Delegate { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -482,7 +498,6 @@ public class Paint_Delegate { // get the delegate Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return 0; } @@ -519,7 +534,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(paint); if (delegate == null) { - assert false; return 0; } @@ -531,7 +545,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return; } @@ -542,14 +555,12 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate_dst = sManager.getDelegate(native_dst); if (delegate_dst == null) { - assert false; return; } // get the delegate from the native int. Paint_Delegate delegate_src = sManager.getDelegate(native_src); if (delegate_src == null) { - assert false; return; } @@ -560,7 +571,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0; } @@ -571,7 +581,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return; } @@ -582,7 +591,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0; } @@ -593,7 +601,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return; } @@ -604,7 +611,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0; } @@ -615,7 +621,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return; } @@ -631,7 +636,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return shader; } @@ -642,18 +646,24 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return filter; } - return delegate.mColorFilter = filter; + delegate.mColorFilter = filter; + + // since none of those are supported, display a fidelity warning right away + ColorFilter_Delegate filterDelegate = delegate.getColorFilter(); + if (filterDelegate != null && filterDelegate.isSupported() == false) { + Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null); + } + + return filter; } /*package*/ static int native_setXfermode(int native_object, int xfermode) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return xfermode; } @@ -664,7 +674,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return effect; } @@ -675,18 +684,24 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return maskfilter; } - return delegate.mMaskFilter = maskfilter; + delegate.mMaskFilter = maskfilter; + + // since none of those are supported, display a fidelity warning right away + MaskFilter_Delegate filterDelegate = delegate.getMaskFilter(); + if (filterDelegate != null && filterDelegate.isSupported() == false) { + Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null); + } + + return maskfilter; } /*package*/ static int native_setTypeface(int native_object, int typeface) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0; } @@ -696,15 +711,27 @@ public class Paint_Delegate { } /*package*/ static int native_setRasterizer(int native_object, int rasterizer) { - // FIXME - throw new UnsupportedOperationException(); + // get the delegate from the native int. + Paint_Delegate delegate = sManager.getDelegate(native_object); + if (delegate == null) { + return rasterizer; + } + + delegate.mRasterizer = rasterizer; + + // since none of those are supported, display a fidelity warning right away + Rasterizer_Delegate rasterizerDelegate = delegate.getRasterizer(); + if (rasterizerDelegate != null && rasterizerDelegate.isSupported() == false) { + Bridge.getLog().fidelityWarning(null, rasterizerDelegate.getSupportMessage(), null); + } + + return rasterizer; } /*package*/ static int native_getTextAlign(int native_object) { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0; } @@ -715,7 +742,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return; } @@ -726,7 +752,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_paint); if (delegate == null) { - assert false; return 0.f; } @@ -751,7 +776,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(native_object); if (delegate == null) { - assert false; return 0.f; } @@ -869,6 +893,7 @@ public class Paint_Delegate { mShader = paint.mShader; mPathEffect = paint.mPathEffect; mMaskFilter = paint.mMaskFilter; + mRasterizer = paint.mRasterizer; updateFontObject(); } @@ -890,12 +915,14 @@ public class Paint_Delegate { mShader = 0; mPathEffect = 0; mMaskFilter = 0; + mRasterizer = 0; updateFontObject(); } /** * Update the {@link Font} object from the typeface, text size and scaling */ + @SuppressWarnings("deprecation") private void updateFontObject() { if (mTypeface != 0) { // Get the fonts from the TypeFace object. @@ -998,7 +1025,6 @@ public class Paint_Delegate { // get the delegate from the native int. Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint); if (delegate == null) { - assert false; return; } diff --git a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java index 811f0f6..c5c3220 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java @@ -80,14 +80,9 @@ public final class Path_Delegate { // create the delegate Path_Delegate newDelegate = new Path_Delegate(); - // get the delegate to copy - if (nPath > 0) { - Path_Delegate pathDelegate = sManager.getDelegate(nPath); - if (pathDelegate == null) { - assert false; - return 0; - } - + // get the delegate to copy, which could be null if nPath is 0 + Path_Delegate pathDelegate = sManager.getDelegate(nPath); + if (pathDelegate != null) { newDelegate.set(pathDelegate); } @@ -97,7 +92,6 @@ public final class Path_Delegate { /*package*/ static void native_reset(int nPath) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -113,13 +107,11 @@ public final class Path_Delegate { /*package*/ static void native_set(int native_dst, int native_src) { Path_Delegate pathDstDelegate = sManager.getDelegate(native_dst); if (pathDstDelegate == null) { - assert false; return; } Path_Delegate pathSrcDelegate = sManager.getDelegate(native_src); if (pathSrcDelegate == null) { - assert false; return; } @@ -129,7 +121,6 @@ public final class Path_Delegate { /*package*/ static int native_getFillType(int nPath) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return 0; } @@ -139,7 +130,6 @@ public final class Path_Delegate { /*package*/ static void native_setFillType(int nPath, int ft) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -149,7 +139,6 @@ public final class Path_Delegate { /*package*/ static boolean native_isEmpty(int nPath) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return true; } @@ -159,7 +148,6 @@ public final class Path_Delegate { /*package*/ static boolean native_isRect(int nPath, RectF rect) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return false; } @@ -179,7 +167,6 @@ public final class Path_Delegate { /*package*/ static void native_computeBounds(int nPath, RectF bounds) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -194,7 +181,6 @@ public final class Path_Delegate { /*package*/ static void native_moveTo(int nPath, float x, float y) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -204,7 +190,6 @@ public final class Path_Delegate { /*package*/ static void native_rMoveTo(int nPath, float dx, float dy) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -214,7 +199,6 @@ public final class Path_Delegate { /*package*/ static void native_lineTo(int nPath, float x, float y) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -224,7 +208,6 @@ public final class Path_Delegate { /*package*/ static void native_rLineTo(int nPath, float dx, float dy) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -234,7 +217,6 @@ public final class Path_Delegate { /*package*/ static void native_quadTo(int nPath, float x1, float y1, float x2, float y2) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -245,7 +227,6 @@ public final class Path_Delegate { float dx2, float dy2) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -256,7 +237,6 @@ public final class Path_Delegate { float x2, float y2, float x3, float y3) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -267,7 +247,6 @@ public final class Path_Delegate { float x2, float y2, float x3, float y3) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -278,7 +257,6 @@ public final class Path_Delegate { float startAngle, float sweepAngle, boolean forceMoveTo) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -288,7 +266,6 @@ public final class Path_Delegate { /*package*/ static void native_close(int nPath) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -298,7 +275,6 @@ public final class Path_Delegate { /*package*/ static void native_addRect(int nPath, RectF rect, int dir) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -309,7 +285,6 @@ public final class Path_Delegate { float right, float bottom, int dir) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -365,18 +340,11 @@ public final class Path_Delegate { int dst_path) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } - Path_Delegate dstDelegate = null; - if (dst_path > 0) { - dstDelegate = sManager.getDelegate(dst_path); - if (dstDelegate == null) { - assert false; - return; - } - } + // could be null if the int is 0; + Path_Delegate dstDelegate = sManager.getDelegate(dst_path); pathDelegate.offset(dx, dy, dstDelegate); } @@ -388,7 +356,6 @@ public final class Path_Delegate { /*package*/ static void native_setLastPoint(int nPath, float dx, float dy) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } @@ -400,24 +367,16 @@ public final class Path_Delegate { int dst_path) { Path_Delegate pathDelegate = sManager.getDelegate(nPath); if (pathDelegate == null) { - assert false; return; } Matrix_Delegate matrixDelegate = Matrix_Delegate.getDelegate(matrix); if (matrixDelegate == null) { - assert false; return; } - Path_Delegate dstDelegate = null; - if (dst_path > 0) { - dstDelegate = sManager.getDelegate(dst_path); - if (dstDelegate == null) { - assert false; - return; - } - } + // this can be null if dst_path is 0 + Path_Delegate dstDelegate = sManager.getDelegate(dst_path); pathDelegate.transform(matrixDelegate, dstDelegate); } diff --git a/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java new file mode 100644 index 0000000..9038636 --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/PorterDuffColorFilter_Delegate.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.PorterDuffColorFilter + * + * Through the layoutlib_create tool, the original native methods of PorterDuffColorFilter have + * been replaced by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original PorterDuffColorFilter class. + * + * Because this extends {@link ColorFilter_Delegate}, there's no need to use a + * {@link DelegateManager}, as all the Shader classes will be added to the manager + * owned by {@link ColorFilter_Delegate}. + * + * @see ColorFilter_Delegate + * + */ +public class PorterDuffColorFilter_Delegate extends ColorFilter_Delegate { + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + @Override + public boolean isSupported() { + return false; + } + + @Override + public String getSupportMessage() { + return "PorterDuff Color Filters are not supported."; + } + + // ---- native methods ---- + + /*package*/ static int native_CreatePorterDuffFilter(int srcColor, int porterDuffMode) { + PorterDuffColorFilter_Delegate newDelegate = new PorterDuffColorFilter_Delegate(); + return sManager.addDelegate(newDelegate); + } + + /*package*/ static int nCreatePorterDuffFilter(int nativeFilter, int srcColor, + int porterDuffMode) { + // pass + return 0; + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java new file mode 100644 index 0000000..9fd67be --- /dev/null +++ b/tools/layoutlib/bridge/src/android/graphics/Rasterizer_Delegate.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.graphics; + +import com.android.layoutlib.bridge.impl.DelegateManager; + +/** + * Delegate implementing the native methods of android.graphics.Rasterizer + * + * Through the layoutlib_create tool, the original native methods of Rasterizer have been replaced + * by calls to methods of the same name in this delegate class. + * + * This class behaves like the original native implementation, but in Java, keeping previously + * native data into its own objects and mapping them to int that are sent back and forth between + * it and the original Rasterizer class. + * + * This also serve as a base class for all Rasterizer delegate classes. + * + * @see DelegateManager + * + */ +public abstract class Rasterizer_Delegate { + + // ---- delegate manager ---- + protected static final DelegateManager<Rasterizer_Delegate> sManager = + new DelegateManager<Rasterizer_Delegate>(); + + // ---- delegate helper data ---- + + // ---- delegate data ---- + + // ---- Public Helper methods ---- + + public static Rasterizer_Delegate getDelegate(int nativeShader) { + return sManager.getDelegate(nativeShader); + } + + public abstract boolean isSupported(); + public abstract String getSupportMessage(); + + // ---- native methods ---- + + /*package*/ static void finalizer(int native_instance) { + sManager.removeDelegate(native_instance); + } + + // ---- Private delegate/helper methods ---- +} diff --git a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java index 3759b26..7903ac9 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Shader_Delegate.java @@ -82,27 +82,16 @@ public abstract class Shader_Delegate { // get the delegate from the native int. Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader); if (shaderDelegate == null) { - assert false; return false; } - Matrix_Delegate localMatrixDelegate = null; - if (shaderDelegate.mLocalMatrix > 0) { - localMatrixDelegate = Matrix_Delegate.getDelegate(shaderDelegate.mLocalMatrix); - if (localMatrixDelegate == null) { - assert false; - return false; - } - } - - Matrix_Delegate destMatrixDelegate = null; - if (matrix_instance > 0) { - destMatrixDelegate = Matrix_Delegate.getDelegate(shaderDelegate.mLocalMatrix); - if (destMatrixDelegate == null) { - assert false; - return false; - } + // can be null if shader has no matrix (int is 0) + Matrix_Delegate localMatrixDelegate = Matrix_Delegate.getDelegate( + shaderDelegate.mLocalMatrix); + // can be null if the int is 0. + Matrix_Delegate destMatrixDelegate = Matrix_Delegate.getDelegate(matrix_instance); + if (destMatrixDelegate != null) { if (localMatrixDelegate != null) { destMatrixDelegate.set(localMatrixDelegate); } else { @@ -120,7 +109,6 @@ public abstract class Shader_Delegate { // get the delegate from the native int. Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader); if (shaderDelegate == null) { - assert false; return; } @@ -130,14 +118,8 @@ public abstract class Shader_Delegate { // ---- Private delegate/helper methods ---- protected java.awt.geom.AffineTransform getLocalMatrix() { - Matrix_Delegate localMatrixDelegate = null; - if (mLocalMatrix > 0) { - localMatrixDelegate = Matrix_Delegate.getDelegate(mLocalMatrix); - if (localMatrixDelegate == null) { - assert false; - return new java.awt.geom.AffineTransform(); - } - + Matrix_Delegate localMatrixDelegate = Matrix_Delegate.getDelegate(mLocalMatrix); + if (localMatrixDelegate != null) { return localMatrixDelegate.getAffineTransform(); } diff --git a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java index 0b54a0e..c7362c0 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Typeface_Delegate.java @@ -78,7 +78,6 @@ public final class Typeface_Delegate { public static List<Font> getFonts(int native_int) { Typeface_Delegate delegate = sManager.getDelegate(native_int); if (delegate == null) { - assert false; return null; } @@ -109,7 +108,6 @@ public final class Typeface_Delegate { /*package*/ static synchronized int nativeCreateFromTypeface(int native_instance, int style) { Typeface_Delegate delegate = sManager.getDelegate(native_instance); if (delegate == null) { - assert false; return 0; } @@ -143,7 +141,6 @@ public final class Typeface_Delegate { /*package*/ static int nativeGetStyle(int native_instance) { Typeface_Delegate delegate = sManager.getDelegate(native_instance); if (delegate == null) { - assert false; return 0; } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java index b272963..05a258d 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java @@ -55,11 +55,21 @@ public final class DelegateManager<T> { /** * Returns the delegate from the given native int. + * <p> + * If the int is zero, then this will always return null. + * <p> + * If the int is non zero and the delegate is not found, this will throw an assert. + * * @param native_object the native int. * @return the delegate or null if not found. */ public T getDelegate(int native_object) { - return mDelegates.get(native_object); + if (native_object > 0) { + T delegate = mDelegates.get(native_object); + assert delegate != null; + return delegate; + } + return null; } /** diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java index 5c2c7cd..afe75a0 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/GcSnapshot.java @@ -706,23 +706,19 @@ public class GcSnapshot { // get the shader first, as it'll replace the color if it can be used it. if (compositeOnly == false) { - int nativeShader = paint.getShader(); - if (nativeShader > 0) { - Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(nativeShader); - assert shaderDelegate != null; - if (shaderDelegate != null) { - if (shaderDelegate.isSupported()) { - java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint(); - assert shaderPaint != null; - if (shaderPaint != null) { - g.setPaint(shaderPaint); - customShader = true; - } - } else { - Bridge.getLog().fidelityWarning(null, - shaderDelegate.getSupportMessage(), - null); + Shader_Delegate shaderDelegate = paint.getShader(); + if (shaderDelegate != null) { + if (shaderDelegate.isSupported()) { + java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint(); + assert shaderPaint != null; + if (shaderPaint != null) { + g.setPaint(shaderPaint); + customShader = true; } + } else { + Bridge.getLog().fidelityWarning(null, + shaderDelegate.getSupportMessage(), + null); } } @@ -732,23 +728,19 @@ public class GcSnapshot { } boolean customStroke = false; - int pathEffect = paint.getPathEffect(); - if (pathEffect > 0) { - PathEffect_Delegate effectDelegate = PathEffect_Delegate.getDelegate(pathEffect); - assert effectDelegate != null; - if (effectDelegate != null) { - if (effectDelegate.isSupported()) { - Stroke stroke = effectDelegate.getStroke(paint); - assert stroke != null; - if (stroke != null) { - g.setStroke(stroke); - customStroke = true; - } - } else { - Bridge.getLog().fidelityWarning(null, - effectDelegate.getSupportMessage(), - null); + PathEffect_Delegate effectDelegate = paint.getPathEffect(); + if (effectDelegate != null) { + if (effectDelegate.isSupported()) { + Stroke stroke = effectDelegate.getStroke(paint); + assert stroke != null; + if (stroke != null) { + g.setStroke(stroke); + customStroke = true; } + } else { + Bridge.getLog().fidelityWarning(null, + effectDelegate.getSupportMessage(), + null); } } @@ -771,23 +763,19 @@ public class GcSnapshot { AlphaComposite.SRC, (float) alpha / 255.f)); } else { boolean customXfermode = false; - int xfermode = paint.getXfermode(); - if (xfermode > 0) { - Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(xfermode); - assert xfermodeDelegate != null; - if (xfermodeDelegate != null) { - if (xfermodeDelegate.isSupported()) { - Composite composite = xfermodeDelegate.getComposite(alpha); - assert composite != null; - if (composite != null) { - g.setComposite(composite); - customXfermode = true; - } - } else { - Bridge.getLog().fidelityWarning(null, - xfermodeDelegate.getSupportMessage(), - null); + Xfermode_Delegate xfermodeDelegate = paint.getXfermode(); + if (xfermodeDelegate != null) { + if (xfermodeDelegate.isSupported()) { + Composite composite = xfermodeDelegate.getComposite(alpha); + assert composite != null; + if (composite != null) { + g.setComposite(composite); + customXfermode = true; } + } else { + Bridge.getLog().fidelityWarning(null, + xfermodeDelegate.getSupportMessage(), + null); } } |