Commit 4f8de2ee authored by Eric Seidel's avatar Eric Seidel

Merge pull request #271 from eseidelGoogle/draw_atlas

Use Skia's drawAtlas now that we've rolled to a newer Skia
parents 9ac347da 7a1e3bb3
...@@ -272,45 +272,13 @@ class ParticleSystem extends Node { ...@@ -272,45 +272,13 @@ class ParticleSystem extends Node {
colors.add(particleColor); colors.add(particleColor);
} }
// TODO(viktork): Verify that the C++ version looks right and is faster!
Paint paint = new Paint()..setTransferMode(transferMode) Paint paint = new Paint()..setTransferMode(transferMode)
..setFilterQuality(FilterQuality.low) // All Skia examples do this. ..setFilterQuality(FilterQuality.low) // All Skia examples do this.
..isAntiAlias = false; // Antialiasing breaks SkCanvas.drawAtlas? ..isAntiAlias = false; // Antialiasing breaks SkCanvas.drawAtlas?
// return canvas.drawAtlas(texture.image, transforms, rects, colors, return canvas.drawAtlas(texture.image, transforms, rects, colors,
// TransferMode.modulate, null, paint); TransferMode.modulate, null, paint);
dartDrawAtlas(canvas, texture.image, transforms, rects, colors,
TransferMode.modulate, paint);
} }
double randMinus1To1() => _rand.nextDouble() * 2.0 - 1.0; double randMinus1To1() => _rand.nextDouble() * 2.0 - 1.0;
} }
void dartDrawAtlas(Canvas canvas, Image image, List<RSTransform> transforms,
List<Rect> rects, List<Color> colors, TransferMode transferMode, Paint paint) {
assert(transforms.length == rects.length && transforms.length == colors.length);
Texture mainTexture = new Texture(image);
for (int i = 0; i < transforms.length; i++) {
RSTransform transform = transforms[i];
Rect rect = rects[i];
Color color = colors[i];
canvas.save();
Matrix4 matrix = new Matrix4(transform.scos, transform.ssin, 0.0, 0.0,
-transform.ssin, transform.scos, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
transform.tx, transform.ty, 0.0, 1.0);
canvas.concat(matrix.storage);
paint.setColorFilter(new ColorFilter.mode(color, transferMode));
paint.color = color;
Texture texture = mainTexture.textureFromRect(rect);
texture.drawTexture(canvas, new Point(-texture.size.width/2.0, -texture.size.height/2.0), paint);
canvas.restore();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment