This change also adds TimeRecorder which records time at the start
of each frame to capture the latest vsync target display time and
wires it in to the rasterizer to add trace events when there is a lag.
This PR touches variable names, class names, and file names so it's significantly more risky than its predecessor https://github.com/flutter/engine/pull/17329
Due to file name changes, this PR is expected to change the license files.
We haven't rename `shell/gpu` to `shell/raster` yet. It should be optional but I think it's better to have `raster_surface_software.cc` than `gpu_surface_software.cc`.
Macros to control inlining are not used and we explicitly recommending against
playing with compiler inlining. The macros for alignment became part of the
standard in C++11 and we already use the standard variants over these macros
(see `PointerData`). The formatters are unused as well and we use the stream
based variants for formatting.
These should only be used on host binaries for more detailed crash reports.
Installing the handler on targets (iOS/Android) may cause use to break existing
crash reporting mechanisms users may have installed themselves in the process.
This should work on Darwin & Linux for now.
Doing something like int* a = nullptr; *a = 12; or abort or tripping an
assertion should print something the following before program termination. We
can tweak the report further if necessary.
```
[ERROR:flutter/fml/backtrace.cc(110)] Caught signal SIGSEGV during program execution.
Frame 0: 0x10658342c void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
Frame 1: 0x106555070 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
Frame 2: 0x106554f81 testing::Test::Run()
Frame 3: 0x106555dc3 testing::TestInfo::Run()
Frame 4: 0x1065570a1 testing::TestSuite::Run()
Frame 5: 0x106562a55 testing::internal::UnitTestImpl::RunAllTests()
Frame 6: 0x10658c22c bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*)
Frame 7: 0x1065625c3 bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*)
Frame 8: 0x106562445 testing::UnitTest::Run()
Frame 9: 0x105c8dc33 RUN_ALL_TESTS()
Frame 10: 0x105c8dbe6 main
Frame 11: 0x7fff7c2dc3d5 start
```
Known issue: This routines that generate the stack trace are not signal safe.
But since we only use the same before the process is terminating, this ought to
be fine. I’ll work in a separate patch to convert all the internals to be signal
safe. In the meantime, this will help us better identify the causes of flakes on
our bots.
Fixes https://github.com/flutter/flutter/issues/50244
This reverts commit 79c230fc7b9aa3bb13dcf38cdfe213256c73028a with the following changes to accommodate an embedder for whom the original optimizations caused issues:
* Ensure stable order in the backing stores presented to the embedder. This is a pessimization that will be reverted when the embedder migrates. Tracked in https://github.com/flutter/flutter/issues/51228
* Forego the optimization where the unused layers would be collected before allocation of new layers needs to happen. This is a pessimization that will be reverted when the embedder migrates. Tracked in https://github.com/flutter/flutter/issues/51229
More context in b/146142979.
During the implementation of custom compositor integration, the embedder gets
callbacks on the render thread to prepare render targets (framebuffers,
textures, etc) for the engine to render into, callbacks to present these render
targets along with platform managed contents, and, callbacks to collect render
targets once they can no longer be recycled by the engine in subsequent frames.
During these callbacks, the engine mandates the OpenGL state on the render
thread be preserved. This restriction has been the source of hard to isolate
issues where the embedder trampled on the OpenGL bindings state in the callback
but failed to restore state before control went back to the engine. Due to the
nature of the OpenGL API, such errors are easy to make and overlook. This patch
lifts the restriction from the embedder. Embedders may now freely work with the
OpenGL state in custom compositor callbacks and the engine will make sure to
disregard OpenGL bindings when control flows back to it.
Disregarding current OpenGL state has a certain performance penalty and the
majority of this patch handles refactoring various engine embedder components
such that this happens only once per frame. The most trivial version of this
patch would reset context bindings on every transition of control flow from the
embedder to the engine. However, that naive approach would have necessitated
more than 50 binding resets in existing unit-test cases (depending on the number
of platform view interleaving levels and render target recycling hit rates). In
this implementation, bindings will be reset only once per frame and this does
not depend on the number of platform views in the scene.
The majority of this patch is a refactoring of engine subsystems used in
`ExternalViewEmbedder::SubmitFrame` which is thoroughly documented with each
opportunity for the embedder to invalidate OpenGL state tagged.
The refactoring also enables the implementation of the following optimizations
to engine behavior which should aid in reducing the memory needed for the
creation of render targets. These optimization include:
* The engine will only ask the embedder for render targets in which it expects
to render into. This was a quirk in the way in which root and non-root render
targets were handled. The engine could require the embedder to create a render
target but then realize it didn’t have anything to render into it. In the
presentation callback, it would skip that render target. But the embedder
still had to allocate that extra render target. This will no longer be the
case and should reduce memory use.
* The engine may now skip always realizing (via the embedder render target
creation callback) and presenting the root render target. This was also a side
effect of the same quirk. Previously, the engine would always ask the embedder
to present the root render target even if it was empty. Since this is no
longer the case, few render targets should be allocated which will reduce
memory consumption.
* The engine will now ask the embedder to collect unused render targets before
it asks it to create new ones. The previous behavior was to ask the embedder
for new targets and then collect old ones. This would cause spikes in memory
use when the size of the render targets would change. These memory use spikes
should now be troughs.
* The previous render target cache also considered the platform view ID in cache
viability considerations (instead of just the size of the render target). This
was a bug which has been fixed. This should lead to better cache utilization
in some situations.
These optimizations are now codified in unit-tests and the updated test
expectations are a result of these optimizations now being in place.
* Fixes https://github.com/flutter/flutter/issues/50751
* Fixes https://github.com/flutter/flutter/issues/46911
* Fixes https://github.com/flutter/flutter/issues/43778
* Fixes b/146142979
Migrates to using os_log for app logging on iOS 13 and above, macOS
10.11 and above. On older platform, fall back to syslog(), which is what
we used previously.
This re-lands commit 0f8ec47a019633558f3d51652f2faa53a9fd79f7 with a fix.
That commit was reverted in 1c570178620e77bd1c5969cf8aa783b8f2d543a7.
Migrates to using os_log for app logging on iOS 13 and above, macOS
10.11 and above. On older platform, fall back to syslog(), which is what
we used previously.
We now have one mutex guarding all accesses to
the underlying task heaps. This simplifies the more granular
but bug prone mechanism of having striped locks.
This also re-enables GPUThreadMerger tests that are currently
disabled due to their flaky nature. The scenario that gets fixed by this
change is as follows:
1. Thread-1: We lock `queue_meta_mutex_` and grab locks on `queue_1` and release the meta mutex.
2. Thread-1: We add an Observer on `queues` object.
3. Thread-2: We lock `queue_meta_mutex_` and grab locks on `queue_2`.
4. Thread-2: We try to dispose all the pending tasks on `queue_2` which calls `erase` on `queues`.
The above situation is not thread safe without having 1 lock.
Note: This increases the contention on one lock and could potentially be bad for perf. We are
explicitly making this trade-off towards reducing the complexity.
Fixes: https://github.com/flutter/flutter/issues/49007
A number of POSIX methods were renamed on Windows to match standards
requirements, giving deprecation warnings when calling strdup on Windows.
This adds a wrapper, to allow calling _strdup on Windows instead.
Part of #16256
Targeted suppression of some deprecation warnings that are build errors under
clang:
- Ignore the deprecation of codecvt's unicode conversion until we decide on
a replacement strategy.
- Allow the deprecated posix names of functions in third_party/txt.
Part of https://github.com/flutter/flutter/issues/16256
There were two variants of string/wstring conversion utils, one using
codecvt_utf8 and the other using codecvt_utf8_utf16. We want the latter,
since we want to be using UTF-16, not UCS2.
This was only necessary when the Engine had to build in multiple buildroots
where the sources where checked out at different paths relative to the
buildroot. This is no longer the case and there are already cases GN rules
have been written that mix and match variable usage with the direct
specification of the path to the Flutter sources relative to the sole buildroot.
The current count is determined from std:🧵:hardware_concurrency which can
return zero. Even in such cases, the implementation may not return a loop with
no workers. There are numerous components that depend on having non-zero workers
in the queue.
`FlutterEnginePostCallbackOnAllNativeThreads` schedule a callback to be run on
all engine managed threads. The engine will attempt to service this callback the
next time the message loops for each managed thread is idle. Since the engine
manages the entire lifecycle of multiple threads, there is no opportunity for
the embedders to finely tune the priorities of threads directly, or, perform
other thread specific configuration (for example, setting thread names for
tracing). This callback gives embedders a chance to affect such tuning.
Fixesflutter/flutter#49551
Fixes b/143774406
Fixes b/148278215
Fixes b/148278931
Tonic used to be used by multiple consumers outside of Flutter Engine. Due to
this, it has an unnecessary abstraction layer as well as utilities duplicated in
FML and other engine subsystems. The sole user of Tonic is now the Flutter
Engine. It is intended that the Flutter Engine team now owns this subsystem,
remove unnecessary utilities and document the headers. This is the first step in
the transition. No history is being imported as the initial history was already
lost in the transition of this component to fuchsia.googlesource. As this
component was unmaintained there, I could see no additional value in importing
the history of the patches there.
No functional change. Just moved the repo from //third_party to
//flutter/third_party and updates GN refs.