| Index: examples/dart/camera_video/lib/main.dart
|
| diff --git a/examples/dart/camera_video/lib/main.dart b/examples/dart/camera_video/lib/main.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..678904d166b8b05c106693ba6c3dd1411afb35ca
|
| --- /dev/null
|
| +++ b/examples/dart/camera_video/lib/main.dart
|
| @@ -0,0 +1,79 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +// This example makes use of mojo:camera which is available only when
|
| +// running on Android. It repeatedly captures camera video frame images
|
| +// and displays it in a mojo view.
|
| +//
|
| +// Example usage:
|
| +// pub get
|
| +// pub run sky_tools build
|
| +// pub run sky_tools run_mojo --mojo-path=../../.. --android
|
| +
|
| +import 'dart:sky';
|
| +import 'dart:typed_data';
|
| +
|
| +import 'package:mojo_services/mojo/camera.mojom.dart';
|
| +import 'package:sky/services.dart';
|
| +
|
| +Image image = null;
|
| +final CameraVideoServiceProxy cameraRoll = new CameraVideoServiceProxy.unbound();
|
| +
|
| +Picture paint(Rect paintBounds) {
|
| + PictureRecorder recorder = new PictureRecorder();
|
| + if (image != null) {
|
| + Canvas canvas = new Canvas(recorder, paintBounds);
|
| + canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
| + canvas.scale(0.3, 0.3);
|
| + Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
|
| + canvas.drawImage(image, new Point(-image.width / 2.0, -image.height / 2.0), paint);
|
| + }
|
| + return recorder.endRecording();
|
| +}
|
| +
|
| +Scene composite(Picture picture, Rect paintBounds) {
|
| + final double devicePixelRatio = view.devicePixelRatio;
|
| + Rect sceneBounds = new Rect.fromLTWH(
|
| + 0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio);
|
| + Float32List deviceTransform = new Float32List(16)
|
| + ..[0] = devicePixelRatio
|
| + ..[5] = devicePixelRatio
|
| + ..[10] = 1.0
|
| + ..[15] = 1.0;
|
| + SceneBuilder sceneBuilder = new SceneBuilder(sceneBounds)
|
| + ..pushTransform(deviceTransform)
|
| + ..addPicture(Offset.zero, picture, paintBounds)
|
| + ..pop();
|
| + return sceneBuilder.build();
|
| +}
|
| +
|
| +void beginFrame(double timeStamp) {
|
| + Rect paintBounds = new Rect.fromLTWH(0.0, 0.0, view.width, view.height);
|
| + Picture picture = paint(paintBounds);
|
| + Scene scene = composite(picture, paintBounds);
|
| + view.scene = scene;
|
| +}
|
| +
|
| +void drawNextPhoto() {
|
| + var future = cameraRoll.ptr.getVideoFrames();
|
| + future.then((response) {
|
| + if (response.content == null) {
|
| + drawNextPhoto();
|
| + return;
|
| + }
|
| + new ImageDecoder(response.content.handle.h, (frame) {
|
| + if (frame != null) {
|
| + image = frame;
|
| + view.scheduleFrame();
|
| + drawNextPhoto();
|
| + }
|
| + });
|
| + });
|
| +}
|
| +
|
| +void main() {
|
| + view.setFrameCallback(beginFrame);
|
| + embedder.connectToService("mojo:camera", cameraRoll);
|
| + drawNextPhoto();
|
| +}
|
|
|