mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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.
This commit is contained in:
parent
641117c52f
commit
fe2c731ec2
@ -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",
|
||||
|
||||
49
sdk/lib/mojo/asset_bundle.dart
Normal file
49
sdk/lib/mojo/asset_bundle.dart
Normal file
@ -0,0 +1,49 @@
|
||||
// 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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user