Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
66c6ce37
Commit
66c6ce37
authored
Oct 06, 2015
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1507 from abarth/image_decoding
NetworkImage occasionally does not grab the image
parents
ebaa45c7
8b1effc5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
16 deletions
+51
-16
services.dart
packages/flutter/lib/services.dart
+1
-0
asset_bundle.dart
packages/flutter/lib/src/services/asset_bundle.dart
+6
-5
image_cache.dart
packages/flutter/lib/src/services/image_cache.dart
+12
-11
image_decoder.dart
packages/flutter/lib/src/services/image_decoder.dart
+32
-0
No files found.
packages/flutter/lib/services.dart
View file @
66c6ce37
...
...
@@ -16,6 +16,7 @@ export 'src/services/asset_bundle.dart';
export
'src/services/embedder.dart'
;
export
'src/services/fetch.dart'
;
export
'src/services/image_cache.dart'
;
export
'src/services/image_decoder.dart'
;
export
'src/services/image_resource.dart'
;
export
'src/services/keyboard.dart'
;
export
'src/services/shell.dart'
;
packages/flutter/lib/src/services/asset_bundle.dart
View file @
66c6ce37
...
...
@@ -11,6 +11,7 @@ import 'package:mojo/core.dart' as core;
import
'package:mojo_services/mojo/asset_bundle/asset_bundle.mojom.dart'
;
import
'package:sky/src/services/fetch.dart'
;
import
'package:sky/src/services/image_cache.dart'
;
import
'package:sky/src/services/image_decoder.dart'
;
import
'package:sky/src/services/image_resource.dart'
;
import
'package:sky/src/services/shell.dart'
;
...
...
@@ -66,13 +67,13 @@ class MojoAssetBundle extends AssetBundle {
_imageCache
=
null
;
}
Future
<
sky
.
Image
>
_fetchImage
(
String
key
)
async
{
return
await
decodeImageFromDataPipe
(
await
load
(
key
));
}
ImageResource
loadImage
(
String
key
)
{
return
_imageCache
.
putIfAbsent
(
key
,
()
{
Completer
<
sky
.
Image
>
completer
=
new
Completer
<
sky
.
Image
>();
load
(
key
).
then
((
assetData
)
{
new
sky
.
ImageDecoder
.
consume
(
assetData
.
handle
.
h
,
completer
.
complete
);
});
return
new
ImageResource
(
completer
.
future
);
return
new
ImageResource
(
_fetchImage
(
key
));
});
}
...
...
packages/flutter/lib/src/services/image_cache.dart
View file @
66c6ce37
...
...
@@ -7,8 +7,18 @@ import 'dart:collection';
import
'dart:sky'
as
sky
;
import
'package:mojo/mojo/url_response.mojom.dart'
;
import
'package:sky/src/services/image_resource.dart'
;
import
'package:sky/src/services/fetch.dart'
;
import
'package:sky/src/services/image_decoder.dart'
;
import
'package:sky/src/services/image_resource.dart'
;
Future
<
sky
.
Image
>
_fetchImage
(
String
url
)
async
{
UrlResponse
response
=
await
fetchUrl
(
url
);
if
(
response
.
statusCode
>=
400
)
{
print
(
"Failed (
${response.statusCode}
) to load image
${url}
"
);
return
null
;
}
return
await
decodeImageFromDataPipe
(
response
.
body
);
}
class
_ImageCache
{
_ImageCache
.
_
();
...
...
@@ -17,16 +27,7 @@ class _ImageCache {
ImageResource
load
(
String
url
)
{
return
_cache
.
putIfAbsent
(
url
,
()
{
Completer
<
sky
.
Image
>
completer
=
new
Completer
<
sky
.
Image
>();
fetchUrl
(
url
).
then
((
UrlResponse
response
)
{
if
(
response
.
statusCode
>=
400
)
{
print
(
"Failed (
${response.statusCode}
) to load image
${url}
"
);
completer
.
complete
(
null
);
}
else
{
new
sky
.
ImageDecoder
.
consume
(
response
.
body
.
handle
.
h
,
completer
.
complete
);
}
});
return
new
ImageResource
(
completer
.
future
);
return
new
ImageResource
(
_fetchImage
(
url
));
});
}
}
...
...
packages/flutter/lib/src/services/image_decoder.dart
0 → 100644
View file @
66c6ce37
// 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'
show
Image
,
ImageDecoder
,
ImageDecoderCallback
;
import
'dart:typed_data'
;
import
'package:mojo/core.dart'
show
MojoDataPipeConsumer
;
final
Set
<
ImageDecoder
>
_activeDecoders
=
new
Set
<
ImageDecoder
>();
typedef
ImageDecoder
_DecoderFactory
(
ImageDecoderCallback
callback
);
Future
<
Image
>
_decode
(
_DecoderFactory
createDecoder
)
{
Completer
<
Image
>
completer
=
new
Completer
<
Image
>();
ImageDecoder
decoder
;
decoder
=
createDecoder
((
Image
image
)
{
_activeDecoders
.
remove
(
decoder
);
completer
.
complete
(
image
);
});
_activeDecoders
.
add
(
decoder
);
return
completer
.
future
;
}
Future
<
Image
>
decodeImageFromDataPipe
(
MojoDataPipeConsumer
consumerHandle
)
{
return
_decode
((
ImageDecoderCallback
callback
)
=>
new
ImageDecoder
.
consume
(
consumerHandle
.
handle
.
h
,
callback
));
}
Future
<
Image
>
decodeImageFromList
(
Uint8List
list
)
{
return
_decode
((
ImageDecoderCallback
callback
)
=>
new
ImageDecoder
.
fromList
(
list
,
callback
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment