浏览代码

hardware antialias re-supporting

/main
xingwei.zhu 5 年前
当前提交
0fad4c86
共有 12 个文件被更改,包括 90 次插入17 次删除
  1. 2
      Editor/UIWidgetsPanelEditor.cs
  2. 12
      Runtime/editor/editor_window.cs
  3. 2
      Runtime/editor/rasterizer.cs
  4. 20
      Runtime/editor/surface.cs
  5. 14
      Runtime/engine/UIWidgetsPanel.cs
  6. 13
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  7. 3
      Runtime/ui/renderer/cmdbufferCanvas/rendering/render_layer.cs
  8. 1
      Runtime/ui/renderer/compositeCanvas/flow/layer.cs
  9. 8
      Runtime/ui/renderer/compositeCanvas/flow/layer_tree.cs
  10. 2
      Runtime/ui/renderer/compositeCanvas/flow/picture_layer.cs
  11. 21
      Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs
  12. 9
      Runtime/ui/window.cs

2
Editor/UIWidgetsPanelEditor.cs


public override void OnInspectorGUI() {
base.OnInspectorGUI();
var pixelRatioProperty = this.serializedObject.FindProperty("devicePixelRatioOverride");
var antiAliasingProperty = this.serializedObject.FindProperty("hardwareAntiAliasing");
EditorGUILayout.PropertyField(antiAliasingProperty);
this.serializedObject.ApplyModifiedProperties();
}
}

12
Runtime/editor/editor_window.cs


protected override float queryDevicePixelRatio() {
return EditorGUIUtility.pixelsPerPoint;
}
protected override int queryAntiAliasing() {
return defaultAntiAliasing;
}
protected override Vector2 queryWindowSize() {
return this.editorWindow.position.size;

public void OnEnable() {
this._devicePixelRatio = this.queryDevicePixelRatio();
this._antiAliasing = this.queryAntiAliasing();
this.updatePhysicalSize();
this.updateSafeArea();
D.assert(this._surface == null);

if (this._devicePixelRatio != this.queryDevicePixelRatio()) {
return true;
}
if (this._antiAliasing != this.queryAntiAliasing()) {
return true;
}
var size = this.queryWindowSize();
if (this._lastWindowWidth != size.x

using (this.getScope()) {
if (this.displayMetricsChanged()) {
this._devicePixelRatio = this.queryDevicePixelRatio();
this._antiAliasing = this.queryAntiAliasing();
var size = this.queryWindowSize();
this._lastWindowWidth = size.x;

}
protected abstract float queryDevicePixelRatio();
protected abstract int queryAntiAliasing();
protected abstract Vector2 queryWindowSize();
protected virtual Surface createSurface() {

layerTree.frameSize = this._physicalSize;
layerTree.devicePixelRatio = this._devicePixelRatio;
layerTree.antiAliasing = this._antiAliasing;
this._rasterizer.draw(layerTree);
}

2
Runtime/editor/rasterizer.cs


D.assert(this._surface != null);
var frame = this._surface.acquireFrame(
layerTree.frameSize, layerTree.devicePixelRatio);
layerTree.frameSize, layerTree.devicePixelRatio, layerTree.antiAliasing);
if (frame == null) {
return false;
}

20
Runtime/editor/surface.cs


}
public interface Surface : IDisposable {
SurfaceFrame acquireFrame(Size size, float devicePixelRatio);
SurfaceFrame acquireFrame(Size size, float devicePixelRatio, int antiAliasing);
MeshPool getMeshPool();
}

this._drawToTargetFunc = drawToTargetFunc;
}
public SurfaceFrame acquireFrame(Size size, float devicePixelRatio) {
this._createOrUpdateRenderTexture(size, devicePixelRatio);
public SurfaceFrame acquireFrame(Size size, float devicePixelRatio, int antiAliasing) {
this._createOrUpdateRenderTexture(size, devicePixelRatio, antiAliasing);
return new SurfaceFrame(this._surface,
(frame, canvas) => this._presentSurface(canvas));

return true;
}
void _createOrUpdateRenderTexture(Size size, float devicePixelRatio) {
void _createOrUpdateRenderTexture(Size size, float devicePixelRatio, int antiAliasing) {
&& this._surface.antiAliasing == antiAliasing
&& this._surface.getRenderTexture() != null) {
return;
}

this._surface = null;
}
this._surface = new GrSurface(size, devicePixelRatio, this._meshPool);
this._surface = new GrSurface(size, devicePixelRatio, antiAliasing, this._meshPool);
}
}

