1// Copyright 2013 The Flutter Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import 'dart:convert' show utf8; 6import 'dart:isolate'; 7import 'dart:typed_data'; 8import 'dart:ui'; 9 10void main() {} 11 12void nativeReportTimingsCallback(List<int> timings) native 'NativeReportTimingsCallback'; 13void nativeOnBeginFrame(int microseconds) native 'NativeOnBeginFrame'; 14 15@pragma('vm:entry-point') 16void reportTimingsMain() { 17 window.onReportTimings = (List<FrameTiming> timings) { 18 List<int> timestamps = []; 19 for (FrameTiming t in timings) { 20 for (FramePhase phase in FramePhase.values) { 21 timestamps.add(t.timestampInMicroseconds(phase)); 22 } 23 } 24 nativeReportTimingsCallback(timestamps); 25 }; 26} 27 28@pragma('vm:entry-point') 29void onBeginFrameMain() { 30 window.onBeginFrame = (Duration beginTime) { 31 nativeOnBeginFrame(beginTime.inMicroseconds); 32 }; 33} 34 35@pragma('vm:entry-point') 36void emptyMain() {} 37 38@pragma('vm:entry-point') 39void dummyReportTimingsMain() { 40 window.onReportTimings = (List<FrameTiming> timings) {}; 41} 42 43@pragma('vm:entry-point') 44void fixturesAreFunctionalMain() { 45 sayHiFromFixturesAreFunctionalMain(); 46} 47 48void sayHiFromFixturesAreFunctionalMain() native 'SayHiFromFixturesAreFunctionalMain'; 49 50void notifyNative() native 'NotifyNative'; 51 52void secondaryIsolateMain(String message) { 53 print('Secondary isolate got message: ' + message); 54 notifyNative(); 55} 56 57@pragma('vm:entry-point') 58void testCanLaunchSecondaryIsolate() { 59 Isolate.spawn(secondaryIsolateMain, 'Hello from root isolate.'); 60 notifyNative(); 61} 62 63@pragma('vm:entry-point') 64void testSkiaResourceCacheSendsResponse() { 65 final PlatformMessageResponseCallback callback = (ByteData data) { 66 notifyNative(); 67 }; 68 const String json = '''{ 69 "method": "Skia.setResourceCacheMaxBytes", 70 "args": 10000 71 }'''; 72 window.sendPlatformMessage( 73 'flutter/skia', 74 Uint8List.fromList(utf8.encode(json)).buffer.asByteData(), 75 callback, 76 ); 77} 78 79void notifyWidthHeight(int width, int height) native 'NotifyWidthHeight'; 80 81@pragma('vm:entry-point') 82void canCreateImageFromDecompressedData() { 83 const int imageWidth = 10; 84 const int imageHeight = 10; 85 final Uint8List pixels = Uint8List.fromList(List<int>.generate( 86 imageWidth * imageHeight * 4, 87 (int i) => i % 4 < 2 ? 0x00 : 0xFF, 88 )); 89 90 91 decodeImageFromPixels( 92 pixels, imageWidth, imageHeight, PixelFormat.rgba8888, 93 (Image image) { 94 notifyWidthHeight(image.width, image.height); 95 }); 96} 97