浏览代码

composite context => using ui-version objects

/main
xingwei.zhu 5 年前
当前提交
c4eb6034
共有 11 个文件被更改,包括 250 次插入106 次删除
  1. 30
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  2. 51
      Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_utils.cs
  3. 12
      Runtime/ui/utils/renderer/common/base_canvas.cs
  4. 88
      Runtime/ui/utils/renderer/common/picture.cs
  5. 70
      Runtime/ui/utils/renderer/geometry/matrix/ui_matrix.cs
  6. 2
      Runtime/ui/utils/renderer/geometry/path/path.cs
  7. 31
      Runtime/ui/utils/renderer/geometry/rect.cs
  8. 8
      Runtime/flow.meta
  9. 53
      Runtime/ui/utils/renderer/common/utils.cs
  10. 11
      Runtime/ui/utils/renderer/common/utils.cs.meta

30
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_impl.cs


void _clipRect(Rect rect) {
var path = uiPath.create();
path.addRect(uiRectHelper.fromRect(rect));
this._clipPath(path);
}
void _clipUIRect(uiRect rect) {
var path = uiPath.create();
path.addRect(rect);
this._clipPath(path);
}

break;
case uiDrawSaveLayer cmd: {
saveCount++;
this._saveLayer(uiRectHelper.fromRect(cmd.rect), cmd.paint);
this._saveLayer(cmd.rect.Value, cmd.paint);
break;
}
case uiDrawRestore _: {

break;
}
case uiDrawRotate cmd: {
this._rotate(cmd.radians, uiOffset.fromOffset(cmd.offset));
this._rotate(cmd.radians, cmd.offset);
break;
}
case uiDrawSkew cmd: {

case uiDrawConcat cmd: {
this._concat(uiMatrix3.fromMatrix3(cmd.matrix));
this._concat(cmd.matrix.Value);
break;
}
case uiDrawResetMatrix _:

this._setMatrix(uiMatrix3.fromMatrix3(cmd.matrix));
this._setMatrix(cmd.matrix.Value);
this._clipRect(cmd.rect);
this._clipUIRect(cmd.rect.Value);
break;
}
case uiDrawClipRRect cmd: {

case uiDrawClipPath cmd: {
var uipath = uiPath.fromPath(cmd.path);
this._clipPath(uipath);
this._clipPath(cmd.path);
var uipath = uiPath.fromPath(cmd.path);
this._drawPath(uipath, cmd.paint);
this._drawPath(cmd.path, cmd.paint);
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
this._drawImage(cmd.image, cmd.offset.Value, cmd.paint);
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst), cmd.paint);
this._drawImageRect(cmd.image, cmd.src, cmd.dst.Value, cmd.paint);
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.center), uiRectHelper.fromRect(cmd.dst), cmd.paint);
this._drawImageNine(cmd.image, cmd.src, cmd.center.Value, cmd.dst.Value, cmd.paint);
break;
}
case uiDrawPicture cmd: {

case uiDrawTextBlob cmd: {
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, cmd.paint);
this._drawTextBlob(cmd.textBlob, cmd.offset.Value, cmd.paint);
break;
}
default:

