Path.FillType.INVERSE_WINDING在HardwareAccelerated View中不起作用

时间:2017-03-22 06:49:36

标签: android path android-canvas android-custom-view hardware-acceleration

我正在尝试使用INVERSE_WINDING绘制一个Rectangle。这在LAYER_TYPE_SOFTWARE的情况下按预期工作,但在硬件加速的情况下很奇怪。以下是结果:

Hardware Accelerated Result Software Accelerated Result

CODE:

public class PathView extends View {

private final Paint mPaint;

public PathView(Context context) {
    this(context, null, 0);
}

public PathView(Context context, @Nullable AttributeSet attrs) {
    this(context, attrs, 0);
}

public PathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    // setLayerType(LAYER_TYPE_SOFTWARE, null); // Toggle this!!!
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(Color.RED);
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    final Path path = new Path();
    path.addRect(50,50,400,400, Path.Direction.CCW); // CCW or CW, same result
    path.close(); // same result even if I didn't close the path
    path.setFillType(Path.FillType.INVERSE_WINDING);
    canvas.drawPath(path, mPaint);
}
}

Android为什么会这样?我阅读了What can't be done in Hardware Acceleration上的文档,但它从未提及Path.FillType上的任何内容。

如何在硬件加速中也获得相同的行为?

0 个答案:

没有答案