浏览代码

review rendering code from start to Object.cs

/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
cb5be7da
共有 13 个文件被更改,包括 294 次插入85 次删除
  1. 7
      com.unity.uiwidgets/Runtime/rendering/animated_size.cs
  2. 33
      com.unity.uiwidgets/Runtime/rendering/binding.cs
  3. 10
      com.unity.uiwidgets/Runtime/rendering/box.cs
  4. 4
      com.unity.uiwidgets/Runtime/rendering/custom_layout.cs
  5. 3
      com.unity.uiwidgets/Runtime/rendering/custom_paint.cs
  6. 32
      com.unity.uiwidgets/Runtime/rendering/debug_overflow_indicator.cs
  7. 117
      com.unity.uiwidgets/Runtime/rendering/editable.cs
  8. 82
      com.unity.uiwidgets/Runtime/rendering/flex.cs
  9. 1
      com.unity.uiwidgets/Runtime/rendering/image.cs
  10. 60
      com.unity.uiwidgets/Runtime/rendering/layer.cs
  11. 3
      com.unity.uiwidgets/Runtime/rendering/list_body.cs
  12. 19
      com.unity.uiwidgets/Runtime/rendering/list_wheel_viewport.cs
  13. 8
      com.unity.uiwidgets/Runtime/rendering/view.cs

7
com.unity.uiwidgets/Runtime/rendering/animated_size.cs


