Add fill type support to vector drawable

The platform has added fill type to vector drawables. This CL implements
the native replacement.
Also remove a couple of delegates for classes that have been removed
from the platform.

Change-Id: Ie6ba344db9c9c2c45cd0ef4b99f11f9d8bcfd7de
This commit is contained in:
Diego Perez
2016-03-22 11:29:47 +00:00
parent ace5a78194
commit 5ceb30f216
7 changed files with 37 additions and 145 deletions

View File

@@ -1,70 +0,0 @@
/*
* 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;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import java.awt.Composite;
/**
* Delegate implementing the native methods of android.graphics.AvoidXfermode
*
* Through the layoutlib_create tool, the original native methods of AvoidXfermode 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 AvoidXfermode class.
*
* Because this extends {@link Xfermode_Delegate}, there's no need to use a
* {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
* {@link Xfermode_Delegate}.
*
*/
public class AvoidXfermode_Delegate extends Xfermode_Delegate {
// ---- delegate data ----
// ---- Public Helper methods ----
@Override
public Composite getComposite(int alpha) {
// FIXME
return null;
}
@Override
public boolean isSupported() {
return false;
}
@Override
public String getSupportMessage() {
return "Avoid Xfermodes are not supported in Layout Preview mode.";
}
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate(int opColor, int tolerance, int nativeMode) {
AvoidXfermode_Delegate newDelegate = new AvoidXfermode_Delegate();
return sManager.addNewDelegate(newDelegate);
}
// ---- Private delegate/helper methods ----
}

View File

