Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a83ed0e

Browse files
itsjustkevinknoppzandersoEmmanuel Garcia
authored
[flutter_releases] Flutter stable 2.10.2 Engine Cherrypicks (#31525)
* Fix crash in BackdropFilterLayer::Diff (#30460) * Fix crash in BackdropFilterLayer::Diff * Pass context transform to filterBounds instead of scaling the filter * Disable building examples by default (#30946) This should be paired with a recipe change to enable building the example on CI that I'll prepare shortly. * Detach from GL context before attaching (#31390) * 'add branch flutter-2.8-candidate.16 to enabled_branches in .ci.yaml' * remove ref to branch * add junit dependency to gradle.build Co-authored-by: Matej Knopp <[email protected]> Co-authored-by: Zachary Anderson <[email protected]> Co-authored-by: Emmanuel Garcia <[email protected]> Co-authored-by: Kevin Chisholm <[email protected]>
1 parent fc0858b commit a83ed0e

File tree

6 files changed

+133
-11
lines changed

6 files changed

+133
-11
lines changed

examples/examples.gni

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
declare_args() {
66
# The example embedders may use dependencies not suitable on all platforms.
7-
# Use this GN arg to disable building the examples.
8-
build_embedder_examples = is_mac || is_linux
7+
# Use this GN arg to enable building the examples.
8+
build_embedder_examples = false
99
}

flow/layers/backdrop_filter_layer.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ void BackdropFilterLayer::Diff(DiffContext* context, const Layer* old_layer) {
2525
context->AddLayerBounds(paint_bounds);
2626

2727
if (filter_) {
28-
// convert paint bounds and filter to screen coordinates
2928
context->GetTransform().mapRect(&paint_bounds);
3029
auto input_filter_bounds = paint_bounds.roundOut();
31-
auto filter = filter_->makeWithLocalMatrix(context->GetTransform());
32-
3330
auto filter_bounds = // in screen coordinates
34-
filter->filterBounds(input_filter_bounds, SkMatrix::I(),
35-
SkImageFilter::kReverse_MapDirection);
36-
31+
filter_->filterBounds(input_filter_bounds, context->GetTransform(),
32+
SkImageFilter::kReverse_MapDirection);
3733
context->AddReadbackRegion(filter_bounds);
3834
}
3935

flow/layers/backdrop_filter_layer_unittests.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,29 @@ TEST_F(BackdropLayerDiffTest, BackdropLayer) {
327327
EXPECT_EQ(damage.frame_damage, SkIRect::MakeLTRB(0, 0, 190, 190));
328328
}
329329

330+
TEST_F(BackdropLayerDiffTest, BackdropLayerInvalidTransform) {
331+
auto filter = SkImageFilters::Blur(10, 10, SkTileMode::kClamp, nullptr);
332+
333+
{
334+
// tests later assume 30px readback area, fail early if that's not the case
335+
auto readback = filter->filterBounds(SkIRect::MakeWH(10, 10), SkMatrix::I(),
336+
SkImageFilter::kReverse_MapDirection);
337+
EXPECT_EQ(readback, SkIRect::MakeLTRB(-30, -30, 40, 40));
338+
}
339+
340+
MockLayerTree l1(SkISize::Make(100, 100));
341+
SkMatrix transform;
342+
transform.setPerspX(0.1);
343+
transform.setPerspY(0.1);
344+
345+
auto transform_layer = std::make_shared<TransformLayer>(transform);
346+
l1.root()->Add(transform_layer);
347+
transform_layer->Add(
348+
std::make_shared<BackdropFilterLayer>(filter, SkBlendMode::kSrcOver));
349+
350+
auto damage = DiffLayerTree(l1, MockLayerTree(SkISize::Make(100, 100)));
351+
EXPECT_EQ(damage.frame_damage, SkIRect::MakeWH(15, 15));
352+
}
353+
330354
} // namespace testing
331355
} // namespace flutter

shell/platform/android/io/flutter/embedding/engine/renderer/SurfaceTextureWrapper.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
public class SurfaceTextureWrapper {
2020
private SurfaceTexture surfaceTexture;
2121
private boolean released;
22+
private boolean attached;
2223

2324
public SurfaceTextureWrapper(@NonNull SurfaceTexture surfaceTexture) {
2425
this.surfaceTexture = surfaceTexture;
@@ -45,6 +46,7 @@ public void release() {
4546
if (!released) {
4647
surfaceTexture.release();
4748
released = true;
49+
attached = false;
4850
}
4951
}
5052
}
@@ -53,16 +55,33 @@ public void release() {
5355
@SuppressWarnings("unused")
5456
public void attachToGLContext(int texName) {
5557
synchronized (this) {
56-
if (!released) {
57-
surfaceTexture.attachToGLContext(texName);
58+
if (released) {
59+
return;
60+
}
61+
// When the rasterizer tasks run on a different thread, the GrContext is re-created.
62+
// This causes the texture to be in an uninitialized state.
63+
// This should *not* be an issue once platform views are always rendered as TextureLayers
64+
// since thread merging will be always disabled on Android.
65+
// For more see: AndroidExternalTextureGL::OnGrContextCreated in
66+
// android_external_texture_gl.cc, and
67+
// https://github.com/flutter/flutter/issues/98155
68+
if (attached) {
69+
surfaceTexture.detachFromGLContext();
5870
}
71+
surfaceTexture.attachToGLContext(texName);
72+
attached = true;
5973
}
6074
}
6175

6276
// Called by native.
6377
@SuppressWarnings("unused")
6478
public void detachFromGLContext() {
65-
surfaceTexture.detachFromGLContext();
79+
synchronized (this) {
80+
if (attached && !released) {
81+
surfaceTexture.detachFromGLContext();
82+
attached = false;
83+
}
84+
}
6685
}
6786

6887
// Called by native.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.flutter.embedding.engine.renderer;
2+
3+
import static junit.framework.TestCase.*;
4+
import static org.mockito.Mockito.*;
5+
6+
import android.graphics.SurfaceTexture;
7+
import androidx.test.ext.junit.runners.AndroidJUnit4;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
@RunWith(AndroidJUnit4.class)
12+
public class SurfaceTextureWrapperTest {
13+
14+
@Test
15+
public void attachToGLContext() {
16+
final SurfaceTexture tx = mock(SurfaceTexture.class);
17+
final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx);
18+
19+
wrapper.attachToGLContext(0);
20+
verify(tx, times(1)).attachToGLContext(0);
21+
verifyNoMoreInteractions(tx);
22+
}
23+
24+
@Test
25+
public void attachToGLContext_detachesFromCurrentContext() {
26+
final SurfaceTexture tx = mock(SurfaceTexture.class);
27+
final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx);
28+
29+
wrapper.attachToGLContext(0);
30+
31+
reset(tx);
32+
33+
wrapper.attachToGLContext(0);
34+
verify(tx, times(1)).detachFromGLContext();
35+
verify(tx, times(1)).attachToGLContext(0);
36+
verifyNoMoreInteractions(tx);
37+
}
38+
39+
@Test
40+
public void attachToGLContext_doesNotDetacheFromCurrentContext() {
41+
final SurfaceTexture tx = mock(SurfaceTexture.class);
42+
final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx);
43+
44+
wrapper.attachToGLContext(0);
45+
46+
wrapper.detachFromGLContext();
47+
48+
reset(tx);
49+
50+
wrapper.attachToGLContext(0);
51+
verify(tx, times(1)).attachToGLContext(0);
52+
verifyNoMoreInteractions(tx);
53+
}
54+
55+
@Test
56+
public void detachFromGLContext() {
57+
final SurfaceTexture tx = mock(SurfaceTexture.class);
58+
final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx);
59+
60+
wrapper.attachToGLContext(0);
61+
reset(tx);
62+
63+
wrapper.detachFromGLContext();
64+
verify(tx, times(1)).detachFromGLContext();
65+
verifyNoMoreInteractions(tx);
66+
}
67+
68+
@Test
69+
public void release() {
70+
final SurfaceTexture tx = mock(SurfaceTexture.class);
71+
final SurfaceTextureWrapper wrapper = new SurfaceTextureWrapper(tx);
72+
73+
wrapper.release();
74+
75+
verify(tx, times(1)).release();
76+
reset(tx);
77+
78+
wrapper.detachFromGLContext();
79+
wrapper.attachToGLContext(0);
80+
verifyNoMoreInteractions(tx);
81+
}
82+
}

shell/platform/android/test_runner/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ android {
4646
testImplementation "com.ibm.icu:icu4j:69.1"
4747
testImplementation "org.robolectric:robolectric:4.6.1"
4848
testImplementation "junit:junit:4.13"
49+
testImplementation "androidx.test.ext:junit:1.1.3"
4950

5051
def mockitoVersion = "4.1.0"
5152
testImplementation "org.mockito:mockito-core:$mockitoVersion"

0 commit comments

Comments
 (0)