浏览代码

Check canvas clipping bounds and record bounds.

/main
Yuncong Zhang 5 年前
当前提交
081956e2
共有 4 个文件被更改,包括 82 次插入1 次删除
  1. 8
      Runtime/ui/painting/path.cs
  2. 64
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs
  3. 8
      Runtime/ui/renderer/common/geometry/path/path.cs
  4. 3
      Runtime/ui/txt/paragraph.cs

8
Runtime/ui/painting/path.cs


return Rect.fromLTRB(this._minX, this._minY, this._maxX, this._maxY);
}
public Rect getBoundsWithMargin(float margin) {
if (this._minX - margin >= this._maxX + margin || this._minY - margin >= this._maxY + margin) {
return Rect.zero;
}
return Rect.fromLTRB(this._minX - margin, this._minY - margin, this._maxX + margin, this._maxY + margin);
}
public static Path combine(PathOperation operation, Path path1, Path path2) {
D.assert(path1 != null);
D.assert(path2 != null);

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


int saveCount = 0;
var drawCmds = picture.drawCmds;
var queryBound = this._currentLayer.currentState.matrix?.invert().Value
.mapRect(this._currentLayer.layerBounds) ??
this._currentLayer.layerBounds;
foreach (var drawCmd in drawCmds) {
switch (drawCmd) {
case DrawSave _:

}
case DrawPath cmd: {
if (uiRectHelper.intersect(uiRectHelper.fromRect(
cmd.path.getBoundsWithMargin(5)).Value, queryBound).isEmpty) {
continue;
}
var uipath = uiPath.fromPath(cmd.path);
this._drawPath(uipath, uiPaint.fromPaint(cmd.paint));
uiPathCacheManager.putToCache(uipath);

case DrawImage cmd: {
if (uiRectHelper.intersect(uiRectHelper.fromLTWH(
cmd.offset.dx, cmd.offset.dy,
cmd.image.width / this._devicePixelRatio,
cmd.image.height / this._devicePixelRatio), queryBound).isEmpty) {
continue;
}
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value,
uiPaint.fromPaint(cmd.paint));
break;

if (uiRectHelper.intersect(uiRectHelper.fromRect(cmd.dst).Value, queryBound).isEmpty) {
continue;
}
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst).Value,
uiPaint.fromPaint(cmd.paint));
break;

if (uiRectHelper.intersect(uiRectHelper.fromLTRB(
cmd.dst.left + ((cmd.center.left - cmd.src.left) * cmd.src.width),
cmd.dst.top + ((cmd.center.top - cmd.src.top) * cmd.src.height),
cmd.dst.right - ((cmd.src.right - cmd.center.right) * cmd.src.width),
cmd.dst.bottom - ((cmd.src.bottom - cmd.center.bottom) * cmd.src.height)
), queryBound).isEmpty) {
continue;
}
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src),
uiRectHelper.fromRect(cmd.center).Value, uiRectHelper.fromRect(cmd.dst).Value,
uiPaint.fromPaint(cmd.paint));

case DrawPicture cmd: {
if (uiRectHelper.intersect(uiRectHelper.fromRect(
cmd.picture.paintBounds).Value, queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(uiRectHelper.fromRect(
cmd.textBlob.Value.boundsInText.translate(cmd.offset.dx, cmd.offset.dy)).Value, queryBound).isEmpty) {
continue;
}
this._paintTextShadow(cmd.textBlob, cmd.offset);
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value,
uiPaint.fromPaint(cmd.paint));

int saveCount = 0;
var drawCmds = picture.drawCmds;
var queryBound = this._currentLayer.currentState.matrix?.invert().Value
.mapRect(this._currentLayer.layerBounds) ??
this._currentLayer.layerBounds;
foreach (var drawCmd in drawCmds) {
switch (drawCmd) {
case uiDrawSave _:

}
case uiDrawPath cmd: {
if (uiRectHelper.intersect(cmd.path.getBoundsWithMargin(5), queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(uiRectHelper.fromLTWH(
cmd.offset.Value.dx, cmd.offset.Value.dy,
cmd.image.width / this._devicePixelRatio,
cmd.image.height / this._devicePixelRatio), queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(cmd.dst.Value, queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(uiRectHelper.fromLTRB(
cmd.dst.Value.left + ((cmd.center.Value.left - cmd.src.Value.left) * cmd.src.Value.width),
cmd.dst.Value.top + ((cmd.center.Value.top - cmd.src.Value.top) * cmd.src.Value.height),
cmd.dst.Value.right - ((cmd.src.Value.right - cmd.center.Value.right) * cmd.src.Value.width),
cmd.dst.Value.bottom - ((cmd.src.Value.bottom - cmd.center.Value.bottom) * cmd.src.Value.height)
), queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(uiRectHelper.fromRect(
cmd.picture.paintBounds).Value, queryBound).isEmpty) {
continue;
}
if (uiRectHelper.intersect(uiRectHelper.fromRect(
cmd.textBlob.Value.boundsInText.translate(cmd.offset.Value.dx, cmd.offset.Value.dy)).Value,
queryBound).isEmpty) {
continue;
}
this._paintTextShadow(cmd.textBlob, new Offset(cmd.offset.Value.dx, cmd.offset.Value.dy));
this._drawTextBlob(cmd.textBlob, cmd.offset.Value, cmd.paint);
break;

8
Runtime/ui/renderer/common/geometry/path/path.cs


return uiRectHelper.fromLTRB(this._minX, this._minY, this._maxX, this._maxY);
}
public uiRect getBoundsWithMargin(float margin) {
if (this._minX - margin >= this._maxX + margin || this._minY - margin >= this._maxY + margin) {
return uiRectHelper.zero;
}
return uiRectHelper.fromLTRB(this._minX - margin, this._minY - margin, this._maxX + margin, this._maxY + margin);
}
void _appendMoveTo(float x, float y) {
this._commands.Add((float) uiPathCommand.moveTo);
this._commands.Add(x);

3
Runtime/ui/txt/paragraph.cs


// If all the positions have not changed, use the cached ellipsized text
// else update the cache
if (!(this._ellipsizedLength == textStart + textCount - truncateCount &&
if (!(this._ellipsizedText != null &&
this._ellipsizedLength == textStart + textCount - truncateCount &&
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
this._ellipsizedText.EndsWith(ellipsis))) {
this._ellipsizedText =

正在加载...
取消
保存