Reverts "Refactor external_ui → external_textures" (#142173)
Reverts flutter/flutter#142062 Initiated by: eliasyishak This change reverts the following previous change: Original Description: This PR makes no _behavioral_ changes to executed code, and instead focuses on organization and naming: 1. Almost[^1] anything named `external_ui` is renamed `external_textures` 1. Extended the README to explain the intent of the test, as well as how to run it 1. Renamed `main.dart` and `main_test.dart` to `frame_rate_main.dart` and `frame_rate_test.dart` (we'll add more) 1. Did some refactoring of the test to make it more obvious what is being asserted (i.e. `widgetBuilds` and friends) Given how complex (and in-flux) this directory is, I'm also requesting either John, Jonah or I review any changes. [^1]: Except the name of the `.ci.yaml` task, i.e. `name: Linux_pixel_7pro external_ui_integration_test` because I'm apparently not able to change that without creating a new task as `bringup: true` and playing a bit of a dance. Maybe that's worth doing though (in future PRs)?
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
<!-- Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file. -->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="io.flutter.externalui">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
|
||||
<application
|
||||
android:name="${applicationName}"
|
||||
android:label="external_textures">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:launchMode="singleTop"
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
</application>
|
||||
<!-- Required to query activities that can process text, see:
|
||||
https://developer.android.com/training/package-visibility?hl=en and
|
||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
||||
|
||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent>
|
||||
</queries>
|
||||
</manifest>
|
||||
@@ -1,156 +0,0 @@
|
||||
// Copyright 2014 The Flutter 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 io.flutter.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 android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity;
|
||||
import io.flutter.embedding.android.FlutterSurfaceView;
|
||||
import io.flutter.embedding.android.FlutterView;
|
||||
import io.flutter.embedding.engine.FlutterEngine;
|
||||
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;
|
||||
import io.flutter.plugins.GeneratedPluginRegistrant;
|
||||
|
||||
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
|
||||
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
|
||||
GeneratedPluginRegistrant.registerWith(flutterEngine);
|
||||
final MethodChannel channel = new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "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() {
|
||||
final long time = System.currentTimeMillis();
|
||||
if (frameRate(framesProduced, startTime, time) < fps) {
|
||||
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(frameRate(framesProduced, startTime, endTime));
|
||||
break;
|
||||
case "getConsumedFrameRate":
|
||||
result.success(frameRate(framesConsumed, startTime, endTime));
|
||||
break;
|
||||
default: result.notImplemented();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFlutterSurfaceViewCreated(@NonNull FlutterSurfaceView flutterSurfaceView) {
|
||||
flutterSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
final SurfaceTextureEntry textureEntry = flutterSurfaceView.getAttachedRenderer().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) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
double frameRate(AtomicInteger frameCounter, long startTime, long endTime) {
|
||||
return frameCounter.get() * 1000 / (double) (endTime - startTime);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user