51
Runtime/ui/utils/renderer/cmdbufferCanvas/rendering/canvas_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
static class uiXformUtils {
public static float getScaleX(uiMatrix3 matrix) {
// ignore perspective parameters for now.
if (matrix.isIdentity()) {
return 1.0f;
}
if (matrix.getSkewY() == 0) {
return matrix.getScaleX();
}
var x = matrix.getScaleX();
var y = matrix.getSkewY();
return Mathf.Sqrt(x * x + y * y);
}
public static float getScaleY(uiMatrix3 matrix) {
// ignore perspective parameters for now.
if (matrix.isIdentity()) {
return 1.0f;
}
if (matrix.getSkewX() == 0) {
return matrix.getScaleY();
}
var x = matrix.getSkewX();
var y = matrix.getScaleY();
return Mathf.Sqrt(x * x + y * y);
}
public static float getScale(uiMatrix3 matrix) {
var scaleX = getScaleX(matrix);
var scaleY = getScaleY(matrix);
if (scaleX == 1.0) {
return scaleY;
}
if (scaleY == 1.0) {
return scaleX;
}
// geometric mean of len0 and len1.
return Mathf.Sqrt(scaleX * scaleY);
}
}
static class BlurUtils {
static readonly Dictionary<_GaussianKernelKey, float[]> _gaussianKernels
= new Dictionary<_GaussianKernelKey, float[]>();

12
Runtime/ui/utils/renderer/common/base_canvas.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public class uiRecorderCanvas : PoolItem {
public class uiRecorderCanvas : PoolItem, Canvas {
public uiRecorderCanvas(uiPictureRecorder recorder) {
this._recorder = recorder;
}

));
}
public uiMatrix3 getTotalMatrix() {
return this._recorder.getTotalMatrix();
readonly Matrix3 _totalMatrix = Matrix3.I();
public Matrix3 getTotalMatrix() {
var localMatrix = this._recorder.getTotalMatrix();
this._totalMatrix.setAll(localMatrix.kMScaleX, localMatrix.kMSkewX, localMatrix.kMTransX,
localMatrix.kMSkewY, localMatrix.kMScaleY, localMatrix.kMTransY,
localMatrix.kMPersp0, localMatrix.kMPersp1, localMatrix.kMPersp2);
return this._totalMatrix;
}
public void resetMatrix() {

88
Runtime/ui/utils/renderer/common/picture.cs


case uiDrawSaveLayer cmd: {
this._states.Add(new uiCanvasState {
xform = uiMatrix3.I(),
scissor = cmd.rect.shift(-cmd.rect.Value.topLeft),
scissor = cmd.rect.Value.shift(-cmd.rect.Value.topLeft),
paintBounds = uiRectHelper.zero,
paintBounds = uiRectHelper.zero
});
break;
}

if (!stateToRestore.saveLayer) {
state.paintBounds = stateToRestore.paintBounds;
} else {
var paintBounds = stateToRestore.paintBounds.shift(stateToRestore.layerOffset);
var paintBounds = stateToRestore.paintBounds.shift(stateToRestore.layerOffset.Value);
paintBounds = state.xform.mapRect(paintBounds);
this._addPaintBounds(paintBounds);
}

var state = this._getState();
state.xform = new Matrix3(state.xform);
state.xform = new uiMatrix3(state.xform);
state.xform = new Matrix3(state.xform);
state.xform = new uiMatrix3(state.xform);
state.xform = new Matrix3(state.xform);
state.xform = new uiMatrix3(state.xform);
cmd.offset.dx,
cmd.offset.dy);
cmd.offset.Value.dx,
cmd.offset.Value.dy);
state.xform = new Matrix3(state.xform);
state.xform = new uiMatrix3(state.xform);
state.xform = new Matrix3(state.xform);
state.xform.preConcat(cmd.matrix);
state.xform = new uiMatrix3(state.xform);
state.xform.preConcat(cmd.matrix.Value);
state.xform = Matrix3.I();
state.xform = uiMatrix3.I();
state.xform = new Matrix3(cmd.matrix);
state.xform = new uiMatrix3(cmd.matrix.Value);
var rect = state.xform.mapRect(cmd.rect);
state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
var rect = state.xform.mapRect(cmd.rect.Value);
state.scissor = state.scissor == null ? rect : state.scissor.Value.intersect(rect);
var rect = state.xform.mapRect(cmd.rrect.outerRect);
state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
var rect = state.xform.mapRect(uiRectHelper.fromRect(cmd.rrect.outerRect));
state.scissor = state.scissor == null ? rect : state.scissor.Value.intersect(rect);
var scale = XformUtils.getScale(state.xform);
var scale = uiXformUtils.getScale(state.xform);
var rect = cmd.path.flatten(
scale * Window.instance.devicePixelRatio
).getFillMesh(out _).transform(state.xform).bounds;
state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
var rectPathCache = cmd.path.flatten(
scale * Window.instance.devicePixelRatio);
var rectMesh = rectPathCache.getFillMesh(out _);
var transformedMesh = rectMesh.transform(state.xform);
var rect = transformedMesh.bounds;
state.scissor = state.scissor == null ? rect : state.scissor.Value.intersect(rect);
rectPathCache.dispose();
rectMesh.dispose();
transformedMesh.dispose();
var scale = XformUtils.getScale(state.xform);
var scale = uiXformUtils.getScale(state.xform);
MeshMesh mesh;
uiMeshMesh mesh;
cache.dispose();
} else {
float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f);
float fringeWidth = 1 / devicePixelRatio;

}
var cache = path.flatten(scale * devicePixelRatio);
mesh = cache.getStrokeMesh(
var strokenMesh = cache.getStrokeMesh(
paint.strokeMiterLimit).transform(state.xform);
paint.strokeMiterLimit);
mesh = strokenMesh.transform(state.xform);
cache.dispose();
strokenMesh.dispose();
this._addPaintBounds(mesh.bounds.inflate(sigma3));
this._addPaintBounds(uiRectHelper.inflate(mesh.bounds, sigma3));
} else {
this._addPaintBounds(mesh.bounds);
}