public readonly float devicePixelRatio;
public readonly int antiAliasing;
readonly MeshPool _meshPool;

return this._canvas;
}
public GrSurface(Size size, float devicePixelRatio, MeshPool meshPool) {
public GrSurface(Size size, float devicePixelRatio, int antiAliasing, MeshPool meshPool) {
this.antiAliasing = antiAliasing;
var desc = new RenderTextureDescriptor(
(int) this.size.width, (int) this.size.height,

};
if (antiAliasing != 0) {
desc.msaaSamples = antiAliasing;
}
this._renderTexture = new RenderTexture(desc);
this._renderTexture.hideFlags = HideFlags.HideAndDontSave;

14
Runtime/engine/UIWidgetsPanel.cs


protected override float queryDevicePixelRatio() {
return this._uiWidgetsPanel.devicePixelRatio;
}
protected override int queryAntiAliasing() {
return this._uiWidgetsPanel.antiAliasing;
}
protected override Vector2 queryWindowSize() {
var rect = this._uiWidgetsPanel.rectTransform.rect;

IPointerEnterHandler, IPointerExitHandler, WindowHost {
static Event _repaintEvent;
[Tooltip("set to zero if you want to use the default device pixel ratio of the target platforms; otherwise the " +
"device pixel ratio will be forced to the given value on all devices.")]
[Tooltip("set to true will enable the hardware anti-alias feature, which will improve the appearance of the UI greatly but " +
"making it much slower. Enable it only when seriously required.")]
[SerializeField] protected bool hardwareAntiAliasing = false;
WindowAdapter _windowAdapter;
Texture _texture;
Vector2 _lastMouseMove;

? this.devicePixelRatioOverride
: this._displayMetrics.devicePixelRatio;
}
}
public int antiAliasing {
get { return this.hardwareAntiAliasing ? Window.defaultAntiAliasing : 0; }
}
public WindowPadding viewPadding {

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


width: textureWidth,
height: textureHeight,
layerBounds: maskBounds,
filterMode: FilterMode.Bilinear
filterMode: FilterMode.Bilinear,
noMSAA: true
);
parentLayer.addLayer(maskLayer);

width: textureWidth,
height: textureHeight,
layerBounds: maskLayer.layerBounds,
filterMode: FilterMode.Bilinear
filterMode: FilterMode.Bilinear,
noMSAA: true
);
parentLayer.addLayer(blurXLayer);

width: textureWidth,
height: textureHeight,
layerBounds: maskLayer.layerBounds,
filterMode: FilterMode.Bilinear
filterMode: FilterMode.Bilinear,
noMSAA: true
);
parentLayer.addLayer(blurYLayer);

useMipMap = false,
autoGenerateMips = false
};
if (this._renderTexture.antiAliasing != 0 && !subLayer.noMSAA) {
desc.msaaSamples = this._renderTexture.antiAliasing;
}
cmdBuf.GetTemporaryRT(subLayer.rtID, desc, subLayer.filterMode);
this._drawLayer(subLayer, cmdBuf);

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


public int width;
public int height;
public FilterMode filterMode = FilterMode.Bilinear;
public bool noMSAA = false;
public uiRect layerBounds;
public uiPaint? layerPaint;
public readonly List<RenderCmd> draws = new List<RenderCmd>(128);

public static RenderLayer create(int rtID = 0, int width = 0, int height = 0,
FilterMode filterMode = FilterMode.Bilinear,
bool noMSAA = false,
uiRect? layerBounds = null, uiPaint? layerPaint = null, bool ignoreClip = true) {
D.assert(layerBounds != null);
var newLayer = ObjectPool<RenderLayer>.alloc();

newLayer.filterMode = filterMode;
newLayer.noMSAA = noMSAA;
newLayer.layerBounds = layerBounds.Value;
newLayer.layerPaint = layerPaint;
newLayer.ignoreClip = ignoreClip;

1
Runtime/ui/renderer/compositeCanvas/flow/layer.cs


public class PrerollContext {
public RasterCache rasterCache;
public float devicePixelRatio;
public int antiAliasing;
public Rect cullRect;
public Stopwatch frameTime;
}

8
Runtime/ui/renderer/compositeCanvas/flow/layer_tree.cs


get { return this._devicePixelRatio; }
set { this._devicePixelRatio = value; }
}
int _antiAliasing;
public int antiAliasing {
get { return this._antiAliasing; }
set { this._antiAliasing = value; }
}
static readonly Matrix3 _identityMatrix = Matrix3.I();