AlignmentGeometry alignment = null,
TextDirection? textDirection = null,
RenderBox child = null
) : base(child: child, alignment: alignment ?? Alignment.center) {
) : base(child: child, alignment: alignment ?? Alignment.center, textDirection: textDirection) {
curve = curve ?? Curves.linear;
curve = curve ?? Curves.linear;
D.assert(curve != null);
_vsync = vsync;
_controller = new AnimationController(
vsync: this.vsync,

}
child.layout(constraints, parentUsesSize: true);
switch (_state) {
case RenderAnimatedSizeState.start:
_layoutStart();

33
com.unity.uiwidgets/Runtime/rendering/binding.cs


public void initRenderView() {
D.assert(renderView == null);
renderView = new RenderView(configuration: createViewConfiguration());
renderView.scheduleInitialFrame();
renderView.prepareInitialFrame();
}
public MouseTracker mouseTracker {

}
protected virtual void handleMetricsChanged() {
D.assert(renderView != null);
renderView.configuration = createViewConfiguration();
scheduleForcedFrame();
}

_mouseTracker.schedulePostFrameCheck();
}
int _firstFrameDeferredCount = 0;
bool _firstFrameSent = false;
bool sendFramesToEngine {
get {
return _firstFrameSent || _firstFrameDeferredCount == 0;
}
}
void deferFirstFrame() {
D.assert(_firstFrameDeferredCount >= 0);
_firstFrameDeferredCount += 1;
}
void allowFirstFrame() {
D.assert(_firstFrameDeferredCount > 0);
_firstFrameDeferredCount -= 1;
if (!_firstFrameSent)
scheduleWarmUpFrame();
}
void resetFirstFrameSent() {
_firstFrameSent = false;
}
readonly protected bool inEditorWindow;

}*/
protected virtual void drawFrame() {
D.assert(renderView != null);
renderView.compositeFrame();
if (sendFramesToEngine) {
renderView.compositeFrame();
_firstFrameSent = true;
}
}
public override void hitTest(HitTestResult result, Offset position) {

10
com.unity.uiwidgets/Runtime/rendering/box.cs


float maxWidth = float.PositiveInfinity,
float minHeight = 0.0f,
float maxHeight = float.PositiveInfinity) {
D.assert(minWidth != null);
D.assert(maxWidth != null);
D.assert(minHeight != null);
D.assert (maxHeight != null);
this.minWidth = minWidth;
this.maxWidth = maxWidth;
this.minHeight = minHeight;

}
public bool addWithRawTransform(
Matrix4 transform,
Offset position,
BoxHitTest hitTest
Matrix4 transform = null,
Offset position = null,
BoxHitTest hitTest = null
) {
D.assert(hitTest != null);
Offset transformedPosition = position == null || transform == null

4
com.unity.uiwidgets/Runtime/rendering/custom_layout.cs


MultiChildLayoutDelegate _delegate;
/*public override void attach(PipelineOwner owner) {
/*public void attach(PipelineOwner owner) {
base.attach(owner);
_delegate?._relayout?.addListener(markNeedsLayout);
}

base.detach();
}*/
}*/ // [!!!] ???
Size _getSize(BoxConstraints constraints) {
D.assert(constraints.debugAssertIsValid());

3
com.unity.uiwidgets/Runtime/rendering/custom_paint.cs


if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount) {
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary($"The {painter} custom painter called canvas.restore() " +
new ErrorSummary(
$"The {painter} custom painter called canvas.restore() " +
$"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " +
"times than it called canvas.save() or canvas.saveLayer()."
),

32
com.unity.uiwidgets/Runtime/rendering/debug_overflow_indicator.cs


TileMode.repeated
);
_labelBackgroundPaint.color = new Color(0xFFFFFFFF);
for (int i = 0; i < 4; i++) {
_OverflowSide e = new _OverflowSide();
var len = Enum.GetNames(e.GetType()).Length;
for (int i = 0; i < len; i++) {
_indicatorLabel.Add(new TextPainter(textDirection: TextDirection.ltr));
}
}

);
regions.Add(new _OverflowRegionData(
rect: markerRect,
label: "LEFT OVERFLOWED BY ${_formatPixels(overflow.left)} PIXELS",
label: $"LEFT OVERFLOWED BY {_formatPixels(overflow.left)} PIXELS",
labelOffset: markerRect.centerLeft +
new Offset(_indicatorFontSizePixels + _indicatorLabelPaddingPixels, 0.0f),
rotation: Mathf.PI / 2.0f,

static void _reportOverflow(RenderObject renderObject, RelativeRect overflow, List<DiagnosticsNode> overflowHints) {
overflowHints = overflowHints ?? new List<DiagnosticsNode>();
if (overflowHints.isEmpty()) {
overflowHints.Add(new ErrorDescription($"The edge of the {renderObject.GetType()} that is " +
"overflowing has been marked in the rendering with a yellow and black " +
"striped pattern. This is usually caused by the contents being too big " +
$"for the {renderObject.GetType()}."));
overflowHints.Add(
new ErrorDescription(
$"The edge of the {renderObject.GetType()} that is " +
"overflowing has been marked in the rendering with a yellow and black " +
"striped pattern. This is usually caused by the contents being too big " +
$"for the {renderObject.GetType()}."));
overflowHints.Add(new ErrorHint("This is considered an error condition because it indicates that there " +
"is content that cannot be seen. If the content is legitimately bigger " +
"than the available space, consider clipping it with a ClipRect widget " +
$"before putting it in the {renderObject.GetType()}, or using a scrollable " +
"container, like a ListView."));
overflowHints.Add(
new ErrorHint(
"This is considered an error condition because it indicates that there " +
"is content that cannot be seen. If the content is legitimately bigger " +
"than the available space, consider clipping it with a ClipRect widget " +
$"before putting it in the {renderObject.GetType()}, or using a scrollable " +
"container, like a ListView."));
List<string> overflows = new List<string> { };
List<string> overflows = new List<string>();
if (overflow.left > 0.0f) {
overflows.Add($"{_formatPixels(overflow.left)} pixels on the left");
}

}
yield return DiagnosticsNode.message($"The specific {renderObject.GetType()} in question is: {renderObject.toStringShallow(joiner: "\n ")}");
yield return DiagnosticsNode.message(string.Concat(Enumerable.Repeat("◢◤", 32)));
yield return DiagnosticsNode.message(string.Concat(Enumerable.Repeat("◢◤", 32)),allowWrap: false);
}
UIWidgetsError.reportError(

117
com.unity.uiwidgets/Runtime/rendering/editable.cs


}
public override string ToString() {
return $"Point: {point}, Direction: {direction}";
switch (direction) {
case TextDirection.ltr:
return $"{point}-ltr";
case TextDirection.rtl:
return $"{point}-rtl";
}
return $"{point}";
}
}

bool? enableInteractiveSelection = null,
EdgeInsets floatingCursorAddedMargin = null,
TextSelectionDelegate textSelectionDelegate = null)
//GlobalKeyEventHandlerDelegate globalKeyEventHandler = null)
{
floatingCursorAddedMargin = floatingCursorAddedMargin ?? EdgeInsets.fromLTRB(4, 4, 4, 5);

_textLayoutLastMinWidth = null;
}
/*void _handleSetSelection(TextSelection selection) {
_handleSelectionChange(selection, SelectionChangedCause.keyboard);
}
void _handleMoveCursorForwardByCharacter(bool extentSelection) {
int extentOffset = _textPainter.getOffsetAfter(_selection.extentOffset);
if (extentOffset == null)
return;
int baseOffset = !extentSelection ? extentOffset : _selection.baseOffset;
_handleSelectionChange(
new TextSelection(baseOffset: baseOffset, extentOffset: extentOffset), SelectionChangedCause.keyboard
);
}
void _handleMoveCursorBackwardByCharacter(bool extentSelection) {
int extentOffset = _textPainter.getOffsetBefore(_selection.extentOffset);
if (extentOffset == null)
return;
int baseOffset = !extentSelection ? extentOffset : _selection.baseOffset;
_handleSelectionChange(
new TextSelection(baseOffset: baseOffset, extentOffset: extentOffset), SelectionChangedCause.keyboard
);
}
void _handleMoveCursorForwardByWord(bool extentSelection) {
TextRange currentWord = _textPainter.getWordBoundary(_selection.extent);
if (currentWord == null)
return;
TextRange nextWord = _getNextWord(currentWord.end);
if (nextWord == null)
return;
int baseOffset = extentSelection ? _selection.baseOffset : nextWord.start;
_handleSelectionChange(
new TextSelection(
baseOffset: baseOffset,
extentOffset: nextWord.start
),
SelectionChangedCause.keyboard
);
}
void _handleMoveCursorBackwardByWord(bool extentSelection) {
TextRange currentWord = _textPainter.getWordBoundary(_selection.extent);
if (currentWord == null)
return;
TextRange previousWord = _getPreviousWord(currentWord.start - 1);
if (previousWord == null)
return;
int baseOffset = extentSelection ? _selection.baseOffset : previousWord.start;
_handleSelectionChange(
new TextSelection(
baseOffset: baseOffset,
extentOffset: previousWord.start
),
SelectionChangedCause.keyboard
);
}
TextRange _getNextWord(int offset) {
while (true) {
TextRange range = _textPainter.getWordBoundary(new TextPosition(offset: offset));
if (range == null || !range.isValid || range.isCollapsed)
return null;
if (!_onlyWhitespace(range))
return range;
offset = range.end;
}
}
TextRange _getPreviousWord(int offset) {
while (offset >= 0) {
TextRange range = _textPainter.getWordBoundary(new TextPosition(offset: offset));
if (range == null || !range.isValid || range.isCollapsed)
return null;
if (!_onlyWhitespace(range))
return range;
offset = range.start - 1;
}
return null;
}
bool _onlyWhitespace(TextRange range) {
for (int i = range.start; i < range.end; i++) {
int codeUnit = text.codeUnitAt(i).Value;
if (!EditableUtils._isWhitespace(codeUnit)) {
return false;
}
}
return true;
}*/ //need?
public void attach(PipelineOwner owner) {
_tap = new TapGestureRecognizer(debugOwner: this);
_tap.onTapDown = _handleTapDown;

if (position.offset >= word.end) {
return TextSelection.fromPosition(position);
}
if (obscureText) {
return new TextSelection(baseOffset: 0, extentOffset: _plainText.Length);
}
return new TextSelection(baseOffset: word.start, extentOffset: word.end);
}

