浏览代码

add isRRect to path/uipath

/main
xingwei.zhu 5 年前
当前提交
a1c9ae00
共有 5 个文件被更改,包括 183 次插入9 次删除
  1. 5
      Runtime/ui/painting/painting.cs
  2. 64
      Runtime/ui/painting/path.cs
  3. 68
      Runtime/ui/painting/shadow_utils.cs
  4. 53
      Runtime/ui/renderer/common/geometry/path/path.cs
  5. 2
      Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs

5
Runtime/ui/painting/painting.cs


solid,
outer,
inner,
shadow
}
public class MaskFilter : IEquatable<MaskFilter> {

public static MaskFilter blur(BlurStyle style, float sigma) {
return new MaskFilter(style, sigma);
}
public static MaskFilter shadow(float sigma) {
return new MaskFilter(BlurStyle.shadow, sigma);
}
public readonly BlurStyle style;

64
Runtime/ui/painting/path.cs


uint _pathKey = 0;
bool _isRRect = false;
public bool isRRect => this._isRRect;
public uint pathKey {
get {
return this._pathKey;

public List<float> commands => this._commands;
void _updateRRectFlag(bool isRRect) {
if (this._commands.Count > 0 && !this._isRRect) {
return;
}
this._isRRect = isRRect && this._hasOnlyMoveTos();
}
bool _hasOnlyMoveTos() {
var i = 0;
while (i < this._commands.Count) {
var cmd = (PathCommand) this._commands[i];
switch (cmd) {
case PathCommand.moveTo:
i += 3;
break;
case PathCommand.lineTo:
return false;
case PathCommand.bezierTo:
return false;
case PathCommand.close:
i++;
break;
case PathCommand.winding:
i += 2;
break;
default:
return false;
}
}
return true;
}
public override string ToString() {
var sb = new StringBuilder("Path: count = " + this._commands.Count);

this._pathKey = pathGlobalKey++;
this._cache = null;
this._isRRect = false;
}
internal PathCache flatten(float scale) {

public void relativeLineTo(float x, float y) {
var x0 = this._commandx;
var y0 = this._commandy;
this._updateRRectFlag(false);
this._updateRRectFlag(false);
this._updateRRectFlag(false);
this._appendBezierTo(c1x, c1y, c2x, c2y, x, y);
}

this._updateRRectFlag(false);
this.cubicTo(x0 + c1x, y0 + c1y, x0 + c2x, y0 + c2y, x0 + x, y0 + y);
}

const float twoThird = 2.0f / 3.0f;
this._updateRRectFlag(false);
this._appendBezierTo(
x0 + twoThird * (cx - x0), y0 + twoThird * (cy - y0),
x + twoThird * (cx - x), y + twoThird * (cy - y),

var x0 = this._commandx;
var y0 = this._commandy;
this._updateRRectFlag(false);
this._updateRRectFlag(false);
if (!(w > 0)) {
this.lineTo(x2, y2);
return;

public void relativeConicTo(float x1, float y1, float x2, float y2, float w) {
var x0 = this._commandx;
var y0 = this._commandy;
this._updateRRectFlag(false);
this.conicTo(x0 + x1, y0 + y1, x0 + x2, y0 + y2, w);
}

bool largeArc = false,
bool clockwise = false) {
radius = radius ?? Radius.zero;
this._updateRRectFlag(false);
D.assert(PaintingUtils._offsetIsValid(arcEnd));
D.assert(PaintingUtils._radiusIsValid(radius));

}
public void addRect(Rect rect) {
this._updateRRectFlag(true);
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);
this._appendLineTo(rect.right, rect.bottom);

public void addRRect(RRect rrect) {
this._updateRRectFlag(true);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

}
public void addEllipse(float cx, float cy, float rx, float ry) {
this._updateRRectFlag(true);
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,
cx - rx * _KAPPA90, cy + ry, cx, cy + ry);

}
public void addCircle(float cx, float cy, float r) {
this._updateRRectFlag(true);
this._updateRRectFlag(true);
this._updateRRectFlag(false);
var x0 = this._commandx;
var y0 = this._commandy;

}
public void arcTo(Rect rect, float startAngle, float sweepAngle, bool forceMoveTo = true) {
this._updateRRectFlag(false);
var mat = Matrix3.makeScale(rect.width / 2, rect.height / 2);
var center = rect.center;
mat.postTranslate(center.dx, center.dy);

}
public void addArc(Rect rect, float startAngle, float sweepAngle) {
this._updateRRectFlag(false);
this.arcTo(rect, startAngle, sweepAngle, true);
}

}
public void addArc(float cx, float cy, float r, float a0, float a1, PathWinding dir, bool forceMoveTo = true) {
this._updateRRectFlag(false);
this._updateRRectFlag(false);
D.assert(points != null);
if (points.Count == 0) {
return;

public void addPath(Path path, Matrix3 transform = null) {
D.assert(path != null);
this._updateRRectFlag(path.isRRect);
var i = 0;
while (i < path._commands.Count) {
var cmd = (PathCommand) path._commands[i];

68
Runtime/ui/painting/shadow_utils.cs


using Unity.UIWidgets.material;
public const bool kUseFastShadow = false;
public const bool kUseFastShadow = true;
const float kAmbientHeightFactor = 1.0f / 128.0f;
const float kAmbientGeomFactor = 64.0f;

const float kMaxAmbientRadius = 300 * kAmbientHeightFactor * kAmbientGeomFactor;
const bool debugShadow = true;
static float divideAndPin(float numer, float denom, float min, float max) {
return (numer / denom).clamp(min, max);

public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
if (kUseFastShadow) {
drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
drawShadowFull2(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
}
else {
drawShadowFull(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);

//spot light
//Matrix3 shadowMatrix = Matrix3.I();
float radius = 0.0f;
if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
_shadowMatrix, ref radius)) {
return;
}
canvas.save();
canvas.setMatrix(_shadowMatrix);
_shadowPaint.color = new Color(spotColor.value);
_shadowPaint.strokeWidth = 0;
_shadowPaint.style = PaintingStyle.fill;
float sigma2 = convertRadiusToSigma(radius);
_shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2);
canvas.drawPath(path, _shadowPaint);
canvas.restore();
_shadowPaint.maskFilter = null;
}
static void drawShadowFull2(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//debug shadow
if (debugShadow) {
var isRRect = path.isRRect;
if (isRRect) {
ambientColor = uiColor.fromColor(Colors.red);
spotColor = uiColor.fromColor(Colors.red);
}
else {
ambientColor = uiColor.fromColor(Colors.green);
spotColor = uiColor.fromColor(Colors.green);
}
}
//ambient light
_devSpacePath.resetAll();
_devSpacePath.addPath(path, viewMatrix);
float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
float oneOverA = ambientRecipAlpha(zPlaneParams.z);
float blurRadius = 0.5f * devSpaceOutset * oneOverA;
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius);
_shadowPaint.color = new Color(ambientColor.value);
_shadowPaint.strokeWidth = strokeWidth;
_shadowPaint.style = PaintingStyle.fill;
canvas.save();
_shadowMatrix.reset();
canvas.setMatrix(_shadowMatrix);
float sigma = convertRadiusToSigma(blurRadius);
_shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma);
canvas.drawPath(_devSpacePath, _shadowPaint);
canvas.restore();
//spot light
float radius = 0.0f;
if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),

53
Runtime/ui/renderer/common/geometry/path/path.cs


public uint pathKey = 0;
public bool needCache = false;
bool _isRRect = false;
public bool isRRect => this._isRRect;
void _updateRRectFlag(bool isRRect) {
if (this._commands.Count > 0 && !this._isRRect) {
return;
}
this._isRRect = isRRect && this._hasOnlyMoveTos();
if (!this._isRRect) {
int s = 0;
}
}
bool _hasOnlyMoveTos() {
var i = 0;
while (i < this._commands.Count) {
var cmd = (PathCommand) this._commands[i];
switch (cmd) {
case PathCommand.moveTo:
i += 3;
break;
case PathCommand.lineTo:
return false;
case PathCommand.bezierTo:
return false;
case PathCommand.close:
i++;
break;
case PathCommand.winding:
i += 2;
break;
default:
return false;
}
}
return true;
}
public static uiPath create(int capacity = 128) {
uiPath newPath = ObjectPool<uiPath>.alloc();

this.needCache = false;
this.pathKey = 0;
this._isRRect = false;
}
void _reset() {

this._maxY = float.MinValue;
ObjectPool<uiPathCache>.release(this._cache);
this._cache = null;
this._isRRect = false;
}
internal uiPathCache flatten(float scale) {

}
public void addRect(uiRect rect) {
this._updateRRectFlag(true);
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);
this._appendLineTo(rect.right, rect.bottom);

public void addRect(Rect rect) {
this._updateRRectFlag(true);
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);
this._appendLineTo(rect.right, rect.bottom);

public void addRRect(RRect rrect) {
this._updateRRectFlag(true);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

}
public void lineTo(float x, float y) {
this._updateRRectFlag(false);
this._appendLineTo(x, y);
}

public void addEllipse(float cx, float cy, float rx, float ry) {
this._updateRRectFlag(true);
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,
cx - rx * _KAPPA90, cy + ry, cx, cy + ry);

}
public void addCircle(float cx, float cy, float r) {
this._updateRRectFlag(true);
this._updateRRectFlag(false);
var mat = Matrix3.makeScale(rect.width / 2, rect.height / 2);
var center = rect.center;
mat.postTranslate(center.dx, center.dy);

if (exists) {
return uipath;
}
uipath._updateRRectFlag(path.isRRect);
var i = 0;
var _commands = path.commands;
while (i < _commands.Count) {

2
Runtime/ui/renderer/compositeCanvas/flow/physical_shape_layer.cs


const float kAmbientAlpha = 0.039f;
const float kLightHeight = 600f;
const float kLightRadius = 800f;
const float kSpotAlpha = ShadowUtils.kUseFastShadow ? 0.1f : 0.25f;
const float kSpotAlpha = 0.25f;
public static void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder,
float dpr) {

正在加载...
取消
保存