浏览代码

update bindings.

/main
kg 6 年前
当前提交
ba624d83
共有 10 个文件被更改,包括 374 次插入87 次删除
  1. 6
      Assets/UIWidgets/Tests/Gestures.cs
  2. 5
      Assets/UIWidgets/editor/editor_window.cs
  3. 3
      Assets/UIWidgets/foundation/basic_types.cs
  4. 14
      Assets/UIWidgets/foundation/debug.cs
  5. 16
      Assets/UIWidgets/gestures/binding.cs
  6. 51
      Assets/UIWidgets/rendering/binding.cs
  7. 2
      Assets/UIWidgets/rendering/view.cs
  8. 217
      Assets/UIWidgets/scheduler/binding.cs
  9. 144
      Assets/UIWidgets/foundation/assertions.cs
  10. 3
      Assets/UIWidgets/foundation/assertions.cs.meta

6
Assets/UIWidgets/Tests/Gestures.cs


this.windowAdapter = new WindowAdapter(this);
this.rendererBindings = new RendererBindings(this.windowAdapter);
this._tapRecognizer = new TapGestureRecognizer(this.rendererBindings.gestureBinding);
this._tapRecognizer = new TapGestureRecognizer(this.rendererBindings.rendererBinding);
this._panRecognizer = new PanGestureRecognizer(this.rendererBindings.gestureBinding);
this._panRecognizer = new PanGestureRecognizer(this.rendererBindings.rendererBinding);
this._doubleTapGesture = new DoubleTapGestureRecognizer(this.rendererBindings.gestureBinding);
this._doubleTapGesture = new DoubleTapGestureRecognizer(this.rendererBindings.rendererBinding);
this._doubleTapGesture.onDoubleTap = () => { Debug.Log("onDoubleTap"); };
}

5
Assets/UIWidgets/editor/editor_window.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
using UIWidgets.async;
using UIWidgets.flow;
using UIWidgets.ui;

public readonly EditorWindow editorWindow;
Rect _lastPosition;
readonly DateTime _epoch = DateTime.Now;
readonly DateTime _epoch = new DateTime(Stopwatch.GetTimestamp());
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue();
readonly TimerProvider _timerProvider = new TimerProvider();

if (evt.type == EventType.Repaint) {
if (this.onBeginFrame != null) {
this.onBeginFrame(DateTime.Now - this._epoch);
this.onBeginFrame(new DateTime(Stopwatch.GetTimestamp()) - this._epoch);
}
this.flushMicrotasks();

3
Assets/UIWidgets/foundation/basic_types.cs


using System.Collections.Generic;
namespace UIWidgets.foundation {
public delegate IEnumerable<T> EnumerableFilter<T>(IEnumerable<T> input);
public static class CollectionUtils {
public static V putIfAbsent<K, V>(this IDictionary<K, V> it, K key, Func<V> ifAbsent) {
V value;

public static bool isNotEmpty(this string it) {
return !string.IsNullOrEmpty(it);
}
}
}

14
Assets/UIWidgets/foundation/debug.cs


[Conditional("UIWidgets_DEBUG")]
public static void assert(bool result, string message = null) {
if (!result) {
throw new Exception(message ?? "assertion failed.");
throw new AssertionError(message);
}
}

public static bool debugPaintPointersEnabled = false;
public static bool debugPrintRecognizerCallbacksTrace = true;
public static bool debugPrintBeginFrameBanner = true;
public static bool debugPrintEndFrameBanner = true;
public static bool debugPrintScheduleFrameStacks = true;
}
[Serializable]
public class AssertionError : Exception {
public AssertionError(string message) : base(message) {
}
}
}

16
Assets/UIWidgets/gestures/binding.cs


