提交 fe2c731e 编写于 作者: A Adam Barth

Add package:sky/mojo/asset_bundle.dart to wrap mojo:asset_bundle

This Dart library exposes a more idiomatic interface to the asset_bundle
service and provides integration with dart:sky.

R=viktorl@google.com

Review URL: https://codereview.chromium.org/1200463002.
上级 641117c5
......@@ -71,6 +71,7 @@ dart_pkg("sdk") {
"lib/framework/theme/typography.dart",
"lib/framework/theme/view_configuration.dart",
"lib/internals.dart",
"lib/mojo/asset_bundle.dart",
"lib/mojo/embedder.dart",
"lib/mojo/net/fetch.dart",
"lib/mojo/net/image_cache.dart",
......
// 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.
import 'dart:async';
import 'dart:sky' as sky;
import 'dart:typed_data';
import 'package:mojo/core.dart' as core;
import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart';
import 'shell.dart' as shell;
import 'net/fetch.dart';
Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) {
Completer<sky.Image> completer = new Completer();
new sky.ImageDecoder(assetData.handle.h, completer.complete);
return completer.future;
}
class AssetBundle {
AssetBundle(AssetBundleProxy this._bundle);
void close() {
_bundle.close();
_bundle = null;
}
Future<sky.Image> fetchImage(String path) async {
core.MojoDataPipeConsumer assetData =
(await _bundle.ptr.getAsStream(path)).assetData;
return await _decodeImage(assetData);
}
AssetBundleProxy _bundle;
}
Future<AssetBundle> fetchAssetBundle(String url) async {
assert(false); // mojo:asset_bundle doesn't exist yet, see https://codereview.chromium.org/1176153007
core.MojoDataPipeConsumer bundleData = (await fetchUrl(url)).body;
AssetUnpackerProxy unpacker = new AssetUnpackerProxy.unbound();
shell.requestService("mojo:asset_bundle", unpacker);
AssetBundleProxy bundle = new AssetBundleProxy.unbound();
unpacker.ptr.unpackZipStream(bundleData, bundle);
unpacker.close();
return new AssetBundle(bundle);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册