Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Unified Diff: sky/examples/raw/spinning_image.dart

Issue 1165753004: Implement a simple image cache for Sky in Dart (no eviction) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase origin/master Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/painting/Image.idl ('k') | sky/sdk/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/examples/raw/spinning_image.dart
diff --git a/sky/examples/raw/spinning_image.dart b/sky/examples/raw/spinning_image.dart
index cd5339fbf01ec43a35833825545b3c26a6aea665..b79162a2c01cbc2ee6f58a4bc8d962ce723bc072 100644
--- a/sky/examples/raw/spinning_image.dart
+++ b/sky/examples/raw/spinning_image.dart
@@ -3,10 +3,13 @@
// found in the LICENSE file.
import 'dart:sky';
+import 'package:sky/framework/net/image_cache.dart' as image_cache;
double timeBase = null;
Image image = null;
+String url1 = "https://www.dartlang.org/logos/dart-logo.png";
+String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
void beginFrame(double timeStamp) {
if (timeBase == null) timeBase = timeStamp;
@@ -22,15 +25,32 @@ void beginFrame(double timeStamp) {
view.scheduleFrame();
}
+void handleImageLoad(result) {
+ if (result != image) {
+ print("${result.width}x${result.width} image loaded!");
+ image = result;
+ view.scheduleFrame();
+ } else {
+ print("Existing image was loaded again");
+ }
+}
+
+bool handleEvent(Event event) {
+ if (event.type == "pointerdown") {
+ return true;
+ }
+
+ if (event.type == "pointerup") {
+ image_cache.load(url2, handleImageLoad);
+ return true;
+ }
+
+ return false;
+}
+
void main() {
- new ImageLoader("https://www.dartlang.org/logos/dart-logo.png", (result) {
- if (result != null) {
- print("${result.width}x${result.width} image loaded!");
- image = result;
- view.scheduleFrame();
- } else {
- print("Image failed to load");
- }
- }).load();
+ image_cache.load(url1, handleImageLoad);
+ image_cache.load(url1, handleImageLoad);
+ view.setEventCallback(handleEvent);
view.setBeginFrameCallback(beginFrame);
}
« no previous file with comments | « sky/engine/core/painting/Image.idl ('k') | sky/sdk/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698