Update: Blocked on https://github.com/flutter/engine/pull/44912 landing,
and merging into google3.
---
Partial work towards https://github.com/flutter/flutter/issues/112498.
_**tl;dr**: In Impeller's backend we intend to _always_ dither
gradients, and never allow any changes long-term (i.e., write your own
shader if you want different behavior) with the assumption that dithered
gradients look better most of the time, and don't typically hurt
elsewhere._
Note that, at the time of this writing, I couldn't find a single case of
this being set explicitly to `true` inside Google, and there are between
[100 and 200 publicly accessible on
GitHub](https://github.com/search?q=%22Paint.enableDithering%22+language%3ADart&type=code&l=Dart),
of which virtually all are setting it explicitly to `true`.
There are some (valid) concerns this would cause a lot of golden-file
image diffs, so I'm going to seek explicit approval from the Google
testing team as well as someone from the framework team before landing
this commit.
## Description
This PR fixes a mistake I made on https://github.com/flutter/engine/pull/44636 where the error handling code wrongly relied on `fl_method_channel_invoke_method_finish` instead of `fl_binary_messenger_send_on_channel_finish`.
The error handling code was not called when running the tests added in https://github.com/flutter/engine/pull/44636 so this mistake did not pop up.
@robert-ancell I added a test that simulates an error response and I had to rely on `g_idle_add` to make it works. Is this approach ok?
## Related Issue
Linux implementation for https://github.com/flutter/flutter/issues/132386
## Tests
Adds one test.
The implementation of DLVerticesGeometry is holding onto a raw ptr that it doesn't own nor does it know that the lifecycle is deterministic. My bad!
This mostly worked (ehhh) until the stopwatch visualizer change. I've confirmed that going back to copying the data fixes the issue with the stopwatch visualizer.
The PR improves the code size and runtime performance of fallback font selection.
### Performance improvements
Initialization of the data structures to support fallback font selection has been moved from creating the FallbackFontManager (first frame) to the first use, i.e. the first frame actually needing a fallback font.
The numbers reported below are for a lightly edited version of the counter demo that appends to the counter about ~300 missing code points that need ~25 fallback fonts to cover the missing code points. Timings taken from a few profiles on my performance workstation.
| | Before | After |
| --- | ---: | ---: |
| FallbackFontManager() |~100ms | <2ms |
| First need | 0ms | 12ms |
| Subsequent need | 20-30ms | <1ms |
### Size improvements
| | Before | After | Î |
| --- | ---: | ---: | ---: |
| main.dart.js | 1586405 | 1477319 | -109086 (-6.87%) |
| brotli -9 | 427304 | 401611 | -25693 (-6.01%) |
### Algorithm notes
#### Startup
The old algorithm built an interval tree from the code point ranges of the ~140 fallback fonts and uses the interval tree to build a list of fonts that support each missing code point. The new algorithm uses a binary search map that directly produces the list of fonts. There are fewer binary search ranges (~22k) than the aggregate ranges for all the fonts (~26k).
Most of the startup time gain comes from using a data unpacks directly into a useful form rather than needing processing to build an interval tree (~12ms vs ~100ms).
#### Running
The runtime for font selection is greatly improved for several reasons
- The code point space is partitioned into components so that code point counting can be batched.
- When a font is selected, the counts are updated incrementally rather than being recomputed.
- The counts are held in fields of the NotoFont and component objects rather than in Maps or Sets.
Batching, incremental update and avoiding hash tables are roughly multiplicative in effect.
## Issues
- https://github.com/flutter/flutter/issues/131440
*If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Fixes https://github.com/flutter/flutter/issues/133377
The default allocation of RasterCacheItems in the layer tree was showing up in profiles of apps running on Impeller which don't actually use the raster cache.
In order to eliminate the overhead of those allocations, RasterCacheItems are now lazily allocated only when the layers encounter an actual raster_cache during the Preroll phase.
Links in an implementation of _availability_version_check on macOS.
This is required due to an upstream compiler builtin (runtime) change
that marked this function as weakly-linked via `__attribute__((weak import))`
As such, no linking failure occurs when the function is unavailable at
link time.
By providing an implementation, the linker picks up our implementation,
which looks up symbol in question at runtime (via dlsym) on the first
invocation, caches it for later invocations, then invokes it. This is,
in fact, precisely what the original clang builtin implementation did.
Upstream clang change: https://reviews.llvm.org/D150397
Issue: https://github.com/flutter/flutter/issues/133777
[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This PR lands changes to `tools/gn` to use Flutter's RBE instance
instead of Goma. It is initially supported only for builds from a Linux
host.
1. Authenticate with `gcloud`
```
engine/src$ ./buildtools/linux-x64/gcloud/bin/gcloud auth application-default login --disable-quota-project
```
2. GN
```
engine/src$ ./flutter/tools/gn --android --android-cpu arm64 --no-lto --runtime-mode debug --rbe
```
3. Build
```
engine/src$ ninja -C out/android_debug_arm64 -j200
```
In https://skia-review.googlesource.com/c/skia/+/742797 Skia refactored
GrBackend* to not require #ifdefs. This changes
callsites in Flutter to use static functions instead of methods that
were conditionally compiled on those classes.
There should be no functional change.
Fixes https://github.com/flutter/flutter/issues/129073
## Changes to Embedder API
Introduced `FlutterRegion` to represent arbitrary region:
```cpp
typedef struct {
/// The size of this struct. Must be sizeof(FlutterRegion).
size_t struct_size;
/// Number of rectangles in the region.
size_t rects_count;
/// The rectangles that make up the region.
FlutterRect* rects;
} FlutterRegion;
```
Note that this is identical to struct `FlutterDamage` with more generic
naming. Maybe down the line we could deprecate `FlutterDamage` and use
`FlutterRegion` instead.
Introduced `FlutterBackingStorePresentInfo`:
```cpp
typedef struct {
size_t struct_size;
/// The area of the backing store that contains Flutter contents. Pixels
/// outside of this area are transparent and the embedder may choose not
/// to render them. Coordinates are in physical pixels.
FlutterRegion* paint_region;
} FlutterBackingStorePresentInfo;
```
In future this struct may also contain more precise hit test region
(when framework supports it) and/or information relevant to partial
repaint (buffer damage, frame damage).
Added a `backing_store_present_info` field to `FlutterLayer`:
```cpp
typedef struct {
...
/// Extra information for the backing store that the embedder may
/// use during presentation.
FlutterBackingStorePresentInfo* backing_store_present_info;
} FlutterLayer;
```
## Changes to the macOS embedder
This PR adds support for `FLTEnableSurfaceDebugInfo` flag in main bundle
`Info.plist` that enables visual indicators of overlay layers.
## Example of unobstructed platform views
https://github.com/flutter/flutter/assets/96958/09a75eee-316b-4d53-a8b4-d6bb4e1e52f7
## Pre-launch Checklist
- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [X] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [X] I updated/added relevant documentation (doc comments with `///`).
- [X] I signed the [CLA].
- [X] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
Relands https://github.com/flutter/engine/pull/45131
Fixes https://github.com/flutter/flutter/issues/132416
Differences from last time:
- Some minor merge conflict fixes
- Use the RTree to get the bounds instead of recalculating the bounds
- Make the iOS platform view controller implementation use the impeller-aware slices instead of the display list ones. This has been fixed for Android and the desktop embedding, but I missed iOS. The unit tests weren't actually running before I branched for my PR, @zanderso fixed them up separately and this resulted in catching the failures on post submit last time.
As discussed offline, this is best deleted when Skia-gold is used for
all of our engine tests.
However, this will be useful for unblocking some PRs until then :)
See README.md for details!
Closes https://github.com/flutter/flutter/issues/126009.
One major change, as-per @jonahwilliams's feedback, is that I created a helper class called `DlVertexPainter`, which provides a `DrawRect`-like API, but just builds a buffer of vertices, resulting into just a single:
```cc
// Actually draw.
canvas->DrawVertices(painter.IntoVertices(), DlBlendMode::kSrc, paint);
```
Also, added test for it, since there is no way to screenshot test to Impeller overlay yet.
# Impeller

This API will help with situations in which the user has a browser
resource that they want to transform into a `ui.Image` and render
directly into the layer tree. Most browser resources can be converted to
an `ImageBitmap` via the `createImageBitmap` API.
The atlas will now store a separate map of glyph positions for each font/scale pair. This avoids the cost of repeated hashing and copying of font objects for each glyph in a text run.
See https://github.com/flutter/flutter/issues/133201