using System;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.scheduler;
public class GestureBinding : HitTestable, HitTestDispatcher, HitTestTarget {
public GestureBinding(Window window, HitTestable hitTestable = null) {
this.window = window;
public class GestureBinding : SchedulerBinding, HitTestable, HitTestDispatcher, HitTestTarget {
public GestureBinding(Window window) : base(window) {
this._hitTestable = hitTestable;
public readonly Window window;
readonly HitTestable _hitTestable;
readonly Queue<PointerEvent> _pendingPointerEvents = new Queue<PointerEvent>();
void _handlePointerDataPacket(PointerDataPacket packet) {

if (evt is PointerDownEvent) {
D.assert(!this._hitTests.ContainsKey(evt.pointer));
result = new HitTestResult();
if (this._hitTestable != null) {
this._hitTestable.hitTest(result, evt.position);
}
this.hitTest(result, evt.position);
this._hitTests[evt.pointer] = result;

}
}
public void hitTest(HitTestResult result, Offset position) {
public virtual void hitTest(HitTestResult result, Offset position) {
result.add(new HitTestEntry(this));
}

51
Assets/UIWidgets/rendering/binding.cs


using UIWidgets.ui;
namespace UIWidgets.rendering {
public class RendererBinding : HitTestable {
public RendererBinding(Window window, SchedulerBinding schedulerBinding) {
this._window = window;
this._schedulerBinding = schedulerBinding;
public class RendererBinding : GestureBinding {
public RendererBinding(Window window) : base(window) {
onNeedVisualUpdate: this._schedulerBinding.ensureVisualUpdate
onNeedVisualUpdate: this.ensureVisualUpdate
this._schedulerBinding.addPersistentFrameCallback(this._handlePersistentFrameCallback);
D.assert(this.renderView != null);
this.addPersistentFrameCallback(this._handlePersistentFrameCallback);
public readonly Window _window;
public readonly SchedulerBinding _schedulerBinding;
D.assert(this.renderView == null);
this.renderView = new RenderView(configuration: this.createViewConfiguration());
this.renderView.scheduleInitialFrame();
}

}
public PipelineOwner _pipelineOwner;
readonly PipelineOwner _pipelineOwner;
public RenderView renderView {
get { return (RenderView) this._pipelineOwner.rootNode; }

public void handleMetricsChanged() {
protected virtual void handleMetricsChanged() {
this._schedulerBinding.scheduleForcedFrame();
this.scheduleForcedFrame();
public ViewConfiguration createViewConfiguration() {
var devicePixelRatio = this._window.devicePixelRatio;
protected virtual ViewConfiguration createViewConfiguration() {
var devicePixelRatio = this.window.devicePixelRatio;
size: this._window.physicalSize / devicePixelRatio,
size: this.window.physicalSize / devicePixelRatio,
public void _handlePersistentFrameCallback(TimeSpan timeStamp) {
void _handlePersistentFrameCallback(TimeSpan timeStamp) {
public void hitTest(HitTestResult result, Offset position) {
D.assert(this.renderView != null);
this.renderView.hitTest(result, position: position);
}
public void drawFrame() {
protected virtual void drawFrame() {
this.pipelineOwner.flushLayout();
this.pipelineOwner.flushCompositingBits();
this.pipelineOwner.flushPaint();

public void render(Scene scene) {
this._window.render(scene);
public override void hitTest(HitTestResult result, Offset position) {
D.assert(this.renderView != null);
this.renderView.hitTest(result, position: position);
base.hitTest(result, position);
}
}

this.schedulerBinding = new SchedulerBinding(window);
this.rendererBinding = new RendererBinding(window, this.schedulerBinding);
this.gestureBinding = new GestureBinding(window, this.rendererBinding);
this.rendererBinding = new RendererBinding(window);
public readonly SchedulerBinding schedulerBinding;
public readonly GestureBinding gestureBinding;
public void setRoot(RenderBox root) {
this.rendererBinding.renderView.child = root;

2
Assets/UIWidgets/rendering/view.cs


var builder = new SceneBuilder();
this.layer.addToScene(builder, Offset.zero);
var scene = builder.build();
this.owner.binding.render(scene);
this.owner.binding.window.render(scene);
}
public override Rect paintBounds {

217
Assets/UIWidgets/scheduler/binding.cs


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using RSG.Promises;
using UIWidgets.foundation;
using UnityEngine;
using Debug = UnityEngine.Debug;
public class _FrameCallbackEntry {
public _FrameCallbackEntry(FrameCallback callback, bool rescheduling = false) {
class _FrameCallbackEntry {
internal _FrameCallbackEntry(FrameCallback callback, bool rescheduling = false) {
D.assert(() => {
if (rescheduling) {
D.assert(() => {
if (_FrameCallbackEntry.debugCurrentCallbackStack == null) {
throw new UIWidgetsError(
"scheduleFrameCallback called with rescheduling true, but no callback is in scope.\n" +
"The \"rescheduling\" argument should only be set to true if the " +
"callback is being reregistered from within the callback itself, " +
"and only then if the callback itself is entirely synchronous. " +
"If this is the initial registration of the callback, or if the " +
"callback is asynchronous, then do not use the \"rescheduling\" " +
"argument.");
}
return true;
});
this.debugStack = _FrameCallbackEntry.debugCurrentCallbackStack;
} else {
this.debugStack = new StackTrace(2, true);
}
return true;
});
public static StackTrace debugCurrentCallbackStack;
public StackTrace debugStack;
}
public enum SchedulerPhase {

public class SchedulerBinding {
public SchedulerBinding(Window window) {
this._window = window;
D.assert(window != null);
this.window = window;
public readonly Window _window;
public readonly Window window;
public double timeDilation {
get { return this._timeDilation; }

}
}
public double _timeDilation = 1.0;
double _timeDilation = 1.0;
public int _nextFrameCallbackId = 0;
public Dictionary<int, _FrameCallbackEntry> _transientCallbacks = new Dictionary<int, _FrameCallbackEntry>();
public HashSet<int> _removedIds = new HashSet<int>();
int _nextFrameCallbackId = 0;
Dictionary<int, _FrameCallbackEntry> _transientCallbacks = new Dictionary<int, _FrameCallbackEntry>();
readonly HashSet<int> _removedIds = new HashSet<int>();
public int transientCallbackCount {
get { return this._transientCallbacks.Count; }

}
public void cancelFrameCallbackWithId(int id) {
D.assert(id > 0);
public readonly List<FrameCallback> _persistentCallbacks = new List<FrameCallback>();
readonly List<FrameCallback> _persistentCallbacks = new List<FrameCallback>();
public readonly List<FrameCallback> _postFrameCallbacks = new List<FrameCallback>();
readonly List<FrameCallback> _postFrameCallbacks = new List<FrameCallback>();
public void addPostFrameCallback(FrameCallback callback) {
this._postFrameCallbacks.Add(callback);

get { return this._hasScheduledFrame; }
}
public bool _hasScheduledFrame = false;
bool _hasScheduledFrame = false;
public SchedulerPhase _schedulerPhase = SchedulerPhase.idle;
SchedulerPhase _schedulerPhase = SchedulerPhase.idle;
public void ensureVisualUpdate() {
switch (this.schedulerPhase) {

return;
}
this._window.scheduleFrame();
D.assert(() => {
if (D.debugPrintScheduleFrameStacks) {
Debug.LogFormat("scheduleFrame() called. Current phase is {0}.", this.schedulerPhase);
}
return true;
});
this.window.scheduleFrame();
this.scheduleFrame();
if (this._hasScheduledFrame) {
return;
}
D.assert(() => {
if (D.debugPrintScheduleFrameStacks) {
Debug.LogFormat("scheduleForcedFrame() called. Current phase is {0}.", this.schedulerPhase);
}
return true;
});
this.window.scheduleFrame();
this._hasScheduledFrame = true;
public TimeSpan? _firstRawTimeStampInEpoch;
public TimeSpan _epochStart = TimeSpan.Zero;
public TimeSpan _lastRawTimeStamp = TimeSpan.Zero;
TimeSpan? _firstRawTimeStampInEpoch;
TimeSpan _epochStart = TimeSpan.Zero;
TimeSpan _lastRawTimeStamp = TimeSpan.Zero;
public void resetEpoch() {
this._epochStart = this._adjustForEpoch(this._lastRawTimeStamp);

public TimeSpan _adjustForEpoch(TimeSpan rawTimeStamp) {
TimeSpan _adjustForEpoch(TimeSpan rawTimeStamp) {
var rawDurationSinceEpoch = this._firstRawTimeStampInEpoch == null
? TimeSpan.Zero
: rawTimeStamp - this._firstRawTimeStampInEpoch.Value;

get { return this._currentFrameTimeStamp.Value; }
}
public TimeSpan? _currentFrameTimeStamp;
TimeSpan? _currentFrameTimeStamp;
int _profileFrameNumber = 0;
string _debugBanner;
public void _handleBeginFrame(TimeSpan rawTimeStamp) {
void _handleBeginFrame(TimeSpan rawTimeStamp) {
public void _handleDrawFrame() {
void _handleDrawFrame() {
if (this._firstRawTimeStampInEpoch == null) {
this._firstRawTimeStampInEpoch = rawTimeStamp;
}
this._firstRawTimeStampInEpoch = this._firstRawTimeStampInEpoch ?? rawTimeStamp;
this._currentFrameTimeStamp = this._adjustForEpoch(rawTimeStamp ?? this._lastRawTimeStamp);
if (rawTimeStamp != null) {

D.assert(() => {
this._profileFrameNumber += 1;
return true;
});
D.assert(() => {
if (D.debugPrintBeginFrameBanner || D.debugPrintEndFrameBanner) {
var frameTimeStampDescription = new StringBuilder();
if (rawTimeStamp != null) {
SchedulerBinding._debugDescribeTimeStamp(
this._currentFrameTimeStamp.Value, frameTimeStampDescription);
} else {
frameTimeStampDescription.Append("(warm-up frame)");
}
this._debugBanner = string.Format("▄▄▄▄▄▄▄▄ Frame {0} {1} ▄▄▄▄▄▄▄▄",
this._profileFrameNumber.ToString().PadRight(7),
frameTimeStampDescription.ToString().PadLeft(18));
if (D.debugPrintBeginFrameBanner) {
Debug.Log(this._debugBanner);
}
}
return true;
});
D.assert(this._schedulerPhase == SchedulerPhase.idle);
this._hasScheduledFrame = false;
try {

foreach (var entry in callbacks) {
if (!this._removedIds.Contains(entry.Key)) {
this._invokeFrameCallback(entry.Value.callback, this._currentFrameTimeStamp.Value);
this._invokeFrameCallback(
entry.Value.callback, this._currentFrameTimeStamp.Value, entry.Value.debugStack);
}
}

}
}
public void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp) {
try {
callback(timeStamp);
}
catch (Exception ex) {
Debug.LogError("error in frame callback: " + ex);
}
}
D.assert(this._schedulerPhase == SchedulerPhase.midFrameMicrotasks);
try {
this._schedulerPhase = SchedulerPhase.persistentCallbacks;
foreach (FrameCallback callback in this._persistentCallbacks) {

}
finally {
this._schedulerPhase = SchedulerPhase.idle;
D.assert(() => {
if (D.debugPrintEndFrameBanner) {
Debug.Log(new string('▀', this._debugBanner.Length));
}
this._debugBanner = null;
return true;
});
}
static void _debugDescribeTimeStamp(TimeSpan timeStamp, StringBuilder buffer) {
if (timeStamp.TotalDays > 0) {
buffer.AppendFormat("{0}d ", timeStamp.Days);
}
if (timeStamp.TotalHours > 0) {
buffer.AppendFormat("{0}h ", timeStamp.Hours);
}
if (timeStamp.TotalMinutes > 0) {
buffer.AppendFormat("{0}m ", timeStamp.Minutes);
}
if (timeStamp.TotalSeconds > 0) {
buffer.AppendFormat("{0}s ", timeStamp.Seconds);
}
buffer.AppendFormat("{0}", timeStamp.Milliseconds);
int microseconds = (int) (timeStamp.Ticks % 10000 / 10);
if (microseconds > 0) {
buffer.AppendFormat(".{0}", microseconds.ToString().PadLeft(3, '0'));
}
buffer.Append("ms");
}
void _invokeFrameCallback(FrameCallback callback, TimeSpan timeStamp, StackTrace callbackStack = null) {
D.assert(callback != null);
D.assert(_FrameCallbackEntry.debugCurrentCallbackStack == null);
D.assert(() => {
_FrameCallbackEntry.debugCurrentCallbackStack = callbackStack;
return true;
});
try {
callback(timeStamp);
}
catch (Exception ex) {
UIWidgetsError.reportError(new UIWidgetsErrorDetails(
exception: ex,
library: "scheduler library",
context: "during a scheduler callback",
informationCollector: callbackStack == null
? (InformationCollector) null
: information => {
information.AppendLine(
"\nThis exception was thrown in the context of a scheduler callback. " +
"When the scheduler callback was _registered_ (as opposed to when the " +
"exception was thrown), this was the stack:"
);
UIWidgetsError.defaultStackFilter(callbackStack.ToString().TrimEnd().Split('\n'))
.Each((line) => information.AppendLine(line));
}
));
}
D.assert(() => {
_FrameCallbackEntry.debugCurrentCallbackStack = null;
return true;
});
}
}
}

144
Assets/UIWidgets/foundation/assertions.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Debug = UnityEngine.Debug;
namespace UIWidgets.foundation {
public delegate void UIWidgetsExceptionHandler(UIWidgetsErrorDetails details);
public delegate void InformationCollector(StringBuilder information);
public class UIWidgetsErrorDetails {
public UIWidgetsErrorDetails(
Exception exception = null,
string library = "UIWidgets framework",
string context = null,
EnumerableFilter<String> stackFilter = null,
InformationCollector informationCollector = null,
bool silent = false
) {
this.exception = exception;
this.library = library;
this.context = context;
this.stackFilter = stackFilter;
this.informationCollector = informationCollector;
this.silent = silent;
}
public readonly Exception exception;
public readonly string library;
public readonly string context;
public readonly EnumerableFilter<String> stackFilter;
public readonly InformationCollector informationCollector;
public readonly bool silent;
public string exceptionAsString() {
string longMessage = null;
if (this.exception != null) {
longMessage = this.exception.Message;
}
if (longMessage != null) {
longMessage = longMessage.TrimEnd();
}
if (longMessage.isEmpty()) {
longMessage = "<no message available>";
}
return longMessage;
}
public override string ToString() {
var buffer = new StringBuilder();
if (this.library.isNotEmpty() || this.context.isNotEmpty()) {
if (this.library.isNotEmpty()) {
buffer.AppendFormat("Error caught by {0}", this.library);
if (this.context.isNotEmpty()) {
buffer.Append(", ");
}
} else {
buffer.Append("Exception ");
}
if (this.context.isNotEmpty()) {
buffer.AppendFormat("thrown {0}", this.context);
}
buffer.Append(". ");
} else {
buffer.Append("An error was caught. ");
}
buffer.AppendLine(this.exceptionAsString());
if (this.informationCollector != null) {
this.informationCollector(buffer);
}
if (this.exception.StackTrace != null) {
IEnumerable<string> stackLines = this.exception.StackTrace.TrimEnd().Split('\n');
if (this.stackFilter != null) {
stackLines = this.stackFilter(stackLines);
} else {
stackLines = UIWidgetsError.defaultStackFilter(stackLines);
}
buffer.Append(string.Join("\n", stackLines.ToArray()));
}
return buffer.ToString().TrimEnd();
}
}
public class UIWidgetsError : AssertionError {
public UIWidgetsError(string message) : base(message) {
}
public static UIWidgetsExceptionHandler onError = dumpErrorToConsole;
static int _errorCount = 0;
public static void resetErrorCount() {
_errorCount = 0;
}
public static void dumpErrorToConsole(UIWidgetsErrorDetails details) {
dumpErrorToConsole(details, forceReport: false);
}
public static void dumpErrorToConsole(UIWidgetsErrorDetails details, bool forceReport = false) {
D.assert(details != null);
D.assert(details.exception != null);
bool reportError = !details.silent;
D.assert(() => {
reportError = true;
return true;
});
if (!reportError && !forceReport) {
return;
}
if (_errorCount == 0 || forceReport) {
Debug.Log(details.ToString());
} else {
Debug.Log("Another exception was thrown: " + details.exceptionAsString());
}
_errorCount += 1;
}
public static IEnumerable<string> defaultStackFilter(IEnumerable<string> frames) {
return frames;
}
public static void reportError(UIWidgetsErrorDetails details) {
D.assert(details != null);
D.assert(details.exception != null);
if (onError != null) {
onError(details);
}
}
}
}

3
Assets/UIWidgets/foundation/assertions.cs.meta


fileFormatVersion: 2
guid: b1c014fd2b864fe696ffb29b063921b4
timeCreated: 1536501637
正在加载...
取消
保存