From d06482cc79bd7c865e3decbb7afc8927fc7568e6 Mon Sep 17 00:00:00 2001 From: Mikkel Nygaard Ravn Date: Wed, 22 Nov 2017 14:16:25 +0100 Subject: [PATCH] Add integration test of textures (#13122) --- .../tasks/external_ui_integration_test.dart | 14 + .../external_ui_integration_test_ios.dart | 14 + .../lib/tasks/integration_tests.dart | 7 + dev/devicelab/manifest.yaml | 14 + dev/integration_tests/external_ui/.gitignore | 10 + dev/integration_tests/external_ui/README.md | 3 + .../external_ui/android/.gitignore | 9 + .../external_ui/android/app/build.gradle | 49 +++ .../android/app/src/main/AndroidManifest.xml | 21 + .../yourcompany/externalui/MainActivity.java | 141 ++++++ .../external_ui/android/build.gradle | 31 ++ .../external_ui/android/gradle.properties | 1 + .../gradle/wrapper/gradle-wrapper.properties | 6 + .../external_ui/android/settings.gradle | 15 + .../external_ui/ios/.gitignore | 41 ++ .../ios/Flutter/AppFrameworkInfo.plist | 30 ++ .../external_ui/ios/Flutter/Debug.xcconfig | 1 + .../external_ui/ios/Flutter/Release.xcconfig | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 413 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/xcschemes/Runner.xcscheme | 91 ++++ .../contents.xcworkspacedata | 7 + .../external_ui/ios/Runner/AppDelegate.h | 10 + .../external_ui/ios/Runner/AppDelegate.m | 76 ++++ .../Runner/Base.lproj/LaunchScreen.storyboard | 37 ++ .../ios/Runner/Base.lproj/Main.storyboard | 26 ++ .../external_ui/ios/Runner/Info.plist | 49 +++ .../external_ui/ios/Runner/main.m | 13 + .../external_ui/lib/main.dart | 148 +++++++ .../external_ui/pubspec.yaml | 11 + .../external_ui/test_driver/main_test.dart | 65 +++ 31 files changed, 1361 insertions(+) create mode 100644 dev/devicelab/bin/tasks/external_ui_integration_test.dart create mode 100644 dev/devicelab/bin/tasks/external_ui_integration_test_ios.dart create mode 100644 dev/integration_tests/external_ui/.gitignore create mode 100644 dev/integration_tests/external_ui/README.md create mode 100644 dev/integration_tests/external_ui/android/.gitignore create mode 100644 dev/integration_tests/external_ui/android/app/build.gradle create mode 100644 dev/integration_tests/external_ui/android/app/src/main/AndroidManifest.xml create mode 100644 dev/integration_tests/external_ui/android/app/src/main/java/com/yourcompany/externalui/MainActivity.java create mode 100644 dev/integration_tests/external_ui/android/build.gradle create mode 100644 dev/integration_tests/external_ui/android/gradle.properties create mode 100644 dev/integration_tests/external_ui/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 dev/integration_tests/external_ui/android/settings.gradle create mode 100644 dev/integration_tests/external_ui/ios/.gitignore create mode 100644 dev/integration_tests/external_ui/ios/Flutter/AppFrameworkInfo.plist create mode 100644 dev/integration_tests/external_ui/ios/Flutter/Debug.xcconfig create mode 100644 dev/integration_tests/external_ui/ios/Flutter/Release.xcconfig create mode 100644 dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.pbxproj create mode 100644 dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 dev/integration_tests/external_ui/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme create mode 100644 dev/integration_tests/external_ui/ios/Runner.xcworkspace/contents.xcworkspacedata create mode 100644 dev/integration_tests/external_ui/ios/Runner/AppDelegate.h create mode 100644 dev/integration_tests/external_ui/ios/Runner/AppDelegate.m create mode 100644 dev/integration_tests/external_ui/ios/Runner/Base.lproj/LaunchScreen.storyboard create mode 100644 dev/integration_tests/external_ui/ios/Runner/Base.lproj/Main.storyboard create mode 100644 dev/integration_tests/external_ui/ios/Runner/Info.plist create mode 100644 dev/integration_tests/external_ui/ios/Runner/main.m create mode 100644 dev/integration_tests/external_ui/lib/main.dart create mode 100644 dev/integration_tests/external_ui/pubspec.yaml create mode 100644 dev/integration_tests/external_ui/test_driver/main_test.dart diff --git a/dev/devicelab/bin/tasks/external_ui_integration_test.dart b/dev/devicelab/bin/tasks/external_ui_integration_test.dart new file mode 100644 index 0000000000..0866f7a7a2 --- /dev/null +++ b/dev/devicelab/bin/tasks/external_ui_integration_test.dart @@ -0,0 +1,14 @@ +// Copyright 2017 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 'package:flutter_devicelab/framework/adb.dart'; +import 'package:flutter_devicelab/framework/framework.dart'; +import 'package:flutter_devicelab/tasks/integration_tests.dart'; + +Future main() async { + deviceOperatingSystem = DeviceOperatingSystem.android; + await task(createExternalUiIntegrationTest()); +} diff --git a/dev/devicelab/bin/tasks/external_ui_integration_test_ios.dart b/dev/devicelab/bin/tasks/external_ui_integration_test_ios.dart new file mode 100644 index 0000000000..2da7c73187 --- /dev/null +++ b/dev/devicelab/bin/tasks/external_ui_integration_test_ios.dart @@ -0,0 +1,14 @@ +// Copyright 2017 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 'package:flutter_devicelab/framework/adb.dart'; +import 'package:flutter_devicelab/framework/framework.dart'; +import 'package:flutter_devicelab/tasks/integration_tests.dart'; + +Future main() async { + deviceOperatingSystem = DeviceOperatingSystem.ios; + await task(createExternalUiIntegrationTest()); +} diff --git a/dev/devicelab/lib/tasks/integration_tests.dart b/dev/devicelab/lib/tasks/integration_tests.dart index f612326565..af4334ae51 100644 --- a/dev/devicelab/lib/tasks/integration_tests.dart +++ b/dev/devicelab/lib/tasks/integration_tests.dart @@ -31,6 +31,13 @@ TaskFunction createFlavorsTest() { ); } +TaskFunction createExternalUiIntegrationTest() { + return new DriverTest( + '${flutterDirectory.path}/dev/integration_tests/external_ui', + 'lib/main.dart', + ); +} + TaskFunction createPlatformChannelSampleTest() { return new DriverTest( '${flutterDirectory.path}/examples/platform_channel', diff --git a/dev/devicelab/manifest.yaml b/dev/devicelab/manifest.yaml index 2ae69aa0ff..28970aaa29 100644 --- a/dev/devicelab/manifest.yaml +++ b/dev/devicelab/manifest.yaml @@ -71,6 +71,13 @@ tasks: stage: devicelab required_agent_capabilities: ["has-android-device"] + external_ui_integration_test: + description: > + Checks that external UIs work on Android. + stage: devicelab + required_agent_capabilities: ["has-android-device"] + flaky: true + platform_interaction_test: description: > Checks platform interaction on Android. @@ -185,6 +192,13 @@ tasks: stage: devicelab_ios required_agent_capabilities: ["has-ios-device"] + external_ui_integration_test_ios: + description: > + Checks that external UIs work on iOS. + stage: devicelab + required_agent_capabilities: ["has-ios-device"] + flaky: true + channels_integration_test_ios: description: > Checks that platform channels work on iOS. diff --git a/dev/integration_tests/external_ui/.gitignore b/dev/integration_tests/external_ui/.gitignore new file mode 100644 index 0000000000..eb15c3d27c --- /dev/null +++ b/dev/integration_tests/external_ui/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +.atom/ +.idea +.packages +.pub/ +build/ +ios/.generated/ +packages +pubspec.lock +.flutter-plugins diff --git a/dev/integration_tests/external_ui/README.md b/dev/integration_tests/external_ui/README.md new file mode 100644 index 0000000000..a51e9462ff --- /dev/null +++ b/dev/integration_tests/external_ui/README.md @@ -0,0 +1,3 @@ +# external_ui + +A Flutter project for testing external texture rendering. diff --git a/dev/integration_tests/external_ui/android/.gitignore b/dev/integration_tests/external_ui/android/.gitignore new file mode 100644 index 0000000000..1658458c92 --- /dev/null +++ b/dev/integration_tests/external_ui/android/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +GeneratedPluginRegistrant.java diff --git a/dev/integration_tests/external_ui/android/app/build.gradle b/dev/integration_tests/external_ui/android/app/build.gradle new file mode 100644 index 0000000000..3fce7313ad --- /dev/null +++ b/dev/integration_tests/external_ui/android/app/build.gradle @@ -0,0 +1,49 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withInputStream { stream -> + localProperties.load(stream) + } +} + +def flutterRoot = localProperties.getProperty('flutter.sdk') +if (flutterRoot == null) { + throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") +} + +apply plugin: 'com.android.application' +apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" + +android { + compileSdkVersion 25 + buildToolsVersion '25.0.3' + + lintOptions { + disable 'InvalidPackage' + } + + defaultConfig { + applicationId "com.yourcompany.externalui" + minSdkVersion 16 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies { + androidTestCompile 'com.android.support:support-annotations:25.4.0' + androidTestCompile 'com.android.support.test:runner:0.5' + androidTestCompile 'com.android.support.test:rules:0.5' +} diff --git a/dev/integration_tests/external_ui/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/external_ui/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..dc488a964b --- /dev/null +++ b/dev/integration_tests/external_ui/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/dev/integration_tests/external_ui/android/app/src/main/java/com/yourcompany/externalui/MainActivity.java b/dev/integration_tests/external_ui/android/app/src/main/java/com/yourcompany/externalui/MainActivity.java new file mode 100644 index 0000000000..e50f75993a --- /dev/null +++ b/dev/integration_tests/external_ui/android/app/src/main/java/com/yourcompany/externalui/MainActivity.java @@ -0,0 +1,141 @@ +// Copyright 2017 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. + +package com.yourcompany.externalui; + +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.SurfaceTexture; +import android.os.Build; +import android.os.Bundle; +import android.view.Surface; +import android.view.SurfaceHolder; + +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicInteger; + +import io.flutter.app.FlutterActivity; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; +import io.flutter.plugin.common.MethodChannel.Result; +import io.flutter.view.TextureRegistry; +import io.flutter.view.TextureRegistry.SurfaceTextureEntry; + +public class MainActivity extends FlutterActivity { + private Surface surface; + private SurfaceTexture texture; + private Timer producerTimer; + private Timer consumerTimer; + private long startTime; + private long endTime; + private AtomicInteger framesProduced = new AtomicInteger(0); + private AtomicInteger framesConsumed = new AtomicInteger(0); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final MethodChannel channel = new MethodChannel(getFlutterView(), "texture"); + channel.setMethodCallHandler(new MethodCallHandler() { + @Override + public void onMethodCall(MethodCall methodCall, Result result) { + switch (methodCall.method) { + case "start": + framesProduced.set(0); + framesConsumed.set(0); + final int fps = methodCall.arguments(); + final FrameRenderer renderer = new FrameRenderer(surface); + producerTimer = new Timer(); + producerTimer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + renderer.drawFrame(); + framesProduced.incrementAndGet(); + } + }, 0, 1000 / fps); + consumerTimer = new Timer(); + consumerTimer.scheduleAtFixedRate(new TimerTask() { + private long lastTimestamp = -1L; + + @Override + public void run() { + final long timestamp = texture.getTimestamp(); + // The texture's timestamp is updated on consumption. + // We detect the change by asking very frequently. + if (timestamp != lastTimestamp) { + lastTimestamp = timestamp; + framesConsumed.incrementAndGet(); + } + } + }, 0, 1); + startTime = System.currentTimeMillis(); + result.success(null); + break; + case "stop": + producerTimer.cancel(); + consumerTimer.cancel(); + endTime = System.currentTimeMillis(); + result.success(null); + break; + case "getProducedFrameRate": + result.success(framesProduced.get() * 1000 / (double) (endTime - startTime)); + break; + case "getConsumedFrameRate": + result.success(framesConsumed.get() * 1000 / (double) (endTime - startTime)); + break; + default: result.notImplemented(); + } + } + }); + + getFlutterView().getHolder().addCallback(new SurfaceHolder.Callback() { + @Override + public void surfaceCreated(SurfaceHolder holder) { + final SurfaceTextureEntry textureEntry = getFlutterView().createSurfaceTexture(); + texture = textureEntry.surfaceTexture(); + texture.setDefaultBufferSize(300, 200); + surface = new Surface(texture); + } + + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + } + }); + } + + @Override + protected void onDestroy() { + if (surface != null) { + surface.release(); + } + super.onDestroy(); + } +} + +class FrameRenderer { + private final Surface surface; + private final Paint paint; + private int frameCount = 0; + + FrameRenderer(Surface surface) { + this.surface = surface; + this.paint = new Paint(); + paint.setColor(0xffff0000); + paint.setTextSize(48.0f); + paint.setAntiAlias(true); + } + + void drawFrame() { + final Canvas canvas = surface.lockCanvas(null); + canvas.drawColor(0xff000000); + canvas.drawText(String.valueOf(++frameCount), 20, 120, paint); + surface.unlockCanvasAndPost(canvas); + } +} diff --git a/dev/integration_tests/external_ui/android/build.gradle b/dev/integration_tests/external_ui/android/build.gradle new file mode 100644 index 0000000000..77cbd09140 --- /dev/null +++ b/dev/integration_tests/external_ui/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + repositories { + jcenter() + maven { + url "https://maven.google.com" + } + } + + dependencies { + classpath 'com.android.tools.build:gradle:2.3.3' + } +} + +allprojects { + repositories { + jcenter() + maven { + url "https://maven.google.com" + } + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/dev/integration_tests/external_ui/android/gradle.properties b/dev/integration_tests/external_ui/android/gradle.properties new file mode 100644 index 0000000000..8bd86f6805 --- /dev/null +++ b/dev/integration_tests/external_ui/android/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx1536M diff --git a/dev/integration_tests/external_ui/android/gradle/wrapper/gradle-wrapper.properties b/dev/integration_tests/external_ui/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..45e7f14e95 --- /dev/null +++ b/dev/integration_tests/external_ui/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 23 08:50:38 CEST 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/dev/integration_tests/external_ui/android/settings.gradle b/dev/integration_tests/external_ui/android/settings.gradle new file mode 100644 index 0000000000..115da6cb4f --- /dev/null +++ b/dev/integration_tests/external_ui/android/settings.gradle @@ -0,0 +1,15 @@ +include ':app' + +def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() + +def plugins = new Properties() +def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') +if (pluginsFile.exists()) { + pluginsFile.withInputStream { stream -> plugins.load(stream) } +} + +plugins.each { name, path -> + def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() + include ":$name" + project(":$name").projectDir = pluginDirectory +} diff --git a/dev/integration_tests/external_ui/ios/.gitignore b/dev/integration_tests/external_ui/ios/.gitignore new file mode 100644 index 0000000000..38864eed23 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/.gitignore @@ -0,0 +1,41 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/app.flx +/Flutter/app.zip +/Flutter/App.framework +/Flutter/Flutter.framework +/Flutter/Generated.xcconfig +/ServiceDefinitions.json + +Pods/ diff --git a/dev/integration_tests/external_ui/ios/Flutter/AppFrameworkInfo.plist b/dev/integration_tests/external_ui/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000000..6c2de8086b --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + UIRequiredDeviceCapabilities + + arm64 + + MinimumOSVersion + 8.0 + + diff --git a/dev/integration_tests/external_ui/ios/Flutter/Debug.xcconfig b/dev/integration_tests/external_ui/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/dev/integration_tests/external_ui/ios/Flutter/Release.xcconfig b/dev/integration_tests/external_ui/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.pbxproj b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..3099a2edd6 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,413 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; + 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; + 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; + 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; + 9740EEBB1CF902C7004384FC /* app.flx in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB71CF902C7004384FC /* app.flx */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, + 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 9740EEB71CF902C7004384FC /* app.flx */ = {isa = PBXFileReference; lastKnownFileType = file; name = app.flx; path = Flutter/app.flx; sourceTree = ""; }; + 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, + 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 9740EEB71CF902C7004384FC /* app.flx */, + 3B80C3931E831B6300D905FE /* App.framework */, + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEBA1CF902C7004384FC /* Flutter.framework */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 97C146F11CF9000F007C117D /* Supporting Files */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 97C146F21CF9000F007C117D /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0830; + ORGANIZATIONNAME = "The Chromium Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9740EEBB1CF902C7004384FC /* app.flx in Resources */, + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 97C146F31CF9000F007C117D /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ARCHS = arm64; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.externalUi; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ARCHS = arm64; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.externalUi; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dev/integration_tests/external_ui/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..1c95807881 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/external_ui/ios/Runner.xcworkspace/contents.xcworkspacedata b/dev/integration_tests/external_ui/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dev/integration_tests/external_ui/ios/Runner/AppDelegate.h b/dev/integration_tests/external_ui/ios/Runner/AppDelegate.h new file mode 100644 index 0000000000..586d534295 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/AppDelegate.h @@ -0,0 +1,10 @@ +// Copyright 2017 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 +#import + +@interface AppDelegate : FlutterAppDelegate + +@end diff --git a/dev/integration_tests/external_ui/ios/Runner/AppDelegate.m b/dev/integration_tests/external_ui/ios/Runner/AppDelegate.m new file mode 100644 index 0000000000..83d3f88467 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/AppDelegate.m @@ -0,0 +1,76 @@ +// Copyright 2017 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. + +#include "AppDelegate.h" + +@interface AppDelegate () + @property (atomic) uint64_t textureId; + @property (atomic) int framesProduced; + @property (atomic) int framesConsumed; + @property (atomic) int lastFrameConsumed; + @property (atomic) double startTime; + @property (atomic) double endTime; + @property (atomic) double frameRate; + @property (atomic) double frameStartTime; + @property (atomic) NSTimer* timer; + + - (void)tick:(NSTimer*)timer; +@end + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + FlutterViewController* flutterController = + (FlutterViewController*)self.window.rootViewController; + FlutterMethodChannel* channel = + [FlutterMethodChannel methodChannelWithName:@"texture" + binaryMessenger:flutterController]; + [channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) { + if ([@"start" isEqualToString:call.method]) { + _framesProduced = 0; + _framesConsumed = 0; + _frameRate = 1.0 / [(NSNumber*) call.arguments intValue]; + _timer = [NSTimer scheduledTimerWithTimeInterval:_frameRate + target:self + selector:@selector(tick:) + userInfo:nil + repeats:YES]; + _startTime = [[NSDate date] timeIntervalSince1970]; + result(nil); + } else if ([@"stop" isEqualToString:call.method]) { + [_timer invalidate]; + _endTime = [[NSDate date] timeIntervalSince1970]; + result(nil); + } else if ([@"getProducedFrameRate" isEqualToString:call.method]) { + result(@(_framesProduced / (_endTime - _startTime))); + } else if ([@"getConsumedFrameRate" isEqualToString:call.method]) { + result(@(_framesConsumed / (_endTime - _startTime))); + } else { + result(FlutterMethodNotImplemented); + } + }]; + _textureId = [flutterController registerTexture:self]; + return [super application:application didFinishLaunchingWithOptions:launchOptions]; +} + +- (void)tick:(NSTimer*)timer { + FlutterViewController* flutterController = + (FlutterViewController*)self.window.rootViewController; + [flutterController textureFrameAvailable:_textureId]; + _frameStartTime = [[NSDate date] timeIntervalSince1970]; + // We just pretend to be producing a frame. + _framesProduced++; +} + +- (CVPixelBufferRef)copyPixelBuffer { + double now = [[NSDate date] timeIntervalSince1970]; + if (now < _frameStartTime + || _frameStartTime + _frameRate < now + || _framesProduced == _lastFrameConsumed) return nil; + _framesConsumed++; + _lastFrameConsumed = _framesProduced; + // We just pretend to be handing over the produced frame to the consumer. + return nil; +} +@end diff --git a/dev/integration_tests/external_ui/ios/Runner/Base.lproj/LaunchScreen.storyboard b/dev/integration_tests/external_ui/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..f2e259c7c9 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/external_ui/ios/Runner/Base.lproj/Main.storyboard b/dev/integration_tests/external_ui/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..f3c28516fb --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/external_ui/ios/Runner/Info.plist b/dev/integration_tests/external_ui/ios/Runner/Info.plist new file mode 100644 index 0000000000..2e5b6ecc14 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + external_ui + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + + diff --git a/dev/integration_tests/external_ui/ios/Runner/main.m b/dev/integration_tests/external_ui/ios/Runner/main.m new file mode 100644 index 0000000000..3ffadad023 --- /dev/null +++ b/dev/integration_tests/external_ui/ios/Runner/main.m @@ -0,0 +1,13 @@ +// Copyright 2017 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 +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/dev/integration_tests/external_ui/lib/main.dart b/dev/integration_tests/external_ui/lib/main.dart new file mode 100644 index 0000000000..496a23b7fe --- /dev/null +++ b/dev/integration_tests/external_ui/lib/main.dart @@ -0,0 +1,148 @@ +// Copyright 2017 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 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_driver/driver_extension.dart'; + +void main() { + enableFlutterDriverExtension(); + runApp(new MyApp()); +} + +class MyApp extends StatefulWidget { + @override + State createState() => new MyAppState(); +} + +const MethodChannel channel = const MethodChannel('texture'); + +enum FrameState { initial, slow, afterSlow, fast, afterFast } + +class MyAppState extends State with SingleTickerProviderStateMixin { + int _widgetBuilds = 0; + FrameState _state; + String _summary = ''; + IconData _icon; + double _flutterFrameRate; + + Future _summarizeStats() async { + final double framesProduced = await channel.invokeMethod('getProducedFrameRate'); + final double framesConsumed = await channel.invokeMethod('getConsumedFrameRate'); + _summary = ''' +Produced: ${framesProduced.toStringAsFixed(1)}fps +Consumed: ${framesConsumed.toStringAsFixed(1)}fps +Widget builds: $_widgetBuilds'''; + } + + Future _nextState() async { + switch (_state) { + case FrameState.initial: + _widgetBuilds = 0; + _summary = 'Producing texture frames at .5x speed...'; + _state = FrameState.slow; + _icon = Icons.stop; + channel.invokeMethod('start', _flutterFrameRate ~/ 2); + break; + case FrameState.slow: + await channel.invokeMethod('stop'); + await _summarizeStats(); + _icon = Icons.fast_forward; + _state = FrameState.afterSlow; + break; + case FrameState.afterSlow: + _widgetBuilds = 0; + _summary = 'Producing texture frames at 2x speed...'; + _state = FrameState.fast; + _icon = Icons.stop; + channel.invokeMethod('start', (_flutterFrameRate * 2).toInt()); + break; + case FrameState.fast: + await channel.invokeMethod('stop'); + await _summarizeStats(); + _state = FrameState.afterFast; + _icon = Icons.replay; + break; + case FrameState.afterFast: + _summary = 'Press play to start again'; + _state = FrameState.initial; + _icon = Icons.play_arrow; + break; + } + setState(() {}); + } + + @override + void initState() { + super.initState(); + _calibrate(); + } + + /// Measures Flutter's frame rate. + Future _calibrate() async { + await new Future.delayed(const Duration(milliseconds: 200)); + DateTime startTime; + int tickCount = 0; + Ticker ticker; + ticker = createTicker((Duration _) { + tickCount++; + if (tickCount == 120) { + final Duration elapsed = new DateTime.now().difference(startTime); + ticker.stop(); + ticker.dispose(); + setState(() { + _flutterFrameRate = tickCount * 1000 / elapsed.inMilliseconds; + _summary = 'Flutter frame rate is ${_flutterFrameRate.toStringAsFixed(1)}fps.\nPress play to produce texture frames.'; + _icon = Icons.play_arrow; + _state = FrameState.initial; + }); + } + }); + ticker.start(); + startTime = new DateTime.now(); + setState(() { + _summary = 'Calibrating...'; + _icon = null; + }); + } + + @override + Widget build(BuildContext context) { + _widgetBuilds++; + return new MaterialApp( + home: new Scaffold( + body: new Center( + child: new Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + new Container( + width: 300.0, + height: 200.0, + child: const Texture(textureId: 0), + ), + new Container( + width: 300.0, + height: 60.0, + color: Colors.grey, + child: new Center( + child: new Text( + _summary, + key: const ValueKey('summary'), + ), + ), + ), + ], + ), + ), + floatingActionButton: (_icon == null ? null : new FloatingActionButton( + key: const ValueKey('fab'), + child: new Icon(_icon), + onPressed: _nextState, + )), + ), + ); + } +} diff --git a/dev/integration_tests/external_ui/pubspec.yaml b/dev/integration_tests/external_ui/pubspec.yaml new file mode 100644 index 0000000000..dd37472039 --- /dev/null +++ b/dev/integration_tests/external_ui/pubspec.yaml @@ -0,0 +1,11 @@ +name: external_ui +description: A test of Flutter integrating external UIs. + +dependencies: + flutter: + sdk: flutter + flutter_driver: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/dev/integration_tests/external_ui/test_driver/main_test.dart b/dev/integration_tests/external_ui/test_driver/main_test.dart new file mode 100644 index 0000000000..fd762fc20b --- /dev/null +++ b/dev/integration_tests/external_ui/test_driver/main_test.dart @@ -0,0 +1,65 @@ +// Copyright 2017 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 'package:flutter_driver/flutter_driver.dart'; +import 'package:test/test.dart'; + +final RegExp calibrationRegExp = new RegExp('Flutter frame rate is (.*)fps'); +final RegExp statsRegExp = new RegExp('Produced: (.*)fps\nConsumed: (.*)fps\nWidget builds: (.*)'); +const Duration samplingTime = const Duration(seconds: 3); + +Future main() async { + group('texture suite', () { + FlutterDriver driver; + + setUpAll(() async { + driver = await FlutterDriver.connect(); + // TODO(mravn): the following pause appears necessary on iOS to avoid + // inflating elements too early (when there is no size). + await new Future.delayed(const Duration(seconds: 1)); + }); + + test('texture rendering', () async { + final SerializableFinder fab = find.byValueKey('fab'); + final SerializableFinder summary = find.byValueKey('summary'); + + // Wait for calibration to complete and fab to appear. + await driver.waitFor(fab, timeout: const Duration(seconds: 10)); + + final String calibrationResult = await driver.getText(summary); + final Match matchCalibration = calibrationRegExp.matchAsPrefix(calibrationResult); + expect(matchCalibration, isNotNull); + final double flutterFrameRate = double.parse(matchCalibration.group(1)); + + // Texture frame stats at 0.5x Flutter frame rate + await driver.tap(fab); + await new Future.delayed(samplingTime); + await driver.tap(fab); + + final String statsSlow = await driver.getText(summary); + final Match matchSlow = statsRegExp.matchAsPrefix(statsSlow); + expect(matchSlow, isNotNull); + expect(double.parse(matchSlow.group(1)), closeTo(flutterFrameRate / 2.0, 5.0)); + expect(double.parse(matchSlow.group(2)), closeTo(flutterFrameRate / 2.0, 5.0)); + expect(int.parse(matchSlow.group(3)), 1); + + // Texture frame stats at 2.0x Flutter frame rate + await driver.tap(fab); + await new Future.delayed(samplingTime); + await driver.tap(fab); + + final String statsFast = await driver.getText(summary); + final Match matchFast = statsRegExp.matchAsPrefix(statsFast); + expect(matchFast, isNotNull); + expect(double.parse(matchFast.group(1)), closeTo(flutterFrameRate * 2.0, 10.0)); + expect(double.parse(matchFast.group(2)), closeTo(flutterFrameRate, 10.0)); + expect(int.parse(matchFast.group(3)), 1); + }); + + tearDownAll(() async { + driver?.close(); + }); + }); +}