if (caretHeight != null) {
switch (Application.platform) {
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.OSXPlayer:
// Center the caret vertically along the text.
caretRect = Rect.fromLTWH(
caretRect.left,
(caretRect.top + heightDiff / 2).Value,

break;
case RuntimePlatform.Android:
// case TargetPlatform.fuchsia:[!!!]
case RuntimePlatform.LinuxPlayer:
case RuntimePlatform.WindowsPlayer:
// Override the height to take the full height of the glyph at the TextPosition
// when not on iOS. iOS has special handling that creates a taller caret.
// TODO(garyq): See the TODO for _getCaretPrototype.
default:
caretRect = Rect.fromLTWH(
caretRect.left,
caretRect.top - EditableUtils._kCaretHeightOffset,

context.pushClipRect(needsCompositing, offset, Offset.zero & size, _paintContents);
}
else {
_paintContents(context, offset);
_paintHandleLayers(context, getEndpointsForSelection(selection));
}
}

82
com.unity.uiwidgets/Runtime/rendering/flex.cs


public int flex;
public FlexFit fit;
public override string ToString() => $"{base.ToString()}; flex={flex}; fit={fit}";
}
public enum MainAxisSize {

public TextBaseline _textBaseline;
bool _debugHasNecessaryDirections {
get {
if (firstChild != null && lastChild != firstChild) {
// i.e. there's more than one child
switch (direction) {
case Axis.horizontal:
D.assert(textDirection != null, () => "Horizontal $runtimeType with multiple children has a null textDirection, so the layout order is undefined.");
break;
case Axis.vertical:
D.assert(verticalDirection != null, () => "Vertical $runtimeType with multiple children has a null verticalDirection, so the layout order is undefined.");
break;
}
}
if (mainAxisAlignment == MainAxisAlignment.start ||
mainAxisAlignment == MainAxisAlignment.end) {
switch (direction) {
case Axis.horizontal:
D.assert(textDirection != null, () => "Horizontal $runtimeType with $mainAxisAlignment has a null textDirection, so the alignment cannot be resolved.");
break;
case Axis.vertical:
D.assert(verticalDirection != null, () => "Vertical $runtimeType with $mainAxisAlignment has a null verticalDirection, so the alignment cannot be resolved.");
break;
}
}
if (crossAxisAlignment == CrossAxisAlignment.start ||
crossAxisAlignment == CrossAxisAlignment.end) {
switch (direction) {
case Axis.horizontal:
D.assert(verticalDirection != null, () => "Horizontal $runtimeType with $crossAxisAlignment has a null verticalDirection, so the alignment cannot be resolved.");
break;
case Axis.vertical:
D.assert(textDirection != null, () => "Vertical $runtimeType with $crossAxisAlignment has a null textDirection, so the alignment cannot be resolved.");
break;
}
}
return true;
}
}
public float _overflow;
bool _hasOverflow {

}
public float _getIntrinsicSize(
Axis sizingDirection,
float extent,
_ChildSizingFunction childSize
Axis? sizingDirection = null,
float? extent = null,
_ChildSizingFunction childSize = null
) {
if (_direction == sizingDirection) {
float totalFlex = 0.0f;

int flex = _getFlex(child);
totalFlex += flex;
if (flex > 0) {
float flexFraction = childSize(child, extent) / _getFlex(child);
float flexFraction = childSize(child, extent.Value) / _getFlex(child);
inflexibleSpace += childSize(child, extent);
inflexibleSpace += childSize(child, extent.Value);
}
var childParentData = (FlexParentData) child.parentData;

return maxFlexFractionSoFar * totalFlex + inflexibleSpace;
}
else {
float availableMainSpace = extent;
float? availableMainSpace = extent;
int totalFlex = 0;
float inflexibleSpace = 0.0f;
float maxCrossSize = 0.0f;

child = childParentData.nextSibling;
}
float spacePerFlex = Mathf.Max(0.0f, (availableMainSpace - inflexibleSpace) / totalFlex);
float spacePerFlex = Mathf.Max(0.0f, ((availableMainSpace - inflexibleSpace) / totalFlex).Value);
child = firstChild;
while (child != null) {

}
protected override void performLayout() {
D.assert(_debugHasNecessaryDirections);
D.assert(constraints != null);
float maxMainSize = _direction == Axis.horizontal
? constraints.maxWidth
: constraints.maxHeight;

allocatedSize += _getMainSize(child);
crossSize = Mathf.Max(crossSize, _getCrossSize(child));
}
D.assert(child.parentData == childParentData);
child = childParentData.nextSibling;
}

protected override bool hitTestChildren(BoxHitTestResult result, Offset position = null) {
return defaultHitTestChildren(result, position: position);
}
public override Rect describeApproximatePaintClip(RenderObject child) => _hasOverflow ? Offset.zero & size : null;
public override string toStringShort() {
String header = base.toStringShort();
if (_overflow is float && _hasOverflow)
header += " OVERFLOWING";
return header;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<Axis>("direction", direction));
properties.add(new EnumProperty<MainAxisAlignment>("mainAxisAlignment", mainAxisAlignment));
properties.add(new EnumProperty<MainAxisSize>("mainAxisSize", mainAxisSize));
properties.add(new EnumProperty<CrossAxisAlignment>("crossAxisAlignment", crossAxisAlignment));
properties.add(new EnumProperty<TextDirection>("textDirection", textDirection, defaultValue: null));
properties.add(new EnumProperty<VerticalDirection>("verticalDirection", verticalDirection, defaultValue: null));
properties.add(new EnumProperty<TextBaseline>("textBaseline", textBaseline, defaultValue: null));
}
}
}

