浏览代码

Merge pull request #223 from UnityTech/gif

Fix gif not animating problem.
/main
GitHub 6 年前
当前提交
dad6b7e3
共有 4 个文件被更改,包括 87 次插入21 次删除
  1. 17
      Runtime/flow/raster_cache.cs
  2. 4
      Runtime/ui/painting/codec_gif.cs
  3. 9
      Runtime/ui/painting/image.cs
  4. 78
      Runtime/ui/painting/picture.cs

17
Runtime/flow/raster_cache.cs


var y = this.matrix[5] * devicePixelRatio;
this.matrix[2] = (x - (int) x) / devicePixelRatio; // x
this.matrix[5] = (y - (int) y) / devicePixelRatio; // y
this.matrix[5] = 0.0f;
this.matrix[5] = 0.0f;
this.devicePixelRatio = devicePixelRatio;
this.antiAliasing = antiAliasing;
}

readonly Dictionary<_RasterCacheKey, _RasterCacheEntry> _cache;
MeshPool _meshPool;
Picture picture, Matrix3 transform, float devicePixelRatio, int antiAliasing, bool isComplex, bool willChange) {
Picture picture, Matrix3 transform, float devicePixelRatio, int antiAliasing, bool isComplex,
bool willChange) {
if (this.threshold == 0) {
return null;
}

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

}
if (!bounds.isFinite) {
return false;
}
if (picture.isDynamic) {
return false;
}

4
Runtime/ui/painting/codec_gif.cs


using System;
using System.Collections;
using System.IO;
using RSG;
using Unity.UIWidgets.foundation;
using UnityEngine;

if (this._texture == null) {
this._texture = new Texture2D(this._width, this._height, TextureFormat.BGRA32, false);
this._texture.hideFlags = HideFlags.HideAndDontSave;
this._image = new Image(this._texture);
this._image = new Image(this._texture, isDynamic: true);
this._frameData.gifFrame = this._decoder.currentFrame;
D.assert(this._frameData.gifFrame != null);

9
Runtime/ui/painting/image.cs


Texture _texture;
readonly bool _noDispose;
readonly bool _isAsset;
readonly bool _isDynamic;
public Image(Texture texture, bool noDispose = false, bool isAsset = false, AssetBundle bundle = null) {
public Image(Texture texture, bool noDispose = false, bool isAsset = false, AssetBundle bundle = null,
bool isDynamic = false) {
D.assert(!noDispose || !isAsset && bundle == null);
D.assert(isAsset || bundle == null);

this._bundle = bundle;
this._isDynamic = isDynamic;
}
public int width {

public Texture texture {
get { return this._texture; }
}
public bool isDynamic {
get { return this._isDynamic; }
}
~Image() {

78
Runtime/ui/painting/picture.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;
public Picture(List<DrawCmd> drawCmds, Rect paintBounds) {
public Picture(List<DrawCmd> drawCmds, Rect paintBounds, bool isDynamic = false) {
this._isDynamic = isDynamic;
public bool isDynamic {
get { return this._isDynamic; }
}
bool _isDynamic;
}
public class PictureRecorder {

bool _isDynamic;
public PictureRecorder() {
this.reset();
}

public void reset() {
this._drawCmds.Clear();
this._isDynamic = false;
this._states.Clear();
this._states.Add(new CanvasState {
xform = Matrix3.I(),

throw new Exception("unmatched save/restore commands");
}
var state = this._getState();
return new Picture(new List<DrawCmd>(this._drawCmds), state.paintBounds);
var state = this._getState();
return new Picture(new List<DrawCmd>(this._drawCmds), state.paintBounds, this._isDynamic);
}
public void addDrawCmd(DrawCmd drawCmd) {

});
break;
}
case DrawRestore _: {
var stateToRestore = this._getState();
this._states.RemoveAt(this._states.Count - 1);

state.paintBounds = stateToRestore.paintBounds;
} else {
}
else {
case DrawTranslate cmd: {
var state = this._getState();
state.xform = new Matrix3(state.xform);

case DrawScale cmd: {
var state = this._getState();
state.xform = new Matrix3(state.xform);

} else {
}
else {
case DrawSkew cmd: {
var state = this._getState();
state.xform = new Matrix3(state.xform);

case DrawConcat cmd: {
var state = this._getState();
state.xform = new Matrix3(state.xform);

case DrawClipRect cmd: {
var state = this._getState();

}
case DrawClipRRect cmd: {
var state = this._getState();

}
case DrawClipPath cmd: {
var state = this._getState();
var scale = XformUtils.getScale(state.xform);

state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect);
break;
}
case DrawPath cmd: {
var state = this._getState();
var scale = XformUtils.getScale(state.xform);

if (paint.style == PaintingStyle.fill) {
var cache = path.flatten(scale * devicePixelRatio);
mesh = cache.getFillMesh(out _).transform(state.xform);
} else {
}
else {
float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f);
float fringeWidth = 1 / devicePixelRatio;

paint.strokeJoin,
paint.strokeMiterLimit).transform(state.xform);
}
} else {
}
else {
case DrawImage cmd: {
var state = this._getState();
var rect = Rect.fromLTWH(cmd.offset.dx, cmd.offset.dy,

if (cmd.image.isDynamic) {
this._isDynamic = true;
}
if (cmd.image.isDynamic) {
this._isDynamic = true;
}
if (cmd.image.isDynamic) {
this._isDynamic = true;
}
if (cmd.picture.isDynamic) {
this._isDynamic = true;
}
} else {
}
else {
default:
throw new Exception("unknown drawCmd: " + drawCmd);
}

if (state.paintBounds.isEmpty) {
state.paintBounds = paintBounds;
} else {
}
else {
state.paintBounds = state.paintBounds.expandToInclude(paintBounds);
}
}

正在加载...
取消
保存