devicePixelRatio = frame.canvas().getDevicePixelRatio(),
antiAliasing = this.antiAliasing,
cullRect = Rect.largest,
frameTime = frame.context().frameTime()
};

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


ctm[5] = ctm[5].alignToPixel(context.devicePixelRatio);
this._rasterCacheResult = context.rasterCache.getPrerolledImage(
this._picture, ctm, context.devicePixelRatio, this._isComplex,
this._picture, ctm, context.devicePixelRatio, context.antiAliasing, this._isComplex,
this._willChange);
}
else {

21
Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs


}
class _RasterCacheKey : IEquatable<_RasterCacheKey> {
internal _RasterCacheKey(Picture picture, Matrix3 matrix, float devicePixelRatio) {
internal _RasterCacheKey(Picture picture, Matrix3 matrix, float devicePixelRatio, int antiAliasing) {
D.assert(picture != null);
D.assert(matrix != null);
this.picture = picture;

this.matrix[2] = 0.0f;
this.matrix[5] = 0.0f;
this.devicePixelRatio = devicePixelRatio;
this.antiAliasing = antiAliasing;
}
public readonly Picture picture;

public readonly float devicePixelRatio;
public readonly int antiAliasing;
public bool Equals(_RasterCacheKey other) {
if (ReferenceEquals(null, other)) {

return Equals(this.picture, other.picture) &&
Equals(this.matrix, other.matrix) &&
this.devicePixelRatio.Equals(other.devicePixelRatio);
this.devicePixelRatio.Equals(other.devicePixelRatio) &&
this.antiAliasing.Equals(other.antiAliasing);
}
public override bool Equals(object obj) {

var hashCode = (this.picture != null ? this.picture.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.matrix != null ? this.matrix.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.devicePixelRatio.GetHashCode();
hashCode = (hashCode * 397) ^ this.antiAliasing.GetHashCode();
return hashCode;
}
}

}
public RasterCacheResult getPrerolledImage(
Picture picture, Matrix3 transform, float devicePixelRatio, bool isComplex,
Picture picture, Matrix3 transform, float devicePixelRatio, int antiAliasing, bool isComplex,
bool willChange) {
if (this.threshold == 0) {
return null;

return null;
}
_RasterCacheKey cacheKey = new _RasterCacheKey(picture, transform, devicePixelRatio);
_RasterCacheKey cacheKey = new _RasterCacheKey(picture, transform, devicePixelRatio, antiAliasing);
var entry = this._cache.putIfAbsent(cacheKey, () => new _RasterCacheEntry());

if (entry.image == null) {
D.assert(this._meshPool != null);
entry.image =
this._rasterizePicture(picture, transform, devicePixelRatio, this._meshPool);
this._rasterizePicture(picture, transform, devicePixelRatio, antiAliasing, this._meshPool);
}
return entry.image;

}
RasterCacheResult _rasterizePicture(Picture picture, Matrix3 transform, float devicePixelRatio,
MeshPool meshPool) {
int antiAliasing, MeshPool meshPool) {
var bounds = transform.mapRect(picture.paintBounds).roundOut(devicePixelRatio);
var desc = new RenderTextureDescriptor(

useMipMap = false,
autoGenerateMips = false,
};
if (antiAliasing != 0) {
desc.msaaSamples = antiAliasing;
}
var renderTexture = new RenderTexture(desc);
renderTexture.hideFlags = HideFlags.HideAndDontSave;

9
Runtime/ui/window.cs


}
internal static Window _instance;
public const int defaultAntiAliasing = 4;
public float devicePixelRatio {
get { return this._devicePixelRatio; }

public int antiAliasing {
get { return this._antiAliasing; }
}
protected int _antiAliasing = defaultAntiAliasing;
public Size physicalSize {
get { return this._physicalSize; }

正在加载...
取消
保存