var state = this._getState();
var rect = Rect.fromLTWH(cmd.offset.dx, cmd.offset.dy,
var rect = uiRectHelper.fromLTWH(cmd.offset.Value.dx, cmd.offset.Value.dy,
cmd.image.width, cmd.image.height);
rect = state.xform.mapRect(rect);
this._addPaintBounds(rect);

var state = this._getState();
var rect = state.xform.mapRect(cmd.dst);
var rect = state.xform.mapRect(cmd.dst.Value);
var rect = state.xform.mapRect(cmd.dst);
var rect = state.xform.mapRect(cmd.dst.Value);
var rect = state.xform.mapRect(cmd.picture.paintBounds);
var rect = state.xform.mapRect(uiRectHelper.fromRect(cmd.picture.paintBounds));
var scale = XformUtils.getScale(state.xform);
var rect = cmd.textBlob.boundsInText.shift(cmd.offset);
var scale = uiXformUtils.getScale(state.xform);
var rect = uiRectHelper.fromRect(cmd.textBlob.boundsInText).shift(cmd.offset.Value);
rect = state.xform.mapRect(rect);
var paint = cmd.paint;

this._addPaintBounds(rect.inflate(sigma3));
this._addPaintBounds(uiRectHelper.inflate(rect, sigma3));
} else {
this._addPaintBounds(rect);
}

}
}
void _addPaintBounds(Rect paintBounds) {
void _addPaintBounds(uiRect? paintBounds) {
paintBounds = paintBounds.intersect(state.scissor);
paintBounds = paintBounds.Value.intersect(state.scissor.Value);
if (paintBounds == null || paintBounds.isEmpty) {
if (paintBounds == null || paintBounds.Value.isEmpty) {
state.paintBounds = paintBounds;
state.paintBounds = paintBounds.Value;
state.paintBounds = state.paintBounds.expandToInclude(paintBounds);
state.paintBounds = state.paintBounds.expandToInclude(paintBounds.Value);
}
}

70
Runtime/ui/utils/renderer/geometry/matrix/ui_matrix.cs


(kUnknown_Mask | kOnlyPerspectiveValid_Mask));
this.fTypeMask = mask;
}
void _orTypeMask(int mask) {
D.assert((mask & kORableMasks) == mask);
this.fTypeMask |= mask;
}
void _clearTypeMask(int mask) {
// only allow a valid mask
D.assert((mask & kAllMasks) == mask);
this.fTypeMask &= ~mask;
}
int _computePerspectiveTypeMask() {

public void preConcat(uiMatrix3 other) {
if (!other.isIdentity()) {
this._setConcat(this, other);
}
}
public void preScale(float sx, float sy, float px, float py) {
if (1 == sx && 1 == sy) {
return;
}
var m = new uiMatrix3();
m.setScale(sx, sy, px, py);
this.preConcat(m);
}
public void preScale(float sx, float sy) {
if (1 == sx && 1 == sy) {
return;
}
this.kMScaleX *= sx;
this.kMSkewY *= sx;
this.kMPersp0 *= sx;
this.kMSkewX *= sy;
this.kMScaleY *= sy;
this.kMPersp1 *= sy;
if (this.kMScaleX == 1 && this.kMScaleY == 1 && (this.fTypeMask &
(int) (TypeMask.kPerspective_Mask | TypeMask.kAffine_Mask)) == 0) {
this._clearTypeMask((int) TypeMask.kScale_Mask);
}
else {
this._orTypeMask((int) TypeMask.kScale_Mask);
}
}
public void preRotate(float radians, float px, float py) {
var m = new uiMatrix3();
m.setRotate(radians, px, py);
this.preConcat(m);
}
public void preRotate(float radians) {
var m = new uiMatrix3();
m.setRotate(radians);
this.preConcat(m);
}
public void preSkew(float kx, float ky) {
var m = new uiMatrix3();
m.setSkew(kx, ky);
this.preConcat(m);
}
public void setScale(float sx, float sy, float px, float py) {
if (1 == sx && 1 == sy) {
this.reset();
}
else {
this._setScaleTranslate(sx, sy, px - sx * px, py - sy * py);
}
}
}

