205 Commits

Author SHA1 Message Date
Chinmay Garde
8f5f888826 Use the standard [[nodiscard]] attribute instead of an FML macro. (flutter/engine#17100) 2020-03-11 13:36:01 -07:00
Chinmay Garde
ac5feeb766 Gather demangled stack traces and report the same to console on crashes. (flutter/engine#16450)
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
2020-03-10 16:31:06 -07:00
Chinmay Garde
df4a467fad Reland "Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks." (flutter/engine#16711)
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.
2020-02-24 11:48:32 -08:00
Chinmay Garde
79c230fc7b Revert "Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks. (#16653)" (flutter/engine#16674)
This reverts commit 277bc6c62bf686874e6e519a8bf5707a5d794cf3.
2020-02-18 18:59:21 -08:00
Chinmay Garde
277bc6c62b Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks. (flutter/engine#16653)
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
2020-02-18 12:51:49 -08:00
George Wright
63ec7cb5e3 Revert "Re-arm timer as necessary in MessageLoopFuchsia" (flutter/engine#16568)
This reverts commit da0fcfec7aa70d363d57bc4bb63e94bb65db2941.
2020-02-12 17:22:02 -08:00
Francisco Magdaleno
e3e1166b21 Revert "Re-land: Use os_log instead of syslog on Apple platforms (#16549)" (flutter/engine#16558)
This reverts commit 0659bad4041dfba456648fe6925e95618d46cf6c.
2020-02-12 12:40:31 -08:00
Chris Bracken
0659bad404 Re-land: Use os_log instead of syslog on Apple platforms (flutter/engine#16549)
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.
2020-02-11 15:11:46 -08:00
Chris Bracken
1c57017862 Revert "Use os_log instead of syslog on Apple platforms (#13487)" (flutter/engine#16546)
Looks like somehow the fix to move to static_cast didn't get merged.

This reverts commit 0f8ec47a019633558f3d51652f2faa53a9fd79f7.
2020-02-11 13:20:52 -08:00
Jenn Magder
0f8ec47a01 Use os_log instead of syslog on Apple platforms (flutter/engine#13487)
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.
2020-02-11 10:23:44 -08:00
Dan Field
c8507b069f Apply lints from internal roll (flutter/engine#16509) 2020-02-10 13:53:04 -08:00
Dan Field
21f6cef10b Fix text range logic for a11y (flutter/engine#16496)
Make sure that a text range at the end of the string is still valid.
2020-02-07 12:20:30 -08:00
Kaushik Iska
d8390d3f38 Simplify task queues locking mechanism (flutter/engine#16477)
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
2020-02-07 10:24:05 -08:00
George Wright
bc12e7c8ab Disable unit tests using --gtest-filter instead of at compile time (flutter/engine#16472) 2020-02-06 13:01:14 -08:00
Chinmay Garde
f0ded2e849 Relax timing restrictions on WakeUpTimersAreSingletons. (flutter/engine#16446)
We don’t run this test on bots because we don’t want timeouts on any tests. This
only runs locally as a sanity check for timers.
2020-02-06 12:35:36 -08:00
stuartmorgan
9c3b20b923 Wrap strdup to use compliant name on Windows (flutter/engine#16372)
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
2020-02-05 22:32:56 -08:00
stuartmorgan
69e4ea885f Suppress some deprecation warnings on Windows (flutter/engine#16416)
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
2020-02-05 21:10:25 -08:00
stuartmorgan
7fb266e910 Fix and consolidate wstring conversion utils (flutter/engine#16342)
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.
2020-02-04 13:33:07 -08:00
Chinmay Garde
604ff446de Disable flaky MessageLoop tests on Fuchsia. (flutter/engine#16340)
Investigation is being tracked in https://github.com/flutter/flutter/issues/50032.
2020-02-03 12:49:50 -08:00
Chinmay Garde
426c48aaac Remove all uses of the redundant flutter_root variable. (flutter/engine#16311)
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.
2020-01-31 21:49:48 -08:00
George Wright
baf04d4ca5 Revert "Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118)" (flutter/engine#16277)
This reverts commit 33999d4bc3ee47928ef959d910d4bbfb42b963fd.
2020-01-30 17:19:13 -08:00
stuartmorgan
0710845880 Fix Windows file checks of unicode paths (flutter/engine#16105) 2020-01-30 15:43:02 -08:00
Chinmay Garde
f5ae64f523 Add test to ensure that concurrent message loops have at least one workers. (flutter/engine#16074)
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.
2020-01-28 11:29:42 -08:00
Chinmay Garde
ef31000576 Allow embedders to schedule a callback on all engine managed threads. (flutter/engine#15980)
`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.

Fixes flutter/flutter#49551
Fixes b/143774406
Fixes b/148278215
Fixes b/148278931
2020-01-27 13:49:39 -08:00
Chinmay Garde
93d67baf2b Move tonic into //flutter/third_party. (flutter/engine#15895)
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.
2020-01-25 17:01:56 -08:00
George Wright
86f501cbd8 Disable flakey CountDownLatchTest.CanWait unit test on Fuchsia (flutter/engine#15982) 2020-01-24 19:21:20 -08:00
Dan Field
62a99c60c5 the the fix (flutter/engine#15973) 2020-01-24 12:43:32 -08:00
George Wright
33999d4bc3 Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118) 2020-01-23 18:54:49 -08:00
George Wright
da0fcfec7a Re-arm timer as necessary in MessageLoopFuchsia 2020-01-23 18:54:49 -08:00
Jason Simmons
65ffe2546f Do not produce timeline events in release mode (flutter/engine#15894)
Calling Dart_TimelineEvent has a performance cost, and the APIs for collecting
timeline events are not available in release mode.
2020-01-23 15:05:00 -08:00
George Wright
7d26c109c8 Revert "Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118)" (flutter/engine#15903)
This reverts commit efe18ad9a6b59a3f7b43e0e4e1cfe8dad94f8e16.
2020-01-22 20:35:41 -08:00
Nathan Rogers
f8c3d8d3aa [fuchsia] Support Skia tracing arguments (flutter/engine#15745)
When running on Fuchsia, respect the argument values that Skia passes
into the Flutter implementation of the |SkEventTracer| interface.

Bug: https://github.com/flutter/flutter/issues/48864
2020-01-21 10:00:11 -08:00
Chinmay Garde
c9f71542d1 Disable GPUThreadMerger tests inline instead of via harness flags. (flutter/engine#15706) 2020-01-16 17:11:54 -08:00
George Wright
efe18ad9a6 Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (flutter/engine#15118) 2020-01-07 19:24:45 -08:00
George Wright
b44f4ae767 Fix message_loop_fuchsia and thus enable fml_tests and flow_tests for Fuchsia (flutter/engine#14583) 2019-12-19 17:25:06 -05:00
Chinmay Garde
b111a13d25 Allow embedders to post Dart objects on send ports from the native side. (flutter/engine#14477)
This is a non-breaking addition to the stable Flutter Embedder API and exposes a
subset of the functionality provided by Dart_PostCObject API in a stable and
tested manner to custom embedder implementations.

Send port acquisition can currently be done as described in the unit-test but
there may be opportunities to extend this API in the future to access ports more
easily or create ports from the native side.

The following capabilities of the the Dart_PostCObject API are explicitly NOT
exposed:
* Object arrays: This allows callers to create complex object graphs but only
  using the primitives specified in the native API. I could find no current use
  case for this and would have made the implementation a lot more complex. This
  is something we can add in the future if necessary however.
* Capabilities and ports: Again no use cases and I honestly I didn’t understand
  how to use capabilities. If needed, these can be added at a later point by
  appending to the union.

Fixes https://github.com/flutter/flutter/issues/46624
Fixes b/145982720
2019-12-13 17:28:21 -08:00
Kaushik Iska
4107c00949 [animator] Pass target frametime for Window.onBeginFrame (flutter/engine#14318)
This gives us a time closer to when the frame will be rendered on
screen.

Fixes: https://github.com/flutter/flutter/issues/10850
2019-12-12 15:03:27 -08:00
David Worsham
df08c2593a Relanding: Add Flow unittests and fixtures (flutter/engine#14091) 2019-12-03 14:33:02 -08:00
Kaushik Iska
16ee373dc9 Revert "Fix fml_unittests (#14062)" (flutter/engine#14087)
This reverts commit ca9e7fc470843285b50999fa0e41ba29084ad474.
2019-12-03 12:24:19 -08:00
liyuqian
52e74298e0 Revert PRs to unblock David and Jim's work (flutter/engine#14088)
* Revert "Add flow test fixtures and tests (#13986)"

This reverts commit 32915132bacdfd0d631421b23bb6a6d5db1095ab.

* Revert "Dynamically determine whether to use offscreen surface based on need (#13976)"

This reverts commit a13401ce86b3019c39154d56644b7b9eb4a5bbe5.
2019-12-03 12:02:37 -08:00
David Worsham
32915132ba Add flow test fixtures and tests (flutter/engine#13986) 2019-12-03 09:43:02 -08:00
David Worsham
ca9e7fc470 Fix fml_unittests (flutter/engine#14062) 2019-11-27 16:04:30 -08:00
Chinmay Garde
1405016707 Add a separate target for Dart coverter on FML types. (flutter/engine#14011)
The converters are still in a separate target that must be included manually. This allows targets that depend on FML but not Dart runtime not have to depend on the runtime.

Adds a test that includes this target and tests image decompression from assets. There is also a test for the standalone DartConvertor in shell_unittests but not in fml_unittests be cause FML uni-tests cannot yet launch a VM. I will work on adding fixtures for those.
2019-11-26 13:33:56 -08:00
David Worsham
5aa9e07326 Fix most fml tests on Fuchsia (flutter/engine#14007)
* Add fuchsia MessageLoopImpl; fix several tests
2019-11-25 14:16:50 -08:00
gaaclarke
ec5cf813f6 Made a way to turn off the OpenGL operations on the IO thread for backgrounded apps (flutter/engine#13908) 2019-11-22 14:08:33 -08:00
gaaclarke
43dce83fc1 Refactor to passing functions by const ref (flutter/engine#13975)
Moved our code to passing functions by const ref
2019-11-22 12:20:02 -08:00
gaaclarke
28e7487bf9 Made the thread checker print out the thread names on Apple platforms. (flutter/engine#13943) 2019-11-20 17:56:00 -08:00
George Wright
04e239fc43 Package fml_unittests in a .far file for fml unit tests on Fuchsia (flutter/engine#13471)
Add fml_tests target for the fml unit tests on Fuchsia
2019-11-06 13:01:54 -08:00
chunhtai
29b3675e23 Reland "fix fml_unittes is not run during presubmit (#13395)" (flutter/engine#13426) 2019-10-31 13:50:19 -07:00
Jason Simmons
97b78693bf Duplicate the directory fd in fml::VisitFiles (flutter/engine#13448)
The fd passed to fdopendir will be unusable afterward.  Using a duplicate
preserves the validity of the original directory fd passed to VisitFiles.

Fixes https://github.com/flutter/flutter/issues/43844
2019-10-31 10:35:52 -07:00