浏览代码

Merge pull request #354 from UnityTech/fix_raster_cache_assert2

fix assert when devicepixelratio is not integer
/main
GitHub 5 年前
当前提交
04ed4e3f
共有 2 个文件被更改,包括 19 次插入7 次删除
  1. 10
      Runtime/ui/geometry.cs
  2. 16
      Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs

10
Runtime/ui/geometry.cs


Mathf.Ceil(this.right), Mathf.Ceil(this.bottom));
}
public Rect roundOut(float devicePixelRatio) {
public Rect roundOutScale(float scale) {
return fromLTRB(
Mathf.Floor(this.left * scale),
Mathf.Floor(this.top * scale),
Mathf.Ceil(this.right * scale),
Mathf.Ceil(this.bottom * scale));
}
public Rect withDevicePixelRatio(float devicePixelRatio) {
return fromLTRB(
Mathf.Floor(this.left * devicePixelRatio) / devicePixelRatio,
Mathf.Floor(this.top * devicePixelRatio) / devicePixelRatio,

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


public readonly float devicePixelRatio;
public void draw(Canvas canvas) {
var bounds = canvas.getTotalMatrix().mapRect(this.logicalRect).roundOut(this.devicePixelRatio);
var boundRect = canvas.getTotalMatrix().mapRect(this.logicalRect);
var bounds = boundRect.withDevicePixelRatio(this.devicePixelRatio);
var textureWidth = Mathf.CeilToInt(bounds.width * this.devicePixelRatio);
var textureHeight = Mathf.CeilToInt(bounds.height * this.devicePixelRatio);
var boundsInPixel = boundRect.roundOutScale(this.devicePixelRatio);
var textureWidth = Mathf.CeilToInt(boundsInPixel.width);
var textureHeight = Mathf.CeilToInt(boundsInPixel.height);
//it is possible that there is a minor difference between the bound size and the image size (1 pixel at
//most) due to the roundOut operation when calculating the bounds if the elements in the canvas transform

RasterCacheResult _rasterizePicture(Picture picture, Matrix3 transform, float devicePixelRatio,
int antiAliasing, MeshPool meshPool) {
var bounds = transform.mapRect(picture.paintBounds).roundOut(devicePixelRatio);
var boundRect = transform.mapRect(picture.paintBounds);
var bounds = boundRect.withDevicePixelRatio(devicePixelRatio);
var boundsInPixel = boundRect.roundOutScale(devicePixelRatio);
Mathf.CeilToInt((bounds.width * devicePixelRatio)),
Mathf.CeilToInt((bounds.height * devicePixelRatio)),
Mathf.CeilToInt(boundsInPixel.width),
Mathf.CeilToInt(boundsInPixel.height),
RenderTextureFormat.Default, 24) {
useMipMap = false,
autoGenerateMips = false,

正在加载...
取消
保存