Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(535)

Side by Side Diff: examples/dart/camera_roll/lib/main.dart

Issue 1375733004: -Add a mojo service to get video frames from the camera through an android service (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove stale files. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // This example makes use of mojo:camera_roll which is available only when
6 // running on Android.
7 //
8 // Example usage:
9 // pub get
10 // pub run sky_tools build
11 // pub run sky_tools run_mojo --mojo-path=../../.. --android
12
13 import 'dart:sky';
14 import 'dart:typed_data';
15
16 import 'package:mojo_services/mojo/camera_roll.mojom.dart';
17 import 'package:sky/services.dart';
18
19 final CameraRollServiceProxy cameraRoll = new CameraRollServiceProxy.unbound();
20 Image currentImage;
21 int photoIndex = 0;
22
23 Picture paint(Rect paintBounds) {
24 PictureRecorder recorder = new PictureRecorder();
25 Canvas canvas = new Canvas(recorder, paintBounds);
26 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
27 if (currentImage != null) {
28 canvas.drawImage(currentImage, new Point(0.0, 0.0), paint);
29 }
30 return recorder.endRecording();
31 }
32
33 Scene composite(Picture picture, Rect paintBounds) {
34 final double devicePixelRatio = view.devicePixelRatio;
35 Rect sceneBounds = new Rect.fromLTWH(
36 0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio);
37 Float32List deviceTransform = new Float32List(16)
38 ..[0] = devicePixelRatio
39 ..[5] = devicePixelRatio
40 ..[10] = 1.0
41 ..[15] = 1.0;
42 SceneBuilder sceneBuilder = new SceneBuilder(sceneBounds)
43 ..pushTransform(deviceTransform)
44 ..addPicture(Offset.zero, picture, paintBounds)
45 ..pop();
46 return sceneBuilder.build();
47 }
48
49 void beginFrame(double timeStamp) {
50 Rect paintBounds = new Rect.fromLTWH(0.0, 0.0, view.width, view.height);
51 Picture picture = paint(paintBounds);
52 Scene scene = composite(picture, paintBounds);
53 view.scene = scene;
54 }
55
56 void getPhoto() {
57 var future = cameraRoll.ptr.getPhoto(photoIndex);
58 future.then((response) {
59 if (response.photo == null) {
60 print("Photo $photoIndex not found, returning to the first photo.");
61 cameraRoll.ptr.update();
62 photoIndex = 0;
63 getPhoto();
64 return;
65 }
66
67 new ImageDecoder(response.photo.content.handle.h, (image) {
68 if (image != null) {
69 currentImage = image;
70 print("view.scheduleFrame");
71 view.scheduleFrame();
72 }
73 });
74 });
75 }
76
77 bool handleEvent(Event event) {
78 if (event.type == 'pointerdown') {
79 return true;
80 }
81
82 if (event.type == 'pointerup') {
83 photoIndex;
84 getPhoto();
85 return true;
86 }
87
88 return false;
89 }
90
91 void main() {
92 embedder.connectToService("mojo:camera", cameraRoll);
93 view.setFrameCallback(beginFrame);
94 view.setEventCallback(handleEvent);
95 getPhoto();
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698