1
com.unity.uiwidgets/Runtime/rendering/image.cs


bool invertColors = false,
FilterQuality filterQuality = FilterQuality.low
) {
D.assert(alignment != null);
_image = image;
_width = width;
_height = height;

60
com.unity.uiwidgets/Runtime/rendering/layer.cs


public class TransformLayer : OffsetLayer {
public TransformLayer(Matrix4 transform = null, Offset offset = null) : base(offset) {
offset = offset ?? Offset.zero;
_transform = transform ?? Matrix4.identity();
}

}
/*public class PlatformViewLayer : Layer {
/// Creates a platform view layer.
///
/// The `rect` and `viewId` parameters must not be null.
public PlatformViewLayer(
Rect rect = null,
int viewId = default,

}
public readonly Rect rect;
public readonly Rect rect;
public readonly int viewId;
public readonly int viewId;
public readonly MouseTrackerAnnotation hoverAnnotation;
public readonly MouseTrackerAnnotation hoverAnnotation;
public override void addToScene(ui.SceneBuilder builder, Offset layerOffset = null) {
Rect shiftedRect = layerOffset == Offset.zero ? rect : rect.shift(layerOffset);
builder.addPlatformView(
viewId,
offset: shiftedRect.topLeft,
width: shiftedRect.width,
height: shiftedRect.height
);
}
public override void addToScene(ui.SceneBuilder builder, Offset layerOffset = null) {
Rect shiftedRect = layerOffset == Offset.zero ? rect : rect.shift(layerOffset);
builder.addPlatformView(
viewId,
offset: shiftedRect.topLeft,
width: shiftedRect.width,
height: shiftedRect.height
);
}
public override bool findAnnotations<S>(AnnotationResult<S> result, Offset localPosition, bool onlyFirst ) {
if (hoverAnnotation == null || !rect.contains(localPosition)) {
return false;
}
if (typeof(S) == typeof(MouseTrackerAnnotation)) {
Object untypedValue = hoverAnnotation;
S typedValue = (S)untypedValue;
result.add(new AnnotationEntry<S>(
annotation: typedValue,
localPosition: localPosition
));
return true;
}
return false;
}
}*/
public override bool findAnnotations<S>(AnnotationResult<S> result, Offset localPosition, bool onlyFirst ) {
if (hoverAnnotation == null || !rect.contains(localPosition)) {
return false;
}
if (typeof(S) == typeof(MouseTrackerAnnotation)) {
Object untypedValue = hoverAnnotation;
S typedValue = (S)untypedValue;
result.add(new AnnotationEntry<S>(
annotation: typedValue,
localPosition: localPosition
));
return true;
}
return false;
}
}*/
public class PerformanceOverlayLayer : Layer {
public PerformanceOverlayLayer(

3
com.unity.uiwidgets/Runtime/rendering/list_body.cs


"placed in a parent that does not constrain the main axis."
),
new ErrorHint(
"You probably want to put the RenderListBody inside a " +
"You probably want to put the RenderListBody inside a " +
"RenderViewport with a matching main axis."
)
});

