Merge "Layoutlib native delegate: path effects and xfermode."
This commit is contained in:
committed by
Android (Google) Code Review
commit
de2dfc91e6
@@ -970,6 +970,8 @@ public class Canvas_Delegate {
|
||||
Graphics2D g = getGraphics2d();
|
||||
g = (Graphics2D)g.create();
|
||||
|
||||
// configure it
|
||||
|
||||
if (paint.isAntiAliased()) {
|
||||
g.setRenderingHint(
|
||||
RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
@@ -977,54 +979,15 @@ public class Canvas_Delegate {
|
||||
RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
}
|
||||
|
||||
// configure it
|
||||
g.setColor(new Color(paint.getColor()));
|
||||
int alpha = paint.getAlpha();
|
||||
float falpha = alpha / 255.f;
|
||||
boolean useColorPaint = true;
|
||||
|
||||
int style = paint.getStyle();
|
||||
if (style == Paint.Style.STROKE.nativeInt ||
|
||||
style == Paint.Style.FILL_AND_STROKE.nativeInt) {
|
||||
/* FIXME
|
||||
PathEffect e = paint.getPathEffect();
|
||||
if (e instanceof DashPathEffect) {
|
||||
DashPathEffect dpe = (DashPathEffect)e;
|
||||
g.setStroke(new BasicStroke(
|
||||
paint.getStrokeWidth(),
|
||||
paint.getStrokeCap().getJavaCap(),
|
||||
paint.getStrokeJoin().getJavaJoin(),
|
||||
paint.getStrokeMiter(),
|
||||
dpe.getIntervals(),
|
||||
dpe.getPhase()));
|
||||
} else {*/
|
||||
g.setStroke(new BasicStroke(
|
||||
paint.getStrokeWidth(),
|
||||
paint.getJavaCap(),
|
||||
paint.getJavaJoin(),
|
||||
paint.getStrokeMiter()));
|
||||
/* }*/
|
||||
}
|
||||
/*
|
||||
Xfermode xfermode = paint.getXfermode();
|
||||
if (xfermode instanceof PorterDuffXfermode) {
|
||||
PorterDuff.Mode mode = ((PorterDuffXfermode)xfermode).getMode();
|
||||
|
||||
setModeInGraphics(mode, g, falpha);
|
||||
} else {
|
||||
if (mLogger != null && xfermode != null) {
|
||||
mLogger.warning(String.format(
|
||||
"Xfermode '%1$s' is not supported in the Layout Editor.",
|
||||
xfermode.getClass().getCanonicalName()));
|
||||
}
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
|
||||
}
|
||||
*/
|
||||
int nativeShader = paint.getShader();
|
||||
Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(nativeShader);
|
||||
// get the shader first, as it'll replace the color if it can be used it.
|
||||
Shader_Delegate shaderDelegate = Shader_Delegate.getDelegate(paint.getShader());
|
||||
if (shaderDelegate != null) {
|
||||
java.awt.Paint shaderPaint = shaderDelegate.getJavaPaint();
|
||||
if (shaderPaint != null) {
|
||||
g.setPaint(shaderPaint);
|
||||
useColorPaint = false;
|
||||
} else {
|
||||
if (mLogger != null) {
|
||||
mLogger.warning(String.format(
|
||||
@@ -1034,6 +997,59 @@ public class Canvas_Delegate {
|
||||
}
|
||||
}
|
||||
|
||||
// need to get the alpha to set it in the composite.
|
||||
float falpha = 1.f;
|
||||
|
||||
if (useColorPaint) {
|
||||
g.setColor(new Color(paint.getColor()));
|
||||
|
||||
// the alpha is taken from the alpha channel of the color
|
||||
int alpha = paint.getAlpha();
|
||||
falpha = alpha / 255.f;
|
||||
}
|
||||
|
||||
int style = paint.getStyle();
|
||||
if (style == Paint.Style.STROKE.nativeInt ||
|
||||
style == Paint.Style.FILL_AND_STROKE.nativeInt) {
|
||||
|
||||
PathEffect_Delegate effectDelegate = PathEffect_Delegate.getDelegate(
|
||||
paint.getPathEffect());
|
||||
|
||||
if (effectDelegate instanceof DashPathEffect_Delegate) {
|
||||
DashPathEffect_Delegate dpe = (DashPathEffect_Delegate)effectDelegate;
|
||||
g.setStroke(new BasicStroke(
|
||||
paint.getStrokeWidth(),
|
||||
paint.getJavaCap(),
|
||||
paint.getJavaJoin(),
|
||||
paint.getStrokeMiter(),
|
||||
dpe.getIntervals(),
|
||||
dpe.getPhase()));
|
||||
} else {
|
||||
g.setStroke(new BasicStroke(
|
||||
paint.getStrokeWidth(),
|
||||
paint.getJavaCap(),
|
||||
paint.getJavaJoin(),
|
||||
paint.getStrokeMiter()));
|
||||
}
|
||||
}
|
||||
|
||||
Xfermode_Delegate xfermodeDelegate = Xfermode_Delegate.getDelegate(paint.getXfermode());
|
||||
if (xfermodeDelegate instanceof PorterDuffXfermode_Delegate) {
|
||||
int mode = ((PorterDuffXfermode_Delegate)xfermodeDelegate).getMode();
|
||||
|
||||
setModeInGraphics(g, mode, falpha);
|
||||
} else {
|
||||
// default mode is src_over
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, falpha));
|
||||
|
||||
// if xfermode wasn't null, then it's something we don't support. log it.
|
||||
if (mLogger != null && xfermodeDelegate != null) {
|
||||
mLogger.warning(String.format(
|
||||
"Xfermode '%1$s' is not supported in the Layout Editor.",
|
||||
xfermodeDelegate.getClass().getCanonicalName()));
|
||||
}
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +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;
|
||||
|
||||
public class DashPathEffect extends PathEffect {
|
||||
|
||||
private final float[] mIntervals;
|
||||
private final float mPhase;
|
||||
|
||||
/**
|
||||
* The intervals array must contain an even number of entries (>=2), with
|
||||
* the even indices specifying the "on" intervals, and the odd indices
|
||||
* specifying the "off" intervals. phase is an offset into the intervals
|
||||
* array (mod the sum of all of the intervals). The intervals array
|
||||
* controls the length of the dashes. The paint's strokeWidth controls the
|
||||
* thickness of the dashes.
|
||||
* Note: this patheffect only affects drawing with the paint's style is set
|
||||
* to STROKE or STROKE_AND_FILL. It is ignored if the drawing is done with
|
||||
* style == FILL.
|
||||
* @param intervals array of ON and OFF distances
|
||||
* @param phase offset into the intervals array
|
||||
*/
|
||||
public DashPathEffect(float intervals[], float phase) {
|
||||
if (intervals.length < 2) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
mIntervals = intervals;
|
||||
mPhase = phase;
|
||||
}
|
||||
|
||||
public float[] getIntervals() {
|
||||
return mIntervals;
|
||||
}
|
||||
|
||||
public float getPhase() {
|
||||
return mPhase;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.DelegateManager;
|
||||
|
||||
/**
|
||||
* Delegate implementing the native methods of android.graphics.DashPathEffect
|
||||
*
|
||||
* Through the layoutlib_create tool, the original native methods of DashPathEffect 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 DashPathEffect class.
|
||||
*
|
||||
* Because this extends {@link PathEffect_Delegate}, there's no need to use a
|
||||
* {@link DelegateManager}, as all the PathEffect classes will be added to the manager owned by
|
||||
* {@link PathEffect_Delegate}.
|
||||
*
|
||||
*/
|
||||
public class DashPathEffect_Delegate extends PathEffect_Delegate {
|
||||
|
||||
// ---- delegate data ----
|
||||
|
||||
private final float[] mIntervals;
|
||||
private final float mPhase;
|
||||
|
||||
// ---- Public Helper methods ----
|
||||
|
||||
public float[] getIntervals() {
|
||||
return mIntervals;
|
||||
}
|
||||
|
||||
public float getPhase() {
|
||||
return mPhase;
|
||||
}
|
||||
|
||||
// ---- native methods ----
|
||||
|
||||
/*package*/ static int nativeCreate(float intervals[], float phase) {
|
||||
DashPathEffect_Delegate newDelegate = new DashPathEffect_Delegate(intervals, phase);
|
||||
return sManager.addDelegate(newDelegate);
|
||||
}
|
||||
|
||||
// ---- Private delegate/helper methods ----
|
||||
|
||||
private DashPathEffect_Delegate(float intervals[], float phase) {
|
||||
mIntervals = new float[intervals.length];
|
||||
System.arraycopy(intervals, 0, mIntervals, 0, intervals.length);
|
||||
mPhase = phase;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.DelegateManager;
|
||||
|
||||
/**
|
||||
* Delegate implementing the native methods of android.graphics.PathEffect
|
||||
*
|
||||
* Through the layoutlib_create tool, the original native methods of PathEffect 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 PathEffect class.
|
||||
*
|
||||
* This also serve as a base class for all PathEffect delegate classes.
|
||||
*
|
||||
* @see DelegateManager
|
||||
*
|
||||
*/
|
||||
public class PathEffect_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<PathEffect_Delegate> sManager =
|
||||
new DelegateManager<PathEffect_Delegate>();
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
// ---- delegate data ----
|
||||
|
||||
// ---- Public Helper methods ----
|
||||
|
||||
public static PathEffect_Delegate getDelegate(int nativeShader) {
|
||||
return sManager.getDelegate(nativeShader);
|
||||
}
|
||||
|
||||
// ---- native methods ----
|
||||
|
||||
/*package*/ static void nativeDestructor(int native_patheffect) {
|
||||
sManager.removeDelegate(native_patheffect);
|
||||
}
|
||||
|
||||
// ---- Private delegate/helper methods ----
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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 android.graphics.PorterDuff.Mode;
|
||||
|
||||
public class PorterDuffXfermode extends Xfermode {
|
||||
private final Mode mMode;
|
||||
|
||||
/**
|
||||
* Create an xfermode that uses the specified porter-duff mode.
|
||||
*
|
||||
* @param mode The porter-duff mode that is applied
|
||||
*/
|
||||
public PorterDuffXfermode(PorterDuff.Mode mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
//---------- Custom Methods
|
||||
|
||||
public PorterDuff.Mode getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
//----------
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.DelegateManager;
|
||||
|
||||
/**
|
||||
* Delegate implementing the native methods of android.graphics.PorterDuffXfermode
|
||||
*
|
||||
* Through the layoutlib_create tool, the original native methods of PorterDuffXfermode 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 PorterDuffXfermode 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 PorterDuffXfermode_Delegate extends Xfermode_Delegate {
|
||||
|
||||
// ---- delegate data ----
|
||||
|
||||
private final int mMode;
|
||||
|
||||
// ---- Public Helper methods ----
|
||||
|
||||
public int getMode() {
|
||||
return mMode;
|
||||
}
|
||||
|
||||
// ---- native methods ----
|
||||
|
||||
/*package*/ static int nativeCreateXfermode(int mode) {
|
||||
PorterDuffXfermode_Delegate newDelegate = new PorterDuffXfermode_Delegate(mode);
|
||||
return sManager.addDelegate(newDelegate);
|
||||
}
|
||||
|
||||
// ---- Private delegate/helper methods ----
|
||||
|
||||
private PorterDuffXfermode_Delegate(int mode) {
|
||||
mMode = mode;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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.DelegateManager;
|
||||
|
||||
/**
|
||||
* Delegate implementing the native methods of android.graphics.Xfermode
|
||||
*
|
||||
* Through the layoutlib_create tool, the original native methods of Xfermode 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 Xfermode class.
|
||||
*
|
||||
* This also serve as a base class for all Xfermode delegate classes.
|
||||
*
|
||||
* @see DelegateManager
|
||||
*
|
||||
*/
|
||||
public class Xfermode_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<Xfermode_Delegate> sManager =
|
||||
new DelegateManager<Xfermode_Delegate>();
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
// ---- delegate data ----
|
||||
|
||||
// ---- Public Helper methods ----
|
||||
|
||||
public static Xfermode_Delegate getDelegate(int native_instance) {
|
||||
return sManager.getDelegate(native_instance);
|
||||
}
|
||||
|
||||
// ---- native methods ----
|
||||
|
||||
/*package*/ static void finalizer(int native_instance) {
|
||||
sManager.removeDelegate(native_instance);
|
||||
}
|
||||
|
||||
// ---- Private delegate/helper methods ----
|
||||
|
||||
}
|
||||
@@ -105,13 +105,17 @@ public final class CreateInfo implements ICreateInfo {
|
||||
private final static String[] DELEGATE_CLASS_NATIVES = new String[] {
|
||||
"android.graphics.Bitmap",
|
||||
"android.graphics.Canvas",
|
||||
"android.graphics.DashPathEffect",
|
||||
"android.graphics.LinearGradient",
|
||||
"android.graphics.Matrix",
|
||||
"android.graphics.Paint",
|
||||
"android.graphics.PathEffect",
|
||||
"android.graphics.PorterDuffXfermode",
|
||||
"android.graphics.RadialGradient",
|
||||
"android.graphics.Shader",
|
||||
"android.graphics.SweepGradient",
|
||||
"android.graphics.Typeface",
|
||||
"android.graphics.Xfermode",
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -131,9 +135,7 @@ public final class CreateInfo implements ICreateInfo {
|
||||
private final static String[] RENAMED_CLASSES =
|
||||
new String[] {
|
||||
"android.graphics.BitmapFactory", "android.graphics._Original_BitmapFactory",
|
||||
"android.graphics.DashPathEffect", "android.graphics._Original_DashPathEffect",
|
||||
"android.graphics.Path", "android.graphics._Original_Path",
|
||||
"android.graphics.PorterDuffXfermode", "android.graphics._Original_PorterDuffXfermode",
|
||||
"android.os.ServiceManager", "android.os._Original_ServiceManager",
|
||||
"android.util.FloatMath", "android.util._Original_FloatMath",
|
||||
"android.view.SurfaceView", "android.view._Original_SurfaceView",
|
||||
|
||||
Reference in New Issue
Block a user