Flutter Engine
The Flutter Engine
SurfaceTexturePlatformViewRenderTargetTest.java
Go to the documentation of this file.
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
5package io.flutter.plugin.platform;
6
7import static io.flutter.Build.API_LEVELS;
8import static org.junit.Assert.*;
9import static org.mockito.ArgumentMatchers.*;
10import static org.mockito.Mockito.*;
11
12import android.annotation.TargetApi;
13import android.content.Context;
14import android.graphics.Canvas;
15import android.graphics.Color;
16import android.graphics.SurfaceTexture;
17import android.view.Surface;
18import android.view.View;
19import androidx.test.core.app.ApplicationProvider;
20import androidx.test.ext.junit.runners.AndroidJUnit4;
21import io.flutter.view.TextureRegistry.SurfaceTextureEntry;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24
25@TargetApi(API_LEVELS.API_31)
26@RunWith(AndroidJUnit4.class)
28 private final Context ctx = ApplicationProvider.getApplicationContext();
29
30 @Test
32 final Canvas canvas = mock(Canvas.class);
33 final Surface surface = mock(Surface.class);
34 when(surface.lockHardwareCanvas()).thenReturn(canvas);
35 when(surface.isValid()).thenReturn(true);
36 final SurfaceTexture surfaceTexture = mock(SurfaceTexture.class);
37 final SurfaceTextureEntry surfaceTextureEntry = mock(SurfaceTextureEntry.class);
38 when(surfaceTextureEntry.surfaceTexture()).thenReturn(surfaceTexture);
39 when(surfaceTexture.isReleased()).thenReturn(false);
40
42 new SurfaceTexturePlatformViewRenderTarget(surfaceTextureEntry) {
43 @Override
44 protected Surface createSurface() {
45 return surface;
46 }
47 };
48
49 // Custom view.
50 final View platformView =
51 new View(ctx) {
52 @Override
53 public void draw(Canvas canvas) {
54 super.draw(canvas);
55 canvas.drawColor(Color.RED);
56 }
57 };
58 final int size = 100;
59 platformView.measure(size, size);
60 platformView.layout(0, 0, size, size);
61
62 // Test.
63 final Surface s = renderTarget.getSurface();
64 final Canvas c = s.lockHardwareCanvas();
65 platformView.draw(c);
66 s.unlockCanvasAndPost(c);
67
68 // Verify.
69 verify(canvas, times(1)).drawColor(Color.RED);
70 verify(surface, times(1)).lockHardwareCanvas();
71 verify(surface, times(1)).unlockCanvasAndPost(canvas);
72 verifyNoMoreInteractions(surface);
73 }
74
75 @Test
76 public void release() {
77 final Canvas canvas = mock(Canvas.class);
78 final Surface surface = mock(Surface.class);
79 when(surface.lockHardwareCanvas()).thenReturn(canvas);
80 when(surface.isValid()).thenReturn(true);
81 final SurfaceTexture surfaceTexture = mock(SurfaceTexture.class);
82 final SurfaceTextureEntry surfaceTextureEntry = mock(SurfaceTextureEntry.class);
83 when(surfaceTextureEntry.surfaceTexture()).thenReturn(surfaceTexture);
84 when(surfaceTexture.isReleased()).thenReturn(false);
86 new SurfaceTexturePlatformViewRenderTarget(surfaceTextureEntry) {
87 @Override
88 protected Surface createSurface() {
89 return surface;
90 }
91 };
92
93 final Surface s = renderTarget.getSurface();
94 final Canvas c = s.lockHardwareCanvas();
95 s.unlockCanvasAndPost(c);
96
98 reset(surfaceTexture);
99
100 // Test.
101 renderTarget.release();
102
103 // Verify.
104 verify(surface, times(1)).release();
105 verifyNoMoreInteractions(surface);
106 verifyNoMoreInteractions(surfaceTexture);
107 }
108}
static SkISize times(const SkISize &size, float factor)
m reset()
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
VkSurfaceKHR surface
Definition: main.cc:49
struct MyStruct s
SK_API sk_sp< SkShader > Color(SkColor)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259