case Axis.vertical:
return _getIntrinsicCrossAxis((RenderBox child) => child.getMinIntrinsicWidth(height));
}
D.assert(false);
return 0.0f;
}

19
com.unity.uiwidgets/Runtime/rendering/list_wheel_viewport.cs


public interface IListWheelChildManager {
int? childCount { get; }
bool childExistsAt(int index);
void createChild(int index, RenderBox after);
void createChild(int index, RenderBox after = null);
void removeChild(RenderBox child);
}

PaintingContext context,
Offset offset,
RenderBox child,
// Matrix4x4 cylindricalTransform,
Matrix4 cylindricalTransform,
Offset offsetToCenter,
Offset untransformedPaintingCoordinates

if (isAfterMagnifierTopLine && isBeforeMagnifierBottomLine) {
Rect centerRect = Rect.fromLTWH(
0.0f,
magnifierTopLinePosition, size.width, _itemExtent * _magnification);
magnifierTopLinePosition,
size.width,
_itemExtent * _magnification);
Rect topHalfRect = Rect.fromLTWH(
0.0f,
0.0f, size.width,

magnifierBottomLinePosition, size.width,
magnifierBottomLinePosition,
size.width,
magnifierTopLinePosition);
context.pushClipRect(

-centerOriginTranslation.dy);
return result;*/ //[!!!]need?
}
Matrix4 _magnifyTransform() {
Matrix4 magnify = Matrix4.identity();
magnify.translate(size.width * (-_offAxisFraction + 0.5), size.height / 2);
magnify.scale(_magnification, _magnification, _magnification);
magnify.translate(-size.width * (-_offAxisFraction + 0.5), -size.height / 2);
return magnify;
}
public override Rect describeApproximatePaintClip(RenderObject child) {
if (child != null && _shouldClipAtCurrentOffset()) {

8
com.unity.uiwidgets/Runtime/rendering/view.cs


owner.requestVisualUpdate();
}
public void prepareInitialFrame() {
D.assert(owner != null);
D.assert(_rootTransform == null);
scheduleInitialLayout();
scheduleInitialPaint((OffsetLayer)_updateMatricesAndCreateNewRootLayer());
D.assert(_rootTransform != null);
}
Matrix4 _rootTransform;
public Layer _updateMatricesAndCreateNewRootLayer() {

正在加载...
取消
保存