LayoutLib: fix clipping issues.
There were two issues:
- Graphics2D.setClip only works on rectangular shapes.
This means doing a setClip on a non rectangular shape should
basically reset the clip and intersect with the new shape.
- the current clip can be null, so the combineShape method
must handle it.
Change-Id: Id2cd7475e991d8b533ff2e8850cc2c27663f9e52
diff --git a/bridge/src/android/graphics/Region_Delegate.java b/bridge/src/android/graphics/Region_Delegate.java
index 684bb90..bc13b52 100644
--- a/bridge/src/android/graphics/Region_Delegate.java
+++ b/bridge/src/android/graphics/Region_Delegate.java
@@ -69,39 +69,64 @@
*
* If the Op is not one that combines two shapes, then this return null
*
- * @param shape1 the firt shape to combine
+ * @param shape1 the firt shape to combine which can be null if there's no original clip.
* @param shape2 the 2nd shape to combine
* @param regionOp the operande for the combine
* @return a new area or null.
*/
public static Area combineShapes(Shape shape1, Shape shape2, int regionOp) {
if (regionOp == Region.Op.DIFFERENCE.nativeInt) {
+ // if shape1 is null (empty), then the result is null.
+ if (shape1 == null) {
+ return null;
+ }
+
// result is always a new area.
Area result = new Area(shape1);
result.subtract(shape2 instanceof Area ? (Area) shape2 : new Area(shape2));
return result;
} else if (regionOp == Region.Op.INTERSECT.nativeInt) {
+ // if shape1 is null, then the result is simply shape2.
+ if (shape1 == null) {
+ return new Area(shape2);
+ }
+
// result is always a new area.
Area result = new Area(shape1);
result.intersect(shape2 instanceof Area ? (Area) shape2 : new Area(shape2));
return result;
} else if (regionOp == Region.Op.UNION.nativeInt) {
+ // if shape1 is null, then the result is simply shape2.
+ if (shape1 == null) {
+ return new Area(shape2);
+ }
+
// result is always a new area.
Area result = new Area(shape1);
result.add(shape2 instanceof Area ? (Area) shape2 : new Area(shape2));
return result;
} else if (regionOp == Region.Op.XOR.nativeInt) {
+ // if shape1 is null, then the result is simply shape2
+ if (shape1 == null) {
+ return new Area(shape2);
+ }
+
// result is always a new area.
Area result = new Area(shape1);
result.exclusiveOr(shape2 instanceof Area ? (Area) shape2 : new Area(shape2));
+ return result;
} else if (regionOp == Region.Op.REVERSE_DIFFERENCE.nativeInt) {
// result is always a new area.
Area result = new Area(shape2);
- result.subtract(shape1 instanceof Area ? (Area) shape1 : new Area(shape1));
+
+ if (shape1 != null) {
+ result.subtract(shape1 instanceof Area ? (Area) shape1 : new Area(shape1));
+ }
+
return result;
}