Commit c4c5452
Jonah Williams
Support backdrop key in flutter framework. (#157278)
The backdrop key functionality allows multiple backdrop filters to share the same input filter, dramatically improving raster performance. This is only supported on the Impeller backend.
The backdrop key class allocates a new int from a static and passes this to the engine layer. with 64 bit integers, we can allocate many backdrop filter ids per frame and never run out.
See also: flutter/flutter#156455
```dart
import 'dart:math';
import 'dart:ui';
import 'package:flutter/material.dart';
final _random = Random();
void main() => runApp(const BackdropFilterDemo());
class BackdropFilterDemo extends StatelessWidget {
const BackdropFilterDemo({super.key});
static final listKey = BackdropKey();
static final overlayKey = BackdropKey();
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: [
ListView.builder(
itemCount: 120, // 60 pairs of red and blue containers
itemBuilder: (context, index) {
return Container(
height: 100,
color: index % 2 == 0 ? Colors.red : Colors.blue,
);
},
),
Center(
child: Container(
width: 400,
height: 400,
decoration: BoxDecoration(
border: Border.all(color: Colors.black),
),
child: Image.network('https://picsum.photos/400'),
),
),
ListView.separated(
separatorBuilder: (_, __) => const SizedBox(height: 8),
itemBuilder: (context, index) => BlurEffect(
backdropKey: listKey,
child: SizedBox(
height: 50,
child: Center(
child: Text(index.toString(),
style: const TextStyle(color: Colors.white)),
),
),
),
itemCount: 200,
),
Positioned.fill(
bottom: null,
child: BlurEffect(
backdropKey: overlayKey,
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).viewPadding.top,
),
child: const SizedBox(height: 45),
),
),
),
Positioned.fill(
top: null,
child: BlurEffect(
backdropKey: overlayKey,
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).viewPadding.bottom,
),
child: const SizedBox(height: 50),
),
),
),
],
),
),
);
}
}
class BlurEffect extends StatelessWidget {
final Widget child;
const BlurEffect({
required this.child,
required this.backdropKey,
super.key,
});
final BackdropKey backdropKey;
@OverRide
Widget build(BuildContext context) {
return ClipRect(
child: BackdropFilter(
backdropKey: backdropKey,
filter: ImageFilter.blur(
sigmaX: 40,
sigmaY: 40,
// tileMode: TileMode.mirror,
),
child: DecoratedBox(
decoration: BoxDecoration(color: Colors.black.withOpacity(.65)),
child: child,
),
),
);
}
}
```
### Skia
<img src="https://github.com/user-attachments/assets/4c08e92d-f0ba-42b2-a4c4-fc44efbcfae0" width="200"/>
### Impeller
<img src="https://github.com/user-attachments/assets/21e95efd-5e0c-4f41-8f84-af3f0e47d1aa" width="200"/>1 parent 2327428 commit c4c5452
File tree
4 files changed
+261
-3
lines changed- packages/flutter
- lib/src
- rendering
- widgets
- test/widgets
4 files changed
+261
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2193 | 2193 | | |
2194 | 2194 | | |
2195 | 2195 | | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
2196 | 2218 | | |
2197 | 2219 | | |
2198 | 2220 | | |
| |||
2237 | 2259 | | |
2238 | 2260 | | |
2239 | 2261 | | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
2240 | 2278 | | |
2241 | 2279 | | |
2242 | 2280 | | |
2243 | 2281 | | |
2244 | 2282 | | |
2245 | 2283 | | |
2246 | 2284 | | |
| 2285 | + | |
2247 | 2286 | | |
2248 | 2287 | | |
2249 | 2288 | | |
| |||
2254 | 2293 | | |
2255 | 2294 | | |
2256 | 2295 | | |
| 2296 | + | |
2257 | 2297 | | |
2258 | 2298 | | |
2259 | 2299 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1213 | 1213 | | |
1214 | 1214 | | |
1215 | 1215 | | |
| 1216 | + | |
1216 | 1217 | | |
1217 | 1218 | | |
1218 | 1219 | | |
1219 | 1220 | | |
| 1221 | + | |
1220 | 1222 | | |
1221 | 1223 | | |
1222 | 1224 | | |
| |||
1261 | 1263 | | |
1262 | 1264 | | |
1263 | 1265 | | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
1264 | 1279 | | |
1265 | 1280 | | |
1266 | 1281 | | |
| |||
1277 | 1292 | | |
1278 | 1293 | | |
1279 | 1294 | | |
| 1295 | + | |
1280 | 1296 | | |
1281 | 1297 | | |
1282 | 1298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
466 | 467 | | |
467 | 468 | | |
468 | 469 | | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
469 | 498 | | |
470 | 499 | | |
471 | 500 | | |
| |||
485 | 514 | | |
486 | 515 | | |
487 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
488 | 559 | | |
489 | 560 | | |
490 | 561 | | |
| |||
582 | 653 | | |
583 | 654 | | |
584 | 655 | | |
585 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
586 | 676 | | |
587 | 677 | | |
588 | 678 | | |
| |||
603 | 693 | | |
604 | 694 | | |
605 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
606 | 711 | | |
607 | 712 | | |
608 | | - | |
| 713 | + | |
609 | 714 | | |
610 | 715 | | |
611 | 716 | | |
612 | 717 | | |
613 | 718 | | |
614 | 719 | | |
615 | 720 | | |
616 | | - | |
| 721 | + | |
| 722 | + | |
617 | 723 | | |
618 | 724 | | |
619 | 725 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
16 | 112 | | |
17 | 113 | | |
18 | 114 | | |
| |||
0 commit comments