2
Runtime/ui/utils/renderer/geometry/path/path.cs


this._commands.Add(winding);
}
public void addRect(Rect rect) {
public void addRect(uiRect rect) {
this._appendMoveTo(rect.left, rect.top);
this._appendLineTo(rect.left, rect.bottom);
this._appendLineTo(rect.right, rect.bottom);

31
Runtime/ui/utils/renderer/geometry/rect.cs


public uiOffset bottomRight {
get { return new uiOffset(this.right, this.bottom); }
}
public uiRect shift(uiOffset offset) {
return uiRectHelper.fromLTRB(this.left + offset.dx, this.top + offset.dy, this.right + offset.dx,
this.bottom + offset.dy);
}
public uiRect intersect(uiRect other) {
return uiRectHelper.fromLTRB(
Mathf.Max(this.left, other.left),
Mathf.Max(this.top, other.top),
Mathf.Min(this.right, other.right),
Mathf.Min(this.bottom, other.bottom)
);
}
public uiRect expandToInclude(uiRect? other) {
if (this.isEmpty) {
return other.Value;
}
if (other == null || other.Value.isEmpty) {
return this;
}
return uiRectHelper.fromLTRB(
Mathf.Min(this.left, other.Value.left),
Mathf.Min(this.top, other.Value.top),
Mathf.Max(this.right, other.Value.right),
Mathf.Max(this.bottom, other.Value.bottom)
);
}
}
public static class uiRectHelper {

8
Runtime/flow.meta


fileFormatVersion: 2
guid: e1056a6e2b8247cbaf7db24691b913ec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

53
Runtime/ui/utils/renderer/common/utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
static class uiXformUtils {
public static float getScaleX(uiMatrix3 matrix) {
// ignore perspective parameters for now.
if (matrix.isIdentity()) {
return 1.0f;
}
if (matrix.getSkewY() == 0) {
return matrix.getScaleX();
}
var x = matrix.getScaleX();
var y = matrix.getSkewY();
return Mathf.Sqrt(x * x + y * y);
}
public static float getScaleY(uiMatrix3 matrix) {
// ignore perspective parameters for now.
if (matrix.isIdentity()) {
return 1.0f;
}
if (matrix.getSkewX() == 0) {
return matrix.getScaleY();
}
var x = matrix.getSkewX();
var y = matrix.getScaleY();
return Mathf.Sqrt(x * x + y * y);
}
public static float getScale(uiMatrix3 matrix) {
var scaleX = getScaleX(matrix);
var scaleY = getScaleY(matrix);
if (scaleX == 1.0) {
return scaleY;
}
if (scaleY == 1.0) {
return scaleX;
}
// geometric mean of len0 and len1.
return Mathf.Sqrt(scaleX * scaleY);
}
}
}

11
Runtime/ui/utils/renderer/common/utils.cs.meta


fileFormatVersion: 2
guid: fb644db0d0fbd48208a50a3321bc5840
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存