Flutter Engine
The Flutter Engine
SurfaceTextureSurfaceProducerTest.java
Go to the documentation of this file.
1package io.flutter.embedding.engine.renderer;
2
3import static io.flutter.Build.API_LEVELS;
4import static org.junit.Assert.assertEquals;
5import static org.mockito.Mockito.mock;
6import static org.robolectric.Shadows.shadowOf;
7
8import android.annotation.TargetApi;
9import android.graphics.Canvas;
10import android.graphics.SurfaceTexture;
11import android.os.Handler;
12import android.os.Looper;
13import android.view.Surface;
14import androidx.test.ext.junit.runners.AndroidJUnit4;
15import io.flutter.embedding.engine.FlutterJNI;
16import java.util.concurrent.atomic.AtomicInteger;
17import org.junit.Test;
18import org.junit.runner.RunWith;
19
20@RunWith(AndroidJUnit4.class)
21@TargetApi(API_LEVELS.API_26)
23 private final FlutterJNI fakeJNI = mock(FlutterJNI.class);
24
25 @Test
27 final FlutterRenderer flutterRenderer = new FlutterRenderer(fakeJNI);
28
29 // Create a surface and set the initial size.
30 final Handler handler = new Handler(Looper.getMainLooper());
31 final SurfaceTextureSurfaceProducer producer =
33 0, handler, fakeJNI, flutterRenderer.registerSurfaceTexture(new SurfaceTexture(0)));
34 final Surface surface = producer.getSurface();
35 AtomicInteger frames = new AtomicInteger();
36 producer
38 .setOnFrameAvailableListener(
39 (texture) -> {
40 if (texture.isReleased()) {
41 return;
42 }
43 frames.getAndIncrement();
44 });
45 producer.setSize(100, 200);
46
47 // Draw.
48 Canvas canvas = surface.lockHardwareCanvas();
49 canvas.drawARGB(255, 255, 0, 0);
50 surface.unlockCanvasAndPost(canvas);
51 shadowOf(Looper.getMainLooper()).idle();
52 assertEquals(frames.get(), 1);
53
54 // Resize and redraw.
55 producer.setSize(400, 800);
56 canvas = surface.lockHardwareCanvas();
57 canvas.drawARGB(255, 255, 0, 0);
58 surface.unlockCanvasAndPost(canvas);
59 shadowOf(Looper.getMainLooper()).idle();
60 assertEquals(frames.get(), 2);
61
62 // Done.
64 producer.release();
65 }
66}
SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture)
VkSurfaceKHR surface
Definition: main.cc:49
FlTexture * texture