浏览代码

refine codes

/main
xingwei.zhu 5 年前
当前提交
9e7fd908
共有 8 个文件被更改,包括 52 次插入54 次删除
  1. 2
      Runtime/engine/UIWidgetsPanel.cs
  2. 15
      Runtime/ui/geometry.cs
  3. 25
      Runtime/ui/painting/path.cs
  4. 27
      Runtime/ui/painting/shadow_utils.cs
  5. 3
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  6. 2
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
  7. 6
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs
  8. 26
      Runtime/ui/renderer/common/geometry/path/path.cs

2
Runtime/engine/UIWidgetsPanel.cs


this._needsPaint = true;
}
this._needsPaint = true;
if (evt.type == EventType.Repaint) {
if (!this._needsPaint) {
return;

15
Runtime/ui/geometry.cs


get { return this.brRadius.y; }
}
public bool isNaiveRRect {
get {
var radius = this.tlRadiusX;
return this.tlRadiusY == radius &&
this.trRadiusX == radius &&
this.trRadiusY == radius &&
this.blRadiusX == radius &&
this.blRadiusY == radius &&
this.brRadiusX == radius &&
this.brRadiusY == radius &&
radius <= this.width / 2 &&
radius <= this.height / 2;
}
}
public static readonly RRect zero = new RRect(0, 0, 0, 0, (Radius) null);
public RRect shift(Offset offset) {

25
Runtime/ui/painting/path.cs


uint _pathKey = 0;
bool _isRRect = false;
public bool isRRect => this._isRRect;
//shadow speeder relevant
bool _isNaiveRRect = false;
public bool isNaiveRRect => this._isNaiveRRect;
float _rCorner;
public float rCorner => this._rCorner;
float _rRectCorner;
public float rRectCorner => this._rRectCorner;
public uint pathKey {
get {

public List<float> commands => this._commands;
void _updateRRectFlag(bool isRRect, PathShapeHint shapeHint = PathShapeHint.Other, float corner = 0) {
if (this._commands.Count > 0 && !this._isRRect) {
void _updateRRectFlag(bool isNaiveRRect, PathShapeHint shapeHint = PathShapeHint.Other, float corner = 0) {
if (this._commands.Count > 0 && !this._isNaiveRRect) {
this._isRRect = isRRect && this._hasOnlyMoveTos();
if (this._isRRect) {
this._isNaiveRRect = isNaiveRRect && this._hasOnlyMoveTos();
if (this._isNaiveRRect) {
this._rCorner = corner;
this._rRectCorner = corner;
}
}

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

}
public void addRRect(RRect rrect) {
this._updateRRectFlag(rrect.isNaiveRRect, PathShapeHint.NaiveRRect, rrect.blRadiusX);
this._updateRRectFlag(rrect.isNaiveRRect(), PathShapeHint.NaiveRRect, rrect.blRadiusX);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

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

27
Runtime/ui/painting/shadow_utils.cs


//debug shadow
if (debugShadow) {
var isRRect = path.isRRect;
var isRRect = path.isNaiveRRect;
if (isRRect) {
ambientColor = uiColor.fromColor(Colors.red);
spotColor = uiColor.fromColor(Colors.red);

_shadowPaint.strokeWidth = 0;
_shadowPaint.style = PaintingStyle.fill;
float sigma2 = convertRadiusToSigma(radius);
_shadowPaint.maskFilter = path.isRRect ? MaskFilter.fastShadow(sigma2) : MaskFilter.blur(BlurStyle.normal, sigma2);
_shadowPaint.maskFilter = path.isNaiveRRect ? MaskFilter.fastShadow(sigma2) : MaskFilter.blur(BlurStyle.normal, sigma2);
canvas.drawPath(path, _shadowPaint);
canvas.restore();

float blurRadius = 0.5f * devSpaceOutset * oneOverA;
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius);
//Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill};
_shadowPaint.color = new Color(ambientColor.value);
_shadowPaint.strokeWidth = strokeWidth;
_shadowPaint.style = PaintingStyle.fill;

canvas.save();
canvas.setMatrix(_shadowMatrix);
//Paint paint2 = new Paint {color = spotColor};
_shadowPaint.color = new Color(spotColor.value);
_shadowPaint.strokeWidth = 0;
_shadowPaint.style = PaintingStyle.fill;

}
/*
* Check whether the RRect is a naive Round-Rect, of which
* (1) all the corner radius are the same
* (2) the corner radius is not bigger than either half the width or the height of the Round Rect's bounding box
*
* Usage: The shadow of a naive Round-Rect can be easily drawn using a ShadowRBox shader, so we can use it to
* find all the situations that a fast shadow can be drawn to tackle the performance issue
*/
public static bool isNaiveRRect(this RRect rrect) {
var radius = rrect.tlRadiusX;
return rrect.tlRadiusY == radius &&
rrect.trRadiusX == radius &&
rrect.trRadiusY == radius &&
rrect.blRadiusX == radius &&
rrect.blRadiusY == radius &&
rrect.brRadiusX == radius &&
rrect.brRadiusY == radius &&
radius <= rrect.width / 2 &&
radius <= rrect.height / 2;
}
}
}

3
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


break;
case CmdDraw cmd:
if (cmd.material != CanvasShader.shadowBox) {
}
this._setRenderTarget(cmdBuf, layer.rtID, ref toClear);
if (cmd.layerId != null) {

2
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs


using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Rendering;

mat = _shadowRBox;
}
//use props to set all the uniforms !!!!!
var props = ObjectPool<MaterialPropertyBlockWrapper>.alloc();
props.SetVector(_viewportId, viewport);
props.SetFloat(_shadowSigmaId, sigma);

6
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs


public partial class PictureFlusher {
void _drawRRectShadow(uiPath path, uiPaint paint) {
D.assert(path.isRRect, () => "Cannot draw Shadow for non-RRect shapes");
D.assert(paint.style == PaintingStyle.fill, () => "Cannot draw Shadow for stroke lines");
D.assert(path.isNaiveRRect, () => "Cannot draw fast Shadow for non-NaiveRRect shapes");
D.assert(paint.style == PaintingStyle.fill, () => "Cannot draw fast Shadow for stroke lines");
var bound = path.getBounds();
if (!this._applyClip(bound)) {
return;

_triangles.Add(3);
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles);
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rRectCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
}
}

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


public uint pathKey = 0;
public bool needCache = false;
bool _isRRect = false;
public bool isRRect => this._isRRect;
bool _isNaiveRRect = false;
public bool isNaiveRRect => this._isNaiveRRect;
float _rCorner;
public float rCorner => this._rCorner;
float _rRectCorner;
public float rRectCorner => this._rRectCorner;
void _updateRRectFlag(bool isRRect, uiPathShapeHint shapeHint = uiPathShapeHint.Other, float corner = 0) {
if (this._commands.Count > 0 && !this._isRRect) {
void _updateRRectFlag(bool isNaiveRRect, uiPathShapeHint shapeHint = uiPathShapeHint.Other, float corner = 0) {
if (this._commands.Count > 0 && !this._isNaiveRRect) {
this._isRRect = isRRect && this._hasOnlyMoveTos();
if (this._isRRect) {
this._isNaiveRRect = isNaiveRRect && this._hasOnlyMoveTos();
if (this._isNaiveRRect) {
this._rCorner = corner;
this._rRectCorner = corner;
}
}

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

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

}
public void addRRect(RRect rrect) {
this._updateRRectFlag(rrect.isNaiveRRect, uiPathShapeHint.NaiveRRect, rrect.blRadiusX);
this._updateRRectFlag(rrect.isNaiveRRect(), uiPathShapeHint.NaiveRRect, rrect.blRadiusX);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

return uipath;
}
uipath._updateRRectFlag(path.isRRect, (uiPathShapeHint)path.shapeHint, path.rCorner);
uipath._updateRRectFlag(path.isNaiveRRect, (uiPathShapeHint)path.shapeHint, path.rRectCorner);
var i = 0;
var _commands = path.commands;

正在加载...
取消
保存