浏览代码

Merge pull request #110 from UnityTech/xwzhu

performance step 1
/main
GitHub 6 年前
当前提交
a0ce2d82
共有 5 个文件被更改,包括 82 次插入14 次删除
  1. 6
      Runtime/material/text_theme.cs
  2. 18
      Runtime/material/theme_data.cs
  3. 48
      Runtime/ui/painting/shadow_utils.cs
  4. 8
      Runtime/widgets/automatic_keep_alive.cs
  5. 16
      Runtime/widgets/ticker_provider.cs

6
Runtime/material/text_theme.cs


return !Equals(left, right);
}
int? _cachedHashCode = null;
if (this._cachedHashCode != null) {
return this._cachedHashCode.Value;
}
unchecked {
var hashCode = this.display4.GetHashCode();
hashCode = (hashCode * 397) ^ this.display3.GetHashCode();

hashCode = (hashCode * 397) ^ this.button.GetHashCode();
hashCode = (hashCode * 397) ^ this.subtitle.GetHashCode();
hashCode = (hashCode * 397) ^ this.overline.GetHashCode();
this._cachedHashCode = hashCode;
return hashCode;
}
}

18
Runtime/material/theme_data.cs


return !Equals(left, right);
}
int? _cachedHashCode = null;
if (this._cachedHashCode != null) {
return this._cachedHashCode.Value;
}
unchecked {
var hashCode = this.brightness.GetHashCode();
hashCode = (hashCode * 397) ^ this.primaryColor.GetHashCode();

hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.dialogTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.typography.GetHashCode();
this._cachedHashCode = hashCode;
return hashCode;
}
}

return true;
}
return this.baseTheme == other.baseTheme &&
this.localTextGeometry == other.localTextGeometry;
return ReferenceEquals(this.baseTheme, other.baseTheme) &&
ReferenceEquals(this.localTextGeometry, other.localTextGeometry);
}
public override bool Equals(object obj) {

public V putIfAbsent(K key, Func<V> value) {
D.assert(key != null);
D.assert(value != null);
if (this._cache.ContainsKey(key)) {
return this._cache[key];
V get_value;
if (this._cache.TryGetValue(key, out get_value)) {
return get_value;
}
if (this._cache.Count == this._maximumSize) {

48
Runtime/ui/painting/shadow_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.ui {
public static class ShadowUtils {
public const bool _drawShadowFlag = false;
static class ShadowUtils {
public static bool kUseFastShadow = true;
public const float kAmbientHeightFactor = 1.0f / 128.0f;
public const float kAmbientGeomFactor = 64.0f;

public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
if (!_drawShadowFlag) {
return;
if (kUseFastShadow) {
drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
else {
drawShadowFull(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
}
}
static void drawShadowFull(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//ambient light

Paint paint2 = new Paint {color = spotColor};
float sigma2 = convertRadiusToSigma(radius);
paint2.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2);
canvas.drawPath(path, paint2);
canvas.restore();
}
static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, Color ambientColor, Color spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//ambient light
float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
float oneOverA = ambientRecipAlpha(zPlaneParams.z);
float blurRadius = 0.5f * devSpaceOutset * oneOverA;
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius);
Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill};
canvas.drawPath(path, paint);
//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);
Paint paint2 = new Paint {color = spotColor};
canvas.drawPath(path, paint2);
canvas.restore();

8
Runtime/widgets/automatic_keep_alive.cs


public Ticker createTicker(TickerCallback onTick) {
this._tickers = this._tickers ?? new HashSet<Ticker>();
var result = new _AutomaticWidgetTicker<T>(onTick, this, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
var result = new _AutomaticWidgetTicker<T>(onTick, this, debugLabel: debugLabel);
this._tickers.Add(result);
return result;
}

16
Runtime/widgets/ticker_provider.cs


"mixing in a SingleTickerProviderStateMixin, use a regular TickerProviderStateMixin."
);
});
this._ticker = new Ticker(onTick, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
this._ticker = new Ticker(onTick, debugLabel: debugLabel);
return this._ticker;
}

public Ticker createTicker(TickerCallback onTick) {
this._tickers = this._tickers ?? new HashSet<Ticker>();
var result = new _WidgetTicker<T>(onTick, this, debugLabel: "created by " + this);
var debugLabel = "";
D.assert(() => {
debugLabel = "created by " + this;
return true;
});
var result = new _WidgetTicker<T>(onTick, this, debugLabel: debugLabel);
this._tickers.Add(result);
return result;
}

正在加载...
取消
保存