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 // This example makes use of mojo:camera which is available only when | 5 // This example makes use of mojo:camera which is available only when |
6 // running on Android. It repeatedly captures camera video frame images | 6 // running on Android. It repeatedly captures camera video frame images |
7 // and displays it in a mojo view. | 7 // and displays it in a mojo view. |
8 // | 8 // |
9 // Example usage: | 9 // Example usage: |
10 // pub get | 10 // pub get |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } | 55 } |
56 | 56 |
57 void beginFrame(double timeStamp) { | 57 void beginFrame(double timeStamp) { |
58 Rect paintBounds = new Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height); | 58 Rect paintBounds = new Rect.fromLTWH(0.0, 0.0, ui.view.width, ui.view.height); |
59 Picture picture = paint(paintBounds); | 59 Picture picture = paint(paintBounds); |
60 ui.Scene scene = composite(picture, paintBounds); | 60 ui.Scene scene = composite(picture, paintBounds); |
61 ui.view.scene = scene; | 61 ui.view.scene = scene; |
62 } | 62 } |
63 | 63 |
64 void drawNextPhoto() { | 64 void drawNextPhoto() { |
65 var future = camera.ptr.getLatestFrame(); | 65 var future = camera.getLatestFrame(); |
66 future.then((response) { | 66 future.then((response) { |
67 if (response.content == null) { | 67 if (response.content == null) { |
68 drawNextPhoto(); | 68 drawNextPhoto(); |
69 return; | 69 return; |
70 } | 70 } |
71 | 71 |
72 final imageFrame = decodeImageFromDataPipe(response.content); | 72 final imageFrame = decodeImageFromDataPipe(response.content); |
73 imageFrame.then((frame) { | 73 imageFrame.then((frame) { |
74 if (frame != null) { | 74 if (frame != null) { |
75 image = frame; | 75 image = frame; |
76 ui.view.scheduleFrame(); | 76 ui.view.scheduleFrame(); |
77 drawNextPhoto(); | 77 drawNextPhoto(); |
78 } | 78 } |
79 }); | 79 }); |
80 }); | 80 }); |
81 } | 81 } |
82 | 82 |
83 void main() { | 83 void main() { |
84 embedder.connectToService("mojo:camera", camera); | 84 embedder.connectToService("mojo:camera", camera); |
85 drawNextPhoto(); | 85 drawNextPhoto(); |
86 ui.view.setFrameCallback(beginFrame); | 86 ui.view.setFrameCallback(beginFrame); |
87 } | 87 } |
OLD | NEW |