203 Commits

Author SHA1 Message Date
Chinmay Garde
92abb22c64
Reland "Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks." (#16711)
This reverts commit ef9e7b1a1365c07ab0df2e2016c4442c3963c2c7 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
ef9e7b1a13
Revert "Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks. (#16653)" (#16674)
This reverts commit 110c1c9adf0f580d16c8252e3b37992af93e9cea.
2020-02-18 18:59:21 -08:00
Chinmay Garde
110c1c9adf
Lift restriction that embedders may not trample the render thread OpenGL context in composition callbacks. (#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
15062ca7a2
Revert "Re-arm timer as necessary in MessageLoopFuchsia" (#16568)
This reverts commit 8ec994b4d6addbe730a0f1044ee63593e5f842c3.
2020-02-12 17:22:02 -08:00
Francisco Magdaleno
e0ebaea590
Revert "Re-land: Use os_log instead of syslog on Apple platforms (#16549)" (#16558)
This reverts commit 6aacf5e76755feb8e0f791fa619cbd99a3bd5885.
2020-02-12 12:40:31 -08:00
Chris Bracken
6aacf5e767
Re-land: Use os_log instead of syslog on Apple platforms (#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 78a8909725bbaeec80870f498d01ea6e56932a3a with a fix.
That commit was reverted in a61dbf2f66b97e85f4d8bf0cfb29a8b3c2640c09.
2020-02-11 15:11:46 -08:00
Chris Bracken
a61dbf2f66
Revert "Use os_log instead of syslog on Apple platforms (#13487)" (#16546)
Looks like somehow the fix to move to static_cast didn't get merged.

This reverts commit 78a8909725bbaeec80870f498d01ea6e56932a3a.
2020-02-11 13:20:52 -08:00
Jenn Magder
78a8909725
Use os_log instead of syslog on Apple platforms (#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
826b2d46ef
Apply lints from internal roll (#16509) 2020-02-10 13:53:04 -08:00
Dan Field
d589ddea68
Fix text range logic for a11y (#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
5c70356a98
Simplify task queues locking mechanism (#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
3ac1e6d8b5
Disable unit tests using --gtest-filter instead of at compile time (#16472) 2020-02-06 13:01:14 -08:00
Chinmay Garde
71ec0a1817
Relax timing restrictions on WakeUpTimersAreSingletons. (#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
9ad81dae16
Wrap strdup to use compliant name on Windows (#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
473f55940f
Suppress some deprecation warnings on Windows (#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
1cd8f3b1aa
Fix and consolidate wstring conversion utils (#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
f8d31baf5b
Disable flaky MessageLoop tests on Fuchsia. (#16340)
Investigation is being tracked in https://github.com/flutter/flutter/issues/50032.
2020-02-03 12:49:50 -08:00
Chinmay Garde
f7b78e001d
Remove all uses of the redundant flutter_root variable. (#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
f5de1acf94
Revert "Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118)" (#16277)
This reverts commit 41e8ed071454cfd9ae02e34198250dea0edab9c4.
2020-01-30 17:19:13 -08:00
stuartmorgan
465529531b
Fix Windows file checks of unicode paths (#16105) 2020-01-30 15:43:02 -08:00
Chinmay Garde
532fdc4f9d
Add test to ensure that concurrent message loops have at least one workers. (#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
c5329ef5c4
Allow embedders to schedule a callback on all engine managed threads. (#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
276481c4d3
Move tonic into //flutter/third_party. (#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
1e7a9debc6
Disable flakey CountDownLatchTest.CanWait unit test on Fuchsia (#15982) 2020-01-24 19:21:20 -08:00
Dan Field
89f3471fa7
the the fix (#15973) 2020-01-24 12:43:32 -08:00
George Wright
41e8ed0714 Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118) 2020-01-23 18:54:49 -08:00
George Wright
8ec994b4d6 Re-arm timer as necessary in MessageLoopFuchsia 2020-01-23 18:54:49 -08:00
Jason Simmons
51919ed38e
Do not produce timeline events in release mode (#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
69bc783016
Revert "Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118)" (#15903)
This reverts commit a50f1ef56a05999bfa97a777cca14fd7a00e8454.
2020-01-22 20:35:41 -08:00
Nathan Rogers
c561e610b1
[fuchsia] Support Skia tracing arguments (#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
2c64a06d4a
Disable GPUThreadMerger tests inline instead of via harness flags. (#15706) 2020-01-16 17:11:54 -08:00
George Wright
a50f1ef56a
Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118) 2020-01-07 19:24:45 -08:00
George Wright
1d3bb8c271
Fix message_loop_fuchsia and thus enable fml_tests and flow_tests for Fuchsia (#14583) 2019-12-19 17:25:06 -05:00
Chinmay Garde
f05832153b
Allow embedders to post Dart objects on send ports from the native side. (#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
e65b4901fa
[animator] Pass target frametime for Window.onBeginFrame (#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
2fc1e1bce1 Relanding: Add Flow unittests and fixtures (#14091) 2019-12-03 14:33:02 -08:00
Kaushik Iska
ea228f2f83
Revert "Fix fml_unittests (#14062)" (#14087)
This reverts commit 6c605f8a9624a99573c6801395f03bff7ee8cc4c.
2019-12-03 12:24:19 -08:00
liyuqian
84bf72917c
Revert PRs to unblock David and Jim's work (#14088)
* Revert "Add flow test fixtures and tests (#13986)"

This reverts commit 620f5281b819f304e8e9e945222e26b17b087cc3.

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

This reverts commit a86ef946563b020108320bbfb974bf7343284fd3.
2019-12-03 12:02:37 -08:00
David Worsham
620f5281b8 Add flow test fixtures and tests (#13986) 2019-12-03 09:43:02 -08:00
David Worsham
6c605f8a96
Fix fml_unittests (#14062) 2019-11-27 16:04:30 -08:00
Chinmay Garde
ca68af252c
Add a separate target for Dart coverter on FML types. (#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
e2aa235ab8
Fix most fml tests on Fuchsia (#14007)
* Add fuchsia MessageLoopImpl; fix several tests
2019-11-25 14:16:50 -08:00
gaaclarke
97a23a80e1
Made a way to turn off the OpenGL operations on the IO thread for backgrounded apps (#13908) 2019-11-22 14:08:33 -08:00
gaaclarke
89e395853c
Refactor to passing functions by const ref (#13975)
Moved our code to passing functions by const ref
2019-11-22 12:20:02 -08:00
gaaclarke
92b2d011c2
Made the thread checker print out the thread names on Apple platforms. (#13943) 2019-11-20 17:56:00 -08:00
George Wright
bc7a007978
Package fml_unittests in a .far file for fml unit tests on Fuchsia (#13471)
Add fml_tests target for the fml unit tests on Fuchsia
2019-11-06 13:01:54 -08:00
chunhtai
d33b91837e
Reland "fix fml_unittes is not run during presubmit (#13395)" (#13426) 2019-10-31 13:50:19 -07:00
Jason Simmons
7fe505ca3c
Duplicate the directory fd in fml::VisitFiles (#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
chunhtai
e569294902
Revert "fix fml_unittes is not run during presubmit (#13395)" (#13425)
This reverts commit 4d553cfe1cd7ec235af4f9d3952a974757cda49b.
2019-10-29 16:36:43 -07:00
chunhtai
4d553cfe1c
fix fml_unittes is not run during presubmit (#13395) 2019-10-29 15:31:25 -07:00