| 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 import 'package:mojo/core.dart' as core; | 8 import 'package:mojo/core.dart' as core; |
| 9 import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart'; | 9 import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart'; |
| 10 | 10 |
| 11 import 'shell.dart' as shell; | 11 import 'shell.dart' as shell; |
| 12 import 'net/fetch.dart'; | 12 import 'net/fetch.dart'; |
| 13 | 13 |
| 14 Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) { | 14 Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) { |
| 15 Completer<sky.Image> completer = new Completer(); | 15 Completer<sky.Image> completer = new Completer<sky.Image>(); |
| 16 new sky.ImageDecoder(assetData.handle.h, completer.complete); | 16 new sky.ImageDecoder(assetData.handle.h, completer.complete); |
| 17 return completer.future; | 17 return completer.future; |
| 18 } | 18 } |
| 19 | 19 |
| 20 abstract class AssetBundle { | 20 abstract class AssetBundle { |
| 21 void close(); | 21 void close(); |
| 22 Future<sky.Image> fetchImage(String key); | 22 Future<sky.Image> fetchImage(String key); |
| 23 } | 23 } |
| 24 | 24 |
| 25 class NetworkAssetBundle extends AssetBundle { | 25 class NetworkAssetBundle extends AssetBundle { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 _bundle.close(); | 59 _bundle.close(); |
| 60 _bundle = null; | 60 _bundle = null; |
| 61 } | 61 } |
| 62 | 62 |
| 63 Future<sky.Image> fetchImage(String name) async { | 63 Future<sky.Image> fetchImage(String name) async { |
| 64 core.MojoDataPipeConsumer assetData = | 64 core.MojoDataPipeConsumer assetData = |
| 65 (await _bundle.ptr.getAsStream(name)).assetData; | 65 (await _bundle.ptr.getAsStream(name)).assetData; |
| 66 return await _decodeImage(assetData); | 66 return await _decodeImage(assetData); |
| 67 } | 67 } |
| 68 } | 68 } |
| OLD | NEW |