| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:sky' as sky; | 5 import 'dart:sky' as sky; |
| 6 import 'dart:math' as math; | 6 import 'dart:math' as math; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 | 8 |
| 9 void beginFrame(double timeStamp) { | 9 void beginFrame(double timeStamp) { |
| 10 sky.PictureRecorder context = new sky.PictureRecorder(sky.view.width, 200.0); | 10 sky.PictureRecorder recorder = new sky.PictureRecorder(); |
| 11 Canvas canvas = new Canvas(recorder, sky.view.width, 200.0); |
| 11 | 12 |
| 12 sky.Paint paint = new sky.Paint(); | 13 sky.Paint paint = new sky.Paint(); |
| 13 sky.Point mid = new sky.Point(context.width / 2.0, context.height / 2.0); | 14 sky.Point mid = new sky.Point(sky.view.width / 2.0, sky.view.height / 2.0); |
| 14 double radius = math.min(mid.x, mid.y); | 15 double radius = math.min(mid.x, mid.y); |
| 15 | 16 |
| 16 context.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF)); | 17 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF)); |
| 17 | 18 |
| 18 context.save(); | 19 canvas.save(); |
| 19 | 20 |
| 20 context.translate(-mid.x/2.0, context.height*2.0); | 21 canvas.translate(-mid.x/2.0, sky.view.height*2.0); |
| 21 context.clipRect( | 22 canvas.clipRect( |
| 22 new sky.Rect.fromLTRB(0.0, -context.height, context.width, radius)); | 23 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius)); |
| 23 | 24 |
| 24 context.translate(mid.x, mid.y); | 25 canvas.translate(mid.x, mid.y); |
| 25 paint.color = const sky.Color.fromARGB(128, 255, 0, 255); | 26 paint.color = const sky.Color.fromARGB(128, 255, 0, 255); |
| 26 context.rotate(math.PI/4.0); | 27 canvas.rotate(math.PI/4.0); |
| 27 | 28 |
| 28 sky.Gradient yellowBlue = new sky.Gradient.linear( | 29 sky.Gradient yellowBlue = new sky.Gradient.linear( |
| 29 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)], | 30 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)], |
| 30 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]); | 31 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]); |
| 31 context.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius), | 32 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius), |
| 32 new sky.Paint()..setShader(yellowBlue)); | 33 new sky.Paint()..setShader(yellowBlue)); |
| 33 | 34 |
| 34 // Scale x and y by 0.5. | 35 // Scale x and y by 0.5. |
| 35 var scaleMatrix = new Float32List.fromList([ | 36 var scaleMatrix = new Float32List.fromList([ |
| 36 0.5, 0.0, 0.0, 0.0, | 37 0.5, 0.0, 0.0, 0.0, |
| 37 0.0, 0.5, 0.0, 0.0, | 38 0.0, 0.5, 0.0, 0.0, |
| 38 0.0, 0.0, 0.0, 0.0, | 39 0.0, 0.0, 0.0, 0.0, |
| 39 0.0, 0.0, 0.0, 1.0, | 40 0.0, 0.0, 0.0, 1.0, |
| 40 ]); | 41 ]); |
| 41 context.concat(scaleMatrix); | 42 canvas.concat(scaleMatrix); |
| 42 paint.color = const sky.Color.fromARGB(128, 0, 255, 0); | 43 paint.color = const sky.Color.fromARGB(128, 0, 255, 0); |
| 43 context.drawCircle(0.0, 0.0, radius, paint); | 44 canvas.drawCircle(0.0, 0.0, radius, paint); |
| 44 | 45 |
| 45 context.restore(); | 46 canvas.restore(); |
| 46 | 47 |
| 47 context.translate(0.0, 50.0); | 48 canvas.translate(0.0, 50.0); |
| 48 var builder = new sky.LayerDrawLooperBuilder() | 49 var builder = new sky.LayerDrawLooperBuilder() |
| 49 ..addLayerOnTop( | 50 ..addLayerOnTop( |
| 50 new sky.DrawLooperLayerInfo() | 51 new sky.DrawLooperLayerInfo() |
| 51 ..setOffset(const sky.Point(150.0, 0.0)) | 52 ..setOffset(const sky.Point(150.0, 0.0)) |
| 52 ..setColorMode(sky.TransferMode.src) | 53 ..setColorMode(sky.TransferMode.src) |
| 53 ..setPaintBits(sky.PaintBits.all), | 54 ..setPaintBits(sky.PaintBits.all), |
| 54 (sky.Paint layerPaint) { | 55 (sky.Paint layerPaint) { |
| 55 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0); | 56 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0); |
| 56 layerPaint.setColorFilter(new sky.ColorFilter.mode( | 57 layerPaint.setColorFilter(new sky.ColorFilter.mode( |
| 57 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)); | 58 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 layerPaint.setMaskFilter(new sky.MaskFilter.blur( | 74 layerPaint.setMaskFilter(new sky.MaskFilter.blur( |
| 74 sky.BlurStyle.normal, 50.0, highQuality: true)); | 75 sky.BlurStyle.normal, 50.0, highQuality: true)); |
| 75 }) | 76 }) |
| 76 ..addLayerOnTop( | 77 ..addLayerOnTop( |
| 77 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0))
, | 78 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0))
, |
| 78 (sky.Paint layerPaint) { | 79 (sky.Paint layerPaint) { |
| 79 // Since this layer uses a DST color mode, this has no effect. | 80 // Since this layer uses a DST color mode, this has no effect. |
| 80 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0); | 81 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0); |
| 81 }); | 82 }); |
| 82 paint.setDrawLooper(builder.build()); | 83 paint.setDrawLooper(builder.build()); |
| 83 context.drawCircle(0.0, 0.0, radius, paint); | 84 canvas.drawCircle(0.0, 0.0, radius, paint); |
| 84 | 85 |
| 85 sky.view.picture = context.endRecording(); | 86 sky.view.picture = recorder.endRecording(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void main() { | 89 void main() { |
| 89 sky.view.setBeginFrameCallback(beginFrame); | 90 sky.view.setBeginFrameCallback(beginFrame); |
| 90 sky.view.scheduleFrame(); | 91 sky.view.scheduleFrame(); |
| 91 } | 92 } |
| OLD | NEW |