@@ -167,13 +167,13 @@ public final class Path_Delegate {
}
@LayoutlibDelegate
/*package*/ static void native_setFillType(long nPath, int ft) {
public static void native_setFillType(long nPath, int ft) {
Path_Delegate pathDelegate = sManager.getDelegate(nPath);
if (pathDelegate == null) {
return;
}
pathDelegate.mFillType = Path.sFillTypeArray[ft];
pathDelegate.setFillType(Path.sFillTypeArray[ft]);
}
@LayoutlibDelegate

View File

@@ -1,70 +0,0 @@
/*
* 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;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import java.awt.Composite;
/**
* Delegate implementing the native methods of android.graphics.PixelXorXfermode
*
* Through the layoutlib_create tool, the original native methods of PixelXorXfermode 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 PixelXorXfermode class.
*
* Because this extends {@link Xfermode_Delegate}, there's no need to use a
* {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
* {@link Xfermode_Delegate}.
*
* @see Xfermode_Delegate
*/
public class PixelXorXfermode_Delegate extends Xfermode_Delegate {
// ---- delegate data ----
// ---- Public Helper methods ----
@Override
public Composite getComposite(int alpha) {
// FIXME
return null;
}
@Override
public boolean isSupported() {
return false;
}
@Override
public String getSupportMessage() {
return "Pixel XOR Xfermodes are not supported in Layout Preview mode.";
}
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate(int opColor) {
PixelXorXfermode_Delegate newDelegate = new PixelXorXfermode_Delegate();
return sManager.addNewDelegate(newDelegate);
}
// ---- Private delegate/helper methods ----
}

View File

@@ -178,6 +178,7 @@ public class VectorDrawable_Delegate {
properties.putInt(VFullPath_Delegate.STROKE_LINE_JOIN_INDEX * 4, path.getStrokeLineJoin());
properties.putFloat(VFullPath_Delegate.STROKE_MITER_LIMIT_INDEX * 4,
path.getStrokeMiterlimit());
properties.putInt(VFullPath_Delegate.FILL_TYPE_INDEX * 4, path.getFillType());
return true;
}
@@ -186,7 +187,7 @@ public class VectorDrawable_Delegate {
static void nUpdateFullPathProperties(long pathPtr, float strokeWidth,
int strokeColor, float strokeAlpha, int fillColor, float fillAlpha, float trimPathStart,
float trimPathEnd, float trimPathOffset, float strokeMiterLimit, int strokeLineCap,
int strokeLineJoin) {
int strokeLineJoin, int fillType) {
VFullPath_Delegate path = VNativeObject.getDelegate(pathPtr);
path.setStrokeWidth(strokeWidth);
@@ -200,6 +201,7 @@ public class VectorDrawable_Delegate {
path.setStrokeMiterlimit(strokeMiterLimit);
path.setStrokeLineCap(strokeLineCap);
path.setStrokeLineJoin(strokeLineJoin);
path.setFillType(fillType);
}
@LayoutlibDelegate
@@ -530,6 +532,7 @@ public class VectorDrawable_Delegate {
private static final int STROKE_LINE_CAP_INDEX = 8;
private static final int STROKE_LINE_JOIN_INDEX = 9;
private static final int STROKE_MITER_LIMIT_INDEX = 10;
private static final int FILL_TYPE_INDEX = 11;
private static final int LINECAP_BUTT = 0;
private static final int LINECAP_ROUND = 1;
@@ -590,6 +593,8 @@ public class VectorDrawable_Delegate {
Join mStrokeLineJoin = MITER;
float mStrokeMiterlimit = 4;
int mFillType = 0; // WINDING(0) is the default value. See Path.FillType
private VFullPath_Delegate() {
// Empty constructor.
}
@@ -612,6 +617,7 @@ public class VectorDrawable_Delegate {
mStrokeGradient = copy.mStrokeGradient;
mFillGradient = copy.mFillGradient;
mFillType = copy.mFillType;
}
private int getStrokeLineCap() {
@@ -755,6 +761,14 @@ public class VectorDrawable_Delegate {
private void setFillGradient(long gradientPtr) {
mFillGradient = gradientPtr;
}
private void setFillType(int fillType) {
mFillType = fillType;
}
private int getFillType() {
return mFillType;
}
}
static class VGroup_Delegate implements VNativeObject {
@@ -1124,6 +1138,7 @@ public class VectorDrawable_Delegate {
assert fillPaintDelegate != null;
fillPaintDelegate.setColorFilter(filterPtr);
fillPaintDelegate.setShader(fullPath.mFillGradient);
Path_Delegate.native_setFillType(mRenderPath.mNativePath, fullPath.mFillType);
Canvas_Delegate.native_drawPath(canvasPtr, mRenderPath.mNativePath, fillPaint
.getNativeInstance());
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@@ -63,6 +63,25 @@
android:fillColor="@color/gradient"
android:pathData="M-20,-20 l0, 10 l10, 0 l0, -10 l-10,0 "
/>
<!--
Draw squares with different fill types
-->
<path
android:fillType="evenOdd"
android:strokeWidth="1"
android:strokeColor="#AABBCC"
android:fillColor="#AAEFCC"
android:pathData="M-20,-40 l0, 10 l10, 0 l0, -10 l-10,0 m5,0 l0, 10 l10, 0 l0, -10 l-10,0"
/>
<path
android:fillType="nonZero"
android:strokeWidth="1"
android:strokeColor="#AABBCC"
android:fillColor="#AAEFCC"
android:pathData="M0,-40 l0, 10 l10, 0 l0, -10 l-10,0 m5,0 l0, 10 l10, 0 l0, -10 l-10,0"
/>
</group>
</vector>

View File

@@ -256,7 +256,6 @@ public final class CreateInfo implements ICreateInfo {
*/
public final static String[] DELEGATE_CLASS_NATIVES = new String[] {
"android.animation.PropertyValuesHolder",
"android.graphics.AvoidXfermode",
"android.graphics.Bitmap",
"android.graphics.BitmapFactory",
"android.graphics.BitmapShader",
@@ -284,7 +283,6 @@ public final class CreateInfo implements ICreateInfo {
"android.graphics.PathDashPathEffect",
"android.graphics.PathEffect",
"android.graphics.PathMeasure",
"android.graphics.PixelXorXfermode",
"android.graphics.PorterDuffColorFilter",
"android.graphics.PorterDuffXfermode",
"android.graphics.RadialGradient",