97 Commits

Author SHA1 Message Date
gaaclarke
2ea8396860
Added unit tests to the engine. (#20216) 2020-08-07 15:55:58 -07:00
Mehmet Fidanboylu
a765090dd8
Fix inconsistent import. (#20206) 2020-08-03 10:29:52 -07:00
Greg Spencer
98cfd1db78
Move platform specific information to PlatformConfiguration class (#19652) 2020-07-31 17:21:02 -07:00
Gary Qian
637a8e7cd0
Revert method channel platform resolved locale (#19136) 2020-06-19 17:40:22 -07:00
Gary Qian
3a96741247
Platform resolved locale and Android localization refactor (#18645) 2020-06-16 04:29:50 -07:00
Gary Qian
8dc91229b4
PlatformResolvedLocale localization message channel (#17755) 2020-04-21 15:34:44 -07:00
chunhtai
7a27e75c67
Add shell api to set default for windows data (#14002) 2020-01-08 19:36:10 -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
1eb15c12fb
Revert 78a8ca0f62b04fa49030ecdd2d91726c0639401f (#13467)
Put `Picture.toImage` back on the GPU thread.  Left the unit tests intact.
2019-10-31 16:57:52 -07:00
Ryan Macnak
f6900001eb
Roll Dart to 6a65ea9cad4b014f88d2f1be1b321db493725a1c. (#13294)
Remove dead shared snapshot arguments to Dart_CreateIsolateGroup.

6a65ea9cad4b [vm] Remove shared snapshot and reused instructions features.
db8370e36147 [gardening] Fix frontend-server dartdevc windows test.
4601bd7bffea Modified supertype check error message to be more descriptive.
0449905e2de6 [CFE] Add a serialization-and-unserialization step to strong test
c8b903c2f94f Update CHANGELOG.md
2a12a13d9684 [Test] Skips emit_aot_size_info_flag_test on crossword.
b26127fe01a5 [cfe] Add reachability test skeleton
2019-10-22 13:14:20 -07:00
Jason Simmons
4ecfa62735
Hold a reference to the Skia unref queue in UIDartState (#13239)
Obtaining the SkiaUnrefQueue through the IOManager is unsafe because
UIDartState has a weak pointer to the IOManager that can not be dereferenced
on the UI thread.
2019-10-21 14:15:03 -07:00
Chinmay Garde
86e3ebb748
Allow embedders to specify arbitrary data to the isolate on launch. (#13047)
Since this is currently only meant to be used by the embedding internally, the setter in Objective-C is only exposed via the FlutterDartProject private class extension. Unit tests have been added to the shell_unittests harness.

Fixes https://github.com/flutter/flutter/issues/37641
2019-10-10 12:31:14 -07:00
gaaclarke
78a8ca0f62
Made Picture::toImage happen on the IO thread with no need for an onscreen surface. (#9813)
Made Picture::toImage happen on the IO thread with no need for a surface.
2019-07-15 17:16:20 -07:00
Chinmay Garde
ad582b5089
Rework image & texture management to use concurrent message queues. (#9486)
This patch reworks image decompression and collection in the following ways
because of misbehavior in the described edge cases.

The current flow for realizing a texture on the GPU from a blob of compressed
bytes is to first pass it to the IO thread for image decompression and then
upload to the GPU. The handle to the texture on the GPU is then passed back to
the UI thread so that it can be included in subsequent layer trees for
rendering. The GPU contexts on the Render & IO threads are in the same
sharegroup so the texture ends up being visible to the Render Thread context
during rendering. This works fine and does not block the UI thread. All
references to the image are owned on UI thread by Dart objects. When the final
reference to the image is dropped, the texture cannot be collected on the UI
thread (because it has not GPU context). Instead, it must be passed to either
the GPU or IO threads. The GPU thread is usually in the middle of a frame
workload so we redirect the same to the IO thread for eventual collection. While
texture collections are usually (comparatively) fast, texture decompression and
upload are slow (order of magnitude of frame intervals).

For application that end up creating (by not necessarily using) numerous large
textures in straight-line execution, it could be the case that texture
collection tasks are pending on the IO task runner after all the image
decompressions (and upload) are done. Put simply, the collection of the first
image could be waiting for the decompression and upload of the last image in the
queue.

This is exacerbated by two other hacks added to workaround unrelated issues.
* First, creating a codec with a single image frame immediately kicks of
  decompression and upload of that frame image (even if the frame was never
  request from the codec). This hack was added because we wanted to get rid of
  the compressed image allocation ASAP. The expectation was codecs would only be
  created with the sole purpose of getting the decompressed image bytes.
  However, for applications that only create codecs to get image sizes (but
  never actually decompress the same), we would end up replacing the compressed
  image allocation with a larger allocation (device resident no less) for no
  obvious use. This issue is particularly insidious when you consider that the
  codec is usually asked for the native image size first before the frame is
  requested at a smaller size (usually using a new codec with same data but new
  targetsize). This would cause the creation of a whole extra texture (at 1:1)
  when the caller was trying to “optimize” for memory use by requesting a
  texture of a smaller size.
* Second, all image collections we delayed in by the unref queue by 250ms
  because of observations that the calling thread (the UI thread) was being
  descheduled unnecessarily when a task with a timeout of zero was posted from
  the same (recall that a task has to be posted to the IO thread for the
  collection of that texture). 250ms is multiple frame intervals worth of
  potentially unnecessary textures.

The net result of these issues is that we may end up creating textures when all
that the application needs is to ask it’s codec for details about the same (but
not necessarily access its bytes). Texture collection could also be delayed
behind other jobs to decompress the textures on the IO thread. Also, all texture
collections are delayed for an arbitrary amount of time.

These issues cause applications to be susceptible to OOM situations. These
situations manifest in various ways. Host memory exhaustion causes the usual OOM
issues. Device memory exhaustion seems to manifest in different ways on iOS and
Android. On Android, allocation of a new texture seems to be causing an
assertion (in the driver). On iOS, the call hangs (presumably waiting for
another thread to release textures which we won’t do because those tasks are
blocked behind the current task completing).

To address peak memory usage, the following changes have been made:
* Image decompression and upload/collection no longer happen on the same thread.
  All image decompression will now be handled on a workqueue. The number of
  worker threads in this workqueue is equal to the number of processors on the
  device. These threads have a lower priority that either the UI or Render
  threads. These workers are shared between all Flutter applications in the
  process.
* Both the images and their codec now report the correct allocation size to Dart
  for GC purposes. The Dart VM uses this to pick objects for collection. Earlier
  the image allocation was assumed to 32bpp with no mipmapping overhead
  reported. Now, the correct image size is reported and the mipmapping overhead
  is accounted for. Image codec sizes were not reported to the VM earlier and
  now are. Expect “External” VM allocations to be higher than previously
  reported and the numbers in Observatory to line up more closely with actual
  memory usage (device and host).
* Decoding images to a specific size used to decode to 1:1 before performing a
  resize to the correct dimensions before texture upload. This has now been
  reworked so that images are first decompressed to a smaller size supported
  natively by the codec before final resizing to the requested target size. The
  intermediate copy is now smaller and more promptly collected. Resizing also
  happens on the workqueue worker.
* The drain interval of the unref queue is now sub-frame-interval. I am hesitant
  to remove the delay entirely because I have not been able to instrument the
  performance overhead of the same. That is next on my list. But now, multiple
  frame intervals worth of textures no longer stick around.

The following issues have been addressed:
* https://github.com/flutter/flutter/issues/34070 Since this was the first usage
  of the concurrent message loops, the number of idle wakes were determined to
  be too high and this component has been rewritten to be simpler and not use
  the existing task runner and MessageLoopImpl interface.
* Image decoding had no tests. The new `ui_unittests` harness has been added
  that sets up a GPU test harness on the host using SwiftShader. Tests have been
  added for image decompression, upload and resizing.
* The device memory exhaustion in this benchmark has been addressed. That
  benchmark is still not viable for inclusion in any harness however because it
  creates 9 million codecs in straight-line execution. Because these codecs are
  destroyed in the microtask callbacks, these are referenced till those
  callbacks are executed. So now, instead of device memory exhaustion, this will
  lead to (slower) exhaustion of host memory. This is expected and working as
  intended.

This patch only addresses peak memory use and makes collection of unused images
and textures more prompt. It does NOT address memory use by images referenced
strongly by the application or framework.
2019-07-09 14:59:34 -07:00
Zachary Anderson
0a2e28d797
Revert tracing changes (#9296)
* Revert "[fuchsia] Fix alignment of Fuchsia/non-Fuchsia tracing (#9289)"

This reverts commit f80ac5f571479053b134e60bca77603269b2ce2a.

* Revert "Align fuchsia and non-fuchsia tracing (#9199)"

This reverts commit 78265484623037c6544dfd5380367bca29fa27b0.
2019-06-12 10:25:49 -07:00
liyuqian
9f088c65ee
Add onReportTimings and FrameRasterizedCallback API (#8983)
Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
https://github.com/flutter/flutter/issues/26154
https://github.com/flutter/flutter/issues/31444
https://github.com/flutter/flutter/issues/32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:
* NoNeedToReportTimingsByDefault
* NeedsReportTimingsIsSetWithCallback
* ReportTimingsIsCalled
* FrameRasterizedCallbackIsCalled
* FrameTimingSetsAndGetsProperly
* onReportTimings preserves callback zone
* FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.
2019-06-06 10:42:48 -07:00
Dan Field
7826548462
Align fuchsia and non-fuchsia tracing (#9199) 2019-06-05 15:14:27 -07:00
Chris Bracken
0f1ff3bdb3
Correct typos, adopt US spellings (#9081)
Corects a bnuch of typeos throughout teh engien codebsae. Also makes
a couple minor Commonwealth -> US spelling adjustments for consistency
with the rest of Flutter's codebase.

Made use of `misspell` tool:
https://github.com/client9/misspell
2019-05-25 13:14:46 -07:00
Chinmay Garde
1239df96aa
Allow native bindings in secondary isolates. (#8658)
The callbacks can be wired in via the Settings object. Both runtime and shell unit-tests have been patched to test this.
2019-04-19 17:36:36 -07:00
Chinmay Garde
eec74e5c92
Rename the blink namespace to flutter. (#8517)
Some components in the Flutter engine were derived from the forked blink codebase. While the forked components have either been removed or rewritten, the use of the blink namespace has mostly (and inconsistently) remained. This renames the blink namesapce to flutter for consistency. There are no functional changes in this patch.
2019-04-09 12:44:42 -07:00
Chinmay Garde
7e38b0aa23
Revert "Revert "Separate the data required to bootstrap the VM into its own class. (#8397)" (#8406)" (#8414)
This reverts commit f7b4903d7c9913447af3aaebc4308d1a1e2a4dde.
2019-04-03 13:38:12 -07:00
Zachary Anderson
f7b4903d7c
Revert "Separate the data required to bootstrap the VM into its own class. (#8397)" (#8406)
This reverts commit c991647404f8117dab2ca4ed49aa3ba48a634240.
2019-04-02 09:12:56 -07:00
Chinmay Garde
c991647404
Separate the data required to bootstrap the VM into its own class. (#8397)
When attempting to shutdown and subsequently restart the VM, having the
VM own this data introduces lifecycle issues due to circular references.
2019-04-01 14:58:05 -07:00
Gary Qian
3661d5e43b
Re-land "Buffer lifecycle in WindowData" (#8032) 2019-03-06 15:38:34 -08:00
Gary Qian
39c46dea4b
Revert "Buffer lifecycle in WindowData (#7999)" (#8010)
This reverts commit 0b174017143c34629546134601bb6c65becf71a3.
2019-03-01 15:14:20 -08:00
Gary Qian
0b17401714
Buffer lifecycle in WindowData (#7999) 2019-03-01 10:43:09 -08:00
Dan Field
572fea361c
Revert "Shut down and restart the Dart VM as needed. (#7832)" (#7877)
This reverts commit 0d6ff1669c4a765774b91e37353b4392408d112a.
2019-02-19 16:14:18 -08:00
Chinmay Garde
0d6ff1669c
Shut down and restart the Dart VM as needed. (#7832)
The shell was already designed to cleanly shut down the VM but it couldnt
earlier as |Dart_Initialize| could never be called after a |Dart_Cleanup|. This
meant that shutting down an engine instance could not shut down the VM to save
memory because newly created engines in the process after that point couldn't
restart the VM. There can only be one VM running in a process at a time.

This patch separate the previous DartVM object into one that references a
running instance of the DartVM and a set of immutable dependencies that
components can reference even as the VM is shutting down.

Unit tests have been added to assert that non-overlapping engine launches use
difference VM instances.
2019-02-15 14:16:17 -08:00
Dan Field
43fa420b04
Make IOManager own resource context (#7272)
* Make IOManager own resource context
2019-01-14 13:46:38 -08:00
Jason Simmons
358a24c499
Make SetLocales more consistent with other RuntimeController methods (#7447) 2019-01-10 17:30:58 -08:00
Zachary Anderson
b7f6bf0192
Pass deadline to embedder idle notification callback (#7444) 2019-01-10 14:08:43 -08:00
Chinmay Garde
b972f75db5
Allow embedders to add per shell idle notification callbacks. (#7427) 2019-01-09 14:33:56 -08:00
Jason Simmons
3978f07530
Keep a copy of each engine's description that can be accessed outside the engine's UI thread (#6885)
The service protocol's ListViews method needs to return description data for
each engine in the process.  Previously ListViews would queue a task to each
UI thread to gather this data.  However, the UI thread might be blocked from
executing tasks (e.g. if the Dart isolate is paused), resulting in a deadlock.

This change provides a copy of the engine's description data to the
ServiceProtocol's global list of engines, allowing ListViews to run without
accessing any UI threads.

Fixes https://github.com/flutter/flutter/issues/24400
2018-11-16 14:47:40 -08:00
Dan Field
396402f5bd
Flush UserSettings to window (#6850) 2018-11-13 23:41:56 -08:00
Michael Goderbauer
09ef73ff6e
Fix code smells reported by chrome's clang plugin (#6833) 2018-11-12 19:59:29 -08:00
Michael Goderbauer
70a1106b50
Unify copyright lines (#6757) 2018-11-07 12:24:35 -08:00
Chinmay Garde
ba8f6aa71c
Handle Windows headers defining ERROR to 0 in log levels. (#6677) 2018-10-26 16:47:14 -07:00
Chinmay Garde
20c805c973
Ensure that Scene::toImage renders texture backed images. (#6636)
TL;DR: Offscreen surface is created on the render thread and device to host
transfer performed there before task completion on the UI thread.

While attempting to snapshot layer trees, the engine was attempting to use the
IO thread context. The reasoning was that this would be safe to do because any
textures uploaded to the GPU as a result of async texture upload would have
originated from this context and hence the handles would be valid in either
context. As it turns out, while the handles are valid, Skia does not support
this use-case because cross-context images transfer ownership of the image from
one context to another. So, when we made the hop from the UI thread to the IO
thread (for snapshotting), if either the UI or GPU threads released the last
reference to the texture backed image, the image would be invalid. This led to
such images being absent from the layer tree snapshot.

Simply referencing the images as they are being used on the IO thread is not
sufficient because accessing images on one context after their ownership has
already been transferred to another is not safe behavior (from Skia's
perspective, the handles are still valid in the sharegroup).

To work around these issues, it was decided that an offscreen render target
would be created on the render thread. The color attachment of this render
target could then be transferred as a cross context image to the IO thread for
the device to host tranfer.

Again, this is currently not quite possible because the only way to create
cross context images is from encoded data. Till Skia exposes the functionality
to create cross-context images from textures in one context, we do a device to
host transfer on the GPU thread. The side effect of this is that this is now
part of the frame workload (image compression, which dominate the wall time,
is still done of the IO thread).

A minor side effect of this patch is that the GPU latch needs to be waited on
before the UI thread tasks can be completed before shell initialization.
2018-10-22 17:40:24 -07:00
Michael Klimushyn
abd04b459c
Programmatically set the root isolate's debug name (#6596)
An integration test will be added to the framework's repo as a followup.

Addresses flutter/flutter#22009
2018-10-18 14:47:24 -07:00
Gary Qian
35340ceaf0
Pass full locale list with script and variant codes to framework (#6557)
* Locale Passing

* Pass full locale list and script and variant codes to framework

* Working Android locale list passing and fallback
2018-10-17 10:53:01 -07:00
Gary Qian
61cf4c01fd
Pass scriptcode and variantcode to dart:ui Window. (#6493) 2018-10-10 17:22:59 -07:00
Jonah Williams
dcd2956f88
Initial support for more finely-grained a11y features on Window (#5901) 2018-07-31 18:18:19 -07:00
Chinmay Garde
9f8285ac6c
Remove all dependencies on Garnet. (#5869) 2018-07-26 12:49:34 -07:00
Chinmay Garde
336c23f846
Remove //flutter/glue and use FML directly. (#5862) 2018-07-25 13:20:48 -07:00
Jason Simmons
0bad812c72
Migrate to a standalone Tonic repository separated from Topaz (#5817) 2018-07-23 11:49:35 -07:00
Jonah Williams
2e57ecd38f
Revert rollback of "add assistiveTechnologyEnabled to window" (#5750) 2018-07-16 09:04:20 -07:00
Jonah Williams
9af920ef22 Revert "Add assistiveTechnologyEnabled flag to window" (#5746)
Reverts flutter/engine#5740
2018-07-13 15:55:49 -07:00
Jonah Williams
9ece2752aa
Add assistiveTechnologyEnabled flag to window (#5740) 2018-07-13 13:47:31 -07:00
Jason Simmons
500f91bc49
Return a failure exit code in flutter_tester if an uncaught error occurs in a microtask (#5736) 2018-07-13 09:44:22 -07:00
Jonah Williams
48d6e1f891
Custom accessibility (local context) action support for iOS and Android. (#5597) 2018-07-11 10:27:50 -07:00